Skip to content

Commit 5565536

Browse files
committed
fixes
1 parent c39477a commit 5565536

File tree

11 files changed

+53
-38
lines changed

11 files changed

+53
-38
lines changed

src/components/transactions/FlowCommons/TxModalDetails.tsx

+13-9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface TxModalDetailsProps {
2525
disabled?: boolean;
2626
chainId?: number;
2727
children?: ReactNode;
28+
showGasStation?: boolean;
2829
}
2930

3031
const ArrowRightIcon = (
@@ -40,6 +41,7 @@ export const TxModalDetails: React.FC<TxModalDetailsProps> = ({
4041
disabled,
4142
children,
4243
chainId,
44+
showGasStation = true,
4345
}) => {
4446
return (
4547
<Box sx={{ pt: 5 }}>
@@ -59,15 +61,17 @@ export const TxModalDetails: React.FC<TxModalDetailsProps> = ({
5961
>
6062
{children}
6163
</Box>
62-
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
63-
<GasStation
64-
chainId={chainId}
65-
gasLimit={parseUnits(gasLimit || '0', 'wei')}
66-
skipLoad={skipLoad}
67-
disabled={disabled}
68-
rightComponent={slippageSelector}
69-
/>
70-
</Box>
64+
{showGasStation && (
65+
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
66+
<GasStation
67+
chainId={chainId}
68+
gasLimit={parseUnits(gasLimit || '0', 'wei')}
69+
skipLoad={skipLoad}
70+
disabled={disabled}
71+
rightComponent={slippageSelector}
72+
/>
73+
</Box>
74+
)}
7175
</Box>
7276
);
7377
};

src/components/transactions/GasStation/GasStation.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { API_ETH_MOCK_ADDRESS } from '@aave/contract-helpers';
22
import { normalize } from '@aave/math-utils';
3-
import { Trans } from '@lingui/macro';
43
import LocalGasStationIcon from '@mui/icons-material/LocalGasStation';
5-
import { Box, CircularProgress, Stack, Typography } from '@mui/material';
4+
import { Box, CircularProgress, Stack } from '@mui/material';
65
import { BigNumber } from 'ethers/lib/ethers';
76
import { formatUnits, parseUnits } from 'ethers/lib/utils';
87
import React, { ReactNode } from 'react';
@@ -103,9 +102,7 @@ export const GasStation: React.FC<GasStationProps> = ({
103102
<GasTooltip />
104103
</>
105104
) : (
106-
<Typography variant="caption" color="text.secondary">
107-
<Trans>This action does not require gas.</Trans>
108-
</Typography>
105+
'-'
109106
)}
110107
</Box>
111108
{rightComponent}

src/components/transactions/Switch/BaseSwitchModalContent.tsx

+25-8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface SwitchModalCustomizableProps {
5454
switchProvider,
5555
ratesLoading,
5656
ratesError,
57+
showGasStation,
5758
}: {
5859
user: string;
5960
switchRates: SwitchRatesType;
@@ -66,6 +67,7 @@ export interface SwitchModalCustomizableProps {
6667
switchProvider?: SwitchProvider;
6768
ratesLoading: boolean;
6869
ratesError: Error | null;
70+
showGasStation?: boolean;
6971
}) => React.ReactNode;
7072
inputBalanceTitle?: string;
7173
outputBalanceTitle?: string;
@@ -116,6 +118,8 @@ export const BaseSwitchModalContent = ({
116118
});
117119
const switchProvider = useSwitchProvider({ chainId: selectedChainId });
118120

121+
const [showGasStation, setShowGasStation] = useState(switchProvider == 'paraswap');
122+
119123
const [cowOpenOrdersTotalAmountFormatted, setCowOpenOrdersTotalAmountFormatted] = useState<
120124
string | undefined
121125
>(undefined);
@@ -274,6 +278,17 @@ export const BaseSwitchModalContent = ({
274278
}
275279
}, [switchRates, switchProvider]);
276280

281+
const [showSlippageWarning, setShowSlippageWarning] = useState(false);
282+
useEffect(() => {
283+
// Debounce to avoid race condition
284+
const timeout = setTimeout(() => {
285+
setShowSlippageWarning(
286+
isCowProtocolRates(switchRates) && Number(slippage) < switchRates?.suggestedSlippage
287+
);
288+
}, 500);
289+
return () => clearTimeout(timeout);
290+
}, [slippage, switchRates]);
291+
277292
// Success View
278293
if (switchRates && switchTxState.success) {
279294
return (
@@ -311,6 +326,7 @@ export const BaseSwitchModalContent = ({
311326
maxSlippage: Number(slippage),
312327
ratesLoading,
313328
ratesError,
329+
showGasStation,
314330
})
315331
: null;
316332

@@ -449,14 +465,14 @@ export const BaseSwitchModalContent = ({
449465
)}
450466

451467
{swapDetailsComponent}
452-
{isCowProtocolRates(switchRates) &&
453-
Number(slippage) < switchRates?.suggestedSlippage && (
454-
<Warning severity="warning" icon={false} sx={{ mt: 5 }}>
455-
<Typography variant="caption">
456-
The slippage is below suggested. It may take longer or fail.
457-
</Typography>
458-
</Warning>
459-
)}
468+
469+
{showSlippageWarning && (
470+
<Warning severity="warning" icon={false} sx={{ mt: 5 }}>
471+
<Typography variant="caption">
472+
The slippage is below suggested. It may take longer or fail.
473+
</Typography>
474+
</Warning>
475+
)}
460476

461477
<SwitchErrors
462478
ratesError={ratesError}
@@ -473,6 +489,7 @@ export const BaseSwitchModalContent = ({
473489
inputName={selectedInputToken.name}
474490
outputName={selectedOutputToken.name}
475491
slippage={safeSlippage.toString()}
492+
setShowGasStation={setShowGasStation}
476493
blocked={
477494
!switchRates ||
478495
Number(debounceInputAmount) > Number(selectedInputToken.balance) ||

src/components/transactions/Switch/SwitchActions.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface SwitchProps {
4545
switchRates?: SwitchRatesType;
4646
inputName: string;
4747
outputName: string;
48+
setShowGasStation: (showGasStation: boolean) => void;
4849
}
4950

5051
interface SignedParams {
@@ -66,6 +67,7 @@ export const SwitchActions = ({
6667
isWrongNetwork,
6768
chainId,
6869
switchRates,
70+
setShowGasStation,
6971
}: SwitchProps) => {
7072
const [
7173
user,
@@ -122,6 +124,10 @@ export const SwitchActions = ({
122124
else return approvedAmount < Number(inputAmount);
123125
}, [approvedAmount, inputAmount, isWrongNetwork]);
124126

127+
useEffect(() => {
128+
setShowGasStation(requiresApproval);
129+
}, [requiresApproval, setShowGasStation]);
130+
125131
const action = async () => {
126132
setMainTxState({ ...mainTxState, loading: true });
127133
if (isParaswapRates(switchRates)) {

src/components/transactions/Switch/SwitchModal.tsx

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,22 @@ import { ModalType } from 'src/hooks/useModal';
77
import { TxModalDetails } from '../FlowCommons/TxModalDetails';
88
import { BaseSwitchModal } from './BaseSwitchModal';
99
import { SwitchDetailsParams as SwitchDetailsParams } from './BaseSwitchModalContent';
10-
import { isNativeToken } from './cowprotocol.helpers';
1110

1211
export const SwitchModal = () => {
1312
const switchDetails = ({
1413
user,
1514
switchRates,
1615
gasLimit,
1716
selectedChainId,
18-
selectedInputToken,
1917
selectedOutputToken,
2018
safeSlippage,
21-
switchProvider,
19+
showGasStation,
2220
}: SwitchDetailsParams) => {
23-
const requiresGas =
24-
switchProvider !== 'cowprotocol' || isNativeToken(selectedInputToken.address);
25-
2621
const usdValue = Number(switchRates.destUSD) * (1 - safeSlippage);
2722
const maxFee = Number(switchRates.srcUSD) - usdValue;
2823

2924
return switchRates && user ? (
30-
<TxModalDetails gasLimit={requiresGas ? gasLimit : undefined} chainId={selectedChainId}>
25+
<TxModalDetails gasLimit={gasLimit} chainId={selectedChainId} showGasStation={showGasStation}>
3126
<Row
3227
caption={<Trans>{`Minimum ${selectedOutputToken.symbol} received`}</Trans>}
3328
captionVariant="caption"

src/components/transactions/Switch/cowprotocol.errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const MESSAGE_MAP: { [key: string]: string } = {
22
NoLiquidity: 'No liquidity found for the given amount and asset pair.',
33
NoRoutesFound: 'No routes found with enough liquidity.',
4-
SellAmountDoesNotCoverFee: 'Amount does not cover fee.',
4+
SellAmountDoesNotCoverFee: 'Sell amount is too small to cover the fee.',
55
};
66

77
const MESSAGE_REGEX_MAP: Array<{ regex: RegExp; message: string }> = [

src/locales/el/messages.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/en/messages.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/en/messages.po

-4
Original file line numberDiff line numberDiff line change
@@ -2609,10 +2609,6 @@ msgstr "We couldn't find any transactions related to your search. Try again with
26092609
msgid "English"
26102610
msgstr "English"
26112611

2612-
#: src/components/transactions/GasStation/GasStation.tsx
2613-
msgid "This action does not require gas."
2614-
msgstr "This action does not require gas."
2615-
26162612
#: src/components/isolationMode/IsolatedBadge.tsx
26172613
msgid "Learn more in our <0>FAQ guide</0>"
26182614
msgstr "Learn more in our <0>FAQ guide</0>"

src/locales/es/messages.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/fr/messages.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)