Skip to content

Commit

Permalink
SOV-3535: Show correct values with fixed conversion rate routes (#724)
Browse files Browse the repository at this point in the history
* Show right values with fixed conversion rate routes

* Create tiny-queens-smoke.md
  • Loading branch information
tiltom authored Dec 19, 2023
1 parent 72d4828 commit 272ca28
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-queens-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frontend": patch
---

SOV-3535: Show correct values with fixed conversion rate routes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const FIXED_RATE_ROUTES = ['MyntBasset', 'MyntFixedRate'];

export const FIXED_MYNT_RATE = '0.004723550439442834'; // We need it here as well because ConvertPage slightly rounds maximum price
27 changes: 24 additions & 3 deletions apps/frontend/src/app/5_pages/ConvertPage/ConvertPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { useWeiAmountInput } from '../../../hooks/useWeiAmountInput';
import { translations } from '../../../locales/i18n';
import { removeTrailingZerosFromString } from '../../../utils/helpers';
import { decimalic, fromWei } from '../../../utils/math';
import { FIXED_MYNT_RATE, FIXED_RATE_ROUTES } from './ConvertPage.constants';
import { smartRouter, stableCoins } from './ConvertPage.types';
import { useConversionMaintenance } from './hooks/useConversionMaintenance';
import { useGetMaximumAvailableAmount } from './hooks/useGetMaximumAvailableAmount';
Expand Down Expand Up @@ -159,16 +160,25 @@ const ConvertPage: FC = () => {
[amount, maximumAmountToConvert],
);

const isMyntFixRoute = useMemo(
() => route && route.name === 'MyntFixedRate',
[route],
);

const minimumReceived = useMemo(() => {
if (!quote || !slippageTolerance) {
if (!quote || !slippageTolerance || !route) {
return '';
}

if (FIXED_RATE_ROUTES.includes(route.name)) {
return quote;
}

return Decimal.from(quote)
.mul(100 - Number(slippageTolerance))
.div(100)
.toString();
}, [quote, slippageTolerance]);
}, [quote, route, slippageTolerance]);

const priceToken = useMemo<SupportedTokens>(() => {
if (!destinationToken) {
Expand All @@ -190,12 +200,23 @@ const ConvertPage: FC = () => {
return '';
}

if (isMyntFixRoute) {
return FIXED_MYNT_RATE;
}

if (priceToken === destinationToken) {
return decimalic(minimumReceived).div(amount).toString();
} else {
return decimalic(amount).div(minimumReceived).toString();
}
}, [amount, destinationToken, minimumReceived, priceToken, quote]);
}, [
amount,
destinationToken,
isMyntFixRoute,
minimumReceived,
priceToken,
quote,
]);

useEffect(() => {
(async () => {
Expand Down

0 comments on commit 272ca28

Please sign in to comment.