Skip to content
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

[RC] 0.9.1: Chart & Order Book Fixes + Sync assets #123

Merged
merged 34 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3726ca9
delist THC and THC-BEP20
naezith Jan 25, 2024
c88469d
update coins hash
naezith Jan 25, 2024
5bc4c7b
sync aibc, boli and coin configs
naezith Jan 25, 2024
31a393f
Merge pull request #103 from KomodoPlatform/delist-thc
ca333 Jan 29, 2024
10a6a74
Migrate BestOrders to mmrpc 2.0 (#110)
takenagain Jan 31, 2024
8f5bd63
Add Binance API provider and repository
takenagain Feb 8, 2024
8e34f0a
Update coins (#112)
takenagain Feb 9, 2024
928df5b
Replace tickers and chart updating with Binance repository
takenagain Feb 10, 2024
5c1414e
Fix candlestick chart zoom and scaling
takenagain Feb 11, 2024
e0f7fa0
Fix year text on timescale
takenagain Feb 11, 2024
6ee700b
Fix candlestick scrolling
takenagain Feb 12, 2024
f199bd2
Add comments and remove unused imports
takenagain Feb 12, 2024
277633f
Reduce candlestick scroll speed
takenagain Feb 12, 2024
93c39d5
Fix candlestick hitching after zoom change
takenagain Feb 12, 2024
2bd4051
Improve candlestick chart performance
takenagain Feb 13, 2024
7cf49c2
Fix zoom timescale shift
takenagain Feb 14, 2024
b0fede2
Fix circular provider updates, limit zoom and refactor
takenagain Feb 14, 2024
0941141
Reduce rebuilds of `BuildCoinPriceListItem`
takenagain Feb 15, 2024
5d1fe0c
Remove `Listener` in `CandleChart`
takenagain Feb 15, 2024
b03df89
Limit tickers to actively traded symbols on Binance
takenagain Feb 15, 2024
c020221
Revert: Remove `Listener` in `CandleChart`
takenagain Feb 15, 2024
a295d2c
Update comments & paint method cleanup cont.
takenagain Feb 16, 2024
0b3d3c8
Display time axis in local time
takenagain Feb 16, 2024
a96b8b4
Merge branch 'dev' into fix/candlestick-data-source
CharlVS Feb 27, 2024
1273573
Fix advanced order book showing incorrect values
takenagain Feb 27, 2024
d7e8737
Fix order book incorrect received amount
takenagain Feb 27, 2024
47fece1
Merge pull request #117 from KomodoPlatform/fix/candlestick-data-source
CharlVS Feb 29, 2024
571a223
Merge pull request #119 from KomodoPlatform/fix/advanced-orderbook-va…
CharlVS Mar 6, 2024
3dffc55
Remove prefix from QR code scans (#121)
takenagain Apr 4, 2024
94a94db
Sync coin assets & bump release version (#122)
takenagain Apr 27, 2024
983a5fa
Revert "Merge pull request #103 from KomodoPlatform/delist-thc"
CharlVS Apr 27, 2024
d68437b
Add vote coin color
CharlVS Apr 27, 2024
e4b06c7
Merge branch 'fix/add-vote-coin-color' into dev
CharlVS Apr 27, 2024
66471b9
Fix order book infinite loading (#125)
takenagain Apr 29, 2024
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
Binary file added assets/coin-icons/aibc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/aipg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/coin-icons/chungus.png
Binary file not shown.
Binary file added assets/coin-icons/clam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/crt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/dpc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/coin-icons/ic.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/kip0003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/kip0004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/coin-icons/ltfn.png
Binary file not shown.
Binary file added assets/coin-icons/mewc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/minu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/coin-icons/nftx.png
Binary file not shown.
Binary file removed assets/coin-icons/pic.png
Binary file not shown.
Binary file added assets/coin-icons/rtb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/coin-icons/space.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/space_avx20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/space_bep20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/space_ftm20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/space_plg20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/spacecoin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/taz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/coin-icons/tbtc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/testbtc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/coin-icons/varrr.png
Binary file added assets/coin-icons/vote2024.png
Binary file added assets/coin-icons/waf.png
496 changes: 468 additions & 28 deletions assets/coins.json

Large diffs are not rendered by default.

8,176 changes: 6,410 additions & 1,766 deletions assets/coins_config.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion coins_ci.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"coins_repo_commit": "c360d9b2e0545fe601b62651728c638687bb0829"
"coins_repo_commit": "9be500c8bf665861a07002ea67de234a290c7748"
}
49 changes: 15 additions & 34 deletions lib/app_config/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,45 +53,26 @@ class AppConfig {
List<String> get walletOnlyCoins => [
'ARRR-BEP20',
'ATOM',
'RBTC',
'OSMO',
'BET',
'BOTS',
'BBK',
'CELR-ARB20',
'CRYPTO',
'HODL',
'JUMBLR',
'LUNA-ERC20',
'LUNA-BEP20',
'LUNA-HRC20',
'LUNA-PLG20',
'MSHARK',
'GALA-BEP20',
'KIP0002',
'KIP0003',
'KIP0004',
'MINU-BEP20',
'NVC',
'OSMO',
'PAXG-ERC20',
'ETH-ARB20',
'ETHK-OPT20',
'ETHR-ARB20',
'PINK',
'POT',
'RBTC',
'RDD',
'SXP-BEP20',
'SXP-ERC20',
'USDT-ARB20',
'USDT-ERC20',
'MGW',
'DEX',
'PANGEA',
'REVS',
'SUPERNET',
'NVC',
'UST-ERC20',
'UST-BEP20',
'UST-HRC20',
'UST-PLG20',
'XPM',
'XVC-OLD',
'SXP-BEP20',
'VOTE2023',
'GALA-BEP20',
'SXP-ERC20',
'BBK',
'RDD',
'PINK',
'POT'
'XPM',
];

List<String> get protocolSuffixes => [
Expand Down
4 changes: 4 additions & 0 deletions lib/app_config/coin_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ String _getColor(String coin) {
'ADA': '#214D78',
'ADX': '#1B75BC',
'AGIX': '#6815FF',
'AIBC': '#FFC745',
'ANKR': '#2075E8',
'ANT': '#33DAE6',
'APE': '#0052F2',
Expand All @@ -155,6 +156,7 @@ String _getColor(String coin) {
'BLK': '#595959',
'BNB': '#F9D987',
'BNBT': '#F9D987',
'BOLI': '#F09E40',
'BNT': '#0000FF',
'BOTS': '#F69B57',
'BRZ': '#B5DEC3',
Expand Down Expand Up @@ -357,6 +359,8 @@ String _getColor(String coin) {
'VET': '#18C6FF',
'VITE': '#007AFF',
'VOTE2022': '#7490AA',
'VOTE2023': '#7490AA',
'VOTE2024': '#7490AA',
'VRA': '#D70A41',
'VRM': '#586A7A',
'VRSC': '#3164D3',
Expand Down
28 changes: 20 additions & 8 deletions lib/model/best_order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ class BestOrders {
if (json['result'] == null) return bestOrders;

final Market action = bestOrders.request.action;
final Map<String, dynamic> result = json['result'];
final Map<String, dynamic> resultOrders =
result['orders'] as Map<String, dynamic>;

json['result'].forEach((String ticker, dynamic items) {
resultOrders.forEach((String ticker, dynamic items) {
bestOrders.result ??= {};
final List<BestOrder> list = [];
for (dynamic item in items) {
for (final Map<String, dynamic> item in items) {
item['action'] = action;
item['other_coin'] =
action == Market.SELL ? bestOrders.request.coin : ticker;
Expand Down Expand Up @@ -45,15 +48,24 @@ class BestOrder {
});

factory BestOrder.fromJson(Map<String, dynamic> json) {
final Map<String, dynamic> price = json['price'];
final Map<String, dynamic> address = json['address'];

// base_ max and min volume are used, as the base and rel coins are swapped
// for buy and sell orders, so the max volume is always the max volume of
// the base coin. The web wallet has a similar implementation.
final Map<String, dynamic> maxVolume = json['base_max_volume'];
final Map<String, dynamic> minVolume = json['base_min_volume'];

return BestOrder(
price: fract2rat(json['price_fraction']) ?? Rational.parse(json['price']),
maxVolume: fract2rat(json['max_volume_fraction']) ??
Rational.parse(json['maxvolume']),
minVolume: fract2rat(json['min_volume_fraction']) ??
Rational.parse(json['min_volume']),
price: fract2rat(price['fraction']) ?? Rational.parse(price['decimal']),
maxVolume: fract2rat(maxVolume['fraction']) ??
Rational.parse(maxVolume['decimal']),
minVolume: fract2rat(minVolume['fraction']) ??
Rational.parse(minVolume['decimal']),
coin: json['coin'],
otherCoin: json['other_coin'],
address: json['address'],
address: address['address_data'],
action: json['action'],
);
}
Expand Down
124 changes: 51 additions & 73 deletions lib/model/cex_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:intl/intl.dart';
import 'package:komodo_dex/blocs/coins_bloc.dart';
import 'package:komodo_dex/packages/binance_candlestick_charts/bloc/binance_repository.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../app_config/app_config.dart';
Expand Down Expand Up @@ -87,56 +88,38 @@ class CexProvider extends ChangeNotifier {
cexPrices.unlinkProvider(this);
}

final String _chartsUrl = appConfig.candlestickData;
final Uri _tickersListUrl = Uri.parse(appConfig.candlestickTickersList);
final Map<String, ChartData> _charts = {}; // {'BTC-USD': ChartData(),}
final Map<String, ChartData> _charts = {};
bool _updatingChart = false;
List<String> _tickers;
final BinanceRepository _binanceRepository = BinanceRepository();

void _updateRates() => cexPrices.updateRates();

List<String> _getTickers() {
if (_tickers != null) return _tickers;
if (_tickers != null) {
return _tickers;
}

_updateTickersList();
return _tickersFallBack;
}

Future<void> _updateTickersList() async {
http.Response _res;
String _body;
try {
_res = await http.get(_tickersListUrl).timeout(
const Duration(seconds: 60),
onTimeout: () {
Log('cex_provider', 'Fetching tickers timed out');
return;
},
);
_body = _res.body;
_tickers = await _binanceRepository.getLegacyTickers();
notifyListeners();
} catch (e) {
Log('cex_provider', 'Failed to fetch tickers list: $e');
}

List<dynamic> json;
try {
json = jsonDecode(_body);
} catch (e) {
Log('cex_provider', 'Failed to parse tickers json: $e');
}

if (json != null) {
_tickers =
json.map<String>((dynamic ticker) => ticker.toString()).toList();
notifyListeners();
}
}

Future<void> _updateChart(String pair) async {
if (_updatingChart) return;

final List<ChainLink> chain = _findChain(pair);
if (chain == null) throw 'No chart data available';
if (chain == null) {
throw 'No chart data available';
}

Map<String, dynamic> json0;
Map<String, dynamic> json1;
Expand Down Expand Up @@ -178,7 +161,7 @@ class CexProvider extends ChangeNotifier {
json0.forEach((String duration, dynamic list) {
final List<CandleData> _durationData = [];

for (var candle in list) {
for (final Map<String, dynamic> candle in list) {
double open = chain[0].reverse
? 1 / candle['open'].toDouble()
: candle['open'].toDouble();
Expand Down Expand Up @@ -248,7 +231,6 @@ class CexProvider extends ChangeNotifier {
}

data[duration] = _durationData;
notifyListeners();
});

_charts[pair] = ChartData(
Expand All @@ -258,79 +240,69 @@ class CexProvider extends ChangeNotifier {
status: ChartStatus.success,
updated: DateTime.now().millisecondsSinceEpoch,
);

notifyListeners();
}

Future<Map<String, dynamic>> _fetchChartData(ChainLink link) async {
final String pair = '${link.rel}-${link.base}';
http.Response _res;
String _body;
try {
_res = await http
.get(Uri.parse('$_chartsUrl/${pair.toLowerCase()}'))
.timeout(
const Duration(seconds: 60),
onTimeout: () {
Log('cex_provider', 'Fetching $pair data timed out');
throw 'Fetching $pair timed out';
},
);
_body = _res.body;
final String pair = '${link.rel}-${link.base}';
final Map<String, dynamic> result =
await _binanceRepository.getLegacyOhlcCandleData(pair);
return result;
} catch (e) {
Log('cex_provider', 'Failed to fetch data: $e');
rethrow;
}

Map<String, dynamic> json;
try {
json = jsonDecode(_body);
} catch (e) {
Log('cex_provider', 'Failed to parse json: $e');
rethrow;
}

return json;
}

List<ChainLink> _findChain(String pair) {
// remove cex postfixes
pair = getCoinTickerRegex(pair);

final List<String> abbr = pair.split('-');
if (abbr[0] == abbr[1]) return null;
if (abbr[0] == abbr[1]) {
return null;
}
final String base = abbr[1].toLowerCase();
final String rel = abbr[0].toLowerCase();
final List<String> tickers = _getTickers();
List<ChainLink> chain;

if (tickers == null) return null;
if (tickers == null) {
return null;
}

// try to find simple chain, direct or reverse
for (String ticker in tickers) {
for (final String ticker in tickers) {
final List<String> availableAbbr = ticker.split('-');
if (!(availableAbbr.contains(rel) && availableAbbr.contains(base))) {
continue;
}

chain = [
ChainLink(
rel: availableAbbr[0],
base: availableAbbr[1],
reverse: availableAbbr[0] != rel,
)
];
break;
}

if (chain != null) return chain;
if (chain != null) {
return chain;
}

tickers.sort((String a, String b) {
if (a.toLowerCase().contains('btc') && !b.toLowerCase().contains('btc'))
if (a.toLowerCase().contains('btc') && !b.toLowerCase().contains('btc')) {
return -1;
if (b.toLowerCase().contains('btc') && !a.toLowerCase().contains('btc'))
}
if (b.toLowerCase().contains('btc') && !a.toLowerCase().contains('btc')) {
return 1;
}
return 0;
});

OUTER:
for (String firstLinkStr in tickers) {
for (final String firstLinkStr in tickers) {
final List<String> firstLinkCoins = firstLinkStr.split('-');
if (!firstLinkCoins.contains(rel) && !firstLinkCoins.contains(base)) {
continue;
Expand All @@ -344,7 +316,7 @@ class CexProvider extends ChangeNotifier {
firstLink.reverse ? firstLink.rel : firstLink.base;
final String secondBase = firstLinkCoins.contains(rel) ? base : rel;

for (String secondLink in tickers) {
for (final String secondLink in tickers) {
final List<String> secondLinkCoins = secondLink.split('-');
if (!(secondLinkCoins.contains(secondRel) &&
secondLinkCoins.contains(secondBase))) {
Expand All @@ -364,7 +336,9 @@ class CexProvider extends ChangeNotifier {
}
}

if (chain != null) return chain;
if (chain != null) {
return chain;
}

return null;
}
Expand Down Expand Up @@ -649,16 +623,18 @@ class CexPrices {
// Some coins are presented in multiple networks,
// like BAT-ERC20 and BAT-BEP20, but have same
// coingeckoId and same usd price
final List<Coin> coins =
(allCoins.where((coin) => getCoinTicker(coin.abbr) == ticker) ?? [])
.toList();
final List<Coin> coins = (allCoins.where(
(Coin coin) => getCoinTickerRegex(coin.abbr) == ticker,
) ??
[])
.toList();

// check if coin volume is enough
double minVolume = 10000;
double lastPrice = double.tryParse(pricesData['last_price']) ?? 0;
double volume24h = double.tryParse(pricesData['volume24h']) ?? 0;
const double minVolume = 10000;
final double lastPrice = double.tryParse(pricesData['last_price']) ?? 0;
final double volume24h = double.tryParse(pricesData['volume24h']) ?? 0;

for (Coin coin in coins) {
for (final Coin coin in coins) {
final String coinAbbr = coin.abbr;
if (coin.type == CoinType.smartChain) {
// enough_volume for all smartChain tokens is always true :. proceed
Expand Down Expand Up @@ -769,7 +745,9 @@ class CexPrices {
}

void _notifyListeners() {
for (CexProvider provider in _providers) provider.notify();
for (final CexProvider provider in _providers) {
provider.notify();
}
}
}

Expand Down
Loading
Loading