diff --git a/engine/paima-mw-core/src/wallets/evm.ts b/engine/paima-mw-core/src/wallets/evm.ts index e562b1872..1628bc9f9 100644 --- a/engine/paima-mw-core/src/wallets/evm.ts +++ b/engine/paima-mw-core/src/wallets/evm.ts @@ -48,7 +48,8 @@ async function switchChain(): Promise { decimals: getChainCurrencyDecimals(), }, rpcUrls: [getChainUri()], - blockExplorerUrls: [getChainExplorerUri()], + // blockExplorerUrls: Chain not added with empty string. + blockExplorerUrls: getChainExplorerUri() ? [getChainExplorerUri()] : undefined, }); return await verifyWalletChain(); } catch (addError) { diff --git a/engine/paima-providers/src/errors.ts b/engine/paima-providers/src/errors.ts index f8d83b7cd..d5442810a 100644 --- a/engine/paima-providers/src/errors.ts +++ b/engine/paima-providers/src/errors.ts @@ -17,8 +17,13 @@ export class ProviderNotInitialized extends Error { } } export class ProviderApiError extends Error { - constructor(message?: string) { + public code: number | undefined; + + constructor(message?: string, code?: number) { super(message); this.name = 'ProviderApiError'; + if (code) { + this.code = code; + } } } diff --git a/engine/paima-providers/src/evm.ts b/engine/paima-providers/src/evm.ts index 9978d93ae..62586f86a 100644 --- a/engine/paima-providers/src/evm.ts +++ b/engine/paima-providers/src/evm.ts @@ -161,17 +161,19 @@ export class EvmProvider implements IProvider { const walletChain = await this.conn.api.request({ method: 'eth_chainId' }); return parseInt(walletChain as string, 16) === parseInt(this.gameInfo.gameChainId, 16); } catch (e: any) { - throw new ProviderApiError(`[verifyWalletChain] error: ${e?.message}`); + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + throw new ProviderApiError(`[verifyWalletChain] error: ${e?.message}`, e?.code); } }; addChain = async (newChain: AddEthereumChainParameter): Promise => { try { await this.conn.api.request({ - method: 'eth_chainId', + method: 'wallet_addEthereumChain', params: [newChain], }); } catch (e: any) { - throw new ProviderApiError(`[addChain] error: ${e?.message}`); + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + throw new ProviderApiError(`[addChain] error: ${e?.message}`, e?.code); } }; switchChain = async (hexChainId: string): Promise => { @@ -181,7 +183,8 @@ export class EvmProvider implements IProvider { params: [{ chainId: hexChainId }], }); } catch (e: any) { - throw new ProviderApiError(`[switchChain] error: ${e?.message}`); + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + throw new ProviderApiError(`[switchChain] error: ${e?.message}`, e?.code); } }; sendTransaction = async (tx: Record): Promise => { @@ -199,7 +202,8 @@ export class EvmProvider implements IProvider { } return hash; } catch (e: any) { - throw new ProviderApiError(`[switchChain] error: ${e?.message}`); + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + throw new ProviderApiError(`[switchChain] error: ${e?.message}`, e?.code); } }; } diff --git a/engine/paima-utils/src/config.ts b/engine/paima-utils/src/config.ts index 500ce0f18..c7a048226 100644 --- a/engine/paima-utils/src/config.ts +++ b/engine/paima-utils/src/config.ts @@ -17,7 +17,7 @@ export class ENV { return process.env.CHAIN_URI || ''; } static get CHAIN_NAME(): string { - return process.env.CHAIN_NAME || ''; + return process.env.CHAIN_NAME || 'UNKNOWN_CHAIN_NAME'; } static get CHAIN_ID(): number { return parseInt(process.env.CHAIN_ID || '0', 10); @@ -26,10 +26,10 @@ export class ENV { return process.env.CHAIN_EXPLORER_URI || ''; } static get CHAIN_CURRENCY_NAME(): string { - return process.env.CHAIN_CURRENCY_NAME || ''; + return process.env.CHAIN_CURRENCY_NAME || 'UNKNOWN_CURRENCY_NAME'; } static get CHAIN_CURRENCY_SYMBOL(): string { - return process.env.CHAIN_CURRENCY_SYMBOL || ''; + return process.env.CHAIN_CURRENCY_SYMBOL || 'NONAME'; } static get CHAIN_CURRENCY_DECIMALS(): number { return parseInt(process.env.CHAIN_CURRENCY_DECIMALS || '0', 10);