From 8efe70fb24b7cc101941716609438757c9177c3b Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Fri, 12 Jul 2024 13:40:37 -0700 Subject: [PATCH] save [skip ci] --- .../lib/bitcoin_transaction_priority.dart | 2 +- cw_bitcoin/lib/litecoin_wallet.dart | 47 ++++--- .../dashboard/pages/transactions_page.dart | 10 +- .../dashboard/widgets/transaction_raw.dart | 116 +++++++++++------- .../widgets/unspent_coins_list_item.dart | 87 ++++++++----- .../dashboard/transaction_list_item.dart | 22 +++- 6 files changed, 181 insertions(+), 103 deletions(-) diff --git a/cw_bitcoin/lib/bitcoin_transaction_priority.dart b/cw_bitcoin/lib/bitcoin_transaction_priority.dart index 7c4dcfd5f..d1f45a545 100644 --- a/cw_bitcoin/lib/bitcoin_transaction_priority.dart +++ b/cw_bitcoin/lib/bitcoin_transaction_priority.dart @@ -87,7 +87,7 @@ class LitecoinTransactionPriority extends BitcoinTransactionPriority { } @override - String get units => 'Latoshi'; + String get units => 'Litoshi'; @override String toString() { diff --git a/cw_bitcoin/lib/litecoin_wallet.dart b/cw_bitcoin/lib/litecoin_wallet.dart index 81b354e7a..4bafaff26 100644 --- a/cw_bitcoin/lib/litecoin_wallet.dart +++ b/cw_bitcoin/lib/litecoin_wallet.dart @@ -178,6 +178,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { if (resp.mwebUtxosHeight > mwebUtxosHeight) { mwebUtxosHeight = resp.mwebUtxosHeight; await checkMwebUtxosSpent(); + // update the confirmations for each transaction: for (final transaction in transactionHistory.transactions.values) { if (transaction.isPending) continue; final confirmations = mwebUtxosHeight - transaction.height + 1; @@ -266,6 +267,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { } if (!(tx.inputAddresses?.contains(utxo.address) ?? false)) { addressRecord.txCount++; + print("COUNT UPDATED HERE 2!!!!! ${addressRecord.txCount}"); } addressRecord.balance += utxo.value.toInt(); addressRecord.setAsUsed(); @@ -283,6 +285,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { final req = UtxosRequest(scanSecret: hex.decode(scanSecret), fromHeight: restoreHeight); bool initDone = false; + // process old utxos: for (final utxo in mwebUtxosBox.values) { if (utxo.address.isEmpty) { initDone = true; @@ -305,6 +308,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { } } + // process new utxos as they come in: await for (Utxo sUtxo in _stub.utxos(req)) { final utxo = MwebUtxo( address: sUtxo.address, @@ -327,6 +331,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { final mwebAddrs = (walletAddresses as LitecoinWalletAddresses).mwebAddrs; + // don't process utxos with addresses that are not in the mwebAddrs list: if (utxo.address.isNotEmpty && !mwebAddrs.contains(utxo.address)) { continue; } @@ -362,7 +367,10 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { if (utxo == null) continue; final addressRecord = walletAddresses.allAddresses .firstWhere((addressRecord) => addressRecord.address == utxo.address); - if (!inputAddresses.contains(utxo.address)) addressRecord.txCount++; + if (!inputAddresses.contains(utxo.address)) { + addressRecord.txCount++; + print("COUNT UPDATED HERE 3!!!!! ${addressRecord.address} ${addressRecord.txCount} !!!!!!"); + } addressRecord.balance -= utxo.value.toInt(); amount += utxo.value.toInt(); inputAddresses.add(utxo.address); @@ -471,6 +479,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { @override Future fetchBalances() async { + print("FETCH BALANCES"); final balance = await super.fetchBalances(); var confirmed = balance.confirmed; var unconfirmed = balance.unconfirmed; @@ -523,6 +532,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { continue; } addressRecord.txCount++; + print("COUNT UPDATED HERE 0!!!!! ${addressRecord.address} ${addressRecord.txCount} !!!!!!"); } } @@ -644,23 +654,26 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { tx.outputs = resp.outputId; return tx ..addListener((transaction) async { - final addresses = {}; - transaction.inputAddresses?.forEach((id) async { - final utxo = mwebUtxosBox.get(id); - await mwebUtxosBox.delete(id); - if (utxo == null) return; - final addressRecord = walletAddresses.allAddresses - .firstWhere((addressRecord) => addressRecord.address == utxo.address); - if (!addresses.contains(utxo.address)) { - addressRecord.txCount++; - addresses.add(utxo.address); - } - addressRecord.balance -= utxo.value.toInt(); - }); - transaction.inputAddresses?.addAll(addresses); - print("BEING ADDED HERE@@@@@@@@@@@@@@@@@@@@@@@3"); + print("LISTENER CALLED @@@@@@@@@@@@@@@@@@"); + // final addresses = {}; + // transaction.inputAddresses?.forEach((id) async { + // final utxo = mwebUtxosBox.get(id); + // await mwebUtxosBox.delete(id); + // if (utxo == null) return; + // final addressRecord = walletAddresses.allAddresses + // .firstWhere((addressRecord) => addressRecord.address == utxo.address); + // if (!addresses.contains(utxo.address)) { + // addressRecord.txCount++; + // print("COUNT UPDATED HERE 1!!!!! ${addressRecord.address} ${addressRecord.txCount} !!!!!!"); + // addresses.add(utxo.address); + // } + // addressRecord.balance -= utxo.value.toInt(); + // }); + // transaction.inputAddresses?.addAll(addresses); + // print("BEING ADDED HERE@@@@@@@@@@@@@@@@@@@@@@@3"); - transactionHistory.addOne(transaction); + // transactionHistory.addOne(transaction); + // await transactionHistory.save(); await updateUnspent(); await updateBalance(); }); diff --git a/lib/src/screens/dashboard/pages/transactions_page.dart b/lib/src/screens/dashboard/pages/transactions_page.dart index 7c0e9cad4..6d76a3184 100644 --- a/lib/src/screens/dashboard/pages/transactions_page.dart +++ b/lib/src/screens/dashboard/pages/transactions_page.dart @@ -52,7 +52,7 @@ class TransactionsPage extends StatelessWidget { try { final uri = Uri.parse( "https://guides.cakewallet.com/docs/FAQ/why_are_my_funds_not_appearing/"); - launchUrl(uri, mode: LaunchMode.externalApplication); + launchUrl(uri, mode: LaunchMode.externalApplication); } catch (_) {} }, title: S.of(context).syncing_wallet_alert_title, @@ -83,10 +83,6 @@ class TransactionsPage extends StatelessWidget { } final transaction = item.transaction; - final transactionType = dashboardViewModel.type == WalletType.ethereum && - transaction.evmSignatureName == 'approval' - ? ' (${transaction.evmSignatureName})' - : ''; return Observer( builder: (_) => TransactionRow( @@ -101,7 +97,9 @@ class TransactionsPage extends StatelessWidget { : item.formattedFiatAmount, isPending: transaction.isPending, title: item.formattedTitle + - item.formattedStatus + ' $transactionType', + item.formattedStatus + + ' ${item.formattedType}', + tag: item.tag, ), ); } diff --git a/lib/src/screens/dashboard/widgets/transaction_raw.dart b/lib/src/screens/dashboard/widgets/transaction_raw.dart index 3a95b9f2e..7dd59bc52 100644 --- a/lib/src/screens/dashboard/widgets/transaction_raw.dart +++ b/lib/src/screens/dashboard/widgets/transaction_raw.dart @@ -5,14 +5,16 @@ import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart'; import 'package:cake_wallet/themes/extensions/transaction_trade_theme.dart'; class TransactionRow extends StatelessWidget { - TransactionRow( - {required this.direction, - required this.formattedDate, - required this.formattedAmount, - required this.formattedFiatAmount, - required this.isPending, - required this.title, - required this.onTap}); + TransactionRow({ + required this.direction, + required this.formattedDate, + required this.formattedAmount, + required this.formattedFiatAmount, + required this.isPending, + required this.title, + required this.onTap, + required this.tag, + }); final VoidCallback onTap; final TransactionDirection direction; @@ -21,6 +23,7 @@ class TransactionRow extends StatelessWidget { final String formattedFiatAmount; final bool isPending; final String title; + final String tag; @override Widget build(BuildContext context) { @@ -38,48 +41,69 @@ class TransactionRow extends StatelessWidget { width: 36, decoration: BoxDecoration( shape: BoxShape.circle, - color: Theme.of(context).extension()!.rowsColor - ), - child: Image.asset( - direction == TransactionDirection.incoming - ? 'assets/images/down_arrow.png' - : 'assets/images/up_arrow.png'), + color: Theme.of(context).extension()!.rowsColor), + child: Image.asset(direction == TransactionDirection.incoming + ? 'assets/images/down_arrow.png' + : 'assets/images/up_arrow.png'), ), SizedBox(width: 12), Expanded( child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(title, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w500, - color: Theme.of(context).extension()!.textColor)), - Text(formattedAmount, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w500, - color: Theme.of(context).extension()!.textColor)) - ]), - SizedBox(height: 5), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(formattedDate, - style: TextStyle( - fontSize: 14, - color: Theme.of(context).extension()!.dateSectionRowColor)), - Text(formattedFiatAmount, - style: TextStyle( - fontSize: 14, - color: Theme.of(context).extension()!.dateSectionRowColor)) - ]) - ], - ) - ) + mainAxisSize: MainAxisSize.min, + children: [ + Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + Text( + title, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w500, + color: Theme.of(context).extension()!.textColor), + ), + Row( + children: [ + if (tag.isNotEmpty) + Container( + height: 17, + padding: EdgeInsets.only(left: 6, right: 6), + margin: EdgeInsets.only(right: 6), + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(8.5)), + color: Colors.white), + alignment: Alignment.center, + child: Text( + tag, + style: TextStyle( + color: Colors.black, + fontSize: 7, + fontWeight: FontWeight.w600, + ), + ), + ), + Text( + formattedAmount, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w500, + color: Theme.of(context).extension()!.textColor), + ), + ], + ), + ]), + SizedBox(height: 5), + Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + Text(formattedDate, + style: TextStyle( + fontSize: 14, + color: + Theme.of(context).extension()!.dateSectionRowColor)), + Text(formattedFiatAmount, + style: TextStyle( + fontSize: 14, + color: + Theme.of(context).extension()!.dateSectionRowColor)) + ]) + ], + )) ], ), )); diff --git a/lib/src/screens/unspent_coins/widgets/unspent_coins_list_item.dart b/lib/src/screens/unspent_coins/widgets/unspent_coins_list_item.dart index 60a23c99b..236d06f4e 100644 --- a/lib/src/screens/unspent_coins/widgets/unspent_coins_list_item.dart +++ b/lib/src/screens/unspent_coins/widgets/unspent_coins_list_item.dart @@ -103,40 +103,63 @@ class UnspentCoinsListItem extends StatelessWidget { ), maxLines: 1, ), - if (isChange) - Container( - height: 17, - padding: EdgeInsets.only(left: 6, right: 6), - decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(8.5)), - color: Colors.white), - alignment: Alignment.center, - child: Text( - S.of(context).unspent_change, - style: TextStyle( - color: itemColor, - fontSize: 7, - fontWeight: FontWeight.w600, + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + if (isChange) + Container( + height: 17, + padding: EdgeInsets.only(left: 6, right: 6), + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(8.5)), + color: Colors.white), + alignment: Alignment.center, + child: Text( + S.of(context).unspent_change, + style: TextStyle( + color: itemColor, + fontSize: 7, + fontWeight: FontWeight.w600, + ), + ), ), - ), - ), - if (isSilentPayment) - Container( - height: 17, - padding: EdgeInsets.only(left: 6, right: 6), - decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(8.5)), - color: Colors.white), - alignment: Alignment.center, - child: Text( - S.of(context).silent_payments, - style: TextStyle( - color: itemColor, - fontSize: 7, - fontWeight: FontWeight.w600, + if (address.toLowerCase().contains("mweb")) + Container( + height: 17, + padding: EdgeInsets.only(left: 6, right: 6), + margin: EdgeInsets.only(left: 6), + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(8.5)), + color: Colors.white), + alignment: Alignment.center, + child: Text( + "MWEB", + style: TextStyle( + color: itemColor, + fontSize: 7, + fontWeight: FontWeight.w600, + ), + ), ), - ), - ), + if (isSilentPayment) + Container( + height: 17, + padding: EdgeInsets.only(left: 6, right: 6), + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(8.5)), + color: Colors.white), + alignment: Alignment.center, + child: Text( + S.of(context).silent_payments, + style: TextStyle( + color: itemColor, + fontSize: 7, + fontWeight: FontWeight.w600, + ), + ), + ), + ], + ), ], ), ), diff --git a/lib/view_model/dashboard/transaction_list_item.dart b/lib/view_model/dashboard/transaction_list_item.dart index 176b4e58d..56c85737b 100644 --- a/lib/view_model/dashboard/transaction_list_item.dart +++ b/lib/view_model/dashboard/transaction_list_item.dart @@ -56,7 +56,8 @@ class TransactionListItem extends ActionListItem with Keyable { } String get formattedPendingStatus { - if (balanceViewModel.wallet.type == WalletType.monero || balanceViewModel.wallet.type == WalletType.haven) { + if (balanceViewModel.wallet.type == WalletType.monero || + balanceViewModel.wallet.type == WalletType.haven) { if (transaction.confirmations >= 0 && transaction.confirmations < 10) { return ' (${transaction.confirmations}/10)'; } @@ -79,6 +80,25 @@ class TransactionListItem extends ActionListItem with Keyable { return transaction.isPending ? S.current.pending : ''; } + String get formattedType { + if (transaction.evmSignatureName == 'approval') { + return ' (${transaction.evmSignatureName})'; + } + return ''; + } + + String get tag { + List addresses = + (transaction.inputAddresses ?? []) + (transaction.outputAddresses ?? []); + for (var address in addresses) { + if (address.toLowerCase().contains('mweb')) { + return 'MWEB'; + } + } + + return ''; + } + CryptoCurrency? get assetOfTransaction { try { if (balanceViewModel.wallet.type == WalletType.ethereum) {