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;
} }

View file

@ -1,27 +1,51 @@
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(
config: KeyboardActionsConfig(
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
keyboardBarColor:
Theme.of(context).accentTextTheme.body2.backgroundColor,
nextFocus: false,
actions: [
KeyboardActionsItem(
focusNode: _cryptoAmountFocus,
toolbarButtons: [(_) => KeyboardDoneButton()],
)
]),
child: Container(
height: 1,
padding: EdgeInsets.fromLTRB(24, 24, 24, 32), padding: EdgeInsets.fromLTRB(24, 24, 24, 32),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: Center( child: Center(
child: QRWidget(addressListViewModel: addressListViewModel), child: QRWidget(
addressListViewModel: addressListViewModel,
amountTextFieldFocusNode: _cryptoAmountFocus,
isAmountFieldShow: !addressListViewModel.hasAccounts),
)), )),
GestureDetector( addressListViewModel.hasAddressList
onTap: () => Navigator.of(context).pushNamed(Routes.receive), ? GestureDetector(
onTap: () =>
Navigator.of(context).pushNamed(Routes.receive),
child: Container( child: Container(
height: 50, height: 50,
padding: EdgeInsets.only(left: 24, right: 12), padding: EdgeInsets.only(left: 24, right: 12),
@ -29,7 +53,8 @@ class AddressPage extends StatelessWidget {
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(25)), borderRadius: BorderRadius.all(Radius.circular(25)),
border: Border.all( border: Border.all(
color: Theme.of(context).textTheme.subhead.color, color:
Theme.of(context).textTheme.subhead.color,
width: 1), width: 1),
color: Theme.of(context).buttonColor), color: Theme.of(context).buttonColor),
child: Row( child: Row(
@ -61,8 +86,16 @@ class AddressPage extends StatelessWidget {
), ),
), ),
) )
: 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"