Files
hash-wallet/lib/view_model/dashboard/receive_option_view_model.dart
T
malik1004xandGitHub 9b50011e75 Hide broken options in Bitcoin wallets without a private key (#3532)
* hide unavailable receive page options

* hide broken options in wallets without a private key

* hide exporting unavailable logs

* hide sign/verify on airgapped wallets

* hide mweb on hwws

* hide mweb ad for hww
2026-08-24 23:24:52 +03:00

56 lines
1.8 KiB
Dart

import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/zcash/zcash.dart';
import 'package:cw_core/receive_page_option.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
part 'receive_option_view_model.g.dart';
class ReceiveOptionViewModel = ReceiveOptionViewModelBase with _$ReceiveOptionViewModel;
abstract class ReceiveOptionViewModelBase with Store {
ReceiveOptionViewModelBase(this._wallet, this.initialPageOption)
: selectedReceiveOption = initialPageOption ??
([WalletType.bitcoin, WalletType.litecoin].contains(_wallet.type)
? bitcoin!.getSelectedAddressType(_wallet)
: (_wallet.type == WalletType.decred && _wallet.isTestnet)
? ReceivePageOption.testnet
: _wallet.type == WalletType.zcash
? zcash!.getSelectedAddressType(_wallet)
: ReceivePageOption.mainnet) {
if (_wallet.type == WalletType.zcash) {
reaction<bool>(
(_) => zcash!.ironwoodActive(_wallet.walletAddresses),
(_) => _syncZcashShieldedLabel(),
);
}
}
final WalletBase _wallet;
final ReceivePageOption? initialPageOption;
@observable
ReceivePageOption selectedReceiveOption;
@computed
List<ReceivePageOption> get options =>
_wallet.walletAddresses.receivePageOptions.where(_wallet.receiveOptionAvailable).toList();
String get walletTypeString => walletTypeToString(_wallet.type);
@action
void selectReceiveOption(ReceivePageOption option) => selectedReceiveOption = option;
@action
void _syncZcashShieldedLabel() {
for (final option in options) {
if (option.value == selectedReceiveOption.value) {
selectedReceiveOption = option;
return;
}
}
}
}