From 7392a7a392638a6524dec863fbe3fb1e6c6abbeb Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Tue, 14 May 2024 12:41:13 +0200 Subject: [PATCH] make isCel2 check lazy --- packages/cli/src/base.ts | 11 +++++++---- packages/cli/src/commands/network/whitelist.ts | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/base.ts b/packages/cli/src/base.ts index 3b8745904..6feda9613 100644 --- a/packages/cli/src/base.ts +++ b/packages/cli/src/base.ts @@ -95,7 +95,7 @@ export abstract class BaseCommand extends Command { private _kit: ContractKit | null = null // Indicates if celocli running in L2 context - private cel2: boolean = false + private cel2: boolean | null = null async getWeb3() { if (!this._web3) { @@ -198,11 +198,10 @@ export abstract class BaseCommand extends Command { kit.defaultAccount = res.flags.from } - this.cel2 = await isCel2(await this.getWeb3()) const gasCurrencyFlag = res.flags.gasCurrency as StrongAddress | undefined if (gasCurrencyFlag) { - const feeCurrencyContract = await getFeeCurrencyContractWrapper(kit, this.isCel2()) + const feeCurrencyContract = await getFeeCurrencyContractWrapper(kit, await this.isCel2()) const validFeeCurrencies = await feeCurrencyContract.getAddresses() if ( @@ -242,7 +241,11 @@ export abstract class BaseCommand extends Command { return super.finally(arg) } - protected isCel2() { + protected async isCel2() { + if (this.cel2 === null) { + this.cel2 = await isCel2(await this.getWeb3()) + } + return this.cel2 } } diff --git a/packages/cli/src/commands/network/whitelist.ts b/packages/cli/src/commands/network/whitelist.ts index 6b9d0d651..2c1f77732 100644 --- a/packages/cli/src/commands/network/whitelist.ts +++ b/packages/cli/src/commands/network/whitelist.ts @@ -14,7 +14,7 @@ export default class Whitelist extends BaseCommand { async run() { const kit = await this.getKit() - const feeCurrencyContract = await getFeeCurrencyContractWrapper(kit, this.isCel2()) + const feeCurrencyContract = await getFeeCurrencyContractWrapper(kit, await this.isCel2()) const validFeeCurrencies = await feeCurrencyContract.getAddresses() const pairs = (await feeCurrencyContract.getFeeCurrencyInformation(validFeeCurrencies)).map(