handle 0 amounts

use null operator where applicable
This commit is contained in:
sneurlax 2023-01-05 12:12:38 -06:00
parent 4d10727360
commit fb7c58f60a
6 changed files with 10 additions and 11 deletions

View file

@ -394,7 +394,7 @@ class Output {
scriptpubkeyType: json['scriptPubKey']['type'] as String?, scriptpubkeyType: json['scriptPubKey']['type'] as String?,
scriptpubkeyAddress: address, scriptpubkeyAddress: address,
value: (Decimal.parse( value: (Decimal.parse(
(json["value"] != null ? json["value"] : 0).toString()) * (json["value"] ?? 0).toString()) *
Decimal.fromInt(Constants.satsPerCoin(Coin Decimal.fromInt(Constants.satsPerCoin(Coin
.firo))) // dirty hack but we need 8 decimal places here to keep consistent data structure .firo))) // dirty hack but we need 8 decimal places here to keep consistent data structure
.toBigInt() .toBigInt()

View file

@ -2380,7 +2380,7 @@ class BitcoinCashWallet extends CoinServiceAPI {
for (final output in txObject["vout"] as List) { for (final output in txObject["vout"] as List) {
final address = getAddress(output); final address = getAddress(output);
if (address != null) { if (address != null) {
final value = (Decimal.parse(output["value"].toString()) * final value = (Decimal.parse((output["value"] ?? 0).toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin))) Decimal.fromInt(Constants.satsPerCoin(coin)))
.toBigInt() .toBigInt()
.toInt(); .toInt();

View file

@ -3320,7 +3320,7 @@ class FiroWallet extends CoinServiceAPI {
for (final output in txObject["vout"] as List) { for (final output in txObject["vout"] as List) {
final addresses = output["scriptPubKey"]["addresses"] as List?; final addresses = output["scriptPubKey"]["addresses"] as List?;
final value = output["value"]; final value = output["value"] ?? 0;
if (addresses != null && addresses.isNotEmpty) { if (addresses != null && addresses.isNotEmpty) {
final address = addresses[0] as String; final address = addresses[0] as String;
if (value != null) { if (value != null) {
@ -3359,7 +3359,7 @@ class FiroWallet extends CoinServiceAPI {
final addresses = output["scriptPubKey"]["addresses"] as List?; final addresses = output["scriptPubKey"]["addresses"] as List?;
if (addresses != null && addresses.isNotEmpty) { if (addresses != null && addresses.isNotEmpty) {
final address = addresses[0] as String; final address = addresses[0] as String;
final value = output["value"]; final value = output["value"] ?? 0;
// Logging.instance.log(address + value.toString()); // Logging.instance.log(address + value.toString());
if (allAddresses.contains(address)) { if (allAddresses.contains(address)) {

View file

@ -2565,8 +2565,7 @@ class LitecoinWallet extends CoinServiceAPI {
for (final output in txObject["vout"] as List) { for (final output in txObject["vout"] as List) {
final String address = final String address =
output["scriptPubKey"]!["addresses"][0] as String; final value = output["value"] ?? 0;
final value = output["value"]!;
final _value = (Decimal.parse(value.toString()) * final _value = (Decimal.parse(value.toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin))) Decimal.fromInt(Constants.satsPerCoin(coin)))
.toBigInt() .toBigInt()
@ -2592,7 +2591,7 @@ class LitecoinWallet extends CoinServiceAPI {
for (final output in txObject["vout"] as List) { for (final output in txObject["vout"] as List) {
final address = output["scriptPubKey"]["addresses"][0]; final address = output["scriptPubKey"]["addresses"][0];
if (address != null) { if (address != null) {
final value = (Decimal.parse(output["value"].toString()) * final value = (Decimal.parse((output["value"] ?? 0).toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin))) Decimal.fromInt(Constants.satsPerCoin(coin)))
.toBigInt() .toBigInt()
.toInt(); .toInt();

View file

@ -2554,7 +2554,7 @@ class NamecoinWallet extends CoinServiceAPI {
for (final output in txObject["vout"] as List) { for (final output in txObject["vout"] as List) {
Logging.instance.log(output, level: LogLevel.Info); Logging.instance.log(output, level: LogLevel.Info);
final address = output["scriptPubKey"]["address"]; final address = output["scriptPubKey"]["address"];
final value = output["value"]; final value = output["value"] ?? 0;
final _value = (Decimal.parse(value.toString()) * final _value = (Decimal.parse(value.toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin))) Decimal.fromInt(Constants.satsPerCoin(coin)))
.toBigInt() .toBigInt()
@ -2583,7 +2583,7 @@ class NamecoinWallet extends CoinServiceAPI {
address = output["scriptPubKey"]["address"] as String?; address = output["scriptPubKey"]["address"] as String?;
} }
if (address != null) { if (address != null) {
final value = (Decimal.parse(output["value"].toString()) * final value = (Decimal.parse((output["value"] ?? 0).toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin))) Decimal.fromInt(Constants.satsPerCoin(coin)))
.toBigInt() .toBigInt()
.toInt(); .toInt();

View file

@ -2361,7 +2361,7 @@ class ParticlWallet extends CoinServiceAPI {
try { try {
final String address = final String address =
output["scriptPubKey"]!["addresses"][0] as String; output["scriptPubKey"]!["addresses"][0] as String;
final value = output["value"]!; final value = output["value"] ?? 0;
final _value = (Decimal.parse(value.toString()) * final _value = (Decimal.parse(value.toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin))) Decimal.fromInt(Constants.satsPerCoin(coin)))
.toBigInt() .toBigInt()
@ -2419,7 +2419,7 @@ class ParticlWallet extends CoinServiceAPI {
try { try {
final address = output["scriptPubKey"]["addresses"][0]; final address = output["scriptPubKey"]["addresses"][0];
if (address != null) { if (address != null) {
final value = (Decimal.parse(output["value"].toString()) * final value = (Decimal.parse((output["value"] ?? 0).toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin))) Decimal.fromInt(Constants.satsPerCoin(coin)))
.toBigInt() .toBigInt()
.toInt(); .toInt();