Skip to content

Commit 717a622

Browse files
committed
pr comments
1 parent 97cf9bb commit 717a622

File tree

2 files changed

+46
-50
lines changed

2 files changed

+46
-50
lines changed

apps/dashboard/src/app/team/[team_slug]/(team)/~/engine/(instance)/[engineId]/overview/components/backend-wallets-table.tsx

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { type ColumnDef, createColumnHelper } from "@tanstack/react-table";
3333
import { ChainIcon } from "components/icons/ChainIcon";
3434
import { TWTable } from "components/shared/TWTable";
3535
import { useTrack } from "hooks/analytics/useTrack";
36-
import { useTxNotifications } from "hooks/useTxNotifications";
3736
import { EngineBackendWalletOptions } from "lib/engine";
3837
import { useActiveChainAsDashboardChain } from "lib/v5-adapter";
3938
import {
@@ -46,8 +45,10 @@ import {
4645
import QRCode from "qrcode";
4746
import { useState } from "react";
4847
import { useForm } from "react-hook-form";
48+
import { toast } from "sonner";
4949
import { getAddress } from "thirdweb";
5050
import { shortenAddress } from "thirdweb/utils";
51+
import invariant from "tiny-invariant";
5152
import { FormHelperText, FormLabel, LinkButton, Text } from "tw-components";
5253
import { prettyPrintCurrency } from "./utils";
5354

@@ -246,25 +247,19 @@ const EditModal = ({
246247
disclosure: UseDisclosureReturn;
247248
instanceUrl: string;
248249
}) => {
249-
const { mutate: updateBackendWallet } =
250-
useEngineUpdateBackendWallet(instanceUrl);
250+
const updateBackendWallet = useEngineUpdateBackendWallet(instanceUrl);
251251
const trackEvent = useTrack();
252-
const { onSuccess, onError } = useTxNotifications(
253-
"Successfully updated backend wallet.",
254-
"Failed to update backend wallet.",
255-
);
256252

257253
const [label, setLabel] = useState(backendWallet.label ?? "");
258254

259-
const onClick = () => {
260-
updateBackendWallet(
255+
const onClick = async () => {
256+
const promise = updateBackendWallet.mutateAsync(
261257
{
262258
walletAddress: backendWallet.address,
263259
label,
264260
},
265261
{
266262
onSuccess: () => {
267-
onSuccess();
268263
disclosure.onClose();
269264
trackEvent({
270265
category: "engine",
@@ -274,7 +269,6 @@ const EditModal = ({
274269
});
275270
},
276271
onError: (error) => {
277-
onError(error);
278272
trackEvent({
279273
category: "engine",
280274
action: "update-backend-wallet",
@@ -285,6 +279,11 @@ const EditModal = ({
285279
},
286280
},
287281
);
282+
283+
toast.promise(promise, {
284+
success: "Successfully updated backend wallet.",
285+
error: "Failed to update backend wallet.",
286+
});
288287
};
289288

290289
return (
@@ -401,39 +400,39 @@ const SendFundsModal = ({
401400
}) => {
402401
const chain = useActiveChainAsDashboardChain();
403402
const form = useForm<SendFundsInput>();
404-
const { mutate: sendTokens } = useEngineSendTokens(instanceUrl);
403+
const sendTokens = useEngineSendTokens(instanceUrl);
405404
const { data: backendWalletBalance } = useEngineBackendWalletBalance(
406405
instanceUrl,
407406
fromWallet.address,
408407
);
409-
const { onSuccess, onError } = useTxNotifications(
410-
"Successfully sent a request to send funds.",
411-
"Failed to send tokens.",
412-
);
413408
const toWalletDisclosure = useDisclosure();
414409

410+
if (!backendWalletBalance) {
411+
return null;
412+
}
413+
415414
const onSubmit = async (data: SendFundsInput) => {
416-
if (!chain) {
417-
return;
418-
}
415+
invariant(chain, "chain is required");
419416

420-
try {
421-
await sendTokens({
417+
const promise = sendTokens.mutateAsync(
418+
{
422419
chainId: chain.chainId,
423420
fromAddress: fromWallet.address,
424421
toAddress: data.toAddress,
425422
amount: data.amount,
426-
});
427-
onSuccess();
428-
disclosure.onClose();
429-
} catch (e) {
430-
onError(e);
431-
}
432-
};
423+
},
424+
{
425+
onSuccess: () => {
426+
disclosure.onClose();
427+
},
428+
},
429+
);
433430

434-
if (!backendWalletBalance) {
435-
return null;
436-
}
431+
toast.promise(promise, {
432+
success: "Successfully sent a request to send funds.",
433+
error: "Failed to send tokens.",
434+
});
435+
};
437436

438437
return (
439438
<Modal isOpen={disclosure.isOpen} onClose={disclosure.onClose} isCentered>
@@ -544,24 +543,18 @@ function DeleteModal({
544543
disclosure: UseDisclosureReturn;
545544
instanceUrl: string;
546545
}) {
547-
const { mutate: deleteBackendWallet } =
548-
useEngineDeleteBackendWallet(instanceUrl);
546+
const deleteBackendWallet = useEngineDeleteBackendWallet(instanceUrl);
549547
const trackEvent = useTrack();
550-
const { onSuccess, onError } = useTxNotifications(
551-
"Successfully deleted backend wallet.",
552-
"Failed to delete backend wallet.",
553-
);
554548

555549
const isLocalWallet =
556550
backendWallet.type === "local" || backendWallet.type === "smart:local";
557551
const [ackDeletion, setAckDeletion] = useState(false);
558552

559553
const onClick = () => {
560-
deleteBackendWallet(
554+
const promise = deleteBackendWallet.mutateAsync(
561555
{ walletAddress: backendWallet.address },
562556
{
563557
onSuccess: () => {
564-
onSuccess();
565558
disclosure.onClose();
566559
trackEvent({
567560
category: "engine",
@@ -571,7 +564,6 @@ function DeleteModal({
571564
});
572565
},
573566
onError: (error) => {
574-
onError(error);
575567
trackEvent({
576568
category: "engine",
577569
action: "delete-backend-wallet",
@@ -582,6 +574,11 @@ function DeleteModal({
582574
},
583575
},
584576
);
577+
578+
toast.promise(promise, {
579+
success: "Successfully deleted backend wallet.",
580+
error: "Failed to delete backend wallet.",
581+
});
585582
};
586583

587584
return (

apps/dashboard/src/app/team/[team_slug]/(team)/~/engine/(instance)/[engineId]/webhooks/components/webhooks-table.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import { createColumnHelper } from "@tanstack/react-table";
2626
import { TWTable } from "components/shared/TWTable";
2727
import { format, formatDistanceToNowStrict } from "date-fns";
2828
import { useTrack } from "hooks/analytics/useTrack";
29-
import { useTxNotifications } from "hooks/useTxNotifications";
3029
import { MailQuestion, TrashIcon } from "lucide-react";
3130
import { useState } from "react";
31+
import { toast } from "sonner";
3232
import { Card, FormLabel, Text } from "tw-components";
3333
import { shortenString } from "utils/usedapp-external";
3434

@@ -182,19 +182,14 @@ function DeleteWebhookModal({
182182
disclosure,
183183
instanceUrl,
184184
}: DeleteWebhookModalProps) {
185-
const { mutate: deleteWebhook } = useEngineDeleteWebhook(instanceUrl);
185+
const deleteWebhook = useEngineDeleteWebhook(instanceUrl);
186186
const trackEvent = useTrack();
187-
const { onSuccess, onError } = useTxNotifications(
188-
"Successfully deleted webhook.",
189-
"Failed to delete webhook.",
190-
);
191187

192188
const onDelete = () => {
193-
deleteWebhook(
189+
const promise = deleteWebhook.mutateAsync(
194190
{ id: webhook.id },
195191
{
196192
onSuccess: () => {
197-
onSuccess();
198193
disclosure.onClose();
199194
trackEvent({
200195
category: "engine",
@@ -204,7 +199,6 @@ function DeleteWebhookModal({
204199
});
205200
},
206201
onError: (error) => {
207-
onError(error);
208202
trackEvent({
209203
category: "engine",
210204
action: "delete-webhook",
@@ -215,6 +209,11 @@ function DeleteWebhookModal({
215209
},
216210
},
217211
);
212+
213+
toast.promise(promise, {
214+
success: "Successfully deleted webhook.",
215+
error: "Failed to delete webhook.",
216+
});
218217
};
219218

220219
return (
@@ -225,7 +224,7 @@ function DeleteWebhookModal({
225224
<ModalCloseButton />
226225
<ModalBody>
227226
<div className="flex flex-col gap-4">
228-
<Text>Are you sure you want to delete this webook?</Text>
227+
<Text>Are you sure you want to delete this webhook?</Text>
229228
<FormControl>
230229
<FormLabel>Name</FormLabel>
231230
<Text>{webhook.name}</Text>

0 commit comments

Comments
 (0)