Skip to content

Commit 4c87544

Browse files
committed
requested fixes
1 parent a1d0f2a commit 4c87544

File tree

5 files changed

+53
-31
lines changed

5 files changed

+53
-31
lines changed

src/components/transactions/Switch/BaseSwitchModalContent.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -521,25 +521,15 @@ export const BaseSwitchModalContent = ({
521521

522522
if (modalType !== ModalType.CollateralSwap) {
523523
setIsSwapFlowSelected(true);
524-
} else if (switchRates?.provider === 'cowprotocol' && !ratesLoading) {
525-
if (shouldUseFlashloanValue) {
526-
setShouldUseFlashloan(true);
527-
} else {
528-
setShouldUseFlashloan(false);
529-
setIsSwapFlowSelected(true);
524+
} else if (!ratesLoading && !!switchRates?.provider) {
525+
if (shouldUseFlashloanValue === shouldUseFlashloan) {
526+
return;
530527
}
531-
} else if (
532-
switchRates?.provider === 'paraswap' &&
533-
!ratesLoading &&
534-
shouldUseFlashloan === true
535-
) {
536-
setIsSwapFlowSelected(true);
537-
} else if (switchRates?.provider === 'paraswap' && !ratesLoading) {
538-
// Only paraswap in given chain
528+
539529
setShouldUseFlashloan(shouldUseFlashloanValue);
540530
setIsSwapFlowSelected(true);
541531
}
542-
}, [modalType, switchRates, ratesLoading]);
532+
}, [modalType, switchRates, ratesLoading, shouldUseFlashloan]);
543533

544534
// Define default slippage for CoW
545535
useEffect(() => {

src/components/transactions/Switch/CollateralSwapModal.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import { BaseSwitchModal } from './BaseSwitchModal';
1313
import { SwitchDetailsParams as SwitchDetailsParams } from './BaseSwitchModalContent';
1414
import { SwitchModalTxDetails } from './SwitchModalTxDetails';
1515

16+
export const UNSUPPORTED_A_TOKENS_PER_CHAIN: Record<number, string[]> = {
17+
[SupportedChainId.GNOSIS_CHAIN]: ['0xedbc7449a9b594ca4e053d9737ec5dc4cbccbfb2'.toLowerCase()], // EURe USD Price not supported
18+
};
19+
1620
export const CollateralSwapModal = () => {
1721
const { args } = useModalContext() as ModalContextType<{
1822
underlyingAsset: string;
@@ -92,6 +96,12 @@ export const CollateralSwapModal = () => {
9296
return undefined;
9397
})
9498
.filter((token) => token !== undefined)
99+
.filter(
100+
(token) =>
101+
!UNSUPPORTED_A_TOKENS_PER_CHAIN[currentNetworkConfig.wagmiChain.id]?.includes(
102+
token.aToken.toLowerCase()
103+
)
104+
)
95105
.sort((a, b) => {
96106
const aBalance = parseFloat(a?.balance ?? '0');
97107
const bBalance = parseFloat(b?.balance ?? '0');
@@ -132,6 +142,12 @@ export const CollateralSwapModal = () => {
132142
};
133143
})
134144
.filter((token) => token !== undefined)
145+
.filter(
146+
(token) =>
147+
!UNSUPPORTED_A_TOKENS_PER_CHAIN[currentNetworkConfig.wagmiChain.id]?.includes(
148+
token.aToken.toLowerCase()
149+
)
150+
)
135151
.sort((a, b) => {
136152
const aBalance = parseFloat(a?.balance ?? '0');
137153
const bBalance = parseFloat(b?.balance ?? '0');

src/components/transactions/Switch/SwitchActions.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,6 @@ export const SwitchActions = ({
396396
}, [inputSymbol, chainId, approvedAmount, inputAmount, setShowUSDTResetWarning, switchRates]);
397397

398398
const invalidate = () => {
399-
queryClient.invalidateQueries({
400-
queryKey: queryKeysFactory.poolTokens(user, findByChainId(chainId) ?? currentMarketData),
401-
});
402-
403-
queryClient.invalidateQueries({
404-
queryKey: queryKeysFactory.transactionHistory(
405-
user,
406-
findByChainId(chainId) ?? currentMarketData
407-
),
408-
});
409-
410-
// Refresh dashboard data after collateral swap
411399
queryClient.invalidateQueries({
412400
queryKey: queryKeysFactory.poolReservesDataHumanized(
413401
findByChainId(chainId) ?? currentMarketData
@@ -422,11 +410,15 @@ export const SwitchActions = ({
422410
});
423411

424412
queryClient.invalidateQueries({
425-
queryKey: queryKeysFactory.userPoolReservesIncentiveDataHumanized(
413+
queryKey: queryKeysFactory.transactionHistory(
426414
user,
427415
findByChainId(chainId) ?? currentMarketData
428416
),
429417
});
418+
419+
queryClient.invalidateQueries({
420+
queryKey: queryKeysFactory.poolTokens(user, currentMarketData),
421+
});
430422
};
431423

432424
const action = async () => {
@@ -784,6 +776,8 @@ export const SwitchActions = ({
784776
);
785777
}
786778

779+
invalidate();
780+
787781
try {
788782
const baseTrackingData: Record<string, string | number | undefined> = {
789783
chainId,
@@ -810,8 +804,6 @@ export const SwitchActions = ({
810804
} catch (error) {
811805
console.error('Error tracking swap event:', error);
812806
}
813-
814-
invalidate();
815807
};
816808

817809
const approval = async () => {

src/hooks/useCowOrderToast.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,30 @@ export const CowOrderToastProvider: React.FC<PropsWithChildren> = ({ children })
8888
const newMap = new Map(prev);
8989
newMap.delete(orderId);
9090

91+
queryClient.invalidateQueries({
92+
queryKey: queryKeysFactory.poolReservesDataHumanized(
93+
findByChainId(order.chainId) ?? currentMarketData
94+
),
95+
});
96+
97+
queryClient.invalidateQueries({
98+
queryKey: queryKeysFactory.userPoolReservesDataHumanized(
99+
account,
100+
findByChainId(order.chainId) ?? currentMarketData
101+
),
102+
});
103+
91104
queryClient.invalidateQueries({
92105
queryKey: queryKeysFactory.transactionHistory(
93106
account,
94107
findByChainId(order.chainId) ?? currentMarketData
95108
),
96109
});
97110

111+
queryClient.invalidateQueries({
112+
queryKey: queryKeysFactory.poolTokens(account, currentMarketData),
113+
});
114+
98115
if (newMap.size === 0) {
99116
setHasActiveOrders(false);
100117
}

src/modules/dashboard/lists/SuppliedPositionsList/SuppliedPositionsListItem.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ProtocolAction } from '@aave/contract-helpers';
22
import { Trans } from '@lingui/macro';
33
import { Button } from '@mui/material';
4+
import { UNSUPPORTED_A_TOKENS_PER_CHAIN } from 'src/components/transactions/Switch/CollateralSwapModal';
45
import { useAppDataContext } from 'src/hooks/app-data-provider/useAppDataProvider';
56
import { useAssetCaps } from 'src/hooks/useAssetCaps';
67
import { useModalContext } from 'src/hooks/useModal';
@@ -26,6 +27,7 @@ export const SuppliedPositionsListItem = ({
2627
underlyingAsset,
2728
}: DashboardReserve) => {
2829
const { user } = useAppDataContext();
30+
const currentNetworkConfig = useRootStore((store) => store.currentNetworkConfig);
2931
const { isIsolated, aIncentivesData, aTokenAddress, isFrozen, isActive, isPaused } = reserve;
3032
const { openSupply, openWithdraw, openCollateralChange, openCollateralSwap } = useModalContext();
3133
const { debtCeiling } = useAssetCaps();
@@ -105,7 +107,12 @@ export const SuppliedPositionsListItem = ({
105107
<ListButtonsColumn>
106108
{showSwitchButton ? (
107109
<Button
108-
disabled={disableSwap}
110+
disabled={
111+
disableSwap ||
112+
UNSUPPORTED_A_TOKENS_PER_CHAIN[currentNetworkConfig.wagmiChain.id]?.includes(
113+
aTokenAddress.toLowerCase()
114+
)
115+
}
109116
variant="contained"
110117
onClick={() => {
111118
// track

0 commit comments

Comments
 (0)