removePoolTransaction function

void removePoolTransaction(
  1. String? bJJ,
  2. String? transactionId
)

Removes a transaction from the transaction pool @param {string} bJJ - The account with which the transaction was originally made @param {string} transactionId - The transaction identifier to remove from the pool @returns {void}

Implementation

void removePoolTransaction(String? bJJ, String? transactionId) async {
  final chainId = getCurrentEnvironment()!.chainId.toString();

  final SharedPreferences prefs = await _prefs;
  if (!prefs.containsKey(TRANSACTION_POOL_KEY)) {
    final emptyTransactionPool = {};
    prefs.setString(TRANSACTION_POOL_KEY, json.encode(emptyTransactionPool));
  }
  final transactionPool =
      json.decode(prefs.get(TRANSACTION_POOL_KEY) as String);

  final chainIdTransactionPool =
      transactionPool.containsKey(chainId) ? transactionPool[chainId] : {};
  final accountTransactionPool = chainIdTransactionPool.containsKey(bJJ)
      ? chainIdTransactionPool[bJJ]
      : [];

  accountTransactionPool.removeWhere((transaction) =>
      Transaction.fromJson(json.decode(transaction)).id == transactionId);

  final newChainIdTransactionPool = {}..addAll(chainIdTransactionPool);
  newChainIdTransactionPool.update(bJJ, (value) => accountTransactionPool,
      ifAbsent: () => accountTransactionPool);

  final newTransactionPool = {}..addAll(transactionPool);
  newTransactionPool.update(chainId, (value) => newChainIdTransactionPool,
      ifAbsent: () => newChainIdTransactionPool);

  prefs.setString(TRANSACTION_POOL_KEY, json.encode(newTransactionPool));
}