diff --git a/lib/pages/cashfusion/cashfusion_view.dart b/lib/pages/cashfusion/cashfusion_view.dart index 8e7326623..e0ca79d29 100644 --- a/lib/pages/cashfusion/cashfusion_view.dart +++ b/lib/pages/cashfusion/cashfusion_view.dart @@ -23,6 +23,7 @@ import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.dart'; import 'package:stackwallet/widgets/background.dart'; @@ -54,6 +55,7 @@ class _CashFusionViewState extends ConsumerState { late final FocusNode portFocusNode; late final TextEditingController fusionRoundController; late final FocusNode fusionRoundFocusNode; + Coin? coin; bool _enableSSLCheckbox = false; bool _enableStartButton = false; @@ -87,7 +89,11 @@ class _CashFusionViewState extends ConsumerState { ); // update user prefs (persistent) - ref.read(prefsChangeNotifierProvider).fusionServerInfo = newInfo; + if (coin == Coin.bitcoincash) { + ref.read(prefsChangeNotifierProvider).fusionServerInfoBch = newInfo; + } else { + ref.read(prefsChangeNotifierProvider).fusionServerInfoXec = newInfo; + } unawaited( fusionWallet.fuse( @@ -111,7 +117,16 @@ class _CashFusionViewState extends ConsumerState { portFocusNode = FocusNode(); fusionRoundFocusNode = FocusNode(); - final info = ref.read(prefsChangeNotifierProvider).fusionServerInfo; + coin = ref + .read(walletsChangeNotifierProvider) + .getManager(widget.walletId) + .wallet + .coin; + + final info = (coin == Coin.bitcoincash) + ? ref.read(prefsChangeNotifierProvider).fusionServerInfoBch + : ref.read(prefsChangeNotifierProvider).fusionServerInfoXec; + serverController.text = info.host; portController.text = info.port.toString(); _enableSSLCheckbox = info.ssl; @@ -212,7 +227,9 @@ class _CashFusionViewState extends ConsumerState { CustomTextButton( text: "Default", onTap: () { - const def = FusionInfo.DEFAULTS; + final def = (coin == Coin.bitcoincash) + ? FusionInfo.BCH_DEFAULTS + : FusionInfo.XEC_DEFAULTS; serverController.text = def.host; portController.text = def.port.toString(); fusionRoundController.text = diff --git a/lib/pages/cashfusion/fusion_progress_view.dart b/lib/pages/cashfusion/fusion_progress_view.dart index 00d037bac..78265d95d 100644 --- a/lib/pages/cashfusion/fusion_progress_view.dart +++ b/lib/pages/cashfusion/fusion_progress_view.dart @@ -17,6 +17,7 @@ import 'package:stackwallet/providers/cash_fusion/fusion_progress_ui_state_provi import 'package:stackwallet/providers/global/prefs_provider.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/show_loading.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; @@ -37,12 +38,13 @@ class FusionProgressView extends ConsumerStatefulWidget { static const routeName = "/cashFusionProgressView"; final String walletId; - @override ConsumerState createState() => _FusionProgressViewState(); } class _FusionProgressViewState extends ConsumerState { + Coin? coin; + Future _requestAndProcessCancel() async { final shouldCancel = await showDialog( context: context, @@ -98,6 +100,12 @@ class _FusionProgressViewState extends ConsumerState { .watch(fusionProgressUIStateProvider(widget.walletId)) .fusionRoundsCompleted; + coin = ref + .read(walletsChangeNotifierProvider) + .getManager(widget.walletId) + .wallet + .coin; + return WillPopScope( onWillPop: () async { return await _requestAndProcessCancel(); @@ -226,7 +234,9 @@ class _FusionProgressViewState extends ConsumerState { final fusionWallet = ref.read(pWallets).getWallet(widget.walletId) as CashFusion; - final fusionInfo = ref.read(prefsChangeNotifierProvider).fusionServerInfo; + final fusionInfo = (coin == Coin.bitcoincash) + ? ref.read(prefsChangeNotifierProvider).fusionServerInfoBch + : ref.read(prefsChangeNotifierProvider).fusionServerInfoXec; try { fusionWallet.uiState = ref.read( diff --git a/lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart b/lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart index 1648097c5..5b6ab9129 100644 --- a/lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart +++ b/lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart @@ -25,6 +25,7 @@ import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; @@ -58,6 +59,7 @@ class _DesktopCashFusion extends ConsumerState { late final FocusNode portFocusNode; late final TextEditingController fusionRoundController; late final FocusNode fusionRoundFocusNode; + late final Coin coin; bool _enableStartButton = false; bool _enableSSLCheckbox = false; @@ -91,7 +93,11 @@ class _DesktopCashFusion extends ConsumerState { ); // update user prefs (persistent) - ref.read(prefsChangeNotifierProvider).fusionServerInfo = newInfo; + if (coin == Coin.bitcoincash) { + ref.read(prefsChangeNotifierProvider).fusionServerInfoBch = newInfo; + } else { + ref.read(prefsChangeNotifierProvider).fusionServerInfoXec = newInfo; + } unawaited( fusionWallet.fuse( @@ -120,7 +126,16 @@ class _DesktopCashFusion extends ConsumerState { portFocusNode = FocusNode(); fusionRoundFocusNode = FocusNode(); - final info = ref.read(prefsChangeNotifierProvider).fusionServerInfo; + coin = ref + .read(walletsChangeNotifierProvider) + .getManager(widget.walletId) + .wallet + .coin; + + final info = (coin == Coin.bitcoincash) + ? ref.read(prefsChangeNotifierProvider).fusionServerInfoBch + : ref.read(prefsChangeNotifierProvider).fusionServerInfoXec; + serverController.text = info.host; portController.text = info.port.toString(); _enableSSLCheckbox = info.ssl; @@ -334,7 +349,9 @@ class _DesktopCashFusion extends ConsumerState { CustomTextButton( text: "Default", onTap: () { - const def = FusionInfo.DEFAULTS; + final def = (coin == Coin.bitcoincash) + ? FusionInfo.BCH_DEFAULTS + : FusionInfo.XEC_DEFAULTS; serverController.text = def.host; portController.text = def.port.toString(); fusionRoundController.text = diff --git a/lib/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart b/lib/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart index 36887a4ab..0cba721bb 100644 --- a/lib/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart +++ b/lib/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart @@ -7,6 +7,7 @@ import 'package:stackwallet/providers/cash_fusion/fusion_progress_ui_state_provi import 'package:stackwallet/providers/global/prefs_provider.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/show_loading.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.dart'; @@ -39,6 +40,8 @@ class FusionDialogView extends ConsumerStatefulWidget { } class _FusionDialogViewState extends ConsumerState { + Coin? coin; + Future _requestAndProcessCancel() async { if (!ref.read(fusionProgressUIStateProvider(widget.walletId)).running) { return true; @@ -151,6 +154,12 @@ class _FusionDialogViewState extends ConsumerState { .watch(fusionProgressUIStateProvider(widget.walletId)) .fusionRoundsCompleted; + coin = ref + .read(walletsChangeNotifierProvider) + .getManager(widget.walletId) + .wallet + .coin; + return DesktopDialog( maxHeight: 600, child: SingleChildScrollView( @@ -284,7 +293,9 @@ class _FusionDialogViewState extends ConsumerState { final fusionWallet = ref.read(pWallets).getWallet(widget.walletId) as CashFusion; - final fusionInfo = ref.read(prefsChangeNotifierProvider).fusionServerInfo; + final fusionInfo = (coin == Coin.bitcoincash) + ? ref.read(prefsChangeNotifierProvider).fusionServerInfoBch + : ref.read(prefsChangeNotifierProvider).fusionServerInfoXec; try { fusionWallet.uiState = ref.read( diff --git a/lib/utilities/prefs.dart b/lib/utilities/prefs.dart index 155798891..c4d3e1739 100644 --- a/lib/utilities/prefs.dart +++ b/lib/utilities/prefs.dart @@ -65,7 +65,8 @@ class Prefs extends ChangeNotifier { await _setAmountUnits(); await _setMaxDecimals(); _useTor = await _getUseTor(); - _fusionServerInfo = await _getFusionServerInfo(); + _fusionServerInfoBch = await _getFusionServerInfoBch(); + _fusionServerInfoXec = await _getFusionServerInfoXec(); _initialized = true; } @@ -936,32 +937,59 @@ class Prefs extends ChangeNotifier { // fusion server info - FusionInfo _fusionServerInfo = FusionInfo.DEFAULTS; + FusionInfo _fusionServerInfoBch = FusionInfo.BCH_DEFAULTS; + FusionInfo _fusionServerInfoXec = FusionInfo.XEC_DEFAULTS; - FusionInfo get fusionServerInfo => _fusionServerInfo; + FusionInfo get fusionServerInfoBch => _fusionServerInfoBch; + FusionInfo get fusionServerInfoXec => _fusionServerInfoXec; - set fusionServerInfo(FusionInfo fusionServerInfo) { - if (this.fusionServerInfo != fusionServerInfo) { + set fusionServerInfoBch(FusionInfo fusionServerInfo) { + if (fusionServerInfoBch != fusionServerInfo) { DB.instance.put( boxName: DB.boxNamePrefs, key: "fusionServerInfo", value: fusionServerInfo.toJsonString(), ); - _fusionServerInfo = fusionServerInfo; + _fusionServerInfoBch = fusionServerInfo; notifyListeners(); } } - Future _getFusionServerInfo() async { + set fusionServerInfoXec(FusionInfo fusionServerInfo) { + if (fusionServerInfoXec != fusionServerInfo) { + DB.instance.put( + boxName: DB.boxNamePrefs, + key: "fusionServerInfoXec", + value: fusionServerInfo.toJsonString(), + ); + _fusionServerInfoXec = fusionServerInfo; + notifyListeners(); + } + } + + Future _getFusionServerInfoBch() async { final saved = await DB.instance.get( boxName: DB.boxNamePrefs, - key: "fusionServerInfo", + key: "fusionServerInfoBch", ) as String?; try { return FusionInfo.fromJsonString(saved!); } catch (_) { - return FusionInfo.DEFAULTS; + return FusionInfo.BCH_DEFAULTS; + } + } + + Future _getFusionServerInfoXec() async { + final saved = await DB.instance.get( + boxName: DB.boxNamePrefs, + key: "fusionServerInfoXec", + ) as String?; + + try { + return FusionInfo.fromJsonString(saved!); + } catch (_) { + return FusionInfo.XEC_DEFAULTS; } } }