mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 03:59:23 +00:00
CWA-169 | added tag to body of createTrade(), created crypto_amount_format, bitcoin_amount_format, bitcoin_cash_amount_format, dash_amount_format, ethereum_amount_format, litecoin_amount_format, changed monero_amount_format, added setup_locator for inject the box
This commit is contained in:
parent
eb875b1321
commit
163d1c48a4
12 changed files with 80 additions and 13 deletions
|
@ -35,6 +35,7 @@ import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
|||
import 'package:cake_wallet/src/domain/services/wallet_service.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/domain/common/language.dart';
|
||||
import 'package:cake_wallet/src/domain/common/setup_locator.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
@ -65,6 +66,8 @@ void main() async {
|
|||
await Hive.openBox<Trade>(Trade.boxName, encryptionKey: tradesBoxKey);
|
||||
final walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName);
|
||||
|
||||
setupLocator(trades);
|
||||
|
||||
final sharedPreferences = await SharedPreferences.getInstance();
|
||||
final walletService = WalletService();
|
||||
final walletListService = WalletListService(
|
||||
|
|
6
lib/src/domain/bitcoin/bitcoin_amount_format.dart
Normal file
6
lib/src/domain/bitcoin/bitcoin_amount_format.dart
Normal file
|
@ -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);
|
1
lib/src/domain/common/crypto_amount_format.dart
Normal file
1
lib/src/domain/common/crypto_amount_format.dart
Normal file
|
@ -0,0 +1 @@
|
|||
double cryptoAmountToDouble({num amount, num divider}) => amount / divider;
|
7
lib/src/domain/common/setup_locator.dart
Normal file
7
lib/src/domain/common/setup_locator.dart
Normal file
|
@ -0,0 +1,7 @@
|
|||
import 'package:get_it/get_it.dart';
|
||||
|
||||
GetIt locator = GetIt.instance;
|
||||
|
||||
void setupLocator<T>(T instance) {
|
||||
locator.registerSingleton<T>(instance);
|
||||
}
|
6
lib/src/domain/dash/dash_amount_format.dart
Normal file
6
lib/src/domain/dash/dash_amount_format.dart
Normal file
|
@ -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);
|
6
lib/src/domain/ethereum/ethereum_amount_format.dart
Normal file
6
lib/src/domain/ethereum/ethereum_amount_format.dart
Normal file
|
@ -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);
|
|
@ -14,6 +14,12 @@ import 'package:cake_wallet/src/domain/exchange/morphtoken/morphtoken_request.da
|
|||
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';
|
||||
import 'package:cake_wallet/src/domain/common/setup_locator.dart';
|
||||
|
||||
class MorphTokenExchangeProvider extends ExchangeProvider {
|
||||
MorphTokenExchangeProvider()
|
||||
|
@ -55,7 +61,7 @@ class MorphTokenExchangeProvider extends ExchangeProvider {
|
|||
ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.xmr)
|
||||
]);
|
||||
|
||||
final trades = Hive.box<Trade>(Trade.boxName);
|
||||
final trades = locator.get<Box<Trade>>();
|
||||
|
||||
static const apiUri = 'https://api.morphtoken.com';
|
||||
static const _morphURISuffix = '/morph';
|
||||
|
@ -72,8 +78,6 @@ class MorphTokenExchangeProvider extends ExchangeProvider {
|
|||
|
||||
@override
|
||||
Future<Limits> fetchLimits({CryptoCurrency from, CryptoCurrency to}) async {
|
||||
const ethereumAmountDivider = 1000000000000000000;
|
||||
const defaultAmountDivider = 100000000;
|
||||
final url = apiUri + _limitsURISuffix;
|
||||
final headers = {'Content-type': 'application/json'};
|
||||
final body =
|
||||
|
@ -107,13 +111,25 @@ class MorphTokenExchangeProvider extends ExchangeProvider {
|
|||
minFormatted = moneroAmountToDouble(amount: min);
|
||||
maxFormatted = moneroAmountToDouble(amount: max);
|
||||
break;
|
||||
case CryptoCurrency.eth:
|
||||
minFormatted = min/ethereumAmountDivider;
|
||||
maxFormatted = ethMax/ethereumAmountDivider;
|
||||
case CryptoCurrency.btc:
|
||||
minFormatted = bitcoinAmountToDouble(amount: min);
|
||||
maxFormatted = bitcoinAmountToDouble(amount: max);
|
||||
break;
|
||||
default:
|
||||
minFormatted = min/defaultAmountDivider;
|
||||
maxFormatted = max/defaultAmountDivider;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -133,7 +149,8 @@ class MorphTokenExchangeProvider extends ExchangeProvider {
|
|||
"asset": _request.to.toString(),
|
||||
"weight": weight,
|
||||
"address": _request.address
|
||||
}]
|
||||
}],
|
||||
"tag": "cakewallet"
|
||||
};
|
||||
|
||||
final response = await post(url,
|
||||
|
@ -190,7 +207,7 @@ class MorphTokenExchangeProvider extends ExchangeProvider {
|
|||
final state = TradeState.deserialize(raw: status.toLowerCase());
|
||||
|
||||
String amount = "";
|
||||
for (final trade in trades.values) {
|
||||
for (final trade in trades.values.toList()) {
|
||||
if (trade.id == id) {
|
||||
amount = trade.amount;
|
||||
break;
|
||||
|
|
6
lib/src/domain/litecoin/litecoin_amount_format.dart
Normal file
6
lib/src/domain/litecoin/litecoin_amount_format.dart
Normal file
|
@ -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);
|
||||
|
|
|
@ -301,6 +301,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.19"
|
||||
get_it:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: get_it
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
glob:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -46,6 +46,7 @@ dependencies:
|
|||
hive: ^1.2.0
|
||||
hive_flutter: ^0.2.1
|
||||
package_info: ^0.4.0+13
|
||||
get_it: ^3.1.0
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
|
|
Loading…
Reference in a new issue