Use WalletInfoKeys (plus standardize Lelantus') and make UI var private

This commit is contained in:
sneurlax 2024-05-30 17:50:09 -05:00
parent cbe9919e67
commit 0f98c0be2c
5 changed files with 15 additions and 11 deletions

View file

@ -64,7 +64,8 @@ class _LelantusSettingsViewState extends ConsumerState<LelantusSettingsView> {
if (wallet?.info.otherDataJsonString != null) {
final otherDataJson = json.decode(wallet!.info.otherDataJsonString!);
enableLelantusScanning =
otherDataJson["enableLelantusScanning"] as bool? ?? false;
otherDataJson[WalletInfoKeys.enableLelantusScanning] as bool? ??
false;
}
_isInitialized = true; // Ensure this logic runs only once

View file

@ -59,7 +59,7 @@ class MoreFeaturesDialog extends ConsumerStatefulWidget {
}
class _MoreFeaturesDialogState extends ConsumerState<MoreFeaturesDialog> {
bool? enableLelantusScanning = false;
bool _enableLelantusScanning = false;
@override
Widget build(BuildContext context) {
@ -72,8 +72,9 @@ class _MoreFeaturesDialogState extends ConsumerState<MoreFeaturesDialog> {
// Parse otherDataJsonString to get the enableLelantusScanning value.
if (wallet.info.otherDataJsonString != null) {
final otherDataJson = json.decode(wallet.info.otherDataJsonString!);
enableLelantusScanning =
otherDataJson["enableLelantusScanning"] as bool? ?? false;
_enableLelantusScanning =
otherDataJson[WalletInfoKeys.enableLelantusScanning] as bool? ??
false;
}
final coinControlPrefEnabled = ref.watch(
@ -169,16 +170,16 @@ class _MoreFeaturesDialogState extends ConsumerState<MoreFeaturesDialog> {
height: 20,
width: 40,
child: DraggableSwitchButton(
isOn: enableLelantusScanning ?? false,
isOn: _enableLelantusScanning,
onValueChanged: (newValue) {
// Toggle enableLelantusScanning in wallet info.
wallet.info.updateOtherData(newEntries: {
WalletInfoKeys.enableLelantusScanning:
!(enableLelantusScanning ?? false)
!(_enableLelantusScanning)
}, isar: ref.read(mainDBProvider).isar).then((value) {
// Should setState be used here?
enableLelantusScanning =
!(enableLelantusScanning ?? false);
_enableLelantusScanning =
!(_enableLelantusScanning);
});
},
),

View file

@ -507,5 +507,5 @@ abstract class WalletInfoKeys {
static const String tezosDerivationPath = "tezosDerivationPathKey";
static const String lelantusCoinIsarRescanRequired =
"lelantusCoinIsarRescanRequired";
static const String enableLelantusScanning = "enableLelantusScanning";
static const String enableLelantusScanning = "enableLelantusScanningKey";
}

View file

@ -615,7 +615,8 @@ class FiroWallet<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
if (info.otherDataJsonString != null) {
final otherDataJson = json.decode(info.otherDataJsonString!);
enableLelantusScanning =
otherDataJson["enableLelantusScanning"] as bool? ?? false;
otherDataJson[WalletInfoKeys.enableLelantusScanning] as bool? ??
false;
}
// lelantus

View file

@ -564,7 +564,8 @@ abstract class Wallet<T extends CryptoCurrency> {
if (this.info.otherDataJsonString != null) {
final otherDataJson = json.decode(this.info.otherDataJsonString!);
enableLelantusScanning =
otherDataJson["enableLelantusScanning"] as bool? ?? false;
otherDataJson[WalletInfoKeys.enableLelantusScanning] as bool? ??
false;
}
if (enableLelantusScanning) {
await (this as LelantusInterface).refreshLelantusData();