mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-24 11:36:21 +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 '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';
|
||||||
|
@ -11,7 +12,8 @@ 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, bool isTestEnvironment = false})
|
MoonPayBuyProvider({WalletBase wallet, this.ordersSource,
|
||||||
|
bool isTestEnvironment = false})
|
||||||
: super(wallet: wallet, isTestEnvironment: isTestEnvironment) {
|
: super(wallet: wallet, isTestEnvironment: isTestEnvironment) {
|
||||||
baseApiUrl = isTestEnvironment
|
baseApiUrl = isTestEnvironment
|
||||||
? _baseTestApiUrl
|
? _baseTestApiUrl
|
||||||
|
@ -23,7 +25,6 @@ class MoonPayBuyProvider extends BuyProvider {
|
||||||
static const _currenciesSuffix = '/v3/currencies';
|
static const _currenciesSuffix = '/v3/currencies';
|
||||||
static const _quoteSuffix = '/buy_quote';
|
static const _quoteSuffix = '/buy_quote';
|
||||||
static const _transactionsSuffix = '/v1/transactions';
|
static const _transactionsSuffix = '/v1/transactions';
|
||||||
static const _fiatCurrency = 'USD';
|
|
||||||
static const _apiKey = secrets.moonPayApiKey;
|
static const _apiKey = secrets.moonPayApiKey;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -38,6 +39,7 @@ 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
|
||||||
|
@ -58,7 +60,7 @@ class MoonPayBuyProvider extends BuyProvider {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<BuyAmount> calculateAmount(String amount, String sourceCurrency) async {
|
Future<BuyAmount> calculateAmount(String amount, String sourceCurrency) async {
|
||||||
final url = baseApiUrl + _currenciesSuffix + '/$currencyCode' +
|
final url = _baseProductApiUrl + _currenciesSuffix + '/$currencyCode' +
|
||||||
_quoteSuffix + '/?apiKey=' + _apiKey +
|
_quoteSuffix + '/?apiKey=' + _apiKey +
|
||||||
'&baseCurrencyAmount=' + amount +
|
'&baseCurrencyAmount=' + amount +
|
||||||
'&baseCurrencyCode' + sourceCurrency.toLowerCase();
|
'&baseCurrencyCode' + sourceCurrency.toLowerCase();
|
||||||
|
@ -80,7 +82,7 @@ class MoonPayBuyProvider extends BuyProvider {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Order> findOrderById(String id) async {
|
Future<Order> findOrderById(String id) async {
|
||||||
final url = baseApiUrl + _transactionsSuffix + '/$id' +
|
final url = _baseProductApiUrl + _transactionsSuffix + '/$id' +
|
||||||
'?apiKey=' + _apiKey;
|
'?apiKey=' + _apiKey;
|
||||||
|
|
||||||
final response = await get(url);
|
final response = await get(url);
|
||||||
|
@ -98,12 +100,23 @@ 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: _fiatCurrency,
|
from: from,
|
||||||
to: currencyCode.toUpperCase(),
|
to: to,
|
||||||
state: state,
|
state: state,
|
||||||
createdAt: createdAt,
|
createdAt: createdAt,
|
||||||
amount: amount.toString(),
|
amount: amount.toString(),
|
||||||
|
|
|
@ -80,7 +80,7 @@ class WyreBuyProvider extends BuyProvider {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<BuyAmount> calculateAmount(String amount, String sourceCurrency) async {
|
Future<BuyAmount> calculateAmount(String amount, String sourceCurrency) async {
|
||||||
final quoteUrl = baseApiUrl + _ordersSuffix + _quoteSuffix;
|
final quoteUrl = _baseProductApiUrl + _ordersSuffix + _quoteSuffix;
|
||||||
final body = {
|
final body = {
|
||||||
'amount': amount,
|
'amount': amount,
|
||||||
'sourceCurrency': sourceCurrency,
|
'sourceCurrency': sourceCurrency,
|
||||||
|
|
|
@ -238,7 +238,6 @@ Future setup(
|
||||||
tradeFilterStore: getIt.get<TradeFilterStore>(),
|
tradeFilterStore: getIt.get<TradeFilterStore>(),
|
||||||
transactionFilterStore: getIt.get<TransactionFilterStore>(),
|
transactionFilterStore: getIt.get<TransactionFilterStore>(),
|
||||||
settingsStore: settingsStore,
|
settingsStore: settingsStore,
|
||||||
ordersSource: _ordersSource,
|
|
||||||
ordersStore: getIt.get<OrdersStore>()));
|
ordersStore: getIt.get<OrdersStore>()));
|
||||||
|
|
||||||
getIt.registerFactory<AuthService>(() => AuthService(
|
getIt.registerFactory<AuthService>(() => AuthService(
|
||||||
|
@ -536,7 +535,7 @@ Future setup(
|
||||||
getIt.registerFactory(() {
|
getIt.registerFactory(() {
|
||||||
final wallet = getIt.get<AppStore>().wallet;
|
final wallet = getIt.get<AppStore>().wallet;
|
||||||
|
|
||||||
return BuyViewModel(ordersSource, getIt.get<OrdersStore>(),
|
return BuyViewModel(_ordersSource, getIt.get<OrdersStore>(),
|
||||||
getIt.get<BuyAmountViewModel>(), wallet: wallet);
|
getIt.get<BuyAmountViewModel>(), wallet: wallet);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -559,6 +558,7 @@ Future setup(
|
||||||
|
|
||||||
return OrderDetailsViewModel(
|
return OrderDetailsViewModel(
|
||||||
wallet: wallet,
|
wallet: wallet,
|
||||||
|
ordersSource: _ordersSource,
|
||||||
orderForDetails: order);
|
orderForDetails: order);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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)
|
MoonPayBuyProvider(wallet: wallet, ordersSource: ordersSource)
|
||||||
];
|
];
|
||||||
items = providerList.map((provider) =>
|
items = providerList.map((provider) =>
|
||||||
BuyItem(provider: provider, buyAmountViewModel: buyAmountViewModel))
|
BuyItem(provider: provider, buyAmountViewModel: buyAmountViewModel))
|
||||||
|
@ -79,6 +79,8 @@ abstract class BuyViewModelBase with Store {
|
||||||
Future<void> saveOrder(String orderId) async {
|
Future<void> saveOrder(String orderId) async {
|
||||||
try {
|
try {
|
||||||
final order = await selectedProvider?.findOrderById(orderId);
|
final order = await selectedProvider?.findOrderById(orderId);
|
||||||
|
order.from = fiatCurrency.title;
|
||||||
|
order.to = cryptoCurrency.title;
|
||||||
await ordersSource.add(order);
|
await ordersSource.add(order);
|
||||||
ordersStore.setOrder(order);
|
ordersStore.setOrder(order);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -57,7 +57,6 @@ abstract class DashboardViewModelBase with Store {
|
||||||
this.tradeFilterStore,
|
this.tradeFilterStore,
|
||||||
this.transactionFilterStore,
|
this.transactionFilterStore,
|
||||||
this.settingsStore,
|
this.settingsStore,
|
||||||
this.ordersSource,
|
|
||||||
this.ordersStore}) {
|
this.ordersStore}) {
|
||||||
filterItems = {
|
filterItems = {
|
||||||
S.current.transactions: [
|
S.current.transactions: [
|
||||||
|
@ -212,8 +211,6 @@ abstract class DashboardViewModelBase with Store {
|
||||||
|
|
||||||
bool get hasRescan => wallet.type == WalletType.monero;
|
bool get hasRescan => wallet.type == WalletType.monero;
|
||||||
|
|
||||||
Box<Order> ordersSource;
|
|
||||||
|
|
||||||
BalanceViewModel balanceViewModel;
|
BalanceViewModel balanceViewModel;
|
||||||
|
|
||||||
AppStore appStore;
|
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/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';
|
||||||
|
@ -18,7 +19,8 @@ class OrderDetailsViewModel = OrderDetailsViewModelBase
|
||||||
with _$OrderDetailsViewModel;
|
with _$OrderDetailsViewModel;
|
||||||
|
|
||||||
abstract class OrderDetailsViewModelBase with Store {
|
abstract class OrderDetailsViewModelBase with Store {
|
||||||
OrderDetailsViewModelBase({WalletBase wallet, Order orderForDetails}) {
|
OrderDetailsViewModelBase({WalletBase wallet, this.ordersSource,
|
||||||
|
Order orderForDetails}) {
|
||||||
order = orderForDetails;
|
order = orderForDetails;
|
||||||
|
|
||||||
if (order.provider != null) {
|
if (order.provider != null) {
|
||||||
|
@ -27,7 +29,8 @@ abstract class OrderDetailsViewModelBase with Store {
|
||||||
_provider = WyreBuyProvider(wallet: wallet);
|
_provider = WyreBuyProvider(wallet: wallet);
|
||||||
break;
|
break;
|
||||||
case BuyProviderDescription.moonPay:
|
case BuyProviderDescription.moonPay:
|
||||||
_provider = MoonPayBuyProvider(wallet: wallet);
|
_provider =
|
||||||
|
MoonPayBuyProvider(wallet: wallet, ordersSource: ordersSource);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +44,8 @@ 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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue