Skip to content

Commit

Permalink
Merge pull request #1961 from argentlabs/fix/BLO-892-ff
Browse files Browse the repository at this point in the history
BLO-892 hotfix: ensure sparse account object
  • Loading branch information
simonheys authored Mar 27, 2023
2 parents 3ccadf1 + 05080b5 commit 577723e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/extension/src/ui/services/backgroundAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
WalletAccount,
} from "../../shared/wallet.model"
import { walletStore } from "../../shared/wallet/walletStore"
import { Account } from "../features/accounts/Account"
import { decryptFromBackground, generateEncryptedSecret } from "./crypto"

export const createNewAccount = async (networkId: string) => {
Expand Down Expand Up @@ -48,9 +49,19 @@ export const accountsOnNetwork = (
networkId: string,
) => accounts.filter((account) => account.networkId === networkId)

function isNotBaseWalletAccount(
account?: BaseWalletAccount,
): account is Account {
return Boolean(account && "toBaseWalletAccount" in account)
}

export const selectAccount = async (
account?: BaseWalletAccount,
): Promise<void> => {
/** coerce to sparse BaseWalletAccount to prevent DataCloneError from full Account class instance on FireFox */
if (isNotBaseWalletAccount(account)) {
account = account.toBaseWalletAccount()
}
await walletStore.set("selected", account ?? null)

return connectAccount(account)
Expand Down

0 comments on commit 577723e

Please sign in to comment.