Skip to content

Commit

Permalink
Create an account on first startup
Browse files Browse the repository at this point in the history
  • Loading branch information
hhanh00 committed Apr 8, 2022
1 parent 38d2596 commit 8120c72
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 16 deletions.
1 change: 0 additions & 1 deletion lib/account_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class AccountManagerState extends State<AccountManagerPage> {
await accounts.refresh();
await accounts.updateTBalance();
});
showAboutOnce(this.context);
}

@override
Expand Down
9 changes: 9 additions & 0 deletions lib/accounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> hasAccount(int coin) async {
final c = settings.coins[coin].def;
final db = c.db;
final List<Map> res = await db.rawQuery(
"SELECT 1 FROM accounts",
[]);
return res.isNotEmpty;
}

static Future<List<Account>> _getList(int coin) async {
final c = settings.coins[coin].def;
final db = c.db;
Expand Down
10 changes: 8 additions & 2 deletions lib/backup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class BackupState extends State<BackupPage> {

@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,
));
Expand Down Expand Up @@ -112,6 +112,12 @@ class BackupState extends State<BackupPage> {
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)),
]),
));
}
Expand Down
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_es.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
10 changes: 10 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class HomeInnerState extends State<HomeInnerPage> with SingleTickerProviderState
});
});
_tabController = tabController;
showAboutOnce(this.context);
}

@override
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
14 changes: 13 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,18 @@ class ZWalletAppState extends State<ZWalletApp> {
_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();
Expand All @@ -307,7 +319,7 @@ class ZWalletAppState extends State<ZWalletApp> {
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);
}
Expand Down
9 changes: 1 addition & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8120c72

Please sign in to comment.