diff --git a/dapp/src/components/TransactionModal/ActiveStakingStep/DepositBTCModal.tsx b/dapp/src/components/TransactionModal/ActiveStakingStep/DepositBTCModal.tsx index c24c847b1..627c9ac65 100644 --- a/dapp/src/components/TransactionModal/ActiveStakingStep/DepositBTCModal.tsx +++ b/dapp/src/components/TransactionModal/ActiveStakingStep/DepositBTCModal.tsx @@ -1,4 +1,4 @@ -import React, { useCallback } from "react" +import React, { useCallback, useEffect } from "react" import { useDepositBTCTransaction, useDepositTelemetry, @@ -24,7 +24,8 @@ export default function DepositBTCModal() { const { btcAddress, depositReceipt, stake } = useStakeFlowContext() const depositTelemetry = useDepositTelemetry() - const toast = useToast({ + const { closeToast, showToast } = useToast({ + id: ID_TOAST, render: ({ onClose }) => ( () => closeToast(), [closeToast]) + const onStakeBTCSuccess = useCallback(() => { setStatus(PROCESS_STATUSES.SUCCEEDED) }, [setStatus]) @@ -61,13 +64,7 @@ export default function DepositBTCModal() { }, 10000) }, [setStatus, handleStake]) - const onDepositBTCError = useCallback(() => { - if (!toast.isActive(ID_TOAST)) { - toast({ - id: ID_TOAST, - }) - } - }, [toast]) + const onDepositBTCError = useCallback(showToast, [showToast]) const { sendBitcoinTransaction } = useDepositBTCTransaction( onDepositBTCSuccess, diff --git a/dapp/src/components/TransactionModal/ActiveStakingStep/SignMessageModal.tsx b/dapp/src/components/TransactionModal/ActiveStakingStep/SignMessageModal.tsx index c631b38c7..921e90d0b 100644 --- a/dapp/src/components/TransactionModal/ActiveStakingStep/SignMessageModal.tsx +++ b/dapp/src/components/TransactionModal/ActiveStakingStep/SignMessageModal.tsx @@ -17,7 +17,8 @@ export default function SignMessageModal() { const { goNext, setStatus } = useModalFlowContext() const { signMessage } = useStakeFlowContext() - const toast = useToast({ + const { closeToast, showToast } = useToast({ + id: ID_TOAST, render: ({ onClose }) => ( Please try again. @@ -25,15 +26,7 @@ export default function SignMessageModal() { ), }) - const onError = useCallback(() => { - if (!toast.isActive(ID_TOAST)) { - toast({ - id: ID_TOAST, - }) - } - }, [toast]) - - const handleSignMessage = useExecuteFunction(signMessage, goNext, onError) + const handleSignMessage = useExecuteFunction(signMessage, goNext, showToast) const handleSignMessageWrapper = useCallback(() => { logPromiseFailure(handleSignMessage()) @@ -43,7 +36,7 @@ export default function SignMessageModal() { setStatus(PROCESS_STATUSES.PENDING) }, [setStatus]) - useEffect(() => () => toast.close(ID_TOAST), [toast]) + useEffect(() => () => closeToast(), [closeToast]) return ( & { id: ToastId }) { + const toast = useChakraToast({ position: "top", duration: null, isClosable: true, containerStyle: { my: 1 }, ...props, }) + + const showToast = useCallback(() => { + if (!toast.isActive(id)) { + toast({ + id, + }) + } + }, [id, toast]) + + const closeToast = useCallback(() => toast.close(id), [id, toast]) + + return { toast, showToast, closeToast } } diff --git a/dapp/src/hooks/useWalletToast.tsx b/dapp/src/hooks/useWalletToast.tsx index 98fa60837..086196edd 100644 --- a/dapp/src/hooks/useWalletToast.tsx +++ b/dapp/src/hooks/useWalletToast.tsx @@ -21,7 +21,8 @@ export function useWalletToast( [requestAccount], ) - const toast = useToast({ + const { closeToast, showToast } = useToast({ + id: `${type}-account-toast`, render: ({ onClose }) => ( { - if (!toast.isActive(type)) { - toast({ id: type }) - } - }, [toast, type]) - useEffect(() => { if (isToastClosed) return @@ -64,7 +59,7 @@ export function useWalletToast( useEffect(() => { if (!account || isToastClosed) return - toast.close(type) + closeToast() setIsToastClosed(true) - }, [account, isToastClosed, toast, type]) + }, [account, closeToast, isToastClosed, type]) }