@mezo-org/passport 0.5.4-dev.9 → 0.5.5-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/src/hooks/index.d.ts +1 -1
  2. package/dist/src/hooks/index.d.ts.map +1 -1
  3. package/dist/src/hooks/index.js +1 -1
  4. package/dist/src/hooks/index.js.map +1 -1
  5. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -1
  6. package/dist/src/hooks/useAssetsConversionRates.js +14 -5
  7. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -1
  8. package/dist/src/hooks/useBorrowData.d.ts.map +1 -1
  9. package/dist/src/hooks/useBorrowData.js +4 -5
  10. package/dist/src/hooks/useBorrowData.js.map +1 -1
  11. package/dist/src/hooks/useCollateralPrice.d.ts.map +1 -1
  12. package/dist/src/hooks/useCollateralPrice.js +4 -4
  13. package/dist/src/hooks/useCollateralPrice.js.map +1 -1
  14. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -1
  15. package/dist/src/hooks/useTokensBalances.js +5 -8
  16. package/dist/src/hooks/useTokensBalances.js.map +1 -1
  17. package/dist/src/provider.d.ts +14 -5
  18. package/dist/src/provider.d.ts.map +1 -1
  19. package/dist/src/provider.js +3 -1
  20. package/dist/src/provider.js.map +1 -1
  21. package/package.json +1 -1
  22. package/src/hooks/index.ts +1 -0
  23. package/src/hooks/useAssetsConversionRates.ts +15 -5
  24. package/src/hooks/useBorrowData.ts +5 -6
  25. package/src/hooks/useCollateralPrice.ts +8 -4
  26. package/src/hooks/useTokensBalances.ts +5 -9
  27. package/src/provider.ts +20 -7
  28. package/dist/src/utils/number2.d.ts +0 -106
  29. package/dist/src/utils/number2.d.ts.map +0 -1
  30. package/dist/src/utils/number2.js +0 -289
  31. package/dist/src/utils/number2.js.map +0 -1
  32. package/dist/src/utils/number2.test.d.ts +0 -2
  33. package/dist/src/utils/number2.test.d.ts.map +0 -1
  34. package/dist/src/utils/number2.test.js +0 -223
  35. package/dist/src/utils/number2.test.js.map +0 -1
  36. package/src/utils/number2.test.ts +0 -309
  37. package/src/utils/number2.ts +0 -419
@@ -1,309 +0,0 @@
1
- import {
2
- bigIntToFloat,
3
- bigIntToHumanReadableFormat,
4
- floatToBigInt,
5
- floatToHumanReadableFormat,
6
- multiplyBigIntWithDecimal,
7
- normalizeDecimalNumber,
8
- trimBeforeDecimals,
9
- trimDecimals,
10
- } from "./number2"
11
-
12
- describe("floatToBigInt", () => {
13
- it("should convert integer string to bigint with default decimals", () => {
14
- expect(floatToBigInt({ amount: "1" })).toBe(1_000_000_000_000_000_000n)
15
- })
16
-
17
- it("should convert float string to bigint with default decimals", () => {
18
- expect(floatToBigInt({ amount: "1.23" })).toBe(1_230_000_000_000_000_000n)
19
- })
20
-
21
- it("should convert float string to bigint with custom decimals", () => {
22
- expect(floatToBigInt({ amount: "1.23", decimals: 2 })).toBe(123n)
23
- expect(floatToBigInt({ amount: "1.2345", decimals: 2 })).toBe(123n)
24
- expect(floatToBigInt({ amount: "1.2345", decimals: 6 })).toBe(1234500n)
25
- })
26
-
27
- it("should handle numbers as input", () => {
28
- expect(floatToBigInt({ amount: 2.5 })).toBe(2_500_000_000_000_000_000n)
29
- })
30
-
31
- it("should handle zero", () => {
32
- expect(floatToBigInt({ amount: "0" })).toBe(0n)
33
- expect(floatToBigInt({ amount: 0 })).toBe(0n)
34
- })
35
-
36
- it("should handle negative numbers", () => {
37
- expect(floatToBigInt({ amount: "-1.5" })).toBe(-1_500_000_000_000_000_000n)
38
- })
39
-
40
- it("should handle numbers with thousands separator", () => {
41
- expect(floatToBigInt({ amount: "1,234.56" })).toBe(
42
- 1_234_560_000_000_000_000_000n,
43
- )
44
- })
45
-
46
- it("should return 0n for invalid input", () => {
47
- expect(floatToBigInt({ amount: "abc" })).toBe(0n)
48
- expect(floatToBigInt({ amount: "1.2.3" })).toBe(0n)
49
- expect(floatToBigInt({ amount: "" })).toBe(0n)
50
- })
51
- })
52
-
53
- describe("bigIntToFloat", () => {
54
- it("should convert bigint to float string with default decimals", () => {
55
- expect(bigIntToFloat({ amount: 1_000_000_000_000_000_000n })).toBe("1")
56
- expect(bigIntToFloat({ amount: 1_230_000_000_000_000_000n })).toBe("1.23")
57
- })
58
-
59
- it("should convert bigint to float string with custom decimals", () => {
60
- expect(bigIntToFloat({ amount: 123n, decimals: 2 })).toBe("1.23")
61
- expect(bigIntToFloat({ amount: 1234500n, decimals: 6 })).toBe("1.2345")
62
- })
63
-
64
- it("should handle desiredDecimals less than decimals", () => {
65
- expect(
66
- bigIntToFloat({
67
- amount: 1_234_567_890_000_000_000n,
68
- decimals: 18,
69
- desiredDecimals: 2,
70
- }),
71
- ).toBe("1.23")
72
- expect(
73
- bigIntToFloat({
74
- amount: 1_234_567_890_000_000_000n,
75
- decimals: 18,
76
- desiredDecimals: 6,
77
- }),
78
- ).toBe("1.234568")
79
- })
80
-
81
- it("should handle zero", () => {
82
- expect(bigIntToFloat({ amount: 0n })).toBe("0")
83
- })
84
-
85
- it("should handle negative numbers", () => {
86
- expect(bigIntToFloat({ amount: -1_500_000_000_000_000_000n })).toBe("-1.5")
87
- })
88
-
89
- it("should handle rounding up", () => {
90
- expect(
91
- bigIntToFloat({
92
- amount: 1_249_999_999_999_999_999n,
93
- decimals: 18,
94
- desiredDecimals: 2,
95
- }),
96
- ).toBe("1.25")
97
- expect(
98
- bigIntToFloat({
99
- amount: 1_234_567_890_000_000_000n,
100
- decimals: 18,
101
- desiredDecimals: 4,
102
- }),
103
- ).toBe("1.2346")
104
- })
105
-
106
- it("should handle large numbers", () => {
107
- expect(
108
- bigIntToFloat({
109
- amount: 123_456_789_012_345_678_901_234_567_890n,
110
- decimals: 18,
111
- desiredDecimals: 2,
112
- }),
113
- ).toBe("123456789012.35")
114
- })
115
- })
116
-
117
- describe("floatToHumanReadableFormat", () => {
118
- it("should format number with thousands separator and default decimals", () => {
119
- expect(floatToHumanReadableFormat({ amount: 1234567.891 })).toBe(
120
- "1,234,567.89",
121
- )
122
- expect(floatToHumanReadableFormat({ amount: "1234567.891" })).toBe(
123
- "1,234,567.89",
124
- )
125
- })
126
-
127
- it("should format with custom decimals", () => {
128
- expect(
129
- floatToHumanReadableFormat({ amount: 1234567.891, desiredDecimals: 3 }),
130
- ).toBe("1,234,567.891")
131
- expect(
132
- floatToHumanReadableFormat({ amount: 1234567.8, desiredDecimals: 0 }),
133
- ).toBe("1,234,568")
134
- })
135
-
136
- it("should format with minDecimals", () => {
137
- expect(
138
- floatToHumanReadableFormat({
139
- amount: 1234.5,
140
- desiredDecimals: 2,
141
- minDecimals: 1,
142
- }),
143
- ).toBe("1,234.5")
144
- expect(
145
- floatToHumanReadableFormat({
146
- amount: 1234.5,
147
- desiredDecimals: 2,
148
- minDecimals: 2,
149
- }),
150
- ).toBe("1,234.50")
151
- expect(
152
- floatToHumanReadableFormat({
153
- amount: 1234.5,
154
- desiredDecimals: 2,
155
- minDecimals: 4,
156
- }),
157
- ).toBe("1,234.5000")
158
- })
159
-
160
- it("should return '0' for invalid input", () => {
161
- expect(floatToHumanReadableFormat({ amount: "abc" })).toBe("0")
162
- })
163
- })
164
-
165
- describe("bigIntToHumanReadableFormat", () => {
166
- it("should format bigint to human readable string", () => {
167
- expect(
168
- bigIntToHumanReadableFormat({
169
- amount: 1_234_567_890_000_000_000n,
170
- decimals: 18,
171
- desiredDecimals: 2,
172
- }),
173
- ).toBe("1.23")
174
- expect(
175
- bigIntToHumanReadableFormat({
176
- amount: 1_234_567_890_000_000_000n,
177
- decimals: 18,
178
- desiredDecimals: 6,
179
- }),
180
- ).toBe("1.234568")
181
- })
182
-
183
- it("should handle negative values", () => {
184
- expect(
185
- bigIntToHumanReadableFormat({
186
- amount: -1_234_567_890_000_000_000n,
187
- decimals: 18,
188
- desiredDecimals: 2,
189
- }),
190
- ).toBe("-1.23")
191
- })
192
-
193
- it("should show <0.01 for very small nonzero values", () => {
194
- expect(
195
- bigIntToHumanReadableFormat({
196
- amount: 1n,
197
- decimals: 18,
198
- desiredDecimals: 2,
199
- }),
200
- ).toBe("<0.01")
201
- expect(
202
- bigIntToHumanReadableFormat({
203
- amount: -1n,
204
- decimals: 18,
205
- desiredDecimals: 2,
206
- }),
207
- ).toBe("<0.01")
208
- })
209
-
210
- it("should format with minDecimals", () => {
211
- expect(
212
- bigIntToHumanReadableFormat({
213
- amount: 1_234_000_000_000_000_000n,
214
- decimals: 18,
215
- desiredDecimals: 2,
216
- minDecimals: 3,
217
- }),
218
- ).toBe("1.234")
219
- expect(
220
- bigIntToHumanReadableFormat({
221
- amount: 1_234_000_000_000_000_000n,
222
- decimals: 18,
223
- desiredDecimals: 3,
224
- minDecimals: 2,
225
- }),
226
- ).toBe("1.234")
227
- expect(
228
- bigIntToHumanReadableFormat({
229
- amount: 1_234_000_000_000_000_000n,
230
- decimals: 18,
231
- desiredDecimals: 2,
232
- minDecimals: 4,
233
- }),
234
- ).toBe("1.2340")
235
- })
236
- })
237
-
238
- describe("multiplyBigIntWithDecimal", () => {
239
- it("should multiply bigint by integer", () => {
240
- expect(multiplyBigIntWithDecimal(10n, 2)).toBe(20n)
241
- })
242
-
243
- it("should multiply bigint by decimal", () => {
244
- expect(multiplyBigIntWithDecimal(100n, 0.5)).toBe(50n)
245
- expect(multiplyBigIntWithDecimal(100n, 1.25)).toBe(125n)
246
- })
247
-
248
- it("should handle scientific notation", () => {
249
- expect(multiplyBigIntWithDecimal(100n, 1e-2)).toBe(1n)
250
- })
251
-
252
- it("should handle zero", () => {
253
- expect(multiplyBigIntWithDecimal(0n, 1.5)).toBe(0n)
254
- })
255
- })
256
-
257
- describe("trimDecimals", () => {
258
- it("should trim decimals to specified precision", () => {
259
- expect(trimDecimals("1.23456", 2)).toBe("1.23")
260
- expect(trimDecimals("1.2", 4)).toBe("1.2")
261
- expect(trimDecimals("1", 2)).toBe("1")
262
- })
263
- })
264
-
265
- describe("trimBeforeDecimals", () => {
266
- it("should trim integer part to specified length", () => {
267
- expect(trimBeforeDecimals("12345.67", 3)).toBe("123.67")
268
- expect(trimBeforeDecimals("12.34", 5)).toBe("12.34")
269
- expect(trimBeforeDecimals("123456", 2)).toBe("12.")
270
- })
271
- })
272
-
273
- describe("normalizeDecimalNumber", () => {
274
- it("should remove invalid characters", () => {
275
- expect(normalizeDecimalNumber("12a3.4b5")).toBe("123.45")
276
- })
277
-
278
- it("should prevent multiple dots", () => {
279
- expect(normalizeDecimalNumber("1.2.3")).toBe("12.3")
280
- expect(normalizeDecimalNumber("1..1.2")).toBe("11.2")
281
- })
282
-
283
- it("should allow only digits and one dot", () => {
284
- expect(normalizeDecimalNumber("abc")).toBe("")
285
- expect(normalizeDecimalNumber("123")).toBe("123")
286
- })
287
-
288
- it("should handle leading and trailing spaces", () => {
289
- expect(normalizeDecimalNumber(" 1.23 ")).toBe("1.23")
290
- expect(normalizeDecimalNumber(" 1.2.3 ")).toBe("12.3")
291
- })
292
-
293
- it("should handle empty input", () => {
294
- expect(normalizeDecimalNumber("")).toBe("")
295
- expect(normalizeDecimalNumber(" ")).toBe("")
296
- })
297
-
298
- it("should handle numbers with thousands separator", () => {
299
- expect(normalizeDecimalNumber("1,234.56")).toBe("1234.56")
300
- expect(normalizeDecimalNumber("1,234,567.89")).toBe("1234567.89")
301
- })
302
-
303
- it("should handle scientific notation", () => {
304
- // This function does not support scientific notation as our input is expected
305
- // to accept only decimal numbers
306
- expect(normalizeDecimalNumber("1e3")).toBe("13")
307
- expect(normalizeDecimalNumber("1.23e2")).toBe("1.232")
308
- })
309
- })