CAKE-306 | fixed moonpay_buy_provider.dart, buy_view_model.dart and order_details_view_model.dart

This commit is contained in:
OleksandrSobol 2021-04-30 13:12:00 +03:00
parent 9627590ba5
commit ae7ccacf29
4 changed files with 6 additions and 26 deletions

View file

@ -1,6 +1,5 @@
import 'dart:convert'; import 'dart:convert';
import 'package:cake_wallet/buy/buy_exception.dart'; import 'package:cake_wallet/buy/buy_exception.dart';
import 'package:hive/hive.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:cake_wallet/buy/buy_amount.dart'; import 'package:cake_wallet/buy/buy_amount.dart';
import 'package:cake_wallet/buy/buy_provider.dart'; import 'package:cake_wallet/buy/buy_provider.dart';
@ -12,8 +11,7 @@ import 'package:cake_wallet/exchange/trade_state.dart';
import 'package:cake_wallet/.secrets.g.dart' as secrets; import 'package:cake_wallet/.secrets.g.dart' as secrets;
class MoonPayBuyProvider extends BuyProvider { class MoonPayBuyProvider extends BuyProvider {
MoonPayBuyProvider({WalletBase wallet, this.ordersSource, MoonPayBuyProvider({WalletBase wallet, bool isTestEnvironment = false})
bool isTestEnvironment = false})
: super(wallet: wallet, isTestEnvironment: isTestEnvironment) { : super(wallet: wallet, isTestEnvironment: isTestEnvironment) {
baseApiUrl = isTestEnvironment baseApiUrl = isTestEnvironment
? _baseTestApiUrl ? _baseTestApiUrl
@ -39,7 +37,6 @@ class MoonPayBuyProvider extends BuyProvider {
@override @override
String get trackUrl => baseApiUrl + '/transaction_receipt?transactionId='; String get trackUrl => baseApiUrl + '/transaction_receipt?transactionId=';
final Box<Order> ordersSource;
String baseApiUrl; String baseApiUrl;
@override @override
@ -100,23 +97,10 @@ class MoonPayBuyProvider extends BuyProvider {
final createdAt = DateTime.parse(createdAtRaw).toLocal(); final createdAt = DateTime.parse(createdAtRaw).toLocal();
final amount = responseJSON['quoteCurrencyAmount'] as double; final amount = responseJSON['quoteCurrencyAmount'] as double;
var from = '';
var to = '';
for (final order in ordersSource.values) {
if (order.id == id) {
from = order.from;
to = order.to;
break;
}
}
return Order( return Order(
id: id, id: id,
provider: description, provider: description,
transferId: id, transferId: id,
from: from,
to: to,
state: state, state: state,
createdAt: createdAt, createdAt: createdAt,
amount: amount.toString(), amount: amount.toString(),

View file

@ -558,7 +558,6 @@ Future setup(
return OrderDetailsViewModel( return OrderDetailsViewModel(
wallet: wallet, wallet: wallet,
ordersSource: _ordersSource,
orderForDetails: order); orderForDetails: order);
}); });

View file

@ -22,7 +22,7 @@ abstract class BuyViewModelBase with Store {
{@required this.wallet}) { {@required this.wallet}) {
providerList = [ providerList = [
WyreBuyProvider(wallet: wallet), WyreBuyProvider(wallet: wallet),
MoonPayBuyProvider(wallet: wallet, ordersSource: ordersSource) MoonPayBuyProvider(wallet: wallet)
]; ];
items = providerList.map((provider) => items = providerList.map((provider) =>
BuyItem(provider: provider, buyAmountViewModel: buyAmountViewModel)) BuyItem(provider: provider, buyAmountViewModel: buyAmountViewModel))

View file

@ -3,7 +3,6 @@ import 'package:cake_wallet/buy/buy_provider.dart';
import 'package:cake_wallet/buy/buy_provider_description.dart'; import 'package:cake_wallet/buy/buy_provider_description.dart';
import 'package:cake_wallet/buy/order.dart'; import 'package:cake_wallet/buy/order.dart';
import 'package:cake_wallet/utils/date_formatter.dart'; import 'package:cake_wallet/utils/date_formatter.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart'; import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
@ -19,8 +18,7 @@ class OrderDetailsViewModel = OrderDetailsViewModelBase
with _$OrderDetailsViewModel; with _$OrderDetailsViewModel;
abstract class OrderDetailsViewModelBase with Store { abstract class OrderDetailsViewModelBase with Store {
OrderDetailsViewModelBase({WalletBase wallet, this.ordersSource, OrderDetailsViewModelBase({WalletBase wallet, Order orderForDetails}) {
Order orderForDetails}) {
order = orderForDetails; order = orderForDetails;
if (order.provider != null) { if (order.provider != null) {
@ -29,8 +27,7 @@ abstract class OrderDetailsViewModelBase with Store {
_provider = WyreBuyProvider(wallet: wallet); _provider = WyreBuyProvider(wallet: wallet);
break; break;
case BuyProviderDescription.moonPay: case BuyProviderDescription.moonPay:
_provider = _provider = MoonPayBuyProvider(wallet: wallet);
MoonPayBuyProvider(wallet: wallet, ordersSource: ordersSource);
break; break;
} }
} }
@ -44,8 +41,6 @@ abstract class OrderDetailsViewModelBase with Store {
timer = Timer.periodic(Duration(seconds: 20), (_) async => _updateOrder()); timer = Timer.periodic(Duration(seconds: 20), (_) async => _updateOrder());
} }
final Box<Order> ordersSource;
@observable @observable
Order order; Order order;
@ -61,6 +56,8 @@ abstract class OrderDetailsViewModelBase with Store {
try { try {
if (_provider != null) { if (_provider != null) {
final updatedOrder = await _provider.findOrderById(order.id); final updatedOrder = await _provider.findOrderById(order.id);
updatedOrder.from = order.from;
updatedOrder.to = order.to;
updatedOrder.receiveAddress = order.receiveAddress; updatedOrder.receiveAddress = order.receiveAddress;
updatedOrder.walletId = order.walletId; updatedOrder.walletId = order.walletId;
if (order.provider != null) { if (order.provider != null) {