@@ -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,36 +321,36 @@ 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
343
349
if ( tokens . length > 1 ) {
344
350
if ( successCount === tokens . length ) {
345
- toast . success ( "All tokens sent successfully" , {
346
- id : "batch-send" ,
347
- duration : 10000 ,
348
- } ) ;
351
+ toast . success ( "All tokens sent successfully" ) ;
349
352
} else {
350
- toast . error ( `Failed to send ${ tokens . length - successCount } tokens` , {
351
- id : "batch-send" ,
352
- duration : 10000 ,
353
- } ) ;
353
+ toast . error ( `Failed to send ${ tokens . length - successCount } tokens` ) ;
354
354
}
355
355
}
356
356
}
@@ -374,20 +374,24 @@ function SendFunds(props: {
374
374
// eslint-disable-next-line no-restricted-syntax
375
375
const chain = defineChain ( values . chainId ) ;
376
376
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
- } ) ;
377
+ try {
378
+ if ( activeAccount . sendBatchTransaction ) {
379
+ await handleBatchSubmit ( {
380
+ tokens : validTokens ,
381
+ chain,
382
+ activeAccount,
383
+ receiverAddress : values . receiverAddress ,
384
+ } ) ;
385
+ } else {
386
+ await handleSingleSubmit ( {
387
+ tokens : validTokens ,
388
+ chain,
389
+ activeAccount,
390
+ receiverAddress : values . receiverAddress ,
391
+ } ) ;
392
+ }
393
+ } catch {
394
+ // no op
391
395
}
392
396
393
397
queryClient . invalidateQueries ( {
0 commit comments