review fixes, additional cleanup

This commit is contained in:
fossephate 2024-09-24 12:57:12 -07:00
parent 6f462aadc3
commit 840287c72d
7 changed files with 56 additions and 77 deletions

View file

@ -48,15 +48,14 @@ class ElectrumBalance extends Balance {
}
@override
String get formattedSecondAvailableBalance => bitcoinAmountToString(amount: secondConfirmed ?? 0);
String get formattedSecondAvailableBalance => bitcoinAmountToString(amount: secondConfirmed);
@override
String get formattedSecondAdditionalBalance =>
bitcoinAmountToString(amount: secondUnconfirmed ?? 0);
String get formattedSecondAdditionalBalance => bitcoinAmountToString(amount: secondUnconfirmed);
@override
String get formattedFullAvailableBalance =>
bitcoinAmountToString(amount: confirmed + (secondConfirmed ?? 0) - frozen);
bitcoinAmountToString(amount: confirmed + secondConfirmed - frozen);
String toJSON() => json.encode({
'confirmed': confirmed,

View file

@ -1357,13 +1357,7 @@ abstract class ElectrumWalletBase
List<Map<String, dynamic>> unspents = [];
List<BitcoinUnspent> updatedUnspentCoins = [];
try {
unspents = await electrumClient.getListUnspent(address.getScriptHash(network));
} catch (e, s) {
print(e);
print(s);
return [];
}
await Future.wait(unspents.map((unspent) async {
try {

View file

@ -97,7 +97,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
late final Bip32Slip10Secp256k1 mwebHd;
late final Box<MwebUtxo> mwebUtxosBox;
Timer? _syncTimer;
Timer? _stuckSyncTimer;
Timer? _feeRatesTimer;
StreamSubscription<Utxo>? _utxoStream;
late RpcClient _stub;
@ -233,6 +232,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
Future<void> waitForMwebAddresses() async {
// ensure that we have the full 1000 mweb addresses generated before continuing:
// should no longer be needed, but leaving here just in case
final mwebAddrs = (walletAddresses as LitecoinWalletAddresses).mwebAddrs;
while (mwebAddrs.length < 1000) {
print("waiting for mweb addresses to finish generating...");
@ -243,7 +243,12 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
@action
@override
Future<void> startSync() async {
print("STARTING SYNC @@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
if (syncStatus is SyncronizingSyncStatus) {
return;
}
print("STARTING SYNC - MWEB ENABLED: $mwebEnabled");
try {
syncStatus = SyncronizingSyncStatus();
await subscribeForUpdates();
@ -267,7 +272,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
}
await waitForMwebAddresses();
try {
await getStub();
await processMwebUtxos();
await updateTransactions();
@ -318,26 +322,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
return;
}
});
// setup a watch dog to restart the sync process if it gets stuck:
List<double> lastFewProgresses = [];
_stuckSyncTimer?.cancel();
_stuckSyncTimer = Timer.periodic(const Duration(seconds: 10), (timer) async {
if (syncStatus is! SyncingSyncStatus) return;
if (syncStatus.progress() > 0.98) return; // don't check if we're close to synced
lastFewProgresses.add(syncStatus.progress());
if (lastFewProgresses.length < 10) return;
// limit list size to 10:
while (lastFewProgresses.length > 10) {
lastFewProgresses.removeAt(0);
}
// if the progress is the same over the last 100 seconds, restart the sync:
if (lastFewProgresses.every((p) => p == lastFewProgresses.first)) {
print("mweb syncing is stuck, restarting...");
syncStatus = LostConnectionSyncStatus();
await stopSync();
}
});
}
@action
@ -345,7 +329,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
Future<void> stopSync() async {
_syncTimer?.cancel();
_utxoStream?.cancel();
_stuckSyncTimer?.cancel();
_feeRatesTimer?.cancel();
await CwMweb.stop();
}
@ -913,7 +896,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
final addresses = <String>{};
transaction.inputAddresses?.forEach((id) async {
final utxo = mwebUtxosBox.get(id);
// await mwebUtxosBox.delete(id);
// await mwebUtxosBox.delete(id);// gets deleted in checkMwebUtxosSpent
if (utxo == null) return;
final addressRecord = walletAddresses.allAddresses
.firstWhere((addressRecord) => addressRecord.address == utxo.address);
@ -946,7 +929,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
@override
Future<void> close() async {
_utxoStream?.cancel();
_stuckSyncTimer?.cancel();
_feeRatesTimer?.cancel();
_syncTimer?.cancel();
await stopSync();

View file

@ -38,7 +38,7 @@ class AddressList extends StatelessWidget {
separatorBuilder: (context, _) => const HorizontalSectionDivider(),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: min(addressListViewModel.items.length, 100),// TODO: don't show all 1000 mweb addresses
itemCount: addressListViewModel.items.length,
itemBuilder: (context, index) {
final item = addressListViewModel.items[index];
Widget cell = Container();

View file

@ -235,17 +235,6 @@ abstract class BalanceViewModelBase with Store {
return walletBalance.formattedAdditionalBalance;
}
@computed
String get secondAdditionalBalance {
final walletBalance = _walletBalance;
if (displayMode == BalanceDisplayMode.hiddenBalance) {
return '---';
}
return walletBalance.formattedSecondAdditionalBalance;
}
@computed
String get availableFiatBalance {
final walletBalance = _walletBalance;

View file

@ -217,7 +217,16 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
PendingTransaction? pendingTransaction;
@computed
String get balance => wallet.balance[selectedCryptoCurrency]!.formattedFullAvailableBalance;
String get balance {
String fullFormattedBalance =
wallet.balance[selectedCryptoCurrency]!.formattedFullAvailableBalance;
String formattedAvailableBalance =
wallet.balance[selectedCryptoCurrency]!.formattedAvailableBalance;
if (fullFormattedBalance.isNotEmpty) {
return fullFormattedBalance;
}
return formattedAvailableBalance;
}
@computed
bool get isFiatDisabled => balanceViewModel.isFiatDisabled;

View file

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/core/wallet_change_listener_view_model.dart';
import 'package:cake_wallet/entities/auto_generate_subaddress_status.dart';
@ -217,8 +219,9 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
}) : _baseItems = <ListItem>[],
selectedCurrency = walletTypeToCryptoCurrency(appStore.wallet!.type),
_cryptoNumberFormat = NumberFormat(_cryptoNumberPattern),
hasAccounts =
appStore.wallet!.type == WalletType.monero || appStore.wallet!.type == WalletType.wownero || appStore.wallet!.type == WalletType.haven,
hasAccounts = appStore.wallet!.type == WalletType.monero ||
appStore.wallet!.type == WalletType.wownero ||
appStore.wallet!.type == WalletType.haven,
amount = '',
_settingsStore = appStore.settingsStore,
super(appStore: appStore) {
@ -230,7 +233,9 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
_init();
selectedCurrency = walletTypeToCryptoCurrency(wallet.type);
hasAccounts = wallet.type == WalletType.monero || wallet.type == WalletType.wownero || wallet.type == WalletType.haven;
hasAccounts = wallet.type == WalletType.monero ||
wallet.type == WalletType.wownero ||
wallet.type == WalletType.haven;
}
static const String _cryptoNumberPattern = '0.00000000';
@ -519,8 +524,7 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
@action
Future<void> setAddressType(dynamic option) async {
if (wallet.type == WalletType.bitcoin ||
wallet.type == WalletType.litecoin) {
if (wallet.type == WalletType.bitcoin || wallet.type == WalletType.litecoin) {
await bitcoin!.setAddressType(wallet, option);
}
}
@ -528,7 +532,9 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
void _init() {
_baseItems = [];
if (wallet.type == WalletType.monero || wallet.type == WalletType.wownero || wallet.type == WalletType.haven) {
if (wallet.type == WalletType.monero ||
wallet.type == WalletType.wownero ||
wallet.type == WalletType.haven) {
_baseItems.add(WalletAccountListHeader());
}