[Wallet] Fix reloading an account tab redirecting to Accounts (#35774)
This commit is contained in:
@@ -43,6 +43,20 @@ export const useAccountsQuery = () => {
|
||||
return useGetAccountInfosRegistryQuery(undefined, {
|
||||
selectFromResult: (res) => ({
|
||||
isLoading: res.isLoading,
|
||||
// True once the accounts registry has actually been fetched.
|
||||
//
|
||||
// `accounts` can't answer this on its own: it falls back to the empty
|
||||
// entity state when `res.data` is undefined, so `accounts.length === 0`
|
||||
// means either "fetch hasn't finished" or "user has zero accounts" —
|
||||
// indistinguishable.
|
||||
//
|
||||
// `!isLoading` can't answer it either: RTK Query dispatches the fetch
|
||||
// from a useEffect, so on the very first render `isLoading` is still
|
||||
// false even though no data has arrived yet.
|
||||
//
|
||||
// Use `hasData` to gate first-render decisions that depend on
|
||||
// knowing the real account list (e.g. redirecting away on not-found).
|
||||
hasData: res.data !== undefined,
|
||||
accounts: selectAllAccountInfosFromQuery(res),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -194,7 +194,7 @@ export const Account = () => {
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
// queries
|
||||
const { accounts } = useAccountsQuery()
|
||||
const { accounts, hasData: hasAccountsData } = useAccountsQuery()
|
||||
const selectedAccount = React.useMemo(() => {
|
||||
return accounts.find(
|
||||
(account) =>
|
||||
@@ -621,8 +621,11 @@ export const Account = () => {
|
||||
openOrPushRoute(WalletRoutes.FundWalletPageStart)
|
||||
}, [foundMeldBuyToken, openOrPushRoute, selectedAccount])
|
||||
|
||||
// redirect (asset not found)
|
||||
if (!selectedAccount) {
|
||||
// Wait for the accounts to load before deciding the account is missing.
|
||||
if (!hasAccountsData) {
|
||||
return null
|
||||
}
|
||||
return <Redirect to={WalletRoutes.Accounts} />
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user