mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
Merge pull request #31 from cake-tech/CWA-169-add-morph-exchange-to-the-app
Cwa 169 add morph exchange to the app
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import 'package:cake_wallet/src/domain/common/crypto_amount_format.dart';
|
||||
|
||||
const bitcoinAmountDivider = 100000000;
|
||||
|
||||
double bitcoinAmountToDouble({int amount}) =>
|
||||
cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider);
|
||||
@@ -0,0 +1,6 @@
|
||||
import 'package:cake_wallet/src/domain/common/crypto_amount_format.dart';
|
||||
|
||||
const bitcoinCashAmountDivider = 100000000;
|
||||
|
||||
double bitcoinCashAmountToDouble({int amount}) =>
|
||||
cryptoAmountToDouble(amount: amount, divider: bitcoinCashAmountDivider);
|
||||
@@ -0,0 +1 @@
|
||||
double cryptoAmountToDouble({num amount, num divider}) => amount / divider;
|
||||
@@ -0,0 +1,8 @@
|
||||
String formatAmount(String amount) {
|
||||
if (!amount.contains('.')) {
|
||||
return amount + '.00';
|
||||
} else if (amount.endsWith('.')) {
|
||||
return amount + '00';
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:cake_wallet/src/domain/monero/monero_amount_format.dart';
|
||||
import 'package:cw_monero/structs/transaction_info_row.dart';
|
||||
import 'package:cake_wallet/src/domain/common/parseBoolFromString.dart';
|
||||
import 'package:cake_wallet/src/domain/common/transaction_direction.dart';
|
||||
import 'package:cake_wallet/src/domain/common/format_amount.dart';
|
||||
|
||||
class TransactionInfo {
|
||||
TransactionInfo(this.id, this.height, this.direction, this.date,
|
||||
@@ -40,9 +41,9 @@ class TransactionInfo {
|
||||
|
||||
String _fiatAmount;
|
||||
|
||||
String amountFormatted() => '${moneroAmountToString(amount: amount)} XMR';
|
||||
String amountFormatted() => '${formatAmount(moneroAmountToString(amount: amount))} XMR';
|
||||
|
||||
String fiatAmount() => _fiatAmount ?? '';
|
||||
|
||||
void changeFiatAmount(String amount) => _fiatAmount = amount;
|
||||
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import 'package:cake_wallet/src/domain/common/crypto_amount_format.dart';
|
||||
|
||||
const dashAmountDivider = 100000000;
|
||||
|
||||
double dashAmountToDouble({int amount}) =>
|
||||
cryptoAmountToDouble(amount: amount, divider: dashAmountDivider);
|
||||
@@ -0,0 +1,6 @@
|
||||
import 'package:cake_wallet/src/domain/common/crypto_amount_format.dart';
|
||||
|
||||
const ethereumAmountDivider = 1000000000000000000;
|
||||
|
||||
double ethereumAmountToDouble({num amount}) =>
|
||||
cryptoAmountToDouble(amount: amount, divider: ethereumAmountDivider);
|
||||
@@ -8,6 +8,8 @@ class ExchangeProviderDescription extends EnumerableItem<int>
|
||||
static const xmrto = ExchangeProviderDescription(title: 'XMR.TO', raw: 0);
|
||||
static const changeNow =
|
||||
ExchangeProviderDescription(title: 'ChangeNOW', raw: 1);
|
||||
static const morphToken =
|
||||
ExchangeProviderDescription(title: 'MorphToken', raw: 2);
|
||||
|
||||
static ExchangeProviderDescription deserialize({int raw}) {
|
||||
switch (raw) {
|
||||
@@ -15,6 +17,8 @@ class ExchangeProviderDescription extends EnumerableItem<int>
|
||||
return xmrto;
|
||||
case 1:
|
||||
return changeNow;
|
||||
case 2:
|
||||
return morphToken;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
import 'dart:convert';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade_not_found_exeption.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/exchange_pair.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/limits.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade_request.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade_state.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/morphtoken/morphtoken_request.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade_not_created_exeption.dart';
|
||||
import 'package:cake_wallet/src/domain/monero/monero_amount_format.dart';
|
||||
import 'package:cake_wallet/src/domain/bitcoin/bitcoin_amount_format.dart';
|
||||
import 'package:cake_wallet/src/domain/bitcoin_cash/bitcoin_cash_amount_format.dart';
|
||||
import 'package:cake_wallet/src/domain/dash/dash_amount_format.dart';
|
||||
import 'package:cake_wallet/src/domain/ethereum/ethereum_amount_format.dart';
|
||||
import 'package:cake_wallet/src/domain/litecoin/litecoin_amount_format.dart';
|
||||
|
||||
class MorphTokenExchangeProvider extends ExchangeProvider {
|
||||
MorphTokenExchangeProvider({@required this.trades})
|
||||
: super(
|
||||
pairList: [
|
||||
ExchangePair(from: CryptoCurrency.xmr, to: CryptoCurrency.eth),
|
||||
ExchangePair(from: CryptoCurrency.xmr, to: CryptoCurrency.bch),
|
||||
ExchangePair(from: CryptoCurrency.xmr, to: CryptoCurrency.ltc),
|
||||
ExchangePair(from: CryptoCurrency.xmr, to: CryptoCurrency.dash),
|
||||
|
||||
ExchangePair(from: CryptoCurrency.dash, to: CryptoCurrency.btc),
|
||||
ExchangePair(from: CryptoCurrency.dash, to: CryptoCurrency.eth),
|
||||
ExchangePair(from: CryptoCurrency.dash, to: CryptoCurrency.bch),
|
||||
ExchangePair(from: CryptoCurrency.dash, to: CryptoCurrency.ltc),
|
||||
ExchangePair(from: CryptoCurrency.dash, to: CryptoCurrency.xmr),
|
||||
|
||||
ExchangePair(from: CryptoCurrency.ltc, to: CryptoCurrency.btc),
|
||||
ExchangePair(from: CryptoCurrency.ltc, to: CryptoCurrency.eth),
|
||||
ExchangePair(from: CryptoCurrency.ltc, to: CryptoCurrency.bch),
|
||||
ExchangePair(from: CryptoCurrency.ltc, to: CryptoCurrency.dash),
|
||||
ExchangePair(from: CryptoCurrency.ltc, to: CryptoCurrency.xmr),
|
||||
|
||||
ExchangePair(from: CryptoCurrency.bch, to: CryptoCurrency.btc),
|
||||
ExchangePair(from: CryptoCurrency.bch, to: CryptoCurrency.eth),
|
||||
ExchangePair(from: CryptoCurrency.bch, to: CryptoCurrency.ltc),
|
||||
ExchangePair(from: CryptoCurrency.bch, to: CryptoCurrency.dash),
|
||||
ExchangePair(from: CryptoCurrency.bch, to: CryptoCurrency.xmr),
|
||||
|
||||
ExchangePair(from: CryptoCurrency.eth, to: CryptoCurrency.btc),
|
||||
ExchangePair(from: CryptoCurrency.eth, to: CryptoCurrency.bch),
|
||||
ExchangePair(from: CryptoCurrency.eth, to: CryptoCurrency.ltc),
|
||||
ExchangePair(from: CryptoCurrency.eth, to: CryptoCurrency.dash),
|
||||
ExchangePair(from: CryptoCurrency.eth, to: CryptoCurrency.xmr),
|
||||
|
||||
ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.eth),
|
||||
ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.bch),
|
||||
ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.ltc),
|
||||
ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.dash),
|
||||
ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.xmr)
|
||||
]);
|
||||
|
||||
Box<Trade> trades;
|
||||
|
||||
static const apiUri = 'https://api.morphtoken.com';
|
||||
static const _morphURISuffix = '/morph';
|
||||
static const _limitsURISuffix = '/limits';
|
||||
static const _ratesURISuffix = '/rates';
|
||||
static const weight = 10000;
|
||||
|
||||
@override
|
||||
String get title => 'MorphToken';
|
||||
|
||||
@override
|
||||
ExchangeProviderDescription get description =>
|
||||
ExchangeProviderDescription.morphToken;
|
||||
|
||||
@override
|
||||
Future<Limits> fetchLimits({CryptoCurrency from, CryptoCurrency to}) async {
|
||||
final url = apiUri + _limitsURISuffix;
|
||||
final headers = {'Content-type': 'application/json'};
|
||||
final body =
|
||||
json.encode({
|
||||
"input": {
|
||||
"asset": from.toString()
|
||||
},
|
||||
"output": [{
|
||||
"asset": to.toString(),
|
||||
"weight": weight
|
||||
}]});
|
||||
final response =
|
||||
await post(url, headers: headers, body: body);
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
|
||||
final min = responseJSON['input']['limits']['min'] as int;
|
||||
int max;
|
||||
double ethMax;
|
||||
|
||||
if (from == CryptoCurrency.eth) {
|
||||
ethMax = responseJSON['input']['limits']['max'] as double;
|
||||
} else {
|
||||
max = responseJSON['input']['limits']['max'] as int;
|
||||
}
|
||||
|
||||
double minFormatted;
|
||||
double maxFormatted;
|
||||
|
||||
switch (from) {
|
||||
case CryptoCurrency.xmr:
|
||||
minFormatted = moneroAmountToDouble(amount: min);
|
||||
maxFormatted = moneroAmountToDouble(amount: max);
|
||||
break;
|
||||
case CryptoCurrency.btc:
|
||||
minFormatted = bitcoinAmountToDouble(amount: min);
|
||||
maxFormatted = bitcoinAmountToDouble(amount: max);
|
||||
break;
|
||||
case CryptoCurrency.bch:
|
||||
minFormatted = bitcoinCashAmountToDouble(amount: min);
|
||||
maxFormatted = bitcoinCashAmountToDouble(amount: max);
|
||||
break;
|
||||
case CryptoCurrency.dash:
|
||||
minFormatted = dashAmountToDouble(amount: min);
|
||||
maxFormatted = dashAmountToDouble(amount: max);
|
||||
break;
|
||||
case CryptoCurrency.eth:
|
||||
minFormatted = ethereumAmountToDouble(amount: min);
|
||||
maxFormatted = ethereumAmountToDouble(amount: ethMax);
|
||||
break;
|
||||
case CryptoCurrency.ltc:
|
||||
minFormatted = litecoinAmountToDouble(amount: min);
|
||||
maxFormatted = litecoinAmountToDouble(amount: max);
|
||||
break;
|
||||
}
|
||||
|
||||
return Limits(min: minFormatted, max: maxFormatted);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Trade> createTrade({TradeRequest request}) async {
|
||||
const url = apiUri + _morphURISuffix;
|
||||
final _request = request as MorphTokenRequest;
|
||||
final body = {
|
||||
"input": {
|
||||
"asset": _request.from.toString(),
|
||||
"refund": _request.refundAddress
|
||||
},
|
||||
"output": [{
|
||||
"asset": _request.to.toString(),
|
||||
"weight": weight,
|
||||
"address": _request.address
|
||||
}],
|
||||
"tag": "cakewallet"
|
||||
};
|
||||
|
||||
final response = await post(url,
|
||||
headers: {'Content-Type': 'application/json'}, body: json.encode(body));
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
if (response.statusCode == 400) {
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final error = responseJSON['description'] as String;
|
||||
|
||||
throw TradeNotCreatedException(description, description: error);
|
||||
}
|
||||
|
||||
throw TradeNotCreatedException(description);
|
||||
}
|
||||
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final id = responseJSON['id'] as String;
|
||||
|
||||
return Trade(
|
||||
id: id,
|
||||
provider: description,
|
||||
from: _request.from,
|
||||
to: _request.to,
|
||||
state: TradeState.created,
|
||||
amount: _request.amount,
|
||||
createdAt: DateTime.now());
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Trade> findTradeById({@required String id}) async {
|
||||
final url = apiUri + _morphURISuffix + '/' + id;
|
||||
final response = await get(url);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
if (response.statusCode == 400) {
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final error = responseJSON['description'] as String;
|
||||
|
||||
throw TradeNotFoundException(id,
|
||||
provider: description, description: error);
|
||||
}
|
||||
|
||||
throw TradeNotFoundException(id, provider: description);
|
||||
}
|
||||
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final fromCurrency = responseJSON['input']['asset'] as String;
|
||||
final from = CryptoCurrency.fromString(fromCurrency.toLowerCase());
|
||||
final toCurrency = responseJSON['output'][0]['asset'] as String;
|
||||
final to = CryptoCurrency.fromString(toCurrency.toLowerCase());
|
||||
final inputAddress = responseJSON['input']['deposit_address'] as String;
|
||||
final status = responseJSON['state'] as String;
|
||||
final state = TradeState.deserialize(raw: status.toLowerCase());
|
||||
|
||||
String amount = "";
|
||||
for (final trade in trades.values) {
|
||||
if (trade.id == id) {
|
||||
amount = trade.amount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Trade(
|
||||
id: id,
|
||||
from: from,
|
||||
to: to,
|
||||
provider: description,
|
||||
inputAddress: inputAddress,
|
||||
amount: amount,
|
||||
state: state);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<double> calculateAmount(
|
||||
{CryptoCurrency from, CryptoCurrency to, double amount}) async {
|
||||
final url = apiUri + _ratesURISuffix;
|
||||
final response = await get(url);
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final rate = responseJSON['data'][from.toString()][to.toString()] as String;
|
||||
|
||||
try {
|
||||
final estimatedAmount = double.parse(rate) * amount;
|
||||
return estimatedAmount;
|
||||
} catch(e) {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade_request.dart';
|
||||
|
||||
class MorphTokenRequest extends TradeRequest {
|
||||
MorphTokenRequest(
|
||||
{@required this.from,
|
||||
@required this.to,
|
||||
@required this.address,
|
||||
@required this.amount,
|
||||
@required this.refundAddress});
|
||||
|
||||
CryptoCurrency from;
|
||||
CryptoCurrency to;
|
||||
String address;
|
||||
String amount;
|
||||
String refundAddress;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:hive/hive.dart';
|
||||
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade_state.dart';
|
||||
import 'package:cake_wallet/src/domain/common/format_amount.dart';
|
||||
|
||||
part 'trade.g.dart';
|
||||
|
||||
@@ -101,4 +102,6 @@ class Trade extends HiveObject {
|
||||
'wallet_id': walletId
|
||||
};
|
||||
}
|
||||
|
||||
String amountFormatted() => formatAmount(amount);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ class TradeState extends EnumerableItem<String> with Serializable<String> {
|
||||
static const created = TradeState(raw: 'created', title: 'Created');
|
||||
static const finished = TradeState(raw: 'finished', title: 'Finished');
|
||||
static const waiting = TradeState(raw: 'waiting', title: 'Waiting');
|
||||
static const processing = TradeState(raw: 'processing', title: 'Processing');
|
||||
|
||||
static TradeState deserialize({String raw}) {
|
||||
switch (raw) {
|
||||
@@ -59,6 +60,8 @@ class TradeState extends EnumerableItem<String> with Serializable<String> {
|
||||
return finished;
|
||||
case 'waiting':
|
||||
return waiting;
|
||||
case 'processing':
|
||||
return processing;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import 'package:cake_wallet/src/domain/common/crypto_amount_format.dart';
|
||||
|
||||
const litecoinAmountDivider = 100000000;
|
||||
|
||||
double litecoinAmountToDouble({int amount}) =>
|
||||
cryptoAmountToDouble(amount: amount, divider: litecoinAmountDivider);
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:cake_wallet/src/domain/common/crypto_amount_format.dart';
|
||||
|
||||
const moneroAmountLength = 12;
|
||||
const moneroAmountDivider = 1000000000000;
|
||||
@@ -7,6 +8,6 @@ final moneroAmountFormat = NumberFormat()
|
||||
..minimumFractionDigits = 1;
|
||||
|
||||
String moneroAmountToString({int amount}) =>
|
||||
moneroAmountFormat.format(amount / moneroAmountDivider);
|
||||
moneroAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider));
|
||||
|
||||
double moneroAmountToDouble({int amount}) => amount / moneroAmountDivider;
|
||||
double moneroAmountToDouble({int amount}) => cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider);
|
||||
|
||||
@@ -480,7 +480,28 @@ class DashboardPageBodyState extends State<DashboardPageBody> {
|
||||
ExchangeProviderDescription
|
||||
.changeNow),
|
||||
)
|
||||
])))
|
||||
]))),
|
||||
PopupMenuItem(
|
||||
value: 5,
|
||||
child: Observer(
|
||||
builder: (_) => Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment
|
||||
.spaceBetween,
|
||||
children: [
|
||||
Text('MorphToken'),
|
||||
Checkbox(
|
||||
value: actionListStore
|
||||
.tradeFilterStore
|
||||
.displayMorphToken,
|
||||
onChanged: (value) =>
|
||||
actionListStore
|
||||
.tradeFilterStore
|
||||
.toggleDisplayExchange(
|
||||
ExchangeProviderDescription
|
||||
.morphToken),
|
||||
)
|
||||
])))
|
||||
],
|
||||
child: Text(S.of(context).filters,
|
||||
style: TextStyle(
|
||||
@@ -556,7 +577,7 @@ class DashboardPageBodyState extends State<DashboardPageBody> {
|
||||
final formattedAmount = trade.amount != null
|
||||
? savedDisplayMode == BalanceDisplayMode.hiddenBalance
|
||||
? '---'
|
||||
: trade.amount
|
||||
: trade.amountFormatted()
|
||||
: trade.amount;
|
||||
|
||||
return TradeRow(
|
||||
|
||||
@@ -82,6 +82,9 @@ class TradeRow extends StatelessWidget {
|
||||
case ExchangeProviderDescription.changeNow:
|
||||
image = Image.asset('assets/images/change_now.png');
|
||||
break;
|
||||
case ExchangeProviderDescription.morphToken:
|
||||
image = Image.asset('assets/images/morph_icon.png');
|
||||
break;
|
||||
default:
|
||||
image = null;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ class DisclaimerBodyState extends State<DisclaimerPageBody> {
|
||||
|
||||
static const xmrtoUrl = 'https://xmr.to/app_static/html/tos.html';
|
||||
static const changenowUrl = 'https://changenow.io/terms-of-use';
|
||||
static const morphUrl = 'http://morphtoken.com/terms';
|
||||
|
||||
final bool _isAccepted;
|
||||
bool _checked = false;
|
||||
@@ -197,6 +198,27 @@ class DisclaimerBodyState extends State<DisclaimerPageBody> {
|
||||
))
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 16.0,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => launchUrl(morphUrl),
|
||||
child: Text(
|
||||
morphUrl,
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
color: Colors.blue,
|
||||
fontSize: 14.0,
|
||||
fontWeight: FontWeight.normal,
|
||||
decoration: TextDecoration.underline),
|
||||
),
|
||||
))
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 16.0,
|
||||
)
|
||||
|
||||
@@ -278,6 +278,9 @@ class ExchangeFormState extends State<ExchangeForm> {
|
||||
case ExchangeProviderDescription.changeNow:
|
||||
imageSrc = 'assets/images/change_now.png';
|
||||
break;
|
||||
case ExchangeProviderDescription.morphToken:
|
||||
imageSrc = 'assets/images/morph_icon.png';
|
||||
break;
|
||||
}
|
||||
|
||||
return Padding(
|
||||
|
||||
@@ -51,12 +51,14 @@ class SettingsFormState extends State<SettingsForm> {
|
||||
final _twitterImage = Image.asset('assets/images/Twitter.png');
|
||||
final _changeNowImage = Image.asset('assets/images/change_now.png');
|
||||
final _xmrBtcImage = Image.asset('assets/images/xmr_btc.png');
|
||||
final _morphImage = Image.asset('assets/images/morph_icon.png');
|
||||
|
||||
final _emailUrl = 'mailto:support@cakewallet.com';
|
||||
final _telegramUrl = 'https:t.me/cakewallet_bot';
|
||||
final _twitterUrl = 'https:twitter.com/CakewalletXMR';
|
||||
final _changeNowUrl = 'mailto:support@changenow.io';
|
||||
final _xmrToUrl = 'mailto:support@xmr.to';
|
||||
final _morphUrl = 'mailto:support@morphtoken.com';
|
||||
|
||||
final _items = List<SettingsItem>();
|
||||
|
||||
@@ -267,6 +269,12 @@ class SettingsFormState extends State<SettingsForm> {
|
||||
link: 'support@xmr.to',
|
||||
image: _xmrBtcImage,
|
||||
attribute: Attributes.link),
|
||||
SettingsItem(
|
||||
onTaped: () => _launchUrl(_morphUrl),
|
||||
title: 'MorphToken',
|
||||
link: 'support@morphtoken.com',
|
||||
image: _morphImage,
|
||||
attribute: Attributes.link),
|
||||
SettingsItem(
|
||||
onTaped: () {
|
||||
Navigator.push(
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:cake_wallet/src/stores/exchange_trade/exchange_trade_store.dart'
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
|
||||
import 'package:cake_wallet/src/screens/transaction_details/standart_list_row.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class TradeDetailsPage extends BasePage {
|
||||
@override
|
||||
@@ -16,6 +17,8 @@ class TradeDetailsPage extends BasePage {
|
||||
@override
|
||||
bool get isModalBackButton => true;
|
||||
|
||||
final createdAtFormat = DateFormat('yyyy-MM-dd HH:mm:ss');
|
||||
|
||||
@override
|
||||
Widget body(BuildContext context) {
|
||||
final exchangeStore = Provider.of<ExchangeTradeStore>(context);
|
||||
@@ -43,7 +46,7 @@ class TradeDetailsPage extends BasePage {
|
||||
if (trade.createdAt != null) {
|
||||
items.add(StandartListItem(
|
||||
title: S.of(context).trade_details_created_at,
|
||||
value: trade.createdAt.toString()));
|
||||
value: createdAtFormat.format(trade.createdAt).toString()));
|
||||
}
|
||||
|
||||
if (trade.from != null && trade.to != null) {
|
||||
|
||||
@@ -11,6 +11,7 @@ abstract class TradeFilterStoreBase with Store {
|
||||
TradeFilterStoreBase(
|
||||
{this.displayXMRTO = true,
|
||||
this.displayChangeNow = true,
|
||||
this.displayMorphToken = true,
|
||||
this.walletStore});
|
||||
|
||||
@observable
|
||||
@@ -19,6 +20,9 @@ abstract class TradeFilterStoreBase with Store {
|
||||
@observable
|
||||
bool displayChangeNow;
|
||||
|
||||
@observable
|
||||
bool displayMorphToken;
|
||||
|
||||
WalletStore walletStore;
|
||||
|
||||
@action
|
||||
@@ -30,13 +34,16 @@ abstract class TradeFilterStoreBase with Store {
|
||||
case ExchangeProviderDescription.xmrto:
|
||||
displayXMRTO = !displayXMRTO;
|
||||
break;
|
||||
case ExchangeProviderDescription.morphToken:
|
||||
displayMorphToken = !displayMorphToken;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
List<TradeListItem> filtered({List<TradeListItem> trades}) {
|
||||
final _trades =
|
||||
trades.where((item) => item.trade.walletId == walletStore.id).toList();
|
||||
final needToFilter = !displayChangeNow || !displayXMRTO;
|
||||
final needToFilter = !displayChangeNow || !displayXMRTO || !displayMorphToken;
|
||||
|
||||
return needToFilter
|
||||
? trades
|
||||
@@ -45,7 +52,10 @@ abstract class TradeFilterStoreBase with Store {
|
||||
item.trade.provider == ExchangeProviderDescription.xmrto) ||
|
||||
(displayChangeNow &&
|
||||
item.trade.provider ==
|
||||
ExchangeProviderDescription.changeNow))
|
||||
ExchangeProviderDescription.changeNow) ||
|
||||
(displayMorphToken &&
|
||||
item.trade.provider ==
|
||||
ExchangeProviderDescription.morphToken))
|
||||
.toList()
|
||||
: _trades;
|
||||
}
|
||||
|
||||
@@ -8,11 +8,15 @@ import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade_request.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/xmrto/xmrto_exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/xmrto/xmrto_trade_request.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/morphtoken/morphtoken_exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/morphtoken/morphtoken_request.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade.dart';
|
||||
import 'package:cake_wallet/src/stores/wallet/wallet_store.dart';
|
||||
import 'package:cake_wallet/src/stores/exchange/exchange_trade_state.dart';
|
||||
import 'package:cake_wallet/src/stores/exchange/limits_state.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/limits.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
part 'exchange_store.g.dart';
|
||||
|
||||
@@ -31,6 +35,7 @@ abstract class ExchangeStoreBase with Store {
|
||||
receiveCurrency = initialReceiveCurrency;
|
||||
limitsState = LimitsInitialState();
|
||||
tradeState = ExchangeTradeStateInitial();
|
||||
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12;
|
||||
loadLimits();
|
||||
}
|
||||
|
||||
@@ -72,11 +77,16 @@ abstract class ExchangeStoreBase with Store {
|
||||
|
||||
WalletStore walletStore;
|
||||
|
||||
Limits limits;
|
||||
|
||||
NumberFormat _cryptoNumberFormat;
|
||||
|
||||
@action
|
||||
void changeProvider({ExchangeProvider provider}) {
|
||||
this.provider = provider;
|
||||
depositAmount = '';
|
||||
receiveAmount = '';
|
||||
loadLimits();
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -105,7 +115,7 @@ abstract class ExchangeStoreBase with Store {
|
||||
provider
|
||||
.calculateAmount(
|
||||
from: depositCurrency, to: receiveCurrency, amount: _amount)
|
||||
.then((amount) => amount.toString())
|
||||
.then((amount) => _cryptoNumberFormat.format(amount).toString().replaceAll(RegExp("\\,"), ""))
|
||||
.then((amount) => depositAmount = amount);
|
||||
}
|
||||
|
||||
@@ -122,7 +132,7 @@ abstract class ExchangeStoreBase with Store {
|
||||
provider
|
||||
.calculateAmount(
|
||||
from: depositCurrency, to: receiveCurrency, amount: _amount)
|
||||
.then((amount) => amount.toString())
|
||||
.then((amount) => _cryptoNumberFormat.format(amount).toString().replaceAll(RegExp("\\,"), ""))
|
||||
.then((amount) => receiveAmount = amount);
|
||||
}
|
||||
|
||||
@@ -131,7 +141,7 @@ abstract class ExchangeStoreBase with Store {
|
||||
limitsState = LimitsIsLoading();
|
||||
|
||||
try {
|
||||
final limits = await provider.fetchLimits(
|
||||
limits = await provider.fetchLimits(
|
||||
from: depositCurrency, to: receiveCurrency);
|
||||
limitsState = LimitsLoadedSuccessfully(limits: limits);
|
||||
} catch (e) {
|
||||
@@ -142,6 +152,8 @@ abstract class ExchangeStoreBase with Store {
|
||||
@action
|
||||
Future createTrade() async {
|
||||
TradeRequest request;
|
||||
String amount;
|
||||
CryptoCurrency currency;
|
||||
|
||||
if (provider is XMRTOExchangeProvider) {
|
||||
request = XMRTOTradeRequest(
|
||||
@@ -150,6 +162,8 @@ abstract class ExchangeStoreBase with Store {
|
||||
amount: receiveAmount,
|
||||
address: receiveAddress,
|
||||
refundAddress: depositAddress);
|
||||
amount = receiveAmount;
|
||||
currency = receiveCurrency;
|
||||
}
|
||||
|
||||
if (provider is ChangeNowExchangeProvider) {
|
||||
@@ -159,17 +173,43 @@ abstract class ExchangeStoreBase with Store {
|
||||
amount: depositAmount,
|
||||
refundAddress: depositAddress,
|
||||
address: receiveAddress);
|
||||
amount = depositAmount;
|
||||
currency = depositCurrency;
|
||||
}
|
||||
|
||||
try {
|
||||
tradeState = TradeIsCreating();
|
||||
final trade = await provider.createTrade(request: request);
|
||||
trade.walletId = walletStore.id;
|
||||
await trades.add(trade);
|
||||
tradeState = TradeIsCreatedSuccessfully(trade: trade);
|
||||
} catch (e) {
|
||||
tradeState = TradeIsCreatedFailure(error: e.toString());
|
||||
if (provider is MorphTokenExchangeProvider) {
|
||||
request = MorphTokenRequest(
|
||||
from: depositCurrency,
|
||||
to: receiveCurrency,
|
||||
amount: depositAmount,
|
||||
refundAddress: depositAddress,
|
||||
address: receiveAddress);
|
||||
amount = depositAmount;
|
||||
currency = depositCurrency;
|
||||
}
|
||||
|
||||
if (limitsState is LimitsLoadedSuccessfully && amount != null) {
|
||||
if (double.parse(amount) < limits.min) {
|
||||
tradeState = TradeIsCreatedFailure(error: S.current.error_text_minimal_limit("${provider.description}",
|
||||
"${limits.min}", currency.toString()));
|
||||
} else if (limits.max != null && double.parse(amount) > limits.max) {
|
||||
tradeState = TradeIsCreatedFailure(error: S.current.error_text_maximum_limit("${provider.description}",
|
||||
"${limits.max}", currency.toString()));
|
||||
} else {
|
||||
try {
|
||||
tradeState = TradeIsCreating();
|
||||
final trade = await provider.createTrade(request: request);
|
||||
trade.walletId = walletStore.id;
|
||||
await trades.add(trade);
|
||||
tradeState = TradeIsCreatedSuccessfully(trade: trade);
|
||||
} catch (e) {
|
||||
tradeState = TradeIsCreatedFailure(error: e.toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tradeState = TradeIsCreatedFailure(error: S.current.error_text_limits_loading_failed("${provider.description}"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -181,6 +221,7 @@ abstract class ExchangeStoreBase with Store {
|
||||
provider = XMRTOExchangeProvider();
|
||||
depositCurrency = CryptoCurrency.xmr;
|
||||
receiveCurrency = CryptoCurrency.btc;
|
||||
loadLimits();
|
||||
}
|
||||
|
||||
List<ExchangeProvider> providersForCurrentPair() {
|
||||
|
||||
@@ -6,7 +6,9 @@ import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/changenow/changenow_exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/xmrto/xmrto_exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/morphtoken/morphtoken_exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/stores/wallet/wallet_store.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
part 'exchange_trade_store.g.dart';
|
||||
|
||||
@@ -14,7 +16,7 @@ class ExchangeTradeStore = ExchangeTradeStoreBase with _$ExchangeTradeStore;
|
||||
|
||||
abstract class ExchangeTradeStoreBase with Store {
|
||||
ExchangeTradeStoreBase(
|
||||
{@required this.trade, @required WalletStore walletStore}) {
|
||||
{@required this.trade, @required WalletStore walletStore, @required this.trades}) {
|
||||
isSendable = trade.from == walletStore.type ||
|
||||
trade.provider == ExchangeProviderDescription.xmrto;
|
||||
|
||||
@@ -25,6 +27,9 @@ abstract class ExchangeTradeStoreBase with Store {
|
||||
case ExchangeProviderDescription.changeNow:
|
||||
_provider = ChangeNowExchangeProvider();
|
||||
break;
|
||||
case ExchangeProviderDescription.morphToken:
|
||||
_provider = MorphTokenExchangeProvider(trades: trades);
|
||||
break;
|
||||
}
|
||||
|
||||
_updateTrade();
|
||||
@@ -37,6 +42,8 @@ abstract class ExchangeTradeStoreBase with Store {
|
||||
@observable
|
||||
bool isSendable;
|
||||
|
||||
Box<Trade> trades;
|
||||
|
||||
ExchangeProvider _provider;
|
||||
|
||||
Timer _timer;
|
||||
|
||||
Reference in New Issue
Block a user