Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle light account backup while on FiatPluginEnterAmountScene #5358

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading