From 16fbd5f26e27213d6f283e62ed9989e3c5943507 Mon Sep 17 00:00:00 2001 From: bry Date: Tue, 10 Sep 2024 14:32:32 -0500 Subject: [PATCH] Refactor walletSignBottomSheet and fix locale string --- src/locales/en.ts | 3 ++- src/solana/WalletSignBottomSheet.tsx | 40 +++++++++------------------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/locales/en.ts b/src/locales/en.ts index f232af94f..66a578c4c 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -1367,7 +1367,7 @@ export default { fetchingSubDaos: 'Fetching SubDaos...', noneFound: 'No Positions Found', closeMessage: 'Close this position?', - flipLockupMesage: + flipLockupMessage: "Your current position of {{amount}} {{symbol}} is {{status}}, please confirm whether you'd like to {{action}} or not?", extendMessage: 'Extend this positions lockup from {{existing}} to {{new}}?', @@ -1415,6 +1415,7 @@ export default { delegatePosition: 'Delegate Position', undelegatePosition: 'Undelegate Tokens', relinquishPosition: 'Relinquish Votes', + flipLockup: 'Flip Lockup', }, errors: { lockTokens: diff --git a/src/solana/WalletSignBottomSheet.tsx b/src/solana/WalletSignBottomSheet.tsx index 15823a9ac..882b5ee13 100644 --- a/src/solana/WalletSignBottomSheet.tsx +++ b/src/solana/WalletSignBottomSheet.tsx @@ -11,9 +11,7 @@ import React, { forwardRef, memo, useCallback, - useEffect, useImperativeHandle, - useMemo, useRef, useState, } from 'react' @@ -27,12 +25,14 @@ import { WalletStandardMessageTypes, } from './walletSignBottomSheetTypes' -let promiseResolve: (value: boolean | PromiseLike) => void const WalletSignBottomSheet = forwardRef( ( { onClose, children }: WalletSignBottomSheetProps, ref: Ref, ) => { + const [promiseResolve, setPromiseResolve] = useState< + ((value: boolean | PromiseLike) => void) | null + >(null) useImperativeHandle(ref, () => ({ show, hide })) const { secondaryText } = useColors() const { backgroundStyle } = useOpacity('surfaceSecondary', 1) @@ -49,26 +49,20 @@ const WalletSignBottomSheet = forwardRef( suppressWarnings: false, }) - const hasRenderer = useMemo( - () => walletSignOpts.renderer !== undefined, - [walletSignOpts], - ) - - useEffect(() => { - bottomSheetModalRef.current?.present() - }, [bottomSheetModalRef]) - + const hasRenderer = walletSignOpts.renderer !== undefined const hide = useCallback(() => { bottomSheetModalRef.current?.close() setSimulated(false) }, []) const show = useCallback((opts: WalletSignOpts) => { + bottomSheetModalRef.current?.present() // Move the present() call here bottomSheetModalRef.current?.expand() setWalletSignOpts(opts) return new Promise((resolve) => { - promiseResolve = resolve + setPromiseResolve(() => resolve) + bottomSheetModalRef.current?.snapToIndex(0) }) }, []) @@ -88,47 +82,39 @@ const WalletSignBottomSheet = forwardRef( if (promiseResolve) { promiseResolve(false) } - // We need to re present the bottom sheet after it is dismissed so that it can be expanded again - bottomSheetModalRef.current?.present() if (onClose) { onClose() } - }, [onClose]) + }, [onClose, promiseResolve]) const onAcceptHandler = useCallback(() => { if (promiseResolve) { hide() promiseResolve(true) } - }, [hide]) + }, [hide, promiseResolve]) const onCancelHandler = useCallback(() => { if (promiseResolve) { hide() promiseResolve(false) } - }, [hide]) + }, [hide, promiseResolve]) return (