Skip to content

Commit 8ceb9eb

Browse files
committed
fix: ramp v2 order detail's crypto amount formatting
1 parent d6fd3c4 commit 8ceb9eb

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

app/components/UI/Ramp/Views/OrderDetails/OrderContent.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,38 @@ describe('OrderContent', () => {
166166
).toBeOnTheScreen();
167167
});
168168

169+
it('truncates long crypto amounts to 5 decimal places', () => {
170+
const longDecimalOrder: RampsOrder = {
171+
...mockOrder,
172+
cryptoAmount: 0.01588973776561068,
173+
};
174+
renderOrder(longDecimalOrder);
175+
const tokenAmount = screen.getByTestId('ramps-order-details-token-amount');
176+
expect(tokenAmount.props.children).not.toContain('0.01588973776561068');
177+
expect(tokenAmount).toHaveTextContent('0.01589 ETH');
178+
});
179+
180+
it('uses subscript notation for very small crypto amounts', () => {
181+
const tinyAmountOrder: RampsOrder = {
182+
...mockOrder,
183+
cryptoAmount: 0.00000614,
184+
};
185+
renderOrder(tinyAmountOrder);
186+
const tokenAmount = screen.getByTestId('ramps-order-details-token-amount');
187+
// 0.00000614 has 5 leading zeros → "0.0₅614"
188+
expect(tokenAmount).toHaveTextContent('0.0₅614 ETH');
189+
});
190+
191+
it('shows "..." when cryptoAmount is missing', () => {
192+
const noAmountOrder: RampsOrder = {
193+
...mockOrder,
194+
cryptoAmount: undefined as unknown as number,
195+
};
196+
renderOrder(noAmountOrder);
197+
const tokenAmount = screen.getByTestId('ramps-order-details-token-amount');
198+
expect(tokenAmount).toHaveTextContent('... ETH');
199+
});
200+
169201
it('does not render info row when statusDescription is absent', () => {
170202
const orderWithoutDescription: RampsOrder = {
171203
...mockOrder,

app/components/UI/Ramp/Views/OrderDetails/OrderContent.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ import BadgeWrapper, {
2424
BadgePosition,
2525
} from '../../../../../component-library/components/Badges/BadgeWrapper';
2626
import { AvatarSize } from '../../../../../component-library/components/Avatars/Avatar';
27-
import { strings } from '../../../../../../locales/i18n';
27+
import I18n, { strings } from '../../../../../../locales/i18n';
2828
import { toDateFormat } from '../../../../../util/date';
2929
import { renderFiat } from '../../../../../util/number';
30+
import { formatSubscriptNotation } from '../../../../../util/number/subscriptNotation';
31+
import { formatWithThreshold } from '../../../../../util/assets';
3032
import { getNetworkImageSource } from '../../../../../util/networks';
3133
import Logger from '../../../../../util/Logger';
3234
import Button, {
@@ -318,7 +320,21 @@ const OrderContent: React.FC<OrderContentProps> = ({
318320
fontWeight={FontWeight.Bold}
319321
twClassName="mt-6 text-center"
320322
>
321-
{order.cryptoAmount} {cryptoSymbol}
323+
{order.cryptoAmount
324+
? (formatSubscriptNotation(
325+
parseFloat(String(order.cryptoAmount)),
326+
) ??
327+
formatWithThreshold(
328+
parseFloat(String(order.cryptoAmount)),
329+
0.00001,
330+
I18n.locale,
331+
{
332+
minimumFractionDigits: 0,
333+
maximumFractionDigits: 5,
334+
},
335+
))
336+
: '...'}{' '}
337+
{cryptoSymbol}
322338
</Text>
323339
</Box>
324340

0 commit comments

Comments
 (0)