Skip to content

Commit 397f496

Browse files
committed
clean up swap currency selection list items and add trocador warnings for ltc and firo
1 parent b6b63bc commit 397f496

File tree

10 files changed

+534
-308
lines changed

10 files changed

+534
-308
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,4 @@ scripts/linux/build/libsecret/subprojects/gi-docgen/.meson-subproject-wrap-hash.
112112
crypto_plugins/cs_monero/built_outputs
113113
crypto_plugins/cs_monero/build
114114
crypto_plugins/*.diff
115+
/devtools_options.yaml

lib/models/exchange/aggregate_currency.dart

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111
import 'package:tuple/tuple.dart';
1212

13+
import '../../services/exchange/trocador/trocador_exchange.dart';
1314
import '../isar/exchange_cache/currency.dart';
1415
import '../isar/exchange_cache/pair.dart';
1516

1617
class AggregateCurrency {
17-
final Map<String, Currency?> _map = {};
18+
final Map<String, Currency> _map = {};
1819

1920
AggregateCurrency({
2021
required List<Tuple2<String, Currency>> exchangeCurrencyPairs,
@@ -32,17 +33,26 @@ class AggregateCurrency {
3233

3334
String? networkFor(String exchangeName) => forExchange(exchangeName)?.network;
3435

35-
String get ticker => _map.values.first!.ticker;
36+
String get ticker => _map.values.first.ticker;
3637

37-
String get name => _map.values.first!.name;
38+
String get name {
39+
if (_map.values.length > 2) {
40+
return _map.values
41+
.firstWhere((e) => e.exchangeName != TrocadorExchange.exchangeName)
42+
.name;
43+
}
44+
45+
// trocador hack
46+
return _map.values.first.name.split(" (Mainnet").first;
47+
}
3848

39-
String get image => _map.values.first!.image;
49+
String get image => _map.values.first.image;
4050

41-
SupportedRateType get rateType => _map.values.first!.rateType;
51+
SupportedRateType get rateType => _map.values.first.rateType;
4252

43-
bool get isStackCoin => _map.values.first!.isStackCoin;
53+
bool get isStackCoin => _map.values.first.isStackCoin;
4454

45-
String get fuzzyNet => _map.values.first!.getFuzzyNet();
55+
String get fuzzyNet => _map.values.first.getFuzzyNet();
4656

4757
@override
4858
String toString() {
@@ -60,11 +70,11 @@ class AggregateCurrency {
6070
other.ticker == ticker &&
6171
other._map.isNotEmpty &&
6272
other._map.length == _map.length &&
63-
other._map.values.first!.getFuzzyNet() ==
64-
_map.values.first!.getFuzzyNet();
73+
other._map.values.first.getFuzzyNet() ==
74+
_map.values.first.getFuzzyNet();
6575
}
6676

6777
@override
6878
int get hashCode =>
69-
Object.hash(ticker, _map.values.first!.getFuzzyNet(), _map.length);
79+
Object.hash(ticker, _map.values.first.getFuzzyNet(), _map.length);
7080
}

lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import '../../../utilities/prefs.dart';
2929
import '../../../utilities/text_styles.dart';
3030
import '../../../utilities/util.dart';
3131
import '../../../widgets/background.dart';
32+
import '../../../widgets/coin_ticker_tag.dart';
3233
import '../../../widgets/conditional_parent.dart';
3334
import '../../../widgets/custom_buttons/app_bar_icon_button.dart';
3435
import '../../../widgets/custom_loading_overlay.dart';
@@ -338,9 +339,8 @@ class _ExchangeCurrencySelectionViewState
338339
primary: isDesktop ? false : null,
339340
itemCount: items.length,
340341
itemBuilder: (builderContext, index) {
341-
final bool hasImageUrl = items[index].image.startsWith(
342-
"http",
343-
);
342+
final image = items[index].image;
343+
final hasImageUrl = image.startsWith("http");
344344
return Padding(
345345
padding: const EdgeInsets.symmetric(vertical: 4),
346346
child: GestureDetector(
@@ -363,18 +363,12 @@ class _ExchangeCurrencySelectionViewState
363363
ticker: items[index].ticker,
364364
size: 24,
365365
)
366-
// ? getIconForTicker(
367-
// items[index].ticker,
368-
// size: 24,
369-
// )
370366
: hasImageUrl
371-
? SvgPicture.network(
372-
items[index].image,
373-
width: 24,
374-
height: 24,
375-
placeholderBuilder:
376-
(_) =>
377-
const LoadingIndicator(),
367+
? _NetImage(
368+
url: image,
369+
key: ValueKey(
370+
image + items[index].fuzzyNet,
371+
),
378372
)
379373
: const SizedBox(
380374
width: 24,
@@ -387,11 +381,29 @@ class _ExchangeCurrencySelectionViewState
387381
crossAxisAlignment:
388382
CrossAxisAlignment.start,
389383
children: [
390-
Text(
391-
items[index].name,
392-
style: STextStyles.largeMedium14(
393-
context,
394-
),
384+
Row(
385+
children: [
386+
Text(
387+
items[index].name,
388+
style: STextStyles.largeMedium14(
389+
context,
390+
),
391+
),
392+
if (items[index].ticker
393+
.toLowerCase() !=
394+
items[index].fuzzyNet
395+
.toLowerCase())
396+
Padding(
397+
padding: const EdgeInsets.only(
398+
left: 12,
399+
),
400+
child: CoinTickerTag(
401+
ticker:
402+
items[index].fuzzyNet
403+
.toUpperCase(),
404+
),
405+
),
406+
],
395407
),
396408
const SizedBox(height: 2),
397409
Text(
@@ -425,3 +437,24 @@ class _ExchangeCurrencySelectionViewState
425437
);
426438
}
427439
}
440+
441+
class _NetImage extends StatelessWidget {
442+
const _NetImage({super.key, required this.url});
443+
444+
final String url;
445+
446+
@override
447+
Widget build(BuildContext context) {
448+
if (url.endsWith(".svg")) {
449+
return SvgPicture.network(
450+
key: key,
451+
url,
452+
width: 24,
453+
height: 24,
454+
placeholderBuilder: (_) => const LoadingIndicator(),
455+
);
456+
} else {
457+
return Image.network(url, width: 24, height: 24, key: key);
458+
}
459+
}
460+
}

lib/pages/exchange_view/exchange_form.dart

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import '../../models/exchange/aggregate_currency.dart';
2222
import '../../models/exchange/incomplete_exchange.dart';
2323
import '../../models/exchange/response_objects/estimate.dart';
2424
import '../../models/exchange/response_objects/range.dart';
25+
import '../../models/isar/exchange_cache/currency.dart';
2526
import '../../models/isar/models/ethereum/eth_contract.dart';
2627
import '../../pages_desktop_specific/desktop_exchange/exchange_steps/step_scaffold.dart';
2728
import '../../providers/providers.dart';
@@ -47,6 +48,7 @@ import '../../widgets/desktop/desktop_dialog.dart';
4748
import '../../widgets/desktop/desktop_dialog_close_button.dart';
4849
import '../../widgets/desktop/primary_button.dart';
4950
import '../../widgets/desktop/secondary_button.dart';
51+
import '../../widgets/dialogs/basic_dialog.dart';
5052
import '../../widgets/rounded_container.dart';
5153
import '../../widgets/rounded_white_container.dart';
5254
import '../../widgets/stack_dialog.dart';
@@ -343,9 +345,80 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
343345
update();
344346
}
345347

348+
Future<bool> _checkTrocadorWarning(Currency from, Currency to) async {
349+
final Set<ProviderWarning> warnings = {};
350+
351+
final firoWarning =
352+
TrocadorExchange.checkFiro(from) ?? TrocadorExchange.checkFiro(to);
353+
final ltcWarning =
354+
TrocadorExchange.checkLtc(from) ?? TrocadorExchange.checkLtc(to);
355+
356+
if (firoWarning != null) warnings.add(firoWarning);
357+
if (ltcWarning != null) warnings.add(ltcWarning);
358+
359+
if (warnings.isNotEmpty) {
360+
final title = warnings.map((e) => e.message).join(" and ");
361+
final message = warnings.map((e) => e.messageDetail).join(" ");
362+
363+
final result = await showDialog<bool>(
364+
context: context,
365+
builder: (context) {
366+
return BasicDialog(
367+
title: title,
368+
message: message,
369+
canPopWithBackButton: true,
370+
flex: true,
371+
desktopHeight: 400,
372+
leftButton: SecondaryButton(
373+
label: "Cancel",
374+
buttonHeight: isDesktop ? ButtonHeight.l : null,
375+
onPressed: () => Navigator.of(context).pop(false),
376+
),
377+
rightButton: PrimaryButton(
378+
label: "Continue",
379+
buttonHeight: isDesktop ? ButtonHeight.l : null,
380+
onPressed: () => Navigator.of(context).pop(true),
381+
),
382+
);
383+
},
384+
);
385+
386+
return result == true;
387+
} else {
388+
return true;
389+
}
390+
}
391+
346392
void onExchangePressed() async {
347393
final exchangeName = ref.read(efExchangeProvider).name;
348394

395+
final fromCurrency = ref
396+
.read(efCurrencyPairProvider)
397+
.send
398+
?.forExchange(exchangeName);
399+
final toCurrency = ref
400+
.read(efCurrencyPairProvider)
401+
.receive
402+
?.forExchange(exchangeName);
403+
404+
if (fromCurrency == null || toCurrency == null) {
405+
await showDialog<void>(
406+
context: context,
407+
builder:
408+
(context) => const StackOkDialog(
409+
title: "Missing currency!",
410+
message: "This should not happen. Please contact support",
411+
),
412+
);
413+
414+
return;
415+
}
416+
417+
if (exchangeName == TrocadorExchange.exchangeName) {
418+
final canContinue = await _checkTrocadorWarning(fromCurrency, toCurrency);
419+
if (!canContinue) return;
420+
}
421+
349422
final rateType = ref.read(efRateTypeProvider);
350423
final fromTicker = ref.read(efCurrencyPairProvider).send?.ticker ?? "";
351424
final fromNetwork = ref
@@ -361,15 +434,17 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
361434
final sendAmount = ref.read(efSendAmountProvider)!;
362435

363436
if (rateType == ExchangeRateType.fixed && toTicker.toUpperCase() == "WOW") {
364-
await showDialog<void>(
365-
context: context,
366-
builder:
367-
(context) => const StackOkDialog(
368-
title: "WOW error",
369-
message:
370-
"Wownero is temporarily disabled as a receiving currency for fixed rate trades due to network issues",
371-
),
372-
);
437+
if (mounted) {
438+
await showDialog<void>(
439+
context: context,
440+
builder:
441+
(context) => const StackOkDialog(
442+
title: "WOW error",
443+
message:
444+
"Wownero is temporarily disabled as a receiving currency for fixed rate trades due to network issues",
445+
),
446+
);
447+
}
373448

374449
return;
375450
}

0 commit comments

Comments
 (0)