Skip to content

Commit 9f5b30b

Browse files
committed
Points handling for payments
1 parent d1cf5c6 commit 9f5b30b

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

src/apps/review/src/lib/components/ChallengePhaseInfo/ChallengePhaseInfo.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,30 @@ export const ChallengePhaseInfo: FC<Props> = (props: Props) => {
104104
const formatCurrency = useCallback((amount: number | string, currency?: string): string => {
105105
const n = typeof amount === 'number' ? amount : Number(amount)
106106
if (Number.isNaN(n)) return String(amount)
107-
const nf = new Intl.NumberFormat('en-US', {
108-
currency: currency || 'USD',
109-
maximumFractionDigits: 2,
110-
minimumFractionDigits: 2,
111-
style: 'currency',
112-
})
113-
return nf.format(n)
107+
108+
const normalizedCurrency = (currency || 'USD').toUpperCase()
109+
if (normalizedCurrency === 'POINT') {
110+
return `${n.toLocaleString('en-US', {
111+
maximumFractionDigits: 2,
112+
minimumFractionDigits: 0,
113+
})} Points`
114+
}
115+
116+
try {
117+
const nf = new Intl.NumberFormat('en-US', {
118+
currency: normalizedCurrency,
119+
maximumFractionDigits: 2,
120+
minimumFractionDigits: 2,
121+
style: 'currency',
122+
})
123+
return nf.format(n)
124+
} catch (err) {
125+
// Fallback for any non-ISO currency codes
126+
return `${normalizedCurrency} ${n.toLocaleString('en-US', {
127+
maximumFractionDigits: 2,
128+
minimumFractionDigits: 2,
129+
})}`
130+
}
114131
}, [])
115132

116133
const taskPaymentFromPrizeSets = useMemo(() => {

src/apps/review/src/lib/components/DialogPayments/DialogPayments.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,30 @@ type PastRow = { id: string, description: string, handle: string, amount: string
2424
const formatCurrency = (amount: number | string, currency?: string): string => {
2525
const n = typeof amount === 'number' ? amount : Number(amount)
2626
if (Number.isNaN(n)) return String(amount)
27-
const nf = new Intl.NumberFormat('en-US', {
28-
currency: currency || 'USD',
29-
maximumFractionDigits: 2,
30-
minimumFractionDigits: 2,
31-
style: 'currency',
32-
})
33-
return nf.format(n)
27+
28+
const normalizedCurrency = (currency || 'USD').toUpperCase()
29+
if (normalizedCurrency === 'POINT') {
30+
return `${n.toLocaleString('en-US', {
31+
maximumFractionDigits: 2,
32+
minimumFractionDigits: 0,
33+
})} Points`
34+
}
35+
36+
try {
37+
const nf = new Intl.NumberFormat('en-US', {
38+
currency: normalizedCurrency,
39+
maximumFractionDigits: 2,
40+
minimumFractionDigits: 2,
41+
style: 'currency',
42+
})
43+
return nf.format(n)
44+
} catch (err) {
45+
// Fallback for any non-ISO currency codes
46+
return `${normalizedCurrency} ${n.toLocaleString('en-US', {
47+
maximumFractionDigits: 2,
48+
minimumFractionDigits: 2,
49+
})}`
50+
}
3451
}
3552

3653
const ordinal = (i: number): string => {

0 commit comments

Comments
 (0)