Skip to content

Commit

Permalink
Merge pull request #1088 from AmbireTech/update/account-adder-account…
Browse files Browse the repository at this point in the history
…-state-error

Update/ Save account state errors in state, instead of emitting error in the accountAdder
  • Loading branch information
PetromirDev authored Nov 12, 2024
2 parents 928a1ff + c2806cb commit dac39e1
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 dac39e1

Please sign in to comment.