fix: cashu token amount parsing from proof values

This commit is contained in:
Khushal
2026-06-01 06:06:32 +05:30
parent 0980a1157e
commit 18d1b4c019
2 changed files with 12 additions and 1 deletions
+10
View File
@@ -265,6 +265,16 @@ describe('CashuUtils', () => {
).toBe(7);
});
it('sums string proof amounts as numbers', () => {
expect(
CashuUtils.sumProofsValue([
{ amount: '64' },
{ amount: '32' },
{ amount: '4' }
])
).toBe(100);
});
it('returns 0 for empty/null', () => {
expect(CashuUtils.sumProofsValue([])).toBe(0);
expect(CashuUtils.sumProofsValue(null)).toBe(0);
+2 -1
View File
@@ -139,7 +139,8 @@ class CashuUtils {
return 0;
}
return proofs.reduce((r: number, c: any) => {
return r + c.amount;
const amount = Number(c?.amount) || 0;
return r + amount;
}, 0);
};