diff --git a/lib/entities/default_settings_migration.dart b/lib/entities/default_settings_migration.dart index a02b40d44..e57d71174 100644 --- a/lib/entities/default_settings_migration.dart +++ b/lib/entities/default_settings_migration.dart @@ -401,6 +401,13 @@ Future defaultSettingsMigration( enabled: false, ); break; + case 48: + _changeExchangeProviderAvailability( + sharedPreferences, + providerName: "SwapTrade", + enabled: true, + ); + break; default: break; } diff --git a/lib/exchange/provider/swaptrade_exchange_provider.dart b/lib/exchange/provider/swaptrade_exchange_provider.dart index 9553c9559..d3f64b712 100644 --- a/lib/exchange/provider/swaptrade_exchange_provider.dart +++ b/lib/exchange/provider/swaptrade_exchange_provider.dart @@ -26,9 +26,11 @@ class SwapTradeExchangeProvider extends ExchangeProvider { CryptoCurrency.ltc, CryptoCurrency.ada, CryptoCurrency.bch, - CryptoCurrency.usdt, + CryptoCurrency.usdterc20, + CryptoCurrency.usdttrc20, CryptoCurrency.bnb, CryptoCurrency.xmr, + CryptoCurrency.zec, ].contains(element)) .toList()) ]; @@ -39,6 +41,7 @@ class SwapTradeExchangeProvider extends ExchangeProvider { static const getRate = '/api/swap/get-rate'; static const getCoins = '/api/swap/get-coins'; static const createOrder = '/api/swap/create-order'; + static const order = '/api/swap/order'; @override String get title => 'SwapTrade'; @@ -108,6 +111,7 @@ class SwapTradeExchangeProvider extends ExchangeProvider { final body = { 'coin_send': _normalizeCurrency(from), 'coin_receive': _normalizeCurrency(to), + 'amount': amount.toString(), 'ref': 'cake', }; @@ -120,7 +124,7 @@ class SwapTradeExchangeProvider extends ExchangeProvider { final data = responseBody['data'] as Map; double rate = double.parse(data['price'].toString()); - return rate; + return rate > 0 ? isFixedRateMode ? amount / rate : rate / amount : 0.0; } catch (e) { printV("error fetching rate: ${e.toString()}"); return 0.0; @@ -138,18 +142,16 @@ class SwapTradeExchangeProvider extends ExchangeProvider { final params = {}; var body = { 'coin_send': _normalizeCurrency(request.fromCurrency), + 'coin_send_network': _networkFor(request.fromCurrency), 'coin_receive': _normalizeCurrency(request.toCurrency), + 'coin_receive_network': _networkFor(request.toCurrency), 'amount_send': request.fromAmount, 'recipient': request.toAddress, 'ref': 'cake', 'markup': markup, + 'refund_address': request.refundAddress, }; - String? fromNetwork = _networkFor(request.fromCurrency); - String? toNetwork = _networkFor(request.toCurrency); - if (fromNetwork != null) body['coin_send_network'] = fromNetwork; - if (toNetwork != null) body['coin_receive_network'] = toNetwork; - final uri = Uri.https(apiAuthority, createOrder, params); final response = await post(uri, body: body, headers: headers); final responseBody = json.decode(response.body) as Map; @@ -193,7 +195,7 @@ class SwapTradeExchangeProvider extends ExchangeProvider { 'order_id': id, }; - final uri = Uri.https(apiAuthority, createOrder, params); + final uri = Uri.https(apiAuthority, order, params); final response = await post(uri, body: body, headers: headers); final responseBody = json.decode(response.body) as Map; @@ -211,10 +213,14 @@ class SwapTradeExchangeProvider extends ExchangeProvider { final toCurrency = responseData['coin_receive'] as String; final to = CryptoCurrency.fromString(toCurrency); final inputAddress = responseData['server_address'] as String; + final payoutAddress = responseData['recipient'] as String; final status = responseData['status'] as String; final state = TradeState.deserialize(raw: status); final response_id = responseData['order_id'] as String; final expectedSendAmount = responseData['amount_send'] as String; + final expectedReceiveAmount = responseData['amount_receive'] as String; + final memo = responseData['memo'] as String?; + final createdAt = responseData['created_at'] as String?; return Trade( id: response_id, @@ -223,7 +229,11 @@ class SwapTradeExchangeProvider extends ExchangeProvider { provider: description, inputAddress: inputAddress, amount: expectedSendAmount, + payoutAddress: payoutAddress, state: state, + receiveAmount: expectedReceiveAmount, + memo: memo, + createdAt: DateTime.tryParse(createdAt ?? ''), ); } catch (e) { printV("error getting trade: ${e.toString()}"); @@ -242,14 +252,14 @@ class SwapTradeExchangeProvider extends ExchangeProvider { } } - String? _networkFor(CryptoCurrency currency) { - switch (currency) { - case CryptoCurrency.usdt: - return "USDT_ERC20"; - case CryptoCurrency.bnb: - return "BNB_BSC"; - default: - return null; - } + String _networkFor(CryptoCurrency currency) { + final network = switch (currency) { + CryptoCurrency.eth => 'ETH', + CryptoCurrency.bnb => 'BNB_BSC', + CryptoCurrency.usdterc20 => 'USDT_ERC20', + CryptoCurrency.usdttrc20 => 'TRX_USDT_S2UZ', + _ => '', + }; + return network; } } diff --git a/lib/exchange/trade_state.dart b/lib/exchange/trade_state.dart index 6d2472a11..7bce8c7e7 100644 --- a/lib/exchange/trade_state.dart +++ b/lib/exchange/trade_state.dart @@ -131,6 +131,8 @@ class TradeState extends EnumerableItem with Serializable { case 'success': case 'done': return success; + case 'expired': + return expired; default: throw Exception('Unexpected token: $raw in TradeState deserialize'); } diff --git a/lib/main.dart b/lib/main.dart index 0e02ef97b..1eedfa6a9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -215,7 +215,7 @@ Future initializeAppConfigs() async { secureStorage: secureStorage, anonpayInvoiceInfo: anonpayInvoiceInfo, havenSeedStore: havenSeedStore, - initialMigrationVersion: 47, + initialMigrationVersion: 48, ); } diff --git a/lib/store/dashboard/trade_filter_store.dart b/lib/store/dashboard/trade_filter_store.dart index a2c6e3646..6a98329d6 100644 --- a/lib/store/dashboard/trade_filter_store.dart +++ b/lib/store/dashboard/trade_filter_store.dart @@ -19,7 +19,8 @@ abstract class TradeFilterStoreBase with Store { displayChainflip = true, displayThorChain = true, displayLetsExchange = true, - displayStealthEx = true; + displayStealthEx = true, + displaySwapTrade = true; @observable bool displayXMRTO; @@ -54,6 +55,9 @@ abstract class TradeFilterStoreBase with Store { @observable bool displayStealthEx; + @observable + bool displaySwapTrade; + @computed bool get displayAllTrades => displayChangeNow && @@ -64,7 +68,8 @@ abstract class TradeFilterStoreBase with Store { displayChainflip && displayThorChain && displayLetsExchange && - displayStealthEx; + displayStealthEx && + displaySwapTrade; @action void toggleDisplayExchange(ExchangeProviderDescription provider) { @@ -102,6 +107,8 @@ abstract class TradeFilterStoreBase with Store { case ExchangeProviderDescription.stealthEx: displayStealthEx = !displayStealthEx; break; + case ExchangeProviderDescription.swapTrade: + displaySwapTrade = !displaySwapTrade; case ExchangeProviderDescription.all: if (displayAllTrades) { displayChangeNow = false; @@ -115,6 +122,7 @@ abstract class TradeFilterStoreBase with Store { displayThorChain = false; displayLetsExchange = false; displayStealthEx = false; + displaySwapTrade = false; } else { displayChangeNow = true; displaySideShift = true; @@ -127,6 +135,7 @@ abstract class TradeFilterStoreBase with Store { displayThorChain = true; displayLetsExchange = true; displayStealthEx = true; + displaySwapTrade = true; } break; } @@ -158,7 +167,8 @@ abstract class TradeFilterStoreBase with Store { item.trade.provider == ExchangeProviderDescription.thorChain) || (displayLetsExchange && item.trade.provider == ExchangeProviderDescription.letsExchange) || - (displayStealthEx && item.trade.provider == ExchangeProviderDescription.stealthEx)) + (displayStealthEx && item.trade.provider == ExchangeProviderDescription.stealthEx) || + (displaySwapTrade && item.trade.provider == ExchangeProviderDescription.swapTrade)) .toList() : _trades; } diff --git a/lib/view_model/dashboard/dashboard_view_model.dart b/lib/view_model/dashboard/dashboard_view_model.dart index 99283a409..40a07e666 100644 --- a/lib/view_model/dashboard/dashboard_view_model.dart +++ b/lib/view_model/dashboard/dashboard_view_model.dart @@ -152,6 +152,11 @@ abstract class DashboardViewModelBase with Store { caption: ExchangeProviderDescription.stealthEx.title, onChanged: () => tradeFilterStore.toggleDisplayExchange(ExchangeProviderDescription.stealthEx)), + FilterItem( + value: () => tradeFilterStore.displaySwapTrade, + caption: ExchangeProviderDescription.swapTrade.title, + onChanged: () => tradeFilterStore + .toggleDisplayExchange(ExchangeProviderDescription.swapTrade)), ] }, subname = '',