Skip to content

Commit 86b49d5

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

File tree

1 file changed

+46
-38
lines changed

1 file changed

+46
-38
lines changed

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

Lines changed: 46 additions & 38 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,35 +321,39 @@ 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) {
345351
toast.success("All tokens sent successfully", {
346352
id: "batch-send",
347-
duration: 10000,
348353
});
349354
} else {
350355
toast.error(`Failed to send ${tokens.length - successCount} tokens`, {
351356
id: "batch-send",
352-
duration: 10000,
353357
});
354358
}
355359
}
@@ -374,20 +378,24 @@ function SendFunds(props: {
374378
// eslint-disable-next-line no-restricted-syntax
375379
const chain = defineChain(values.chainId);
376380

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-
});
381+
try {
382+
if (activeAccount.sendBatchTransaction) {
383+
await handleBatchSubmit({
384+
tokens: validTokens,
385+
chain,
386+
activeAccount,
387+
receiverAddress: values.receiverAddress,
388+
});
389+
} else {
390+
await handleSingleSubmit({
391+
tokens: validTokens,
392+
chain,
393+
activeAccount,
394+
receiverAddress: values.receiverAddress,
395+
});
396+
}
397+
} catch {
398+
// no op
391399
}
392400

393401
queryClient.invalidateQueries({

0 commit comments

Comments
 (0)