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

Prevent importing from mnemonic when offline #2061

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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/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
Loading