Skip to content

Commit f7b79fe

Browse files
Merge pull request #1172 from cypherstack/more-bugs
More bug fixes
2 parents f7f00e3 + 22c1e04 commit f7b79fe

File tree

4 files changed

+275
-119
lines changed

4 files changed

+275
-119
lines changed

lib/pages/exchange_view/exchange_step_views/step_4_view.dart

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import '../../../models/exchange/incomplete_exchange.dart';
2121
import '../../../notifications/show_flush_bar.dart';
2222
import '../../../providers/providers.dart';
2323
import '../../../route_generator.dart';
24+
import '../../../services/wallets.dart';
2425
import '../../../themes/stack_colors.dart';
2526
import '../../../utilities/amount/amount.dart';
2627
import '../../../utilities/amount/amount_formatter.dart';
@@ -34,6 +35,8 @@ import '../../../wallets/crypto_currency/crypto_currency.dart';
3435
import '../../../wallets/isar/providers/wallet_info_provider.dart';
3536
import '../../../wallets/models/tx_data.dart';
3637
import '../../../wallets/wallet/impl/firo_wallet.dart';
38+
import '../../../wallets/wallet/intermediate/external_wallet.dart';
39+
import '../../../wallets/wallet/wallet_mixin_interfaces/mweb_interface.dart';
3740
import '../../../widgets/background.dart';
3841
import '../../../widgets/custom_buttons/app_bar_icon_button.dart';
3942
import '../../../widgets/desktop/secondary_button.dart';
@@ -65,20 +68,28 @@ class Step4View extends ConsumerStatefulWidget {
6568
}
6669

6770
class _Step4ViewState extends ConsumerState<Step4View> {
71+
late final bool isWalletCoinAndCanSend;
6872
late final IncompleteExchangeModel model;
6973
late final ClipboardInterface clipboard;
7074

7175
String _statusString = "New";
7276

7377
Timer? _statusTimer;
7478

75-
bool _isWalletCoinAndHasWallet(String ticker, WidgetRef ref) {
79+
bool isWalletCoinAndCanSendWithoutWalletOpened(
80+
String ticker,
81+
Wallets walletsInstance,
82+
) {
7683
try {
7784
final coin = AppConfig.getCryptoCurrencyForTicker(ticker);
78-
return ref
79-
.read(pWallets)
80-
.wallets
81-
.where((e) => e.info.coin == coin)
85+
return walletsInstance.wallets
86+
.where(
87+
(e) =>
88+
e.info.coin == coin &&
89+
(e is! ExternalWallet ||
90+
e is MwebInterface), // ltc mweb is external but swaps
91+
// should not use mweb, hence the odd logic check here
92+
)
8293
.isNotEmpty;
8394
} catch (_) {
8495
return false;
@@ -111,6 +122,11 @@ class _Step4ViewState extends ConsumerState<Step4View> {
111122
model = widget.model;
112123
clipboard = widget.clipboard;
113124

125+
isWalletCoinAndCanSend = isWalletCoinAndCanSendWithoutWalletOpened(
126+
model.trade!.payInCurrency,
127+
ref.read(pWallets),
128+
);
129+
114130
_statusTimer = Timer.periodic(const Duration(seconds: 60), (_) {
115131
_updateStatus();
116132
});
@@ -339,10 +355,6 @@ class _Step4ViewState extends ConsumerState<Step4View> {
339355

340356
@override
341357
Widget build(BuildContext context) {
342-
final bool isWalletCoin = _isWalletCoinAndHasWallet(
343-
model.trade!.payInCurrency,
344-
ref,
345-
);
346358
return WillPopScope(
347359
onWillPop: () async {
348360
await _close();
@@ -791,8 +803,9 @@ class _Step4ViewState extends ConsumerState<Step4View> {
791803
style: STextStyles.button(context),
792804
),
793805
),
794-
if (isWalletCoin) const SizedBox(height: 12),
795-
if (isWalletCoin)
806+
if (isWalletCoinAndCanSend)
807+
const SizedBox(height: 12),
808+
if (isWalletCoinAndCanSend)
796809
Builder(
797810
builder: (context) {
798811
String buttonTitle =

lib/pages/exchange_view/trade_details_view.dart

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import '../../services/exchange/exchange.dart';
3232
import '../../services/exchange/nanswap/nanswap_exchange.dart';
3333
import '../../services/exchange/simpleswap/simpleswap_exchange.dart';
3434
import '../../services/exchange/trocador/trocador_exchange.dart';
35+
import '../../services/wallets.dart';
3536
import '../../themes/stack_colors.dart';
3637
import '../../themes/theme_providers.dart';
3738
import '../../utilities/amount/amount.dart';
@@ -43,6 +44,8 @@ import '../../utilities/format.dart';
4344
import '../../utilities/text_styles.dart';
4445
import '../../utilities/util.dart';
4546
import '../../wallets/crypto_currency/crypto_currency.dart';
47+
import '../../wallets/wallet/intermediate/external_wallet.dart';
48+
import '../../wallets/wallet/wallet_mixin_interfaces/mweb_interface.dart';
4649
import '../../widgets/background.dart';
4750
import '../../widgets/conditional_parent.dart';
4851
import '../../widgets/custom_buttons/app_bar_icon_button.dart';
@@ -152,6 +155,26 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {
152155
}
153156
}
154157

158+
bool isWalletCoinAndCanSendWithoutWalletOpened(
159+
String ticker,
160+
Wallets walletsInstance,
161+
) {
162+
try {
163+
final coin = AppConfig.getCryptoCurrencyForTicker(ticker);
164+
return walletsInstance.wallets
165+
.where(
166+
(e) =>
167+
e.info.coin == coin &&
168+
(e is! ExternalWallet ||
169+
e is MwebInterface), // ltc mweb is external but swaps
170+
// should not use mweb, hence the odd logic check here
171+
)
172+
.isNotEmpty;
173+
} catch (_) {
174+
return false;
175+
}
176+
}
177+
155178
@override
156179
Widget build(BuildContext context) {
157180
final bool sentFromStack =
@@ -193,13 +216,11 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {
193216

194217
final showSendFromStackButton =
195218
!hasTx &&
196-
![
197-
"xmr",
198-
"monero",
199-
"wow",
200-
"wownero",
201-
].contains(trade.payInCurrency.toLowerCase()) &&
202219
AppConfig.isStackCoin(trade.payInCurrency) &&
220+
isWalletCoinAndCanSendWithoutWalletOpened(
221+
trade.payInCurrency,
222+
ref.read(pWallets),
223+
) &&
203224
(trade.status == "New" ||
204225
trade.status == "new" ||
205226
trade.status == "waiting" ||

lib/pages_desktop_specific/desktop_exchange/exchange_steps/step_scaffold.dart

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ import '../../../models/exchange/response_objects/trade.dart';
2020
import '../../../pages/exchange_view/send_from_view.dart';
2121
import '../../../providers/exchange/exchange_form_state_provider.dart';
2222
import '../../../providers/global/trades_service_provider.dart';
23+
import '../../../providers/global/wallets_provider.dart';
2324
import '../../../route_generator.dart';
2425
import '../../../services/exchange/exchange_response.dart';
2526
import '../../../services/notifications_api.dart';
27+
import '../../../services/wallets.dart';
2628
import '../../../themes/stack_colors.dart';
2729
import '../../../utilities/amount/amount.dart';
2830
import '../../../utilities/assets.dart';
2931
import '../../../utilities/enums/exchange_rate_type_enum.dart';
3032
import '../../../utilities/text_styles.dart';
33+
import '../../../wallets/wallet/intermediate/external_wallet.dart';
34+
import '../../../wallets/wallet/wallet_mixin_interfaces/mweb_interface.dart';
3135
import '../../../widgets/custom_buttons/app_bar_icon_button.dart';
3236
import '../../../widgets/custom_loading_overlay.dart';
3337
import '../../../widgets/desktop/desktop_dialog.dart';
@@ -241,6 +245,26 @@ class _StepScaffoldState extends ConsumerState<StepScaffold> {
241245
);
242246
}
243247

248+
bool isWalletCoinAndCanSendWithoutWalletOpened(
249+
String ticker,
250+
Wallets walletsInstance,
251+
) {
252+
try {
253+
final coin = AppConfig.getCryptoCurrencyForTicker(ticker);
254+
return walletsInstance.wallets
255+
.where(
256+
(e) =>
257+
e.info.coin == coin &&
258+
(e is! ExternalWallet ||
259+
e is MwebInterface), // ltc mweb is external but swaps
260+
// should not use mweb, hence the odd logic check here
261+
)
262+
.isNotEmpty;
263+
} catch (_) {
264+
return false;
265+
}
266+
}
267+
244268
@override
245269
void initState() {
246270
duration = const Duration(milliseconds: 250);
@@ -251,6 +275,18 @@ class _StepScaffoldState extends ConsumerState<StepScaffold> {
251275
@override
252276
Widget build(BuildContext context) {
253277
final model = ref.watch(desktopExchangeModelProvider);
278+
279+
final bool canSendFromStack;
280+
if (currentStep != 4) {
281+
// set to true anyways to show back button
282+
canSendFromStack = true;
283+
} else {
284+
canSendFromStack = isWalletCoinAndCanSendWithoutWalletOpened(
285+
model?.sendTicker ?? "",
286+
ref.read(pWallets),
287+
);
288+
}
289+
254290
return Column(
255291
mainAxisAlignment: MainAxisAlignment.start,
256292
children: [
@@ -307,25 +343,27 @@ class _StepScaffoldState extends ConsumerState<StepScaffold> {
307343
),
308344
child: Row(
309345
children: [
310-
Expanded(
311-
child: AnimatedCrossFade(
312-
duration: const Duration(milliseconds: 250),
313-
crossFadeState:
314-
currentStep == 4
315-
? CrossFadeState.showSecond
316-
: CrossFadeState.showFirst,
317-
firstChild: SecondaryButton(
318-
label: "Back",
319-
buttonHeight: ButtonHeight.l,
320-
onPressed: onBack,
321-
),
322-
secondChild: SecondaryButton(
323-
label: "Send from ${AppConfig.appName}",
324-
buttonHeight: ButtonHeight.l,
325-
onPressed: sendFromStack,
326-
),
327-
),
328-
),
346+
canSendFromStack
347+
? Expanded(
348+
child: AnimatedCrossFade(
349+
duration: const Duration(milliseconds: 250),
350+
crossFadeState:
351+
currentStep == 4
352+
? CrossFadeState.showSecond
353+
: CrossFadeState.showFirst,
354+
firstChild: SecondaryButton(
355+
label: "Back",
356+
buttonHeight: ButtonHeight.l,
357+
onPressed: onBack,
358+
),
359+
secondChild: SecondaryButton(
360+
label: "Send from ${AppConfig.appName}",
361+
buttonHeight: ButtonHeight.l,
362+
onPressed: sendFromStack,
363+
),
364+
),
365+
)
366+
: const Spacer(),
329367
const SizedBox(width: 16),
330368
Expanded(
331369
child: AnimatedCrossFade(

0 commit comments

Comments
 (0)