CW-260 show amount received for each account (#907)

* Show amount received for each account

* Enable litcoin send all

* disable litcoin send all

* Indent code

* Fix large font resolution for account title
This commit is contained in:
Godwin Asuquo 2023-05-05 15:58:41 +03:00 committed by GitHub
parent 25b743df47
commit 9714961298
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 84 additions and 45 deletions

View file

@ -1,10 +1,12 @@
class Account {
Account({required this.id, required this.label});
Account({required this.id, required this.label, this.balance});
Account.fromMap(Map<String, Object> map)
: this.id = map['id'] == null ? 0 : int.parse(map['id'] as String),
this.label = (map['label'] ?? '') as String;
this.label = (map['label'] ?? '') as String,
this.balance = (map['balance'] ?? '0.00') as String;
final int id;
final String label;
final String? balance;
}

View file

@ -1,6 +1,8 @@
import 'package:cw_core/monero_amount_format.dart';
import 'package:mobx/mobx.dart';
import 'package:cw_core/account.dart';
import 'package:cw_monero/api/account_list.dart' as account_list;
import 'package:cw_monero/api/wallet.dart' as monero_wallet;
part 'monero_account_list.g.dart';
@ -41,12 +43,16 @@ abstract class MoneroAccountListBase with Store {
}
}
List<Account> getAll() => account_list
.getAllAccount()
.map((accountRow) => Account(
id: accountRow.getId(),
label: accountRow.getLabel()))
.toList();
List<Account> getAll() => account_list.getAllAccount().map((accountRow) {
final accountIndex = accountRow.getId();
final balance = monero_wallet.getFullBalance(accountIndex: accountIndex);
return Account(
id: accountRow.getId(),
label: accountRow.getLabel(),
balance: moneroAmountToString(amount: balance),
);
}).toList();
Future<void> addAccount({required String label}) async {
await account_list.addAccount(label: label);
@ -54,8 +60,7 @@ abstract class MoneroAccountListBase with Store {
}
Future<void> setLabelAccount({required int accountIndex, required String label}) async {
await account_list.setLabelForAccount(
accountIndex: accountIndex, label: label);
await account_list.setLabelForAccount(accountIndex: accountIndex, label: label);
update();
}

View file

@ -10,7 +10,7 @@ class CWMoneroAccountList extends MoneroAccountList {
final moneroWallet = _wallet as MoneroWallet;
final accounts = moneroWallet.walletAddresses.accountList
.accounts
.map((acc) => Account(id: acc.id, label: acc.label))
.map((acc) => Account(id: acc.id, label: acc.label, balance: acc.balance))
.toList();
return ObservableList<Account>.of(accounts);
}
@ -32,7 +32,7 @@ class CWMoneroAccountList extends MoneroAccountList {
final moneroWallet = wallet as MoneroWallet;
return moneroWallet.walletAddresses.accountList
.getAll()
.map((acc) => Account(id: acc.id, label: acc.label))
.map((acc) => Account(id: acc.id, label: acc.label, balance: acc.balance))
.toList();
}
@ -122,7 +122,7 @@ class CWMoneroWalletDetails extends MoneroWalletDetails {
Account get account {
final moneroWallet = _wallet as MoneroWallet;
final acc = moneroWallet.walletAddresses.account;
return Account(id: acc!.id, label: acc.label);
return Account(id: acc!.id, label: acc.label, balance: acc.balance);
}
@computed
@ -316,13 +316,13 @@ class CWMonero extends Monero {
Account getCurrentAccount(Object wallet) {
final moneroWallet = wallet as MoneroWallet;
final acc = moneroWallet.walletAddresses.account;
return Account(id: acc!.id, label: acc.label);
return Account(id: acc!.id, label: acc.label, balance: acc.balance);
}
@override
void setCurrentAccount(Object wallet, int id, String label) {
void setCurrentAccount(Object wallet, int id, String label, String? balance) {
final moneroWallet = wallet as MoneroWallet;
moneroWallet.walletAddresses.account = monero_account.Account(id: id, label: label);
moneroWallet.walletAddresses.account = monero_account.Account(id: id, label: label, balance: balance);
}
@override

View file

@ -88,13 +88,16 @@ class MoneroAccountListPage extends StatelessWidget {
itemBuilder: (context, index) {
final account = accounts[index];
return AccountTile(
isCurrent: account.isSelected,
accountName: account.label,
onTap: () {
if (account.isSelected) {
return;
}
return AccountTile(
isCurrent: account.isSelected,
accountName: account.label,
accountBalance: account.balance ?? '0.00',
currency: accountListViewModel
.currency.toString(),
onTap: () {
if (account.isSelected) {
return;
}
accountListViewModel
.select(account);

View file

@ -1,45 +1,68 @@
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:cake_wallet/generated/i18n.dart';
class AccountTile extends StatelessWidget {
AccountTile({
required this.isCurrent,
required this.accountName,
this.accountBalance,
required this.currency,
required this.onTap,
required this.onEdit
});
final bool isCurrent;
final String accountName;
final String? accountBalance;
final String currency;
final Function() onTap;
final Function() onEdit;
@override
Widget build(BuildContext context) {
final color = isCurrent
? Theme.of(context).textTheme!.subtitle2!.decorationColor!
: Theme.of(context).textTheme!.headline1!.decorationColor!;
? Theme.of(context).textTheme.subtitle2!.decorationColor!
: Theme.of(context).textTheme.headline1!.decorationColor!;
final textColor = isCurrent
? Theme.of(context).textTheme!.subtitle2!.color!
: Theme.of(context).textTheme!.headline1!.color!;
? Theme.of(context).textTheme.subtitle2!.color!
: Theme.of(context).textTheme.headline1!.color!;
final Widget cell = GestureDetector(
onTap: onTap,
child: Container(
height: 77,
padding: EdgeInsets.only(left: 24, right: 24),
alignment: Alignment.centerLeft,
color: color,
child: Text(
accountName,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: textColor,
decoration: TextDecoration.none,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 2,
child: Text(
accountName,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: textColor,
decoration: TextDecoration.none,
),
),
),
if (accountBalance != null)
Expanded(
child: Text(
'${accountBalance.toString()} $currency',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: Theme.of(context).textTheme.headline4!.color!,
decoration: TextDecoration.none,
),
),
),
],
),
),
);

View file

@ -1,10 +1,9 @@
import 'package:flutter/foundation.dart';
class AccountListItem {
AccountListItem(
{required this.label, required this.id, this.isSelected = false});
{required this.label, required this.id, this.balance, this.isSelected = false});
final String label;
final int id;
final bool isSelected;
final String? balance;
}

View file

@ -1,3 +1,4 @@
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
import 'package:cw_core/wallet_base.dart';
@ -21,6 +22,8 @@ abstract class MoneroAccountListViewModelBase with Store {
this.scrollOffsetFromTop = scrollOffsetFromTop;
}
CryptoCurrency get currency => _wallet.currency;
@computed
List<AccountListItem> get accounts {
if (_wallet.type == WalletType.haven) {
@ -39,6 +42,7 @@ abstract class MoneroAccountListViewModelBase with Store {
.accounts.map((acc) => AccountListItem(
label: acc.label,
id: acc.id,
balance: acc.balance,
isSelected: acc.id == monero!.getCurrentAccount(_wallet).id))
.toList();
}
@ -53,7 +57,9 @@ abstract class MoneroAccountListViewModelBase with Store {
monero!.setCurrentAccount(
_wallet,
item.id,
item.label);
item.label,
item.balance,
);
}
if (_wallet.type == WalletType.haven) {

View file

@ -158,9 +158,10 @@ import 'package:cw_monero/pending_monero_transaction.dart';
const moneroCwPart = "part 'cw_monero.dart';";
const moneroContent = """
class Account {
Account({required this.id, required this.label});
Account({required this.id, required this.label, this.balance});
final int id;
final String label;
final String? balance;
}
class Subaddress {
@ -246,7 +247,7 @@ abstract class Monero {
double formatterMoneroAmountToDouble({required int amount});
int formatterMoneroParseAmount({required String amount});
Account getCurrentAccount(Object wallet);
void setCurrentAccount(Object wallet, int id, String label);
void setCurrentAccount(Object wallet, int id, String label, String? balance);
void onStartup();
int getTransactionInfoAccountId(TransactionInfo tx);
WalletService createMoneroWalletService(Box<WalletInfo> walletInfoSource);