Skip to content

Commit 0b4f504

Browse files
committed
fix: decimal helper crashing
1 parent e8cf255 commit 0b4f504

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

.changeset/brave-drinks-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sovryn/utils': patch
3+
---
4+
5+
fix: decimal util crashing when null value is given

packages/utils/src/math/Decimal.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,29 @@ export class Decimal {
9393
case 'object':
9494
if (decimalish instanceof Decimal) {
9595
return decimalish;
96+
} else if (decimalish === null || decimalish === undefined) {
97+
return Decimal.ZERO;
9698
} else {
97-
throw new Error('invalid Decimalish value');
99+
throw new Error(
100+
'invalid Decimalish value: ' +
101+
typeof decimalish +
102+
'(' +
103+
decimalish +
104+
')',
105+
);
98106
}
99107
case 'string':
100108
return Decimal._fromString(decimalish);
101109
case 'number':
102110
return Decimal._fromString(decimalish.toString());
103111
default:
104-
throw new Error('invalid Decimalish value');
112+
throw new Error(
113+
'invalid Decimalish value: ' +
114+
typeof decimalish +
115+
'(' +
116+
decimalish +
117+
')',
118+
);
105119
}
106120
}
107121

0 commit comments

Comments
 (0)