Category: Frontend - Bug
Priority: High
Estimated Time: 1 hour
Description:
components/session-provider.tsx calls JSON.stringify(next) on the session object and JSON.parse(stored) as Session on load. The Session type only contains token, userId, and merchantId — all strings — so the round-trip is currently safe.
However, the broader pattern in lib/api.ts uses bigint for amount_stroops, available, and pending fields. If any future code attempts to persist Balance or Payment objects through the same JSON.stringify path, BigInt serialisation will throw TypeError: Do not know how to serialize a BigInt. The custom stringifyWithBigInts / parseWithBigInts pair in lib/api.ts must be used for any persistence of API response objects.
Tasks:
- Add an ESLint rule or TypeScript type guard preventing direct
JSON.stringify calls on API response types containing bigint fields
- Add a comment in
session-provider.tsx explaining why only Session (string-only) is safe to use with plain JSON.stringify
- Add a unit test asserting that
JSON.stringify of a Balance object throws and that stringifyWithBigInts handles it correctly
Category: Frontend - Bug
Priority: High
Estimated Time: 1 hour
Description:
components/session-provider.tsxcallsJSON.stringify(next)on the session object andJSON.parse(stored) as Sessionon load. TheSessiontype only containstoken,userId, andmerchantId— all strings — so the round-trip is currently safe.However, the broader pattern in
lib/api.tsusesbigintforamount_stroops,available, andpendingfields. If any future code attempts to persistBalanceorPaymentobjects through the sameJSON.stringifypath,BigIntserialisation will throwTypeError: Do not know how to serialize a BigInt. The customstringifyWithBigInts/parseWithBigIntspair inlib/api.tsmust be used for any persistence of API response objects.Tasks:
JSON.stringifycalls on API response types containingbigintfieldssession-provider.tsxexplaining why onlySession(string-only) is safe to use with plainJSON.stringifyJSON.stringifyof aBalanceobject throws and thatstringifyWithBigIntshandles it correctly