This commit is contained in:
M 2020-06-03 12:56:23 +03:00
parent e5d6586a6d
commit cfde445d32
6 changed files with 102 additions and 63 deletions

16
lib/core/app_service.dart Normal file
View file

@ -0,0 +1,16 @@
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/core/auth_service.dart';
import 'package:cake_wallet/core/wallet_base.dart';
import 'package:cake_wallet/core/wallet_creation_service.dart';
part 'app_service.g.dart';
class AppService = AppServiceBase with _$AppService;
abstract class AppServiceBase with Store {
AppServiceBase({this.walletCreationService, this.authService, this.wallet});
WalletCreationService walletCreationService;
AuthService authService;
WalletBase wallet;
}

View file

@ -1,12 +0,0 @@
import 'package:mobx/mobx.dart';
part 'app_store.g.dart';
class AppStore = AppStoreBase with _$AppStore;
abstract class AppStoreBase with Store {
// Sign Up
// Auth
// Wallet
// Settings
}

View file

@ -24,7 +24,7 @@ part 'bitcoin_wallet.g.dart';
class BitcoinWallet = BitcoinWalletBase with _$BitcoinWallet; class BitcoinWallet = BitcoinWalletBase with _$BitcoinWallet;
abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store { abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
static Future<BitcoinWallet> load( static Future<BitcoinWalletBase> load(
{@required String name, @required String password}) async { {@required String name, @required String password}) async {
final walletDirPath = final walletDirPath =
await pathForWalletDir(name: name, type: WalletType.bitcoin); await pathForWalletDir(name: name, type: WalletType.bitcoin);
@ -37,7 +37,7 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
? 0 ? 0
: int.parse(jsoned['account_index'] as String); : int.parse(jsoned['account_index'] as String);
return BitcoinWallet.build( return BitcoinWalletBase.build(
mnemonic: mnemonic, mnemonic: mnemonic,
password: password, password: password,
name: name, name: name,

View file

@ -16,9 +16,13 @@ abstract class WalletCreationServiceBase with Store {
@observable @observable
WalletCreationState state; WalletCreationState state;
WalletType type;
WalletListService _service; WalletListService _service;
void changeWalletType({@required WalletType type}) { void changeWalletType({@required WalletType type}) {
this.type = type;
switch (type) { switch (type) {
case WalletType.monero: case WalletType.monero:
_service = MoneroWalletListService(); _service = MoneroWalletListService();

View file

@ -1,3 +1,6 @@
import 'package:cake_wallet/core/app_service.dart';
import 'package:cake_wallet/core/auth_service.dart';
import 'package:cake_wallet/core/wallet_creation_service.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -41,7 +44,6 @@ import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/domain/common/language.dart'; import 'package:cake_wallet/src/domain/common/language.dart';
import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart'; import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart';
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
@ -73,7 +75,8 @@ void main() async {
await Hive.openBox<Trade>(Trade.boxName, encryptionKey: tradesBoxKey); await Hive.openBox<Trade>(Trade.boxName, encryptionKey: tradesBoxKey);
final walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName); final walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName);
final templates = await Hive.openBox<Template>(Template.boxName); final templates = await Hive.openBox<Template>(Template.boxName);
final exchangeTemplates = await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName); final exchangeTemplates =
await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName);
final sharedPreferences = await SharedPreferences.getInstance(); final sharedPreferences = await SharedPreferences.getInstance();
final walletService = WalletService(); final walletService = WalletService();
@ -111,7 +114,13 @@ void main() async {
sharedPreferences: sharedPreferences, walletsService: walletListService); sharedPreferences: sharedPreferences, walletsService: walletListService);
final seedLanguageStore = SeedLanguageStore(); final seedLanguageStore = SeedLanguageStore();
final sendTemplateStore = SendTemplateStore(templateSource: templates); final sendTemplateStore = SendTemplateStore(templateSource: templates);
final exchangeTemplateStore = ExchangeTemplateStore(templateSource: exchangeTemplates); final exchangeTemplateStore =
ExchangeTemplateStore(templateSource: exchangeTemplates);
final walletCreationService = WalletCreationService();
final authService = AuthService();
final appStore = AppService(
walletCreationService: walletCreationService, authService: authService);
setReactions( setReactions(
settingsStore: settingsStore, settingsStore: settingsStore,
@ -140,6 +149,9 @@ void main() async {
Provider(create: (_) => seedLanguageStore), Provider(create: (_) => seedLanguageStore),
Provider(create: (_) => sendTemplateStore), Provider(create: (_) => sendTemplateStore),
Provider(create: (_) => exchangeTemplateStore), Provider(create: (_) => exchangeTemplateStore),
Provider(create: (_) => appStore),
Provider(create: (_) => walletCreationService),
Provider(create: (_) => authService)
], child: CakeWalletApp())); ], child: CakeWalletApp()));
} }

View file

@ -1,3 +1,7 @@
import 'package:cake_wallet/core/monero_wallet_list_service.dart';
import 'package:cake_wallet/core/wallet_creation_service.dart';
import 'package:cake_wallet/core/wallet_credentials.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -55,9 +59,13 @@ class _WalletNameFormState extends State<WalletNameForm> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final walletCreationStore = Provider.of<WalletCreationStore>(context); final walletCreationStore = Provider.of<WalletCreationStore>(context);
final walletCreationService = Provider.of<WalletCreationService>(context);
// FIXME: Does seed language store is really needed ???
final seedLanguageStore = Provider.of<SeedLanguageStore>(context); final seedLanguageStore = Provider.of<SeedLanguageStore>(context);
final List<String> seedLocales = [ final seedLocales = [
S.current.seed_language_english, S.current.seed_language_english,
S.current.seed_language_chinese, S.current.seed_language_chinese,
S.current.seed_language_dutch, S.current.seed_language_dutch,
@ -68,13 +76,8 @@ class _WalletNameFormState extends State<WalletNameForm> {
S.current.seed_language_spanish S.current.seed_language_spanish
]; ];
nameController.addListener(() { nameController.addListener(() =>
if (nameController.text.isNotEmpty) { walletCreationStore.setDisabledStatus(!nameController.text.isNotEmpty));
walletCreationStore.setDisabledStatus(false);
} else {
walletCreationStore.setDisabledStatus(true);
}
});
reaction((_) => walletCreationStore.state, (WalletCreationState state) { reaction((_) => walletCreationStore.state, (WalletCreationState state) {
if (state is WalletCreatedSuccessfully) { if (state is WalletCreatedSuccessfully) {
@ -90,8 +93,7 @@ class _WalletNameFormState extends State<WalletNameForm> {
alertTitle: S.current.new_wallet, alertTitle: S.current.new_wallet,
alertContent: state.error, alertContent: state.error,
buttonText: S.of(context).ok, buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop() buttonAction: () => Navigator.of(context).pop());
);
}); });
}); });
} }
@ -101,15 +103,14 @@ class _WalletNameFormState extends State<WalletNameForm> {
padding: EdgeInsets.only(top: 24), padding: EdgeInsets.only(top: 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:
crossAxisAlignment: CrossAxisAlignment.center, Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
children: [ Padding(
Padding( padding: EdgeInsets.only(left: 12, right: 12),
padding: EdgeInsets.only(left: 12, right: 12), child: AspectRatio(
child: AspectRatio( aspectRatio: aspectRatioImage,
aspectRatio: aspectRatioImage, child: FittedBox(child: walletNameImage, fit: BoxFit.fill)),
child: FittedBox(child: walletNameImage, fit: BoxFit.fill)), ),
),
Padding( Padding(
padding: EdgeInsets.only(top: 24), padding: EdgeInsets.only(top: 24),
child: Form( child: Form(
@ -124,11 +125,13 @@ class _WalletNameFormState extends State<WalletNameForm> {
decoration: InputDecoration( decoration: InputDecoration(
hintStyle: TextStyle( hintStyle: TextStyle(
fontSize: 16.0, fontSize: 16.0,
color: Theme.of(context).primaryTextTheme.caption.color), color: Theme.of(context)
.primaryTextTheme
.caption
.color),
hintText: S.of(context).wallet_name, hintText: S.of(context).wallet_name,
focusedBorder: UnderlineInputBorder( focusedBorder: UnderlineInputBorder(
borderSide: borderSide: BorderSide(
BorderSide(
color: Theme.of(context).dividerColor, color: Theme.of(context).dividerColor,
width: 1.0)), width: 1.0)),
enabledBorder: UnderlineInputBorder( enabledBorder: UnderlineInputBorder(
@ -141,42 +144,42 @@ class _WalletNameFormState extends State<WalletNameForm> {
}, },
)), )),
), ),
Padding(padding: EdgeInsets.only(top: 40), Padding(
padding: EdgeInsets.only(top: 40),
child: Text( child: Text(
S.of(context).seed_language_choose, S.of(context).seed_language_choose,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
fontSize: 16.0, fontSize: 16.0,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Theme.of(context).primaryTextTheme.title.color color: Theme.of(context).primaryTextTheme.title.color),
),
), ),
), ),
Padding(padding: EdgeInsets.only(top: 24), Padding(
padding: EdgeInsets.only(top: 24),
child: Observer( child: Observer(
builder: (_) => SelectButton( builder: (_) => SelectButton(
image: null, image: null,
text: seedLocales[seedLanguages.indexOf(seedLanguageStore.selectedSeedLanguage)], text: seedLocales[seedLanguages
color: Theme.of(context).accentTextTheme.title.backgroundColor, .indexOf(seedLanguageStore.selectedSeedLanguage)],
textColor: Theme.of(context).primaryTextTheme.title.color, color: Theme.of(context)
onTap: () async => await showDialog( .accentTextTheme
context: context, .title
builder: (BuildContext context) => SeedLanguagePicker() .backgroundColor,
) textColor: Theme.of(context).primaryTextTheme.title.color,
) onTap: () async => await showDialog(
), context: context,
builder: (BuildContext context) =>
SeedLanguagePicker()))),
) )
]), ]),
bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24), bottomSectionPadding:
EdgeInsets.only(left: 24, right: 24, bottom: 24),
bottomSection: Observer( bottomSection: Observer(
builder: (context) { builder: (context) {
return LoadingPrimaryButton( return LoadingPrimaryButton(
onPressed: () { onPressed: () => _confirmForm(walletCreationService,
if (_formKey.currentState.validate()) { seedLanguageStore.selectedSeedLanguage),
walletCreationStore.create(name: nameController.text,
language: seedLanguageStore.selectedSeedLanguage);
}
},
text: S.of(context).continue_text, text: S.of(context).continue_text,
color: Colors.green, color: Colors.green,
textColor: Colors.white, textColor: Colors.white,
@ -187,4 +190,20 @@ class _WalletNameFormState extends State<WalletNameForm> {
)), )),
); );
} }
void _confirmForm(
WalletCreationService walletCreationService, String language) {
if (!_formKey.currentState.validate()) {
return;
}
WalletCredentials credentials;
if (walletCreationService.type == WalletType.monero) {
credentials = MoneroNewWalletCredentials(
name: nameController.text, language: language);
}
walletCreationService.create(credentials);
}
} }