diff --git a/src/components/transactions/Supply/SupplyActions.tsx b/src/components/transactions/Supply/SupplyActions.tsx index f522141c1e..897f2fcbfd 100644 --- a/src/components/transactions/Supply/SupplyActions.tsx +++ b/src/components/transactions/Supply/SupplyActions.tsx @@ -19,11 +19,11 @@ import { useWeb3Context } from 'src/libs/hooks/useWeb3Context'; import { useRootStore } from 'src/store/root'; import { ApprovalMethod } from 'src/store/walletSlice'; import { getErrorTextFromError, TxAction } from 'src/ui-config/errorMapping'; -import { queryKeysFactory } from 'src/ui-config/queries'; import { useShallow } from 'zustand/shallow'; import { TxActionsWrapper } from '../TxActionsWrapper'; import { APPROVAL_GAS_LIMIT, checkRequiresApproval } from '../utils'; +import { refetchSupplyPoolData } from './utils'; // Minimal ABI for Pool multicall + setUserEMode + supply const POOL_MULTICALL_ABI = [ @@ -71,6 +71,7 @@ export const SupplyActions = React.memo( estimateGasLimit, addTransaction, currentMarketData, + account, ] = useRootStore( useShallow((state) => [ state.tryPermit, @@ -81,6 +82,7 @@ export const SupplyActions = React.memo( state.estimateGasLimit, state.addTransaction, state.currentMarketData, + state.account, ]) ); const { reserves } = useAppDataContext(); @@ -263,12 +265,6 @@ export const SupplyActions = React.memo( await response.wait(1); } - setMainTxState({ - txHash: response.hash, - loading: false, - success: true, - }); - addTransaction(response.hash, { action, txState: 'success', @@ -283,7 +279,13 @@ export const SupplyActions = React.memo( })(), }); - queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool }); + await refetchSupplyPoolData(queryClient, account, currentMarketData); + + setMainTxState({ + txHash: response.hash, + loading: false, + success: true, + }); } catch (error) { const parsedError = getErrorTextFromError(error, TxAction.GAS_ESTIMATION, false); setTxError(parsedError); diff --git a/src/components/transactions/Supply/SupplyWrappedTokenActions.tsx b/src/components/transactions/Supply/SupplyWrappedTokenActions.tsx index 0e8658c934..9b0fb09423 100644 --- a/src/components/transactions/Supply/SupplyWrappedTokenActions.tsx +++ b/src/components/transactions/Supply/SupplyWrappedTokenActions.tsx @@ -20,6 +20,7 @@ import { useShallow } from 'zustand/shallow'; import { TxActionsWrapper } from '../TxActionsWrapper'; import { APPROVAL_GAS_LIMIT, checkRequiresApproval } from '../utils'; +import { refetchSupplyPoolData } from './utils'; interface SignedParams { signature: SignatureLike; @@ -166,12 +167,6 @@ export const SupplyWrappedTokenActions = ({ await response.wait(1); } - setMainTxState({ - txHash: response.hash, - loading: false, - success: true, - }); - addTransaction(response.hash, { action, txState: 'success', @@ -181,7 +176,7 @@ export const SupplyWrappedTokenActions = ({ amountUsd: valueToBigNumber(amountToSupply).multipliedBy(reserve.priceInUSD).toString(), }); - queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool }); + await refetchSupplyPoolData(queryClient, user, marketData); queryClient.invalidateQueries({ queryKey: queryKeysFactory.approvedAmount( user, @@ -190,6 +185,12 @@ export const SupplyWrappedTokenActions = ({ marketData.chainId ), }); + + setMainTxState({ + txHash: response.hash, + loading: false, + success: true, + }); } catch (error) { const parsedError = getErrorTextFromError(error, TxAction.GAS_ESTIMATION, false); setTxError(parsedError); diff --git a/src/components/transactions/Supply/utils.ts b/src/components/transactions/Supply/utils.ts new file mode 100644 index 0000000000..3d194640a9 --- /dev/null +++ b/src/components/transactions/Supply/utils.ts @@ -0,0 +1,18 @@ +import type { QueryClient } from '@tanstack/react-query'; +import type { MarketDataType } from 'src/ui-config/marketsConfig'; +import { queryKeysFactory } from 'src/ui-config/queries'; + +export const refetchSupplyPoolData = async ( + queryClient: QueryClient, + account: string, + marketData: MarketDataType +) => { + await queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool }); + + if (account) { + await queryClient.refetchQueries({ + queryKey: queryKeysFactory.poolTokens(account, marketData), + type: 'active', + }); + } +};