@@ -33,7 +33,6 @@ import { type ColumnDef, createColumnHelper } from "@tanstack/react-table";
3333import { ChainIcon } from "components/icons/ChainIcon" ;
3434import { TWTable } from "components/shared/TWTable" ;
3535import { useTrack } from "hooks/analytics/useTrack" ;
36- import { useTxNotifications } from "hooks/useTxNotifications" ;
3736import { EngineBackendWalletOptions } from "lib/engine" ;
3837import { useActiveChainAsDashboardChain } from "lib/v5-adapter" ;
3938import {
@@ -46,8 +45,10 @@ import {
4645import QRCode from "qrcode" ;
4746import { useState } from "react" ;
4847import { useForm } from "react-hook-form" ;
48+ import { toast } from "sonner" ;
4949import { getAddress } from "thirdweb" ;
5050import { shortenAddress } from "thirdweb/utils" ;
51+ import invariant from "tiny-invariant" ;
5152import { FormHelperText , FormLabel , LinkButton , Text } from "tw-components" ;
5253import { 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 (
0 commit comments