Skip to content

Commit

Permalink
Handle light account backup while on FiatPluginEnterAmountScene
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-edge committed Nov 19, 2024
1 parent ed5d72a commit d3d4778
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 20 additions & 1 deletion src/plugins/gui/scenes/FiatPluginEnterAmountScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -85,6 +87,9 @@ export const FiatPluginEnterAmountScene = React.memo((props: Props) => {
throw new Error('disableInput must be 1 or 2')
}
const lastUsed = React.useRef<number>(1)
const account = useSelector(state => state.core.account)
const currentUsername = useWatch(account, 'username')
const initUsername = React.useRef<string | undefined>(account.username)

const stateManager = useStateManager<EnterAmountState>({ ...defaultEnterAmountState, ...initState })
const { value1, value2, poweredBy, spinner1, spinner2, statusText } = stateManager.state
Expand All @@ -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 = <Image style={styles.icon} source={{ uri: headerIconUri }} />
Expand Down

0 comments on commit d3d4778

Please sign in to comment.