mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 01:37:40 +00:00
Integrated wallet names generation
This commit is contained in:
parent
62cf0d0b4c
commit
0c197660a8
9 changed files with 89 additions and 34 deletions
|
@ -14,6 +14,7 @@ import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_page.dart'
|
|||
import 'package:cake_wallet/src/screens/faq/faq_page.dart';
|
||||
import 'package:cake_wallet/src/screens/nodes/node_create_or_edit_page.dart';
|
||||
import 'package:cake_wallet/src/screens/nodes/nodes_list_page.dart';
|
||||
import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart';
|
||||
import 'package:cake_wallet/src/screens/rescan/rescan_page.dart';
|
||||
import 'package:cake_wallet/src/screens/restore/wallet_restore_page.dart';
|
||||
import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart';
|
||||
|
@ -237,7 +238,10 @@ Future setup(
|
|||
() => SendTemplatePage(sendViewModel: getIt.get<SendViewModel>()));
|
||||
|
||||
getIt.registerFactory(() => WalletListViewModel(
|
||||
walletInfoSource, getIt.get<AppStore>(), getIt.get<KeyService>()));
|
||||
walletInfoSource,
|
||||
getIt.get<AppStore>(),
|
||||
getIt.get<KeyService>(),
|
||||
getIt.get<WalletNewVM>(param1: WalletType.monero)));
|
||||
|
||||
getIt.registerFactory(() =>
|
||||
WalletListPage(walletListViewModel: getIt.get<WalletListViewModel>()));
|
||||
|
@ -361,7 +365,7 @@ Future setup(
|
|||
getIt.get<AuthService>(), getIt.get<SettingsStore>()));
|
||||
|
||||
getIt.registerFactoryParam<SetupPinCodePage,
|
||||
void Function(BuildContext, String), void>(
|
||||
void Function(PinCodeState<PinCodeWidget>, String), void>(
|
||||
(onSuccessfulPinSetup, _) => SetupPinCodePage(
|
||||
getIt.get<SetupPinCodeViewModel>(),
|
||||
onSuccessfulPinSetup: onSuccessfulPinSetup));
|
||||
|
|
18
lib/entities/generate_name.dart
Normal file
18
lib/entities/generate_name.dart
Normal file
|
@ -0,0 +1,18 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
Future<String> generateName() async {
|
||||
final randomThing = Random();
|
||||
final adjectiveStringRaw =
|
||||
await rootBundle.loadString('assets/text/Wallet_Adjectives.txt');
|
||||
final nounStringRaw =
|
||||
await rootBundle.loadString('assets/text/Wallet_Nouns.txt');
|
||||
final adjectives = List<String>.from(adjectiveStringRaw.split('\n'));
|
||||
final nouns = List<String>.from(nounStringRaw.split('\n'));
|
||||
final chosenAdjective = adjectives[randomThing.nextInt(adjectives.length)];
|
||||
final chosenNoun = nouns[randomThing.nextInt(nouns.length)];
|
||||
final returnString = chosenAdjective + ' ' + chosenNoun;
|
||||
|
||||
return returnString;
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:cake_wallet/entities/contact_record.dart';
|
||||
import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart';
|
||||
import 'package:cake_wallet/src/screens/restore/wallet_restore_page.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -57,8 +58,17 @@ Route<dynamic> createRoute(RouteSettings settings) {
|
|||
case Routes.newWalletFromWelcome:
|
||||
return CupertinoPageRoute<void>(
|
||||
builder: (_) => getIt.get<SetupPinCodePage>(
|
||||
param1: (BuildContext context, dynamic _) =>
|
||||
Navigator.pushNamed(context, Routes.newWallet)),
|
||||
param1: (PinCodeState<PinCodeWidget> context, dynamic _) async {
|
||||
try {
|
||||
context.changeProcessText('Creating new wallet'); // FIXME: Unnamed constant
|
||||
final newWalletVM = getIt.get<WalletNewVM>(param1: WalletType.monero);
|
||||
await newWalletVM.create(options: 'English'); // FIXME: Unnamed constant
|
||||
context.hideProgressText();
|
||||
await Navigator.of(context.context).pushNamed(Routes.seed, arguments: true);
|
||||
} catch(e) {
|
||||
context.changeProcessText('Error: ${e.toString()}');
|
||||
}
|
||||
}),
|
||||
fullscreenDialog: true);
|
||||
|
||||
case Routes.newWalletType:
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:flushbar/flushbar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
|
@ -33,6 +35,7 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
|
|||
String pin;
|
||||
String title;
|
||||
double _aspectRatio;
|
||||
Flushbar<void> _progressBar;
|
||||
|
||||
int currentPinLength() => pin.length;
|
||||
|
||||
|
@ -80,6 +83,17 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
|
|||
setState(() {});
|
||||
}
|
||||
|
||||
void changeProcessText(String text) {
|
||||
hideProgressText();
|
||||
_progressBar = createBar<void>(text, duration: null)
|
||||
..show(_key.currentContext);
|
||||
}
|
||||
|
||||
void hideProgressText() {
|
||||
_progressBar?.dismiss();
|
||||
_progressBar = null;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
key: _key, body: body(context), resizeToAvoidBottomPadding: false);
|
||||
|
|
|
@ -8,19 +8,23 @@ import 'package:cake_wallet/view_model/setup_pin_code_view_model.dart';
|
|||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||
|
||||
class SetupPinCodePage extends BasePage {
|
||||
SetupPinCodePage(this.pinCodeViewModel, {this.onSuccessfulPinSetup});
|
||||
SetupPinCodePage(this.pinCodeViewModel, {this.onSuccessfulPinSetup})
|
||||
: pinCodeStateKey = GlobalKey<PinCodeState>();
|
||||
|
||||
final SetupPinCodeViewModel pinCodeViewModel;
|
||||
final void Function(BuildContext, String) onSuccessfulPinSetup;
|
||||
final void Function(PinCodeState<PinCodeWidget>, String) onSuccessfulPinSetup;
|
||||
final GlobalKey<PinCodeState> pinCodeStateKey;
|
||||
|
||||
@override
|
||||
String get title => S.current.setup_pin;
|
||||
|
||||
@override
|
||||
Widget body(BuildContext context) => PinCodeWidget(
|
||||
key: pinCodeStateKey,
|
||||
hasLengthSwitcher: true,
|
||||
onFullPin: (String pin, PinCodeState<PinCodeWidget> state) async {
|
||||
if (pinCodeViewModel.isOriginalPinCodeFull && !pinCodeViewModel.isRepeatedPinCodeFull) {
|
||||
if (pinCodeViewModel.isOriginalPinCodeFull &&
|
||||
!pinCodeViewModel.isRepeatedPinCodeFull) {
|
||||
state.title = S.current.enter_your_pin_again;
|
||||
state.clear();
|
||||
return;
|
||||
|
@ -53,7 +57,7 @@ class SetupPinCodePage extends BasePage {
|
|||
buttonText: S.of(context).ok,
|
||||
buttonAction: () {
|
||||
Navigator.of(context).pop();
|
||||
onSuccessfulPinSetup(context, pin);
|
||||
onSuccessfulPinSetup(pinCodeStateKey.currentState, pin);
|
||||
state.reset();
|
||||
},
|
||||
alertBarrierDismissible: false,
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
||||
import 'package:cake_wallet/src/screens/wallet_list/widgets/wallet_menu_alert.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart';
|
||||
import 'package:flushbar/flushbar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
|
@ -42,6 +44,7 @@ class WalletListBodyState extends State<WalletListBody> {
|
|||
Image.asset('assets/images/bitcoin.png', height: 24, width: 24);
|
||||
final scrollController = ScrollController();
|
||||
final double tileHeight = 60;
|
||||
Flushbar<void> _progressBar;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -164,8 +167,7 @@ class WalletListBodyState extends State<WalletListBody> {
|
|||
),
|
||||
bottomSection: Column(children: <Widget>[
|
||||
PrimaryImageButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pushNamed(Routes.newWallet),
|
||||
onPressed: () => _generateNewWallet(),
|
||||
image: newWalletImage,
|
||||
text: S.of(context).wallet_list_create_new_wallet,
|
||||
color: Theme.of(context).accentTextTheme.subtitle.decorationColor,
|
||||
|
@ -237,4 +239,25 @@ class WalletListBodyState extends State<WalletListBody> {
|
|||
auth.close();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _generateNewWallet() async {
|
||||
try {
|
||||
changeProcessText('Creating new wallet'); // FIXME: Unnamed constant
|
||||
await widget.walletListViewModel.walletNewVM.create(options: 'English'); // FIXME: Unnamed constant
|
||||
hideProgressText();
|
||||
await Navigator.of(context).pushNamed(Routes.seed, arguments: true);
|
||||
} catch(e) {
|
||||
changeProcessText('Error: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
void changeProcessText(String text) {
|
||||
_progressBar = createBar<void>(text, duration: null)
|
||||
..show(context);
|
||||
}
|
||||
|
||||
void hideProgressText() {
|
||||
_progressBar?.dismiss();
|
||||
_progressBar = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,7 @@ import 'package:cake_wallet/entities/pathForWallet.dart';
|
|||
import 'package:cake_wallet/entities/wallet_info.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'dart:math';
|
||||
import 'package:cake_wallet/entities/generate_name.dart';
|
||||
|
||||
part 'wallet_creation_vm.g.dart';
|
||||
|
||||
|
@ -33,26 +32,9 @@ abstract class WalletCreationVMBase with Store {
|
|||
final Box<WalletInfo> _walletInfoSource;
|
||||
final AppStore _appStore;
|
||||
|
||||
Future<String> generateName() async {
|
||||
final adjectiveStringRaw =
|
||||
await rootBundle.loadString('assets/text/Wallet_Adjectives.txt');
|
||||
final nounStringRaw =
|
||||
await rootBundle.loadString('assets/text/Wallet_Nouns.txt');
|
||||
|
||||
final randomThing = new Random();
|
||||
|
||||
final adjectives = new List<String>.from(adjectiveStringRaw.split("\n"));
|
||||
final nouns = new List<String>.from(nounStringRaw.split("\n"));
|
||||
|
||||
final chosenAdjective = adjectives[randomThing.nextInt(adjectives.length)];
|
||||
final chosenNoun = nouns[randomThing.nextInt(nouns.length)];
|
||||
|
||||
final returnString = chosenAdjective + " " + chosenNoun;
|
||||
return returnString;
|
||||
}
|
||||
|
||||
Future<void> create({dynamic options}) async {
|
||||
try {
|
||||
name = await generateName();
|
||||
state = IsExecutingState();
|
||||
final dirPath = await pathForWalletDir(name: name, type: type);
|
||||
final path = await pathForWallet(name: name, type: type);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:cake_wallet/view_model/wallet_new_vm.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/di.dart';
|
||||
|
@ -12,8 +13,8 @@ part 'wallet_list_view_model.g.dart';
|
|||
class WalletListViewModel = WalletListViewModelBase with _$WalletListViewModel;
|
||||
|
||||
abstract class WalletListViewModelBase with Store {
|
||||
WalletListViewModelBase(
|
||||
this._walletInfoSource, this._appStore, this._keyService) {
|
||||
WalletListViewModelBase(this._walletInfoSource, this._appStore,
|
||||
this._keyService, this.walletNewVM) {
|
||||
wallets = ObservableList<WalletListItem>();
|
||||
_updateList();
|
||||
}
|
||||
|
@ -24,6 +25,7 @@ abstract class WalletListViewModelBase with Store {
|
|||
final AppStore _appStore;
|
||||
final Box<WalletInfo> _walletInfoSource;
|
||||
final KeyService _keyService;
|
||||
final WalletNewVM walletNewVM;
|
||||
|
||||
@action
|
||||
Future<void> loadWallet(WalletListItem wallet) async {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/core/generate_wallet_password.dart';
|
||||
|
@ -37,7 +36,6 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
|||
WalletCredentials getCredentials(dynamic options) {
|
||||
final password = generateWalletPassword(type);
|
||||
final height = options['height'] as int;
|
||||
name = Uuid().v4().substring(0, 10);
|
||||
|
||||
if (mode == WalletRestoreMode.seed) {
|
||||
final seed = options['seed'] as String;
|
||||
|
|
Loading…
Reference in a new issue