Skip to content

Commit

Permalink
fix: Use near provider with error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
paouvrard committed Aug 12, 2024
1 parent d978481 commit 7bb1665
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/ethereum-wallets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
25 changes: 17 additions & 8 deletions packages/ethereum-wallets/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface EthereumWalletsParams {
devMode?: boolean;
devModeAccount?: string;
deprecated?: boolean;
nearNodeUrl?: string;
}

interface EthereumWalletsState {
Expand Down Expand Up @@ -103,6 +104,7 @@ const EthereumWallets: WalletBehaviourFactory<
alwaysOnboardDuringSignIn = false,
devMode,
devModeAccount = "eth-wallet.testnet",
nearNodeUrl,
},
}) => {
if (!wagmiCore) {
Expand All @@ -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<Array<Account>> => {
const address = wagmiCore!.getAccount(wagmiConfig).address?.toLowerCase();
Expand Down Expand Up @@ -422,7 +435,7 @@ const EthereumWallets: WalletBehaviourFactory<
throw new Error("Failed to fetch the relayer's public key.");
}
try {
const key = await provider.query<AccessKeyViewRaw>({
const key = await nearProvider.query<AccessKeyViewRaw>({
request_type: "view_access_key",
finality: "final",
account_id: accountId,
Expand Down Expand Up @@ -507,7 +520,7 @@ const EthereumWallets: WalletBehaviourFactory<
if (accountLogIn.publicKey && nearTxs.length) {
let accessKeyUsable;
try {
const accessKey = await provider.query<AccessKeyViewRaw>({
const accessKey = await nearProvider.query<AccessKeyViewRaw>({
request_type: "view_access_key",
finality: "final",
account_id: accountLogIn.accountId,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -713,7 +722,7 @@ const EthereumWallets: WalletBehaviourFactory<
if (accountLogIn.publicKey) {
try {
// Check that the key exists before making a transaction.
await provider.query<AccessKeyViewRaw>({
await nearProvider.query<AccessKeyViewRaw>({
request_type: "view_access_key",
finality: "final",
account_id: accountLogIn.accountId,
Expand Down Expand Up @@ -844,7 +853,7 @@ const EthereumWallets: WalletBehaviourFactory<
let reUseKeyPair = false;
if (keyPair) {
try {
await provider.query<AccessKeyViewRaw>({
await nearProvider.query<AccessKeyViewRaw>({
request_type: "view_access_key",
finality: "final",
account_id: accountId,
Expand Down

0 comments on commit 7bb1665

Please sign in to comment.