Skip to content

Commit

Permalink
Merge pull request #2061 from oasisprotocol/lw/fix-missing-balance
Browse files Browse the repository at this point in the history
Prevent importing from mnemonic when offline
  • Loading branch information
lukaw3d authored Sep 23, 2024
2 parents dd0ad14 + 30013e1 commit 009e151
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions .changelog/2061.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent importing from mnemonic when offline
7 changes: 1 addition & 6 deletions src/app/components/TransactionModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/state/importaccounts/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ function* enumerateAccountsFromMnemonic(action: PayloadAction<string>) {
}
yield* put(importAccountsActions.accountsListed(wallets))
yield* setStep(ImportAccountsStep.Idle)
yield* ensureAllBalancesArePresentOnCurrentPage()
} catch (e: any) {
let payload: ErrorPayload
if (e instanceof WalletError) {
Expand All @@ -130,6 +129,7 @@ function* enumerateAccountsFromMnemonic(action: PayloadAction<string>) {

yield* put(importAccountsActions.operationFailed(payload))
}
yield* ensureAllBalancesArePresentOnCurrentPage()
}

function* fetchBalanceForAccount(account: ImportAccountsListAccount) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/state/transaction/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/app/state/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Wallet>) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/state/wallet/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function* openWalletFromMnemonic({ payload }: PayloadAction<OpenSelectedA
for (const account of accounts) {
yield* call(addWallet, {
address: account.address,
balance: account.balance!,
balance: account.balance!, // should be defined due to ensureAllBalancesArePresentOnCurrentPage
path: account.path,
pathDisplay: account.pathDisplay,
privateKey: account.privateKey,
Expand Down

0 comments on commit 009e151

Please sign in to comment.