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

@ -52,7 +52,7 @@ class TransactionsPage extends StatelessWidget {
try { try {
final uri = Uri.parse( final uri = Uri.parse(
"https://guides.cakewallet.com/docs/FAQ/why_are_my_funds_not_appearing/"); "https://guides.cakewallet.com/docs/FAQ/why_are_my_funds_not_appearing/");
launchUrl(uri, mode: LaunchMode.externalApplication); launchUrl(uri, mode: LaunchMode.externalApplication);
} catch (_) {} } catch (_) {}
}, },
title: S.of(context).syncing_wallet_alert_title, title: S.of(context).syncing_wallet_alert_title,
@ -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,48 +41,69 @@ 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( ? 'assets/images/down_arrow.png'
direction == TransactionDirection.incoming : 'assets/images/up_arrow.png'),
? 'assets/images/down_arrow.png'
: 'assets/images/up_arrow.png'),
), ),
SizedBox(width: 12), SizedBox(width: 12),
Expanded( Expanded(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Row( Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[
mainAxisAlignment: MainAxisAlignment.spaceBetween, Text(
children: <Widget>[ title,
Text(title, 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, Row(
style: TextStyle( children: [
fontSize: 16, if (tag.isNotEmpty)
fontWeight: FontWeight.w500, Container(
color: Theme.of(context).extension<DashboardPageTheme>()!.textColor)) height: 17,
]), padding: EdgeInsets.only(left: 6, right: 6),
SizedBox(height: 5), margin: EdgeInsets.only(right: 6),
Row( decoration: BoxDecoration(
mainAxisAlignment: MainAxisAlignment.spaceBetween, borderRadius: BorderRadius.all(Radius.circular(8.5)),
children: <Widget>[ color: Colors.white),
Text(formattedDate, alignment: Alignment.center,
style: TextStyle( child: Text(
fontSize: 14, tag,
color: Theme.of(context).extension<CakeTextTheme>()!.dateSectionRowColor)), style: TextStyle(
Text(formattedFiatAmount, color: Colors.black,
style: TextStyle( fontSize: 7,
fontSize: 14, fontWeight: FontWeight.w600,
color: Theme.of(context).extension<CakeTextTheme>()!.dateSectionRowColor)) ),
]) ),
], ),
) Text(
) formattedAmount,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Theme.of(context).extension<DashboardPageTheme>()!.textColor),
),
],
),
]),
SizedBox(height: 5),
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[
Text(formattedDate,
style: TextStyle(
fontSize: 14,
color:
Theme.of(context).extension<CakeTextTheme>()!.dateSectionRowColor)),
Text(formattedFiatAmount,
style: TextStyle(
fontSize: 14,
color:
Theme.of(context).extension<CakeTextTheme>()!.dateSectionRowColor))
])
],
))
], ],
), ),
)); ));

View file

@ -103,40 +103,63 @@ class UnspentCoinsListItem extends StatelessWidget {
), ),
maxLines: 1, maxLines: 1,
), ),
if (isChange) Row(
Container( mainAxisAlignment: MainAxisAlignment.spaceEvenly,
height: 17, children: [
padding: EdgeInsets.only(left: 6, right: 6), if (isChange)
decoration: BoxDecoration( Container(
borderRadius: BorderRadius.all(Radius.circular(8.5)), height: 17,
color: Colors.white), padding: EdgeInsets.only(left: 6, right: 6),
alignment: Alignment.center, decoration: BoxDecoration(
child: Text( borderRadius: BorderRadius.all(Radius.circular(8.5)),
S.of(context).unspent_change, color: Colors.white),
style: TextStyle( alignment: Alignment.center,
color: itemColor, child: Text(
fontSize: 7, S.of(context).unspent_change,
fontWeight: FontWeight.w600, style: TextStyle(
color: itemColor,
fontSize: 7,
fontWeight: FontWeight.w600,
),
),
), ),
), if (address.toLowerCase().contains("mweb"))
), Container(
if (isSilentPayment) height: 17,
Container( padding: EdgeInsets.only(left: 6, right: 6),
height: 17, margin: EdgeInsets.only(left: 6),
padding: EdgeInsets.only(left: 6, right: 6), decoration: BoxDecoration(
decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(8.5)),
borderRadius: BorderRadius.all(Radius.circular(8.5)), color: Colors.white),
color: Colors.white), alignment: Alignment.center,
alignment: Alignment.center, child: Text(
child: Text( "MWEB",
S.of(context).silent_payments, style: TextStyle(
style: TextStyle( color: itemColor,
color: itemColor, fontSize: 7,
fontSize: 7, fontWeight: FontWeight.w600,
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,
),
),
),
],
),
], ],
), ),
), ),

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) {