save [skip ci]

This commit is contained in:
Matthew Fosse 2024-07-12 13:40:37 -07:00
parent 720914727e
commit 8efe70fb24
6 changed files with 181 additions and 103 deletions

View file

@ -87,7 +87,7 @@ class LitecoinTransactionPriority extends BitcoinTransactionPriority {
} }
@override @override
String get units => 'Latoshi'; String get units => 'Litoshi';
@override @override
String toString() { String toString() {

View file

@ -178,6 +178,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
if (resp.mwebUtxosHeight > mwebUtxosHeight) { if (resp.mwebUtxosHeight > mwebUtxosHeight) {
mwebUtxosHeight = resp.mwebUtxosHeight; mwebUtxosHeight = resp.mwebUtxosHeight;
await checkMwebUtxosSpent(); await checkMwebUtxosSpent();
// update the confirmations for each transaction:
for (final transaction in transactionHistory.transactions.values) { for (final transaction in transactionHistory.transactions.values) {
if (transaction.isPending) continue; if (transaction.isPending) continue;
final confirmations = mwebUtxosHeight - transaction.height + 1; final confirmations = mwebUtxosHeight - transaction.height + 1;
@ -266,6 +267,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
} }
if (!(tx.inputAddresses?.contains(utxo.address) ?? false)) { if (!(tx.inputAddresses?.contains(utxo.address) ?? false)) {
addressRecord.txCount++; addressRecord.txCount++;
print("COUNT UPDATED HERE 2!!!!! ${addressRecord.txCount}");
} }
addressRecord.balance += utxo.value.toInt(); addressRecord.balance += utxo.value.toInt();
addressRecord.setAsUsed(); addressRecord.setAsUsed();
@ -283,6 +285,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
final req = UtxosRequest(scanSecret: hex.decode(scanSecret), fromHeight: restoreHeight); final req = UtxosRequest(scanSecret: hex.decode(scanSecret), fromHeight: restoreHeight);
bool initDone = false; bool initDone = false;
// process old utxos:
for (final utxo in mwebUtxosBox.values) { for (final utxo in mwebUtxosBox.values) {
if (utxo.address.isEmpty) { if (utxo.address.isEmpty) {
initDone = true; 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)) { await for (Utxo sUtxo in _stub.utxos(req)) {
final utxo = MwebUtxo( final utxo = MwebUtxo(
address: sUtxo.address, address: sUtxo.address,
@ -327,6 +331,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
final mwebAddrs = (walletAddresses as LitecoinWalletAddresses).mwebAddrs; 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)) { if (utxo.address.isNotEmpty && !mwebAddrs.contains(utxo.address)) {
continue; continue;
} }
@ -362,7 +367,10 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
if (utxo == null) continue; if (utxo == null) continue;
final addressRecord = walletAddresses.allAddresses final addressRecord = walletAddresses.allAddresses
.firstWhere((addressRecord) => addressRecord.address == utxo.address); .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(); addressRecord.balance -= utxo.value.toInt();
amount += utxo.value.toInt(); amount += utxo.value.toInt();
inputAddresses.add(utxo.address); inputAddresses.add(utxo.address);
@ -471,6 +479,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
@override @override
Future<ElectrumBalance> fetchBalances() async { Future<ElectrumBalance> fetchBalances() async {
print("FETCH BALANCES");
final balance = await super.fetchBalances(); final balance = await super.fetchBalances();
var confirmed = balance.confirmed; var confirmed = balance.confirmed;
var unconfirmed = balance.unconfirmed; var unconfirmed = balance.unconfirmed;
@ -523,6 +532,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
continue; continue;
} }
addressRecord.txCount++; 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; tx.outputs = resp.outputId;
return tx return tx
..addListener((transaction) async { ..addListener((transaction) async {
final addresses = <String>{}; print("LISTENER CALLED @@@@@@@@@@@@@@@@@@");
transaction.inputAddresses?.forEach((id) async { // final addresses = <String>{};
final utxo = mwebUtxosBox.get(id); // transaction.inputAddresses?.forEach((id) async {
await mwebUtxosBox.delete(id); // final utxo = mwebUtxosBox.get(id);
if (utxo == null) return; // await mwebUtxosBox.delete(id);
final addressRecord = walletAddresses.allAddresses // if (utxo == null) return;
.firstWhere((addressRecord) => addressRecord.address == utxo.address); // final addressRecord = walletAddresses.allAddresses
if (!addresses.contains(utxo.address)) { // .firstWhere((addressRecord) => addressRecord.address == utxo.address);
addressRecord.txCount++; // if (!addresses.contains(utxo.address)) {
addresses.add(utxo.address); // addressRecord.txCount++;
} // print("COUNT UPDATED HERE 1!!!!! ${addressRecord.address} ${addressRecord.txCount} !!!!!!");
addressRecord.balance -= utxo.value.toInt(); // addresses.add(utxo.address);
}); // }
transaction.inputAddresses?.addAll(addresses); // addressRecord.balance -= utxo.value.toInt();
print("BEING ADDED HERE@@@@@@@@@@@@@@@@@@@@@@@3"); // });
// transaction.inputAddresses?.addAll(addresses);
// print("BEING ADDED HERE@@@@@@@@@@@@@@@@@@@@@@@3");
transactionHistory.addOne(transaction); // transactionHistory.addOne(transaction);
// await transactionHistory.save();
await updateUnspent(); await updateUnspent();
await updateBalance(); await updateBalance();
}); });

View file

@ -83,10 +83,6 @@ class TransactionsPage extends StatelessWidget {
} }
final transaction = item.transaction; final transaction = item.transaction;
final transactionType = dashboardViewModel.type == WalletType.ethereum &&
transaction.evmSignatureName == 'approval'
? ' (${transaction.evmSignatureName})'
: '';
return Observer( return Observer(
builder: (_) => TransactionRow( builder: (_) => TransactionRow(
@ -101,7 +97,9 @@ class TransactionsPage extends StatelessWidget {
: item.formattedFiatAmount, : item.formattedFiatAmount,
isPending: transaction.isPending, isPending: transaction.isPending,
title: item.formattedTitle + title: item.formattedTitle +
item.formattedStatus + ' $transactionType', item.formattedStatus +
' ${item.formattedType}',
tag: item.tag,
), ),
); );
} }

View file

@ -5,14 +5,16 @@ import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart';
import 'package:cake_wallet/themes/extensions/transaction_trade_theme.dart'; import 'package:cake_wallet/themes/extensions/transaction_trade_theme.dart';
class TransactionRow extends StatelessWidget { class TransactionRow extends StatelessWidget {
TransactionRow( TransactionRow({
{required this.direction, required this.direction,
required this.formattedDate, required this.formattedDate,
required this.formattedAmount, required this.formattedAmount,
required this.formattedFiatAmount, required this.formattedFiatAmount,
required this.isPending, required this.isPending,
required this.title, required this.title,
required this.onTap}); required this.onTap,
required this.tag,
});
final VoidCallback onTap; final VoidCallback onTap;
final TransactionDirection direction; final TransactionDirection direction;
@ -21,6 +23,7 @@ class TransactionRow extends StatelessWidget {
final String formattedFiatAmount; final String formattedFiatAmount;
final bool isPending; final bool isPending;
final String title; final String title;
final String tag;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -38,10 +41,8 @@ class TransactionRow extends StatelessWidget {
width: 36, width: 36,
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.circle,
color: Theme.of(context).extension<TransactionTradeTheme>()!.rowsColor color: Theme.of(context).extension<TransactionTradeTheme>()!.rowsColor),
), child: Image.asset(direction == TransactionDirection.incoming
child: Image.asset(
direction == TransactionDirection.incoming
? 'assets/images/down_arrow.png' ? 'assets/images/down_arrow.png'
: 'assets/images/up_arrow.png'), : 'assets/images/up_arrow.png'),
), ),
@ -50,36 +51,59 @@ class TransactionRow extends StatelessWidget {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[
Text(
title,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Theme.of(context).extension<DashboardPageTheme>()!.textColor),
),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
children: <Widget>[ if (tag.isNotEmpty)
Text(title, 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( style: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: Theme.of(context).extension<DashboardPageTheme>()!.textColor)), color: Theme.of(context).extension<DashboardPageTheme>()!.textColor),
Text(formattedAmount, ),
style: TextStyle( ],
fontSize: 16, ),
fontWeight: FontWeight.w500,
color: Theme.of(context).extension<DashboardPageTheme>()!.textColor))
]), ]),
SizedBox(height: 5), SizedBox(height: 5),
Row( Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(formattedDate, Text(formattedDate,
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
color: Theme.of(context).extension<CakeTextTheme>()!.dateSectionRowColor)), color:
Theme.of(context).extension<CakeTextTheme>()!.dateSectionRowColor)),
Text(formattedFiatAmount, Text(formattedFiatAmount,
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
color: Theme.of(context).extension<CakeTextTheme>()!.dateSectionRowColor)) color:
Theme.of(context).extension<CakeTextTheme>()!.dateSectionRowColor))
]) ])
], ],
) ))
)
], ],
), ),
)); ));

View file

@ -103,6 +103,9 @@ class UnspentCoinsListItem extends StatelessWidget {
), ),
maxLines: 1, maxLines: 1,
), ),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
if (isChange) if (isChange)
Container( Container(
height: 17, height: 17,
@ -120,6 +123,24 @@ class UnspentCoinsListItem extends StatelessWidget {
), ),
), ),
), ),
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) if (isSilentPayment)
Container( Container(
height: 17, height: 17,
@ -139,6 +160,8 @@ class UnspentCoinsListItem extends StatelessWidget {
), ),
], ],
), ),
],
),
), ),
])), ])),
], ],

View file

@ -56,7 +56,8 @@ class TransactionListItem extends ActionListItem with Keyable {
} }
String get formattedPendingStatus { 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) { if (transaction.confirmations >= 0 && transaction.confirmations < 10) {
return ' (${transaction.confirmations}/10)'; return ' (${transaction.confirmations}/10)';
} }
@ -79,6 +80,25 @@ class TransactionListItem extends ActionListItem with Keyable {
return transaction.isPending ? S.current.pending : ''; return transaction.isPending ? S.current.pending : '';
} }
String get formattedType {
if (transaction.evmSignatureName == 'approval') {
return ' (${transaction.evmSignatureName})';
}
return '';
}
String get tag {
List<String> addresses =
(transaction.inputAddresses ?? []) + (transaction.outputAddresses ?? []);
for (var address in addresses) {
if (address.toLowerCase().contains('mweb')) {
return 'MWEB';
}
}
return '';
}
CryptoCurrency? get assetOfTransaction { CryptoCurrency? get assetOfTransaction {
try { try {
if (balanceViewModel.wallet.type == WalletType.ethereum) { if (balanceViewModel.wallet.type == WalletType.ethereum) {