Remove network initialization from startup page
This commit is contained in:
parent
573e483588
commit
8b8123df79
|
@ -163,14 +163,13 @@ class AccountManagerState extends State<AccountManagerPage> {
|
|||
|
||||
void _onDismissed(int index, Account account) async {
|
||||
await accounts.delete(account.coin, account.id);
|
||||
accounts.refresh();
|
||||
final id = await active.refreshId(active.coin);
|
||||
if (id == 0)
|
||||
active.reset();
|
||||
await accounts.refresh();
|
||||
await active.checkAndUpdate();
|
||||
}
|
||||
|
||||
_selectAccount(Account account) async {
|
||||
await active.setActiveAccount(account.coin, account.id);
|
||||
await active.refreshAccount();
|
||||
if (syncStatus.accountRestored) {
|
||||
syncStatus.setAccountRestored(false);
|
||||
final height = await rescanDialog(context);
|
||||
|
|
|
@ -55,8 +55,7 @@ abstract class _AccountManager2 with Store {
|
|||
@action
|
||||
Future<void> delete(int coin, int id) async {
|
||||
WarpApi.deleteAccount(coin, id);
|
||||
if (active.coin == coin && active.id == id)
|
||||
active.reset();
|
||||
await active.checkAndUpdate();
|
||||
}
|
||||
|
||||
@action
|
||||
|
@ -157,40 +156,62 @@ abstract class _ActiveAccount with Store {
|
|||
@observable
|
||||
bool pnlDesc = false;
|
||||
|
||||
AccountId toId() { return AccountId(coin, id); }
|
||||
|
||||
@action
|
||||
Future<void> restore() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final coin = prefs.getInt('coin') ?? 0;
|
||||
final id = prefs.getInt('account') ?? 0;
|
||||
await setActiveAccount(coin, id);
|
||||
var id = prefs.getInt('account') ?? 0;
|
||||
active.coin = coin;
|
||||
active.id = id;
|
||||
await checkAndUpdate();
|
||||
await refreshAccount();
|
||||
}
|
||||
|
||||
Future<void> reset() async {
|
||||
for (var coin_data in settings.coins) {
|
||||
if (await refreshId(coin_data.coin) != 0)
|
||||
return;
|
||||
Future<void> checkAndUpdate() async {
|
||||
final aid = await getAvailableId(active.toId());
|
||||
if (aid == null) {
|
||||
await setActiveAccount(0, 0);
|
||||
}
|
||||
else if (aid != active.toId()) {
|
||||
await setActiveAccount(aid.coin, aid.id);
|
||||
await refreshAccount();
|
||||
}
|
||||
await setActiveAccount(0, 0);
|
||||
}
|
||||
|
||||
// check that the active account still exists
|
||||
Future<AccountId?> getAvailableId(AccountId aid) async {
|
||||
final nid = await getAvailableIdForCoin(aid.coin, aid.id);
|
||||
if (nid != null) return nid;
|
||||
for (var coin_data in settings.coins) {
|
||||
// look for an account in any other coin
|
||||
if (coin_data.coin != coin) {
|
||||
final nid = await getAvailableIdForCoin(coin_data.coin, coin_data.active);
|
||||
if (nid != null)
|
||||
return nid;
|
||||
}
|
||||
}
|
||||
// We have no accounts
|
||||
return null;
|
||||
}
|
||||
|
||||
// check that the account still exists
|
||||
// if not, pick any account
|
||||
// if there are none, return null
|
||||
Future<int> refreshId(int coin) async {
|
||||
// if there are none, return 0
|
||||
Future<AccountId?> getAvailableIdForCoin(int coin, int id) async {
|
||||
coinDef = settings.coins[coin].def;
|
||||
final db = coinDef.db;
|
||||
final List<Map> res1 = await db.rawQuery(
|
||||
"SELECT 1 FROM accounts WHERE id_account = ?1", [active.id]);
|
||||
"SELECT 1 FROM accounts WHERE id_account = ?1", [id]);
|
||||
if (res1.isNotEmpty)
|
||||
return active.id;
|
||||
return AccountId(coin, id);
|
||||
final List<Map> res2 = await db.rawQuery(
|
||||
"SELECT id_account FROM accounts", []);
|
||||
if (res2.isNotEmpty) {
|
||||
final id = res2[0]['id_account'];
|
||||
await setActiveAccount(coin, id);
|
||||
return id;
|
||||
return AccountId(coin, id);
|
||||
}
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
|
||||
@action
|
||||
|
@ -204,7 +225,11 @@ abstract class _ActiveAccount with Store {
|
|||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.setInt('coin', coin);
|
||||
prefs.setInt('account', id);
|
||||
WarpApi.setActiveAccount(coin, id);
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> refreshAccount() async {
|
||||
coinDef = settings.coins[coin].def;
|
||||
final db = coinDef.db;
|
||||
|
||||
|
@ -222,10 +247,9 @@ abstract class _ActiveAccount with Store {
|
|||
|
||||
showTAddr = false;
|
||||
balances = Balances.zero;
|
||||
WarpApi.setActiveAccount(coin, id);
|
||||
|
||||
await update();
|
||||
await priceStore.updateChart();
|
||||
Future.microtask(priceStore.updateChart);
|
||||
}
|
||||
|
||||
@action
|
||||
|
|
|
@ -10,6 +10,10 @@ class AccountId {
|
|||
final int coin;
|
||||
final int id;
|
||||
AccountId(this.coin, this.id);
|
||||
|
||||
bool operator ==(covariant AccountId other) {
|
||||
return coin == other.coin && id == other.id;
|
||||
}
|
||||
}
|
||||
|
||||
class BackupPage extends StatefulWidget {
|
||||
|
|
|
@ -38,7 +38,15 @@ class HomeState extends State<HomePage> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (active.id == 0) return;
|
||||
if (active.id == 0) {
|
||||
Future.microtask(() async {
|
||||
await syncStatus.update();
|
||||
for (var c in settings.coins) {
|
||||
syncStatus.markAsSynced(c.coin);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
Future.microtask(() async {
|
||||
await syncStatus.update();
|
||||
|
|
|
@ -344,8 +344,6 @@ class ZWalletAppState extends State<ZWalletApp> {
|
|||
await accounts.refresh();
|
||||
_setProgress(0.7, 'Restoring Active Account');
|
||||
await active.restore();
|
||||
_setProgress(0.8, 'Checking Sync Status');
|
||||
await syncStatus.update();
|
||||
|
||||
if (isMobile()) {
|
||||
_setProgress(0.9, 'Setting Dashboard Shortcuts');
|
||||
|
@ -378,12 +376,6 @@ class ZWalletAppState extends State<ZWalletApp> {
|
|||
}
|
||||
|
||||
await active.restore();
|
||||
if (active.id == 0) {
|
||||
for (var c in settings.coins) {
|
||||
syncStatus.markAsSynced(c.coin);
|
||||
}
|
||||
await syncStatus.update();
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
|
|
|
@ -188,6 +188,7 @@ class _AddAccountPageState extends State<AddAccountPage> {
|
|||
} else {
|
||||
await accounts.refresh();
|
||||
await active.setActiveAccount(_coin, account);
|
||||
await active.refreshAccount();
|
||||
final nav = Navigator.of(context);
|
||||
if (_keyController.text != "") {
|
||||
syncStatus.setAccountRestored(true);
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit de506ba0743b0cb489b5bcc3d5cfaf171f077c06
|
||||
Subproject commit c51cb5181806cd5600c1fe59219b5205b31c9538
|
|
@ -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.12+270
|
||||
version: 1.2.12+272
|
||||
|
||||
environment:
|
||||
sdk: ">=2.12.0 <3.0.0"
|
||||
|
|
Loading…
Reference in New Issue