Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/components/transactions/Supply/SupplyActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -71,6 +71,7 @@ export const SupplyActions = React.memo(
estimateGasLimit,
addTransaction,
currentMarketData,
account,
] = useRootStore(
useShallow((state) => [
state.tryPermit,
Expand All @@ -81,6 +82,7 @@ export const SupplyActions = React.memo(
state.estimateGasLimit,
state.addTransaction,
state.currentMarketData,
state.account,
])
);
const { reserves } = useAppDataContext();
Expand Down Expand Up @@ -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',
Expand All @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions src/components/transactions/Supply/SupplyWrappedTokenActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand All @@ -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,
Expand All @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions src/components/transactions/Supply/utils.ts
Original file line number Diff line number Diff line change
@@ -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',
});
}
};