@@ -278,7 +278,6 @@ function SendFunds(props: {
278278 activeAccount : Account ;
279279 } ) {
280280 const { tokens, chain, receiverAddress } = params ;
281- toast . loading ( `Sending ${ tokens . length } Tokens` ) ;
282281
283282 const transactions = tokens . map ( ( { token, amount } ) => {
284283 return getTokenTransferTransaction ( {
@@ -289,18 +288,19 @@ function SendFunds(props: {
289288 } ) ;
290289 } ) ;
291290
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 ;
304304 }
305305
306306 async function handleSingleSubmit ( params : {
@@ -321,22 +321,28 @@ function SendFunds(props: {
321321 receiverAddress,
322322 } ) ;
323323
324- toast . loading ( `Sending Token ${ token . name } ` ) ;
325- await sendAndConfirmTransaction . mutateAsync ( tx ) ;
324+ const txPromise = sendAndConfirmTransaction . mutateAsync ( tx ) ;
326325
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+ } ,
329335 } ) ;
336+
337+ await txPromise ;
338+
330339 queryClient . invalidateQueries ( {
331340 queryKey : [ "walletBalance" ] ,
332341 } ) ;
333342
334343 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
340346 }
341347 }
342348
@@ -374,20 +380,24 @@ function SendFunds(props: {
374380 // eslint-disable-next-line no-restricted-syntax
375381 const chain = defineChain ( values . chainId ) ;
376382
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
391401 }
392402
393403 queryClient . invalidateQueries ( {
0 commit comments