Skip to content

Commit

Permalink
fix: update chain should also wrap query in try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
jurevans committed Feb 8, 2024
1 parent 81eba4d commit 374abd8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions apps/extension/src/background/chains/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class ChainsService {
const nativeToken = await query.query_native_token();
defaultChain.currency.address = nativeToken || tokenAddress;
} catch (e) {
console.warn(`Chain is not reachable: ${e}`);
console.warn(`Chain is unreachable: ${e}`);
}
}

Expand All @@ -46,15 +46,17 @@ export class ChainsService {
if (!chain) {
throw new Error("No chain found!");
}
let {
currency: { address },
} = chain;

// If query fails, leave address undefined so it will be caught when chain is available
let address: string | undefined;

// Attempt to fetch native token, fallback to env
if (!address) {
try {
const query = new Query(chain.rpc);
const nativeToken = await query.query_native_token();
address = nativeToken || tokenAddress;
} catch (e) {
console.warn(`Chain is unreachable: ${e}`);
}

await this.chainsStore.set(CHAINS_KEY, {
Expand Down

0 comments on commit 374abd8

Please sign in to comment.