Skip to content

Commit

Permalink
fix: update ui to send vtt with explorer v1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Feb 14, 2024
1 parent 9bcd0a9 commit ce741b5
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 35 deletions.
8 changes: 4 additions & 4 deletions lib/bloc/explorer/api_explorer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -194,9 +194,9 @@ class ApiExplorer {
}

/// get the ValueTransferInfo from the explorer for a given transaction ID.
Future<ValueTransferInfo> getVtt(String transactionId) async {
Future<ValueTransferInfo?> getVtt(String transactionId) async {
var result = await hash(transactionId);
return result as ValueTransferInfo;
return result as ValueTransferInfo?;
}

Future<MintEntry> getMint(BlockInfo blockInfo) async {
Expand Down
20 changes: 12 additions & 8 deletions lib/bloc/explorer/explorer_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,19 @@ class ExplorerBloc extends Bloc<ExplorerEvent, ExplorerState> {
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();
Expand Down Expand Up @@ -491,8 +496,8 @@ class ExplorerBloc extends Bloc<ExplorerEvent, ExplorerState> {
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) {
Expand Down Expand Up @@ -523,7 +528,6 @@ class ExplorerBloc extends Bloc<ExplorerEvent, ExplorerState> {
await database.updateCurrentWallet(
currentWalletId: wallet.id,
isHdWallet: wallet.walletType == WalletType.hd);
print('FINISH SYNC');
return storage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -36,9 +37,10 @@ Future<bool> _sendTransaction(Transaction transaction) async {
try {
var resp =
await Locator.instance.get<ApiExplorer>().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;
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"valueTransferTxn": "Value Transfer",
"mintTxn": "Mint",
"confirmed": "Confirmed",
"mined": "Mined",
"pending": "Pending",
"reverted": "Reverted"
}
10 changes: 4 additions & 6 deletions lib/util/filter_utxos.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import 'package:witnet/data_structures.dart';
import 'package:witnet/explorer.dart';
import 'package:witnet/schema.dart';

List<Utxo> filterUsedUtxos(
{required List<Utxo> utxoList,
required List<ValueTransferInfo> pendingVtts}) {
List<Utxo> filteredUtxos = [];
List<OutputPointer> outputPointers = [];
List<String> 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);
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/util/storage/database/transaction_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? [],
Expand Down
2 changes: 1 addition & 1 deletion lib/util/storage/database/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Wallet {
List<ValueTransferInfo> pendingTransactions() {
List<ValueTransferInfo> pendingVtts = [];
allTransactions().forEach((vtt) {
if (vtt.status == "pending") {
if (vtt.status == TxStatusLabel.pending) {
pendingVtts.add(vtt);
}
});
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/transaction_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 6 additions & 9 deletions test/util/transactions_list/get_transaction_address_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@ void main() {
List<InputUtxo> inputs = [
InputUtxo(
address: 'wit1zl7ty0lwr7atp5fu34azkgewhtfx2fl4wv69cw',
input: Input(
outputPointer: OutputPointer.fromString(
'59e4dc54077871e71875a4b840da67c23659d89d41eaad85cdb9a5d552254b5d:9')),
inputUtxo:
'59e4dc54077871e71875a4b840da67c23659d89d41eaad85cdb9a5d552254b5d:9',
value: 10180697116),
];
List<InputUtxo> 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<ValueTransferOutput> outputs = [
Expand Down
6 changes: 2 additions & 4 deletions test/util/transactions_list/get_transaction_label_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> externalAddresses = [
Expand All @@ -22,9 +21,8 @@ void main() {
List<InputUtxo> inputs = [
InputUtxo(
address: 'wit1zl7ty0lwr7atp5fu34azkgewhtfx2fl4wv69cw',
input: Input(
outputPointer: OutputPointer.fromString(
'59e4dc54077871e71875a4b840da67c23659d89d41eaad85cdb9a5d552254b5d:9')),
inputUtxo:
'59e4dc54077871e71875a4b840da67c23659d89d41eaad85cdb9a5d552254b5d:9',
value: 10180697116),
];

Expand Down

0 comments on commit ce741b5

Please sign in to comment.