Skip to content

Commit

Permalink
SOV-2023: Show maximum price (#2527)
Browse files Browse the repository at this point in the history
  • Loading branch information
pietro-maximoff authored May 4, 2023
1 parent f59623e commit 5e9e6cd
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { stringToFixedPrecision } from 'utils/display-text/format';
import { ErrorBadge } from 'app/components/Form/ErrorBadge';
import { discordInvite } from 'utils/classifiers';
import { useMaintenance } from 'app/hooks/useMaintenance';
import { AssetValue } from 'app/components/AssetValue';
import { AssetValueMode } from 'app/components/AssetValue/types';

interface IReviewDialogProps {
isOpen: boolean;
Expand All @@ -25,6 +27,7 @@ interface IReviewDialogProps {
amount: string;
expectedReturn: string;
amountReceived: string;
maximumPrice: string;
}
export const ReviewDialog: React.FC<IReviewDialogProps> = ({
isOpen,
Expand All @@ -35,6 +38,7 @@ export const ReviewDialog: React.FC<IReviewDialogProps> = ({
amount,
expectedReturn,
amountReceived,
maximumPrice,
}) => {
const { t } = useTranslation();
const { checkMaintenance, States } = useMaintenance();
Expand Down Expand Up @@ -74,14 +78,26 @@ export const ReviewDialog: React.FC<IReviewDialogProps> = ({
className="tw-h-10 tw-truncate"
/>
<div className="tw-truncate tw-text-xs tw-font-light tw-tracking-normal tw-flex tw-justify-between tw-mt-1">
<p className="tw-mb-3">
<p className="tw-m-0">
{t(translations.swapTradeForm.minimumReceived)}
</p>
<div className="tw-font-semibold">
{weiToFixed(amountReceived, 6)}{' '}
<AssetRenderer asset={targetToken} />
</div>
</div>

<div className="tw-truncate tw-text-xs tw-font-light tw-tracking-normal tw-flex tw-justify-between tw-mt-1">
<p className="tw-mb-3">{t(translations.swap.maximumPrice)}</p>
<div className="tw-font-semibold">
<AssetValue
value={maximumPrice}
assetString={sourceToken}
mode={AssetValueMode.auto}
maxDecimals={6}
/>
</div>
</div>
</FormGroup>

<TxFeeCalculator
Expand Down
3 changes: 3 additions & 0 deletions src/app/containers/SwapFormContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ export const SwapFormContainer: React.FC = () => {
onClose={() => setDialogOpen(false)}
onChange={setSlippage}
dataActionId="swap-"
maximumPrice={sourceTokenValue}
maximumPriceAsset={sourceToken}
/>

<div className="tw-bg-gray-3 tw-w-full tw-mb-10 tw-overflow-hidden">
Expand Down Expand Up @@ -420,6 +422,7 @@ export const SwapFormContainer: React.FC = () => {
amount={amount}
expectedReturn={rateByPath}
amountReceived={minReturn}
maximumPrice={sourceTokenValue}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { FormGroup } from 'app/components/Form/FormGroup';
import { AssetRenderer } from 'app/components/AssetRenderer';
import { Slider } from 'app/components/Form/Slider';
import { sliderDefaultLabelValues } from 'app/components/Form/Slider/sliderDefaultLabelValues';
import { AssetValue } from 'app/components/AssetValue';
import { AssetValueMode } from 'app/components/AssetValue/types';

interface ISlippageDialogProps {
isOpen: boolean;
Expand All @@ -20,6 +22,8 @@ interface ISlippageDialogProps {
onChange: (value: number) => void;
asset?: Asset;
dataActionId?: string;
maximumPrice?: string;
maximumPriceAsset?: Asset;
}

export const SlippageDialog: React.FC<ISlippageDialogProps> = ({
Expand All @@ -29,6 +33,8 @@ export const SlippageDialog: React.FC<ISlippageDialogProps> = ({
dataActionId,
isOpen,
asset,
maximumPrice,
maximumPriceAsset,
...props
}) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -87,8 +93,22 @@ export const SlippageDialog: React.FC<ISlippageDialogProps> = ({
<AssetRenderer asset={asset || Asset.SOV} />
</>
}
className="tw-mt-5"
className="tw-mb-0 tw-mt-5"
/>

{maximumPrice && maximumPriceAsset && (
<LabelValuePair
label={t(translations.buySovPage.slippageDialog.maximumPrice)}
value={
<AssetValue
value={maximumPrice}
assetString={maximumPriceAsset}
mode={AssetValueMode.auto}
maxDecimals={6}
/>
}
/>
)}
</FormGroup>
</div>
</div>
Expand Down
34 changes: 25 additions & 9 deletions src/app/pages/SpotTradingPage/components/TradeDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface ITradeDialogProps {
duration?: number;
fee?: React.ReactNode;
buttonLoading?: boolean;
maximumSpotPrice?: string;
}

export const TradeDialog: React.FC<ITradeDialogProps> = ({
Expand All @@ -52,6 +53,7 @@ export const TradeDialog: React.FC<ITradeDialogProps> = ({
duration,
fee,
buttonLoading,
maximumSpotPrice,
}) => {
const { t } = useTranslation();
const { connected } = useWalletContext();
Expand Down Expand Up @@ -114,15 +116,29 @@ export const TradeDialog: React.FC<ITradeDialogProps> = ({
}
/>
{orderType === OrderType.MARKET && (
<LabelValuePair
label={t(translations.swap.minimumReceived)}
value={
<>
{weiToNumberFormat(minReturn, 6)}{' '}
<AssetRenderer asset={targetToken} />
</>
}
/>
<>
<LabelValuePair
label={t(translations.swap.minimumReceived)}
value={
<>
{weiToNumberFormat(minReturn, 6)}{' '}
<AssetRenderer asset={targetToken} />
</>
}
/>

{maximumSpotPrice && (
<LabelValuePair
label={t(translations.swap.maximumPrice)}
value={
<>
{weiToNumberFormat(maximumSpotPrice, 6)}{' '}
<AssetRenderer asset={sourceToken} />
</>
}
/>
)}
</>
)}

{orderType === OrderType.LIMIT && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const MarketForm: React.FC<ITradeFormProps> = ({
orderType={OrderType.MARKET}
amount={amount}
minReturn={minReturn}
maximumSpotPrice={maximumSpotPrice}
targetToken={targetToken}
sourceToken={sourceToken}
expectedReturn={weiToFixed(rateByPath, 6)}
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,8 @@
"title": "Advanced Settings",
"tolerance": "Slippage Tolerance:",
"minimumReceived": "Minimum Received",
"minEntryPrice": "Minimum Entry Price"
"minEntryPrice": "Minimum Entry Price",
"maximumPrice": "Maximum Price"
},
"txDialog": {
"pendingUser": {
Expand Down

0 comments on commit 5e9e6cd

Please sign in to comment.