mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-21 06:18:42 +02:00
CAKE-306 | added MoonPay option for BTC buying; applied PreOrderPage to the app; created Wyre and MoonPay buy providers
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:cake_wallet/exchange/trade_state.dart';
|
||||
import 'package:cake_wallet/entities/format_amount.dart';
|
||||
|
||||
part 'order.g.dart';
|
||||
|
||||
@HiveType(typeId: Order.typeId)
|
||||
class Order extends HiveObject {
|
||||
Order(
|
||||
{this.id,
|
||||
this.transferId,
|
||||
this.from,
|
||||
this.to,
|
||||
TradeState state,
|
||||
this.createdAt,
|
||||
this.amount,
|
||||
this.receiveAddress,
|
||||
this.walletId})
|
||||
: stateRaw = state?.raw;
|
||||
|
||||
static const typeId = 8;
|
||||
static const boxName = 'Orders';
|
||||
static const boxKey = 'ordersBoxKey';
|
||||
|
||||
@HiveField(0)
|
||||
String id;
|
||||
|
||||
@HiveField(1)
|
||||
String transferId;
|
||||
|
||||
@HiveField(2)
|
||||
String from;
|
||||
|
||||
@HiveField(3)
|
||||
String to;
|
||||
|
||||
@HiveField(4)
|
||||
String stateRaw;
|
||||
|
||||
TradeState get state => TradeState.deserialize(raw: stateRaw);
|
||||
|
||||
@HiveField(5)
|
||||
DateTime createdAt;
|
||||
|
||||
@HiveField(6)
|
||||
String amount;
|
||||
|
||||
@HiveField(7)
|
||||
String receiveAddress;
|
||||
|
||||
@HiveField(8)
|
||||
String walletId;
|
||||
|
||||
String amountFormatted() => formatAmount(amount);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import 'package:cake_wallet/exchange/trade_state.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
import 'package:cake_wallet/entities/order.dart';
|
||||
import 'package:cake_wallet/buy/order.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
|
||||
class WyreService {
|
||||
@@ -26,6 +26,7 @@ class WyreService {
|
||||
static const _trackProductUrl = 'https://dash.sendwyre.com/track/';
|
||||
static const _ordersSuffix = '/v3/orders';
|
||||
static const _reserveSuffix = '/reserve';
|
||||
static const _quoteSuffix = '/quote/partner';
|
||||
static const _timeStampSuffix = '?timestamp=';
|
||||
static const _transferSuffix = '/v2/transfer/';
|
||||
static const _trackSuffix = '/track';
|
||||
@@ -47,10 +48,12 @@ class WyreService {
|
||||
final secretKey = secrets.wyreSecretKey;
|
||||
final accountId = secrets.wyreAccountId;
|
||||
final body = {
|
||||
'amount': '1',
|
||||
'sourceCurrency': 'USD',
|
||||
'destCurrency': walletTypeToCryptoCurrency(walletType).title,
|
||||
'dest': walletTypeToString(walletType).toLowerCase() + ':' + walletAddress,
|
||||
'referrerAccountId': accountId,
|
||||
'lockFields': ['destCurrency', 'dest']
|
||||
'lockFields': ['amount', 'sourceCurrency', 'destCurrency', 'dest']
|
||||
};
|
||||
|
||||
final response = await post(url,
|
||||
@@ -113,4 +116,36 @@ class WyreService {
|
||||
walletId: walletId
|
||||
);
|
||||
}
|
||||
|
||||
Future<double> getAmount() async {
|
||||
final quoteUrl = baseApiUrl + _ordersSuffix + _quoteSuffix;
|
||||
|
||||
final secretKey = secrets.wyreSecretKey;
|
||||
final accountId = secrets.wyreAccountId;
|
||||
final body = {
|
||||
'amount': '1',
|
||||
'sourceCurrency': 'USD',
|
||||
'destCurrency': walletTypeToCryptoCurrency(walletType).title,
|
||||
'dest': walletTypeToString(walletType).toLowerCase() + ':' + walletAddress,
|
||||
'accountId': accountId,
|
||||
'country': 'US'
|
||||
};
|
||||
|
||||
final response = await post(quoteUrl,
|
||||
headers: {
|
||||
'Authorization': 'Bearer $secretKey',
|
||||
'Content-Type': 'application/json',
|
||||
'cache-control': 'no-cache'
|
||||
},
|
||||
body: json.encode(body));
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw WyreException('Quote is not found! ');
|
||||
}
|
||||
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final amount = responseJSON['destAmount'] as double;
|
||||
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user