remove coin enum hasPaynymSupport getter in favor of type checking

This commit is contained in:
julian 2023-01-25 15:46:48 -06:00
parent 907c380812
commit 7cb497f4f7
5 changed files with 21 additions and 38 deletions

View file

@ -8,8 +8,7 @@ import 'package:stackwallet/pages/paynym/paynym_home_view.dart';
import 'package:stackwallet/providers/global/paynym_api_provider.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/providers/wallet/my_paynym_account_state_provider.dart';
import 'package:stackwallet/services/coins/coin_paynym_extension.dart';
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
import 'package:stackwallet/services/mixins/paynym_support.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
@ -18,7 +17,7 @@ import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/loading_indicator.dart';
class WalletNavigationBar extends StatefulWidget {
class WalletNavigationBar extends ConsumerStatefulWidget {
const WalletNavigationBar({
Key? key,
required this.onReceivePressed,
@ -41,10 +40,11 @@ class WalletNavigationBar extends StatefulWidget {
final String walletId;
@override
State<WalletNavigationBar> createState() => _WalletNavigationBarState();
ConsumerState<WalletNavigationBar> createState() =>
_WalletNavigationBarState();
}
class _WalletNavigationBarState extends State<WalletNavigationBar> {
class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
double scale = 0;
final duration = const Duration(milliseconds: 200);
@ -115,14 +115,15 @@ class _WalletNavigationBarState extends State<WalletNavigationBar> {
),
);
// todo make generic and not doge specific
final wallet = (ref
final manager = ref
.read(walletsChangeNotifierProvider)
.getManager(widget.walletId)
.wallet as DogecoinWallet);
.getManager(widget.walletId);
final code = await wallet.getPaymentCode(
DerivePathTypeExt.primaryFor(wallet.coin));
final paynymInterface =
manager.wallet as PaynymWalletInterface;
final code = await paynymInterface.getPaymentCode(
DerivePathTypeExt.primaryFor(manager.coin));
final account = await ref
.read(paynymAPIProvider)
@ -359,7 +360,8 @@ class _WalletNavigationBarState extends State<WalletNavigationBar> {
),
),
),
if (widget.coin.hasPaynymSupport)
if (ref.watch(walletsChangeNotifierProvider.select((value) =>
value.getManager(widget.walletId).hasPaynymSupport)))
RawMaterialButton(
constraints: const BoxConstraints(
minWidth: 66,

View file

@ -21,7 +21,6 @@ import 'package:stackwallet/providers/global/paynym_api_provider.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/providers/ui/transaction_filter_provider.dart';
import 'package:stackwallet/providers/wallet/my_paynym_account_state_provider.dart';
import 'package:stackwallet/services/coins/coin_paynym_extension.dart';
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
@ -536,7 +535,8 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
);
},
),
if (coin.hasPaynymSupport)
if (ref.watch(walletsChangeNotifierProvider.select((value) =>
value.getManager(widget.walletId).hasPaynymSupport)))
SecondaryButton(
label: "PayNym",
width: 160,

View file

@ -9,6 +9,7 @@ import 'package:stackwallet/services/coins/coin_service.dart';
import 'package:stackwallet/services/event_bus/events/global/node_connection_status_changed_event.dart';
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
import 'package:stackwallet/services/mixins/paynym_support.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/logger.dart';
@ -214,4 +215,6 @@ class Manager with ChangeNotifier {
}
int get currentHeight => _currentWallet.storedChainHeight;
bool get hasPaynymSupport => _currentWallet is PaynymWalletInterface;
}

View file

@ -1,6 +1,7 @@
import 'package:bip47/src/util.dart';
import 'package:decimal/decimal.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart';
import 'package:stackwallet/services/mixins/paynym_support.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/format.dart';
import 'package:tuple/tuple.dart';
@ -186,7 +187,7 @@ mixin ElectrumXParsing {
}
TransactionSubType txSubType = TransactionSubType.none;
if (coin.hasPaynymSupport && outs.length > 1 && ins.isNotEmpty) {
if (this is PaynymWalletInterface && outs.length > 1 && ins.isNotEmpty) {
List<String>? scriptChunks = outs[1].scriptPubKeyAsm?.split(" ");
if (scriptChunks?.length == 2 && scriptChunks?[0] == "OP_RETURN") {
final blindedPaymentCode = scriptChunks![1];

View file

@ -171,29 +171,6 @@ extension CoinExt on Coin {
}
}
bool get hasPaynymSupport {
switch (this) {
case Coin.bitcoin:
case Coin.litecoin:
case Coin.bitcoincash:
case Coin.firo:
case Coin.namecoin:
case Coin.particl:
case Coin.bitcoinTestNet:
case Coin.litecoinTestNet:
case Coin.bitcoincashTestnet:
case Coin.firoTestNet:
case Coin.epicCash:
case Coin.monero:
case Coin.wownero:
return false;
case Coin.dogecoin:
case Coin.dogecoinTestNet:
return true;
}
}
int get requiredConfirmations {
switch (this) {
case Coin.bitcoin: