@@ -69,6 +69,111 @@ export const syncApi = {
6969 }
7070 } ,
7171
72+ /**
73+ * Sync a campaign deletion after the owner deletes it on-chain
74+ * @param campaignId - The on-chain campaign ID
75+ * @param txHash - Transaction hash from the delete transaction
76+ * @param senderId - Account ID of the campaign owner who deleted it
77+ */
78+ async campaignDelete (
79+ campaignId : number | string ,
80+ txHash : string ,
81+ senderId : string ,
82+ ) : Promise < { success : boolean ; message ?: string } > {
83+ try {
84+ const response = await fetch (
85+ `${ CAMPAIGNS_SYNC_API_BASE_URL } /api/v1/campaigns/${ campaignId } /delete/sync` ,
86+ {
87+ method : "POST" ,
88+ headers : { "Content-Type" : "application/json" } ,
89+ body : JSON . stringify ( { tx_hash : txHash , sender_id : senderId } ) ,
90+ } ,
91+ ) ;
92+
93+ if ( ! response . ok ) {
94+ const error = await response . json ( ) . catch ( ( ) => ( { } ) ) ;
95+ console . warn ( "Failed to sync campaign deletion:" , error ) ;
96+ return { success : false , message : error ?. error || "Sync failed" } ;
97+ }
98+
99+ const result = await response . json ( ) ;
100+ return { success : true , message : result . message } ;
101+ } catch ( error ) {
102+ console . warn ( "Failed to sync campaign deletion:" , error ) ;
103+ return { success : false , message : String ( error ) } ;
104+ }
105+ } ,
106+
107+ /**
108+ * Sync campaign donation refunds after process_refunds_batch is executed
109+ * @param campaignId - The on-chain campaign ID
110+ * @param txHash - Transaction hash from the refund transaction
111+ * @param senderId - Account ID of the sender who triggered refunds
112+ */
113+ async campaignRefund (
114+ campaignId : number | string ,
115+ txHash : string ,
116+ senderId : string ,
117+ ) : Promise < { success : boolean ; message ?: string } > {
118+ try {
119+ const response = await fetch (
120+ `${ CAMPAIGNS_SYNC_API_BASE_URL } /api/v1/campaigns/${ campaignId } /refunds/sync` ,
121+ {
122+ method : "POST" ,
123+ headers : { "Content-Type" : "application/json" } ,
124+ body : JSON . stringify ( { tx_hash : txHash , sender_id : senderId } ) ,
125+ } ,
126+ ) ;
127+
128+ if ( ! response . ok ) {
129+ const error = await response . json ( ) . catch ( ( ) => ( { } ) ) ;
130+ console . warn ( "Failed to sync campaign refunds:" , error ) ;
131+ return { success : false , message : error ?. error || "Sync failed" } ;
132+ }
133+
134+ const result = await response . json ( ) ;
135+ return { success : true , message : result . message } ;
136+ } catch ( error ) {
137+ console . warn ( "Failed to sync campaign refunds:" , error ) ;
138+ return { success : false , message : String ( error ) } ;
139+ }
140+ } ,
141+
142+ /**
143+ * Sync campaign donation unescrow after process_escrowed_donations_batch is executed
144+ * @param campaignId - The on-chain campaign ID
145+ * @param txHash - Transaction hash from the unescrow transaction
146+ * @param senderId - Account ID of the sender who triggered unescrow
147+ */
148+ async campaignUnescrow (
149+ campaignId : number | string ,
150+ txHash : string ,
151+ senderId : string ,
152+ ) : Promise < { success : boolean ; message ?: string } > {
153+ try {
154+ const response = await fetch (
155+ `${ CAMPAIGNS_SYNC_API_BASE_URL } /api/v1/campaigns/${ campaignId } /unescrow/sync` ,
156+ {
157+ method : "POST" ,
158+ headers : { "Content-Type" : "application/json" } ,
159+ body : JSON . stringify ( { tx_hash : txHash , sender_id : senderId } ) ,
160+ } ,
161+ ) ;
162+
163+ if ( ! response . ok ) {
164+ const error = await response . json ( ) . catch ( ( ) => ( { } ) ) ;
165+ console . warn ( "Failed to sync campaign unescrow:" , error ) ;
166+ return { success : false , message : error ?. error || "Sync failed" } ;
167+ }
168+
169+ const result = await response . json ( ) ;
170+ return { success : true , message : result . message } ;
171+ } catch ( error ) {
172+ console . warn ( "Failed to sync campaign unescrow:" , error ) ;
173+ return { success : false , message : String ( error ) } ;
174+ }
175+ } ,
176+
72177 /**
73178 * Sync an account profile and recalculate donation stats
74179 * @param accountId - The NEAR account ID
0 commit comments