Fixes.
M committed
Dec 17, 2020 at 15:39 UTC
4a2f1e48ff25fbe3f0168c23968d26771fb56428
7 files changed
+65
-43
lib/bitcoin/bitcoin_balance.dart
+5
-2
@@ -7,7 +7,10 @@ import 'package:cake_wallet/entities/balance.dart';
7
8
class BitcoinBalance extends Balance {
9
const BitcoinBalance({@required this.confirmed, @required this.unconfirmed})
10
- : super(const [BalanceDisplayMode.availableBalance]);
10
+ : super(const [
11
+ BalanceDisplayMode.availableBalance,
12
+ BalanceDisplayMode.fullBalance
13
+ ]);
14
15
factory BitcoinBalance.fromJSON(String jsonSource) {
16
if (jsonSource == null) {
@@ -38,7 +41,7 @@ class BitcoinBalance extends Balance {
41
case BalanceDisplayMode.fullBalance:
42
return totalFormatted;
43
case BalanceDisplayMode.availableBalance:
41
- return totalFormatted;
44
+ return confirmedFormatted;
45
default:
46
return null;
47
}
lib/bitcoin/bitcoin_transaction_info.dart
+22
-6
@@ -12,6 +12,7 @@ class BitcoinTransactionInfo extends TransactionInfo {
12
{@required String id,
13
@required int height,
14
@required int amount,
15
+ @required int fee,
16
@required TransactionDirection direction,
17
@required bool isPending,
18
@required DateTime date,
@@ -19,6 +20,7 @@ class BitcoinTransactionInfo extends TransactionInfo {
20
this.id = id;
21
this.height = height;
22
this.amount = amount;
23
+ this.fee = fee;
24
this.direction = direction;
25
this.date = date;
26
this.isPending = isPending;
@@ -36,37 +38,42 @@ class BitcoinTransactionInfo extends TransactionInfo {
38
: DateTime.now();
39
final confirmations = obj['confirmations'] as int ?? 0;
40
var direction = TransactionDirection.incoming;
41
+ var inputsAmount = 0;
42
+ var amount = 0;
43
+ var totalOutAmount = 0;
44
45
for (dynamic vin in vins) {
46
final vout = vin['vout'] as int;
47
final out = vin['tx']['vout'][vout] as Map;
48
final outAddresses =
49
(out['scriptPubKey']['addresses'] as List<Object>)?.toSet();
50
+ inputsAmount += doubleToBitcoinAmount(out['value'] as double ?? 0);
51
52
if (outAddresses?.intersection(addressesSet)?.isNotEmpty ?? false) {
53
direction = TransactionDirection.outgoing;
48
- break;
54
}
55
}
56
52
- final amount = vout.fold(0, (int acc, dynamic out) {
57
+ for (dynamic out in vout) {
58
final outAddresses =
59
out['scriptPubKey']['addresses'] as List<Object> ?? [];
60
final ntrs = outAddresses.toSet().intersection(addressesSet);
56
- var amount = acc;
61
+ final value = doubleToBitcoinAmount(out['value'] as double ?? 0.0);
62
+ totalOutAmount += value;
63
64
if ((direction == TransactionDirection.incoming && ntrs.isNotEmpty) ||
65
(direction == TransactionDirection.outgoing && ntrs.isEmpty)) {
60
- amount += doubleToBitcoinAmount(out['value'] as double ?? 0.0);
66
+ amount += value;
67
}
68
+ }
69
63
- return amount;
64
- });
70
+ final fee = inputsAmount - totalOutAmount;
71
72
return BitcoinTransactionInfo(
73
id: id,
74
height: height,
75
isPending: false,
76
+ fee: fee,
77
direction: direction,
78
amount: amount,
79
date: date,
@@ -101,6 +108,7 @@ class BitcoinTransactionInfo extends TransactionInfo {
108
id: tx.getId(),
109
height: height,
110
isPending: false,
111
+ fee: null,
112
direction: TransactionDirection.incoming,
113
amount: amount,
114
date: date,
@@ -112,6 +120,7 @@ class BitcoinTransactionInfo extends TransactionInfo {
120
id: data['id'] as String,
121
height: data['height'] as int,
122
amount: data['amount'] as int,
123
+ fee: data['fee'] as int,
124
direction: parseTransactionDirectionFromInt(data['direction'] as int),
125
date: DateTime.fromMillisecondsSinceEpoch(data['date'] as int),
126
isPending: data['isPending'] as bool,
@@ -124,6 +133,11 @@ class BitcoinTransactionInfo extends TransactionInfo {
133
String amountFormatted() =>
134
'${formatAmount(bitcoinAmountToString(amount: amount))} BTC';
135
136
+ @override
137
+ String feeFormatted() => fee != null
138
+ ? '${formatAmount(bitcoinAmountToString(amount: fee))} BTC'
139
+ : '';
140
+
141
@override
142
String fiatAmount() => _fiatAmount ?? '';
143
@@ -135,6 +149,7 @@ class BitcoinTransactionInfo extends TransactionInfo {
149
id: id,
150
height: info.height,
151
amount: info.amount,
152
+ fee: info.fee,
153
direction: direction ?? info.direction,
154
date: date ?? info.date,
155
isPending: isPending ?? info.isPending,
@@ -150,6 +165,7 @@ class BitcoinTransactionInfo extends TransactionInfo {
165
m['date'] = date.millisecondsSinceEpoch;
166
m['isPending'] = isPending;
167
m['confirmations'] = confirmations;
168
+ m['fee'] = fee;
169
return m;
170
}
171
}
lib/entities/transaction_info.dart
+2
@@ -4,6 +4,7 @@ import 'package:cake_wallet/utils/mobx.dart';
4
abstract class TransactionInfo extends Object with Keyable {
5
String id;
6
int amount;
7
+ int fee;
8
TransactionDirection direction;
9
bool isPending;
10
DateTime date;
@@ -11,6 +12,7 @@ abstract class TransactionInfo extends Object with Keyable {
12
int confirmations;
13
String amountFormatted();
14
String fiatAmount();
15
+ String feeFormatted();
16
void changeFiatAmount(String amount);
17
18
@override
lib/generated/i18n.dart
+11
-11
@@ -208,7 +208,7 @@ class S implements WidgetsLocalizations {
208
String get send_error_currency => "Currency can only contain numbers";
209
String get send_error_minimum_value => "Minimum value of amount is 0.01";
210
String get send_estimated_fee => "Estimated fee:";
211
- String get send_fee => "Fee:";
211
+ String get send_fee => "Fee";
212
String get send_got_it => "Got it";
213
String get send_name => "Name";
214
String get send_new => "New";
@@ -396,7 +396,7 @@ class $de extends S {
396
@override
397
String get transaction_sent => "Transaktion gesendet!";
398
@override
399
- String get send_fee => "Gebühr:";
399
+ String get send_fee => "Gebühr";
400
@override
401
String get password => "Passwort";
402
@override
@@ -1780,7 +1780,7 @@ class $ru extends S {
1780
@override
1781
String get transaction_sent => "Tранзакция отправлена!";
1782
@override
1783
- String get send_fee => "Комиссия:";
1783
+ String get send_fee => "Комиссия";
1784
@override
1785
String get password => "Пароль";
1786
@override
@@ -2472,7 +2472,7 @@ class $ko extends S {
2472
@override
2473
String get transaction_sent => "거래가 전송되었습니다!";
2474
@override
2475
- String get send_fee => "회비:";
2475
+ String get send_fee => "회비";
2476
@override
2477
String get password => "암호";
2478
@override
@@ -3164,7 +3164,7 @@ class $pt extends S {
3164
@override
3165
String get transaction_sent => "Transação enviada!";
3166
@override
3167
- String get send_fee => "Taxa:";
3167
+ String get send_fee => "Taxa";
3168
@override
3169
String get password => "Senha";
3170
@override
@@ -3856,7 +3856,7 @@ class $uk extends S {
3856
@override
3857
String get transaction_sent => "Tранзакцію відправлено!";
3858
@override
3859
- String get send_fee => "Комісія:";
3859
+ String get send_fee => "Комісія";
3860
@override
3861
String get password => "Пароль";
3862
@override
@@ -4548,7 +4548,7 @@ class $ja extends S {
4548
@override
4549
String get transaction_sent => "トランザクションが送信されました!";
4550
@override
4551
- String get send_fee => "費用:";
4551
+ String get send_fee => "費用";
4552
@override
4553
String get password => "パスワード";
4554
@override
@@ -5244,7 +5244,7 @@ class $pl extends S {
5244
@override
5245
String get transaction_sent => "Transakcja wysłana!";
5246
@override
5247
- String get send_fee => "Opłata:";
5247
+ String get send_fee => "Opłata";
5248
@override
5249
String get password => "Hasło";
5250
@override
@@ -5936,7 +5936,7 @@ class $es extends S {
5936
@override
5937
String get transaction_sent => "Transacción enviada!";
5938
@override
5939
- String get send_fee => "Cuota:";
5939
+ String get send_fee => "Cuota";
5940
@override
5941
String get password => "Contraseña";
5942
@override
@@ -6628,7 +6628,7 @@ class $nl extends S {
6628
@override
6629
String get transaction_sent => "Transactie verzonden!";
6630
@override
6631
- String get send_fee => "Vergoeding:";
6631
+ String get send_fee => "Vergoeding";
6632
@override
6633
String get password => "Wachtwoord";
6634
@override
@@ -7320,7 +7320,7 @@ class $zh extends S {
7320
@override
7321
String get transaction_sent => "交易已发送";
7322
@override
7323
- String get send_fee => "費用:";
7323
+ String get send_fee => "費用";
7324
@override
7325
String get password => "密码";
7326
@override
lib/src/screens/dashboard/widgets/address_page.dart
+15
-17
@@ -16,10 +16,9 @@ class AddressPage extends StatelessWidget {
16
child: Column(
17
children: <Widget>[
18
Expanded(
19
- child: Center(
20
- child: QRWidget(addressListViewModel: addressListViewModel),
21
- )
22
- ),
19
+ child: Center(
20
+ child: QRWidget(addressListViewModel: addressListViewModel),
21
+ )),
22
GestureDetector(
23
onTap: () => Navigator.of(context).pushNamed(Routes.receive),
24
child: Container(
@@ -27,24 +26,23 @@ class AddressPage extends StatelessWidget {
26
padding: EdgeInsets.only(left: 24, right: 12),
27
alignment: Alignment.center,
28
decoration: BoxDecoration(
30
- borderRadius: BorderRadius.all(Radius.circular(25)),
31
- border: Border.all(
32
- color: Theme.of(context).textTheme.subhead.color,
33
- width: 1
34
- ),
35
- color: Theme.of(context).buttonColor
36
- ),
29
+ borderRadius: BorderRadius.all(Radius.circular(25)),
30
+ border: Border.all(
31
+ color: Theme.of(context).textTheme.subhead.color,
32
+ width: 1),
33
+ color: Theme.of(context).buttonColor),
34
child: Row(
35
mainAxisSize: MainAxisSize.max,
36
mainAxisAlignment: MainAxisAlignment.spaceBetween,
37
children: <Widget>[
38
Text(
42
- S.of(context).accounts_subaddresses,
39
+ addressListViewModel.hasAccounts
40
+ ? S.of(context).accounts_subaddresses
41
+ : S.of(context).addresses,
42
style: TextStyle(
44
- fontSize: 14,
45
- fontWeight: FontWeight.w500,
46
- color: Colors.white
47
- ),
43
+ fontSize: 14,
44
+ fontWeight: FontWeight.w500,
45
+ color: Colors.white),
46
),
47
Icon(
48
Icons.arrow_forward_ios,
@@ -59,4 +57,4 @@ class AddressPage extends StatelessWidget {
57
),
58
);
59
}
62
-}
\ No newline at end of file
60
+}
lib/src/screens/transaction_details/transaction_details_page.dart
+9
-6
@@ -13,7 +13,8 @@ import 'package:cake_wallet/utils/date_formatter.dart';
13
import 'package:hive/hive.dart';
14
15
class TransactionDetailsPage extends BasePage {
16
- TransactionDetailsPage(this.transactionInfo, bool showRecipientAddress, Box<TransactionDescription> transactionDescriptionBox)
16
+ TransactionDetailsPage(this.transactionInfo, bool showRecipientAddress,
17
+ Box<TransactionDescription> transactionDescriptionBox)
18
: _items = [] {
19
final dateFormat = DateFormatter.withCurrentLocal();
20
final tx = transactionInfo;
@@ -30,9 +31,7 @@ class TransactionDetailsPage extends BasePage {
31
StandartListItem(
32
title: S.current.transaction_details_amount,
33
value: tx.amountFormatted()),
33
- StandartListItem(
34
- title: S.current.send_fee,
35
- value: tx.feeFormatted())
34
+ StandartListItem(title: S.current.send_fee, value: tx.feeFormatted())
35
];
36
37
if (tx.key?.isNotEmpty ?? null) {
@@ -56,14 +55,18 @@ class TransactionDetailsPage extends BasePage {
55
title: S.current.transaction_details_height, value: '${tx.height}'),
56
StandartListItem(
57
title: S.current.transaction_details_amount,
59
- value: tx.amountFormatted())
58
+ value: tx.amountFormatted()),
59
+ if (tx.feeFormatted()?.isNotEmpty)
60
+ StandartListItem(title: S.current.send_fee, value: tx.feeFormatted())
61
];
62
63
_items.addAll(items);
64
}
65
66
if (showRecipientAddress) {
66
- final recipientAddress = transactionDescriptionBox.values.firstWhere((val) => val.id == transactionInfo.id, orElse: () => null)?.recipientAddress;
67
+ final recipientAddress = transactionDescriptionBox.values
68
+ .firstWhere((val) => val.id == transactionInfo.id, orElse: () => null)
69
+ ?.recipientAddress;
70
71
if (recipientAddress?.isNotEmpty ?? false) {
72
_items.add(StandartListItem(
lib/view_model/dashboard/balance_view_model.dart
+1
-1
@@ -95,7 +95,7 @@ abstract class BalanceViewModelBase with Store {
95
96
if (_wallet is BitcoinWallet) {
97
return WalletBalance(
98
- unlockedBalance: _wallet.balance.totalFormatted,
98
+ unlockedBalance: _wallet.balance.confirmedFormatted,
99
totalBalance: _wallet.balance.totalFormatted);
100
}
101