do not partially open monero wallets at the same time on startup

This commit is contained in:
julian 2023-01-02 09:13:00 -06:00
parent bdab241d7e
commit 57add19e88
4 changed files with 86 additions and 36 deletions

View file

@ -60,6 +60,14 @@ class CoinWalletsTable extends ConsumerWidget {
ref.read(currentWalletIdProvider.state).state =
walletIds[i];
final manager = ref
.read(walletsChangeNotifierProvider)
.getManager(walletIds[i]);
if (manager.coin == Coin.monero ||
manager.coin == Coin.wownero) {
await manager.initializeExisting();
}
await Navigator.of(context).pushNamed(
DesktopWalletView.routeName,
arguments: walletIds[i],

View file

@ -792,27 +792,48 @@ class MoneroWallet extends CoinServiceAPI {
}
};
Future<void> _updateCachedBalance(int sats) async {
await DB.instance.put<dynamic>(
boxName: walletId,
key: "cachedMoneroBalanceSats",
value: sats,
);
}
int _getCachedBalance() =>
DB.instance.get<dynamic>(
boxName: walletId,
key: "cachedMoneroBalanceSats",
) as int? ??
0;
@override
Future<Decimal> get totalBalance async {
final balanceEntries = walletBase?.balance?.entries;
if (balanceEntries != null) {
int bal = 0;
for (var element in balanceEntries) {
bal = bal + element.value.fullBalance;
}
return Format.satoshisToAmount(bal, coin: coin);
} else {
final transactions = walletBase!.transactionHistory!.transactions;
int transactionBalance = 0;
for (var tx in transactions!.entries) {
if (tx.value.direction == TransactionDirection.incoming) {
transactionBalance += tx.value.amount!;
} else {
transactionBalance += -tx.value.amount! - tx.value.fee!;
try {
final balanceEntries = walletBase?.balance?.entries;
if (balanceEntries != null) {
int bal = 0;
for (var element in balanceEntries) {
bal = bal + element.value.fullBalance;
}
await _updateCachedBalance(bal);
return Format.satoshisToAmount(bal, coin: coin);
} else {
final transactions = walletBase!.transactionHistory!.transactions;
int transactionBalance = 0;
for (var tx in transactions!.entries) {
if (tx.value.direction == TransactionDirection.incoming) {
transactionBalance += tx.value.amount!;
} else {
transactionBalance += -tx.value.amount! - tx.value.fee!;
}
}
}
return Format.satoshisToAmount(transactionBalance, coin: coin);
await _updateCachedBalance(transactionBalance);
return Format.satoshisToAmount(transactionBalance, coin: coin);
}
} catch (_) {
return Format.satoshisToAmount(_getCachedBalance(), coin: coin);
}
}

View file

@ -820,27 +820,48 @@ class WowneroWallet extends CoinServiceAPI {
}
};
Future<void> _updateCachedBalance(int sats) async {
await DB.instance.put<dynamic>(
boxName: walletId,
key: "cachedWowneroBalanceSats",
value: sats,
);
}
int _getCachedBalance() =>
DB.instance.get<dynamic>(
boxName: walletId,
key: "cachedWowneroBalanceSats",
) as int? ??
0;
@override
Future<Decimal> get totalBalance async {
final balanceEntries = walletBase?.balance?.entries;
if (balanceEntries != null) {
int bal = 0;
for (var element in balanceEntries) {
bal = bal + element.value.fullBalance;
}
return Format.satoshisToAmount(bal, coin: coin);
} else {
final transactions = walletBase!.transactionHistory!.transactions;
int transactionBalance = 0;
for (var tx in transactions!.entries) {
if (tx.value.direction == TransactionDirection.incoming) {
transactionBalance += tx.value.amount!;
} else {
transactionBalance += -tx.value.amount! - tx.value.fee!;
try {
final balanceEntries = walletBase?.balance?.entries;
if (balanceEntries != null) {
int bal = 0;
for (var element in balanceEntries) {
bal = bal + element.value.fullBalance;
}
await _updateCachedBalance(bal);
return Format.satoshisToAmount(bal, coin: coin);
} else {
final transactions = walletBase!.transactionHistory!.transactions;
int transactionBalance = 0;
for (var tx in transactions!.entries) {
if (tx.value.direction == TransactionDirection.incoming) {
transactionBalance += tx.value.amount!;
} else {
transactionBalance += -tx.value.amount! - tx.value.fee!;
}
}
}
return Format.satoshisToAmount(transactionBalance, coin: coin);
await _updateCachedBalance(transactionBalance);
return Format.satoshisToAmount(transactionBalance, coin: coin);
}
} catch (_) {
return Format.satoshisToAmount(_getCachedBalance(), coin: coin);
}
}

View file

@ -238,7 +238,7 @@ class Wallets extends ChangeNotifier {
walletIdsToEnableAutoSync.contains(manager.walletId);
if (manager.coin == Coin.monero || manager.coin == Coin.wownero) {
walletsToInitLinearly.add(Tuple2(manager, shouldSetAutoSync));
// walletsToInitLinearly.add(Tuple2(manager, shouldSetAutoSync));
} else {
walletInitFutures.add(manager.initializeExisting().then((value) {
if (shouldSetAutoSync) {
@ -328,7 +328,7 @@ class Wallets extends ChangeNotifier {
walletIdsToEnableAutoSync.contains(manager.walletId);
if (manager.coin == Coin.monero || manager.coin == Coin.wownero) {
walletsToInitLinearly.add(Tuple2(manager, shouldSetAutoSync));
// walletsToInitLinearly.add(Tuple2(manager, shouldSetAutoSync));
} else {
walletInitFutures.add(manager.initializeExisting().then((value) {
if (shouldSetAutoSync) {