Skip to content

Commit 89a5d66

Browse files
committed
feat: update SwapDetails component UI
1 parent 59cdb5f commit 89a5d66

5 files changed

Lines changed: 33 additions & 61 deletions

File tree

apps/evm/src/containers/SwapDetails/index.tsx

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { TertiaryButton, cn } from '@venusprotocol/ui';
22

33
import { Icon, LabeledInlineContent, Modal, TextField, type TextFieldProps } from 'components';
4-
import PLACEHOLDER_KEY from 'constants/placeholderKey';
54
import {
65
DEFAULT_SLIPPAGE_TOLERANCE_PERCENTAGE,
76
HIGH_PRICE_IMPACT_THRESHOLD_PERCENTAGE,
@@ -10,26 +9,20 @@ import { useUserChainSettings } from 'hooks/useUserChainSettings';
109
import { useTranslation } from 'libs/translations';
1110
import { useState } from 'react';
1211
import type { Token } from 'types';
13-
import {
14-
formatPercentageToReadableValue,
15-
formatTokensToReadableValue,
16-
getDecimals,
17-
} from 'utilities';
12+
import { formatPercentageToReadableValue, getDecimals } from 'utilities';
1813

1914
export const slippageToleranceOptions = ['0.1', String(DEFAULT_SLIPPAGE_TOLERANCE_PERCENTAGE), '1'];
2015
const MAX_SLIPPAGE_TOLERANCE_DECIMALS = 2;
2116

2217
export interface SwapDetailsProps extends React.HTMLAttributes<HTMLDivElement> {
2318
fromToken: Token;
2419
toToken: Token;
25-
exchangeRate?: BigNumber;
2620
priceImpactPercentage?: number;
2721
}
2822

2923
export const SwapDetails: React.FC<SwapDetailsProps> = ({
3024
fromToken,
3125
toToken,
32-
exchangeRate,
3326
priceImpactPercentage,
3427
...otherProps
3528
}) => {
@@ -38,12 +31,6 @@ export const SwapDetails: React.FC<SwapDetailsProps> = ({
3831
const [userChainSettings, setUserChainSettings] = useUserChainSettings();
3932
const [isSlippageToleranceModalOpen, setIsSlippageToleranceModalOpen] = useState(false);
4033

41-
const readableExchangeRate = formatTokensToReadableValue({
42-
value: exchangeRate,
43-
token: toToken,
44-
addSymbol: false,
45-
});
46-
4734
const readablePriceImpact = formatPercentageToReadableValue(priceImpactPercentage);
4835

4936
const userSlippageTolerancePercentage = userChainSettings.slippageTolerancePercentage
@@ -80,18 +67,11 @@ export const SwapDetails: React.FC<SwapDetailsProps> = ({
8067

8168
return (
8269
<>
83-
<div className="space-y-2" {...otherProps}>
84-
<LabeledInlineContent label={t('swapDetails.exchangeRate.label')}>
85-
{exchangeRate !== undefined
86-
? t('swapDetails.exchangeRate.value', {
87-
fromTokenSymbol: fromToken.symbol,
88-
toTokenSymbol: toToken.symbol,
89-
rate: readableExchangeRate,
90-
})
91-
: PLACEHOLDER_KEY}
92-
</LabeledInlineContent>
93-
94-
<LabeledInlineContent label={t('swapDetails.slippageTolerance.label')}>
70+
<div className="flex items-center justify-between gap-x-2" {...otherProps}>
71+
<LabeledInlineContent
72+
label={t('swapDetails.slippageTolerance.label')}
73+
className="justify-start space-x-1 w-auto text-sm"
74+
>
9575
<div className="flex items-center justify-center gap-x-1">
9676
{readableUserSlippageTolerance}
9777

@@ -105,7 +85,7 @@ export const SwapDetails: React.FC<SwapDetailsProps> = ({
10585

10686
<LabeledInlineContent
10787
label={t('swapDetails.priceImpact.label')}
108-
tooltip={t('swapDetails.priceImpact.tooltip')}
88+
className="justify-start space-x-1 w-auto text-sm"
10989
>
11090
<span
11191
className={cn(

apps/evm/src/libs/translations/translations/en.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -989,13 +989,8 @@
989989
}
990990
},
991991
"swapDetails": {
992-
"exchangeRate": {
993-
"label": "Exchange rate",
994-
"value": "1 {{fromTokenSymbol}} ≈ {{rate}} {{toTokenSymbol}}"
995-
},
996992
"priceImpact": {
997-
"label": "Price impact",
998-
"tooltip": "Difference between the market price and estimated price due to trade size."
993+
"label": "Price impact"
999994
},
1000995
"slippageTolerance": {
1001996
"label": "Slippage tolerance"
@@ -1538,4 +1533,4 @@
15381533
},
15391534
"withdrawTabTitle": "Withdraw"
15401535
}
1541-
}
1536+
}

apps/evm/src/pages/Market/OperationForm/BoostForm/index.tsx

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import {
77
LabeledInlineContent,
88
type OptionalTokenBalance,
99
RiskAcknowledgementToggle,
10-
SelectTokenTextField,
10+
TokenTextField,
1111
} from 'components';
1212
import { HEALTH_FACTOR_MODERATE_THRESHOLD } from 'constants/healthFactor';
1313
import { ConnectWallet } from 'containers/ConnectWallet';
14+
import { SwapDetails } from 'containers/SwapDetails';
1415
import useDebounceValue from 'hooks/useDebounceValue';
1516
import { useSimulateBalanceMutations } from 'hooks/useSimulateBalanceMutations';
1617
import { useAnalytics } from 'libs/analytics';
@@ -192,11 +193,10 @@ const BoostForm: React.FC<BoostFormProps> = ({ asset: borrowedAsset, pool, onSub
192193
});
193194

194195
// Convert input amount to percentage of limit
195-
const riskSliderValue = new BigNumber(formValues.amountTokens || 0)
196-
.multipliedBy(100)
197-
.div(limitTokens)
198-
.dp(1)
199-
.toNumber();
196+
const riskSliderValue =
197+
limitTokens.isGreaterThan(0) && Number(formValues.amountTokens) > 0
198+
? new BigNumber(formValues.amountTokens).multipliedBy(100).div(limitTokens).dp(1).toNumber()
199+
: 0;
200200

201201
const handleRiskSliderChange = (riskLevelPercentage: number) => {
202202
const amountTokens = limitTokens
@@ -269,20 +269,11 @@ const BoostForm: React.FC<BoostFormProps> = ({ asset: borrowedAsset, pool, onSub
269269
suppliedTokenSymbol={suppliedAsset.vToken.underlyingToken.symbol}
270270
/>
271271

272-
<SelectTokenTextField
273-
data-testid={TEST_IDS.selectTokenTextField}
272+
<TokenTextField
274273
name="amountTokens"
275274
displayTokenIcon
276275
token={borrowedAsset.vToken.underlyingToken}
277-
selectedToken={suppliedAsset.vToken.underlyingToken}
278-
tokenBalances={tokenBalances}
279276
value={formValues.amountTokens}
280-
onChangeSelectedToken={suppliedToken =>
281-
setFormValues(currentFormValues => ({
282-
...currentFormValues,
283-
suppliedToken,
284-
}))
285-
}
286277
onChange={amountTokens => {
287278
captureAmountSetAnalyticEvent({
288279
amountTokens,
@@ -314,7 +305,7 @@ const BoostForm: React.FC<BoostFormProps> = ({ asset: borrowedAsset, pool, onSub
314305
</div>
315306

316307
<ConnectWallet
317-
className={cn('space-y-6', accountAddress ? 'mt-4' : 'mt-6')}
308+
className={cn('space-y-6', accountAddress ? 'mt-2' : 'mt-6')}
318309
// TODO: add analytic variant
319310
>
320311
<div className="space-y-4">
@@ -331,8 +322,6 @@ const BoostForm: React.FC<BoostFormProps> = ({ asset: borrowedAsset, pool, onSub
331322
</button>
332323
</LabeledInlineContent>
333324

334-
{/* TODO: add spending limit */}
335-
336325
<RiskSlider
337326
disabled={isDisabled}
338327
value={riskSliderValue}
@@ -341,6 +330,8 @@ const BoostForm: React.FC<BoostFormProps> = ({ asset: borrowedAsset, pool, onSub
341330

342331
<Delimiter />
343332

333+
{/* TODO: add step to allow Comptroller contract as delegate */}
334+
344335
<OperationDetails
345336
action="borrow"
346337
pool={pool}
@@ -356,13 +347,19 @@ const BoostForm: React.FC<BoostFormProps> = ({ asset: borrowedAsset, pool, onSub
356347
)}
357348
</div>
358349

359-
<SubmitSection
360-
isFormSubmitting={isSubmitting}
361-
isFormValid={isFormValid}
362-
formErrorCode={formError?.code}
363-
/>
350+
<div className="space-y-3">
351+
<SubmitSection
352+
isFormSubmitting={isSubmitting}
353+
isFormValid={isFormValid}
354+
formErrorCode={formError?.code}
355+
/>
364356

365-
{/* TODO: add swap details */}
357+
<SwapDetails
358+
fromToken={borrowedAsset.vToken.underlyingToken}
359+
toToken={suppliedAsset.vToken.underlyingToken}
360+
priceImpactPercentage={swap?.priceImpactPercentage}
361+
/>
362+
</div>
366363
</ConnectWallet>
367364
</form>
368365
);

apps/evm/src/pages/Market/OperationForm/RepayForm/__tests__/__snapshots__/indexIntegratedSwap.spec.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`RepayForm - Feature flag enabled: integratedSwap > displays correct swap details 1`] = `"You will repay≈ 999.999999 XVSExchange rate1 BUSD ≈ 0.003333 XVSSlippage tolerance0.5%Price impact< 0.01%"`;
3+
exports[`RepayForm - Feature flag enabled: integratedSwap > displays correct swap details 1`] = `"You will repay≈ 999.999999 XVSSlippage tolerance0.5%Price impact< 0.01%"`;
44

55
exports[`RepayForm - Feature flag enabled: integratedSwap > displays correct swap details 2`] = `"You will repay 999.999999 XVS using 299.99K BUSD"`;
66

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`SupplyForm - Feature flag enabled: integratedSwap > displays correct swap details 1`] = `"You will supply≈ 8.9K XVSExchange rate1 BUSD ≈ 0.029666 XVSSlippage tolerance0.5%Price impact< 0.01%"`;
3+
exports[`SupplyForm - Feature flag enabled: integratedSwap > displays correct swap details 1`] = `"You will supply≈ 8.9K XVSSlippage tolerance0.5%Price impact< 0.01%"`;
44

55
exports[`SupplyForm - Feature flag enabled: integratedSwap > displays correct swap details 2`] = `"You will supply 8.9K XVS using 299.99K BUSD"`;

0 commit comments

Comments
 (0)