Minor bug fixes.

This commit is contained in:
M
2021-05-11 18:37:26 +03:00
parent a439560d4d
commit f4c57e22f2
11 changed files with 75 additions and 76 deletions
+4 -6
View File
@@ -538,8 +538,7 @@ Future setup(
TradeDetailsPage(getIt.get<TradeDetailsViewModel>(param1: trade)));
getIt.registerFactory(() {
final wallet = getIt.get<AppStore>().wallet;
return WyreService(wallet: wallet);
return WyreService(appStore: getIt.get<AppStore>());
});
getIt.registerFactory(() {
@@ -551,10 +550,9 @@ Future setup(
WyrePage(getIt.get<WyreViewModel>(),
ordersStore: getIt.get<OrdersStore>(), url: url));
getIt.registerFactoryParam<OrderDetailsViewModel, Order, void>(
(order, _) => OrderDetailsViewModel(
wyreViewModel: getIt.get<WyreViewModel>(),
orderForDetails: order));
getIt.registerFactoryParam<OrderDetailsViewModel, Order, void>((order, _) =>
OrderDetailsViewModel(
wyreViewModel: getIt.get<WyreViewModel>(), orderForDetails: order));
getIt.registerFactoryParam<OrderDetailsPage, Order, void>((Order order, _) =>
OrderDetailsPage(getIt.get<OrderDetailsViewModel>(param1: order)));
+3 -2
View File
@@ -4,11 +4,12 @@ String calculateFiatAmount({double price, String cryptoAmount}) {
}
final _amount = double.parse(cryptoAmount);
final result = price * _amount;
final _result = price * _amount;
final result = _result < 0 ? _result * -1 : _result;
if (result == 0.0) {
return '0.00';
}
return result > 0.01 ? result.toStringAsFixed(2) : '< 0.01';
}
}
+20 -23
View File
@@ -1,7 +1,7 @@
import 'dart:convert';
import 'package:cake_wallet/core/wallet_base.dart';
import 'package:cake_wallet/entities/wyre_exception.dart';
import 'package:cake_wallet/exchange/trade_state.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart';
import 'package:cake_wallet/.secrets.g.dart' as secrets;
@@ -9,15 +9,9 @@ import 'package:cake_wallet/entities/order.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
class WyreService {
WyreService({
@required this.wallet,
this.isTestEnvironment = false}) {
baseApiUrl = isTestEnvironment
? _baseTestApiUrl
: _baseProductApiUrl;
trackUrl = isTestEnvironment
? _trackTestUrl
: _trackProductUrl;
WyreService({@required this.appStore, this.isTestEnvironment = false}) {
baseApiUrl = isTestEnvironment ? _baseTestApiUrl : _baseProductApiUrl;
trackUrl = isTestEnvironment ? _trackTestUrl : _trackProductUrl;
}
static const _baseTestApiUrl = 'https://api.testwyre.com';
@@ -31,24 +25,28 @@ class WyreService {
static const _trackSuffix = '/track';
final bool isTestEnvironment;
final WalletBase wallet;
final AppStore appStore;
WalletType get walletType => wallet.type;
String get walletAddress => wallet.address;
String get walletId => wallet.id;
WalletType get walletType => appStore.wallet.type;
String get walletAddress => appStore.wallet.address;
String get walletId => appStore.wallet.id;
String baseApiUrl;
String trackUrl;
Future<String> getWyreUrl() async {
final timestamp = DateTime.now().millisecondsSinceEpoch.toString();
final url = baseApiUrl + _ordersSuffix + _reserveSuffix +
_timeStampSuffix + timestamp;
final url = baseApiUrl +
_ordersSuffix +
_reserveSuffix +
_timeStampSuffix +
timestamp;
final secretKey = secrets.wyreSecretKey;
final accountId = secrets.wyreAccountId;
final body = {
'destCurrency': walletTypeToCryptoCurrency(walletType).title,
'dest': walletTypeToString(walletType).toLowerCase() + ':' + walletAddress,
'dest':
walletTypeToString(walletType).toLowerCase() + ':' + walletAddress,
'referrerAccountId': accountId,
'lockFields': ['destCurrency', 'dest']
};
@@ -79,7 +77,7 @@ class WyreService {
}
final orderResponseJSON =
json.decode(orderResponse.body) as Map<String, dynamic>;
json.decode(orderResponse.body) as Map<String, dynamic>;
final transferId = orderResponseJSON['transferId'] as String;
final from = orderResponseJSON['sourceCurrency'] as String;
final to = orderResponseJSON['destCurrency'] as String;
@@ -87,7 +85,7 @@ class WyreService {
final state = TradeState.deserialize(raw: status.toLowerCase());
final createdAtRaw = orderResponseJSON['createdAt'] as int;
final createdAt =
DateTime.fromMillisecondsSinceEpoch(createdAtRaw).toLocal();
DateTime.fromMillisecondsSinceEpoch(createdAtRaw).toLocal();
final transferUrl =
baseApiUrl + _transferSuffix + transferId + _trackSuffix;
@@ -98,7 +96,7 @@ class WyreService {
}
final transferResponseJSON =
json.decode(transferResponse.body) as Map<String, dynamic>;
json.decode(transferResponse.body) as Map<String, dynamic>;
final amount = transferResponseJSON['destAmount'] as double;
return Order(
@@ -110,7 +108,6 @@ class WyreService {
createdAt: createdAt,
amount: amount.toString(),
receiveAddress: walletAddress,
walletId: walletId
);
walletId: walletId);
}
}
}
@@ -84,6 +84,8 @@ abstract class DashboardViewModelBase with Store {
name = appStore.wallet?.name;
wallet ??= appStore.wallet;
type = wallet.type;
isOutdatedElectrumWallet =
wallet.type == WalletType.bitcoin && wallet.seed.split(' ').length < 24;
final _wallet = wallet;
if (_wallet is MoneroWallet) {
@@ -234,9 +236,8 @@ abstract class DashboardViewModelBase with Store {
await wallet.connectToNode(node: node);
}
@computed
bool get isOutdatedElectrumWallet =>
wallet.type == WalletType.bitcoin && wallet.seed.split(' ').length < 24;
@observable
bool isOutdatedElectrumWallet;
@action
void _onWalletChange(
@@ -246,6 +247,8 @@ abstract class DashboardViewModelBase with Store {
this.wallet = wallet;
type = wallet.type;
name = wallet.name;
isOutdatedElectrumWallet =
wallet.type == WalletType.bitcoin && wallet.seed.split(' ').length < 24;
if (wallet is MoneroWallet) {
subname = wallet.account?.label;