Skip to content

Commit 2f34a84

Browse files
committed
fix(frontend): correct formatTokenAmount in IncomingStreams to use Intl.NumberFormat
The value passed to formatTokenAmount is already a human-scaled token amount (stroops divided by 1e7 in the dashboard mapper). The previous implementation incorrectly passed it through formatAmount(BigInt(Math.floor(value)), 7), re-interpreting it as raw base units and dividing by 1e7 a second time. This caused the Deposited, Withdrawn, and Claimable columns to display wildly wrong (tiny) values — e.g. 10.5 XLM was rendered as 0.0000010. Fix: format the human number directly via Intl.NumberFormat with up to 7 fraction digits, consistent with IncomingStreamCard. Remove the now-unused formatAmount import. Closes #575
1 parent 215b769 commit 2f34a84

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

frontend/src/components/IncomingStreams.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@ import React, { useState } from 'react';
44
import type { Stream } from '@/lib/dashboard';
55
import { useStreamingAmount } from '@/hooks/useStreamingAmount';
66
import toast from 'react-hot-toast';
7-
import { formatAmount } from '@/lib/amount';
7+
88

99
interface IncomingStreamsProps {
1010
streams: Stream[];
1111
onWithdraw: (stream: Stream) => Promise<void>;
1212
withdrawingStreamId?: string | null;
1313
}
1414

15-
function formatTokenAmount(value: number, decimals: number = 7): string {
15+
/**
16+
* Format an already-human-scaled token amount (e.g. 10.5) for display.
17+
*
18+
* Values coming from the Stream interface have already been divided by 1e7
19+
* (stroops → token units) by the dashboard mapper, so we must NOT re-scale
20+
* them through formatAmount. Instead we format the number directly using
21+
* Intl.NumberFormat, consistent with IncomingStreamCard.
22+
*/
23+
function formatTokenAmount(value: number, maximumFractionDigits = 7): string {
1624
if (!Number.isFinite(value)) return '0.0000000';
17-
return formatAmount(BigInt(Math.floor(value)), decimals);
25+
return new Intl.NumberFormat('en-US', {
26+
minimumFractionDigits: 0,
27+
maximumFractionDigits,
28+
}).format(value);
1829
}
1930

2031
const ClaimableAmount: React.FC<{ stream: Stream }> = ({ stream }) => {

0 commit comments

Comments
 (0)