From 8120c726f3fdbc53d724253b40203a1591aa2edb Mon Sep 17 00:00:00 2001 From: Hanh Date: Thu, 7 Apr 2022 20:59:43 +0800 Subject: [PATCH] Create an account on first startup --- lib/account_manager.dart | 1 - lib/accounts.dart | 9 +++++++++ lib/backup.dart | 10 ++++++++-- lib/generated/intl/messages_en.dart | 2 ++ lib/generated/intl/messages_es.dart | 2 ++ lib/generated/intl/messages_fr.dart | 2 ++ lib/generated/l10n.dart | 10 ++++++++++ lib/home.dart | 1 + lib/l10n/intl_en.arb | 3 ++- lib/l10n/intl_es.arb | 3 ++- lib/l10n/intl_fr.arb | 3 ++- lib/main.dart | 14 +++++++++++++- pubspec.lock | 9 +-------- pubspec.yaml | 2 +- 14 files changed, 55 insertions(+), 16 deletions(-) diff --git a/lib/account_manager.dart b/lib/account_manager.dart index a1b2d65e5..ae4790923 100644 --- a/lib/account_manager.dart +++ b/lib/account_manager.dart @@ -26,7 +26,6 @@ class AccountManagerState extends State { await accounts.refresh(); await accounts.updateTBalance(); }); - showAboutOnce(this.context); } @override diff --git a/lib/accounts.dart b/lib/accounts.dart index 720bcbb22..95650da91 100644 --- a/lib/accounts.dart +++ b/lib/accounts.dart @@ -77,6 +77,15 @@ abstract class _AccountManager2 with Store { Account get(int coin, int id) => list.firstWhere((e) => e.coin == coin && e.id == id, orElse: () => emptyAccount); + Future hasAccount(int coin) async { + final c = settings.coins[coin].def; + final db = c.db; + final List res = await db.rawQuery( + "SELECT 1 FROM accounts", + []); + return res.isNotEmpty; + } + static Future> _getList(int coin) async { final c = settings.coins[coin].def; final db = c.db; diff --git a/lib/backup.dart b/lib/backup.dart index 13f418869..e07bbe3b8 100644 --- a/lib/backup.dart +++ b/lib/backup.dart @@ -42,8 +42,8 @@ class BackupState extends State { @override Widget build(BuildContext context) { - return Scaffold(appBar: AppBar(title: Text(S.of(context).backup)), body: - FutureBuilder( + return Scaffold(appBar: AppBar(title: Text(S.of(context).backup)), + body: FutureBuilder( future: _init(), builder: _build, )); @@ -112,6 +112,12 @@ class BackupState extends State { child: Text(s.backupWarning, style: theme.textTheme.subtitle1! .copyWith(color: theme.primaryColor)))), + ElevatedButton.icon( + icon: Icon(Icons.check), + label: Text(S.of(context).iHaveMadeABackup), + onPressed: () { Navigator.of(context).pop(); }, + ), + Padding(padding: EdgeInsets.symmetric(vertical: 4)), ]), )); } diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index d46059c60..0608bca3a 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -178,6 +178,8 @@ class MessageLookup extends MessageLookupByLibrary { "height": MessageLookupByLibrary.simpleMessage("Height"), "help": MessageLookupByLibrary.simpleMessage("Help"), "history": MessageLookupByLibrary.simpleMessage("History"), + "iHaveMadeABackup": + MessageLookupByLibrary.simpleMessage("I have made a backup"), "includeFeeInAmount": MessageLookupByLibrary.simpleMessage("Include Fee in Amount"), "invalidAddress": diff --git a/lib/generated/intl/messages_es.dart b/lib/generated/intl/messages_es.dart index f8dddb229..32f0d7f92 100644 --- a/lib/generated/intl/messages_es.dart +++ b/lib/generated/intl/messages_es.dart @@ -179,6 +179,8 @@ class MessageLookup extends MessageLookupByLibrary { "height": MessageLookupByLibrary.simpleMessage("Altura"), "help": MessageLookupByLibrary.simpleMessage("Ayuda"), "history": MessageLookupByLibrary.simpleMessage("Historia"), + "iHaveMadeABackup": MessageLookupByLibrary.simpleMessage( + "He hecho una copia de seguridad"), "includeFeeInAmount": MessageLookupByLibrary.simpleMessage( "Incluir tarifa en la cantidad"), "invalidAddress": diff --git a/lib/generated/intl/messages_fr.dart b/lib/generated/intl/messages_fr.dart index 569e72705..a4145f920 100644 --- a/lib/generated/intl/messages_fr.dart +++ b/lib/generated/intl/messages_fr.dart @@ -182,6 +182,8 @@ class MessageLookup extends MessageLookupByLibrary { "height": MessageLookupByLibrary.simpleMessage("Hauteur"), "help": MessageLookupByLibrary.simpleMessage("Aide"), "history": MessageLookupByLibrary.simpleMessage("Historique"), + "iHaveMadeABackup": + MessageLookupByLibrary.simpleMessage("J\'ai fait une sauvegarde"), "includeFeeInAmount": MessageLookupByLibrary.simpleMessage( "Inclure les frais dans le montant"), "invalidAddress": diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 1662fcdad..529ea8498 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -2091,6 +2091,16 @@ class S { args: [], ); } + + /// `I have made a backup` + String get iHaveMadeABackup { + return Intl.message( + 'I have made a backup', + name: 'iHaveMadeABackup', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/home.dart b/lib/home.dart index d61515cc2..12316824d 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -94,6 +94,7 @@ class HomeInnerState extends State with SingleTickerProviderState }); }); _tabController = tabController; + showAboutOnce(this.context); } @override diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index a1dc98e2f..67a2b1306 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -202,5 +202,6 @@ "pleaseRestartNow": "Please Restart now", "disconnected": "Disconnected", "ledger": "Ledger", - "mobileCharges": "On Mobile Data, scanning may incur additional charges. Do you want to proceed?" + "mobileCharges": "On Mobile Data, scanning may incur additional charges. Do you want to proceed?", + "iHaveMadeABackup": "I have made a backup" } diff --git a/lib/l10n/intl_es.arb b/lib/l10n/intl_es.arb index 9c75a76c0..d81305863 100644 --- a/lib/l10n/intl_es.arb +++ b/lib/l10n/intl_es.arb @@ -200,5 +200,6 @@ "pleaseRestartNow": "Please Restart now", "disconnected": "Disconnected", "ledger": "Ledger", - "mobileCharges": "On Mobile Data, scanning may incur additional charges. Do you want to proceed?" + "mobileCharges": "On Mobile Data, scanning may incur additional charges. Do you want to proceed?", + "iHaveMadeABackup": "He hecho una copia de seguridad" } diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index fd2af3321..baa552d86 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -200,5 +200,6 @@ "pleaseRestartNow": "Please Restart now", "disconnected": "Déconnecté", "ledger": "Ledger", - "mobileCharges": "Sans Wi-fi, les frais peuvent être élevés. Voulez vous continuer?" + "mobileCharges": "Sans Wi-fi, les frais peuvent être élevés. Voulez vous continuer?", + "iHaveMadeABackup": "J'ai fait une sauvegarde" } diff --git a/lib/main.dart b/lib/main.dart index 549db150e..cc1228e76 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -290,6 +290,18 @@ class ZWalletAppState extends State { _setProgress(0.4, 'Initializing Wallet'); WarpApi.initWallet(dbPath); + final about = prefs.getBool('about'); + var synced = false; + if (about == null && !await accounts.hasAccount(1)) { + _setProgress(0.5, 'Creating First Account'); + final accountId = WarpApi.newAccount(1, 'Main', '', 0); + await active.setActiveAccount(1, accountId); + Future.microtask(() { + Navigator.of(context).pushNamed('/backup', arguments: AccountId(1, accountId)); + }); + synced = true; // synced because no previous account + } + if (recover) { final f = await getRecoveryFile(); final backup = await f.readAsString(); @@ -307,7 +319,7 @@ class ZWalletAppState extends State { await active.restore(); _setProgress(0.8, 'Checking Sync Status'); await syncStatus.update(); - if (accounts.list.isEmpty) { + if (synced) { for (var c in settings.coins) { syncStatus.markAsSynced(c.coin); } diff --git a/pubspec.lock b/pubspec.lock index af66f629c..ab50f366b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -606,13 +606,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.11" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.3" material_design_icons_flutter: dependency: "direct main" description: @@ -1205,7 +1198,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" + version: "0.4.3" timing: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 1416902ba..7b313e9b7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.2.1+215 +version: 1.2.2+216 environment: sdk: ">=2.12.0 <3.0.0"