Fix Epiccash caching issue, add additional status messages as in Epicpay

This commit is contained in:
likho 2023-05-28 14:57:05 +02:00
parent e526bb4fe6
commit 83778bb121
20 changed files with 81 additions and 19 deletions

View file

@ -12,6 +12,7 @@ part 'transaction.g.dart';
@Collection() @Collection()
class Transaction { class Transaction {
Transaction({ Transaction({
required this.walletId, required this.walletId,
required this.txid, required this.txid,
@ -29,6 +30,7 @@ class Transaction {
required this.inputs, required this.inputs,
required this.outputs, required this.outputs,
required this.nonce, required this.nonce,
required this.numberOfMessages,
}); });
Tuple2<Transaction, Address?> copyWith({ Tuple2<Transaction, Address?> copyWith({
@ -50,6 +52,7 @@ class Transaction {
int? nonce, int? nonce,
Id? id, Id? id,
Address? address, Address? address,
int? numberOfMessages,
}) { }) {
return Tuple2( return Tuple2(
Transaction( Transaction(
@ -68,7 +71,8 @@ class Transaction {
otherData: otherData ?? this.otherData, otherData: otherData ?? this.otherData,
nonce: nonce ?? this.nonce, nonce: nonce ?? this.nonce,
inputs: inputs ?? this.inputs, inputs: inputs ?? this.inputs,
outputs: outputs ?? this.outputs) outputs: outputs ?? this.outputs,
numberOfMessages: numberOfMessages ?? this.numberOfMessages)
..id = id ?? this.id, ..id = id ?? this.id,
address ?? this.address.value, address ?? this.address.value,
); );
@ -114,6 +118,8 @@ class Transaction {
late final List<Output> outputs; late final List<Output> outputs;
late final int? numberOfMessages;
@Backlink(to: "transactions") @Backlink(to: "transactions")
final address = IsarLink<Address>(); final address = IsarLink<Address>();
@ -154,6 +160,7 @@ class Transaction {
"address: ${address.value}, " "address: ${address.value}, "
"inputsLength: ${inputs.length}, " "inputsLength: ${inputs.length}, "
"outputsLength: ${outputs.length}, " "outputsLength: ${outputs.length}, "
"numberOfMessages: $numberOfMessages, "
"}"; "}";
String toJsonString() { String toJsonString() {
@ -175,6 +182,7 @@ class Transaction {
"address": address.value?.toJsonString(), "address": address.value?.toJsonString(),
"inputs": inputs.map((e) => e.toJsonString()).toList(), "inputs": inputs.map((e) => e.toJsonString()).toList(),
"outputs": outputs.map((e) => e.toJsonString()).toList(), "outputs": outputs.map((e) => e.toJsonString()).toList(),
"numberOfMessages": numberOfMessages,
}; };
return jsonEncode(result); return jsonEncode(result);
} }
@ -205,6 +213,7 @@ class Transaction {
outputs: List<String>.from(json["outputs"] as List) outputs: List<String>.from(json["outputs"] as List)
.map((e) => Output.fromJsonString(e)) .map((e) => Output.fromJsonString(e))
.toList(), .toList(),
numberOfMessages: json["numberOfMessages"] as int,
); );
if (json["address"] == null) { if (json["address"] == null) {
return Tuple2(transaction, null); return Tuple2(transaction, null);

View file

@ -286,6 +286,7 @@ Transaction _transactionDeserialize(
type: _TransactiontypeValueEnumMap[reader.readByteOrNull(offsets[14])] ?? type: _TransactiontypeValueEnumMap[reader.readByteOrNull(offsets[14])] ??
TransactionType.outgoing, TransactionType.outgoing,
walletId: reader.readString(offsets[15]), walletId: reader.readString(offsets[15]),
numberOfMessages: reader.readLong(offsets[2]),
); );
object.id = id; object.id = id;
return object; return object;

View file

@ -155,6 +155,9 @@ class Transaction {
// @HiveField(18) // @HiveField(18)
final String? otherData; final String? otherData;
// @HiveField(16)
final int? numberOfMessages;
Transaction({ Transaction({
required this.txid, required this.txid,
required this.confirmedStatus, required this.confirmedStatus,
@ -176,6 +179,7 @@ class Transaction {
this.isCancelled = false, this.isCancelled = false,
this.slateId, this.slateId,
this.otherData, this.otherData,
this.numberOfMessages,
}); });
factory Transaction.fromJson(Map<String, dynamic> json) { factory Transaction.fromJson(Map<String, dynamic> json) {
@ -211,6 +215,7 @@ class Transaction {
isCancelled: json["isCancelled"] as bool? ?? false, isCancelled: json["isCancelled"] as bool? ?? false,
slateId: json["slateId"] as String?, slateId: json["slateId"] as String?,
otherData: json["otherData"] as String?, otherData: json["otherData"] as String?,
numberOfMessages: json["numberOfMessages"] as int?,
); );
} }
@ -269,6 +274,7 @@ class Transaction {
bool? isCancelled, bool? isCancelled,
String? slateId, String? slateId,
String? otherData, String? otherData,
int? numberOfMessages,
}) { }) {
return Transaction( return Transaction(
txid: txid ?? this.txid, txid: txid ?? this.txid,
@ -292,13 +298,14 @@ class Transaction {
isCancelled: isCancelled ?? this.isCancelled, isCancelled: isCancelled ?? this.isCancelled,
slateId: slateId ?? this.slateId, slateId: slateId ?? this.slateId,
otherData: otherData ?? this.otherData, otherData: otherData ?? this.otherData,
numberOfMessages: numberOfMessages ?? this.numberOfMessages,
); );
} }
@override @override
String toString() { String toString() {
String transaction = String transaction =
"{txid: $txid, type: $txType, subType: $subType, value: $amount, fee: $fees, height: $height, confirm: $confirmedStatus, confirmations: $confirmations, address: $address, timestamp: $timestamp, worthNow: $worthNow, inputs: $inputs, slateid: $slateId }"; "{txid: $txid, type: $txType, subType: $subType, value: $amount, fee: $fees, height: $height, confirm: $confirmedStatus, confirmations: $confirmations, address: $address, timestamp: $timestamp, worthNow: $worthNow, inputs: $inputs, slateid: $slateId, numberOfMessages: $numberOfMessages }";
return transaction; return transaction;
} }
} }

View file

@ -93,12 +93,7 @@ class _TransactionsListState extends ConsumerState<TransactionsList> {
children: [ children: [
TransactionCard( TransactionCard(
// this may mess with combined firo transactions // this may mess with combined firo transactions
key: isConfirmed key: UniqueKey(), //
? Key(tx.txid +
tx.type.name +
tx.address.value.toString() +
tx.height.toString())
: UniqueKey(), //
transaction: tx, transaction: tx,
walletId: widget.walletId, walletId: widget.walletId,
), ),
@ -193,12 +188,7 @@ class _TransactionsListState extends ConsumerState<TransactionsList> {
), ),
child: TransactionCard( child: TransactionCard(
// this may mess with combined firo transactions // this may mess with combined firo transactions
key: isConfirmed key: UniqueKey(),
? Key(tx.txid +
tx.type.name +
tx.address.value.toString() +
tx.height.toString())
: UniqueKey(),
transaction: tx, transaction: tx,
walletId: widget.walletId, walletId: widget.walletId,
), ),

View file

@ -126,6 +126,37 @@ class _TransactionDetailsViewState
} }
} }
if (coin == Coin.epicCash) {
if (_transaction.isCancelled) {
return "Cancelled";
} else if (type == TransactionType.incoming) {
if (tx.isConfirmed(height, coin.requiredConfirmations)) {
return "Received";
} else {
if (_transaction.numberOfMessages == 1) {
return "Receiving (waiting for sender)";
} else if ((_transaction.numberOfMessages ?? 0) > 1) {
return
"Receiving (waiting for confirmations)"; // TODO test if the sender still has to open again after the receiver has 2 messages present, ie. sender->receiver->sender->node (yes) vs. sender->receiver->node (no)
} else {
return "Receiving";
}
}
} else if (type == TransactionType.outgoing) {
if (tx.isConfirmed(height, coin.requiredConfirmations)) {
return "Sent (confirmed)";
} else {
if (_transaction.numberOfMessages == 1) {
return "Sending (waiting for receiver)";
} else if ((_transaction.numberOfMessages ?? 0) > 1) {
return "Sending (waiting for confirmations)";
} else {
return "Sending";
}
}
}
}
if (type == TransactionType.incoming) { if (type == TransactionType.incoming) {
// if (_transaction.isMinting) { // if (_transaction.isMinting) {
// return "Minting"; // return "Minting";

View file

@ -1288,6 +1288,7 @@ class BitcoinWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
final address = txData["address"] is String final address = txData["address"] is String

View file

@ -1153,6 +1153,7 @@ class BitcoinCashWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
final address = txData["address"] is String final address = txData["address"] is String
@ -2137,6 +2138,7 @@ class BitcoinCashWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: inputs, inputs: inputs,
outputs: outputs, outputs: outputs,
numberOfMessages: null,
); );
txns.add(Tuple2(tx, transactionAddress)); txns.add(Tuple2(tx, transactionAddress));

View file

@ -1140,6 +1140,7 @@ class DogecoinWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
final address = txData["address"] is String final address = txData["address"] is String

View file

@ -1365,6 +1365,7 @@ class ECashWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: inputs, inputs: inputs,
outputs: outputs, outputs: outputs,
numberOfMessages: null,
); );
txns.add(Tuple2(tx, transactionAddress)); txns.add(Tuple2(tx, transactionAddress));
@ -2770,6 +2771,7 @@ class ECashWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
final address = txData["address"] is String final address = txData["address"] is String

View file

@ -1153,10 +1153,6 @@ class EpicCashWallet extends CoinServiceAPI
Future<bool> startScans() async { Future<bool> startScans() async {
try { try {
if (ListenerManager.pointer != null) { if (ListenerManager.pointer != null) {
Logging.instance
.log("LISTENER HANDLER IS NOT NULL ....", level: LogLevel.Info);
Logging.instance
.log("STOPPING ANY WALLET LISTENER ....", level: LogLevel.Info);
epicboxListenerStop(ListenerManager.pointer!); epicboxListenerStop(ListenerManager.pointer!);
} }
@ -1643,7 +1639,7 @@ class EpicCashWallet extends CoinServiceAPI
Future<void> _refreshTransactions() async { Future<void> _refreshTransactions() async {
// final currentChainHeight = await chainHeight; // final currentChainHeight = await chainHeight;
final wallet = await _secureStore.read(key: '${_walletId}_wallet'); final wallet = await _secureStore.read(key: '${_walletId}_wallet');
const refreshFromNode = 0; const refreshFromNode = 1;
dynamic message; dynamic message;
await m.protect(() async { await m.protect(() async {
@ -1709,6 +1705,7 @@ class EpicCashWallet extends CoinServiceAPI
?[tx["tx_type"] == "TxReceived" ? "from" : "to"] as String? ?? ?[tx["tx_type"] == "TxReceived" ? "from" : "to"] as String? ??
""; "";
String? commitId = slatesToCommits[slateId]?['commitId'] as String?; String? commitId = slatesToCommits[slateId]?['commitId'] as String?;
tx['numberOfMessages'] = tx['messages']?['messages']?.length;
int? height; int? height;
@ -1721,6 +1718,7 @@ class EpicCashWallet extends CoinServiceAPI
final isIncoming = (tx["tx_type"] == "TxReceived" || final isIncoming = (tx["tx_type"] == "TxReceived" ||
tx["tx_type"] == "TxReceivedCancelled"); tx["tx_type"] == "TxReceivedCancelled");
final txn = isar_models.Transaction( final txn = isar_models.Transaction(
walletId: walletId, walletId: walletId,
txid: commitId ?? tx["id"].toString(), txid: commitId ?? tx["id"].toString(),
@ -1744,6 +1742,7 @@ class EpicCashWallet extends CoinServiceAPI
otherData: tx["id"].toString(), otherData: tx["id"].toString(),
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: ((tx["numberOfMessages"] == null) ? 0 : tx["numberOfMessages"]) as int,
); );
// txn.address = // txn.address =

View file

@ -944,6 +944,7 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB {
response.value?.nonce.toBigIntFromHex.toInt(), response.value?.nonce.toBigIntFromHex.toInt(),
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
Address? address = await db.getAddress( Address? address = await db.getAddress(
@ -1035,6 +1036,7 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB {
nonce: tuple.item2, nonce: tuple.item2,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
Address? transactionAddress = await db Address? transactionAddress = await db

View file

@ -449,6 +449,7 @@ Future<Map<dynamic, dynamic>> staticProcessRestore(
nonce: null, nonce: null,
inputs: element.inputs, inputs: element.inputs,
outputs: element.outputs, outputs: element.outputs,
numberOfMessages: null,
)..address.value = element.address.value; )..address.value = element.address.value;
} }
}); });
@ -891,6 +892,7 @@ class FiroWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
final address = txData["address"] is String final address = txData["address"] is String
@ -3033,6 +3035,7 @@ class FiroWallet extends CoinServiceAPI
otherData: transactionInfo["otherData"] as String?, otherData: transactionInfo["otherData"] as String?,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
final transactionAddress = await db final transactionAddress = await db
@ -3513,6 +3516,7 @@ class FiroWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: ins, inputs: ins,
outputs: [], outputs: [],
numberOfMessages: null,
); );
txnsData.add(Tuple2(tx, null)); txnsData.add(Tuple2(tx, null));
@ -3635,6 +3639,7 @@ class FiroWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: ins, inputs: ins,
outputs: outs, outputs: outs,
numberOfMessages: null,
); );
txnsData.add(Tuple2(tx, transactionAddress)); txnsData.add(Tuple2(tx, transactionAddress));
@ -3786,6 +3791,7 @@ class FiroWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: ins, inputs: ins,
outputs: outs, outputs: outs,
numberOfMessages: null,
); );
txnsData.add(Tuple2(tx, transactionAddress)); txnsData.add(Tuple2(tx, transactionAddress));
@ -5064,6 +5070,7 @@ class FiroWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
final address = await db final address = await db

View file

@ -1271,6 +1271,7 @@ class LitecoinWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
final address = txData["address"] is String final address = txData["address"] is String

View file

@ -954,6 +954,7 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
nonce: null, nonce: null,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
txnsData.add(Tuple2(txn, address)); txnsData.add(Tuple2(txn, address));

View file

@ -1260,6 +1260,7 @@ class NamecoinWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
final address = txData["address"] is String final address = txData["address"] is String

View file

@ -1188,6 +1188,7 @@ class ParticlWallet extends CoinServiceAPI
nonce: null, nonce: null,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
final address = txData["address"] is String final address = txData["address"] is String
@ -2391,6 +2392,7 @@ class ParticlWallet extends CoinServiceAPI
nonce: null, nonce: null,
slateId: null, slateId: null,
otherData: null, otherData: null,
numberOfMessages: null,
); );
txns.add(Tuple2(tx, transactionAddress)); txns.add(Tuple2(tx, transactionAddress));

View file

@ -1041,6 +1041,7 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
nonce: null, nonce: null,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
txnsData.add(Tuple2(txn, address)); txnsData.add(Tuple2(txn, address));

View file

@ -169,6 +169,7 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
response.value?.nonce.toBigIntFromHex.toInt(), response.value?.nonce.toBigIntFromHex.toInt(),
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
Address? address = await ethWallet.db.getAddress( Address? address = await ethWallet.db.getAddress(
@ -519,6 +520,7 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
otherData: tuple.item1.address, otherData: tuple.item1.address,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: null,
); );
Address? transactionAddress = await ethWallet.db Address? transactionAddress = await ethWallet.db

View file

@ -258,6 +258,7 @@ mixin ElectrumXParsing {
nonce: null, nonce: null,
inputs: ins, inputs: ins,
outputs: outs, outputs: outs,
numberOfMessages: null,
); );
return Tuple2(tx, transactionAddress); return Tuple2(tx, transactionAddress);

View file

@ -397,6 +397,7 @@ class DbVersionMigrator with WalletDB {
nonce: null, nonce: null,
inputs: [], inputs: [],
outputs: [], outputs: [],
numberOfMessages: tx.numberOfMessages,
); );
if (tx.address.isEmpty) { if (tx.address.isEmpty) {