From d3d47788ab588bb922d5d278d22afd3ab1176ad1 Mon Sep 17 00:00:00 2001 From: Jon Tzeng Date: Wed, 13 Nov 2024 17:02:17 -0800 Subject: [PATCH] Handle light account backup while on `FiatPluginEnterAmountScene` --- CHANGELOG.md | 1 + .../gui/scenes/FiatPluginEnterAmountScene.tsx | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dd8bea5404..a5823cb9a84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - added: Close button (X) for `EdgeModals,` specifically if a desktop platform is detected. - changed: Auto-enable required tokens when navigating to `Stake*` scenes - fixed: Incorrect `SwapInput` amounts on `SwapCreateScene` after changing wallet. +- fixed: Backing up a light account while on the `FiatPluginEnterAmountScene` retains light account-related quote errors - fixed: Various `EarnScene` display bugs - fixed: `EarnScene` missing wallet creation option in "Discover" view diff --git a/src/plugins/gui/scenes/FiatPluginEnterAmountScene.tsx b/src/plugins/gui/scenes/FiatPluginEnterAmountScene.tsx index 2958f9eb684..594fae1a4e1 100644 --- a/src/plugins/gui/scenes/FiatPluginEnterAmountScene.tsx +++ b/src/plugins/gui/scenes/FiatPluginEnterAmountScene.tsx @@ -13,7 +13,9 @@ import { FilledTextInput } from '../../../components/themed/FilledTextInput' import { MainButton } from '../../../components/themed/MainButton' import { SceneHeader } from '../../../components/themed/SceneHeader' import { useHandler } from '../../../hooks/useHandler' +import { useWatch } from '../../../hooks/useWatch' import { lstrings } from '../../../locales/strings' +import { useSelector } from '../../../types/reactRedux' import { BuyTabSceneProps } from '../../../types/routerTypes' import { getPartnerIconUri } from '../../../util/CdnUris' import { FiatPluginEnterAmountResponse } from '../fiatPluginTypes' @@ -66,7 +68,7 @@ const defaultEnterAmountState: EnterAmountState = { export const FiatPluginEnterAmountScene = React.memo((props: Props) => { const theme = useTheme() const styles = getStyles(theme) - const { route } = props + const { route, navigation } = props const { disableInput, initState, @@ -85,6 +87,9 @@ export const FiatPluginEnterAmountScene = React.memo((props: Props) => { throw new Error('disableInput must be 1 or 2') } const lastUsed = React.useRef(1) + const account = useSelector(state => state.core.account) + const currentUsername = useWatch(account, 'username') + const initUsername = React.useRef(account.username) const stateManager = useStateManager({ ...defaultEnterAmountState, ...initState }) const { value1, value2, poweredBy, spinner1, spinner2, statusText } = stateManager.state @@ -102,6 +107,20 @@ export const FiatPluginEnterAmountScene = React.memo((props: Props) => { } }, [initState?.value1, convertValue, stateManager]) + // Handle light account backups initiated from this scene + useEffect(() => { + if (initUsername.current !== currentUsername) { + // TODO: Doesn't seem to be a straightforward way to update the stale + // fiat plugin with the new username state, so just go back to the + // `GuiPluginListScene` after upgrading. Ideally we somehow + // re-initialize the plugin and automatically end up back on this + // scene... + // For now, simply go back to the `GuiPluginListScene`. + navigation.goBack() + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [currentUsername]) + let headerIcon = null if (headerIconUri != null) { headerIcon =