+
+
+ {formatUSD(source.amountUSD)}
+
+
{''}
{source.balance && (
diff --git a/src/swap/components/SwapProvider.tsx b/src/swap/components/SwapProvider.tsx
index ec91f772c5..547d2ba1af 100644
--- a/src/swap/components/SwapProvider.tsx
+++ b/src/swap/components/SwapProvider.tsx
@@ -224,7 +224,10 @@ export function SwapProvider({
return;
}
if (amount === '' || amount === '.' || Number.parseFloat(amount) === 0) {
- return destination.setAmount('');
+ destination.setAmount('');
+ destination.setAmountUSD('');
+ source.setAmountUSD('');
+ return;
}
// When toAmount changes we fetch quote for fromAmount
@@ -272,7 +275,9 @@ export function SwapProvider({
response.toAmount,
response.to.decimals,
);
+ destination.setAmountUSD(response.toAmountUSD);
destination.setAmount(formattedAmount);
+ source.setAmountUSD(response.fromAmountUSD);
updateLifecycleStatus({
statusName: 'amountChange',
statusData: {
diff --git a/src/swap/hooks/useFromTo.test.ts b/src/swap/hooks/useFromTo.test.ts
index 12932d5437..929a707d7b 100644
--- a/src/swap/hooks/useFromTo.test.ts
+++ b/src/swap/hooks/useFromTo.test.ts
@@ -30,8 +30,10 @@ describe('useFromTo', () => {
(useValue as Mock).mockImplementation((props) => ({
...props,
amount: '100',
+ amountUSD: '150',
response: props.response,
setAmount: vi.fn(),
+ setAmountUSD: vi.fn(),
setLoading: vi.fn(),
setToken: vi.fn(),
token: USDC_TOKEN,
@@ -39,22 +41,26 @@ describe('useFromTo', () => {
const { result } = renderHook(() => useFromTo('0x123'));
expect(result.current.from).toEqual({
amount: '100',
+ amountUSD: '150',
balance: '100',
balanceResponse: { refetch: expect.any(Function) },
error: null,
loading: false,
setAmount: expect.any(Function),
+ setAmountUSD: expect.any(Function),
setLoading: expect.any(Function),
setToken: expect.any(Function),
token: USDC_TOKEN,
});
expect(result.current.to).toEqual({
amount: '100',
+ amountUSD: '150',
balance: '200',
balanceResponse: { refetch: expect.any(Function) },
error: null,
loading: false,
setAmount: expect.any(Function),
+ setAmountUSD: expect.any(Function),
setLoading: expect.any(Function),
setToken: expect.any(Function),
token: USDC_TOKEN,
diff --git a/src/swap/hooks/useFromTo.ts b/src/swap/hooks/useFromTo.ts
index 12db7f2a4f..3731035ae5 100644
--- a/src/swap/hooks/useFromTo.ts
+++ b/src/swap/hooks/useFromTo.ts
@@ -7,8 +7,10 @@ import { useSwapBalances } from './useSwapBalances';
export const useFromTo = (address?: Address): FromTo => {
const [fromAmount, setFromAmount] = useState('');
+ const [fromAmountUSD, setFromAmountUSD] = useState('');
const [fromToken, setFromToken] = useState();
const [toAmount, setToAmount] = useState('');
+ const [toAmountUSD, setToAmountUSD] = useState('');
const [toToken, setToToken] = useState();
const [toLoading, setToLoading] = useState(false);
const [fromLoading, setFromLoading] = useState(false);
@@ -27,6 +29,8 @@ export const useFromTo = (address?: Address): FromTo => {
balanceResponse: fromTokenResponse,
amount: fromAmount,
setAmount: setFromAmount,
+ amountUSD: fromAmountUSD,
+ setAmountUSD: setFromAmountUSD,
token: fromToken,
setToken: setFromToken,
loading: fromLoading,
@@ -38,6 +42,8 @@ export const useFromTo = (address?: Address): FromTo => {
balance: toBalanceString,
balanceResponse: toTokenResponse,
amount: toAmount,
+ amountUSD: toAmountUSD,
+ setAmountUSD: setToAmountUSD,
setAmount: setToAmount,
token: toToken,
setToken: setToToken,
diff --git a/src/swap/types.ts b/src/swap/types.ts
index b99811b0c7..a3406028dc 100644
--- a/src/swap/types.ts
+++ b/src/swap/types.ts
@@ -242,11 +242,13 @@ export type SwapQuote = {
amountReference: string; // The reference amount for the quote
from: Token; // The source token for the swap
fromAmount: string; // The amount of the source token
+ fromAmountUSD: string; // The USD value of the source token
hasHighPriceImpact: boolean; // Whether the price impact is high
priceImpact: string; // The price impact of the swap
slippage: string; // The slippage of the swap
to: Token; // The destination token for the swap
toAmount: string; // The amount of the destination token
+ toAmountUSD: string; // The USD value of the destination token
warning?: QuoteWarning; // The warning associated with the quote
};
@@ -338,11 +340,13 @@ export type SwapTransactionType = 'Batched' | 'ERC20' | 'Permit2' | 'Swap'; // C
export type SwapUnit = {
amount: string;
+ amountUSD: string;
balance?: string;
balanceResponse?: UseBalanceReturnType | UseReadContractReturnType;
error?: SwapError;
loading: boolean;
setAmount: Dispatch>;
+ setAmountUSD: Dispatch>;
setLoading: Dispatch>;
setToken: Dispatch>;
token: Token | undefined;