Skip to content

Refactor: session-provider stores bigint balances as strings in localStorage — breaks JSON round-trip #595

Description

@henrypeters

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programauthAuthentication and authorizationbugSomething isn't workingfinancialFinancial calculation or data

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions