Simple token balance manager that uses localStorage to store transactions.

To do this, this class the list of all transactions and their corresponding amounts.

When a transaction is added, it is added to the list. When a transaction is removed, it is removed from the list.

The balance is the sum of all the amounts in the list.

  • IapticProductDefinition.tokenType
  • IapticProductDefinition.tokenValue
const tokensManager = new IapticTokensManager(iaptic);
// ... tokensManager is now tracking consumable purchases that have a tokenType defined.
const balance = tokensManager.getBalance('coin');

Constructors

Methods

  • Add a transaction to the map and persist it

    Parameters

    • transactionId: string

      Unique identifier for the transaction

    • type: string

      Type of token (e.g., 'gems', 'coins', 'credits')

    • amount: number

      Number of tokens earned (positive) or spent (negative)

    Returns Promise<void>

  • Helper method to check if we've already processed a transaction This can be used before processing a purchase to avoid double-counting

    Parameters

    • transactionId: string

    Returns boolean

  • Remove a transaction and update storage

    Parameters

    • transactionId: string

    Returns Promise<void>