Reset app option
This commit is contained in:
parent
8ac1693c18
commit
01568fd506
|
@ -142,7 +142,8 @@ abstract class _ActiveAccount with Store {
|
|||
final prefs = await SharedPreferences.getInstance();
|
||||
final coin = prefs.getInt('coin') ?? 0;
|
||||
var id = prefs.getInt('account') ?? 0;
|
||||
setActiveAccount(coin, id);
|
||||
if (WarpApi.checkAccount(coin, id))
|
||||
setActiveAccount(coin, id);
|
||||
checkAndUpdate();
|
||||
}
|
||||
|
||||
|
|
|
@ -388,14 +388,17 @@ class ZWalletAppState extends State<ZWalletApp> {
|
|||
WarpApi.mempoolRun(unconfirmedBalancePort.sendPort.nativePort);
|
||||
|
||||
final c = coins.first;
|
||||
if (!isMobile() && File(c.dbFullPath).existsSync()) {
|
||||
if (!WarpApi.decryptDb(c.dbFullPath, '')) {
|
||||
final passwd = await getDbPasswd(context, c.dbFullPath);
|
||||
if (passwd != null) {
|
||||
settings.dbPasswd = passwd;
|
||||
}
|
||||
do {
|
||||
if (isMobile()) break; // db encryption is only for desktop
|
||||
if (!File(c.dbFullPath).existsSync()) break; // fresh install
|
||||
if (WarpApi.decryptDb(c.dbFullPath, '')) break; // not encrypted
|
||||
|
||||
final reset = await getDbPasswd(context, c.dbFullPath);
|
||||
if (reset) { // user didn't input the passwd and wants to reset
|
||||
await clearApp(context);
|
||||
}
|
||||
}
|
||||
else break;
|
||||
} while(true);
|
||||
|
||||
for (var c in coins) {
|
||||
_setProgress(0.2 * (c.coin+1), 'Initializing ${c.ticker}');
|
||||
|
@ -977,8 +980,9 @@ void resetApp() {
|
|||
WarpApi.truncateData();
|
||||
}
|
||||
|
||||
Future<String?> getDbPasswd(BuildContext context, String dbPath) async {
|
||||
Future<bool> getDbPasswd(BuildContext context, String dbPath) async {
|
||||
final s = S.of(context);
|
||||
final navigator = navigatorKey.currentState!;
|
||||
final passwdController = TextEditingController();
|
||||
final checkPasswd = (String? v) {
|
||||
final valid = WarpApi.decryptDb(dbPath, passwdController.text);
|
||||
|
@ -987,7 +991,7 @@ Future<String?> getDbPasswd(BuildContext context, String dbPath) async {
|
|||
};
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
final confirmed = await showDialog<bool>(
|
||||
final reset = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierColor: Colors.black,
|
||||
barrierDismissible: false,
|
||||
|
@ -1000,14 +1004,28 @@ Future<String?> getDbPasswd(BuildContext context, String dbPath) async {
|
|||
decoration: InputDecoration(labelText: s.databasePassword),
|
||||
controller: passwdController,
|
||||
validator: checkPasswd,
|
||||
onSaved: (v) { settings.dbPasswd = v!; },
|
||||
obscureText: true,
|
||||
),
|
||||
])))),
|
||||
actions: confirmButtons(context, () {
|
||||
if (formKey.currentState!.validate())
|
||||
Navigator.of(context).pop(true);
|
||||
}, okLabel: s.ok),
|
||||
);
|
||||
actions:
|
||||
<ElevatedButton>[
|
||||
ElevatedButton.icon(
|
||||
icon: Icon(Icons.lock_reset),
|
||||
label: Text(s.reset),
|
||||
onPressed: () => navigator.pop(true)),
|
||||
ElevatedButton.icon(
|
||||
icon: Icon(Icons.done),
|
||||
label: Text(s.ok),
|
||||
onPressed: () {
|
||||
final fs = formKey.currentState!;
|
||||
if (fs.validate()) {
|
||||
fs.save();
|
||||
navigator.pop(false);
|
||||
}
|
||||
})
|
||||
]);
|
||||
}) ?? false;
|
||||
return confirmed ? passwdController.text : null;
|
||||
|
||||
return reset;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:flutter_mobx/flutter_mobx.dart';
|
|||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:warp_api/types.dart';
|
||||
import 'package:warp_api/warp_api.dart';
|
||||
import 'coin/coins.dart';
|
||||
import 'generated/l10n.dart';
|
||||
import 'main.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
@ -230,3 +231,16 @@ Future<void> showRestartMessage() async {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> clearApp(BuildContext context) async {
|
||||
final reset = await showDialog<bool>(context: context, barrierDismissible: false, builder:
|
||||
(context) => AlertDialog(
|
||||
title: Text('Reset Database'),
|
||||
content: Text('Are you sure you want to DELETE ALL your data?'),
|
||||
actions: confirmButtons(context, () => Navigator.of(context).pop(true)),
|
||||
)) ?? false;
|
||||
if (reset) {
|
||||
final c = coins.first;
|
||||
File(c.dbDir).deleteSync(recursive: true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 2940d8f8dac0c365f97e06adaab1c88174cff805
|
||||
Subproject commit 56b8113084bda7ea367a76e0e10efab1e467efe3
|
|
@ -190,6 +190,10 @@ class WarpApi {
|
|||
return unwrapResultString(address);
|
||||
}
|
||||
|
||||
static bool checkAccount(int coin, int account) {
|
||||
return account != 0 && warp_api_lib.check_account(coin, account) != 0;
|
||||
}
|
||||
|
||||
static void setActiveAccount(int coin, int account) {
|
||||
warp_api_lib.set_active(coin);
|
||||
warp_api_lib.set_active_account(coin, account);
|
||||
|
|
|
@ -761,6 +761,21 @@ class NativeLibrary {
|
|||
late final _dart_truncate_sync_data _truncate_sync_data =
|
||||
_truncate_sync_data_ptr.asFunction<_dart_truncate_sync_data>();
|
||||
|
||||
int check_account(
|
||||
int coin,
|
||||
int account,
|
||||
) {
|
||||
return _check_account(
|
||||
coin,
|
||||
account,
|
||||
);
|
||||
}
|
||||
|
||||
late final _check_account_ptr =
|
||||
_lookup<ffi.NativeFunction<_c_check_account>>('check_account');
|
||||
late final _dart_check_account _check_account =
|
||||
_check_account_ptr.asFunction<_dart_check_account>();
|
||||
|
||||
void delete_account(
|
||||
int coin,
|
||||
int account,
|
||||
|
@ -2008,6 +2023,16 @@ typedef _c_truncate_sync_data = ffi.Void Function();
|
|||
|
||||
typedef _dart_truncate_sync_data = void Function();
|
||||
|
||||
typedef _c_check_account = ffi.Int8 Function(
|
||||
ffi.Uint8 coin,
|
||||
ffi.Uint32 account,
|
||||
);
|
||||
|
||||
typedef _dart_check_account = int Function(
|
||||
int coin,
|
||||
int account,
|
||||
);
|
||||
|
||||
typedef _c_delete_account = ffi.Void Function(
|
||||
ffi.Uint8 coin,
|
||||
ffi.Uint32 account,
|
||||
|
|
|
@ -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.3.5+397
|
||||
version: 1.3.5+398
|
||||
|
||||
environment:
|
||||
sdk: ">=2.12.0 <3.0.0"
|
||||
|
|
Loading…
Reference in New Issue