mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-11 05:04:35 +00:00
do not partially open monero wallets at the same time on startup
This commit is contained in:
parent
bdab241d7e
commit
57add19e88
4 changed files with 86 additions and 36 deletions
|
@ -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],
|
||||
|
|
|
@ -792,14 +792,31 @@ 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 {
|
||||
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;
|
||||
|
@ -812,8 +829,12 @@ class MoneroWallet extends CoinServiceAPI {
|
|||
}
|
||||
}
|
||||
|
||||
await _updateCachedBalance(transactionBalance);
|
||||
return Format.satoshisToAmount(transactionBalance, coin: coin);
|
||||
}
|
||||
} catch (_) {
|
||||
return Format.satoshisToAmount(_getCachedBalance(), coin: coin);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -820,14 +820,31 @@ 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 {
|
||||
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;
|
||||
|
@ -840,8 +857,12 @@ class WowneroWallet extends CoinServiceAPI {
|
|||
}
|
||||
}
|
||||
|
||||
await _updateCachedBalance(transactionBalance);
|
||||
return Format.satoshisToAmount(transactionBalance, coin: coin);
|
||||
}
|
||||
} catch (_) {
|
||||
return Format.satoshisToAmount(_getCachedBalance(), coin: coin);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue