From 4519e179770db5d3abc7649152add964b8b2f140 Mon Sep 17 00:00:00 2001 From: Peiman <25097709+Rickk137@users.noreply.github.com> Date: Tue, 23 Apr 2024 13:24:20 +0330 Subject: [PATCH] fix: position loading issue (#253) --- .../useCollateralPriceUpdates.ts | 2 ++ .../lib/useLiquidityPosition/useLiquidityPosition.ts | 8 +++++--- .../lib/useLiquidityPositions/useLiquidityPositions.ts | 9 ++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/liquidity/lib/useCollateralPriceUpdates/useCollateralPriceUpdates.ts b/liquidity/lib/useCollateralPriceUpdates/useCollateralPriceUpdates.ts index 4c668dcef..80681acc9 100644 --- a/liquidity/lib/useCollateralPriceUpdates/useCollateralPriceUpdates.ts +++ b/liquidity/lib/useCollateralPriceUpdates/useCollateralPriceUpdates.ts @@ -19,6 +19,8 @@ const priceIds = [ '0x39d020f60982ed892abbcd4a06a276a9f9b7bfbce003204c110b6e488f502da3', '0x5c6c0d2386e3352356c3ab84434fafb5ea067ac2678a38a338c4a69ddc4bdb0c', '0x5de33a9112c2b700b8d30b8a3402c103578ccfa2765696471cc672bd5cf6ac52', + '0x385f64d993f7b77d8182ed5003d97c60aa3361f3cecfe711544d2d59165e9bdf', + '0x193c739db502aadcef37c2589738b1e37bdb257d58cf1ab3c7ebc8e6df4e3ec0', ]; const priceService = new EvmPriceServiceConnection(offchainMainnetEndpoint); diff --git a/liquidity/lib/useLiquidityPosition/useLiquidityPosition.ts b/liquidity/lib/useLiquidityPosition/useLiquidityPosition.ts index 09f880c21..ab89702ac 100644 --- a/liquidity/lib/useLiquidityPosition/useLiquidityPosition.ts +++ b/liquidity/lib/useLiquidityPosition/useLiquidityPosition.ts @@ -4,7 +4,7 @@ import { ZodBigNumber } from '@snx-v3/zod'; import Wei, { wei } from '@synthetixio/wei'; import { useQuery } from '@tanstack/react-query'; import { z } from 'zod'; -import { useNetwork } from '@snx-v3/useBlockchain'; +import { useNetwork, useProviderForChain } from '@snx-v3/useBlockchain'; import { erc7412Call } from '@snx-v3/withERC7412'; import { loadPrices } from '@snx-v3/useCollateralPrices'; import { loadAccountCollateral, AccountCollateralType } from '@snx-v3/useAccountCollateral'; @@ -81,6 +81,7 @@ export const useLiquidityPosition = ({ const { data: UsdProxy } = useUSDProxy(); const { network } = useNetwork(); const { data: priceUpdateTx } = useCollateralPriceUpdates(); + const provider = useProviderForChain(network!); return useQuery({ queryKey: [ @@ -105,7 +106,8 @@ export const useLiquidityPosition = ({ !tokenAddress || !collateralPriceUpdates || !UsdProxy || - !network + !network || + !provider ) { throw Error('useLiquidityPosition should not be enabled'); } @@ -144,7 +146,7 @@ export const useLiquidityPosition = ({ return await erc7412Call( network, - CoreProxy.provider, + provider, allCalls, (encoded) => { if (!Array.isArray(encoded)) throw Error('Expected array '); diff --git a/liquidity/lib/useLiquidityPositions/useLiquidityPositions.ts b/liquidity/lib/useLiquidityPositions/useLiquidityPositions.ts index 82a664c91..279769cef 100644 --- a/liquidity/lib/useLiquidityPositions/useLiquidityPositions.ts +++ b/liquidity/lib/useLiquidityPositions/useLiquidityPositions.ts @@ -4,7 +4,7 @@ import { loadPosition } from '@snx-v3/useLiquidityPosition'; import { usePools } from '@snx-v3/usePools'; import Wei, { wei } from '@synthetixio/wei'; import { useQuery } from '@tanstack/react-query'; -import { useNetwork } from '@snx-v3/useBlockchain'; +import { useNetwork, useProviderForChain } from '@snx-v3/useBlockchain'; import { loadPrices } from '@snx-v3/useCollateralPrices'; import { calculateCRatio } from '@snx-v3/calculations'; import { erc7412Call } from '@snx-v3/withERC7412'; @@ -39,12 +39,14 @@ function toPairs(array: T[]): [T, T][] { export const useLiquidityPositions = ({ accountId }: { accountId?: string }) => { const { data: CoreProxy } = useCoreProxy(); + const { data: pools } = usePools(); const { data: collateralTypes } = useCollateralTypes(); const { data: collateralPriceUpdates } = useAllCollateralPriceIds(); const { data: priceUpdateTx } = useCollateralPriceUpdates(); const { network } = useNetwork(); + const provider = useProviderForChain(network!); return useQuery({ queryKey: [ @@ -65,7 +67,8 @@ export const useLiquidityPositions = ({ accountId }: { accountId?: string }) => !CoreProxy || !accountId || !collateralPriceUpdates || - !network + !network || + !provider ) { throw Error('Query should not be enabled'); } @@ -106,7 +109,7 @@ export const useLiquidityPositions = ({ accountId }: { accountId?: string }) => return await erc7412Call( network, - CoreProxy.provider, + provider!, allCalls, (encoded) => { if (!Array.isArray(encoded)) throw Error('Expected array');