Changed address list for btc wallet type. Changed android and ios projects version.

This commit is contained in:
M 2021-01-07 14:19:21 +02:00
parent 41b4c337e9
commit 26a30a62f0
7 changed files with 140 additions and 89 deletions

View file

@ -354,7 +354,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 12; CURRENT_PROJECT_VERSION = 13;
DEVELOPMENT_TEAM = 32J6BB6VUS; DEVELOPMENT_TEAM = 32J6BB6VUS;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
@ -494,7 +494,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 12; CURRENT_PROJECT_VERSION = 13;
DEVELOPMENT_TEAM = 32J6BB6VUS; DEVELOPMENT_TEAM = 32J6BB6VUS;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
@ -528,7 +528,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 12; CURRENT_PROJECT_VERSION = 13;
DEVELOPMENT_TEAM = 32J6BB6VUS; DEVELOPMENT_TEAM = 32J6BB6VUS;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (

View file

@ -1,19 +1,17 @@
import 'dart:convert'; import 'dart:convert';
class BitcoinAddressRecord { class BitcoinAddressRecord {
BitcoinAddressRecord(this.address, {this.label, this.index}); BitcoinAddressRecord(this.address, {this.index});
factory BitcoinAddressRecord.fromJSON(String jsonSource) { factory BitcoinAddressRecord.fromJSON(String jsonSource) {
final decoded = json.decode(jsonSource) as Map; final decoded = json.decode(jsonSource) as Map;
return BitcoinAddressRecord(decoded['address'] as String, return BitcoinAddressRecord(decoded['address'] as String,
label: decoded['label'] as String, index: decoded['index'] as int); index: decoded['index'] as int);
} }
final String address; final String address;
int index; int index;
String label;
String toJSON() => String toJSON() => json.encode({'address': address, 'index': index});
json.encode({'label': label, 'address': address, 'index': index});
} }

View file

@ -167,21 +167,31 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
Map<String, BehaviorSubject<Object>> _scripthashesUpdateSubject; Map<String, BehaviorSubject<Object>> _scripthashesUpdateSubject;
Future<void> init() async { Future<void> init() async {
if (addresses.isEmpty) { if (addresses.isEmpty || addresses.length < 33) {
final index = 0; final addressesCount = 33 - addresses.length;
addresses await generateNewAddresses(addressesCount, startIndex: _accountIndex);
.add(BitcoinAddressRecord(_getAddress(index: index), index: index));
} }
address = addresses.first.address; address = addresses[_accountIndex].address;
transactionHistory.wallet = this; transactionHistory.wallet = this;
await transactionHistory.init(); await transactionHistory.init();
} }
Future<BitcoinAddressRecord> generateNewAddress({String label}) async { @action
void nextAddress() {
_accountIndex += 1;
if (_accountIndex >= addresses.length) {
_accountIndex = 0;
}
address = addresses[_accountIndex].address;
}
Future<BitcoinAddressRecord> generateNewAddress() async {
_accountIndex += 1; _accountIndex += 1;
final address = BitcoinAddressRecord(_getAddress(index: _accountIndex), final address = BitcoinAddressRecord(_getAddress(index: _accountIndex),
index: _accountIndex, label: label); index: _accountIndex);
addresses.add(address); addresses.add(address);
await save(); await save();
@ -189,13 +199,12 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
return address; return address;
} }
Future<List<BitcoinAddressRecord>> generateNewAddresses(int count) async { Future<List<BitcoinAddressRecord>> generateNewAddresses(int count,
{int startIndex = 0}) async {
final list = <BitcoinAddressRecord>[]; final list = <BitcoinAddressRecord>[];
for (var i = 0; i < count; i++) { for (var i = startIndex; i < count + startIndex; i++) {
_accountIndex += 1; final address = BitcoinAddressRecord(_getAddress(index: i), index: i);
final address = BitcoinAddressRecord(_getAddress(index: _accountIndex),
index: _accountIndex, label: null);
list.add(address); list.add(address);
} }
@ -205,10 +214,9 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
return list; return list;
} }
Future<void> updateAddress(String address, {String label}) async { Future<void> updateAddress(String address) async {
for (final addr in addresses) { for (final addr in addresses) {
if (addr.address == address) { if (addr.address == address) {
addr.label = label;
await save(); await save();
break; break;
} }
@ -368,7 +376,7 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
} }
@override @override
void close() async{ void close() async {
await eclient.close(); await eclient.close();
} }

View file

@ -1,68 +1,101 @@
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart'; import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart';
import 'package:cake_wallet/src/screens/receive/widgets/qr_widget.dart'; import 'package:cake_wallet/src/screens/receive/widgets/qr_widget.dart';
import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
class AddressPage extends StatelessWidget { class AddressPage extends StatelessWidget {
AddressPage({@required this.addressListViewModel}); AddressPage({@required this.addressListViewModel})
: _cryptoAmountFocus = FocusNode();
final WalletAddressListViewModel addressListViewModel; final WalletAddressListViewModel addressListViewModel;
final FocusNode _cryptoAmountFocus;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return KeyboardActions(
padding: EdgeInsets.fromLTRB(24, 24, 24, 32), config: KeyboardActionsConfig(
child: Column( keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
children: <Widget>[ keyboardBarColor:
Expanded( Theme.of(context).accentTextTheme.body2.backgroundColor,
child: Center( nextFocus: false,
child: QRWidget(addressListViewModel: addressListViewModel), actions: [
)), KeyboardActionsItem(
GestureDetector( focusNode: _cryptoAmountFocus,
onTap: () => Navigator.of(context).pushNamed(Routes.receive), toolbarButtons: [(_) => KeyboardDoneButton()],
child: Container( )
height: 50, ]),
padding: EdgeInsets.only(left: 24, right: 12), child: Container(
alignment: Alignment.center, height: 1,
decoration: BoxDecoration( padding: EdgeInsets.fromLTRB(24, 24, 24, 32),
borderRadius: BorderRadius.all(Radius.circular(25)), child: Column(
border: Border.all( children: <Widget>[
color: Theme.of(context).textTheme.subhead.color, Expanded(
width: 1), child: Center(
color: Theme.of(context).buttonColor), child: QRWidget(
child: Row( addressListViewModel: addressListViewModel,
mainAxisSize: MainAxisSize.max, amountTextFieldFocusNode: _cryptoAmountFocus,
mainAxisAlignment: MainAxisAlignment.spaceBetween, isAmountFieldShow: !addressListViewModel.hasAccounts),
children: <Widget>[ )),
Observer( addressListViewModel.hasAddressList
builder: (_) => Text( ? GestureDetector(
addressListViewModel.hasAccounts onTap: () =>
? S.of(context).accounts_subaddresses Navigator.of(context).pushNamed(Routes.receive),
: S.of(context).addresses, child: Container(
style: TextStyle( height: 50,
fontSize: 14, padding: EdgeInsets.only(left: 24, right: 12),
fontWeight: FontWeight.w500, alignment: Alignment.center,
color: Theme.of(context) decoration: BoxDecoration(
.accentTextTheme borderRadius: BorderRadius.all(Radius.circular(25)),
.display3 border: Border.all(
.backgroundColor), color:
)), Theme.of(context).textTheme.subhead.color,
Icon( width: 1),
Icons.arrow_forward_ios, color: Theme.of(context).buttonColor),
size: 14, child: Row(
color: Theme.of(context) mainAxisSize: MainAxisSize.max,
.accentTextTheme mainAxisAlignment: MainAxisAlignment.spaceBetween,
.display3 children: <Widget>[
.backgroundColor, Observer(
) builder: (_) => Text(
], addressListViewModel.hasAccounts
), ? S.of(context).accounts_subaddresses
), : S.of(context).addresses,
) style: TextStyle(
], fontSize: 14,
), fontWeight: FontWeight.w500,
); color: Theme.of(context)
.accentTextTheme
.display3
.backgroundColor),
)),
Icon(
Icons.arrow_forward_ios,
size: 14,
color: Theme.of(context)
.accentTextTheme
.display3
.backgroundColor,
)
],
),
),
)
: PrimaryButton(
onPressed: () => addressListViewModel.nextAddress(),
text: 'Next address',
color: Theme.of(context).buttonColor,
textColor: Theme.of(context)
.accentTextTheme
.display3
.backgroundColor)
],
),
));
} }
} }

View file

@ -63,7 +63,7 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store {
final wallet = _wallet; final wallet = _wallet;
if (wallet is BitcoinWallet) { if (wallet is BitcoinWallet) {
await wallet.generateNewAddress(label: label); await wallet.generateNewAddress();
} }
if (wallet is MoneroWallet) { if (wallet is MoneroWallet) {
@ -77,7 +77,7 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store {
final wallet = _wallet; final wallet = _wallet;
if (wallet is BitcoinWallet) { if (wallet is BitcoinWallet) {
await wallet.updateAddress(_item.address as String, label: label); await wallet.updateAddress(_item.address as String);
} }
if (wallet is MoneroWallet) { if (wallet is MoneroWallet) {

View file

@ -119,7 +119,7 @@ abstract class WalletAddressListViewModelBase with Store {
return WalletAddressListItem( return WalletAddressListItem(
isPrimary: isPrimary, isPrimary: isPrimary,
name: addr.label, name: null,
address: addr.address); address: addr.address);
}); });
addressList.addAll(bitcoinAddresses); addressList.addAll(bitcoinAddresses);
@ -131,15 +131,6 @@ abstract class WalletAddressListViewModelBase with Store {
@observable @observable
bool hasAccounts; bool hasAccounts;
@observable
WalletBase _wallet;
List<ListItem> _baseItems;
AppStore _appStore;
ReactionDisposer _onWalletChangeReaction;
@computed @computed
String get accountLabel { String get accountLabel {
final wallet = _wallet; final wallet = _wallet;
@ -151,6 +142,18 @@ abstract class WalletAddressListViewModelBase with Store {
return null; return null;
} }
bool get hasAddressList => _wallet.type == WalletType.monero;
@observable
WalletBase _wallet;
List<ListItem> _baseItems;
AppStore _appStore;
ReactionDisposer _onWalletChangeReaction;
@action @action
void setAddress(WalletAddressListItem address) => void setAddress(WalletAddressListItem address) =>
_wallet.address = address.address; _wallet.address = address.address;
@ -164,4 +167,13 @@ abstract class WalletAddressListViewModelBase with Store {
_baseItems.add(WalletAddressListHeader()); _baseItems.add(WalletAddressListHeader());
} }
@action
void nextAddress() {
final wallet = _wallet;
if (wallet is BitcoinWallet) {
wallet.nextAddress();
}
}
} }

View file

@ -11,7 +11,7 @@ description: Cake Wallet.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at # Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 4.1.0+28 version: 4.1.0+29
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: ">=2.7.0 <3.0.0"