Skip to content

Commit 92ecfe9

Browse files
tiltomtiltom
andauthored
SOV-5216: Show estimated usd value (#1117)
* Show estimated USD value of a bridge transfer * Create blue-fireants-lie.md * Trigger staging build * Trigger branch deploy * Add fix for ESOV --------- Co-authored-by: tiltom <tiltom.defi@protonmail.com>
1 parent eed68c9 commit 92ecfe9

5 files changed

Lines changed: 72 additions & 19 deletions

File tree

.changeset/blue-fireants-lie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"frontend": patch
3+
---
4+
5+
SOV-5216: Show estimated USD value of bridge transfers

apps/frontend/src/app/3_organisms/ERC20BridgeDialog/components/ReceiveFlow/components/AmountScreen.tsx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ import {
1919

2020
import { RSK_CHAIN_ID } from '../../../../../../config/chains';
2121

22+
import { AmountRenderer } from '../../../../../2_molecules/AmountRenderer/AmountRenderer';
2223
import { MaxButton } from '../../../../../2_molecules/MaxButton/MaxButton';
24+
import { USD } from '../../../../../../constants/currencies';
2325
import { useAccount } from '../../../../../../hooks';
2426
import { useChainStore } from '../../../../../../hooks/useChainStore';
27+
import { useDollarValue } from '../../../../../../hooks/useDollarValue';
2528
import { useTokenDetailsByAsset } from '../../../../../../hooks/useTokenDetailsByAsset';
2629
import { translations } from '../../../../../../locales/i18n';
30+
import { toWei } from '../../../../../../utils/math';
2731
import {
2832
ReceiveFlowContext,
2933
ReceiveFlowStep,
@@ -80,6 +84,12 @@ export const AmountScreen: React.FC = () => {
8084
receiver,
8185
});
8286

87+
const { usdValue } = useDollarValue(
88+
token!,
89+
amount !== '' ? toWei(amount).toString() : '0',
90+
RSK_CHAIN_ID,
91+
);
92+
8393
const isBridgeLocked = useERC20BridgeLocked();
8494

8595
return (
@@ -111,15 +121,21 @@ export const AmountScreen: React.FC = () => {
111121
)}
112122
</div>
113123

114-
<AmountInput
115-
value={amount}
116-
onChangeText={setAmount}
117-
label={t(translations.common.amount)}
118-
unit={token}
119-
min={0}
120-
className="w-full max-w-full"
121-
placeholder="0"
122-
/>
124+
<div>
125+
<AmountInput
126+
value={amount}
127+
onChangeText={setAmount}
128+
label={t(translations.common.amount)}
129+
unit={token}
130+
min={0}
131+
className="w-full max-w-full"
132+
placeholder="0"
133+
/>
134+
135+
<div className="flex justify-end text-tiny text-gray-30 mt-1">
136+
<AmountRenderer value={usdValue} suffix={USD} />
137+
</div>
138+
</div>
123139

124140
<Paragraph className="mb-1 mt-6 text-sm font-medium">
125141
{t(translations.erc20Bridge.receive.addressLabel)}

apps/frontend/src/app/3_organisms/ERC20BridgeDialog/components/SendFlow/components/AmountScreen.tsx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ import {
2020

2121
import { RSK_CHAIN_ID } from '../../../../../../config/chains';
2222

23+
import { AmountRenderer } from '../../../../../2_molecules/AmountRenderer/AmountRenderer';
2324
import { MaxButton } from '../../../../../2_molecules/MaxButton/MaxButton';
25+
import { USD } from '../../../../../../constants/currencies';
2426
import { useAccount } from '../../../../../../hooks';
27+
import { useDollarValue } from '../../../../../../hooks/useDollarValue';
2528
import { useTokenDetailsByAsset } from '../../../../../../hooks/useTokenDetailsByAsset';
2629
import { translations } from '../../../../../../locales/i18n';
30+
import { toWei } from '../../../../../../utils/math';
2731
import { SendFlowContext, SendFlowStep } from '../../../contexts/sendflow';
2832
import { useBridgeService } from '../../../hooks/useBridgeService';
2933
import { useBridgeValidation } from '../../../hooks/useBridgeValidation';
@@ -74,6 +78,12 @@ export const AmountScreen: React.FC = () => {
7478
receiver,
7579
});
7680

81+
const { usdValue } = useDollarValue(
82+
token!,
83+
amount !== '' ? toWei(amount).toString() : '0',
84+
RSK_CHAIN_ID,
85+
);
86+
7787
return (
7888
<div>
7989
{chainId && (
@@ -103,15 +113,21 @@ export const AmountScreen: React.FC = () => {
103113
)}
104114
</div>
105115

106-
<AmountInput
107-
value={amount}
108-
onChangeText={setAmount}
109-
label={t(translations.common.amount)}
110-
unit={token}
111-
min={0}
112-
className="w-full mb-6 max-w-full"
113-
placeholder="0"
114-
/>
116+
<div className="mb-6">
117+
<AmountInput
118+
value={amount}
119+
onChangeText={setAmount}
120+
label={t(translations.common.amount)}
121+
unit={token}
122+
min={0}
123+
className="w-full mb-0 max-w-full"
124+
placeholder="0"
125+
/>
126+
127+
<div className="flex justify-end text-tiny text-gray-30 mt-1">
128+
<AmountRenderer value={usdValue} suffix={USD} />
129+
</div>
130+
</div>
115131

116132
<Paragraph className="mb-1 text-sm font-medium">
117133
<Trans

apps/frontend/src/contexts/TokenPricesContext.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { keepPreviousData, useQuery } from '@tanstack/react-query';
22

33
import React, { createContext, useContext, ReactNode } from 'react';
44

5+
import { ChainIds } from '@sovryn/ethers-provider';
6+
57
import { DATA_REFRESH_INTERVAL } from '../constants/general';
68
import { useCurrentChain } from '../hooks/useChainStore';
79
import { loadIndexer } from '../lib/indexer';
@@ -25,6 +27,13 @@ export type TokenData = {
2527
usdPrice: string;
2628
};
2729

30+
const UNSUPPORTED_CHAIN_IDS = [
31+
ChainIds.MAINNET,
32+
ChainIds.SEPOLIA,
33+
ChainIds.BSC_MAINNET,
34+
ChainIds.BSC_TESTNET,
35+
];
36+
2837
const TokenPricesContext = createContext<TokenPricesContextType | undefined>(
2938
undefined,
3039
);
@@ -40,7 +49,12 @@ export const TokenPricesProvider: React.FC<TokenPricesProviderProps> = ({
4049
placeholderData: keepPreviousData,
4150
refetchInterval: DATA_REFRESH_INTERVAL,
4251
queryFn: async () => {
43-
const data = await loadIndexer(currentChainId).tokens.list();
52+
// Fallback to RSK_MAINNET if current chain is unsupported
53+
const chain = UNSUPPORTED_CHAIN_IDS.includes(currentChainId as ChainIds)
54+
? ChainIds.RSK_MAINNET
55+
: currentChainId;
56+
57+
const data = await loadIndexer(chain).tokens.list();
4458

4559
if (data) {
4660
const prices = data.reduce(

apps/frontend/src/hooks/useDollarValue.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export function useDollarValue(
4545
return COMMON_SYMBOLS.ETH;
4646
} else if (['wbtc', 'tbtc'].includes(asset.toLocaleLowerCase())) {
4747
return COMMON_SYMBOLS.BTC;
48+
} else if (asset.toLocaleLowerCase() === 'esov') {
49+
return COMMON_SYMBOLS.SOV;
4850
}
4951
}
5052
return asset.toUpperCase();

0 commit comments

Comments
 (0)