mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-04 17:59:22 +00:00
fix probable infinite loop causing view only refresh to stay stuck forever
This commit is contained in:
parent
216719ba56
commit
6dd7ef183a
4 changed files with 82 additions and 8 deletions
lib
pages/receive_view
pages_desktop_specific/my_stack_view/wallet_view/sub_widgets
wallets/wallet
|
@ -35,6 +35,7 @@ import '../../wallets/isar/providers/wallet_info_provider.dart';
|
|||
import '../../wallets/wallet/impl/bitcoin_wallet.dart';
|
||||
import '../../wallets/wallet/intermediate/bip39_hd_wallet.dart';
|
||||
import '../../wallets/wallet/wallet_mixin_interfaces/bcash_interface.dart';
|
||||
import '../../wallets/wallet/wallet_mixin_interfaces/extended_keys_interface.dart';
|
||||
import '../../wallets/wallet/wallet_mixin_interfaces/multi_address_interface.dart';
|
||||
import '../../wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
|
||||
import '../../wallets/wallet/wallet_mixin_interfaces/view_only_option_interface.dart';
|
||||
|
@ -109,11 +110,29 @@ class _ReceiveViewState extends ConsumerState<ReceiveView> {
|
|||
|
||||
final Address? address;
|
||||
if (wallet is Bip39HDWallet && wallet is! BCashInterface) {
|
||||
final type = DerivePathType.values.firstWhere(
|
||||
(e) => e.getAddressType() == _walletAddressTypes[_currentIndex],
|
||||
);
|
||||
DerivePathType? type;
|
||||
if (wallet.isViewOnly && wallet is ExtendedKeysInterface) {
|
||||
final voData = await wallet.getViewOnlyWalletData()
|
||||
as ExtendedKeysViewOnlyWalletData;
|
||||
for (final t in wallet.cryptoCurrency.supportedDerivationPathTypes) {
|
||||
final testPath = wallet.cryptoCurrency.constructDerivePath(
|
||||
derivePathType: t,
|
||||
chain: 0,
|
||||
index: 0,
|
||||
);
|
||||
if (testPath.startsWith(voData.xPubs.first.path)) {
|
||||
type = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
type = DerivePathType.values.firstWhere(
|
||||
(e) => e.getAddressType() == _walletAddressTypes[_currentIndex],
|
||||
);
|
||||
}
|
||||
|
||||
address = await wallet.generateNextReceivingAddress(
|
||||
derivePathType: type,
|
||||
derivePathType: type!,
|
||||
);
|
||||
final isar = ref.read(mainDBProvider).isar;
|
||||
await isar.writeTxn(() async {
|
||||
|
|
|
@ -39,6 +39,7 @@ import '../../../../wallets/isar/providers/wallet_info_provider.dart';
|
|||
import '../../../../wallets/wallet/impl/bitcoin_wallet.dart';
|
||||
import '../../../../wallets/wallet/intermediate/bip39_hd_wallet.dart';
|
||||
import '../../../../wallets/wallet/wallet_mixin_interfaces/bcash_interface.dart';
|
||||
import '../../../../wallets/wallet/wallet_mixin_interfaces/extended_keys_interface.dart';
|
||||
import '../../../../wallets/wallet/wallet_mixin_interfaces/multi_address_interface.dart';
|
||||
import '../../../../wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
|
||||
import '../../../../wallets/wallet/wallet_mixin_interfaces/view_only_option_interface.dart';
|
||||
|
@ -106,11 +107,28 @@ class _DesktopReceiveState extends ConsumerState<DesktopReceive> {
|
|||
|
||||
final Address? address;
|
||||
if (wallet is Bip39HDWallet && wallet is! BCashInterface) {
|
||||
final type = DerivePathType.values.firstWhere(
|
||||
(e) => e.getAddressType() == _walletAddressTypes[_currentIndex],
|
||||
);
|
||||
DerivePathType? type;
|
||||
if (wallet.isViewOnly && wallet is ExtendedKeysInterface) {
|
||||
final voData = await wallet.getViewOnlyWalletData()
|
||||
as ExtendedKeysViewOnlyWalletData;
|
||||
for (final t in wallet.cryptoCurrency.supportedDerivationPathTypes) {
|
||||
final testPath = wallet.cryptoCurrency.constructDerivePath(
|
||||
derivePathType: t,
|
||||
chain: 0,
|
||||
index: 0,
|
||||
);
|
||||
if (testPath.startsWith(voData.xPubs.first.path)) {
|
||||
type = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
type = DerivePathType.values.firstWhere(
|
||||
(e) => e.getAddressType() == _walletAddressTypes[_currentIndex],
|
||||
);
|
||||
}
|
||||
address = await wallet.generateNextReceivingAddress(
|
||||
derivePathType: type,
|
||||
derivePathType: type!,
|
||||
);
|
||||
final isar = ref.read(mainDBProvider).isar;
|
||||
await isar.writeTxn(() async {
|
||||
|
|
|
@ -76,6 +76,34 @@ abstract class Bip39HDWallet<T extends Bip39HDCurrency> extends Bip39Wallet<T>
|
|||
return address;
|
||||
}
|
||||
|
||||
@override
|
||||
List<FilterOperation> get standardReceivingAddressFilters => [
|
||||
// view only only have a single derivation path currently
|
||||
if (!isViewOnly)
|
||||
FilterCondition.equalTo(
|
||||
property: r"type",
|
||||
value: info.mainAddressType,
|
||||
),
|
||||
const FilterCondition.equalTo(
|
||||
property: r"subType",
|
||||
value: AddressSubType.receiving,
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
List<FilterOperation> get standardChangeAddressFilters => [
|
||||
// view only only have a single derivation path currently
|
||||
if (!isViewOnly)
|
||||
FilterCondition.equalTo(
|
||||
property: r"type",
|
||||
value: info.mainAddressType,
|
||||
),
|
||||
const FilterCondition.equalTo(
|
||||
property: r"subType",
|
||||
value: AddressSubType.change,
|
||||
),
|
||||
];
|
||||
|
||||
/// Generates a receiving address. If none
|
||||
/// are in the current wallet db it will generate at index 0, otherwise the
|
||||
/// highest index found in the current wallet db.
|
||||
|
|
|
@ -5,16 +5,25 @@ import 'electrumx_interface.dart';
|
|||
abstract class XKey {
|
||||
XKey({required this.path});
|
||||
final String path;
|
||||
|
||||
@override
|
||||
String toString() => "Path: $path";
|
||||
}
|
||||
|
||||
class XPub extends XKey {
|
||||
XPub({required super.path, required this.encoded});
|
||||
final String encoded;
|
||||
|
||||
@override
|
||||
String toString() => "XPub { path: $path, encoded: $encoded }";
|
||||
}
|
||||
|
||||
class XPriv extends XKey {
|
||||
XPriv({required super.path, required this.encoded});
|
||||
final String encoded;
|
||||
|
||||
@override
|
||||
String toString() => "XPriv { path: $path, encoded: $encoded }";
|
||||
}
|
||||
|
||||
mixin ExtendedKeysInterface<T extends ElectrumXCurrencyInterface>
|
||||
|
|
Loading…
Reference in a new issue