Skip to content

Commit 139a015

Browse files
committed
Nebula: Improved toasts in move funds page
1 parent 2d15cd6 commit 139a015

File tree

1 file changed

+48
-44
lines changed

1 file changed

+48
-44
lines changed

apps/dashboard/src/app/nebula-app/move-funds/move-funds.tsx

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -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,36 +321,36 @@ 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

343349
if (tokens.length > 1) {
344350
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");
349352
} 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`);
354354
}
355355
}
356356
}
@@ -374,20 +374,24 @@ function SendFunds(props: {
374374
// eslint-disable-next-line no-restricted-syntax
375375
const chain = defineChain(values.chainId);
376376

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
391395
}
392396

393397
queryClient.invalidateQueries({

0 commit comments

Comments
 (0)