Skip to content

Commit

Permalink
fix: position loading issue (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rickk137 authored Apr 23, 2024
1 parent 4c47a21 commit 4519e17
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const priceIds = [
'0x39d020f60982ed892abbcd4a06a276a9f9b7bfbce003204c110b6e488f502da3',
'0x5c6c0d2386e3352356c3ab84434fafb5ea067ac2678a38a338c4a69ddc4bdb0c',
'0x5de33a9112c2b700b8d30b8a3402c103578ccfa2765696471cc672bd5cf6ac52',
'0x385f64d993f7b77d8182ed5003d97c60aa3361f3cecfe711544d2d59165e9bdf',
'0x193c739db502aadcef37c2589738b1e37bdb257d58cf1ab3c7ebc8e6df4e3ec0',
];

const priceService = new EvmPriceServiceConnection(offchainMainnetEndpoint);
Expand Down
8 changes: 5 additions & 3 deletions liquidity/lib/useLiquidityPosition/useLiquidityPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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: [
Expand All @@ -105,7 +106,8 @@ export const useLiquidityPosition = ({
!tokenAddress ||
!collateralPriceUpdates ||
!UsdProxy ||
!network
!network ||
!provider
) {
throw Error('useLiquidityPosition should not be enabled');
}
Expand Down Expand Up @@ -144,7 +146,7 @@ export const useLiquidityPosition = ({

return await erc7412Call(
network,
CoreProxy.provider,
provider,
allCalls,
(encoded) => {
if (!Array.isArray(encoded)) throw Error('Expected array ');
Expand Down
9 changes: 6 additions & 3 deletions liquidity/lib/useLiquidityPositions/useLiquidityPositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -39,12 +39,14 @@ function toPairs<T>(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: [
Expand All @@ -65,7 +67,8 @@ export const useLiquidityPositions = ({ accountId }: { accountId?: string }) =>
!CoreProxy ||
!accountId ||
!collateralPriceUpdates ||
!network
!network ||
!provider
) {
throw Error('Query should not be enabled');
}
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 4519e17

Please sign in to comment.