Simple token balance manager that persists transactions to AsyncStorage.

Tracks all consumable token transactions and their corresponding amounts. When a transaction is added, it is appended to the persisted list. When a transaction is removed (refund), it is removed from the list. The balance is the sum of all amounts in the list.

@react-native-async-storage/async-storage — install with: npm install @react-native-async-storage/async-storage@~2.1.0

  • IapticProductDefinition.tokenType
  • IapticProductDefinition.tokenValue
const tokensManager = new IapticTokensManager();
// ... 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>