Skip to content

Commit

Permalink
update: save account state errors in state, instead of emitting error…
Browse files Browse the repository at this point in the history
…s (accountAdder)
  • Loading branch information
PetromirDev committed Nov 12, 2024
1 parent 928a1ff commit c2806cb
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/controllers/accountAdder/accountAdder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export class AccountAdderController extends EventEmitter {

linkedAccountsLoading: boolean = false

networksWithAccountStateError: NetworkId[] = []

#derivedAccounts: DerivedAccount[] = []

#linkedAccounts: { account: AccountWithNetworkMeta; isLinked: boolean }[] = []
Expand Down Expand Up @@ -299,6 +301,7 @@ export class AccountAdderController extends EventEmitter {
this.#derivedAccounts = []
this.#linkedAccounts = []
this.readyToAddAccounts = []
this.networksWithAccountStateError = []
this.readyToAddKeys = { internal: [], external: [] }
this.isInitialized = false
this.isInitializedWithSavedSeed = false
Expand Down Expand Up @@ -476,6 +479,7 @@ export class AccountAdderController extends EventEmitter {
this.#derivedAccounts = []
this.#linkedAccounts = []
this.accountsLoading = true
this.networksWithAccountStateError = []
this.emitUpdate()
try {
this.#derivedAccounts = await this.#deriveAccounts()
Expand Down Expand Up @@ -785,17 +789,9 @@ export class AccountAdderController extends EventEmitter {
network,
accounts.map((acc) => acc.account)
).catch(() => {
const message = `Failed to determine if accounts are used on ${network.name}.`
// Prevents toast spamming
if (this.emittedErrors.find((err) => err.message === message)) return

this.emitError({
level: 'major',
message,
error: new Error(
`accountAdder.#getAccountsUsedOnNetworks: failed to determine if accounts are used on ${network.name}`
)
})
console.error('accountAdder: failed to get account state on ', providerKey)
if (this.networksWithAccountStateError.includes(providerKey)) return
this.networksWithAccountStateError.push(providerKey)
})

if (!accountState) return
Expand Down

0 comments on commit c2806cb

Please sign in to comment.