From fb7c58f60a0e8935e9fe3d80012ebfced7be5ebd Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 5 Jan 2023 12:12:38 -0600 Subject: [PATCH] handle 0 amounts use null operator where applicable --- lib/models/paymint/transactions_model.dart | 2 +- lib/services/coins/bitcoincash/bitcoincash_wallet.dart | 2 +- lib/services/coins/firo/firo_wallet.dart | 4 ++-- lib/services/coins/litecoin/litecoin_wallet.dart | 5 ++--- lib/services/coins/namecoin/namecoin_wallet.dart | 4 ++-- lib/services/coins/particl/particl_wallet.dart | 4 ++-- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/models/paymint/transactions_model.dart b/lib/models/paymint/transactions_model.dart index 0a1567105..1d40ac01c 100644 --- a/lib/models/paymint/transactions_model.dart +++ b/lib/models/paymint/transactions_model.dart @@ -394,7 +394,7 @@ class Output { scriptpubkeyType: json['scriptPubKey']['type'] as String?, scriptpubkeyAddress: address, value: (Decimal.parse( - (json["value"] != null ? json["value"] : 0).toString()) * + (json["value"] ?? 0).toString()) * Decimal.fromInt(Constants.satsPerCoin(Coin .firo))) // dirty hack but we need 8 decimal places here to keep consistent data structure .toBigInt() diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index c6dc8ca03..ebd2e2df8 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -2380,7 +2380,7 @@ class BitcoinCashWallet extends CoinServiceAPI { for (final output in txObject["vout"] as List) { final address = getAddress(output); if (address != null) { - final value = (Decimal.parse(output["value"].toString()) * + final value = (Decimal.parse((output["value"] ?? 0).toString()) * Decimal.fromInt(Constants.satsPerCoin(coin))) .toBigInt() .toInt(); diff --git a/lib/services/coins/firo/firo_wallet.dart b/lib/services/coins/firo/firo_wallet.dart index 5d29bd0a9..58ac019b0 100644 --- a/lib/services/coins/firo/firo_wallet.dart +++ b/lib/services/coins/firo/firo_wallet.dart @@ -3320,7 +3320,7 @@ class FiroWallet extends CoinServiceAPI { for (final output in txObject["vout"] as List) { final addresses = output["scriptPubKey"]["addresses"] as List?; - final value = output["value"]; + final value = output["value"] ?? 0; if (addresses != null && addresses.isNotEmpty) { final address = addresses[0] as String; if (value != null) { @@ -3359,7 +3359,7 @@ class FiroWallet extends CoinServiceAPI { final addresses = output["scriptPubKey"]["addresses"] as List?; if (addresses != null && addresses.isNotEmpty) { final address = addresses[0] as String; - final value = output["value"]; + final value = output["value"] ?? 0; // Logging.instance.log(address + value.toString()); if (allAddresses.contains(address)) { diff --git a/lib/services/coins/litecoin/litecoin_wallet.dart b/lib/services/coins/litecoin/litecoin_wallet.dart index 269f59610..f027ab2db 100644 --- a/lib/services/coins/litecoin/litecoin_wallet.dart +++ b/lib/services/coins/litecoin/litecoin_wallet.dart @@ -2565,8 +2565,7 @@ class LitecoinWallet extends CoinServiceAPI { for (final output in txObject["vout"] as List) { final String address = - output["scriptPubKey"]!["addresses"][0] as String; - final value = output["value"]!; + final value = output["value"] ?? 0; final _value = (Decimal.parse(value.toString()) * Decimal.fromInt(Constants.satsPerCoin(coin))) .toBigInt() @@ -2592,7 +2591,7 @@ class LitecoinWallet extends CoinServiceAPI { for (final output in txObject["vout"] as List) { final address = output["scriptPubKey"]["addresses"][0]; if (address != null) { - final value = (Decimal.parse(output["value"].toString()) * + final value = (Decimal.parse((output["value"] ?? 0).toString()) * Decimal.fromInt(Constants.satsPerCoin(coin))) .toBigInt() .toInt(); diff --git a/lib/services/coins/namecoin/namecoin_wallet.dart b/lib/services/coins/namecoin/namecoin_wallet.dart index 85fea61ad..f20bfa36f 100644 --- a/lib/services/coins/namecoin/namecoin_wallet.dart +++ b/lib/services/coins/namecoin/namecoin_wallet.dart @@ -2554,7 +2554,7 @@ class NamecoinWallet extends CoinServiceAPI { for (final output in txObject["vout"] as List) { Logging.instance.log(output, level: LogLevel.Info); final address = output["scriptPubKey"]["address"]; - final value = output["value"]; + final value = output["value"] ?? 0; final _value = (Decimal.parse(value.toString()) * Decimal.fromInt(Constants.satsPerCoin(coin))) .toBigInt() @@ -2583,7 +2583,7 @@ class NamecoinWallet extends CoinServiceAPI { address = output["scriptPubKey"]["address"] as String?; } if (address != null) { - final value = (Decimal.parse(output["value"].toString()) * + final value = (Decimal.parse((output["value"] ?? 0).toString()) * Decimal.fromInt(Constants.satsPerCoin(coin))) .toBigInt() .toInt(); diff --git a/lib/services/coins/particl/particl_wallet.dart b/lib/services/coins/particl/particl_wallet.dart index fe535dbf0..897f5951f 100644 --- a/lib/services/coins/particl/particl_wallet.dart +++ b/lib/services/coins/particl/particl_wallet.dart @@ -2361,7 +2361,7 @@ class ParticlWallet extends CoinServiceAPI { try { final String address = output["scriptPubKey"]!["addresses"][0] as String; - final value = output["value"]!; + final value = output["value"] ?? 0; final _value = (Decimal.parse(value.toString()) * Decimal.fromInt(Constants.satsPerCoin(coin))) .toBigInt() @@ -2419,7 +2419,7 @@ class ParticlWallet extends CoinServiceAPI { try { final address = output["scriptPubKey"]["addresses"][0]; if (address != null) { - final value = (Decimal.parse(output["value"].toString()) * + final value = (Decimal.parse((output["value"] ?? 0).toString()) * Decimal.fromInt(Constants.satsPerCoin(coin))) .toBigInt() .toInt();