diff --git a/.changelog/2061.bugfix.md b/.changelog/2061.bugfix.md new file mode 100644 index 0000000000..6d5ff6c84c --- /dev/null +++ b/.changelog/2061.bugfix.md @@ -0,0 +1 @@ +Prevent importing from mnemonic when offline diff --git a/src/app/components/TransactionModal/index.tsx b/src/app/components/TransactionModal/index.tsx index 5060e2de66..9fa43be811 100644 --- a/src/app/components/TransactionModal/index.tsx +++ b/src/app/components/TransactionModal/index.tsx @@ -4,7 +4,7 @@ import { selectChainContext } from 'app/state/network/selectors' import { transactionActions } from 'app/state/transaction' import { selectTransaction } from 'app/state/transaction/selectors' import { TransactionStep } from 'app/state/transaction/types' -import { selectAddress, selectBalance } from 'app/state/wallet/selectors' +import { selectAddress } from 'app/state/wallet/selectors' import { Box } from 'grommet/es6/components/Box' import { Button } from 'grommet/es6/components/Button' import { Spinner } from 'grommet/es6/components/Spinner' @@ -45,14 +45,9 @@ export function TransactionModal() { const { t } = useTranslation() const { preview, step } = useSelector(selectTransaction) const walletAddress = useSelector(selectAddress) - const balance = useSelector(selectBalance) const chainContext = useSelector(selectChainContext) const isMobile = useContext(ResponsiveContext) === 'small' - if (!balance) { - throw new Error('No balance found for wallet') - } - const dispatch = useDispatch() const abortTransaction = () => { diff --git a/src/app/state/importaccounts/saga.ts b/src/app/state/importaccounts/saga.ts index 3967256831..c658dde534 100644 --- a/src/app/state/importaccounts/saga.ts +++ b/src/app/state/importaccounts/saga.ts @@ -119,7 +119,6 @@ function* enumerateAccountsFromMnemonic(action: PayloadAction) { } yield* put(importAccountsActions.accountsListed(wallets)) yield* setStep(ImportAccountsStep.Idle) - yield* ensureAllBalancesArePresentOnCurrentPage() } catch (e: any) { let payload: ErrorPayload if (e instanceof WalletError) { @@ -130,6 +129,7 @@ function* enumerateAccountsFromMnemonic(action: PayloadAction) { yield* put(importAccountsActions.operationFailed(payload)) } + yield* ensureAllBalancesArePresentOnCurrentPage() } function* fetchBalanceForAccount(account: ImportAccountsListAccount) { diff --git a/src/app/state/transaction/saga.ts b/src/app/state/transaction/saga.ts index 3723695950..0b8197029e 100644 --- a/src/app/state/transaction/saga.ts +++ b/src/app/state/transaction/saga.ts @@ -323,7 +323,7 @@ function assertValidAddress(address: string) { function* assertSufficientBalance(amount: bigint) { const wallet = yield* select(selectActiveWallet) // If balance is missing, allow this to pass. It's just more likely that transaction will fail after submitting. - if (wallet?.balance.available == null) return + if (wallet?.balance?.available == null) return const balance = BigInt(wallet.balance.available) if (amount > balance) { diff --git a/src/app/state/wallet/index.ts b/src/app/state/wallet/index.ts index 6674b7989d..2c8ddf56be 100644 --- a/src/app/state/wallet/index.ts +++ b/src/app/state/wallet/index.ts @@ -47,8 +47,11 @@ export const walletSlice = createSlice({ // - Refactor redux-state-sync to ignore actions until tab2 receives // synced state. But tab1 needs to listen to actions too, even tho it // never asks for synced state. - if (state.wallets[action.payload.address]?.balance) { - Object.assign(state.wallets[action.payload.address].balance, action.payload.balance) + if (state.wallets[action.payload.address]) { + state.wallets[action.payload.address].balance = { + ...state.wallets[action.payload.address].balance, + ...action.payload.balance, + } } }, walletOpened(state, action: PayloadAction) { diff --git a/src/app/state/wallet/saga.ts b/src/app/state/wallet/saga.ts index 7f82b19c69..86e37726bf 100644 --- a/src/app/state/wallet/saga.ts +++ b/src/app/state/wallet/saga.ts @@ -91,7 +91,7 @@ export function* openWalletFromMnemonic({ payload }: PayloadAction