getBalanceOfAddressOnSpecificBlockchain method

Future<String> getBalanceOfAddressOnSpecificBlockchain({
  1. required TransferRequest transferRequest,
})

Implementation

Future<String> getBalanceOfAddressOnSpecificBlockchain({
  required TransferRequest transferRequest,
}) async {
  if (transferRequest.accountID != null) {
    return blockchainService.getWalletBalance(
        transferRequest: transferRequest);
  } else {
    final wallet = walletsStream.value.firstWhereOrNull(
        (element) => element.id == transferRequest.walletId);
    final publicKey = wallet?.blockchainsData?[transferRequest.blockchainType]
        ?.firstWhereOrNull((element) =>
            element.derivationPath == transferRequest.currentDerivationPath)
        ?.publicKey;
    if (publicKey != null) {
      transferRequest.accountID = publicKey;
      return blockchainService.getWalletBalance(
          transferRequest: transferRequest);
    } else {
      throw Exception("Public key is null");
    }
  }
}