review comments + transaction filter item

This commit is contained in:
Serhii 2024-03-10 13:50:44 +02:00
parent 52f16b5130
commit 7e66d3524b
9 changed files with 52 additions and 30 deletions

View file

@ -81,6 +81,7 @@ class AmountConverter {
return _moneroAmountToString(amount); return _moneroAmountToString(amount);
case CryptoCurrency.btc: case CryptoCurrency.btc:
case CryptoCurrency.bch: case CryptoCurrency.bch:
case CryptoCurrency.ltc:
return _bitcoinAmountToString(amount); return _bitcoinAmountToString(amount);
case CryptoCurrency.xhv: case CryptoCurrency.xhv:
case CryptoCurrency.xag: case CryptoCurrency.xag:

View file

@ -232,7 +232,6 @@ import 'package:cake_wallet/entities/qr_view_data.dart';
import 'buy/dfx/dfx_buy_provider.dart'; import 'buy/dfx/dfx_buy_provider.dart';
import 'core/totp_request_details.dart'; import 'core/totp_request_details.dart';
import 'exchange/provider/thorchain_exchange.provider.dart';
import 'src/screens/settings/desktop_settings/desktop_settings_page.dart'; import 'src/screens/settings/desktop_settings/desktop_settings_page.dart';
final getIt = GetIt.instance; final getIt = GetIt.instance;
@ -1196,7 +1195,5 @@ Future<void> setup({
getIt.registerFactory(() => NFTViewModel(appStore, getIt.get<BottomSheetService>())); getIt.registerFactory(() => NFTViewModel(appStore, getIt.get<BottomSheetService>()));
getIt.registerFactory<TorPage>(() => TorPage(getIt.get<AppStore>())); getIt.registerFactory<TorPage>(() => TorPage(getIt.get<AppStore>()));
getIt.registerFactory(() => ThorChainExchangeProvider(tradesStore: tradesSource));
_isSetupFinished = true; _isSetupFinished = true;
} }

View file

@ -72,5 +72,4 @@ class PreferencesKey {
static const lastSeenAppVersion = 'last_seen_app_version'; static const lastSeenAppVersion = 'last_seen_app_version';
static const shouldShowMarketPlaceInDashboard = 'should_show_marketplace_in_dashboard'; static const shouldShowMarketPlaceInDashboard = 'should_show_marketplace_in_dashboard';
static const isNewInstall = 'is_new_install'; static const isNewInstall = 'is_new_install';
static const thorChainTradeCounter = 'thor_chain_trade_counter';
} }

View file

@ -23,9 +23,9 @@ class ExchangeProviderDescription extends EnumerableItem<int> with Serializable<
static const exolix = static const exolix =
ExchangeProviderDescription(title: 'Exolix', raw: 6, image: 'assets/images/exolix.png'); ExchangeProviderDescription(title: 'Exolix', raw: 6, image: 'assets/images/exolix.png');
static const thorChain = 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}) { static ExchangeProviderDescription deserialize({required int raw}) {
switch (raw) { switch (raw) {
@ -43,9 +43,9 @@ class ExchangeProviderDescription extends EnumerableItem<int> with Serializable<
return trocador; return trocador;
case 6: case 6:
return exolix; return exolix;
case 7:
return thorChain;
case 8: case 8:
return thorChain;
case 7:
return all; return all;
default: default:
throw Exception('Unexpected token: $raw for ExchangeProviderDescription deserialize'); throw Exception('Unexpected token: $raw for ExchangeProviderDescription deserialize');

View file

@ -21,14 +21,20 @@ class ThorChainExchangeProvider extends ExchangeProvider {
CryptoCurrency.btc, CryptoCurrency.btc,
CryptoCurrency.eth, CryptoCurrency.eth,
CryptoCurrency.ltc, CryptoCurrency.ltc,
CryptoCurrency.bch CryptoCurrency.bch,
CryptoCurrency.aave,
CryptoCurrency.dai,
CryptoCurrency.gusd,
CryptoCurrency.usdc,
CryptoCurrency.usdterc20,
CryptoCurrency.wbtc,
].contains(element)) ].contains(element))
.toList()) .toList())
]; ];
static final isRefundAddressSupported = [CryptoCurrency.eth]; 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 _quotePath = '/thorchain/quote/swap';
static const _txInfoPath = '/thorchain/tx/status/'; static const _txInfoPath = '/thorchain/tx/status/';
static const _affiliateName = 'cakewallet'; static const _affiliateName = 'cakewallet';
@ -145,7 +151,7 @@ class ThorChainExchangeProvider extends ExchangeProvider {
Future<Trade> findTradeById({required String id}) async { Future<Trade> findTradeById({required String id}) async {
if (id.isEmpty) throw Exception('Trade id is empty'); if (id.isEmpty) throw Exception('Trade id is empty');
final formattedId = id.startsWith('0x') ? id.substring(2) : id; 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); final response = await http.get(uri);
if (response.statusCode == 404) { if (response.statusCode == 404) {
@ -157,7 +163,7 @@ class ThorChainExchangeProvider extends ExchangeProvider {
final responseJSON = json.decode(response.body); final responseJSON = json.decode(response.body);
final Map<String, dynamic> stagesJson = responseJSON['stages'] as Map<String, dynamic>; final Map<String, dynamic> stagesJson = responseJSON['stages'] as Map<String, dynamic>;
final inboundObservedStarted = stagesJson['inbound_observed']?['started'] as bool? ?? true; final inboundObservedStarted = stagesJson['inbound_observed']?['started'] as bool? ?? false;
if (!inboundObservedStarted) { if (!inboundObservedStarted) {
throw Exception('Trade has not started for id: $formattedId'); 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<dynamic>?; final plannedOutTxs = responseJSON['planned_out_txs'] as List<dynamic>?;
final isRefund = plannedOutTxs?.any((tx) => tx['refund'] == true) ?? false; final isRefund = plannedOutTxs?.any((tx) => tx['refund'] == true) ?? false;
return Trade( return Trade(
id: id, id: id,
from: CryptoCurrency.fromString(tx['chain'] as String? ?? ''), from: CryptoCurrency.fromString(tx['chain'] as String? ?? ''),
@ -189,7 +194,7 @@ class ThorChainExchangeProvider extends ExchangeProvider {
} }
Future<Map<String, dynamic>> _getSwapQuote(Map<String, String> params) async { Future<Map<String, dynamic>> _getSwapQuote(Map<String, String> params) async {
final uri = Uri.parse('$_baseURL$_quotePath${Uri(queryParameters: params)}'); Uri uri = Uri.https(_baseURL, _quotePath, params);
final response = await http.get(uri); final response = await http.get(uri);
@ -204,7 +209,10 @@ class ThorChainExchangeProvider extends ExchangeProvider {
return json.decode(response.body) as Map<String, dynamic>; return json.decode(response.body) as Map<String, dynamic>;
} }
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(); String _doubleToThorChainString(double amount) => (amount * 1e8).toInt().toString();

View file

@ -9,7 +9,7 @@ class FilterTile extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
width: double.infinity, width: double.infinity,
padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 24.0), padding: EdgeInsets.symmetric(vertical: 6.0, horizontal: 24.0),
child: child, child: child,
); );
} }

View file

@ -209,7 +209,6 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
bottomSectionPadding: EdgeInsets.fromLTRB(24, 0, 24, 24), bottomSectionPadding: EdgeInsets.fromLTRB(24, 0, 24, 24),
bottomSection: Observer(builder: (_) { bottomSection: Observer(builder: (_) {
final trade = widget.exchangeTradeViewModel.trade; final trade = widget.exchangeTradeViewModel.trade;
print('trade.amount: ${trade.amount}');
final sendingState = final sendingState =
widget.exchangeTradeViewModel.sendViewModel.state; widget.exchangeTradeViewModel.sendViewModel.state;

View file

@ -3,18 +3,20 @@ import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart';
import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_base.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
part'trade_filter_store.g.dart'; part 'trade_filter_store.g.dart';
class TradeFilterStore = TradeFilterStoreBase with _$TradeFilterStore; class TradeFilterStore = TradeFilterStoreBase with _$TradeFilterStore;
abstract class TradeFilterStoreBase with Store { abstract class TradeFilterStoreBase with Store {
TradeFilterStoreBase() : displayXMRTO = true, TradeFilterStoreBase()
: displayXMRTO = true,
displayChangeNow = true, displayChangeNow = true,
displaySideShift = true, displaySideShift = true,
displayMorphToken = true, displayMorphToken = true,
displaySimpleSwap = true, displaySimpleSwap = true,
displayTrocador = true, displayTrocador = true,
displayExolix = true; displayExolix = true,
displayThorChain = true;
@observable @observable
bool displayXMRTO; bool displayXMRTO;
@ -37,8 +39,17 @@ abstract class TradeFilterStoreBase with Store {
@observable @observable
bool displayExolix; bool displayExolix;
@observable
bool displayThorChain;
@computed @computed
bool get displayAllTrades => displayChangeNow && displaySideShift && displaySimpleSwap && displayTrocador && displayExolix; bool get displayAllTrades =>
displayChangeNow &&
displaySideShift &&
displaySimpleSwap &&
displayTrocador &&
displayExolix &&
displayThorChain;
@action @action
void toggleDisplayExchange(ExchangeProviderDescription provider) { void toggleDisplayExchange(ExchangeProviderDescription provider) {
@ -64,6 +75,9 @@ abstract class TradeFilterStoreBase with Store {
case ExchangeProviderDescription.exolix: case ExchangeProviderDescription.exolix:
displayExolix = !displayExolix; displayExolix = !displayExolix;
break; break;
case ExchangeProviderDescription.thorChain:
displayThorChain = !displayThorChain;
break;
case ExchangeProviderDescription.all: case ExchangeProviderDescription.all:
if (displayAllTrades) { if (displayAllTrades) {
displayChangeNow = false; displayChangeNow = false;
@ -73,6 +87,7 @@ abstract class TradeFilterStoreBase with Store {
displaySimpleSwap = false; displaySimpleSwap = false;
displayTrocador = false; displayTrocador = false;
displayExolix = false; displayExolix = false;
displayThorChain = false;
} else { } else {
displayChangeNow = true; displayChangeNow = true;
displaySideShift = true; displaySideShift = true;
@ -81,6 +96,7 @@ abstract class TradeFilterStoreBase with Store {
displaySimpleSwap = true; displaySimpleSwap = true;
displayTrocador = true; displayTrocador = true;
displayExolix = true; displayExolix = true;
displayThorChain = true;
} }
break; break;
} }
@ -96,16 +112,13 @@ abstract class TradeFilterStoreBase with Store {
? _trades ? _trades
.where((item) => .where((item) =>
(displayXMRTO && item.trade.provider == ExchangeProviderDescription.xmrto) || (displayXMRTO && item.trade.provider == ExchangeProviderDescription.xmrto) ||
(displaySideShift && (displaySideShift && item.trade.provider == ExchangeProviderDescription.sideShift) ||
item.trade.provider == ExchangeProviderDescription.sideShift) || (displayChangeNow && item.trade.provider == ExchangeProviderDescription.changeNow) ||
(displayChangeNow && (displayMorphToken && item.trade.provider == ExchangeProviderDescription.morphToken) ||
item.trade.provider == ExchangeProviderDescription.changeNow) || (displaySimpleSwap && item.trade.provider == ExchangeProviderDescription.simpleSwap) ||
(displayMorphToken &&
item.trade.provider == ExchangeProviderDescription.morphToken) ||
(displaySimpleSwap &&
item.trade.provider == ExchangeProviderDescription.simpleSwap) ||
(displayTrocador && item.trade.provider == ExchangeProviderDescription.trocador) || (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() .toList()
: _trades; : _trades;
} }

View file

@ -116,6 +116,11 @@ abstract class DashboardViewModelBase with Store {
caption: ExchangeProviderDescription.exolix.title, caption: ExchangeProviderDescription.exolix.title,
onChanged: () => onChanged: () =>
tradeFilterStore.toggleDisplayExchange(ExchangeProviderDescription.exolix)), tradeFilterStore.toggleDisplayExchange(ExchangeProviderDescription.exolix)),
FilterItem(
value: () => tradeFilterStore.displayThorChain,
caption: ExchangeProviderDescription.thorChain.title,
onChanged: () =>
tradeFilterStore.toggleDisplayExchange(ExchangeProviderDescription.thorChain)),
] ]
}, },
subname = '', subname = '',