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
Godwin Asuquo committed
May 5, 2023 at 15:58 UTC
971496129802e37d8f348aac35e7d908c4fee019
8 files changed
+84
-45
cw_core/lib/account.dart
+4
-2
@@ -1,10 +1,12 @@
1
class Account {
2
- Account({required this.id, required this.label});
2
+ Account({required this.id, required this.label, this.balance});
3
4
Account.fromMap(Map<String, Object> map)
5
: this.id = map['id'] == null ? 0 : int.parse(map['id'] as String),
6
- this.label = (map['label'] ?? '') as String;
6
+ this.label = (map['label'] ?? '') as String,
7
+ this.balance = (map['balance'] ?? '0.00') as String;
8
9
final int id;
10
final String label;
11
+ final String? balance;
12
}
\ No newline at end of file
cw_monero/lib/monero_account_list.dart
+13
-8
@@ -1,6 +1,8 @@
1
+import 'package:cw_core/monero_amount_format.dart';
2
import 'package:mobx/mobx.dart';
3
import 'package:cw_core/account.dart';
4
import 'package:cw_monero/api/account_list.dart' as account_list;
5
+import 'package:cw_monero/api/wallet.dart' as monero_wallet;
6
7
part 'monero_account_list.g.dart';
8
@@ -41,12 +43,16 @@ abstract class MoneroAccountListBase with Store {
43
}
44
}
45
44
- List<Account> getAll() => account_list
45
- .getAllAccount()
46
- .map((accountRow) => Account(
47
- id: accountRow.getId(),
48
- label: accountRow.getLabel()))
49
- .toList();
46
+ List<Account> getAll() => account_list.getAllAccount().map((accountRow) {
47
+ final accountIndex = accountRow.getId();
48
+ final balance = monero_wallet.getFullBalance(accountIndex: accountIndex);
49
+
50
+ return Account(
51
+ id: accountRow.getId(),
52
+ label: accountRow.getLabel(),
53
+ balance: moneroAmountToString(amount: balance),
54
+ );
55
+ }).toList();
56
57
Future<void> addAccount({required String label}) async {
58
await account_list.addAccount(label: label);
@@ -54,8 +60,7 @@ abstract class MoneroAccountListBase with Store {
60
}
61
62
Future<void> setLabelAccount({required int accountIndex, required String label}) async {
57
- await account_list.setLabelForAccount(
58
- accountIndex: accountIndex, label: label);
63
+ await account_list.setLabelForAccount(accountIndex: accountIndex, label: label);
64
update();
65
}
66
lib/monero/cw_monero.dart
+6
-6
@@ -10,7 +10,7 @@ class CWMoneroAccountList extends MoneroAccountList {
10
final moneroWallet = _wallet as MoneroWallet;
11
final accounts = moneroWallet.walletAddresses.accountList
12
.accounts
13
- .map((acc) => Account(id: acc.id, label: acc.label))
13
+ .map((acc) => Account(id: acc.id, label: acc.label, balance: acc.balance))
14
.toList();
15
return ObservableList<Account>.of(accounts);
16
}
@@ -32,7 +32,7 @@ class CWMoneroAccountList extends MoneroAccountList {
32
final moneroWallet = wallet as MoneroWallet;
33
return moneroWallet.walletAddresses.accountList
34
.getAll()
35
- .map((acc) => Account(id: acc.id, label: acc.label))
35
+ .map((acc) => Account(id: acc.id, label: acc.label, balance: acc.balance))
36
.toList();
37
}
38
@@ -122,7 +122,7 @@ class CWMoneroWalletDetails extends MoneroWalletDetails {
122
Account get account {
123
final moneroWallet = _wallet as MoneroWallet;
124
final acc = moneroWallet.walletAddresses.account;
125
- return Account(id: acc!.id, label: acc.label);
125
+ return Account(id: acc!.id, label: acc.label, balance: acc.balance);
126
}
127
128
@computed
@@ -316,13 +316,13 @@ class CWMonero extends Monero {
316
Account getCurrentAccount(Object wallet) {
317
final moneroWallet = wallet as MoneroWallet;
318
final acc = moneroWallet.walletAddresses.account;
319
- return Account(id: acc!.id, label: acc.label);
319
+ return Account(id: acc!.id, label: acc.label, balance: acc.balance);
320
}
321
322
@override
323
- void setCurrentAccount(Object wallet, int id, String label) {
323
+ void setCurrentAccount(Object wallet, int id, String label, String? balance) {
324
final moneroWallet = wallet as MoneroWallet;
325
- moneroWallet.walletAddresses.account = monero_account.Account(id: id, label: label);
325
+ moneroWallet.walletAddresses.account = monero_account.Account(id: id, label: label, balance: balance);
326
}
327
328
@override
lib/src/screens/monero_accounts/monero_account_list_page.dart
+10
-7
@@ -88,13 +88,16 @@ class MoneroAccountListPage extends StatelessWidget {
88
itemBuilder: (context, index) {
89
final account = accounts[index];
90
91
- return AccountTile(
92
- isCurrent: account.isSelected,
93
- accountName: account.label,
94
- onTap: () {
95
- if (account.isSelected) {
96
- return;
97
- }
91
+ return AccountTile(
92
+ isCurrent: account.isSelected,
93
+ accountName: account.label,
94
+ accountBalance: account.balance ?? '0.00',
95
+ currency: accountListViewModel
96
+ .currency.toString(),
97
+ onTap: () {
98
+ if (account.isSelected) {
99
+ return;
100
+ }
101
102
accountListViewModel
103
.select(account);
lib/src/screens/monero_accounts/widgets/account_tile.dart
+39
-16
@@ -1,45 +1,68 @@
1
import 'package:flutter/material.dart';
2
-import 'package:flutter_slidable/flutter_slidable.dart';
3
-import 'package:cake_wallet/generated/i18n.dart';
2
3
class AccountTile extends StatelessWidget {
4
AccountTile({
5
required this.isCurrent,
6
required this.accountName,
7
+ this.accountBalance,
8
+ required this.currency,
9
required this.onTap,
10
required this.onEdit
11
});
12
13
final bool isCurrent;
14
final String accountName;
15
+ final String? accountBalance;
16
+ final String currency;
17
final Function() onTap;
18
final Function() onEdit;
19
20
@override
21
Widget build(BuildContext context) {
22
final color = isCurrent
21
- ? Theme.of(context).textTheme!.subtitle2!.decorationColor!
22
- : Theme.of(context).textTheme!.headline1!.decorationColor!;
23
+ ? Theme.of(context).textTheme.subtitle2!.decorationColor!
24
+ : Theme.of(context).textTheme.headline1!.decorationColor!;
25
final textColor = isCurrent
24
- ? Theme.of(context).textTheme!.subtitle2!.color!
25
- : Theme.of(context).textTheme!.headline1!.color!;
26
+ ? Theme.of(context).textTheme.subtitle2!.color!
27
+ : Theme.of(context).textTheme.headline1!.color!;
28
29
final Widget cell = GestureDetector(
30
onTap: onTap,
31
child: Container(
32
height: 77,
33
padding: EdgeInsets.only(left: 24, right: 24),
32
- alignment: Alignment.centerLeft,
34
color: color,
34
- child: Text(
35
- accountName,
36
- style: TextStyle(
37
- fontSize: 18,
38
- fontWeight: FontWeight.w600,
39
- fontFamily: 'Lato',
40
- color: textColor,
41
- decoration: TextDecoration.none,
42
- ),
35
+ child: Row(
36
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
37
+ children: [
38
+ Expanded(
39
+ flex: 2,
40
+ child: Text(
41
+ accountName,
42
+ style: TextStyle(
43
+ fontSize: 18,
44
+ fontWeight: FontWeight.w600,
45
+ fontFamily: 'Lato',
46
+ color: textColor,
47
+ decoration: TextDecoration.none,
48
+ ),
49
+ ),
50
+ ),
51
+ if (accountBalance != null)
52
+ Expanded(
53
+ child: Text(
54
+ '${accountBalance.toString()} $currency',
55
+ textAlign: TextAlign.end,
56
+ style: TextStyle(
57
+ fontSize: 15,
58
+ fontWeight: FontWeight.w600,
59
+ fontFamily: 'Lato',
60
+ color: Theme.of(context).textTheme.headline4!.color!,
61
+ decoration: TextDecoration.none,
62
+ ),
63
+ ),
64
+ ),
65
+ ],
66
),
67
),
68
);
lib/view_model/monero_account_list/account_list_item.dart
+2
-3
@@ -1,10 +1,9 @@
1
-import 'package:flutter/foundation.dart';
2
-
1
class AccountListItem {
2
AccountListItem(
5
- {required this.label, required this.id, this.isSelected = false});
3
+ {required this.label, required this.id, this.balance, this.isSelected = false});
4
5
final String label;
6
final int id;
7
final bool isSelected;
8
+ final String? balance;
9
}
lib/view_model/monero_account_list/monero_account_list_view_model.dart
+7
-1
@@ -1,3 +1,4 @@
1
+import 'package:cw_core/crypto_currency.dart';
2
import 'package:cw_core/wallet_type.dart';
3
import 'package:mobx/mobx.dart';
4
import 'package:cw_core/wallet_base.dart';
@@ -21,6 +22,8 @@ abstract class MoneroAccountListViewModelBase with Store {
22
this.scrollOffsetFromTop = scrollOffsetFromTop;
23
}
24
25
+ CryptoCurrency get currency => _wallet.currency;
26
+
27
@computed
28
List<AccountListItem> get accounts {
29
if (_wallet.type == WalletType.haven) {
@@ -39,6 +42,7 @@ abstract class MoneroAccountListViewModelBase with Store {
42
.accounts.map((acc) => AccountListItem(
43
label: acc.label,
44
id: acc.id,
45
+ balance: acc.balance,
46
isSelected: acc.id == monero!.getCurrentAccount(_wallet).id))
47
.toList();
48
}
@@ -53,7 +57,9 @@ abstract class MoneroAccountListViewModelBase with Store {
57
monero!.setCurrentAccount(
58
_wallet,
59
item.id,
56
- item.label);
60
+ item.label,
61
+ item.balance,
62
+ );
63
}
64
65
if (_wallet.type == WalletType.haven) {
tool/configure.dart
+3
-2
@@ -158,9 +158,10 @@ import 'package:cw_monero/pending_monero_transaction.dart';
158
const moneroCwPart = "part 'cw_monero.dart';";
159
const moneroContent = """
160
class Account {
161
- Account({required this.id, required this.label});
161
+ Account({required this.id, required this.label, this.balance});
162
final int id;
163
final String label;
164
+ final String? balance;
165
}
166
167
class Subaddress {
@@ -246,7 +247,7 @@ abstract class Monero {
247
double formatterMoneroAmountToDouble({required int amount});
248
int formatterMoneroParseAmount({required String amount});
249
Account getCurrentAccount(Object wallet);
249
- void setCurrentAccount(Object wallet, int id, String label);
250
+ void setCurrentAccount(Object wallet, int id, String label, String? balance);
251
void onStartup();
252
int getTransactionInfoAccountId(TransactionInfo tx);
253
WalletService createMoneroWalletService(Box<WalletInfo> walletInfoSource);