Skip to content

Commit

Permalink
[NO CHANGELOG] [Add Tokens Widget] Fix add funds price formatting (#2365
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mimi-imtbl authored Nov 4, 2024
1 parent fe5f852 commit 856426e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function FeesBreakdown({
loading = false,
}: FeesBreakdownProps) {
const { t } = useTranslation();

return (
<Drawer
headerBarTitle={t('drawers.feesBreakdown.heading')}
Expand Down
3 changes: 3 additions & 0 deletions packages/checkout/widgets-lib/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@
"geoBlockError": {
"buyTokenButton": "Buy tokens",
"bridgeTokenButton": "Bridge tokens"
},
"fees": {
"fiatPricePrefix": "≈ USD"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RouteResponse } from '@0xsquid/squid-types';

import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { FeesBreakdown } from '../../../components/FeesBreakdown/FeesBreakdown';
import { FormattedFee } from '../../swap/functions/swapFees';
import {
Expand All @@ -23,11 +24,13 @@ export function RouteFees({
totalAmount,
totalFiatAmount,
}: RouteFeesProps) {
const { t } = useTranslation();

const feeCosts = useMemo<FormattedFee[]>(
() => routeData?.route.estimate.feeCosts.map((fee) => ({
label: fee.name,
amount: getFormattedNumber(fee.amount, fee.token.decimals),
fiatAmount: `USD ≈ ${getFormattedAmounts(fee.amountUsd)}`,
fiatAmount: `${t('views.ADD_TOKENS.fees.fiatPricePrefix')}${getFormattedAmounts(fee.amountUsd)}`,
token: {
name: fee.token.name,
symbol: fee.token.symbol,
Expand All @@ -44,7 +47,7 @@ export function RouteFees({
() => routeData?.route.estimate.gasCosts.map((fee) => ({
label: 'Gas (transaction)',
amount: getFormattedNumber(fee.amount, fee.token.decimals),
fiatAmount: `USD ≈ ${getFormattedAmounts(fee.amountUsd)}`,
fiatAmount: `${t('views.ADD_TOKENS.fees.fiatPricePrefix')}${getFormattedAmounts(fee.amountUsd)}`,
token: {
name: fee.token.name,
symbol: fee.token.symbol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Sticker,
} from '@biom3/react';
import { ReactElement, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { Chain, RouteData } from '../types';
import { getDurationFormatted } from '../functions/getDurationFormatted';
import { getTotalRouteFees } from '../functions/getTotalRouteFees';
Expand Down Expand Up @@ -39,6 +40,8 @@ export function RouteOption<RC extends ReactElement | undefined = undefined>({
rc = <span />,
selected = false,
}: RouteOptionProps<RC>) {
const { t } = useTranslation();

const { fromToken } = routeData.amountData;
const { estimate } = routeData.route.route;

Expand Down Expand Up @@ -89,11 +92,11 @@ export function RouteOption<RC extends ReactElement | undefined = undefined>({
</Sticker>
)}

<MenuItem.Caption>{`Balance: USD ${routeBalanceUsd}`}</MenuItem.Caption>
<MenuItem.Caption>{`Balance ${t('views.ADD_TOKENS.fees.fiatPricePrefix')} $${routeBalanceUsd}`}</MenuItem.Caption>

<MenuItem.PriceDisplay price={fromAmount}>
<MenuItem.PriceDisplay.Caption>
{`USD $${fromAmountUsd}`}
{`${t('views.ADD_TOKENS.fees.fiatPricePrefix')} $${fromAmountUsd}`}
</MenuItem.PriceDisplay.Caption>
</MenuItem.PriceDisplay>

Expand Down Expand Up @@ -135,7 +138,7 @@ export function RouteOption<RC extends ReactElement | undefined = undefined>({
sx={{ mr: 'base.spacing.x2' }}
/>
)}
{`Fee ~ USD $${getFormattedAmounts(totalFeesUsd)}`}
{`Fee ${t('views.ADD_TOKENS.fees.fiatPricePrefix')} $${getFormattedAmounts(totalFeesUsd)}`}
</Body>
</Stack>
</MenuItem.BottomSlot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'react';

import { Checkout } from '@imtbl/checkout-sdk';
import { useTranslation } from 'react-i18next';
import { Chain, RouteData } from '../types';
import { getRouteAndTokenBalances } from '../functions/getRouteAndTokenBalances';
import { getRemoteVideo } from '../../../lib/utils';
Expand Down Expand Up @@ -68,6 +69,8 @@ export function SelectedRouteOption({
showOnrampOption = false,
onClick,
}: SelectedRouteOptionProps) {
const { t } = useTranslation();

const { fromToken } = routeData?.amountData ?? {};
const chain = chains?.find((c) => c.id === fromToken?.chainId);

Expand Down Expand Up @@ -181,11 +184,13 @@ export function SelectedRouteOption({
>
<Stack gap="0px">
<MenuItem.Label>{fromToken?.name}</MenuItem.Label>
<MenuItem.Caption>{`Balance USD $${routeBalanceUsd}`}</MenuItem.Caption>
<MenuItem.Caption>
{`Balance ${t('views.ADD_TOKENS.fees.fiatPricePrefix')} $${routeBalanceUsd}`}
</MenuItem.Caption>
</Stack>
<MenuItem.PriceDisplay price={fromAmount}>
<MenuItem.PriceDisplay.Caption>
{`USD $${fromAmountUsd}`}
{`${t('views.ADD_TOKENS.fees.fiatPricePrefix')} $${fromAmountUsd}`}
</MenuItem.PriceDisplay.Caption>
</MenuItem.PriceDisplay>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from 'react';
import { Web3Provider } from '@ethersproject/providers';
import { Environment } from '@imtbl/config';
import { useTranslation } from 'react-i18next';
import { SimpleLayout } from '../../../components/SimpleLayout/SimpleLayout';
import { EventTargetContext } from '../../../context/event-target-context/EventTargetContext';
import {
Expand Down Expand Up @@ -113,6 +114,7 @@ export function AddTokens({

const { viewDispatch } = useContext(ViewContext);
const { track, page } = useAnalytics();
const { t } = useTranslation();

const {
eventTargetState: { eventTarget },
Expand Down Expand Up @@ -338,12 +340,12 @@ export function AddTokens({
setAllowedTokens(updatedTokens);

if (toTokenAddress) {
const token = updatedTokens.find(
(t) => t.address?.toLowerCase() === toTokenAddress.toLowerCase(),
const preselectedToken = updatedTokens.find(
(token) => token.address?.toLowerCase() === toTokenAddress.toLowerCase(),
);

if (token) {
setSelectedToken(token);
if (preselectedToken) {
setSelectedToken(preselectedToken);
}
}

Expand Down Expand Up @@ -458,10 +460,10 @@ export function AddTokens({

const shouldShowOnRampOption = useMemo(() => {
if (showOnrampOption && selectedToken) {
const token = onRampAllowedTokens.find(
(t) => t.address?.toLowerCase() === selectedToken.address?.toLowerCase(),
const isAllowedToken = onRampAllowedTokens.find(
(token) => token.address?.toLowerCase() === selectedToken.address?.toLowerCase(),
);
return !!token;
return !!isAllowedToken;
}
return false;
}, [selectedToken, onRampAllowedTokens, showOnrampOption]);
Expand Down Expand Up @@ -639,8 +641,8 @@ export function AddTokens({
/>

<HeroFormControl.Caption>
USD $
{getFormattedNumberWithDecimalPlaces(selectedAmountUsd)}
{`${t('views.ADD_TOKENS.fees.fiatPricePrefix')}
$${getFormattedNumberWithDecimalPlaces(selectedAmountUsd)}`}
</HeroFormControl.Caption>
</HeroFormControl>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export function Review({
}}
>
Included fees
{` USD $${getFormattedAmounts(totalFeesUsd)}`}
{` ${t('views.ADD_TOKENS.fees.fiatPricePrefix')} $${getFormattedAmounts(totalFeesUsd)}`}
<Icon
icon="ChevronExpand"
sx={{ ml: 'base.spacing.x2', w: 'base.icon.size.200' }}
Expand Down Expand Up @@ -485,7 +485,7 @@ export function Review({
sx={{ flexShrink: 0, alignSelf: 'flex-start' }}
>
<PriceDisplay.Caption size="small">
{`USD $${route?.route.estimate.fromAmountUSD ?? ''}`}
{`${t('views.ADD_TOKENS.fees.fiatPricePrefix')} $${route?.route.estimate.fromAmountUSD ?? ''}`}
</PriceDisplay.Caption>
</PriceDisplay>
</Stack>
Expand Down Expand Up @@ -626,7 +626,7 @@ export function Review({
sx={{ flexShrink: 0, alignSelf: 'flex-start' }}
>
<PriceDisplay.Caption size="small">
{`USD $${route?.route.estimate.toAmountUSD ?? ''}`}
{`${t('views.ADD_TOKENS.fees.fiatPricePrefix')} $${route?.route.estimate.toAmountUSD ?? ''}`}
</PriceDisplay.Caption>
</PriceDisplay>
</Stack>
Expand Down

0 comments on commit 856426e

Please sign in to comment.