diff --git a/packages/ethereum-wallets/README.md b/packages/ethereum-wallets/README.md index b0f1b570b..93e3b33ba 100644 --- a/packages/ethereum-wallets/README.md +++ b/packages/ethereum-wallets/README.md @@ -79,6 +79,7 @@ Project ID is required, please obtain it from [walletconnect.com](https://wallet - `iconUrl` (`string?`): Image URL for the icon shown in the modal. This can also be a relative path or base64 encoded image. Defaults to `./assets/ethereum-wallets-icon.png`. - `wagmiCore` (`typeof import("@wagmi/core")?`): Optional, @wagmi/core functions can be overidden by the dapp to interract with the wallet. - `alwaysOnboardDuringSignIn` (`boolean?`): A dapp without SignIn access key will not onboard the relayer by default, this option does the relayer onboarding during login. +- `nearNodeUrl` (`string?`): NEAR node url to query the NEAR transaction status and onboarding access key. Developent options (before the NEAR protocol upgrade to support 0x accounts natively): diff --git a/packages/ethereum-wallets/src/lib/index.ts b/packages/ethereum-wallets/src/lib/index.ts index 3f40b2aa6..05f72dd71 100644 --- a/packages/ethereum-wallets/src/lib/index.ts +++ b/packages/ethereum-wallets/src/lib/index.ts @@ -64,6 +64,7 @@ export interface EthereumWalletsParams { devMode?: boolean; devModeAccount?: string; deprecated?: boolean; + nearNodeUrl?: string; } interface EthereumWalletsState { @@ -103,6 +104,7 @@ const EthereumWallets: WalletBehaviourFactory< alwaysOnboardDuringSignIn = false, devMode, devModeAccount = "eth-wallet.testnet", + nearNodeUrl, }, }) => { if (!wagmiCore) { @@ -123,6 +125,17 @@ const EthereumWallets: WalletBehaviourFactory< if (!nearExplorer) { throw new Error("Failed to parse NEAR explorer url from wagmiConfig."); } + // NOTE: use a custom provider because the failover provider doesn't give error details. + const nearProvider = new JsonRpcProvider( + nearNodeUrl ?? + // @ts-expect-error + provider.provider.connection ?? + // @ts-expect-error + provider.provider.providers[ + // @ts-expect-error + provider.provider.currentProviderIndex + ].connection + ); const getAccounts = async (): Promise> => { const address = wagmiCore!.getAccount(wagmiConfig).address?.toLowerCase(); @@ -422,7 +435,7 @@ const EthereumWallets: WalletBehaviourFactory< throw new Error("Failed to fetch the relayer's public key."); } try { - const key = await provider.query({ + const key = await nearProvider.query({ request_type: "view_access_key", finality: "final", account_id: accountId, @@ -507,7 +520,7 @@ const EthereumWallets: WalletBehaviourFactory< if (accountLogIn.publicKey && nearTxs.length) { let accessKeyUsable; try { - const accessKey = await provider.query({ + const accessKey = await nearProvider.query({ request_type: "view_access_key", finality: "final", account_id: accountLogIn.accountId, @@ -653,10 +666,6 @@ const EthereumWallets: WalletBehaviourFactory< } } logger.log("Receipt:", receipt); - const nearProvider = new JsonRpcProvider( - // @ts-expect-error - provider.provider.connection - ); let nearTx; while (!nearTx) { try { @@ -713,7 +722,7 @@ const EthereumWallets: WalletBehaviourFactory< if (accountLogIn.publicKey) { try { // Check that the key exists before making a transaction. - await provider.query({ + await nearProvider.query({ request_type: "view_access_key", finality: "final", account_id: accountLogIn.accountId, @@ -844,7 +853,7 @@ const EthereumWallets: WalletBehaviourFactory< let reUseKeyPair = false; if (keyPair) { try { - await provider.query({ + await nearProvider.query({ request_type: "view_access_key", finality: "final", account_id: accountId,