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:
		
							parent
							
								
									c4b93e771a
								
							
						
					
					
						commit
						7e76cb79d1
					
				| @ -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] }; | ||||
|         }), | ||||
|       ); | ||||
| 
 | ||||
|  | ||||
| @ -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, | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user