Changed address list for btc wallet type. Changed android and ios projects version.
M committed
Jan 7, 2021 at 14:19 UTC
26a30a62f031655910bbcc196c78ebb1c399e480
7 files changed
+140
-89
ios/Runner.xcodeproj/project.pbxproj
+3
-3
@@ -354,7 +354,7 @@
354
buildSettings = {
355
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
356
CLANG_ENABLE_MODULES = YES;
357
- CURRENT_PROJECT_VERSION = 12;
357
+ CURRENT_PROJECT_VERSION = 13;
358
DEVELOPMENT_TEAM = 32J6BB6VUS;
359
ENABLE_BITCODE = NO;
360
FRAMEWORK_SEARCH_PATHS = (
@@ -494,7 +494,7 @@
494
buildSettings = {
495
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
496
CLANG_ENABLE_MODULES = YES;
497
- CURRENT_PROJECT_VERSION = 12;
497
+ CURRENT_PROJECT_VERSION = 13;
498
DEVELOPMENT_TEAM = 32J6BB6VUS;
499
ENABLE_BITCODE = NO;
500
FRAMEWORK_SEARCH_PATHS = (
@@ -528,7 +528,7 @@
528
buildSettings = {
529
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
530
CLANG_ENABLE_MODULES = YES;
531
- CURRENT_PROJECT_VERSION = 12;
531
+ CURRENT_PROJECT_VERSION = 13;
532
DEVELOPMENT_TEAM = 32J6BB6VUS;
533
ENABLE_BITCODE = NO;
534
FRAMEWORK_SEARCH_PATHS = (
lib/bitcoin/bitcoin_address_record.dart
+3
-5
@@ -1,19 +1,17 @@
1
import 'dart:convert';
2
3
class BitcoinAddressRecord {
4
- BitcoinAddressRecord(this.address, {this.label, this.index});
4
+ BitcoinAddressRecord(this.address, {this.index});
5
6
factory BitcoinAddressRecord.fromJSON(String jsonSource) {
7
final decoded = json.decode(jsonSource) as Map;
8
9
return BitcoinAddressRecord(decoded['address'] as String,
10
- label: decoded['label'] as String, index: decoded['index'] as int);
10
+ index: decoded['index'] as int);
11
}
12
13
final String address;
14
int index;
15
- String label;
15
17
- String toJSON() =>
18
- json.encode({'label': label, 'address': address, 'index': index});
16
+ String toJSON() => json.encode({'address': address, 'index': index});
17
}
lib/bitcoin/bitcoin_wallet.dart
+23
-15
@@ -167,21 +167,31 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
167
Map<String, BehaviorSubject<Object>> _scripthashesUpdateSubject;
168
169
Future<void> init() async {
170
- if (addresses.isEmpty) {
171
- final index = 0;
172
- addresses
173
- .add(BitcoinAddressRecord(_getAddress(index: index), index: index));
170
+ if (addresses.isEmpty || addresses.length < 33) {
171
+ final addressesCount = 33 - addresses.length;
172
+ await generateNewAddresses(addressesCount, startIndex: _accountIndex);
173
}
174
176
- address = addresses.first.address;
175
+ address = addresses[_accountIndex].address;
176
transactionHistory.wallet = this;
177
await transactionHistory.init();
178
}
179
181
- Future<BitcoinAddressRecord> generateNewAddress({String label}) async {
180
+ @action
181
+ void nextAddress() {
182
+ _accountIndex += 1;
183
+
184
+ if (_accountIndex >= addresses.length) {
185
+ _accountIndex = 0;
186
+ }
187
+
188
+ address = addresses[_accountIndex].address;
189
+ }
190
+
191
+ Future<BitcoinAddressRecord> generateNewAddress() async {
192
_accountIndex += 1;
193
final address = BitcoinAddressRecord(_getAddress(index: _accountIndex),
184
- index: _accountIndex, label: label);
194
+ index: _accountIndex);
195
addresses.add(address);
196
197
await save();
@@ -189,13 +199,12 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
199
return address;
200
}
201
192
- Future<List<BitcoinAddressRecord>> generateNewAddresses(int count) async {
202
+ Future<List<BitcoinAddressRecord>> generateNewAddresses(int count,
203
+ {int startIndex = 0}) async {
204
final list = <BitcoinAddressRecord>[];
205
195
- for (var i = 0; i < count; i++) {
196
- _accountIndex += 1;
197
- final address = BitcoinAddressRecord(_getAddress(index: _accountIndex),
198
- index: _accountIndex, label: null);
206
+ for (var i = startIndex; i < count + startIndex; i++) {
207
+ final address = BitcoinAddressRecord(_getAddress(index: i), index: i);
208
list.add(address);
209
}
210
@@ -205,10 +214,9 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
214
return list;
215
}
216
208
- Future<void> updateAddress(String address, {String label}) async {
217
+ Future<void> updateAddress(String address) async {
218
for (final addr in addresses) {
219
if (addr.address == address) {
211
- addr.label = label;
220
await save();
221
break;
222
}
@@ -368,7 +376,7 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
376
}
377
378
@override
371
- void close() async{
379
+ void close() async {
380
await eclient.close();
381
}
382
lib/src/screens/dashboard/widgets/address_page.dart
+86
-53
@@ -1,68 +1,101 @@
1
+import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
2
+import 'package:cake_wallet/src/widgets/primary_button.dart';
3
import 'package:flutter/material.dart';
4
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart';
5
import 'package:cake_wallet/src/screens/receive/widgets/qr_widget.dart';
6
import 'package:cake_wallet/routes.dart';
7
import 'package:cake_wallet/generated/i18n.dart';
8
import 'package:flutter_mobx/flutter_mobx.dart';
9
+import 'package:keyboard_actions/keyboard_actions.dart';
10
11
class AddressPage extends StatelessWidget {
9
- AddressPage({@required this.addressListViewModel});
12
+ AddressPage({@required this.addressListViewModel})
13
+ : _cryptoAmountFocus = FocusNode();
14
15
final WalletAddressListViewModel addressListViewModel;
16
17
+ final FocusNode _cryptoAmountFocus;
18
+
19
@override
20
Widget build(BuildContext context) {
15
- return Container(
16
- padding: EdgeInsets.fromLTRB(24, 24, 24, 32),
17
- child: Column(
18
- children: <Widget>[
19
- Expanded(
20
- child: Center(
21
- child: QRWidget(addressListViewModel: addressListViewModel),
22
- )),
23
- GestureDetector(
24
- onTap: () => Navigator.of(context).pushNamed(Routes.receive),
25
- child: Container(
26
- height: 50,
27
- padding: EdgeInsets.only(left: 24, right: 12),
28
- alignment: Alignment.center,
29
- 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
- color: Theme.of(context).buttonColor),
35
- child: Row(
36
- mainAxisSize: MainAxisSize.max,
37
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
38
- children: <Widget>[
39
- Observer(
40
- builder: (_) => Text(
41
- addressListViewModel.hasAccounts
42
- ? S.of(context).accounts_subaddresses
43
- : S.of(context).addresses,
44
- style: TextStyle(
45
- fontSize: 14,
46
- fontWeight: FontWeight.w500,
47
- color: Theme.of(context)
48
- .accentTextTheme
49
- .display3
50
- .backgroundColor),
51
- )),
52
- Icon(
53
- Icons.arrow_forward_ios,
54
- size: 14,
55
- color: Theme.of(context)
56
- .accentTextTheme
57
- .display3
58
- .backgroundColor,
59
- )
60
- ],
61
- ),
62
- ),
63
- )
64
- ],
65
- ),
66
- );
21
+ return KeyboardActions(
22
+ config: KeyboardActionsConfig(
23
+ keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
24
+ keyboardBarColor:
25
+ Theme.of(context).accentTextTheme.body2.backgroundColor,
26
+ nextFocus: false,
27
+ actions: [
28
+ KeyboardActionsItem(
29
+ focusNode: _cryptoAmountFocus,
30
+ toolbarButtons: [(_) => KeyboardDoneButton()],
31
+ )
32
+ ]),
33
+ child: Container(
34
+ height: 1,
35
+ padding: EdgeInsets.fromLTRB(24, 24, 24, 32),
36
+ child: Column(
37
+ children: <Widget>[
38
+ Expanded(
39
+ child: Center(
40
+ child: QRWidget(
41
+ addressListViewModel: addressListViewModel,
42
+ amountTextFieldFocusNode: _cryptoAmountFocus,
43
+ isAmountFieldShow: !addressListViewModel.hasAccounts),
44
+ )),
45
+ addressListViewModel.hasAddressList
46
+ ? GestureDetector(
47
+ onTap: () =>
48
+ Navigator.of(context).pushNamed(Routes.receive),
49
+ child: Container(
50
+ height: 50,
51
+ padding: EdgeInsets.only(left: 24, right: 12),
52
+ alignment: Alignment.center,
53
+ decoration: BoxDecoration(
54
+ borderRadius: BorderRadius.all(Radius.circular(25)),
55
+ border: Border.all(
56
+ color:
57
+ Theme.of(context).textTheme.subhead.color,
58
+ width: 1),
59
+ color: Theme.of(context).buttonColor),
60
+ child: Row(
61
+ mainAxisSize: MainAxisSize.max,
62
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
63
+ children: <Widget>[
64
+ Observer(
65
+ builder: (_) => Text(
66
+ addressListViewModel.hasAccounts
67
+ ? S.of(context).accounts_subaddresses
68
+ : S.of(context).addresses,
69
+ style: TextStyle(
70
+ fontSize: 14,
71
+ fontWeight: FontWeight.w500,
72
+ color: Theme.of(context)
73
+ .accentTextTheme
74
+ .display3
75
+ .backgroundColor),
76
+ )),
77
+ Icon(
78
+ Icons.arrow_forward_ios,
79
+ size: 14,
80
+ color: Theme.of(context)
81
+ .accentTextTheme
82
+ .display3
83
+ .backgroundColor,
84
+ )
85
+ ],
86
+ ),
87
+ ),
88
+ )
89
+ : PrimaryButton(
90
+ onPressed: () => addressListViewModel.nextAddress(),
91
+ text: 'Next address',
92
+ color: Theme.of(context).buttonColor,
93
+ textColor: Theme.of(context)
94
+ .accentTextTheme
95
+ .display3
96
+ .backgroundColor)
97
+ ],
98
+ ),
99
+ ));
100
}
101
}
lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart
+2
-2
@@ -63,7 +63,7 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store {
63
final wallet = _wallet;
64
65
if (wallet is BitcoinWallet) {
66
- await wallet.generateNewAddress(label: label);
66
+ await wallet.generateNewAddress();
67
}
68
69
if (wallet is MoneroWallet) {
@@ -77,7 +77,7 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store {
77
final wallet = _wallet;
78
79
if (wallet is BitcoinWallet) {
80
- await wallet.updateAddress(_item.address as String, label: label);
80
+ await wallet.updateAddress(_item.address as String);
81
}
82
83
if (wallet is MoneroWallet) {
lib/view_model/wallet_address_list/wallet_address_list_view_model.dart
+22
-10
@@ -119,7 +119,7 @@ abstract class WalletAddressListViewModelBase with Store {
119
120
return WalletAddressListItem(
121
isPrimary: isPrimary,
122
- name: addr.label,
122
+ name: null,
123
address: addr.address);
124
});
125
addressList.addAll(bitcoinAddresses);
@@ -131,15 +131,6 @@ abstract class WalletAddressListViewModelBase with Store {
131
@observable
132
bool hasAccounts;
133
134
- @observable
135
- WalletBase _wallet;
136
-
137
- List<ListItem> _baseItems;
138
-
139
- AppStore _appStore;
140
-
141
- ReactionDisposer _onWalletChangeReaction;
142
-
134
@computed
135
String get accountLabel {
136
final wallet = _wallet;
@@ -151,6 +142,18 @@ abstract class WalletAddressListViewModelBase with Store {
142
return null;
143
}
144
145
+ bool get hasAddressList => _wallet.type == WalletType.monero;
146
+
147
+ @observable
148
+ WalletBase _wallet;
149
+
150
+ List<ListItem> _baseItems;
151
+
152
+ AppStore _appStore;
153
+
154
+ ReactionDisposer _onWalletChangeReaction;
155
+
156
+
157
@action
158
void setAddress(WalletAddressListItem address) =>
159
_wallet.address = address.address;
@@ -164,4 +167,13 @@ abstract class WalletAddressListViewModelBase with Store {
167
168
_baseItems.add(WalletAddressListHeader());
169
}
170
+
171
+ @action
172
+ void nextAddress() {
173
+ final wallet = _wallet;
174
+
175
+ if (wallet is BitcoinWallet) {
176
+ wallet.nextAddress();
177
+ }
178
+ }
179
}
pubspec.yaml
+1
-1
@@ -11,7 +11,7 @@ description: Cake Wallet.
11
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
12
# Read more about iOS versioning at
13
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
14
-version: 4.1.0+28
14
+version: 4.1.0+29
15
16
environment:
17
sdk: ">=2.7.0 <3.0.0"