Skip to content

Uee SafeArea and swap currency selection fixes #1143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ scripts/linux/build/libsecret/subprojects/gi-docgen/.meson-subproject-wrap-hash.
crypto_plugins/cs_monero/built_outputs
crypto_plugins/cs_monero/build
crypto_plugins/*.diff
/devtools_options.yaml
17 changes: 10 additions & 7 deletions lib/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import 'wallets/crypto_currency/intermediate/frost_currency.dart';

part 'app_config.g.dart';

enum AppFeature {
themeSelection,
buy,
swap;
}
enum AppFeature { themeSelection, buy, swap }

abstract class AppConfig {
static const appName = _prefix + _separator + suffix;
Expand All @@ -27,7 +23,8 @@ abstract class AppConfig {

static List<CryptoCurrency> get coins => _supportedCoins;

static ({String from, String to}) get swapDefaults => _swapDefaults;
static ({String from, String fromFuzzyNet, String to, String toFuzzyNet})
get swapDefaults => _swapDefaults;

static bool get isSingleCoinApp => coins.length == 1;

Expand Down Expand Up @@ -75,7 +72,13 @@ abstract class AppConfig {
/// Fuzzy logic. Use with caution!!
@Deprecated("dangerous")
static CryptoCurrency getCryptoCurrencyByPrettyName(final String prettyName) {
final name = prettyName.replaceAll(" ", "").toLowerCase();
// trocador hack
const hackSplitter = " (Mainnet";
final name =
prettyName.contains(hackSplitter)
? prettyName.split(hackSplitter).first.toLowerCase()
: prettyName.replaceAll(" ", "").toLowerCase();

try {
return coins.firstWhere(
(e) => e.identifier.toLowerCase() == name || e.prettyName == prettyName,
Expand Down
42 changes: 34 additions & 8 deletions lib/models/exchange/aggregate_currency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

import 'package:tuple/tuple.dart';

import '../../services/exchange/trocador/trocador_exchange.dart';
import '../isar/exchange_cache/currency.dart';
import '../isar/exchange_cache/pair.dart';

class AggregateCurrency {
final Map<String, Currency?> _map = {};
final Map<String, Currency> _map = {};

AggregateCurrency({
required List<Tuple2<String, Currency>> exchangeCurrencyPairs,
Expand All @@ -32,23 +33,48 @@ class AggregateCurrency {

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

String get ticker => _map.values.first!.ticker;
String get ticker => _map.values.first.ticker;

String get name => _map.values.first!.name;
String get name {
if (_map.values.length > 2) {
return _map.values
.firstWhere((e) => e.exchangeName != TrocadorExchange.exchangeName)
.name;
}

// trocador hack
return _map.values.first.name.split(" (Mainnet").first;
}

String get image => _map.values.first!.image;
String get image => _map.values.first.image;

SupportedRateType get rateType => _map.values.first!.rateType;
SupportedRateType get rateType => _map.values.first.rateType;

bool get isStackCoin => _map.values.first!.isStackCoin;
bool get isStackCoin => _map.values.first.isStackCoin;

String get fuzzyNet => _map.values.first.getFuzzyNet();

@override
String toString() {
String str = "AggregateCurrency: {";
for (final key in _map.keys) {
str += " $key: ${_map[key]},";
str += "\n $key: ${_map[key]},";
}
str += " }";
str += "\n}";
return str;
}

@override
bool operator ==(Object other) {
return other is AggregateCurrency &&
other.ticker == ticker &&
other._map.isNotEmpty &&
other._map.length == _map.length &&
other._map.values.first.getFuzzyNet() ==
_map.values.first.getFuzzyNet();
}

@override
int get hashCode =>
Object.hash(ticker, _map.values.first.getFuzzyNet(), _map.length);
}
6 changes: 3 additions & 3 deletions lib/models/exchange/change_now/estimated_exchange_amount.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EstimatedExchangeAmount {
final String? rateId;

/// Date and time before which the estimated amount is valid if using `rateId`.
final DateTime validUntil;
final DateTime? validUntil;

/// Dash-separated min and max estimated time in minutes.
final String? transactionSpeedForecast;
Expand Down Expand Up @@ -87,7 +87,7 @@ class EstimatedExchangeAmount {
flow: _parseFlow(json["flow"] as String),
type: _parseType(json["type"] as String),
rateId: json["rateId"] as String?,
validUntil: DateTime.parse(json["validUntil"] as String),
validUntil: DateTime.tryParse(json["validUntil"] as String? ?? ""),
transactionSpeedForecast: json["transactionSpeedForecast"] as String?,
warningMessage: json["warningMessage"] as String?,
depositFee: Decimal.parse(json["depositFee"].toString()),
Expand All @@ -108,7 +108,7 @@ class EstimatedExchangeAmount {
"flow": flow.name.replaceAll("fixedRate", "fixed-rate"),
"type": type.name,
"rateId": rateId,
"validUntil": validUntil.toIso8601String(),
"validUntil": validUntil?.toIso8601String(),
"transactionSpeedForecast": transactionSpeedForecast,
"warningMessage": warningMessage,
"depositFee": depositFee.toString(),
Expand Down
19 changes: 10 additions & 9 deletions lib/models/exchange/incomplete_exchange.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import 'package:decimal/decimal.dart';
import 'package:flutter/foundation.dart';

import '../../utilities/enums/exchange_rate_type_enum.dart';
import '../isar/exchange_cache/currency.dart';
import 'response_objects/estimate.dart';
import 'response_objects/trade.dart';

class IncompleteExchangeModel extends ChangeNotifier {
final String sendTicker;
final String? sendNetwork;
final String receiveTicker;
final String? receiveNetwork;
final Currency sendCurrency;
final Currency receiveCurrency;

String get sendTicker => sendCurrency.ticker;
String get receiveTicker => receiveCurrency.ticker;

final String rateInfo;

Expand Down Expand Up @@ -76,16 +78,15 @@ class IncompleteExchangeModel extends ChangeNotifier {
}

IncompleteExchangeModel({
required this.sendTicker,
required this.sendNetwork,
required this.receiveTicker,
required this.receiveNetwork,
required this.sendCurrency,
required this.receiveCurrency,
required this.rateInfo,
required this.sendAmount,
required this.receiveAmount,
required this.rateType,
required this.reversed,
required this.walletInitiated,
Estimate? estimate,
}) : _estimate = estimate;
}) : _estimate = estimate,
assert(sendCurrency.exchangeName == receiveCurrency.exchangeName);
}
39 changes: 33 additions & 6 deletions lib/models/isar/exchange_cache/currency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import 'package:isar/isar.dart';

import '../../../app_config.dart';
import '../../../services/exchange/change_now/change_now_exchange.dart';
import '../../../services/exchange/exchange.dart';
import '../../../services/exchange/majestic_bank/majestic_bank_exchange.dart';
import '../../../services/exchange/nanswap/nanswap_exchange.dart';
import '../../../services/exchange/trocador/trocador_exchange.dart';
import 'pair.dart';

part 'currency.g.dart';
Expand All @@ -23,12 +28,7 @@ class Currency {
final String exchangeName;

/// Currency ticker
@Index(
composite: [
CompositeIndex("exchangeName"),
CompositeIndex("name"),
],
)
@Index(composite: [CompositeIndex("exchangeName"), CompositeIndex("name")])
final String ticker;

/// Currency name
Expand Down Expand Up @@ -68,6 +68,33 @@ class Currency {
rateType == SupportedRateType.estimated ||
rateType == SupportedRateType.both;

// used to group coins across providers
@ignore
String? _fuzzyCache;
String getFuzzyNet() {
return _fuzzyCache ??= switch (Exchange.fromName(
exchangeName,
).runtimeType) {
// already lower case ticker basically
const (ChangeNowExchange) => network,

// not used at the time being
// case const (SimpleSwapExchange):

// currently a hardcoded of coins so we can just
const (MajesticBankExchange) => ticker.toLowerCase(),

const (TrocadorExchange) =>
(network == "Mainnet" ? ticker.toLowerCase() : network),

// only a few coins and `network` is the ticker
const (NanswapExchange) =>
network.isNotEmpty ? network.toLowerCase() : ticker.toLowerCase(),

_ => throw Exception("Unknown exchange: $exchangeName"),
};
}

Currency({
required this.exchangeName,
required this.ticker,
Expand Down
Loading
Loading