diff --git a/lib/bloc/explorer/api_explorer.dart b/lib/bloc/explorer/api_explorer.dart index b0d29803..5bfd183f 100644 --- a/lib/bloc/explorer/api_explorer.dart +++ b/lib/bloc/explorer/api_explorer.dart @@ -138,8 +138,8 @@ class ApiExplorer { for (int i = 0; i < vttsToUpdate.length; i++) { try { - ValueTransferInfo vtt = await getVtt(vttsToUpdate[i]); - await db.addVtt(vtt); + ValueTransferInfo? vtt = await getVtt(vttsToUpdate[i]); + if (vtt != null) await db.addVtt(vtt); } catch (e) { print('Error adding vtt to database $e'); rethrow; @@ -194,9 +194,9 @@ class ApiExplorer { } /// get the ValueTransferInfo from the explorer for a given transaction ID. - Future getVtt(String transactionId) async { + Future getVtt(String transactionId) async { var result = await hash(transactionId); - return result as ValueTransferInfo; + return result as ValueTransferInfo?; } Future getMint(BlockInfo blockInfo) async { diff --git a/lib/bloc/explorer/explorer_bloc.dart b/lib/bloc/explorer/explorer_bloc.dart index dec9166e..7c0d19e6 100644 --- a/lib/bloc/explorer/explorer_bloc.dart +++ b/lib/bloc/explorer/explorer_bloc.dart @@ -337,14 +337,19 @@ class ExplorerBloc extends Bloc { ValueTransferInfo? vtt = walletStorage.getVtt(newVtt.hash); if (vtt != null) { if (vtt.status != TxStatusLabel.confirmed) { - ValueTransferInfo _vtt = await explorer.getVtt(newVtt.hash); + ValueTransferInfo? _vtt = await explorer.getVtt(newVtt.hash); + if (_vtt != null) { + walletStorage.setVtt( + database.walletStorage.currentWallet.id, _vtt); + database.addOrUpdateVttInDB(_vtt); + } + } + } else { + ValueTransferInfo? _vtt = await explorer.getVtt(newVtt.hash); + if (_vtt != null) { walletStorage.setVtt(database.walletStorage.currentWallet.id, _vtt); database.addOrUpdateVttInDB(_vtt); } - } else { - ValueTransferInfo _vtt = await explorer.getVtt(newVtt.hash); - walletStorage.setVtt(database.walletStorage.currentWallet.id, _vtt); - database.addOrUpdateVttInDB(_vtt); } } account.vttHashes.clear(); @@ -491,8 +496,8 @@ class ExplorerBloc extends Bloc { for (int i = 0; i < unconfirmedVtts.length; i++) { ValueTransferInfo _vtt = unconfirmedVtts[i]; try { - ValueTransferInfo vtt = await explorer.getVtt(_vtt.hash); - if (_vtt.status != vtt.status) { + ValueTransferInfo? vtt = await explorer.getVtt(_vtt.txnHash); + if (vtt != null && _vtt.status != vtt.status) { await database.updateVtt(wallet.id, vtt); } } catch (e) { @@ -523,7 +528,6 @@ class ExplorerBloc extends Bloc { await database.updateCurrentWallet( currentWalletId: wallet.id, isHdWallet: wallet.walletType == WalletType.hd); - print('FINISH SYNC'); return storage; } } diff --git a/lib/bloc/transactions/value_transfer/vtt_create/vtt_create_bloc.dart b/lib/bloc/transactions/value_transfer/vtt_create/vtt_create_bloc.dart index 44f5360e..9f3ed6f4 100644 --- a/lib/bloc/transactions/value_transfer/vtt_create/vtt_create_bloc.dart +++ b/lib/bloc/transactions/value_transfer/vtt_create/vtt_create_bloc.dart @@ -18,6 +18,7 @@ import 'package:my_wit_wallet/shared/locator.dart'; import 'package:my_wit_wallet/shared/api_database.dart'; import 'package:my_wit_wallet/util/storage/database/wallet.dart'; import 'package:my_wit_wallet/util/storage/database/account.dart'; +import 'dart:convert'; part 'vtt_create_event.dart'; part 'vtt_create_state.dart'; @@ -36,9 +37,10 @@ Future _sendTransaction(Transaction transaction) async { try { var resp = await Locator.instance.get().sendTransaction(transaction); - return resp['result']; + return resp['result'] != null ? true : false; } catch (e) { - print('Error sending transaction: $transaction $e'); + print( + 'Error sending transaction: ${json.encode(transaction.jsonMap(asHex: true))} $e'); return false; } } diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 6759ba0c..9b9f93ea 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -286,6 +286,7 @@ "valueTransferTxn": "Value Transfer", "mintTxn": "Mint", "confirmed": "Confirmed", + "mined": "Mined", "pending": "Pending", "reverted": "Reverted" } \ No newline at end of file diff --git a/lib/util/filter_utxos.dart b/lib/util/filter_utxos.dart index 2f9e88a7..437df9a9 100644 --- a/lib/util/filter_utxos.dart +++ b/lib/util/filter_utxos.dart @@ -1,23 +1,21 @@ import 'package:witnet/data_structures.dart'; import 'package:witnet/explorer.dart'; -import 'package:witnet/schema.dart'; List filterUsedUtxos( {required List utxoList, required List pendingVtts}) { List filteredUtxos = []; - List outputPointers = []; + List outputPointers = []; for (int i = 0; i < pendingVtts.length; i++) { - pendingVtts[i].inputAddresses.forEach((String inputAddress) { - //FIX: get output pointer from new value trasnfer schema - // outputPointers.add(input.input.outputPointer); + pendingVtts[i].inputUtxos.forEach((InputUtxo input) { + outputPointers.add(input.inputUtxo); }); } for (int i = 0; i < utxoList.length; i++) { Utxo currentUtxo = utxoList[i]; - if (!outputPointers.contains(currentUtxo.outputPointer)) { + if (!outputPointers.contains(currentUtxo.outputPointer.toString())) { filteredUtxos.add(currentUtxo); } } diff --git a/lib/util/storage/database/transaction_adapter.dart b/lib/util/storage/database/transaction_adapter.dart index ffa3478c..35df7ee0 100644 --- a/lib/util/storage/database/transaction_adapter.dart +++ b/lib/util/storage/database/transaction_adapter.dart @@ -108,7 +108,8 @@ class GeneralTransaction extends HashInfo { priority: valueTransferInfo.priority)); ValueTransferInfo toValueTransferInfo() => ValueTransferInfo( - block: blockHash, + block: blockHash ?? + '0000000000000000000000000000000000000000000000000000000000000000', fee: fee, inputUtxos: vtt?.inputs ?? [], outputs: vtt?.outputs ?? [], diff --git a/lib/util/storage/database/wallet.dart b/lib/util/storage/database/wallet.dart index 69a58d52..0e98a6b2 100644 --- a/lib/util/storage/database/wallet.dart +++ b/lib/util/storage/database/wallet.dart @@ -182,7 +182,7 @@ class Wallet { List pendingTransactions() { List pendingVtts = []; allTransactions().forEach((vtt) { - if (vtt.status == "pending") { + if (vtt.status == TxStatusLabel.pending) { pendingVtts.add(vtt); } }); diff --git a/lib/widgets/transaction_details.dart b/lib/widgets/transaction_details.dart index 57880ce9..23f6726c 100644 --- a/lib/widgets/transaction_details.dart +++ b/lib/widgets/transaction_details.dart @@ -64,6 +64,8 @@ class TransactionDetails extends StatelessWidget { switch (status) { case TxStatusLabel.confirmed: return localization.confirmed; + case TxStatusLabel.mined: + return localization.mined; case TxStatusLabel.pending: return localization.pending; case TxStatusLabel.reverted: diff --git a/test/util/transactions_list/get_transaction_address_test.dart b/test/util/transactions_list/get_transaction_address_test.dart index 252f4a07..ef5221f0 100644 --- a/test/util/transactions_list/get_transaction_address_test.dart +++ b/test/util/transactions_list/get_transaction_address_test.dart @@ -12,23 +12,20 @@ void main() { List inputs = [ InputUtxo( address: 'wit1zl7ty0lwr7atp5fu34azkgewhtfx2fl4wv69cw', - input: Input( - outputPointer: OutputPointer.fromString( - '59e4dc54077871e71875a4b840da67c23659d89d41eaad85cdb9a5d552254b5d:9')), + inputUtxo: + '59e4dc54077871e71875a4b840da67c23659d89d41eaad85cdb9a5d552254b5d:9', value: 10180697116), ]; List severalInputs = [ InputUtxo( address: 'wit1zl7ty0lwr7atp5fu34azkgewhtfx2fl4wv69cw', - input: Input( - outputPointer: OutputPointer.fromString( - '59e4dc54077871e71875a4b840da67c23659d89d41eaad85cdb9a5d552254b5d:9')), + inputUtxo: + '59e4dc54077871e71875a4b840da67c23659d89d41eaad85cdb9a5d552254b5d:9', value: 10180697116), InputUtxo( address: 'wit2zl7ty0lwr7atp5fu34azkgewhtfx2fl4wv69cw', - input: Input( - outputPointer: OutputPointer.fromString( - '59e4dc54077871e71875a4b840da67c23659d89d41eaad85cdb9a5d552254b5d:9')), + inputUtxo: + '59e4dc54077871e71875a4b840da67c23659d89d41eaad85cdb9a5d552254b5d:9', value: 10180697116) ]; List outputs = [ diff --git a/test/util/transactions_list/get_transaction_label_test.dart b/test/util/transactions_list/get_transaction_label_test.dart index 83b6cb8c..ddd82a4b 100644 --- a/test/util/transactions_list/get_transaction_label_test.dart +++ b/test/util/transactions_list/get_transaction_label_test.dart @@ -2,7 +2,6 @@ import 'package:my_wit_wallet/util/storage/database/account.dart'; import 'package:my_wit_wallet/util/transactions_list/get_transaction_label.dart'; import 'package:test/test.dart'; import 'package:witnet/explorer.dart'; -import 'package:witnet/schema.dart'; void main() { List externalAddresses = [ @@ -22,9 +21,8 @@ void main() { List inputs = [ InputUtxo( address: 'wit1zl7ty0lwr7atp5fu34azkgewhtfx2fl4wv69cw', - input: Input( - outputPointer: OutputPointer.fromString( - '59e4dc54077871e71875a4b840da67c23659d89d41eaad85cdb9a5d552254b5d:9')), + inputUtxo: + '59e4dc54077871e71875a4b840da67c23659d89d41eaad85cdb9a5d552254b5d:9', value: 10180697116), ];