getDisputes method

Future<List<Dispute>> getDisputes()

Implementation

Future<List<Dispute>> getDisputes() async {
  if (!havenoChannel.isConnected) {
    throw DaemonNotConnectedException();
  }
  try {
    // Attempt to retrieve disputes from the service
    GetDisputesReply? getDisputesReply = await havenoChannel.disputesClient?.getDisputes(GetDisputesRequest());

    // Ensure the reply is not null
    if (getDisputesReply == null) {
      debugPrint("getDisputesReply is null, cannot proceed.");
      return [];
    }

    // Extract the list of disputes
    List<Dispute> disputesList = getDisputesReply.disputes;

    // Check if the disputes list is empty
    if (disputesList.isEmpty) {
      debugPrint("No disputes found.");
    } else {
      // Iterate through each dispute and map the tradeId to the dispute
      for (var dispute in disputesList) {
        _disputeToTradeIdMap[dispute.id] = dispute.tradeId;
        _tradeIdToDisputeMap[dispute.tradeId] = dispute;

        // Debugging output to verify the mapping
        debugPrint("Mapping added: Trade ID ${dispute.tradeId} -> Dispute ID ${dispute.id}");
        debugPrint("Current _tradeIdToDisputeMap contents:");
        _tradeIdToDisputeMap.forEach((tradeId, mappedDispute) {
          debugPrint("Trade ID: $tradeId, Dispute ID: ${mappedDispute.id}");
        });
      }
    }
    _disputes = disputesList;
    return _disputes;
  } on GrpcError catch (e) {
    handleGrpcError(e);
    return [];
  }
}