From 588d93c1a442df6e4868d0ff18901398bd3cfaaa Mon Sep 17 00:00:00 2001 From: M Date: Sat, 24 Oct 2020 15:55:24 +0300 Subject: [PATCH] Fixes --- ios/Runner.xcodeproj/project.pbxproj | 6 +- .../xmrto/xmrto_exchange_provider.dart | 8 +- lib/src/screens/exchange/exchange_page.dart | 140 +++++++++--------- .../dashboard/dashboard_view_model.dart | 7 +- .../exchange/exchange_view_model.dart | 4 +- pubspec.lock | 2 +- 6 files changed, 82 insertions(+), 85 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index ab58cffaf..97e09ec63 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -354,7 +354,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 10; DEVELOPMENT_TEAM = 32J6BB6VUS; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -493,7 +493,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 10; DEVELOPMENT_TEAM = 32J6BB6VUS; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -526,7 +526,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 10; DEVELOPMENT_TEAM = 32J6BB6VUS; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( diff --git a/lib/exchange/xmrto/xmrto_exchange_provider.dart b/lib/exchange/xmrto/xmrto_exchange_provider.dart index 25232db65..31464d7bb 100644 --- a/lib/exchange/xmrto/xmrto_exchange_provider.dart +++ b/lib/exchange/xmrto/xmrto_exchange_provider.dart @@ -89,8 +89,8 @@ class XMRTOExchangeProvider extends ExchangeProvider { final url = await getApiUri() + _orderCreateUriSufix; final body = { 'amount': _request.isBTCRequest - ? _request.receiveAmount - : _request.amount, + ? _request.receiveAmount.replaceAll(',', '.') + : _request.amount.replaceAll(',', '.'), 'amount_currency': _request.isBTCRequest ? _request.to.toString() : _request.from.toString(), @@ -146,9 +146,9 @@ class XMRTOExchangeProvider extends ExchangeProvider { } final responseJSON = json.decode(response.body) as Map; - final address = responseJSON['xmr_receiving_integrated_address'] as String; + final address = responseJSON['receiving_subaddress'] as String; final paymentId = responseJSON['xmr_required_payment_id_short'] as String; - final amount = responseJSON['xmr_amount_total'].toString(); + final amount = responseJSON['incoming_amount_total'].toString(); final stateRaw = responseJSON['state'] as String; final expiredAtRaw = responseJSON['expires_at'] as String; final expiredAt = DateTime.parse(expiredAtRaw).toLocal(); diff --git a/lib/src/screens/exchange/exchange_page.dart b/lib/src/screens/exchange/exchange_page.dart index bf587776f..b16aa9df8 100644 --- a/lib/src/screens/exchange/exchange_page.dart +++ b/lib/src/screens/exchange/exchange_page.dart @@ -1,26 +1,25 @@ import 'dart:ui'; -import 'package:cake_wallet/exchange/exchange_provider.dart'; -import 'package:cake_wallet/core/execution_state.dart'; -import 'package:cake_wallet/exchange/exchange_template.dart'; -import 'package:cake_wallet/src/screens/base_page.dart'; -import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; -import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; -import 'package:cake_wallet/src/widgets/template_tile.dart'; -import 'package:cake_wallet/src/widgets/trail_button.dart'; -import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:dotted_border/dotted_border.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:keyboard_actions/keyboard_actions.dart'; import 'package:mobx/mobx.dart'; +import 'package:cake_wallet/exchange/exchange_provider.dart'; +import 'package:cake_wallet/core/execution_state.dart'; +import 'package:cake_wallet/exchange/exchange_template.dart'; +import 'package:cake_wallet/exchange/exchange_trade_state.dart'; +import 'package:cake_wallet/exchange/limits_state.dart'; +import 'package:cake_wallet/src/screens/base_page.dart'; +import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; +import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; +import 'package:cake_wallet/src/widgets/template_tile.dart'; +import 'package:cake_wallet/src/widgets/trail_button.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/entities/crypto_currency.dart'; import 'package:cake_wallet/exchange/xmrto/xmrto_exchange_provider.dart'; - -// import 'package:cake_wallet/exchange/exchange_trade_state.dart'; -// import 'package:cake_wallet/exchange/limits_state.dart'; import 'package:cake_wallet/src/screens/exchange/widgets/exchange_card.dart'; import 'package:cake_wallet/src/widgets/primary_button.dart'; import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart'; @@ -209,9 +208,10 @@ class ExchangePage extends BasePage { exchangeViewModel.wallet.currency ? exchangeViewModel.wallet.address : exchangeViewModel.receiveAddress, - initialIsAmountEditable: - exchangeViewModel.provider is - XMRTOExchangeProvider ? true : false, + initialIsAmountEditable: exchangeViewModel + .provider is XMRTOExchangeProvider + ? true + : false, initialIsAddressEditable: exchangeViewModel .isReceiveAddressEnabled, @@ -401,7 +401,7 @@ class ExchangePage extends BasePage { Theme.of(context).accentTextTheme.body2.color, textColor: Colors.white, isLoading: exchangeViewModel.tradeState - is IsExecutingState, + is TradeIsCreating, )), ]), )), @@ -447,20 +447,16 @@ class ExchangePage extends BasePage { final receiveAmountController = receiveKey.currentState.amountController; final limitsState = exchangeViewModel.limitsState; - // FIXME: FIXME - - // final limitsState = exchangeViewModel.limitsState; - // - // if (limitsState is LimitsLoadedSuccessfully) { - // final min = limitsState.limits.min != null - // ? limitsState.limits.min.toString() - // : null; - // final max = limitsState.limits.max != null - // ? limitsState.limits.max.toString() - // : null; - // final key = depositKey; - // key.currentState.changeLimits(min: min, max: max); - // } + if (limitsState is LimitsLoadedSuccessfully) { + final min = limitsState.limits.min != null + ? limitsState.limits.min.toString() + : null; + final max = limitsState.limits.max != null + ? limitsState.limits.max.toString() + : null; + final key = depositKey; + key.currentState.changeLimits(min: min, max: max); + } _onCurrencyChange( exchangeViewModel.receiveCurrency, exchangeViewModel, receiveKey); @@ -523,55 +519,51 @@ class ExchangePage extends BasePage { reaction((_) => exchangeViewModel.provider, (ExchangeProvider provider) { provider is XMRTOExchangeProvider - ? receiveKey.currentState.isAmountEditable(isEditable: true) - : receiveKey.currentState.isAmountEditable(isEditable: false); + ? receiveKey.currentState.isAmountEditable(isEditable: true) + : receiveKey.currentState.isAmountEditable(isEditable: false); }); - // FIXME: FIXME + reaction((_) => exchangeViewModel.tradeState, (ExchangeTradeState state) { + if (state is TradeIsCreatedFailure) { + WidgetsBinding.instance.addPostFrameCallback((_) { + showPopUp( + context: context, + builder: (BuildContext context) { + return AlertWithOneAction( + alertTitle: S.of(context).error, + alertContent: state.error, + buttonText: S.of(context).ok, + buttonAction: () => Navigator.of(context).pop()); + }); + }); + } + if (state is TradeIsCreatedSuccessfully) { + Navigator.of(context).pushNamed(Routes.exchangeConfirm); + } + }); - // reaction((_) => exchangeViewModel.tradeState, (ExchangeTradeState state) { - // if (state is TradeIsCreatedFailure) { - // WidgetsBinding.instance.addPostFrameCallback((_) { - // showPopUp( - // context: context, - // builder: (BuildContext context) { - // return AlertWithOneAction( - // alertTitle: S.of(context).error, - // alertContent: state.error, - // buttonText: S.of(context).ok, - // buttonAction: () => Navigator.of(context).pop()); - // }); - // }); - // } - // if (state is TradeIsCreatedSuccessfully) { - // Navigator.of(context).pushNamed(Routes.exchangeConfirm); - // } - // }); + reaction((_) => exchangeViewModel.limitsState, (LimitsState state) { + String min; + String max; - // FIXME: FIXME + if (state is LimitsLoadedSuccessfully) { + min = state.limits.min != null ? state.limits.min.toString() : null; + max = state.limits.max != null ? state.limits.max.toString() : null; + } - // reaction((_) => exchangeViewModel.limitsState, (LimitsState state) { - // String min; - // String max; - // - // if (state is LimitsLoadedSuccessfully) { - // min = state.limits.min != null ? state.limits.min.toString() : null; - // max = state.limits.max != null ? state.limits.max.toString() : null; - // } - // - // if (state is LimitsLoadedFailure) { - // min = '0'; - // max = '0'; - // } - // - // if (state is LimitsIsLoading) { - // min = '...'; - // max = '...'; - // } - // - // depositKey.currentState.changeLimits(min: min, max: max); - // receiveKey.currentState.changeLimits(min: null, max: null); - // }); + if (state is LimitsLoadedFailure) { + min = '0'; + max = '0'; + } + + if (state is LimitsIsLoading) { + min = '...'; + max = '...'; + } + + depositKey.currentState.changeLimits(min: min, max: max); + receiveKey.currentState.changeLimits(min: null, max: null); + }); depositAddressController.addListener( () => exchangeViewModel.depositAddress = depositAddressController.text); diff --git a/lib/view_model/dashboard/dashboard_view_model.dart b/lib/view_model/dashboard/dashboard_view_model.dart index 54a6297eb..1dacbd949 100644 --- a/lib/view_model/dashboard/dashboard_view_model.dart +++ b/lib/view_model/dashboard/dashboard_view_model.dart @@ -138,7 +138,9 @@ abstract class DashboardViewModelBase with Store { appStore.settingsStore.balanceDisplayMode; @computed - List get trades => tradesStore.trades; + List get trades => tradesStore.trades + .where((trade) => trade.trade.walletId == wallet.id) + .toList(); @computed double get price => balanceViewModel.price; @@ -153,6 +155,7 @@ abstract class DashboardViewModelBase with Store { return formattedItemsList(_items); } + @observable WalletBase wallet; BalanceViewModel balanceViewModel; @@ -174,7 +177,9 @@ abstract class DashboardViewModelBase with Store { await wallet.connectToNode(node: node); } + @action void _onWalletChange(WalletBase wallet) { + this.wallet = wallet; name = wallet.name; transactions.clear(); transactions.addAll(wallet.transactionHistory.transactions.values.map( diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index b6efa310f..a52f5b652 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -137,7 +137,7 @@ abstract class ExchangeViewModelBase with Store { return; } - final _amount = double.parse(amount) ?? 0; + final _amount = double.parse(amount.replaceAll(',', '.')) ?? 0; provider .calculateAmount( @@ -160,7 +160,7 @@ abstract class ExchangeViewModelBase with Store { return; } - final _amount = double.parse(amount); + final _amount = double.parse(amount.replaceAll(',', '.')); provider .calculateAmount( from: depositCurrency, to: receiveCurrency, amount: _amount, diff --git a/pubspec.lock b/pubspec.lock index b745cd3f5..4fb92a462 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -930,7 +930,7 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "5.7.6" + version: "5.7.7" url_launcher_linux: dependency: transitive description: