fix(api): use /account-balance endpoint instead of /account-assets

There seems to be a weird race condition on the `/account-assets`
endpoint when handling two different requests for the same chainId.

Reproduction:
https://codesandbox.io/s/ethereum-api-race-condition-repro-f24x4t?file=/src/index.js
This commit is contained in:
Ben Kremer 2022-02-21 17:49:32 +01:00
parent c4b93e771a
commit 7e76cb79d1
2 changed files with 12 additions and 3 deletions

View File

@ -18,7 +18,7 @@ import {
DEFAULT_PROJECT_ID,
DEFAULT_RELAY_URL,
} from "../constants";
import { AccountBalances, apiGetAccountAssets } from "../helpers";
import { AccountBalances, apiGetAccountBalance } from "../helpers";
import { ERROR, getAppMetadata } from "@walletconnect/utils";
/**
@ -73,8 +73,8 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
_accounts.map(async account => {
const [namespace, reference, address] = account.split(":");
const chainId = `${namespace}:${reference}`;
const assets = await apiGetAccountAssets(address, chainId);
return { account, assets };
const assets = await apiGetAccountBalance(address, chainId);
return { account, assets: [assets] };
}),
);

View File

@ -19,6 +19,15 @@ export async function apiGetAccountAssets(address: string, chainId: string): Pro
return result;
}
export async function apiGetAccountBalance(address: string, chainId: string): Promise<AssetData> {
const ethChainId = chainId.split(":")[1];
const response = await ethereumApi.get(
`/account-balance?address=${address}&chainId=${ethChainId}`,
);
const { result } = response.data;
return result;
}
export async function apiGetAccountTransactions(
address: string,
chainId: string,