mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
Make SP scanning, wallet-specific (#2383)
This commit is contained in:
@@ -168,7 +168,6 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
|
||||
required Box<PayjoinSession> payjoinBox,
|
||||
required String password,
|
||||
required EncryptionFileUtils encryptionFileUtils,
|
||||
required bool alwaysScan,
|
||||
}) async {
|
||||
final network = walletInfo.network != null
|
||||
? BasedUtxoNetwork.fromName(walletInfo.network!)
|
||||
@@ -252,7 +251,7 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
|
||||
initialChangeAddressIndex: snp?.changeAddressIndex,
|
||||
addressPageType: snp?.addressPageType,
|
||||
networkParam: network,
|
||||
alwaysScan: alwaysScan,
|
||||
alwaysScan: snp?.alwaysScan,
|
||||
payjoinBox: payjoinBox);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,11 @@ class BitcoinWalletService extends WalletService<
|
||||
BitcoinRestoreWalletFromWIFCredentials,
|
||||
BitcoinRestoreWalletFromHardware> {
|
||||
BitcoinWalletService(this.walletInfoSource, this.unspentCoinsInfoSource,
|
||||
this.payjoinSessionSource, this.alwaysScan, this.isDirect);
|
||||
this.payjoinSessionSource, this.isDirect);
|
||||
|
||||
final Box<WalletInfo> walletInfoSource;
|
||||
final Box<UnspentCoinsInfo> unspentCoinsInfoSource;
|
||||
final Box<PayjoinSession> payjoinSessionSource;
|
||||
final bool alwaysScan;
|
||||
final bool isDirect;
|
||||
|
||||
@override
|
||||
@@ -84,7 +83,6 @@ class BitcoinWalletService extends WalletService<
|
||||
walletInfo: walletInfo,
|
||||
unspentCoinsInfo: unspentCoinsInfoSource,
|
||||
payjoinBox: payjoinSessionSource,
|
||||
alwaysScan: alwaysScan,
|
||||
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||
);
|
||||
await wallet.init();
|
||||
@@ -98,7 +96,6 @@ class BitcoinWalletService extends WalletService<
|
||||
walletInfo: walletInfo,
|
||||
unspentCoinsInfo: unspentCoinsInfoSource,
|
||||
payjoinBox: payjoinSessionSource,
|
||||
alwaysScan: alwaysScan,
|
||||
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||
);
|
||||
await wallet.init();
|
||||
@@ -133,7 +130,6 @@ class BitcoinWalletService extends WalletService<
|
||||
walletInfo: currentWalletInfo,
|
||||
unspentCoinsInfo: unspentCoinsInfoSource,
|
||||
payjoinBox: payjoinSessionSource,
|
||||
alwaysScan: alwaysScan,
|
||||
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||
);
|
||||
|
||||
|
||||
@@ -150,6 +150,7 @@ abstract class ElectrumWalletBase
|
||||
}
|
||||
}
|
||||
|
||||
@observable
|
||||
bool? alwaysScan;
|
||||
|
||||
final Bip32Slip10Secp256k1 accountHD;
|
||||
|
||||
@@ -210,7 +210,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||
required WalletInfo walletInfo,
|
||||
required Box<UnspentCoinsInfo> unspentCoinsInfo,
|
||||
required String password,
|
||||
required bool alwaysScan,
|
||||
required EncryptionFileUtils encryptionFileUtils,
|
||||
}) async {
|
||||
final hasKeysFile = await WalletKeysFile.hasKeysFile(name, walletInfo.type);
|
||||
|
||||
@@ -23,11 +23,10 @@ class LitecoinWalletService extends WalletService<
|
||||
BitcoinRestoreWalletFromWIFCredentials,
|
||||
BitcoinRestoreWalletFromHardware> {
|
||||
LitecoinWalletService(
|
||||
this.walletInfoSource, this.unspentCoinsInfoSource, this.alwaysScan, this.isDirect);
|
||||
this.walletInfoSource, this.unspentCoinsInfoSource, this.isDirect);
|
||||
|
||||
final Box<WalletInfo> walletInfoSource;
|
||||
final Box<UnspentCoinsInfo> unspentCoinsInfoSource;
|
||||
final bool alwaysScan;
|
||||
final bool isDirect;
|
||||
|
||||
@override
|
||||
@@ -78,7 +77,6 @@ class LitecoinWalletService extends WalletService<
|
||||
name: name,
|
||||
walletInfo: walletInfo,
|
||||
unspentCoinsInfo: unspentCoinsInfoSource,
|
||||
alwaysScan: alwaysScan,
|
||||
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||
);
|
||||
await wallet.init();
|
||||
@@ -91,7 +89,6 @@ class LitecoinWalletService extends WalletService<
|
||||
name: name,
|
||||
walletInfo: walletInfo,
|
||||
unspentCoinsInfo: unspentCoinsInfoSource,
|
||||
alwaysScan: alwaysScan,
|
||||
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||
);
|
||||
await wallet.init();
|
||||
@@ -146,7 +143,6 @@ class LitecoinWalletService extends WalletService<
|
||||
name: currentName,
|
||||
walletInfo: currentWalletInfo,
|
||||
unspentCoinsInfo: unspentCoinsInfoSource,
|
||||
alwaysScan: alwaysScan,
|
||||
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||
);
|
||||
|
||||
|
||||
@@ -231,15 +231,14 @@ class CWBitcoin extends Bitcoin {
|
||||
Box<WalletInfo> walletInfoSource,
|
||||
Box<UnspentCoinsInfo> unspentCoinSource,
|
||||
Box<PayjoinSession> payjoinSessionSource,
|
||||
bool alwaysScan,
|
||||
bool isDirect) {
|
||||
return BitcoinWalletService(walletInfoSource, unspentCoinSource,
|
||||
payjoinSessionSource, alwaysScan, isDirect);
|
||||
payjoinSessionSource, isDirect);
|
||||
}
|
||||
|
||||
WalletService createLitecoinWalletService(Box<WalletInfo> walletInfoSource,
|
||||
Box<UnspentCoinsInfo> unspentCoinSource, bool alwaysScan, bool isDirect) {
|
||||
return LitecoinWalletService(walletInfoSource, unspentCoinSource, alwaysScan, isDirect);
|
||||
Box<UnspentCoinsInfo> unspentCoinSource, bool isDirect) {
|
||||
return LitecoinWalletService(walletInfoSource, unspentCoinSource, isDirect);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -580,6 +579,15 @@ class CWBitcoin extends Bitcoin {
|
||||
bitcoinWallet.setSilentPaymentsScanning(active);
|
||||
}
|
||||
|
||||
Future<void> setIsAlwaysScanningSP(Object wallet, bool active) async {
|
||||
final bitcoinWallet = wallet as ElectrumWallet;
|
||||
bitcoinWallet.alwaysScan = active;
|
||||
bitcoinWallet.save();
|
||||
}
|
||||
|
||||
@computed
|
||||
bool getIsAlwaysScanningSP(Object wallet) => (wallet as ElectrumWallet).alwaysScan ?? false;
|
||||
|
||||
@override
|
||||
bool isTestnet(Object wallet) {
|
||||
final bitcoinWallet = wallet as ElectrumWallet;
|
||||
|
||||
@@ -28,7 +28,7 @@ class AddressValidator extends TextValidator {
|
||||
pattern: getPattern(type, isTestnet: isTestnet),
|
||||
length: getLength(type));
|
||||
|
||||
static String getPattern(CryptoCurrency type, {required bool isTestnet}) {
|
||||
static String getPattern(CryptoCurrency type, {bool isTestnet = false}) {
|
||||
var pattern = "";
|
||||
if (type is Erc20Token) {
|
||||
pattern = '0x[0-9a-zA-Z]+';
|
||||
|
||||
@@ -76,7 +76,6 @@ import 'package:cake_wallet/entities/qr_view_data.dart';
|
||||
import 'package:cake_wallet/entities/template.dart';
|
||||
import 'package:cake_wallet/entities/transaction_description.dart';
|
||||
import 'package:cake_wallet/ethereum/ethereum.dart';
|
||||
import 'package:cake_wallet/cake_pay/src/models/cake_pay_card.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_template.dart';
|
||||
import 'package:cake_wallet/exchange/trade.dart';
|
||||
import 'package:cake_wallet/monero/monero.dart';
|
||||
@@ -1119,14 +1118,12 @@ Future<void> setup({
|
||||
_walletInfoSource,
|
||||
_unspentCoinsInfoSource,
|
||||
_payjoinSessionSource,
|
||||
getIt.get<SettingsStore>().silentPaymentsAlwaysScan,
|
||||
SettingsStoreBase.walletPasswordDirectInput,
|
||||
);
|
||||
case WalletType.litecoin:
|
||||
return bitcoin!.createLitecoinWalletService(
|
||||
_walletInfoSource,
|
||||
_unspentCoinsInfoSource,
|
||||
getIt.get<SettingsStore>().mwebAlwaysScan,
|
||||
SettingsStoreBase.walletPasswordDirectInput,
|
||||
);
|
||||
case WalletType.ethereum:
|
||||
|
||||
@@ -54,7 +54,6 @@ class PreferencesKey {
|
||||
static const decredTransactionPriority = 'current_fee_priority_decred';
|
||||
static const customBitcoinFeeRate = 'custom_electrum_fee_rate';
|
||||
static const silentPaymentsCardDisplay = 'silentPaymentsCardDisplay';
|
||||
static const silentPaymentsAlwaysScan = 'silentPaymentsAlwaysScan';
|
||||
static const mwebCardDisplay = 'mwebCardDisplay';
|
||||
static const mwebEnabled = 'mwebEnabled';
|
||||
static const hasEnabledMwebBefore = 'hasEnabledMwebBefore';
|
||||
|
||||
@@ -123,7 +123,6 @@ abstract class SettingsStoreBase with Store {
|
||||
required this.showPayjoinCard,
|
||||
required this.customBitcoinFeeRate,
|
||||
required this.silentPaymentsCardDisplay,
|
||||
required this.silentPaymentsAlwaysScan,
|
||||
required this.mwebAlwaysScan,
|
||||
required this.mwebCardDisplay,
|
||||
required this.mwebEnabled,
|
||||
@@ -592,11 +591,6 @@ abstract class SettingsStoreBase with Store {
|
||||
PreferencesKey.silentPaymentsCardDisplay, silentPaymentsCardDisplay);
|
||||
});
|
||||
|
||||
reaction(
|
||||
(_) => silentPaymentsAlwaysScan,
|
||||
(bool silentPaymentsAlwaysScan) => _sharedPreferences.setBool(
|
||||
PreferencesKey.silentPaymentsAlwaysScan, silentPaymentsAlwaysScan));
|
||||
|
||||
reaction(
|
||||
(_) => mwebAlwaysScan,
|
||||
(bool mwebAlwaysScan) =>
|
||||
@@ -850,9 +844,6 @@ abstract class SettingsStoreBase with Store {
|
||||
@observable
|
||||
bool silentPaymentsCardDisplay;
|
||||
|
||||
@observable
|
||||
bool silentPaymentsAlwaysScan;
|
||||
|
||||
@observable
|
||||
bool mwebAlwaysScan;
|
||||
|
||||
@@ -1036,8 +1027,6 @@ abstract class SettingsStoreBase with Store {
|
||||
final customBitcoinFeeRate = sharedPreferences.getInt(PreferencesKey.customBitcoinFeeRate) ?? 1;
|
||||
final silentPaymentsCardDisplay =
|
||||
sharedPreferences.getBool(PreferencesKey.silentPaymentsCardDisplay) ?? true;
|
||||
final silentPaymentsAlwaysScan =
|
||||
sharedPreferences.getBool(PreferencesKey.silentPaymentsAlwaysScan) ?? false;
|
||||
final mwebAlwaysScan = sharedPreferences.getBool(PreferencesKey.mwebAlwaysScan) ?? false;
|
||||
final mwebCardDisplay = sharedPreferences.getBool(PreferencesKey.mwebCardDisplay) ?? true;
|
||||
final mwebEnabled = sharedPreferences.getBool(PreferencesKey.mwebEnabled) ?? false;
|
||||
@@ -1341,7 +1330,6 @@ abstract class SettingsStoreBase with Store {
|
||||
showPayjoinCard: showPayjoinCard,
|
||||
customBitcoinFeeRate: customBitcoinFeeRate,
|
||||
silentPaymentsCardDisplay: silentPaymentsCardDisplay,
|
||||
silentPaymentsAlwaysScan: silentPaymentsAlwaysScan,
|
||||
mwebAlwaysScan: mwebAlwaysScan,
|
||||
mwebCardDisplay: mwebCardDisplay,
|
||||
mwebEnabled: mwebEnabled,
|
||||
@@ -1525,8 +1513,6 @@ abstract class SettingsStoreBase with Store {
|
||||
customBitcoinFeeRate = sharedPreferences.getInt(PreferencesKey.customBitcoinFeeRate) ?? 1;
|
||||
silentPaymentsCardDisplay =
|
||||
sharedPreferences.getBool(PreferencesKey.silentPaymentsCardDisplay) ?? true;
|
||||
silentPaymentsAlwaysScan =
|
||||
sharedPreferences.getBool(PreferencesKey.silentPaymentsAlwaysScan) ?? false;
|
||||
mwebAlwaysScan = sharedPreferences.getBool(PreferencesKey.mwebAlwaysScan) ?? false;
|
||||
mwebCardDisplay = sharedPreferences.getBool(PreferencesKey.mwebCardDisplay) ?? true;
|
||||
mwebEnabled = sharedPreferences.getBool(PreferencesKey.mwebEnabled) ?? false;
|
||||
|
||||
@@ -12,7 +12,6 @@ import 'package:cake_wallet/entities/provider_types.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/themes/core/material_base_theme.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
@@ -89,7 +88,7 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
|
||||
return isBuyAction ? formattedFiatAmount : formattedCryptoAmount;
|
||||
}
|
||||
|
||||
AppStore _appStore;
|
||||
final AppStore _appStore;
|
||||
|
||||
Quote? bestRateQuote;
|
||||
|
||||
@@ -315,14 +314,16 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
|
||||
...outOfLimitQuotes,
|
||||
]);
|
||||
|
||||
await Navigator.of(context).pushNamed(
|
||||
Routes.buyOptionsPage,
|
||||
arguments: [
|
||||
updatedQuoteOptions,
|
||||
changeOption,
|
||||
launchTrade,
|
||||
],
|
||||
).then((value) => calculateBestRate());
|
||||
if (context.mounted) {
|
||||
await Navigator.of(context).pushNamed(
|
||||
Routes.buyOptionsPage,
|
||||
arguments: [
|
||||
updatedQuoteOptions,
|
||||
changeOption,
|
||||
launchTrade,
|
||||
],
|
||||
).then((value) => calculateBestRate());
|
||||
}
|
||||
}
|
||||
|
||||
void _onPairChange() {
|
||||
|
||||
@@ -18,7 +18,7 @@ abstract class SilentPaymentsSettingsViewModelBase with Store {
|
||||
bool get silentPaymentsCardDisplay => _settingsStore.silentPaymentsCardDisplay;
|
||||
|
||||
@computed
|
||||
bool get silentPaymentsAlwaysScan => _settingsStore.silentPaymentsAlwaysScan;
|
||||
bool get silentPaymentsAlwaysScan => bitcoin!.getIsAlwaysScanningSP(_wallet);
|
||||
|
||||
@action
|
||||
void setSilentPaymentsCardDisplay(bool value) {
|
||||
@@ -27,7 +27,7 @@ abstract class SilentPaymentsSettingsViewModelBase with Store {
|
||||
|
||||
@action
|
||||
void setSilentPaymentsAlwaysScan(bool value) {
|
||||
_settingsStore.silentPaymentsAlwaysScan = value;
|
||||
bitcoin!.setIsAlwaysScanningSP(_wallet, value);
|
||||
if (value) bitcoin!.setScanningActive(_wallet, true);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -192,8 +192,8 @@ abstract class Bitcoin {
|
||||
List<Unspent> getUnspents(Object wallet, {UnspentCoinType coinTypeToSpendFrom = UnspentCoinType.any});
|
||||
Future<void> updateUnspents(Object wallet);
|
||||
WalletService createBitcoinWalletService(
|
||||
Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource, Box<PayjoinSession> payjoinSessionSource, bool alwaysScan, bool isDirect);
|
||||
WalletService createLitecoinWalletService(Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource, bool alwaysScan, bool isDirect);
|
||||
Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource, Box<PayjoinSession> payjoinSessionSource, bool isDirect);
|
||||
WalletService createLitecoinWalletService(Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource, bool isDirect);
|
||||
TransactionPriority getBitcoinTransactionPriorityMedium();
|
||||
TransactionPriority getBitcoinTransactionPriorityCustom();
|
||||
TransactionPriority getLitecoinTransactionPriorityMedium();
|
||||
@@ -216,6 +216,8 @@ abstract class Bitcoin {
|
||||
bool hasTaprootInput(PendingTransaction pendingTransaction);
|
||||
bool getScanningActive(Object wallet);
|
||||
Future<void> setScanningActive(Object wallet, bool active);
|
||||
Future<void> setIsAlwaysScanningSP(Object wallet, bool active);
|
||||
bool getIsAlwaysScanningSP(Object wallet);
|
||||
bool isTestnet(Object wallet);
|
||||
|
||||
Future<PendingTransaction> replaceByFee(Object wallet, String transactionHash, String fee);
|
||||
|
||||
Reference in New Issue
Block a user