Skip to content

Commit 281c40c

Browse files
committed
fix: use Intl for bridge fiat currency symbols
1 parent 79443b7 commit 281c40c

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

app/components/UI/Bridge/hooks/useSourceAmountInput/index.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
22
import { useSelector } from 'react-redux';
33
import { selectCurrentCurrency } from '../../../../../selectors/currencyRateController';
4-
import currencySymbols from '../../../../../util/currency-symbols.json';
5-
import { getCurrencySymbol } from '../../../../../util/number/bigint';
64
import { MAX_INPUT_LENGTH } from '../../components/TokenInputArea';
75
import { BridgeToken } from '../../types';
86
import { formatAmountWithLocaleSeparators } from '../../utils/formatAmountWithLocaleSeparators';
@@ -12,20 +10,11 @@ import {
1210
formatSecondaryTokenAmount,
1311
formatTokenInputAmountFromFiat,
1412
} from '../../utils/sourceAmountInputMode';
15-
import { formatCurrency } from '../../utils/currencyUtils';
13+
import { formatCurrency, getCurrencySymbol } from '../../utils/currencyUtils';
1614
import { useSourceAmountCursor } from '../useSourceAmountCursor';
1715
import { useTokenFiatRate } from '../useTokenFiatRate';
1816

1917
const FIAT_KEYPAD_CURRENCY = 'SWAPS_FIAT_INPUT';
20-
type CurrencyCode = keyof typeof currencySymbols;
21-
22-
const getInputCurrencySymbol = (currency?: string) => {
23-
const currencyCode = (currency || 'usd').toLowerCase();
24-
25-
return currencyCode in currencySymbols
26-
? getCurrencySymbol(currencyCode as CurrencyCode)
27-
: currencyCode.toUpperCase();
28-
};
2918

3019
export const useSourceAmountInput = ({
3120
sourceAmount,
@@ -202,7 +191,7 @@ export const useSourceAmountInput = ({
202191
}, [canToggle, currentCurrency, isFiatMode, sourceAmount, sourceToken]);
203192

204193
const inputPrefix = isFiatMode
205-
? getInputCurrencySymbol(currentCurrency)
194+
? getCurrencySymbol(currentCurrency || 'usd')
206195
: undefined;
207196

208197
return {

app/components/UI/Bridge/utils/currencyUtils.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,27 @@ export function formatCurrency(
4646
return String(amount);
4747
}
4848
}
49+
50+
export function getCurrencySymbol(currency: string): string {
51+
const normalizedCurrency = (currency || 'USD').toUpperCase();
52+
53+
try {
54+
const formattedZero = getIntlNumberFormatter(I18n.locale, {
55+
style: 'currency',
56+
currency: normalizedCurrency,
57+
currencyDisplay: 'symbol',
58+
minimumFractionDigits: 0,
59+
maximumFractionDigits: 0,
60+
}).format(0);
61+
62+
const currencySymbol = formattedZero.replace(/[\d\s.,'_-]/gu, '').trim();
63+
64+
if (currencySymbol && currencySymbol.toUpperCase() !== normalizedCurrency) {
65+
return currencySymbol;
66+
}
67+
} catch (error) {
68+
console.error('Error getting currency symbol:', error);
69+
}
70+
71+
return normalizedCurrency;
72+
}

0 commit comments

Comments
 (0)