mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-08 20:09:24 +00:00
CAKE-306 | fixed findOrderById() in the moonpay_buy_provider.dart; fixed saveOrder() in the buy_view_model.dart
This commit is contained in:
parent
1c976bfaa1
commit
9627590ba5
6 changed files with 33 additions and 16 deletions
|
@ -1,5 +1,6 @@
|
|||
import 'dart:convert';
|
||||
import 'package:cake_wallet/buy/buy_exception.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:cake_wallet/buy/buy_amount.dart';
|
||||
import 'package:cake_wallet/buy/buy_provider.dart';
|
||||
|
@ -11,9 +12,10 @@ import 'package:cake_wallet/exchange/trade_state.dart';
|
|||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
|
||||
class MoonPayBuyProvider extends BuyProvider {
|
||||
MoonPayBuyProvider({WalletBase wallet, bool isTestEnvironment = false})
|
||||
MoonPayBuyProvider({WalletBase wallet, this.ordersSource,
|
||||
bool isTestEnvironment = false})
|
||||
: super(wallet: wallet, isTestEnvironment: isTestEnvironment) {
|
||||
baseApiUrl = isTestEnvironment
|
||||
baseApiUrl = isTestEnvironment
|
||||
? _baseTestApiUrl
|
||||
: _baseProductApiUrl;
|
||||
}
|
||||
|
@ -23,7 +25,6 @@ class MoonPayBuyProvider extends BuyProvider {
|
|||
static const _currenciesSuffix = '/v3/currencies';
|
||||
static const _quoteSuffix = '/buy_quote';
|
||||
static const _transactionsSuffix = '/v1/transactions';
|
||||
static const _fiatCurrency = 'USD';
|
||||
static const _apiKey = secrets.moonPayApiKey;
|
||||
|
||||
@override
|
||||
|
@ -38,6 +39,7 @@ class MoonPayBuyProvider extends BuyProvider {
|
|||
@override
|
||||
String get trackUrl => baseApiUrl + '/transaction_receipt?transactionId=';
|
||||
|
||||
final Box<Order> ordersSource;
|
||||
String baseApiUrl;
|
||||
|
||||
@override
|
||||
|
@ -58,7 +60,7 @@ class MoonPayBuyProvider extends BuyProvider {
|
|||
|
||||
@override
|
||||
Future<BuyAmount> calculateAmount(String amount, String sourceCurrency) async {
|
||||
final url = baseApiUrl + _currenciesSuffix + '/$currencyCode' +
|
||||
final url = _baseProductApiUrl + _currenciesSuffix + '/$currencyCode' +
|
||||
_quoteSuffix + '/?apiKey=' + _apiKey +
|
||||
'&baseCurrencyAmount=' + amount +
|
||||
'&baseCurrencyCode' + sourceCurrency.toLowerCase();
|
||||
|
@ -80,7 +82,7 @@ class MoonPayBuyProvider extends BuyProvider {
|
|||
|
||||
@override
|
||||
Future<Order> findOrderById(String id) async {
|
||||
final url = baseApiUrl + _transactionsSuffix + '/$id' +
|
||||
final url = _baseProductApiUrl + _transactionsSuffix + '/$id' +
|
||||
'?apiKey=' + _apiKey;
|
||||
|
||||
final response = await get(url);
|
||||
|
@ -98,12 +100,23 @@ class MoonPayBuyProvider extends BuyProvider {
|
|||
final createdAt = DateTime.parse(createdAtRaw).toLocal();
|
||||
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(
|
||||
id: id,
|
||||
provider: description,
|
||||
transferId: id,
|
||||
from: _fiatCurrency,
|
||||
to: currencyCode.toUpperCase(),
|
||||
from: from,
|
||||
to: to,
|
||||
state: state,
|
||||
createdAt: createdAt,
|
||||
amount: amount.toString(),
|
||||
|
|
|
@ -80,7 +80,7 @@ class WyreBuyProvider extends BuyProvider {
|
|||
|
||||
@override
|
||||
Future<BuyAmount> calculateAmount(String amount, String sourceCurrency) async {
|
||||
final quoteUrl = baseApiUrl + _ordersSuffix + _quoteSuffix;
|
||||
final quoteUrl = _baseProductApiUrl + _ordersSuffix + _quoteSuffix;
|
||||
final body = {
|
||||
'amount': amount,
|
||||
'sourceCurrency': sourceCurrency,
|
||||
|
|
|
@ -238,7 +238,6 @@ Future setup(
|
|||
tradeFilterStore: getIt.get<TradeFilterStore>(),
|
||||
transactionFilterStore: getIt.get<TransactionFilterStore>(),
|
||||
settingsStore: settingsStore,
|
||||
ordersSource: _ordersSource,
|
||||
ordersStore: getIt.get<OrdersStore>()));
|
||||
|
||||
getIt.registerFactory<AuthService>(() => AuthService(
|
||||
|
@ -536,7 +535,7 @@ Future setup(
|
|||
getIt.registerFactory(() {
|
||||
final wallet = getIt.get<AppStore>().wallet;
|
||||
|
||||
return BuyViewModel(ordersSource, getIt.get<OrdersStore>(),
|
||||
return BuyViewModel(_ordersSource, getIt.get<OrdersStore>(),
|
||||
getIt.get<BuyAmountViewModel>(), wallet: wallet);
|
||||
});
|
||||
|
||||
|
@ -559,6 +558,7 @@ Future setup(
|
|||
|
||||
return OrderDetailsViewModel(
|
||||
wallet: wallet,
|
||||
ordersSource: _ordersSource,
|
||||
orderForDetails: order);
|
||||
});
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ abstract class BuyViewModelBase with Store {
|
|||
{@required this.wallet}) {
|
||||
providerList = [
|
||||
WyreBuyProvider(wallet: wallet),
|
||||
MoonPayBuyProvider(wallet: wallet)
|
||||
MoonPayBuyProvider(wallet: wallet, ordersSource: ordersSource)
|
||||
];
|
||||
items = providerList.map((provider) =>
|
||||
BuyItem(provider: provider, buyAmountViewModel: buyAmountViewModel))
|
||||
|
@ -79,6 +79,8 @@ abstract class BuyViewModelBase with Store {
|
|||
Future<void> saveOrder(String orderId) async {
|
||||
try {
|
||||
final order = await selectedProvider?.findOrderById(orderId);
|
||||
order.from = fiatCurrency.title;
|
||||
order.to = cryptoCurrency.title;
|
||||
await ordersSource.add(order);
|
||||
ordersStore.setOrder(order);
|
||||
} catch (e) {
|
||||
|
|
|
@ -57,7 +57,6 @@ abstract class DashboardViewModelBase with Store {
|
|||
this.tradeFilterStore,
|
||||
this.transactionFilterStore,
|
||||
this.settingsStore,
|
||||
this.ordersSource,
|
||||
this.ordersStore}) {
|
||||
filterItems = {
|
||||
S.current.transactions: [
|
||||
|
@ -212,8 +211,6 @@ abstract class DashboardViewModelBase with Store {
|
|||
|
||||
bool get hasRescan => wallet.type == WalletType.monero;
|
||||
|
||||
Box<Order> ordersSource;
|
||||
|
||||
BalanceViewModel balanceViewModel;
|
||||
|
||||
AppStore appStore;
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:cake_wallet/buy/buy_provider.dart';
|
|||
import 'package:cake_wallet/buy/buy_provider_description.dart';
|
||||
import 'package:cake_wallet/buy/order.dart';
|
||||
import 'package:cake_wallet/utils/date_formatter.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
|
||||
|
@ -18,7 +19,8 @@ class OrderDetailsViewModel = OrderDetailsViewModelBase
|
|||
with _$OrderDetailsViewModel;
|
||||
|
||||
abstract class OrderDetailsViewModelBase with Store {
|
||||
OrderDetailsViewModelBase({WalletBase wallet, Order orderForDetails}) {
|
||||
OrderDetailsViewModelBase({WalletBase wallet, this.ordersSource,
|
||||
Order orderForDetails}) {
|
||||
order = orderForDetails;
|
||||
|
||||
if (order.provider != null) {
|
||||
|
@ -27,7 +29,8 @@ abstract class OrderDetailsViewModelBase with Store {
|
|||
_provider = WyreBuyProvider(wallet: wallet);
|
||||
break;
|
||||
case BuyProviderDescription.moonPay:
|
||||
_provider = MoonPayBuyProvider(wallet: wallet);
|
||||
_provider =
|
||||
MoonPayBuyProvider(wallet: wallet, ordersSource: ordersSource);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +44,8 @@ abstract class OrderDetailsViewModelBase with Store {
|
|||
timer = Timer.periodic(Duration(seconds: 20), (_) async => _updateOrder());
|
||||
}
|
||||
|
||||
final Box<Order> ordersSource;
|
||||
|
||||
@observable
|
||||
Order order;
|
||||
|
||||
|
|
Loading…
Reference in a new issue