fix: dont use current value in update callback for estimate queries (#2721)
This commit is contained in:
parent
68446ccf65
commit
a016feab2a
@ -9,26 +9,23 @@ export const useMarketAccountBalance = (marketId: string) => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
const [accountBalance, setAccountBalance] = useState<string>('');
|
||||
const [accountDecimals, setAccountDecimals] = useState<number | null>(null);
|
||||
const variables = useMemo(() => {
|
||||
return { partyId: pubKey || '' };
|
||||
}, [pubKey]);
|
||||
const update = useCallback(
|
||||
({ data }: { data: Account[] | null }) => {
|
||||
const account = getMarketAccount({ accounts: data, marketId });
|
||||
if (accountBalance !== account?.balance) {
|
||||
if (account?.balance) {
|
||||
setAccountBalance(account?.balance || '');
|
||||
}
|
||||
if (accountDecimals !== account?.asset.decimals) {
|
||||
if (account?.asset.decimals) {
|
||||
setAccountDecimals(account?.asset.decimals || null);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
[accountBalance, accountDecimals, marketId]
|
||||
[marketId]
|
||||
);
|
||||
|
||||
useDataProvider({
|
||||
dataProvider: accountsDataProvider,
|
||||
variables,
|
||||
variables: { partyId: pubKey || '' },
|
||||
skip: !pubKey || !marketId,
|
||||
update,
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { useDataProvider } from '@vegaprotocol/react-helpers';
|
||||
import { marginsDataProvider } from './margin-data-provider';
|
||||
@ -22,19 +22,16 @@ const getMarketMarginPosition = ({
|
||||
export const useMarketMargin = (marketId: string) => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
const [marginLevel, setMarginLevel] = useState<string>('');
|
||||
const variables = useMemo(() => {
|
||||
return { partyId: pubKey || '' };
|
||||
}, [pubKey]);
|
||||
|
||||
const update = useCallback(
|
||||
({ data }: { data: MarginsQuery['party'] | null }) => {
|
||||
const marginMarketPosition = getMarketMarginPosition({ data, marketId });
|
||||
if (marginLevel !== marginMarketPosition?.maintenanceLevel) {
|
||||
if (marginMarketPosition?.maintenanceLevel) {
|
||||
setMarginLevel(marginMarketPosition?.maintenanceLevel || '');
|
||||
}
|
||||
return true;
|
||||
},
|
||||
[marginLevel, setMarginLevel, marketId]
|
||||
[setMarginLevel, marketId]
|
||||
);
|
||||
|
||||
useDataProvider<
|
||||
@ -42,7 +39,7 @@ export const useMarketMargin = (marketId: string) => {
|
||||
MarginsSubscriptionSubscription['margins']
|
||||
>({
|
||||
dataProvider: marginsDataProvider,
|
||||
variables,
|
||||
variables: { partyId: pubKey || '' },
|
||||
skip: !pubKey || !marketId,
|
||||
update,
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { positionsDataProvider } from './positions-data-providers';
|
||||
import { useDataProvider } from '@vegaprotocol/react-helpers';
|
||||
@ -22,18 +22,15 @@ const getMarketPosition = ({
|
||||
export const useMarketPositionOpenVolume = (marketId: string) => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
const [openVolume, setOpenVolume] = useState<string>('');
|
||||
const variables = useMemo(() => {
|
||||
return { partyId: pubKey || '' };
|
||||
}, [pubKey]);
|
||||
const update = useCallback(
|
||||
({ data }: { data: PositionsQuery['party'] | undefined }) => {
|
||||
const position = getMarketPosition({ data, marketId });
|
||||
if (openVolume !== position?.openVolume) {
|
||||
if (position?.openVolume) {
|
||||
setOpenVolume(position?.openVolume || '');
|
||||
}
|
||||
return true;
|
||||
},
|
||||
[openVolume, setOpenVolume, marketId]
|
||||
[setOpenVolume, marketId]
|
||||
);
|
||||
|
||||
useDataProvider<
|
||||
@ -41,7 +38,7 @@ export const useMarketPositionOpenVolume = (marketId: string) => {
|
||||
PositionsSubscriptionSubscription['positions']
|
||||
>({
|
||||
dataProvider: positionsDataProvider,
|
||||
variables,
|
||||
variables: { partyId: pubKey || '' },
|
||||
skip: !pubKey || !marketId,
|
||||
update,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user