Skip to content

Commit 88931fa

Browse files
committed
Merge remote-tracking branch 'origin/staging' into salvium
# Conflicts: # lib/pages/settings_views/wallet_settings_view/wallet_settings_view.dart # lib/pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/wallet_settings_wallet_settings_view.dart
2 parents aaac3e7 + 219164d commit 88931fa

File tree

126 files changed

+18518
-18827
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+18518
-18827
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/app_config.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import 'wallets/crypto_currency/intermediate/frost_currency.dart';
33

44
part 'app_config.g.dart';
55

6-
enum AppFeature {
7-
themeSelection,
8-
buy,
9-
swap;
10-
}
6+
enum AppFeature { themeSelection, buy, swap }
117

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

2824
static List<CryptoCurrency> get coins => _supportedCoins;
2925

30-
static ({String from, String to}) get swapDefaults => _swapDefaults;
26+
static ({String from, String fromFuzzyNet, String to, String toFuzzyNet})
27+
get swapDefaults => _swapDefaults;
3128

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

@@ -75,7 +72,13 @@ abstract class AppConfig {
7572
/// Fuzzy logic. Use with caution!!
7673
@Deprecated("dangerous")
7774
static CryptoCurrency getCryptoCurrencyByPrettyName(final String prettyName) {
78-
final name = prettyName.replaceAll(" ", "").toLowerCase();
75+
// trocador hack
76+
const hackSplitter = " (Mainnet";
77+
final name =
78+
prettyName.contains(hackSplitter)
79+
? prettyName.split(hackSplitter).first.toLowerCase()
80+
: prettyName.replaceAll(" ", "").toLowerCase();
81+
7982
try {
8083
return coins.firstWhere(
8184
(e) => e.identifier.toLowerCase() == name || e.prettyName == prettyName,

lib/models/exchange/aggregate_currency.dart

Lines changed: 34 additions & 8 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,23 +33,48 @@ 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;
54+
55+
String get fuzzyNet => _map.values.first.getFuzzyNet();
4456

4557
@override
4658
String toString() {
4759
String str = "AggregateCurrency: {";
4860
for (final key in _map.keys) {
49-
str += " $key: ${_map[key]},";
61+
str += "\n $key: ${_map[key]},";
5062
}
51-
str += " }";
63+
str += "\n}";
5264
return str;
5365
}
66+
67+
@override
68+
bool operator ==(Object other) {
69+
return other is AggregateCurrency &&
70+
other.ticker == ticker &&
71+
other._map.isNotEmpty &&
72+
other._map.length == _map.length &&
73+
other._map.values.first.getFuzzyNet() ==
74+
_map.values.first.getFuzzyNet();
75+
}
76+
77+
@override
78+
int get hashCode =>
79+
Object.hash(ticker, _map.values.first.getFuzzyNet(), _map.length);
5480
}

lib/models/exchange/change_now/estimated_exchange_amount.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class EstimatedExchangeAmount {
2929
final String? rateId;
3030

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

3434
/// Dash-separated min and max estimated time in minutes.
3535
final String? transactionSpeedForecast;
@@ -87,7 +87,7 @@ class EstimatedExchangeAmount {
8787
flow: _parseFlow(json["flow"] as String),
8888
type: _parseType(json["type"] as String),
8989
rateId: json["rateId"] as String?,
90-
validUntil: DateTime.parse(json["validUntil"] as String),
90+
validUntil: DateTime.tryParse(json["validUntil"] as String? ?? ""),
9191
transactionSpeedForecast: json["transactionSpeedForecast"] as String?,
9292
warningMessage: json["warningMessage"] as String?,
9393
depositFee: Decimal.parse(json["depositFee"].toString()),
@@ -108,7 +108,7 @@ class EstimatedExchangeAmount {
108108
"flow": flow.name.replaceAll("fixedRate", "fixed-rate"),
109109
"type": type.name,
110110
"rateId": rateId,
111-
"validUntil": validUntil.toIso8601String(),
111+
"validUntil": validUntil?.toIso8601String(),
112112
"transactionSpeedForecast": transactionSpeedForecast,
113113
"warningMessage": warningMessage,
114114
"depositFee": depositFee.toString(),

lib/models/exchange/incomplete_exchange.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ import 'package:decimal/decimal.dart';
1212
import 'package:flutter/foundation.dart';
1313

1414
import '../../utilities/enums/exchange_rate_type_enum.dart';
15+
import '../isar/exchange_cache/currency.dart';
1516
import 'response_objects/estimate.dart';
1617
import 'response_objects/trade.dart';
1718

1819
class IncompleteExchangeModel extends ChangeNotifier {
19-
final String sendTicker;
20-
final String? sendNetwork;
21-
final String receiveTicker;
22-
final String? receiveNetwork;
20+
final Currency sendCurrency;
21+
final Currency receiveCurrency;
22+
23+
String get sendTicker => sendCurrency.ticker;
24+
String get receiveTicker => receiveCurrency.ticker;
2325

2426
final String rateInfo;
2527

@@ -76,16 +78,15 @@ class IncompleteExchangeModel extends ChangeNotifier {
7678
}
7779

7880
IncompleteExchangeModel({
79-
required this.sendTicker,
80-
required this.sendNetwork,
81-
required this.receiveTicker,
82-
required this.receiveNetwork,
81+
required this.sendCurrency,
82+
required this.receiveCurrency,
8383
required this.rateInfo,
8484
required this.sendAmount,
8585
required this.receiveAmount,
8686
required this.rateType,
8787
required this.reversed,
8888
required this.walletInitiated,
8989
Estimate? estimate,
90-
}) : _estimate = estimate;
90+
}) : _estimate = estimate,
91+
assert(sendCurrency.exchangeName == receiveCurrency.exchangeName);
9192
}

lib/models/isar/exchange_cache/currency.dart

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
import 'package:isar/isar.dart';
1212

1313
import '../../../app_config.dart';
14+
import '../../../services/exchange/change_now/change_now_exchange.dart';
15+
import '../../../services/exchange/exchange.dart';
16+
import '../../../services/exchange/majestic_bank/majestic_bank_exchange.dart';
17+
import '../../../services/exchange/nanswap/nanswap_exchange.dart';
18+
import '../../../services/exchange/trocador/trocador_exchange.dart';
1419
import 'pair.dart';
1520

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

2530
/// Currency ticker
26-
@Index(
27-
composite: [
28-
CompositeIndex("exchangeName"),
29-
CompositeIndex("name"),
30-
],
31-
)
31+
@Index(composite: [CompositeIndex("exchangeName"), CompositeIndex("name")])
3232
final String ticker;
3333

3434
/// Currency name
@@ -68,6 +68,33 @@ class Currency {
6868
rateType == SupportedRateType.estimated ||
6969
rateType == SupportedRateType.both;
7070

71+
// used to group coins across providers
72+
@ignore
73+
String? _fuzzyCache;
74+
String getFuzzyNet() {
75+
return _fuzzyCache ??= switch (Exchange.fromName(
76+
exchangeName,
77+
).runtimeType) {
78+
// already lower case ticker basically
79+
const (ChangeNowExchange) => network,
80+
81+
// not used at the time being
82+
// case const (SimpleSwapExchange):
83+
84+
// currently a hardcoded of coins so we can just
85+
const (MajesticBankExchange) => ticker.toLowerCase(),
86+
87+
const (TrocadorExchange) =>
88+
(network == "Mainnet" ? ticker.toLowerCase() : network),
89+
90+
// only a few coins and `network` is the ticker
91+
const (NanswapExchange) =>
92+
network.isNotEmpty ? network.toLowerCase() : ticker.toLowerCase(),
93+
94+
_ => throw Exception("Unknown exchange: $exchangeName"),
95+
};
96+
}
97+
7198
Currency({
7299
required this.exchangeName,
73100
required this.ticker,

0 commit comments

Comments
 (0)