From 7e66d3524b468437317f15ecd47a64ba5714cb13 Mon Sep 17 00:00:00 2001 From: Serhii Date: Sun, 10 Mar 2024 13:50:44 +0200 Subject: [PATCH] review comments + transaction filter item --- cw_core/lib/amount_converter.dart | 1 + lib/di.dart | 3 -- lib/entities/preferences_key.dart | 1 - .../exchange_provider_description.dart | 8 ++-- .../provider/thorchain_exchange.provider.dart | 22 +++++++---- .../dashboard/widgets/filter_tile.dart | 2 +- .../exchange_trade/exchange_trade_page.dart | 1 - lib/store/dashboard/trade_filter_store.dart | 39 ++++++++++++------- .../dashboard/dashboard_view_model.dart | 5 +++ 9 files changed, 52 insertions(+), 30 deletions(-) diff --git a/cw_core/lib/amount_converter.dart b/cw_core/lib/amount_converter.dart index 6fd43dd82..249b87bd3 100644 --- a/cw_core/lib/amount_converter.dart +++ b/cw_core/lib/amount_converter.dart @@ -81,6 +81,7 @@ class AmountConverter { return _moneroAmountToString(amount); case CryptoCurrency.btc: case CryptoCurrency.bch: + case CryptoCurrency.ltc: return _bitcoinAmountToString(amount); case CryptoCurrency.xhv: case CryptoCurrency.xag: diff --git a/lib/di.dart b/lib/di.dart index 6f5535c5e..473eaed00 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -232,7 +232,6 @@ import 'package:cake_wallet/entities/qr_view_data.dart'; import 'buy/dfx/dfx_buy_provider.dart'; import 'core/totp_request_details.dart'; -import 'exchange/provider/thorchain_exchange.provider.dart'; import 'src/screens/settings/desktop_settings/desktop_settings_page.dart'; final getIt = GetIt.instance; @@ -1196,7 +1195,5 @@ Future setup({ getIt.registerFactory(() => NFTViewModel(appStore, getIt.get())); getIt.registerFactory(() => TorPage(getIt.get())); - getIt.registerFactory(() => ThorChainExchangeProvider(tradesStore: tradesSource)); - _isSetupFinished = true; } diff --git a/lib/entities/preferences_key.dart b/lib/entities/preferences_key.dart index 3ef133e19..0dd251aaa 100644 --- a/lib/entities/preferences_key.dart +++ b/lib/entities/preferences_key.dart @@ -72,5 +72,4 @@ class PreferencesKey { static const lastSeenAppVersion = 'last_seen_app_version'; static const shouldShowMarketPlaceInDashboard = 'should_show_marketplace_in_dashboard'; static const isNewInstall = 'is_new_install'; - static const thorChainTradeCounter = 'thor_chain_trade_counter'; } diff --git a/lib/exchange/exchange_provider_description.dart b/lib/exchange/exchange_provider_description.dart index fab35537a..4d9691035 100644 --- a/lib/exchange/exchange_provider_description.dart +++ b/lib/exchange/exchange_provider_description.dart @@ -23,9 +23,9 @@ class ExchangeProviderDescription extends EnumerableItem with Serializable< static const exolix = ExchangeProviderDescription(title: 'Exolix', raw: 6, image: 'assets/images/exolix.png'); static const thorChain = - ExchangeProviderDescription(title: 'ThorChain' , raw: 7, image: 'assets/images/thorchain.png'); + ExchangeProviderDescription(title: 'ThorChain' , raw: 8, image: 'assets/images/thorchain.png'); - static const all = ExchangeProviderDescription(title: 'All trades', raw: 8, image: ''); + static const all = ExchangeProviderDescription(title: 'All trades', raw: 7, image: ''); static ExchangeProviderDescription deserialize({required int raw}) { switch (raw) { @@ -43,9 +43,9 @@ class ExchangeProviderDescription extends EnumerableItem with Serializable< return trocador; case 6: return exolix; - case 7: - return thorChain; case 8: + return thorChain; + case 7: return all; default: throw Exception('Unexpected token: $raw for ExchangeProviderDescription deserialize'); diff --git a/lib/exchange/provider/thorchain_exchange.provider.dart b/lib/exchange/provider/thorchain_exchange.provider.dart index 379c79593..4a3c0cf6e 100644 --- a/lib/exchange/provider/thorchain_exchange.provider.dart +++ b/lib/exchange/provider/thorchain_exchange.provider.dart @@ -21,14 +21,20 @@ class ThorChainExchangeProvider extends ExchangeProvider { CryptoCurrency.btc, CryptoCurrency.eth, CryptoCurrency.ltc, - CryptoCurrency.bch + CryptoCurrency.bch, + CryptoCurrency.aave, + CryptoCurrency.dai, + CryptoCurrency.gusd, + CryptoCurrency.usdc, + CryptoCurrency.usdterc20, + CryptoCurrency.wbtc, ].contains(element)) .toList()) ]; static final isRefundAddressSupported = [CryptoCurrency.eth]; - static const _baseURL = 'https://thornode.ninerealms.com'; + static const _baseURL = 'thornode.ninerealms.com'; static const _quotePath = '/thorchain/quote/swap'; static const _txInfoPath = '/thorchain/tx/status/'; static const _affiliateName = 'cakewallet'; @@ -145,7 +151,7 @@ class ThorChainExchangeProvider extends ExchangeProvider { Future findTradeById({required String id}) async { if (id.isEmpty) throw Exception('Trade id is empty'); final formattedId = id.startsWith('0x') ? id.substring(2) : id; - final uri = Uri.parse('$_baseURL$_txInfoPath$formattedId'); + final uri = Uri.https(_baseURL, '$_txInfoPath$formattedId'); final response = await http.get(uri); if (response.statusCode == 404) { @@ -157,7 +163,7 @@ class ThorChainExchangeProvider extends ExchangeProvider { final responseJSON = json.decode(response.body); final Map stagesJson = responseJSON['stages'] as Map; - final inboundObservedStarted = stagesJson['inbound_observed']?['started'] as bool? ?? true; + final inboundObservedStarted = stagesJson['inbound_observed']?['started'] as bool? ?? false; if (!inboundObservedStarted) { throw Exception('Trade has not started for id: $formattedId'); } @@ -173,7 +179,6 @@ class ThorChainExchangeProvider extends ExchangeProvider { final plannedOutTxs = responseJSON['planned_out_txs'] as List?; final isRefund = plannedOutTxs?.any((tx) => tx['refund'] == true) ?? false; - return Trade( id: id, from: CryptoCurrency.fromString(tx['chain'] as String? ?? ''), @@ -189,7 +194,7 @@ class ThorChainExchangeProvider extends ExchangeProvider { } Future> _getSwapQuote(Map params) async { - final uri = Uri.parse('$_baseURL$_quotePath${Uri(queryParameters: params)}'); + Uri uri = Uri.https(_baseURL, _quotePath, params); final response = await http.get(uri); @@ -204,7 +209,10 @@ class ThorChainExchangeProvider extends ExchangeProvider { return json.decode(response.body) as Map; } - String _normalizeCurrency(CryptoCurrency currency) => '${currency.title}.${currency.title}'; + String _normalizeCurrency(CryptoCurrency currency) { + final networkTitle = currency.tag == 'ETH' ? 'ETH' : currency.title; + return '$networkTitle.${currency.title}'; + } String _doubleToThorChainString(double amount) => (amount * 1e8).toInt().toString(); diff --git a/lib/src/screens/dashboard/widgets/filter_tile.dart b/lib/src/screens/dashboard/widgets/filter_tile.dart index 3be96073a..d2f824806 100644 --- a/lib/src/screens/dashboard/widgets/filter_tile.dart +++ b/lib/src/screens/dashboard/widgets/filter_tile.dart @@ -9,7 +9,7 @@ class FilterTile extends StatelessWidget { Widget build(BuildContext context) { return Container( width: double.infinity, - padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 24.0), + padding: EdgeInsets.symmetric(vertical: 6.0, horizontal: 24.0), child: child, ); } diff --git a/lib/src/screens/exchange_trade/exchange_trade_page.dart b/lib/src/screens/exchange_trade/exchange_trade_page.dart index 4ea14ec4c..c4dcae32c 100644 --- a/lib/src/screens/exchange_trade/exchange_trade_page.dart +++ b/lib/src/screens/exchange_trade/exchange_trade_page.dart @@ -209,7 +209,6 @@ class ExchangeTradeState extends State { bottomSectionPadding: EdgeInsets.fromLTRB(24, 0, 24, 24), bottomSection: Observer(builder: (_) { final trade = widget.exchangeTradeViewModel.trade; - print('trade.amount: ${trade.amount}'); final sendingState = widget.exchangeTradeViewModel.sendViewModel.state; diff --git a/lib/store/dashboard/trade_filter_store.dart b/lib/store/dashboard/trade_filter_store.dart index 4e901aa5e..c05839578 100644 --- a/lib/store/dashboard/trade_filter_store.dart +++ b/lib/store/dashboard/trade_filter_store.dart @@ -3,18 +3,20 @@ import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart'; import 'package:cw_core/wallet_base.dart'; import 'package:mobx/mobx.dart'; -part'trade_filter_store.g.dart'; +part 'trade_filter_store.g.dart'; class TradeFilterStore = TradeFilterStoreBase with _$TradeFilterStore; abstract class TradeFilterStoreBase with Store { - TradeFilterStoreBase() : displayXMRTO = true, + TradeFilterStoreBase() + : displayXMRTO = true, displayChangeNow = true, displaySideShift = true, displayMorphToken = true, displaySimpleSwap = true, displayTrocador = true, - displayExolix = true; + displayExolix = true, + displayThorChain = true; @observable bool displayXMRTO; @@ -37,8 +39,17 @@ abstract class TradeFilterStoreBase with Store { @observable bool displayExolix; + @observable + bool displayThorChain; + @computed - bool get displayAllTrades => displayChangeNow && displaySideShift && displaySimpleSwap && displayTrocador && displayExolix; + bool get displayAllTrades => + displayChangeNow && + displaySideShift && + displaySimpleSwap && + displayTrocador && + displayExolix && + displayThorChain; @action void toggleDisplayExchange(ExchangeProviderDescription provider) { @@ -64,6 +75,9 @@ abstract class TradeFilterStoreBase with Store { case ExchangeProviderDescription.exolix: displayExolix = !displayExolix; break; + case ExchangeProviderDescription.thorChain: + displayThorChain = !displayThorChain; + break; case ExchangeProviderDescription.all: if (displayAllTrades) { displayChangeNow = false; @@ -73,6 +87,7 @@ abstract class TradeFilterStoreBase with Store { displaySimpleSwap = false; displayTrocador = false; displayExolix = false; + displayThorChain = false; } else { displayChangeNow = true; displaySideShift = true; @@ -81,6 +96,7 @@ abstract class TradeFilterStoreBase with Store { displaySimpleSwap = true; displayTrocador = true; displayExolix = true; + displayThorChain = true; } break; } @@ -96,16 +112,13 @@ abstract class TradeFilterStoreBase with Store { ? _trades .where((item) => (displayXMRTO && item.trade.provider == ExchangeProviderDescription.xmrto) || - (displaySideShift && - item.trade.provider == ExchangeProviderDescription.sideShift) || - (displayChangeNow && - item.trade.provider == ExchangeProviderDescription.changeNow) || - (displayMorphToken && - item.trade.provider == ExchangeProviderDescription.morphToken) || - (displaySimpleSwap && - item.trade.provider == ExchangeProviderDescription.simpleSwap) || + (displaySideShift && item.trade.provider == ExchangeProviderDescription.sideShift) || + (displayChangeNow && item.trade.provider == ExchangeProviderDescription.changeNow) || + (displayMorphToken && item.trade.provider == ExchangeProviderDescription.morphToken) || + (displaySimpleSwap && item.trade.provider == ExchangeProviderDescription.simpleSwap) || (displayTrocador && item.trade.provider == ExchangeProviderDescription.trocador) || - (displayExolix && item.trade.provider == ExchangeProviderDescription.exolix)) + (displayExolix && item.trade.provider == ExchangeProviderDescription.exolix) || + (displayThorChain && item.trade.provider == ExchangeProviderDescription.thorChain)) .toList() : _trades; } diff --git a/lib/view_model/dashboard/dashboard_view_model.dart b/lib/view_model/dashboard/dashboard_view_model.dart index da5eb0373..683d3fa0d 100644 --- a/lib/view_model/dashboard/dashboard_view_model.dart +++ b/lib/view_model/dashboard/dashboard_view_model.dart @@ -116,6 +116,11 @@ abstract class DashboardViewModelBase with Store { caption: ExchangeProviderDescription.exolix.title, onChanged: () => tradeFilterStore.toggleDisplayExchange(ExchangeProviderDescription.exolix)), + FilterItem( + value: () => tradeFilterStore.displayThorChain, + caption: ExchangeProviderDescription.thorChain.title, + onChanged: () => + tradeFilterStore.toggleDisplayExchange(ExchangeProviderDescription.thorChain)), ] }, subname = '',