Skip to content

Commit

Permalink
Rename methods for useToast
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosiorowska committed Apr 8, 2024
1 parent 1107ecf commit 07b035f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function DepositBTCModal() {
const { setStatus } = useModalFlowContext()
const { btcAddress, depositReceipt, stake } = useStakeFlowContext()
const depositTelemetry = useDepositTelemetry()
const { close: closeToast, open: openToast } = useToast()
const { closeToast, openToast } = useToast()

const [isLoading, setIsLoading] = useState(false)
const [buttonText, setButtonText] = useState("Deposit BTC")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function SignMessageModal() {
const { goNext, setStatus } = useModalFlowContext()
const { signMessage } = useStakeFlowContext()
const [buttonText, setButtonText] = useState("Sign now")
const { close: closeToast, open: openToast } = useToast()
const { closeToast, openToast } = useToast()

useEffect(() => {
setStatus(PROCESS_STATUSES.PENDING)
Expand Down
10 changes: 5 additions & 5 deletions dapp/src/hooks/toasts/useShowWalletErrorToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function useShowWalletErrorToast(
const {
[type]: { account, requestAccount },
} = useWallet()
const { close, open } = useToast()
const { closeToast, openToast } = useToast()

const toastId = WALLET_ERROR_TOAST_ID[type]

Expand All @@ -26,7 +26,7 @@ export function useShowWalletErrorToast(

const handleOpen = useCallback(
() =>
open({
openToast({
id: toastId,
render: ({ onClose }) =>
WalletErrorToast({
Expand All @@ -35,14 +35,14 @@ export function useShowWalletErrorToast(
onClick: handleConnect,
}),
}),
[handleConnect, open, toastId, type],
[handleConnect, openToast, toastId, type],
)

useTimeout(handleOpen, delay)

useEffect(() => {
if (!account) return

close(toastId)
}, [account, close, toastId])
closeToast(toastId)
}, [account, closeToast, toastId])
}
17 changes: 9 additions & 8 deletions dapp/src/hooks/toasts/useToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function useToast() {
[toast],
)

const open = useCallback(
const openToast = useCallback(
({ id, ...options }: UseToastOptions) => {
if (!id) {
overriddenToast(options)
Expand All @@ -30,11 +30,12 @@ export function useToast() {
[overriddenToast, toast],
)

return useMemo(
() => ({
...Object.assign(overriddenToast, toast),
open,
}),
[overriddenToast, toast, open],
)
return useMemo(() => {
const { close: closeToast, ...rest } = Object.assign(overriddenToast, toast)
return {
...rest,
openToast,
closeToast,
}
}, [overriddenToast, toast, openToast])
}

0 comments on commit 07b035f

Please sign in to comment.