@@ -278,7 +278,6 @@ function SendFunds(props: {
278
278
activeAccount : Account ;
279
279
} ) {
280
280
const { tokens, chain, receiverAddress } = params ;
281
- toast . loading ( `Sending ${ tokens . length } Tokens` ) ;
282
281
283
282
const transactions = tokens . map ( ( { token, amount } ) => {
284
283
return getTokenTransferTransaction ( {
@@ -289,18 +288,19 @@ function SendFunds(props: {
289
288
} ) ;
290
289
} ) ;
291
290
292
- try {
293
- await sendBatchTransactions . mutateAsync ( transactions ) ;
294
- toast . success ( "Tokens sent successfully" , {
295
- duration : 10000 ,
296
- } ) ;
297
- } catch ( e ) {
298
- toast . error ( "Failed to send tokens" , {
299
- description : parseError ( e ) ,
300
- duration : 10000 ,
301
- } ) ;
302
- console . error ( e ) ;
303
- }
291
+ const txPromise = sendBatchTransactions . mutateAsync ( transactions ) ;
292
+ toast . promise ( txPromise , {
293
+ loading : `Sending ${ tokens . length } tokens` ,
294
+ success : `${ tokens . length } tokens sent successfully` ,
295
+ error : ( result ) => {
296
+ return {
297
+ message : "Failed to send tokens. Please try again" ,
298
+ description : parseError ( result ) ,
299
+ } ;
300
+ } ,
301
+ } ) ;
302
+
303
+ await txPromise ;
304
304
}
305
305
306
306
async function handleSingleSubmit ( params : {
@@ -321,22 +321,28 @@ function SendFunds(props: {
321
321
receiverAddress,
322
322
} ) ;
323
323
324
- toast . loading ( `Sending Token ${ token . name } ` ) ;
325
- await sendAndConfirmTransaction . mutateAsync ( tx ) ;
324
+ const txPromise = sendAndConfirmTransaction . mutateAsync ( tx ) ;
326
325
327
- toast . success ( `${ token . name } sent successfully` , {
328
- duration : 10000 ,
326
+ toast . promise ( txPromise , {
327
+ loading : `Sending Token ${ token . name } ` ,
328
+ success : `${ token . name } sent successfully` ,
329
+ error : ( result ) => {
330
+ return {
331
+ message : `Failed to send ${ token . name } . Please try again` ,
332
+ description : parseError ( result ) ,
333
+ } ;
334
+ } ,
329
335
} ) ;
336
+
337
+ await txPromise ;
338
+
330
339
queryClient . invalidateQueries ( {
331
340
queryKey : [ "walletBalance" ] ,
332
341
} ) ;
333
342
334
343
successCount ++ ;
335
- } catch ( e ) {
336
- toast . error ( `Failed to send ${ token . name } ` , {
337
- description : parseError ( e ) ,
338
- duration : 10000 ,
339
- } ) ;
344
+ } catch {
345
+ // no op
340
346
}
341
347
}
342
348
@@ -374,20 +380,24 @@ function SendFunds(props: {
374
380
// eslint-disable-next-line no-restricted-syntax
375
381
const chain = defineChain ( values . chainId ) ;
376
382
377
- if ( activeAccount . sendBatchTransaction ) {
378
- await handleBatchSubmit ( {
379
- tokens : validTokens ,
380
- chain,
381
- activeAccount,
382
- receiverAddress : values . receiverAddress ,
383
- } ) ;
384
- } else {
385
- await handleSingleSubmit ( {
386
- tokens : validTokens ,
387
- chain,
388
- activeAccount,
389
- receiverAddress : values . receiverAddress ,
390
- } ) ;
383
+ try {
384
+ if ( activeAccount . sendBatchTransaction ) {
385
+ await handleBatchSubmit ( {
386
+ tokens : validTokens ,
387
+ chain,
388
+ activeAccount,
389
+ receiverAddress : values . receiverAddress ,
390
+ } ) ;
391
+ } else {
392
+ await handleSingleSubmit ( {
393
+ tokens : validTokens ,
394
+ chain,
395
+ activeAccount,
396
+ receiverAddress : values . receiverAddress ,
397
+ } ) ;
398
+ }
399
+ } catch {
400
+ // no op
391
401
}
392
402
393
403
queryClient . invalidateQueries ( {
0 commit comments