mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-12 09:32:33 +00:00
TMP 3
This commit is contained in:
parent
e5d6586a6d
commit
cfde445d32
6 changed files with 102 additions and 63 deletions
16
lib/core/app_service.dart
Normal file
16
lib/core/app_service.dart
Normal 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;
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -24,7 +24,7 @@ part 'bitcoin_wallet.g.dart';
|
|||
class BitcoinWallet = BitcoinWalletBase with _$BitcoinWallet;
|
||||
|
||||
abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
|
||||
static Future<BitcoinWallet> load(
|
||||
static Future<BitcoinWalletBase> load(
|
||||
{@required String name, @required String password}) async {
|
||||
final walletDirPath =
|
||||
await pathForWalletDir(name: name, type: WalletType.bitcoin);
|
||||
|
@ -37,7 +37,7 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
|
|||
? 0
|
||||
: int.parse(jsoned['account_index'] as String);
|
||||
|
||||
return BitcoinWallet.build(
|
||||
return BitcoinWalletBase.build(
|
||||
mnemonic: mnemonic,
|
||||
password: password,
|
||||
name: name,
|
||||
|
|
|
@ -16,9 +16,13 @@ abstract class WalletCreationServiceBase with Store {
|
|||
@observable
|
||||
WalletCreationState state;
|
||||
|
||||
WalletType type;
|
||||
|
||||
WalletListService _service;
|
||||
|
||||
void changeWalletType({@required WalletType type}) {
|
||||
this.type = type;
|
||||
|
||||
switch (type) {
|
||||
case WalletType.monero:
|
||||
_service = MoneroWalletListService();
|
||||
|
|
|
@ -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:path_provider/path_provider.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/stores/seed_language/seed_language_store.dart';
|
||||
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
|
@ -73,7 +75,8 @@ void main() async {
|
|||
await Hive.openBox<Trade>(Trade.boxName, encryptionKey: tradesBoxKey);
|
||||
final walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.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 walletService = WalletService();
|
||||
|
@ -111,7 +114,13 @@ void main() async {
|
|||
sharedPreferences: sharedPreferences, walletsService: walletListService);
|
||||
final seedLanguageStore = SeedLanguageStore();
|
||||
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(
|
||||
settingsStore: settingsStore,
|
||||
|
@ -140,6 +149,9 @@ void main() async {
|
|||
Provider(create: (_) => seedLanguageStore),
|
||||
Provider(create: (_) => sendTemplateStore),
|
||||
Provider(create: (_) => exchangeTemplateStore),
|
||||
Provider(create: (_) => appStore),
|
||||
Provider(create: (_) => walletCreationService),
|
||||
Provider(create: (_) => authService)
|
||||
], child: CakeWalletApp()));
|
||||
}
|
||||
|
||||
|
|
|
@ -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:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
@ -55,9 +59,13 @@ class _WalletNameFormState extends State<WalletNameForm> {
|
|||
@override
|
||||
Widget build(BuildContext 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 List<String> seedLocales = [
|
||||
final seedLocales = [
|
||||
S.current.seed_language_english,
|
||||
S.current.seed_language_chinese,
|
||||
S.current.seed_language_dutch,
|
||||
|
@ -68,13 +76,8 @@ class _WalletNameFormState extends State<WalletNameForm> {
|
|||
S.current.seed_language_spanish
|
||||
];
|
||||
|
||||
nameController.addListener(() {
|
||||
if (nameController.text.isNotEmpty) {
|
||||
walletCreationStore.setDisabledStatus(false);
|
||||
} else {
|
||||
walletCreationStore.setDisabledStatus(true);
|
||||
}
|
||||
});
|
||||
nameController.addListener(() =>
|
||||
walletCreationStore.setDisabledStatus(!nameController.text.isNotEmpty));
|
||||
|
||||
reaction((_) => walletCreationStore.state, (WalletCreationState state) {
|
||||
if (state is WalletCreatedSuccessfully) {
|
||||
|
@ -90,8 +93,7 @@ class _WalletNameFormState extends State<WalletNameForm> {
|
|||
alertTitle: S.current.new_wallet,
|
||||
alertContent: state.error,
|
||||
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),
|
||||
child: ScrollableWithBottomSection(
|
||||
contentPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 12, right: 12),
|
||||
child: AspectRatio(
|
||||
aspectRatio: aspectRatioImage,
|
||||
child: FittedBox(child: walletNameImage, fit: BoxFit.fill)),
|
||||
),
|
||||
content:
|
||||
Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 12, right: 12),
|
||||
child: AspectRatio(
|
||||
aspectRatio: aspectRatioImage,
|
||||
child: FittedBox(child: walletNameImage, fit: BoxFit.fill)),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 24),
|
||||
child: Form(
|
||||
|
@ -124,11 +125,13 @@ class _WalletNameFormState extends State<WalletNameForm> {
|
|||
decoration: InputDecoration(
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Theme.of(context).primaryTextTheme.caption.color),
|
||||
color: Theme.of(context)
|
||||
.primaryTextTheme
|
||||
.caption
|
||||
.color),
|
||||
hintText: S.of(context).wallet_name,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).dividerColor,
|
||||
width: 1.0)),
|
||||
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(
|
||||
S.of(context).seed_language_choose,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Theme.of(context).primaryTextTheme.title.color
|
||||
),
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Theme.of(context).primaryTextTheme.title.color),
|
||||
),
|
||||
),
|
||||
Padding(padding: EdgeInsets.only(top: 24),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 24),
|
||||
child: Observer(
|
||||
builder: (_) => SelectButton(
|
||||
image: null,
|
||||
text: seedLocales[seedLanguages.indexOf(seedLanguageStore.selectedSeedLanguage)],
|
||||
color: Theme.of(context).accentTextTheme.title.backgroundColor,
|
||||
textColor: Theme.of(context).primaryTextTheme.title.color,
|
||||
onTap: () async => await showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) => SeedLanguagePicker()
|
||||
)
|
||||
)
|
||||
),
|
||||
builder: (_) => SelectButton(
|
||||
image: null,
|
||||
text: seedLocales[seedLanguages
|
||||
.indexOf(seedLanguageStore.selectedSeedLanguage)],
|
||||
color: Theme.of(context)
|
||||
.accentTextTheme
|
||||
.title
|
||||
.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(
|
||||
builder: (context) {
|
||||
return LoadingPrimaryButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState.validate()) {
|
||||
walletCreationStore.create(name: nameController.text,
|
||||
language: seedLanguageStore.selectedSeedLanguage);
|
||||
}
|
||||
},
|
||||
onPressed: () => _confirmForm(walletCreationService,
|
||||
seedLanguageStore.selectedSeedLanguage),
|
||||
text: S.of(context).continue_text,
|
||||
color: Colors.green,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue