mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-02-02 19:26:27 +00:00
Fixes
This commit is contained in:
parent
9ad76376d9
commit
62a877dd61
16 changed files with 223 additions and 123 deletions
|
@ -128,6 +128,17 @@ Uint8List mnemonicToSeedBytes(String mnemonic, {String prefix = segwit}) {
|
||||||
nonce: cryptography.Nonce('electrum'.codeUnits));
|
nonce: cryptography.Nonce('electrum'.codeUnits));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool matchesAnyPrefix(String mnemonic) =>
|
||||||
|
prefixMatches(mnemonic, [segwit]).any((el) => el);
|
||||||
|
|
||||||
|
bool validateMnemonic(String mnemonic, {String prefix = segwit}) {
|
||||||
|
try {
|
||||||
|
return matchesAnyPrefix(mnemonic);
|
||||||
|
} catch(e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final COMBININGCODEPOINTS = combiningcodepoints();
|
final COMBININGCODEPOINTS = combiningcodepoints();
|
||||||
|
|
||||||
List<int> combiningcodepoints() {
|
List<int> combiningcodepoints() {
|
||||||
|
|
|
@ -65,7 +65,7 @@ abstract class BitcoinTransactionHistoryBase
|
||||||
|
|
||||||
return historiesWithDetails.fold<Map<String, BitcoinTransactionInfo>>(
|
return historiesWithDetails.fold<Map<String, BitcoinTransactionInfo>>(
|
||||||
<String, BitcoinTransactionInfo>{}, (acc, tx) {
|
<String, BitcoinTransactionInfo>{}, (acc, tx) {
|
||||||
acc[tx.id] = tx;
|
acc[tx.id] = acc[tx.id]?.updated(tx) ?? tx;
|
||||||
return acc;
|
return acc;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -103,10 +103,6 @@ abstract class BitcoinTransactionHistoryBase
|
||||||
|
|
||||||
Future<void> save() async {
|
Future<void> save() async {
|
||||||
final data = json.encode({'height': _height, 'transactions': transactions});
|
final data = json.encode({'height': _height, 'transactions': transactions});
|
||||||
|
|
||||||
print('data');
|
|
||||||
print(data);
|
|
||||||
|
|
||||||
await writeData(path: path, password: _password, data: data);
|
await writeData(path: path, password: _password, data: data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +164,9 @@ abstract class BitcoinTransactionHistoryBase
|
||||||
});
|
});
|
||||||
|
|
||||||
_height = content['height'] as int;
|
_height = content['height'] as int;
|
||||||
} catch (_) {}
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateOrInsert(BitcoinTransactionInfo transaction) {
|
void _updateOrInsert(BitcoinTransactionInfo transaction) {
|
||||||
|
|
|
@ -130,6 +130,17 @@ class BitcoinTransactionInfo extends TransactionInfo {
|
||||||
@override
|
@override
|
||||||
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
|
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
|
||||||
|
|
||||||
|
BitcoinTransactionInfo updated(BitcoinTransactionInfo info) {
|
||||||
|
return BitcoinTransactionInfo(
|
||||||
|
id: id,
|
||||||
|
height: info.height,
|
||||||
|
amount: info.amount,
|
||||||
|
direction: direction ?? info.direction,
|
||||||
|
date: date ?? info.date,
|
||||||
|
isPending: isPending ?? info.isPending,
|
||||||
|
confirmations: info.confirmations);
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
final m = <String, dynamic>{};
|
final m = <String, dynamic>{};
|
||||||
m['id'] = id;
|
m['id'] = id;
|
||||||
|
|
|
@ -175,6 +175,22 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<BitcoinAddressRecord>> generateNewAddresses(int count) async {
|
||||||
|
final list = <BitcoinAddressRecord>[];
|
||||||
|
|
||||||
|
for (var i = 0; i < count; i++) {
|
||||||
|
_accountIndex += 1;
|
||||||
|
final address = BitcoinAddressRecord(_getAddress(index: _accountIndex),
|
||||||
|
index: _accountIndex, label: null);
|
||||||
|
list.add(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
addresses.addAll(list);
|
||||||
|
await save();
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> updateAddress(String address, {String label}) async {
|
Future<void> updateAddress(String address, {String label}) async {
|
||||||
for (final addr in addresses) {
|
for (final addr in addresses) {
|
||||||
if (addr.address == address) {
|
if (addr.address == address) {
|
||||||
|
@ -190,8 +206,10 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
|
||||||
Future<void> startSync() async {
|
Future<void> startSync() async {
|
||||||
try {
|
try {
|
||||||
syncStatus = StartingSyncStatus();
|
syncStatus = StartingSyncStatus();
|
||||||
transactionHistory.updateAsync(
|
transactionHistory.updateAsync(onFinished: () {
|
||||||
onFinished: () => print('transactionHistory update finished!'));
|
print('transactionHistory update finished!');
|
||||||
|
transactionHistory.save();
|
||||||
|
});
|
||||||
_subscribeForUpdates();
|
_subscribeForUpdates();
|
||||||
await _updateBalance();
|
await _updateBalance();
|
||||||
syncStatus = SyncedSyncStatus();
|
syncStatus = SyncedSyncStatus();
|
||||||
|
@ -315,8 +333,10 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
|
||||||
bitcoinAmountToDouble(amount: _feeMultiplier(priority));
|
bitcoinAmountToDouble(amount: _feeMultiplier(priority));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> save() async =>
|
Future<void> save() async {
|
||||||
await write(path: path, password: _password, data: toJSON());
|
await write(path: path, password: _password, data: toJSON());
|
||||||
|
await transactionHistory.save();
|
||||||
|
}
|
||||||
|
|
||||||
bitcoin.ECPair keyPairFor({@required int index}) =>
|
bitcoin.ECPair keyPairFor({@required int index}) =>
|
||||||
generateKeyPair(hd: hd, index: index);
|
generateKeyPair(hd: hd, index: index);
|
||||||
|
|
|
@ -84,6 +84,7 @@ class BitcoinWalletService extends WalletService<
|
||||||
walletInfo: credentials.walletInfo);
|
walletInfo: credentials.walletInfo);
|
||||||
await wallet.save();
|
await wallet.save();
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
|
await wallet.generateNewAddresses(32);
|
||||||
|
|
||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,14 +78,14 @@ class ElectrumClient {
|
||||||
print(jsoned);
|
print(jsoned);
|
||||||
final method = jsoned['method'];
|
final method = jsoned['method'];
|
||||||
final id = jsoned['id'] as String;
|
final id = jsoned['id'] as String;
|
||||||
final params = jsoned['result'];
|
final result = jsoned['result'];
|
||||||
|
|
||||||
if (method is String) {
|
if (method is String) {
|
||||||
_methodHandler(method: method, request: jsoned);
|
_methodHandler(method: method, request: jsoned);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_finish(id, params);
|
_finish(id, result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
}
|
}
|
||||||
|
@ -209,16 +209,20 @@ class ElectrumClient {
|
||||||
|
|
||||||
Future<Map<String, Object>> getTransactionExpanded(
|
Future<Map<String, Object>> getTransactionExpanded(
|
||||||
{@required String hash}) async {
|
{@required String hash}) async {
|
||||||
final originalTx = await getTransactionRaw(hash: hash);
|
try {
|
||||||
final vins = originalTx['vin'] as List<Object>;
|
final originalTx = await getTransactionRaw(hash: hash);
|
||||||
|
final vins = originalTx['vin'] as List<Object>;
|
||||||
|
|
||||||
for (dynamic vin in vins) {
|
for (dynamic vin in vins) {
|
||||||
if (vin is Map<String, Object>) {
|
if (vin is Map<String, Object>) {
|
||||||
vin['tx'] = await getTransactionRaw(hash: vin['txid'] as String);
|
vin['tx'] = await getTransactionRaw(hash: vin['txid'] as String);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return originalTx;
|
return originalTx;
|
||||||
|
} catch (_) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> broadcastTransaction(
|
Future<String> broadcastTransaction(
|
||||||
|
@ -256,11 +260,13 @@ class ElectrumClient {
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
BehaviorSubject<Object> scripthashUpdate(String scripthash) =>
|
BehaviorSubject<Object> scripthashUpdate(String scripthash) {
|
||||||
subscribe<Object>(
|
_id += 1;
|
||||||
id: 'blockchain.scripthash.subscribe:$scripthash',
|
return subscribe<Object>(
|
||||||
method: 'blockchain.scripthash.subscribe',
|
id: 'blockchain.scripthash.subscribe:$scripthash',
|
||||||
params: [scripthash]);
|
method: 'blockchain.scripthash.subscribe',
|
||||||
|
params: [scripthash]);
|
||||||
|
}
|
||||||
|
|
||||||
BehaviorSubject<T> subscribe<T>(
|
BehaviorSubject<T> subscribe<T>(
|
||||||
{@required String id,
|
{@required String id,
|
||||||
|
@ -273,7 +279,8 @@ class ElectrumClient {
|
||||||
return subscription;
|
return subscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> call({String method, List<Object> params = const []}) {
|
Future<dynamic> call({String method, List<Object> params = const []}) async {
|
||||||
|
await Future<void>.delayed(Duration(milliseconds: 100));
|
||||||
final completer = Completer<dynamic>();
|
final completer = Completer<dynamic>();
|
||||||
_id += 1;
|
_id += 1;
|
||||||
final id = _id;
|
final id = _id;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import 'package:bip39/src/wordlists/english.dart' as bitcoin_english;
|
import 'package:cake_wallet/bitcoin/bitcoin_mnemonic.dart' as bitcoin_electrum;
|
||||||
import 'package:cake_wallet/core/validator.dart';
|
import 'package:cake_wallet/core/validator.dart';
|
||||||
import 'package:cake_wallet/entities/mnemonic_item.dart';
|
import 'package:cake_wallet/entities/mnemonic_item.dart';
|
||||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||||
|
@ -64,7 +64,7 @@ class SeedValidator extends Validator<MnemonicItem> {
|
||||||
|
|
||||||
static List<String> getBitcoinWordList(String language) {
|
static List<String> getBitcoinWordList(String language) {
|
||||||
assert(language.toLowerCase() == LanguageList.english.toLowerCase());
|
assert(language.toLowerCase() == LanguageList.english.toLowerCase());
|
||||||
return bitcoin_english.WORDLIST;
|
return bitcoin_electrum.englishWordlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:cake_wallet/bitcoin/bitcoin_mnemonic.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
|
|
@ -74,7 +74,7 @@ Route<dynamic> createRoute(RouteSettings settings) {
|
||||||
param2: true));
|
param2: true));
|
||||||
|
|
||||||
case Routes.newWallet:
|
case Routes.newWallet:
|
||||||
final type = WalletType.monero; // settings.arguments as WalletType;
|
final type = settings.arguments as WalletType;
|
||||||
final walletNewVM = getIt.get<WalletNewVM>(param1: type);
|
final walletNewVM = getIt.get<WalletNewVM>(param1: type);
|
||||||
|
|
||||||
return CupertinoPageRoute<void>(
|
return CupertinoPageRoute<void>(
|
||||||
|
@ -96,7 +96,7 @@ Route<dynamic> createRoute(RouteSettings settings) {
|
||||||
builder: (_) => getIt.get<NewWalletTypePage>(
|
builder: (_) => getIt.get<NewWalletTypePage>(
|
||||||
param1: (BuildContext context, WalletType type) =>
|
param1: (BuildContext context, WalletType type) =>
|
||||||
Navigator.of(context)
|
Navigator.of(context)
|
||||||
.pushNamed(Routes.restoreWalletFromSeed, arguments: type),
|
.pushNamed(Routes.restoreWallet, arguments: type),
|
||||||
param2: false));
|
param2: false));
|
||||||
|
|
||||||
case Routes.restoreOptions:
|
case Routes.restoreOptions:
|
||||||
|
@ -146,7 +146,7 @@ Route<dynamic> createRoute(RouteSettings settings) {
|
||||||
case Routes.restoreWallet:
|
case Routes.restoreWallet:
|
||||||
return MaterialPageRoute<void>(
|
return MaterialPageRoute<void>(
|
||||||
builder: (_) =>
|
builder: (_) =>
|
||||||
getIt.get<WalletRestorePage>(param1: WalletType.monero));
|
getIt.get<WalletRestorePage>(param1: settings.arguments as WalletType));
|
||||||
|
|
||||||
case Routes.restoreWalletFromSeed:
|
case Routes.restoreWalletFromSeed:
|
||||||
final type = settings.arguments as WalletType;
|
final type = settings.arguments as WalletType;
|
||||||
|
|
|
@ -70,7 +70,7 @@ class WalletTypeFormState extends State<WalletTypeForm> {
|
||||||
: walletTypeLightImage;
|
: walletTypeLightImage;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: EdgeInsets.only(top: 24),
|
padding: EdgeInsets.only(top: 24, bottom: 24),
|
||||||
child: ScrollableWithBottomSection(
|
child: ScrollableWithBottomSection(
|
||||||
contentPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
contentPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
||||||
content: Column(
|
content: Column(
|
||||||
|
@ -107,7 +107,10 @@ class WalletTypeFormState extends State<WalletTypeForm> {
|
||||||
bottomSection: PrimaryButton(
|
bottomSection: PrimaryButton(
|
||||||
onPressed: () => onTypeSelected(),
|
onPressed: () => onTypeSelected(),
|
||||||
text: S.of(context).seed_language_next,
|
text: S.of(context).seed_language_next,
|
||||||
color: Colors.green,
|
color: Theme.of(context)
|
||||||
|
.accentTextTheme
|
||||||
|
.subtitle
|
||||||
|
.decorationColor,
|
||||||
textColor: Colors.white,
|
textColor: Colors.white,
|
||||||
isDisabled: selected == null,
|
isDisabled: selected == null,
|
||||||
),
|
),
|
||||||
|
|
|
@ -16,7 +16,7 @@ class SelectButton extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final color = isSelected
|
final color = isSelected
|
||||||
? Theme.of(context).accentTextTheme.subtitle.decorationColor
|
? Colors.green
|
||||||
: Theme.of(context).accentTextTheme.caption.color;
|
: Theme.of(context).accentTextTheme.caption.color;
|
||||||
final textColor = isSelected
|
final textColor = isSelected
|
||||||
? Theme.of(context).accentTextTheme.headline.decorationColor
|
? Theme.of(context).accentTextTheme.headline.decorationColor
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||||
|
import 'package:cake_wallet/view_model/wallet_restore_view_model.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
|
@ -7,12 +9,20 @@ import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
|
||||||
import 'package:cake_wallet/src/widgets/blockchain_height_widget.dart';
|
import 'package:cake_wallet/src/widgets/blockchain_height_widget.dart';
|
||||||
|
|
||||||
class WalletRestoreFromSeedForm extends StatefulWidget {
|
class WalletRestoreFromSeedForm extends StatefulWidget {
|
||||||
WalletRestoreFromSeedForm({Key key, this.blockHeightFocusNode,
|
WalletRestoreFromSeedForm(
|
||||||
this.onHeightOrDateEntered})
|
{Key key,
|
||||||
|
@required this.displayLanguageSelector,
|
||||||
|
@required this.displayBlockHeightSelector,
|
||||||
|
@required this.type,
|
||||||
|
this.blockHeightFocusNode,
|
||||||
|
this.onHeightOrDateEntered})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
|
final WalletType type;
|
||||||
|
final bool displayLanguageSelector;
|
||||||
|
final bool displayBlockHeightSelector;
|
||||||
final FocusNode blockHeightFocusNode;
|
final FocusNode blockHeightFocusNode;
|
||||||
final Function (bool) onHeightOrDateEntered;
|
final Function(bool) onHeightOrDateEntered;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
WalletRestoreFromSeedFormState createState() =>
|
WalletRestoreFromSeedFormState createState() =>
|
||||||
|
@ -41,32 +51,35 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
|
||||||
return Container(
|
return Container(
|
||||||
padding: EdgeInsets.only(left: 25, right: 25),
|
padding: EdgeInsets.only(left: 25, right: 25),
|
||||||
child: Column(children: [
|
child: Column(children: [
|
||||||
SeedWidget(key: seedWidgetStateKey, language: language),
|
SeedWidget(
|
||||||
GestureDetector(
|
key: seedWidgetStateKey, language: language, type: widget.type),
|
||||||
onTap: () async {
|
if (widget.displayLanguageSelector)
|
||||||
final selected = await showPopUp<String>(
|
GestureDetector(
|
||||||
context: context,
|
onTap: () async {
|
||||||
builder: (BuildContext context) =>
|
final selected = await showPopUp<String>(
|
||||||
SeedLanguagePicker(selected: language));
|
context: context,
|
||||||
|
builder: (BuildContext context) =>
|
||||||
|
SeedLanguagePicker(selected: language));
|
||||||
|
|
||||||
if (selected == null || selected.isEmpty) {
|
if (selected == null || selected.isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_changeLanguage(selected);
|
_changeLanguage(selected);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
padding: EdgeInsets.only(top: 20.0),
|
padding: EdgeInsets.only(top: 20.0),
|
||||||
child: IgnorePointer(
|
child: IgnorePointer(
|
||||||
child: BaseTextFormField(
|
child: BaseTextFormField(
|
||||||
controller: languageController,
|
controller: languageController,
|
||||||
enableInteractiveSelection: false,
|
enableInteractiveSelection: false,
|
||||||
readOnly: true)))),
|
readOnly: true)))),
|
||||||
BlockchainHeightWidget(
|
if (widget.displayBlockHeightSelector)
|
||||||
focusNode: widget.blockHeightFocusNode,
|
BlockchainHeightWidget(
|
||||||
key: blockchainHeightKey,
|
focusNode: widget.blockHeightFocusNode,
|
||||||
onHeightOrDateEntered: widget.onHeightOrDateEntered)
|
key: blockchainHeightKey,
|
||||||
|
onHeightOrDateEntered: widget.onHeightOrDateEntered)
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,16 +25,30 @@ class WalletRestorePage extends BasePage {
|
||||||
_pages = [],
|
_pages = [],
|
||||||
_blockHeightFocusNode = FocusNode(),
|
_blockHeightFocusNode = FocusNode(),
|
||||||
_controller = PageController(initialPage: 0) {
|
_controller = PageController(initialPage: 0) {
|
||||||
_pages.addAll([
|
walletRestoreViewModel.availableModes.forEach((mode) {
|
||||||
WalletRestoreFromSeedForm(
|
switch (mode) {
|
||||||
key: walletRestoreFromSeedFormKey,
|
case WalletRestoreMode.seed:
|
||||||
blockHeightFocusNode: _blockHeightFocusNode,
|
_pages.add(WalletRestoreFromSeedForm(
|
||||||
onHeightOrDateEntered: (value)
|
displayBlockHeightSelector:
|
||||||
=> walletRestoreViewModel.isButtonEnabled = value),
|
walletRestoreViewModel.hasBlockchainHeightLanguageSelector,
|
||||||
WalletRestoreFromKeysFrom(key: walletRestoreFromKeysFormKey,
|
displayLanguageSelector:
|
||||||
onHeightOrDateEntered: (value)
|
walletRestoreViewModel.hasSeedLanguageSelector,
|
||||||
=> walletRestoreViewModel.isButtonEnabled = value)
|
type: walletRestoreViewModel.type,
|
||||||
]);
|
key: walletRestoreFromSeedFormKey,
|
||||||
|
blockHeightFocusNode: _blockHeightFocusNode,
|
||||||
|
onHeightOrDateEntered: (value) =>
|
||||||
|
walletRestoreViewModel.isButtonEnabled = value));
|
||||||
|
break;
|
||||||
|
case WalletRestoreMode.keys:
|
||||||
|
_pages.add(WalletRestoreFromKeysFrom(
|
||||||
|
key: walletRestoreFromKeysFormKey,
|
||||||
|
onHeightOrDateEntered: (value) =>
|
||||||
|
walletRestoreViewModel.isButtonEnabled = value));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -76,20 +90,19 @@ class WalletRestorePage extends BasePage {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
reaction((_) => walletRestoreViewModel.mode, (WalletRestoreMode mode)
|
reaction((_) => walletRestoreViewModel.mode, (WalletRestoreMode mode) {
|
||||||
{
|
walletRestoreViewModel.isButtonEnabled = false;
|
||||||
walletRestoreViewModel.isButtonEnabled = false;
|
|
||||||
|
|
||||||
walletRestoreFromSeedFormKey.currentState.blockchainHeightKey
|
walletRestoreFromSeedFormKey.currentState.blockchainHeightKey.currentState
|
||||||
.currentState.restoreHeightController.text = '';
|
.restoreHeightController.text = '';
|
||||||
walletRestoreFromSeedFormKey.currentState.blockchainHeightKey
|
walletRestoreFromSeedFormKey.currentState.blockchainHeightKey.currentState
|
||||||
.currentState.dateController.text = '';
|
.dateController.text = '';
|
||||||
|
|
||||||
walletRestoreFromKeysFormKey.currentState.blockchainHeightKey
|
walletRestoreFromKeysFormKey.currentState.blockchainHeightKey.currentState
|
||||||
.currentState.restoreHeightController.text = '';
|
.restoreHeightController.text = '';
|
||||||
walletRestoreFromKeysFormKey.currentState.blockchainHeightKey
|
walletRestoreFromKeysFormKey.currentState.blockchainHeightKey.currentState
|
||||||
.currentState.dateController.text = '';
|
.dateController.text = '';
|
||||||
});
|
});
|
||||||
|
|
||||||
return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
|
return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
|
@ -100,40 +113,37 @@ class WalletRestorePage extends BasePage {
|
||||||
},
|
},
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
itemCount: _pages.length,
|
itemCount: _pages.length,
|
||||||
itemBuilder: (_, index) => SingleChildScrollView(child: _pages[index]))),
|
itemBuilder: (_, index) =>
|
||||||
Padding(
|
SingleChildScrollView(child: _pages[index]))),
|
||||||
padding: EdgeInsets.only(top: 10),
|
if (_pages.length > 1)
|
||||||
child: SmoothPageIndicator(
|
Padding(
|
||||||
controller: _controller,
|
padding: EdgeInsets.only(top: 10),
|
||||||
count: _pages.length,
|
child: SmoothPageIndicator(
|
||||||
effect: ColorTransitionEffect(
|
controller: _controller,
|
||||||
spacing: 6.0,
|
count: _pages.length,
|
||||||
radius: 6.0,
|
effect: ColorTransitionEffect(
|
||||||
dotWidth: 6.0,
|
spacing: 6.0,
|
||||||
dotHeight: 6.0,
|
radius: 6.0,
|
||||||
dotColor: Theme.of(context).hintColor.withOpacity(0.5),
|
dotWidth: 6.0,
|
||||||
activeDotColor: Theme.of(context).hintColor),
|
dotHeight: 6.0,
|
||||||
)),
|
dotColor: Theme.of(context).hintColor.withOpacity(0.5),
|
||||||
|
activeDotColor: Theme.of(context).hintColor),
|
||||||
|
)),
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(top: 20, bottom: 40, left: 25, right: 25),
|
padding: EdgeInsets.only(top: 20, bottom: 40, left: 25, right: 25),
|
||||||
child: Observer(
|
child: Observer(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return LoadingPrimaryButton(
|
return LoadingPrimaryButton(
|
||||||
onPressed: () =>
|
onPressed: () =>
|
||||||
walletRestoreViewModel.create(options: _credentials()),
|
walletRestoreViewModel.create(options: _credentials()),
|
||||||
text: S.of(context).restore_recover,
|
text: S.of(context).restore_recover,
|
||||||
color: Theme
|
color:
|
||||||
.of(context)
|
Theme.of(context).accentTextTheme.subtitle.decorationColor,
|
||||||
.accentTextTheme
|
textColor:
|
||||||
.subtitle
|
Theme.of(context).accentTextTheme.headline.decorationColor,
|
||||||
.decorationColor,
|
isLoading: walletRestoreViewModel.state is IsExecutingState,
|
||||||
textColor: Theme
|
isDisabled: !walletRestoreViewModel.isButtonEnabled,
|
||||||
.of(context)
|
);
|
||||||
.accentTextTheme
|
|
||||||
.headline
|
|
||||||
.decorationColor,
|
|
||||||
isLoading: walletRestoreViewModel.state is IsExecutingState,
|
|
||||||
isDisabled: !walletRestoreViewModel.isButtonEnabled,);
|
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
]);
|
]);
|
||||||
|
@ -145,8 +155,11 @@ class WalletRestorePage extends BasePage {
|
||||||
if (walletRestoreViewModel.mode == WalletRestoreMode.seed) {
|
if (walletRestoreViewModel.mode == WalletRestoreMode.seed) {
|
||||||
credentials['seed'] = walletRestoreFromSeedFormKey
|
credentials['seed'] = walletRestoreFromSeedFormKey
|
||||||
.currentState.seedWidgetStateKey.currentState.text;
|
.currentState.seedWidgetStateKey.currentState.text;
|
||||||
credentials['height'] = walletRestoreFromSeedFormKey
|
|
||||||
.currentState.blockchainHeightKey.currentState.height;
|
if (walletRestoreViewModel.hasBlockchainHeightLanguageSelector) {
|
||||||
|
credentials['height'] = walletRestoreFromSeedFormKey
|
||||||
|
.currentState.blockchainHeightKey.currentState.height;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
credentials['address'] =
|
credentials['address'] =
|
||||||
walletRestoreFromKeysFormKey.currentState.addressController.text;
|
walletRestoreFromKeysFormKey.currentState.addressController.text;
|
||||||
|
|
|
@ -12,20 +12,21 @@ import 'package:cake_wallet/generated/i18n.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
class SeedWidget extends StatefulWidget {
|
class SeedWidget extends StatefulWidget {
|
||||||
SeedWidget({Key key, this.language}) : super(key: key);
|
SeedWidget({Key key, this.language, this.type}) : super(key: key);
|
||||||
|
|
||||||
final String language;
|
final String language;
|
||||||
|
final WalletType type;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
SeedWidgetState createState() => SeedWidgetState(language);
|
SeedWidgetState createState() => SeedWidgetState(language, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
class SeedWidgetState extends State<SeedWidget> {
|
class SeedWidgetState extends State<SeedWidget> {
|
||||||
SeedWidgetState(String language)
|
SeedWidgetState(String language, this.type)
|
||||||
: controller = TextEditingController(),
|
: controller = TextEditingController(),
|
||||||
focusNode = FocusNode(),
|
focusNode = FocusNode(),
|
||||||
words = SeedValidator.getWordList(
|
words = SeedValidator.getWordList(
|
||||||
type: WalletType.monero, language: language) {
|
type:type, language: language) {
|
||||||
focusNode.addListener(() {
|
focusNode.addListener(() {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (!focusNode.hasFocus && controller.text.isEmpty) {
|
if (!focusNode.hasFocus && controller.text.isEmpty) {
|
||||||
|
@ -41,6 +42,7 @@ class SeedWidgetState extends State<SeedWidget> {
|
||||||
|
|
||||||
final TextEditingController controller;
|
final TextEditingController controller;
|
||||||
final FocusNode focusNode;
|
final FocusNode focusNode;
|
||||||
|
final WalletType type;
|
||||||
List<String> words;
|
List<String> words;
|
||||||
bool _showPlaceholder;
|
bool _showPlaceholder;
|
||||||
|
|
||||||
|
@ -55,7 +57,7 @@ class SeedWidgetState extends State<SeedWidget> {
|
||||||
void changeSeedLanguage(String language) {
|
void changeSeedLanguage(String language) {
|
||||||
setState(() {
|
setState(() {
|
||||||
words = SeedValidator.getWordList(
|
words = SeedValidator.getWordList(
|
||||||
type: WalletType.monero, language: language);
|
type: type, language: language);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,6 +178,7 @@ abstract class DashboardViewModelBase with Store {
|
||||||
@action
|
@action
|
||||||
void _onWalletChange(WalletBase wallet) {
|
void _onWalletChange(WalletBase wallet) {
|
||||||
this.wallet = wallet;
|
this.wallet = wallet;
|
||||||
|
type = wallet.type;
|
||||||
name = wallet.name;
|
name = wallet.name;
|
||||||
transactions.clear();
|
transactions.clear();
|
||||||
transactions.addAll(wallet.transactionHistory.transactions.values.map(
|
transactions.addAll(wallet.transactionHistory.transactions.values.map(
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:cake_wallet/bitcoin/bitcoin_wallet_creation_credentials.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
|
@ -22,10 +23,16 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||||
WalletRestoreViewModelBase(AppStore appStore, this._walletCreationService,
|
WalletRestoreViewModelBase(AppStore appStore, this._walletCreationService,
|
||||||
Box<WalletInfo> walletInfoSource,
|
Box<WalletInfo> walletInfoSource,
|
||||||
{@required WalletType type})
|
{@required WalletType type})
|
||||||
: super(appStore, walletInfoSource, type: type, isRecovery: true) {
|
: availableModes = type == WalletType.monero
|
||||||
isButtonEnabled = false;
|
? WalletRestoreMode.values
|
||||||
|
: [WalletRestoreMode.seed],
|
||||||
|
hasSeedLanguageSelector = type == WalletType.monero,
|
||||||
|
hasBlockchainHeightLanguageSelector = type == WalletType.monero,
|
||||||
|
super(appStore, walletInfoSource, type: type, isRecovery: true) {
|
||||||
|
isButtonEnabled =
|
||||||
|
!hasSeedLanguageSelector && !hasBlockchainHeightLanguageSelector;
|
||||||
mode = WalletRestoreMode.seed;
|
mode = WalletRestoreMode.seed;
|
||||||
_walletCreationService.changeWalletType(type: WalletType.monero);
|
_walletCreationService.changeWalletType(type: type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
|
@ -34,6 +41,10 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||||
@observable
|
@observable
|
||||||
bool isButtonEnabled;
|
bool isButtonEnabled;
|
||||||
|
|
||||||
|
final List<WalletRestoreMode> availableModes;
|
||||||
|
final bool hasSeedLanguageSelector;
|
||||||
|
final bool hasBlockchainHeightLanguageSelector;
|
||||||
|
|
||||||
final WalletCreationService _walletCreationService;
|
final WalletCreationService _walletCreationService;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -44,8 +55,16 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||||
if (mode == WalletRestoreMode.seed) {
|
if (mode == WalletRestoreMode.seed) {
|
||||||
final seed = options['seed'] as String;
|
final seed = options['seed'] as String;
|
||||||
|
|
||||||
return MoneroRestoreWalletFromSeedCredentials(
|
switch (type) {
|
||||||
name: name, height: height, mnemonic: seed, password: password);
|
case WalletType.monero:
|
||||||
|
return MoneroRestoreWalletFromSeedCredentials(
|
||||||
|
name: name, height: height, mnemonic: seed, password: password);
|
||||||
|
case WalletType.bitcoin:
|
||||||
|
return BitcoinRestoreWalletFromSeedCredentials(
|
||||||
|
name: name, mnemonic: seed, password: password);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == WalletRestoreMode.keys) {
|
if (mode == WalletRestoreMode.keys) {
|
||||||
|
|
Loading…
Reference in a new issue