mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-21 06:18:42 +02:00
Merge branch 'main' of https://github.com/cake-tech/cake_wallet into new-fiat-currencies
Conflicts: lib/reactions/on_current_wallet_change.dart
This commit is contained in:
@@ -57,7 +57,7 @@ class AnyPayPayment {
|
||||
|
||||
List<String> get outAddresses {
|
||||
return instructions
|
||||
.map((instuction) => instuction.outputs.map((out) => out.address))
|
||||
.map((instruction) => instruction.outputs.map((out) => out.address))
|
||||
.expand((e) => e)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ class BackupService {
|
||||
final fiatApiMode = data[PreferencesKey.currentFiatApiModeKey] as int?;
|
||||
final currentPinLength = data[PreferencesKey.currentPinLength] as int?;
|
||||
final currentTheme = data[PreferencesKey.currentTheme] as int?;
|
||||
final disableExchange = data[PreferencesKey.disableExchangeKey] as bool?;
|
||||
final exchangeStatus = data[PreferencesKey.exchangeStatusKey] as int?;
|
||||
final currentDefaultSettingsMigrationVersion = data[PreferencesKey.currentDefaultSettingsMigrationVersion] as int?;
|
||||
final moneroTransactionPriority = data[PreferencesKey.moneroTransactionPriority] as int?;
|
||||
final bitcoinTransactionPriority = data[PreferencesKey.bitcoinTransactionPriority] as int?;
|
||||
@@ -280,9 +280,9 @@ class BackupService {
|
||||
await _sharedPreferences.setInt(
|
||||
PreferencesKey.currentTheme, currentTheme);
|
||||
|
||||
if (disableExchange != null)
|
||||
await _sharedPreferences.setBool(
|
||||
PreferencesKey.disableExchangeKey, disableExchange);
|
||||
if (exchangeStatus != null)
|
||||
await _sharedPreferences.setInt(
|
||||
PreferencesKey.exchangeStatusKey, exchangeStatus);
|
||||
|
||||
if (currentDefaultSettingsMigrationVersion != null)
|
||||
await _sharedPreferences.setInt(
|
||||
@@ -431,8 +431,8 @@ class BackupService {
|
||||
_sharedPreferences.getInt(PreferencesKey.displayActionListModeKey),
|
||||
PreferencesKey.currentTheme:
|
||||
_sharedPreferences.getInt(PreferencesKey.currentTheme),
|
||||
PreferencesKey.disableExchangeKey:
|
||||
_sharedPreferences.getBool(PreferencesKey.disableExchangeKey),
|
||||
PreferencesKey.exchangeStatusKey:
|
||||
_sharedPreferences.getInt(PreferencesKey.exchangeStatusKey),
|
||||
PreferencesKey.currentDefaultSettingsMigrationVersion: _sharedPreferences
|
||||
.getInt(PreferencesKey.currentDefaultSettingsMigrationVersion),
|
||||
PreferencesKey.bitcoinTransactionPriority:
|
||||
|
||||
@@ -4,18 +4,31 @@ import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart';
|
||||
|
||||
const fiatApiAuthority = 'fiat-api.cakewallet.com';
|
||||
const fiatApiPath = '/v1/rates';
|
||||
const _fiatApiClearNetAuthority = 'fiat-api.cakewallet.com';
|
||||
const _fiatApiOnionAuthority = 'n4z7bdcmwk2oyddxvzaap3x2peqcplh3pzdy7tpkk5ejz5n4mhfvoxqd.onion';
|
||||
const _fiatApiPath = '/v2/rates';
|
||||
|
||||
Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
||||
final crypto = args['crypto'] as CryptoCurrency;
|
||||
final fiat = args['fiat'] as FiatCurrency;
|
||||
final torOnly = args['torOnly'] as bool;
|
||||
|
||||
final Map<String, String> queryParams = {
|
||||
'interval_count': '1',
|
||||
'base': crypto.toString(),
|
||||
'quote': fiat.toString(),
|
||||
};
|
||||
|
||||
double price = 0.0;
|
||||
|
||||
try {
|
||||
final fiatStringified = fiat.toString();
|
||||
final uri = Uri.https(fiatApiAuthority, fiatApiPath,
|
||||
<String, String>{'convert': fiatStringified});
|
||||
late final Uri uri;
|
||||
if (torOnly) {
|
||||
uri = Uri.http(_fiatApiOnionAuthority, _fiatApiPath, queryParams);
|
||||
} else {
|
||||
uri = Uri.https(_fiatApiClearNetAuthority, _fiatApiPath, queryParams);
|
||||
}
|
||||
|
||||
final response = await get(uri);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
@@ -23,13 +36,10 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
||||
}
|
||||
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final data = responseJSON['data'] as List<dynamic>;
|
||||
final results = responseJSON['results'] as Map<String, dynamic>;
|
||||
|
||||
for (final item in data) {
|
||||
if (item['symbol'] == crypto.title) {
|
||||
price = item['quote'][fiatStringified]['price'] as double;
|
||||
break;
|
||||
}
|
||||
if (results.isNotEmpty) {
|
||||
price = results.values.first as double;
|
||||
}
|
||||
|
||||
return price;
|
||||
@@ -38,12 +48,14 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
||||
}
|
||||
}
|
||||
|
||||
Future<double> _fetchPriceAsync(
|
||||
CryptoCurrency crypto, FiatCurrency fiat) async =>
|
||||
compute(_fetchPrice, {'fiat': fiat, 'crypto': crypto});
|
||||
Future<double> _fetchPriceAsync(CryptoCurrency crypto, FiatCurrency fiat, bool torOnly) async =>
|
||||
compute(_fetchPrice, {'fiat': fiat, 'crypto': crypto, 'torOnly': torOnly});
|
||||
|
||||
class FiatConversionService {
|
||||
static Future<double> fetchPrice(
|
||||
CryptoCurrency crypto, FiatCurrency fiat) async =>
|
||||
await _fetchPriceAsync(crypto, fiat);
|
||||
static Future<double> fetchPrice({
|
||||
required CryptoCurrency crypto,
|
||||
required FiatCurrency fiat,
|
||||
required bool torOnly,
|
||||
}) async =>
|
||||
await _fetchPriceAsync(crypto, fiat, torOnly);
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@ class WalletLoadingService {
|
||||
final wallet = await walletService.openWallet(name, password);
|
||||
|
||||
if (type == WalletType.monero) {
|
||||
await upateMoneroWalletPassword(wallet);
|
||||
await updateMoneroWalletPassword(wallet);
|
||||
}
|
||||
|
||||
return wallet;
|
||||
}
|
||||
|
||||
Future<void> upateMoneroWalletPassword(WalletBase wallet) async {
|
||||
Future<void> updateMoneroWalletPassword(WalletBase wallet) async {
|
||||
final key = PreferencesKey.moneroWalletUpdateV1Key(wallet.name);
|
||||
var isPasswordUpdated = sharedPreferences.getBool(key) ?? false;
|
||||
|
||||
@@ -37,8 +37,8 @@ class WalletLoadingService {
|
||||
}
|
||||
|
||||
final password = generateWalletPassword();
|
||||
// Save new generated password with backup key for case
|
||||
// if wallet will change password, but it will faild to updated in secure storage
|
||||
// Save new generated password with backup key for case where
|
||||
// wallet will change password, but it will fail to update in secure storage
|
||||
final bakWalletName = '#__${wallet.name}_bak__#';
|
||||
await keyService.saveWalletPassword(walletName: bakWalletName, password: password);
|
||||
await wallet.changePassword(password);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import 'dart:io' show File, Platform;
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
import 'package:cw_core/pathForWallet.dart';
|
||||
import 'package:cake_wallet/entities/secret_store_key.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:cake_wallet/entities/preferences_key.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
@@ -142,7 +144,9 @@ Future defaultSettingsMigration(
|
||||
case 19:
|
||||
await validateBitcoinSavedTransactionPriority(sharedPreferences);
|
||||
break;
|
||||
|
||||
case 20:
|
||||
await migrateExchangeStatus(sharedPreferences);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -501,3 +505,15 @@ Future<void> changeDefaultHavenNode(
|
||||
await node.save();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> migrateExchangeStatus(SharedPreferences sharedPreferences) async {
|
||||
final isExchangeDisabled = sharedPreferences.getBool(PreferencesKey.disableExchangeKey);
|
||||
if (isExchangeDisabled == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
await sharedPreferences.setInt(PreferencesKey.exchangeStatusKey, isExchangeDisabled
|
||||
? ExchangeApiMode.disabled.raw : ExchangeApiMode.enabled.raw);
|
||||
|
||||
await sharedPreferences.remove(PreferencesKey.disableExchangeKey);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cw_core/enumerable_item.dart';
|
||||
|
||||
class ExchangeApiMode extends EnumerableItem<int> with Serializable<int> {
|
||||
const ExchangeApiMode({required String title, required int raw}) : super(title: title, raw: raw);
|
||||
|
||||
static const all = [ExchangeApiMode.enabled, ExchangeApiMode.torOnly, ExchangeApiMode.disabled];
|
||||
|
||||
static const enabled = ExchangeApiMode(raw: 0, title: 'Enabled');
|
||||
static const torOnly = ExchangeApiMode(raw: 1, title: 'Tor only');
|
||||
static const disabled = ExchangeApiMode(raw: 2, title: 'Disabled');
|
||||
|
||||
static ExchangeApiMode deserialize({required int raw}) {
|
||||
switch (raw) {
|
||||
case 0:
|
||||
return enabled;
|
||||
case 1:
|
||||
return torOnly;
|
||||
case 2:
|
||||
return disabled;
|
||||
default:
|
||||
throw Exception('Unexpected token: $raw for ExchangeApiMode deserialize');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
switch (this) {
|
||||
case ExchangeApiMode.enabled:
|
||||
return S.current.enabled;
|
||||
case ExchangeApiMode.torOnly:
|
||||
return S.current.tor_only;
|
||||
case ExchangeApiMode.disabled:
|
||||
return S.current.disabled;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,10 @@ class LanguageService {
|
||||
'ar': 'العربية (Arabic)',
|
||||
'tr': 'Türkçe (Turkish)',
|
||||
'my': 'မြန်မာ (Burmese)',
|
||||
'ur': 'اردو (Urdu)'
|
||||
'bg': 'Български (Bulgarian)',
|
||||
'cs': 'čeština (Czech)',
|
||||
'ur': 'اردو (Urdu)',
|
||||
'id': 'Bahasa Indonesia (Indonesian)'
|
||||
};
|
||||
|
||||
static const Map<String, String> localeCountryCode = {
|
||||
@@ -46,7 +49,10 @@ class LanguageService {
|
||||
'ar': 'sau',
|
||||
'tr': 'tur',
|
||||
'my': 'mmr',
|
||||
'ur': 'pak'
|
||||
'bg': 'bgr',
|
||||
'cs': 'czk',
|
||||
'ur': 'pak',
|
||||
'id': 'idn'
|
||||
};
|
||||
|
||||
static final list = <String, String> {};
|
||||
|
||||
@@ -13,6 +13,7 @@ class PreferencesKey {
|
||||
static const allowBiometricalAuthenticationKey =
|
||||
'allow_biometrical_authentication';
|
||||
static const disableExchangeKey = 'disable_exchange';
|
||||
static const exchangeStatusKey = 'exchange_status';
|
||||
static const currentTheme = 'current_theme';
|
||||
static const isDarkThemeLegacy = 'dark_theme';
|
||||
static const displayActionListModeKey = 'display_list_mode';
|
||||
|
||||
@@ -269,6 +269,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
|
||||
: currency.title.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String normalizeCryptoCurrency(CryptoCurrency currency) {
|
||||
|
||||
@@ -14,6 +14,7 @@ abstract class ExchangeProvider {
|
||||
bool get isAvailable;
|
||||
bool get isEnabled;
|
||||
bool get supportsFixedRate;
|
||||
bool get supportsOnionAddress => false;
|
||||
|
||||
@override
|
||||
String toString() => title;
|
||||
|
||||
@@ -1,31 +1,30 @@
|
||||
import 'package:cw_core/enumerable_item.dart';
|
||||
|
||||
class ExchangeProviderDescription extends EnumerableItem<int>
|
||||
with Serializable<int> {
|
||||
const ExchangeProviderDescription({
|
||||
required String title,
|
||||
required int raw,
|
||||
required this.image,
|
||||
this.horizontalLogo = false})
|
||||
class ExchangeProviderDescription extends EnumerableItem<int> with Serializable<int> {
|
||||
const ExchangeProviderDescription(
|
||||
{required String title, required int raw, required this.image, this.horizontalLogo = false})
|
||||
: super(title: title, raw: raw);
|
||||
|
||||
final bool horizontalLogo;
|
||||
final String image;
|
||||
|
||||
static const xmrto = ExchangeProviderDescription(title: 'XMR.TO', raw: 0, image: 'assets/images/xmrto.png');
|
||||
static const xmrto =
|
||||
ExchangeProviderDescription(title: 'XMR.TO', raw: 0, image: 'assets/images/xmrto.png');
|
||||
static const changeNow =
|
||||
ExchangeProviderDescription(title: 'ChangeNOW', raw: 1, image: 'assets/images/changenow.png');
|
||||
static const morphToken =
|
||||
ExchangeProviderDescription(title: 'MorphToken', raw: 2, image: 'assets/images/morph.png');
|
||||
|
||||
static const sideShift =
|
||||
static const sideShift =
|
||||
ExchangeProviderDescription(title: 'SideShift', raw: 3, image: 'assets/images/sideshift.png');
|
||||
|
||||
static const simpleSwap =
|
||||
ExchangeProviderDescription(title: 'SimpleSwap', raw: 4, image: 'assets/images/simpleSwap.png');
|
||||
static const simpleSwap = ExchangeProviderDescription(
|
||||
title: 'SimpleSwap', raw: 4, image: 'assets/images/simpleSwap.png');
|
||||
|
||||
static const all =
|
||||
ExchangeProviderDescription(title: 'All trades', raw: 5, image:'');
|
||||
static const trocador =
|
||||
ExchangeProviderDescription(title: 'Trocador', raw: 5, image: 'assets/images/trocador.png');
|
||||
|
||||
static const all = ExchangeProviderDescription(title: 'All trades', raw: 6, image: '');
|
||||
|
||||
static ExchangeProviderDescription deserialize({required int raw}) {
|
||||
switch (raw) {
|
||||
@@ -40,6 +39,8 @@ class ExchangeProviderDescription extends EnumerableItem<int>
|
||||
case 4:
|
||||
return simpleSwap;
|
||||
case 5:
|
||||
return trocador;
|
||||
case 6:
|
||||
return all;
|
||||
default:
|
||||
throw Exception('Unexpected token: $raw for ExchangeProviderDescription deserialize');
|
||||
|
||||
+31
-20
@@ -8,21 +8,25 @@ part 'trade.g.dart';
|
||||
|
||||
@HiveType(typeId: Trade.typeId)
|
||||
class Trade extends HiveObject {
|
||||
Trade(
|
||||
{required this.id,
|
||||
required this.amount,
|
||||
ExchangeProviderDescription? provider,
|
||||
CryptoCurrency? from,
|
||||
CryptoCurrency? to,
|
||||
TradeState? state,
|
||||
this.createdAt,
|
||||
this.expiredAt,
|
||||
this.inputAddress,
|
||||
this.extraId,
|
||||
this.outputTransaction,
|
||||
this.refundAddress,
|
||||
this.walletId,
|
||||
this.payoutAddress}) {
|
||||
Trade({
|
||||
required this.id,
|
||||
required this.amount,
|
||||
ExchangeProviderDescription? provider,
|
||||
CryptoCurrency? from,
|
||||
CryptoCurrency? to,
|
||||
TradeState? state,
|
||||
this.createdAt,
|
||||
this.expiredAt,
|
||||
this.inputAddress,
|
||||
this.extraId,
|
||||
this.outputTransaction,
|
||||
this.refundAddress,
|
||||
this.walletId,
|
||||
this.payoutAddress,
|
||||
this.password,
|
||||
this.providerId,
|
||||
this.providerName,
|
||||
}) {
|
||||
if (provider != null) {
|
||||
providerRaw = provider.raw;
|
||||
}
|
||||
@@ -92,16 +96,23 @@ class Trade extends HiveObject {
|
||||
@HiveField(13)
|
||||
String? payoutAddress;
|
||||
|
||||
@HiveField(14)
|
||||
String? password;
|
||||
|
||||
@HiveField(15)
|
||||
String? providerId;
|
||||
|
||||
@HiveField(16)
|
||||
String? providerName;
|
||||
|
||||
static Trade fromMap(Map<String, Object?> map) {
|
||||
return Trade(
|
||||
id: map['id'] as String,
|
||||
provider: ExchangeProviderDescription.deserialize(
|
||||
raw: map['provider'] as int),
|
||||
provider: ExchangeProviderDescription.deserialize(raw: map['provider'] as int),
|
||||
from: CryptoCurrency.deserialize(raw: map['input'] as int),
|
||||
to: CryptoCurrency.deserialize(raw: map['output'] as int),
|
||||
createdAt: map['date'] != null
|
||||
? DateTime.fromMillisecondsSinceEpoch(map['date'] as int)
|
||||
: null,
|
||||
createdAt:
|
||||
map['date'] != null ? DateTime.fromMillisecondsSinceEpoch(map['date'] as int) : null,
|
||||
amount: map['amount'] as String,
|
||||
walletId: map['wallet_id'] as String);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:cake_wallet/exchange/exchange_pair.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/trade_state.dart';
|
||||
import 'package:cake_wallet/exchange/trocador/trocador_request.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cake_wallet/exchange/trade_request.dart';
|
||||
import 'package:cake_wallet/exchange/trade.dart';
|
||||
import 'package:cake_wallet/exchange/limits.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
import 'package:http/http.dart';
|
||||
|
||||
class TrocadorExchangeProvider extends ExchangeProvider {
|
||||
TrocadorExchangeProvider({this.useTorOnly = false})
|
||||
: _lastUsedRateId = '',
|
||||
super(pairList: _supportedPairs());
|
||||
|
||||
bool useTorOnly;
|
||||
|
||||
static const List<CryptoCurrency> _notSupported = [
|
||||
CryptoCurrency.scrt,
|
||||
CryptoCurrency.stx,
|
||||
CryptoCurrency.zaddr,
|
||||
];
|
||||
|
||||
static List<ExchangePair> _supportedPairs() {
|
||||
final supportedCurrencies =
|
||||
CryptoCurrency.all.where((element) => !_notSupported.contains(element)).toList();
|
||||
|
||||
return supportedCurrencies
|
||||
.map((i) => supportedCurrencies.map((k) => ExchangePair(from: i, to: k, reverse: true)))
|
||||
.expand((i) => i)
|
||||
.toList();
|
||||
}
|
||||
|
||||
static const onionApiAuthority = 'trocadorfyhlu27aefre5u7zri66gudtzdyelymftvr4yjwcxhfaqsid.onion';
|
||||
static const clearNetAuthority = 'trocador.app';
|
||||
static const apiKey = secrets.trocadorApiKey;
|
||||
static const markup = secrets.trocadorExchangeMarkup;
|
||||
static const newRatePath = '/api/new_rate';
|
||||
static const createTradePath = 'api/new_trade';
|
||||
static const tradePath = 'api/trade';
|
||||
static const coinPath = 'api/coin';
|
||||
String _lastUsedRateId;
|
||||
|
||||
@override
|
||||
Future<bool> checkIsAvailable() async => true;
|
||||
|
||||
@override
|
||||
Future<Trade> createTrade({required TradeRequest request, required bool isFixedRateMode}) {
|
||||
final _request = request as TrocadorRequest;
|
||||
return _createTrade(request: _request, isFixedRateMode: isFixedRateMode);
|
||||
}
|
||||
|
||||
Future<Trade> _createTrade({
|
||||
required TrocadorRequest request,
|
||||
required bool isFixedRateMode,
|
||||
}) async {
|
||||
final params = <String, String>{
|
||||
'api_key': apiKey,
|
||||
'ticker_from': request.from.title.toLowerCase(),
|
||||
'ticker_to': request.to.title.toLowerCase(),
|
||||
'network_from': _networkFor(request.from),
|
||||
'network_to': _networkFor(request.to),
|
||||
'payment': isFixedRateMode ? 'True' : 'False',
|
||||
'min_kycrating': 'C',
|
||||
'markup': markup,
|
||||
'best_only': 'True',
|
||||
if (!isFixedRateMode) 'amount_from': request.fromAmount,
|
||||
if (isFixedRateMode) 'amount_to': request.toAmount,
|
||||
'address': request.address,
|
||||
'refund': request.refundAddress
|
||||
};
|
||||
|
||||
if (isFixedRateMode) {
|
||||
await fetchRate(
|
||||
from: request.from,
|
||||
to: request.to,
|
||||
amount: double.tryParse(request.toAmount) ?? 0,
|
||||
isFixedRateMode: true,
|
||||
isReceiveAmount: true,
|
||||
);
|
||||
params['id'] = _lastUsedRateId;
|
||||
}
|
||||
|
||||
final uri = await _getUri(createTradePath, params);
|
||||
final response = await get(uri);
|
||||
|
||||
if (response.statusCode == 400) {
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final error = responseJSON['error'] as String;
|
||||
final message = responseJSON['message'] as String;
|
||||
throw Exception('${error}\n$message');
|
||||
}
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Unexpected http status: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final id = responseJSON['trade_id'] as String;
|
||||
final inputAddress = responseJSON['address_provider'] as String;
|
||||
final refundAddress = responseJSON['refund_address'] as String;
|
||||
final status = responseJSON['status'] as String;
|
||||
final state = TradeState.deserialize(raw: status);
|
||||
final payoutAddress = responseJSON['address_user'] as String;
|
||||
final date = responseJSON['date'] as String;
|
||||
final password = responseJSON['password'] as String;
|
||||
final providerId = responseJSON['id_provider'] as String;
|
||||
final providerName = responseJSON['provider'] as String;
|
||||
|
||||
return Trade(
|
||||
id: id,
|
||||
from: request.from,
|
||||
to: request.to,
|
||||
provider: description,
|
||||
inputAddress: inputAddress,
|
||||
refundAddress: refundAddress,
|
||||
state: state,
|
||||
password: password,
|
||||
providerId: providerId,
|
||||
providerName: providerName,
|
||||
createdAt: DateTime.tryParse(date)?.toLocal(),
|
||||
amount: responseJSON['amount_from']?.toString() ?? request.fromAmount,
|
||||
payoutAddress: payoutAddress);
|
||||
}
|
||||
|
||||
@override
|
||||
ExchangeProviderDescription get description => ExchangeProviderDescription.trocador;
|
||||
|
||||
@override
|
||||
Future<Limits> fetchLimits(
|
||||
{required CryptoCurrency from,
|
||||
required CryptoCurrency to,
|
||||
required bool isFixedRateMode}) async {
|
||||
final params = <String, String>{
|
||||
'api_key': apiKey,
|
||||
'ticker': from.title.toLowerCase(),
|
||||
'name': from.name,
|
||||
};
|
||||
|
||||
final uri = await _getUri(coinPath, params);
|
||||
|
||||
final response = await get(uri);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Unexpected http status: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseJSON = json.decode(response.body) as List<dynamic>;
|
||||
|
||||
if (responseJSON.isEmpty) {
|
||||
throw Exception('No data');
|
||||
}
|
||||
|
||||
final coinJson = responseJSON.first as Map<String, dynamic>;
|
||||
|
||||
return Limits(
|
||||
min: coinJson['minimum'] as double,
|
||||
max: coinJson['maximum'] as double,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<double> fetchRate(
|
||||
{required CryptoCurrency from,
|
||||
required CryptoCurrency to,
|
||||
required double amount,
|
||||
required bool isFixedRateMode,
|
||||
required bool isReceiveAmount}) async {
|
||||
try {
|
||||
if (amount == 0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
final params = <String, String>{
|
||||
'api_key': apiKey,
|
||||
'ticker_from': from.title.toLowerCase(),
|
||||
'ticker_to': to.title.toLowerCase(),
|
||||
'network_from': _networkFor(from),
|
||||
'network_to': _networkFor(to),
|
||||
if (!isFixedRateMode) 'amount_from': amount.toString(),
|
||||
if (isFixedRateMode) 'amount_to': amount.toString(),
|
||||
'payment': isFixedRateMode ? 'True' : 'False',
|
||||
'min_kycrating': 'C',
|
||||
'markup': markup,
|
||||
'best_only': 'True',
|
||||
};
|
||||
|
||||
final uri = await _getUri(newRatePath, params);
|
||||
final response = await get(uri);
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final fromAmount = double.parse(responseJSON['amount_from'].toString());
|
||||
final toAmount = double.parse(responseJSON['amount_to'].toString());
|
||||
final rateId = responseJSON['trade_id'] as String? ?? '';
|
||||
|
||||
if (rateId.isNotEmpty) {
|
||||
_lastUsedRateId = rateId;
|
||||
}
|
||||
|
||||
return isReceiveAmount ? (amount / fromAmount) : (toAmount / amount);
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Trade> findTradeById({required String id}) async {
|
||||
final uri = await _getUri(tradePath, {'api_key': apiKey, 'id': id});
|
||||
return get(uri).then((response) {
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Unexpected http status: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseListJson = json.decode(response.body) as List;
|
||||
|
||||
final responseJSON = responseListJson.first;
|
||||
final id = responseJSON['trade_id'] as String;
|
||||
final inputAddress = responseJSON['address_user'] as String;
|
||||
final refundAddress = responseJSON['refund_address'] as String;
|
||||
final payoutAddress = responseJSON['address_provider'] as String;
|
||||
final fromAmount = responseJSON['amount_from']?.toString() ?? '0';
|
||||
final from = CryptoCurrency.fromString(responseJSON['ticker_from'] as String);
|
||||
final to = CryptoCurrency.fromString(responseJSON['ticker_to'] as String);
|
||||
final state = TradeState.deserialize(raw: responseJSON['status'] as String);
|
||||
final date = DateTime.parse(responseJSON['date'] as String);
|
||||
final password = responseJSON['password'] as String;
|
||||
final providerId = responseJSON['id_provider'] as String;
|
||||
final providerName = responseJSON['provider'] as String;
|
||||
|
||||
return Trade(
|
||||
id: id,
|
||||
from: from,
|
||||
to: to,
|
||||
provider: description,
|
||||
inputAddress: inputAddress,
|
||||
refundAddress: refundAddress,
|
||||
createdAt: date,
|
||||
amount: fromAmount,
|
||||
state: state,
|
||||
payoutAddress: payoutAddress,
|
||||
password: password,
|
||||
providerId: providerId,
|
||||
providerName: providerName,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isAvailable => true;
|
||||
|
||||
@override
|
||||
bool get isEnabled => true;
|
||||
|
||||
@override
|
||||
bool get supportsFixedRate => true;
|
||||
|
||||
@override
|
||||
bool get supportsOnionAddress => true;
|
||||
|
||||
@override
|
||||
String get title => 'Trocador';
|
||||
|
||||
String _networkFor(CryptoCurrency currency) {
|
||||
switch (currency) {
|
||||
case CryptoCurrency.eth:
|
||||
return 'ERC20';
|
||||
case CryptoCurrency.maticpoly:
|
||||
return 'Mainnet';
|
||||
case CryptoCurrency.usdcpoly:
|
||||
return 'MATIC';
|
||||
case CryptoCurrency.zec:
|
||||
return 'Mainnet';
|
||||
default:
|
||||
return currency.tag != null ? _normalizeTag(currency.tag!) : 'Mainnet';
|
||||
}
|
||||
}
|
||||
|
||||
String _normalizeTag(String tag) {
|
||||
switch (tag) {
|
||||
case 'ETH':
|
||||
return 'ERC20';
|
||||
case 'TRX':
|
||||
return 'TRC20';
|
||||
default:
|
||||
return tag.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uri> _getUri(String path, Map<String, String> queryParams) async {
|
||||
if (!supportsOnionAddress) {
|
||||
return Uri.https(clearNetAuthority, path, queryParams);
|
||||
}
|
||||
|
||||
final uri = Uri.http(onionApiAuthority, path, queryParams);
|
||||
|
||||
if (useTorOnly) {
|
||||
return uri;
|
||||
}
|
||||
|
||||
try {
|
||||
await get(uri);
|
||||
|
||||
return uri;
|
||||
} catch (e) {
|
||||
return Uri.https(clearNetAuthority, path, queryParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:cake_wallet/exchange/trade_request.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
|
||||
class TrocadorRequest extends TradeRequest {
|
||||
TrocadorRequest(
|
||||
{required this.from,
|
||||
required this.to,
|
||||
required this.address,
|
||||
required this.fromAmount,
|
||||
required this.toAmount,
|
||||
required this.refundAddress,
|
||||
required this.isReverse});
|
||||
|
||||
CryptoCurrency from;
|
||||
CryptoCurrency to;
|
||||
String address;
|
||||
String fromAmount;
|
||||
String toAmount;
|
||||
String refundAddress;
|
||||
bool isReverse;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'package:cake_wallet/reactions/fiat_rate_update.dart';
|
||||
import 'package:cake_wallet/reactions/on_current_fiat_api_mode_change.dart';
|
||||
import 'package:cake_wallet/reactions/on_current_node_change.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
@@ -31,6 +32,7 @@ Future<void> bootstrap(GlobalKey<NavigatorState> navigatorKey) async {
|
||||
startCurrentWalletChangeReaction(
|
||||
appStore, settingsStore, fiatConversionStore);
|
||||
startCurrentFiatChangeReaction(appStore, settingsStore, fiatConversionStore);
|
||||
startCurrentFiatApiModeChangeReaction(appStore, settingsStore, fiatConversionStore);
|
||||
startOnCurrentNodeChangeReaction(appStore);
|
||||
startFiatRateUpdate(appStore, settingsStore, fiatConversionStore);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ Future<void> startFiatRateUpdate(
|
||||
} else {
|
||||
fiatConversionStore.prices[appStore.wallet!.currency] =
|
||||
await FiatConversionService.fetchPrice(
|
||||
appStore.wallet!.currency, settingsStore.fiatCurrency);
|
||||
crypto: appStore.wallet!.currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/utils/exception_handler.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/entities/load_current_wallet.dart';
|
||||
@@ -16,8 +17,9 @@ void startAuthenticationStateChange(AuthenticationStore authenticationStore,
|
||||
if (state == AuthenticationState.installed) {
|
||||
try {
|
||||
await loadCurrentWallet();
|
||||
} catch (e) {
|
||||
loginError = e;
|
||||
} catch (error, stack) {
|
||||
loginError = error;
|
||||
ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/fiat_conversion_service.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
|
||||
ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer;
|
||||
|
||||
void startCurrentFiatApiModeChangeReaction(AppStore appStore,
|
||||
SettingsStore settingsStore, FiatConversionStore fiatConversionStore) {
|
||||
_onCurrentFiatCurrencyChangeDisposer?.reaction.dispose();
|
||||
_onCurrentFiatCurrencyChangeDisposer = reaction(
|
||||
(_) => settingsStore.fiatApiMode, (FiatApiMode fiatApiMode) async {
|
||||
if (appStore.wallet == null || fiatApiMode == FiatApiMode.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
fiatConversionStore.prices[appStore.wallet!.currency] =
|
||||
await FiatConversionService.fetchPrice(
|
||||
crypto: appStore.wallet!.currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
torOnly: fiatApiMode == FiatApiMode.torOnly);
|
||||
});
|
||||
}
|
||||
@@ -18,7 +18,10 @@ void startCurrentFiatChangeReaction(AppStore appStore,
|
||||
}
|
||||
|
||||
final cryptoCurrency = appStore.wallet!.currency;
|
||||
fiatConversionStore.prices[appStore.wallet!.currency] =
|
||||
await FiatConversionService.fetchPrice(cryptoCurrency, fiatCurrency);
|
||||
fiatConversionStore.prices[cryptoCurrency] =
|
||||
await FiatConversionService.fetchPrice(
|
||||
crypto: cryptoCurrency,
|
||||
fiat: fiatCurrency,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ void startCurrentWalletChangeReaction(AppStore appStore,
|
||||
if (wallet.type == WalletType.haven) {
|
||||
await updateHavenRate(fiatConversionStore);
|
||||
}
|
||||
|
||||
if (wallet.walletInfo.address?.isEmpty ?? true) {
|
||||
|
||||
if (wallet.walletInfo.address.isEmpty) {
|
||||
wallet.walletInfo.address = wallet.walletAddresses.address;
|
||||
|
||||
if (wallet.walletInfo.isInBox) {
|
||||
@@ -94,7 +94,9 @@ void startCurrentWalletChangeReaction(AppStore appStore,
|
||||
fiatConversionStore.prices[wallet.currency] = 0;
|
||||
fiatConversionStore.prices[wallet.currency] =
|
||||
await FiatConversionService.fetchPrice(
|
||||
wallet.currency, settingsStore.fiatCurrency);
|
||||
crypto: wallet.currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import 'dart:io';
|
||||
import 'package:cake_wallet/palette.dart';
|
||||
import 'package:cake_wallet/utils/share_util.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:cross_file/cross_file.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
@@ -110,7 +109,7 @@ class BackupPage extends BasePage {
|
||||
if (Platform.isAndroid) {
|
||||
onExportAndroid(context, backup);
|
||||
} else {
|
||||
await share(backup);
|
||||
await share(backup, context);
|
||||
}
|
||||
},
|
||||
actionLeftButton: () => Navigator.of(dialogContext).pop());
|
||||
@@ -140,18 +139,14 @@ class BackupPage extends BasePage {
|
||||
},
|
||||
actionLeftButton: () async {
|
||||
Navigator.of(dialogContext).pop();
|
||||
await share(backup);
|
||||
await share(backup, context);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> share(BackupExportFile backup) async {
|
||||
const mimeType = 'application/*';
|
||||
Future<void> share(BackupExportFile backup, BuildContext context) async {
|
||||
final path = await backupViewModelBase.saveBackupFileLocally(backup);
|
||||
await Share.shareXFiles(<XFile>[XFile(
|
||||
path,
|
||||
name: backup.name,
|
||||
mimeType: mimeType)]);
|
||||
await ShareUtil.shareFile(filePath: path, fileName: backup.name, context: context);
|
||||
await backupViewModelBase.removeBackupFileLocally(backup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||
import 'package:cake_wallet/themes/theme_base.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/src/screens/dashboard/widgets/menu_widget.dart';
|
||||
@@ -229,7 +228,8 @@ class DashboardPage extends BasePage {
|
||||
}
|
||||
|
||||
await Future<void>.delayed(Duration(seconds: 1));
|
||||
await showPopUp<void>(
|
||||
if (context.mounted) {
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
@@ -239,6 +239,7 @@ class DashboardPage extends BasePage {
|
||||
buttonText: S.of(context).understand,
|
||||
buttonAction: () => Navigator.of(context).pop());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var needToPresentYat = false;
|
||||
|
||||
@@ -117,7 +117,8 @@ class AddressPage extends BasePage {
|
||||
}
|
||||
|
||||
await Future<void>.delayed(Duration(seconds: 1));
|
||||
await showPopUp<void>(
|
||||
if (context.mounted) {
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithTwoActions(
|
||||
@@ -131,6 +132,7 @@ class AddressPage extends BasePage {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return KeyboardActions(
|
||||
|
||||
@@ -9,7 +9,8 @@ class TradeRow extends StatelessWidget {
|
||||
required this.to,
|
||||
required this.createdAtFormattedDate,
|
||||
this.onTap,
|
||||
this.formattedAmount,});
|
||||
this.formattedAmount,
|
||||
});
|
||||
|
||||
final VoidCallback? onTap;
|
||||
final ExchangeProviderDescription provider;
|
||||
@@ -35,47 +36,40 @@ class TradeRow extends StatelessWidget {
|
||||
SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
Text('${from.toString()} → ${to.toString()}',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!
|
||||
)),
|
||||
formattedAmount != null
|
||||
? Text(formattedAmount! + ' ' + amountCrypto,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!
|
||||
))
|
||||
: Container()
|
||||
]),
|
||||
SizedBox(height: 5),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
if (createdAtFormattedDate != null)
|
||||
Text(createdAtFormattedDate!,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).textTheme!
|
||||
.overline!.backgroundColor!))
|
||||
])
|
||||
],
|
||||
)
|
||||
)
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[
|
||||
Text('${from.toString()} → ${to.toString()}',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!)),
|
||||
formattedAmount != null
|
||||
? Text(formattedAmount! + ' ' + amountCrypto,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color:
|
||||
Theme.of(context).accentTextTheme!.headline2!.backgroundColor!))
|
||||
: Container()
|
||||
]),
|
||||
SizedBox(height: 5),
|
||||
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[
|
||||
if (createdAtFormattedDate != null)
|
||||
Text(createdAtFormattedDate!,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).textTheme!.overline!.backgroundColor!))
|
||||
])
|
||||
],
|
||||
))
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
Image? _getPoweredImage(ExchangeProviderDescription provider) {
|
||||
Image? image;
|
||||
Widget? _getPoweredImage(ExchangeProviderDescription provider) {
|
||||
Widget? image;
|
||||
|
||||
switch (provider) {
|
||||
case ExchangeProviderDescription.xmrto:
|
||||
@@ -93,10 +87,15 @@ class TradeRow extends StatelessWidget {
|
||||
case ExchangeProviderDescription.simpleSwap:
|
||||
image = Image.asset('assets/images/simpleSwap.png', width: 36, height: 36);
|
||||
break;
|
||||
case ExchangeProviderDescription.trocador:
|
||||
image = ClipRRect(
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
child: Image.asset('assets/images/trocador.png', width: 36, height: 36));
|
||||
break;
|
||||
default:
|
||||
image = null;
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:cake_wallet/src/screens/nodes/widgets/node_form.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/widgets/settings_choices_cell.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/widgets/settings_switcher_cell.dart';
|
||||
import 'package:cake_wallet/view_model/node_list/node_create_or_edit_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/advanced_privacy_settings_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/settings/choices_list_item.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
@@ -48,29 +52,47 @@ class _AdvancedPrivacySettingsBodyState extends State<AdvancedPrivacySettingsBod
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
...widget.privacySettingsViewModel.settings.map(
|
||||
(item) => Observer(
|
||||
builder: (_) => SettingsSwitcherCell(
|
||||
title: item.title,
|
||||
value: item.value(),
|
||||
onValueChange: item.onValueChange,
|
||||
Observer(builder: (_) {
|
||||
return SettingsChoicesCell(
|
||||
ChoicesListItem<FiatApiMode>(
|
||||
title: S.current.disable_fiat,
|
||||
items: FiatApiMode.all,
|
||||
selectedItem: widget.privacySettingsViewModel.fiatApiMode,
|
||||
onItemSelected: (FiatApiMode mode) =>
|
||||
widget.privacySettingsViewModel.setFiatApiMode(mode),
|
||||
),
|
||||
),
|
||||
),
|
||||
Observer(
|
||||
builder: (_) {
|
||||
if (widget.privacySettingsViewModel.addCustomNode) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: 24, right: 24, top: 24),
|
||||
child: NodeForm(
|
||||
formKey: _formKey,
|
||||
nodeViewModel: widget.nodeViewModel,
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
);
|
||||
}),
|
||||
Observer(builder: (_) {
|
||||
return SettingsChoicesCell(
|
||||
ChoicesListItem<ExchangeApiMode>(
|
||||
title: S.current.exchange,
|
||||
items: ExchangeApiMode.all,
|
||||
selectedItem: widget.privacySettingsViewModel.exchangeStatus,
|
||||
onItemSelected: (ExchangeApiMode mode) =>
|
||||
widget.privacySettingsViewModel.setExchangeApiMode(mode),
|
||||
),
|
||||
);
|
||||
}),
|
||||
Observer(builder: (_) {
|
||||
return Column(
|
||||
children: [
|
||||
SettingsSwitcherCell(
|
||||
title: S.current.add_custom_node,
|
||||
value: widget.privacySettingsViewModel.addCustomNode,
|
||||
onValueChange: (_, __) => widget.privacySettingsViewModel.toggleAddCustomNode(),
|
||||
),
|
||||
if (widget.privacySettingsViewModel.addCustomNode)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 24, right: 24, top: 24),
|
||||
child: NodeForm(
|
||||
formKey: _formKey,
|
||||
nodeViewModel: widget.nodeViewModel,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
bottomSectionPadding: EdgeInsets.all(24),
|
||||
|
||||
@@ -379,7 +379,8 @@ class SendPage extends BasePage {
|
||||
|
||||
if (state is ExecutedSuccessfullyState) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
showPopUp<void>(
|
||||
if (context.mounted) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ConfirmSendingAlert(
|
||||
@@ -423,6 +424,7 @@ class SendPage extends BasePage {
|
||||
},
|
||||
actionLeftButton: () => Navigator.of(context).pop());
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/widgets/settings_choices_cell.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/widgets/settings_switcher_cell.dart';
|
||||
import 'package:cake_wallet/view_model/settings/choices_list_item.dart';
|
||||
import 'package:cake_wallet/view_model/settings/privacy_settings_view_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
@@ -18,29 +22,34 @@ class PrivacyPage extends BasePage {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: Observer(builder: (_) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SettingsSwitcherCell(
|
||||
title: S.current.disable_fiat,
|
||||
value: _privacySettingsViewModel.isFiatDisabled,
|
||||
onValueChange: (BuildContext context, bool value) {
|
||||
_privacySettingsViewModel.setFiatMode(value);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SettingsChoicesCell(
|
||||
ChoicesListItem<FiatApiMode>(
|
||||
title: S.current.fiat_api,
|
||||
items: FiatApiMode.all,
|
||||
selectedItem: _privacySettingsViewModel.fiatApiMode,
|
||||
onItemSelected: (FiatApiMode fiatApiMode) =>
|
||||
_privacySettingsViewModel.setFiatMode(fiatApiMode),
|
||||
),
|
||||
),
|
||||
SettingsChoicesCell(
|
||||
ChoicesListItem<ExchangeApiMode>(
|
||||
title: S.current.exchange,
|
||||
items: ExchangeApiMode.all,
|
||||
selectedItem: _privacySettingsViewModel.exchangeStatus,
|
||||
onItemSelected: (ExchangeApiMode mode) => _privacySettingsViewModel.setExchangeApiMode(mode),
|
||||
),
|
||||
),
|
||||
SettingsSwitcherCell(
|
||||
title: S.current.settings_save_recipient_address,
|
||||
value: _privacySettingsViewModel.shouldSaveRecipientAddress,
|
||||
onValueChange: (BuildContext _, bool value) {
|
||||
_privacySettingsViewModel.setShouldSaveRecipientAddress(value);
|
||||
}),
|
||||
SettingsSwitcherCell(
|
||||
title: S.current.disable_exchange,
|
||||
value: _privacySettingsViewModel.disableExchange,
|
||||
onValueChange: (BuildContext context, bool value) {
|
||||
_privacySettingsViewModel.setEnableExchange(value);
|
||||
}),
|
||||
SettingsSwitcherCell(
|
||||
title: S.current.settings_save_recipient_address,
|
||||
value: _privacySettingsViewModel.shouldSaveRecipientAddress,
|
||||
onValueChange: (BuildContext _, bool value) {
|
||||
_privacySettingsViewModel.setShouldSaveRecipientAddress(value);
|
||||
})
|
||||
],
|
||||
);
|
||||
],
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ class SettingsLinkProviderCell extends StandardListRow {
|
||||
color: Palette.blueCraiola));
|
||||
|
||||
static void _launchUrl(String url) async {
|
||||
if (await canLaunch(url)) await launch(url, forceSafariVC: false);
|
||||
try {
|
||||
await launch(url, forceSafariVC: false);
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class CheckBoxPickerState extends State<CheckBoxPicker> {
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
if (widget.title?.isNotEmpty ?? false)
|
||||
if (widget.title.isNotEmpty)
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Text(
|
||||
@@ -58,7 +58,7 @@ class CheckBoxPickerState extends State<CheckBoxPicker> {
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.all(Radius.circular(30)),
|
||||
child: Container(
|
||||
color: Theme.of(context).accentTextTheme!.headline6!.color!,
|
||||
color: Theme.of(context).accentTextTheme.headline6!.color!,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.of(context).size.height * 0.65,
|
||||
@@ -70,7 +70,7 @@ class CheckBoxPickerState extends State<CheckBoxPicker> {
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: <Widget>[
|
||||
(items?.length ?? 0) > 3
|
||||
(items.length) > 3
|
||||
? Scrollbar(
|
||||
controller: controller,
|
||||
child: itemsList(),
|
||||
@@ -95,14 +95,14 @@ class CheckBoxPickerState extends State<CheckBoxPicker> {
|
||||
|
||||
Widget itemsList() {
|
||||
return Container(
|
||||
color: Theme.of(context).accentTextTheme!.headline6!.backgroundColor!,
|
||||
color: Theme.of(context).accentTextTheme.headline6!.backgroundColor!,
|
||||
child: ListView.separated(
|
||||
padding: EdgeInsets.zero,
|
||||
controller: controller,
|
||||
shrinkWrap: true,
|
||||
separatorBuilder: (context, index) => widget.isSeparated
|
||||
? Divider(
|
||||
color: Theme.of(context).accentTextTheme!.headline6!.backgroundColor!,
|
||||
color: Theme.of(context).accentTextTheme.headline6!.backgroundColor!,
|
||||
height: 1,
|
||||
)
|
||||
: const SizedBox(),
|
||||
@@ -121,13 +121,13 @@ class CheckBoxPickerState extends State<CheckBoxPicker> {
|
||||
},
|
||||
child: Container(
|
||||
height: 55,
|
||||
color: Theme.of(context).accentTextTheme!.headline6!.color!,
|
||||
color: Theme.of(context).accentTextTheme.headline6!.color!,
|
||||
padding: EdgeInsets.only(left: 24, right: 24),
|
||||
child: CheckboxListTile(
|
||||
value: item.value,
|
||||
activeColor: item.value
|
||||
? Palette.blueCraiola
|
||||
: Theme.of(context).accentTextTheme!.subtitle1!.decorationColor!,
|
||||
: Theme.of(context).accentTextTheme.subtitle1!.decorationColor!,
|
||||
checkColor: Colors.white,
|
||||
title: widget.displayItem?.call(item) ??
|
||||
Text(
|
||||
@@ -138,7 +138,7 @@ class CheckBoxPickerState extends State<CheckBoxPicker> {
|
||||
fontWeight: FontWeight.w600,
|
||||
color: item.isDisabled
|
||||
? Colors.grey.withOpacity(0.5)
|
||||
: Theme.of(context).primaryTextTheme!.headline6!.color!,
|
||||
: Theme.of(context).primaryTextTheme.headline6!.color!,
|
||||
decoration: TextDecoration.none,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -12,7 +12,8 @@ abstract class TradeFilterStoreBase with Store {
|
||||
displayChangeNow = true,
|
||||
displaySideShift = true,
|
||||
displayMorphToken = true,
|
||||
displaySimpleSwap = true;
|
||||
displaySimpleSwap = true,
|
||||
displayTrocador = true;
|
||||
|
||||
@observable
|
||||
bool displayXMRTO;
|
||||
@@ -29,8 +30,11 @@ abstract class TradeFilterStoreBase with Store {
|
||||
@observable
|
||||
bool displaySimpleSwap;
|
||||
|
||||
@observable
|
||||
bool displayTrocador;
|
||||
|
||||
@computed
|
||||
bool get displayAllTrades => displayChangeNow && displaySideShift && displaySimpleSwap;
|
||||
bool get displayAllTrades => displayChangeNow && displaySideShift && displaySimpleSwap && displayTrocador;
|
||||
|
||||
@action
|
||||
void toggleDisplayExchange(ExchangeProviderDescription provider) {
|
||||
@@ -50,6 +54,9 @@ abstract class TradeFilterStoreBase with Store {
|
||||
case ExchangeProviderDescription.morphToken:
|
||||
displayMorphToken = !displayMorphToken;
|
||||
break;
|
||||
case ExchangeProviderDescription.trocador:
|
||||
displayTrocador = !displayTrocador;
|
||||
break;
|
||||
case ExchangeProviderDescription.all:
|
||||
if (displayAllTrades) {
|
||||
displayChangeNow = false;
|
||||
@@ -57,12 +64,14 @@ abstract class TradeFilterStoreBase with Store {
|
||||
displayXMRTO = false;
|
||||
displayMorphToken = false;
|
||||
displaySimpleSwap = false;
|
||||
displayTrocador = false;
|
||||
} else {
|
||||
displayChangeNow = true;
|
||||
displaySideShift = true;
|
||||
displayXMRTO = true;
|
||||
displayMorphToken = true;
|
||||
displaySimpleSwap = true;
|
||||
displayTrocador = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -88,7 +97,8 @@ abstract class TradeFilterStoreBase with Store {
|
||||
ExchangeProviderDescription.morphToken)
|
||||
||(displaySimpleSwap &&
|
||||
item.trade.provider ==
|
||||
ExchangeProviderDescription.simpleSwap))
|
||||
ExchangeProviderDescription.simpleSwap)
|
||||
||(displayTrocador && item.trade.provider == ExchangeProviderDescription.trocador))
|
||||
.toList()
|
||||
: _trades;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/pin_code_required_duration.dart';
|
||||
import 'package:cake_wallet/entities/preferences_key.dart';
|
||||
import 'package:cw_core/transaction_priority.dart';
|
||||
@@ -31,7 +32,7 @@ abstract class SettingsStoreBase with Store {
|
||||
required bool initialSaveRecipientAddress,
|
||||
required FiatApiMode initialFiatMode,
|
||||
required bool initialAllowBiometricalAuthentication,
|
||||
required bool initialExchangeEnabled,
|
||||
required ExchangeApiMode initialExchangeStatus,
|
||||
required ThemeBase initialTheme,
|
||||
required int initialPinLength,
|
||||
required String initialLanguageCode,
|
||||
@@ -53,7 +54,7 @@ abstract class SettingsStoreBase with Store {
|
||||
shouldSaveRecipientAddress = initialSaveRecipientAddress,
|
||||
fiatApiMode = initialFiatMode,
|
||||
allowBiometricalAuthentication = initialAllowBiometricalAuthentication,
|
||||
disableExchange = initialExchangeEnabled,
|
||||
exchangeStatus = initialExchangeStatus,
|
||||
currentTheme = initialTheme,
|
||||
pinCodeLength = initialPinLength,
|
||||
languageCode = initialLanguageCode,
|
||||
@@ -153,9 +154,9 @@ abstract class SettingsStoreBase with Store {
|
||||
PreferencesKey.currentBalanceDisplayModeKey, mode.serialize()));
|
||||
|
||||
reaction(
|
||||
(_) => disableExchange,
|
||||
(bool disableExchange) => sharedPreferences.setBool(
|
||||
PreferencesKey.disableExchangeKey, disableExchange));
|
||||
(_) => exchangeStatus,
|
||||
(ExchangeApiMode mode) => sharedPreferences.setInt(
|
||||
PreferencesKey.exchangeStatusKey, mode.serialize()));
|
||||
|
||||
this
|
||||
.nodes
|
||||
@@ -192,7 +193,7 @@ abstract class SettingsStoreBase with Store {
|
||||
bool allowBiometricalAuthentication;
|
||||
|
||||
@observable
|
||||
bool disableExchange;
|
||||
ExchangeApiMode exchangeStatus;
|
||||
|
||||
@observable
|
||||
ThemeBase currentTheme;
|
||||
@@ -284,8 +285,9 @@ abstract class SettingsStoreBase with Store {
|
||||
final allowBiometricalAuthentication = sharedPreferences
|
||||
.getBool(PreferencesKey.allowBiometricalAuthenticationKey) ??
|
||||
false;
|
||||
final disableExchange = sharedPreferences
|
||||
.getBool(PreferencesKey.disableExchangeKey) ?? false;
|
||||
final exchangeStatus = ExchangeApiMode.deserialize(
|
||||
raw: sharedPreferences
|
||||
.getInt(PreferencesKey.exchangeStatusKey) ?? ExchangeApiMode.enabled.raw);
|
||||
final legacyTheme =
|
||||
(sharedPreferences.getBool(PreferencesKey.isDarkThemeLegacy) ?? false)
|
||||
? ThemeType.dark.index
|
||||
@@ -354,7 +356,7 @@ abstract class SettingsStoreBase with Store {
|
||||
initialSaveRecipientAddress: shouldSaveRecipientAddress,
|
||||
initialFiatMode: currentFiatApiMode,
|
||||
initialAllowBiometricalAuthentication: allowBiometricalAuthentication,
|
||||
initialExchangeEnabled: disableExchange,
|
||||
initialExchangeStatus: exchangeStatus,
|
||||
initialTheme: savedTheme,
|
||||
actionlistDisplayMode: actionListDisplayMode,
|
||||
initialPinLength: pinLength,
|
||||
@@ -400,7 +402,9 @@ abstract class SettingsStoreBase with Store {
|
||||
allowBiometricalAuthentication = sharedPreferences
|
||||
.getBool(PreferencesKey.allowBiometricalAuthenticationKey) ??
|
||||
allowBiometricalAuthentication;
|
||||
disableExchange = sharedPreferences.getBool(PreferencesKey.disableExchangeKey) ?? disableExchange;
|
||||
exchangeStatus = ExchangeApiMode.deserialize(
|
||||
raw: sharedPreferences
|
||||
.getInt(PreferencesKey.exchangeStatusKey) ?? ExchangeApiMode.enabled.raw);
|
||||
final legacyTheme =
|
||||
(sharedPreferences.getBool(PreferencesKey.isDarkThemeLegacy) ?? false)
|
||||
? ThemeType.dark.index
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cake_wallet/entities/preferences_key.dart';
|
||||
@@ -6,9 +5,11 @@ import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/main.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mailer/flutter_mailer.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
@@ -31,7 +32,7 @@ class ExceptionHandler {
|
||||
==========================================================\n\n''';
|
||||
|
||||
await file.writeAsString(
|
||||
jsonEncode(exception) + separator,
|
||||
"$exception $separator",
|
||||
mode: FileMode.append,
|
||||
);
|
||||
}
|
||||
@@ -42,6 +43,8 @@ class ExceptionHandler {
|
||||
|
||||
final file = File('${appDocDir.path}/error.txt');
|
||||
|
||||
await _addDeviceInfo(file);
|
||||
|
||||
final MailOptions mailOptions = MailOptions(
|
||||
subject: 'Mobile App Issue',
|
||||
recipients: ['support@cakewallet.com'],
|
||||
@@ -121,13 +124,97 @@ class ExceptionHandler {
|
||||
_ignoredErrors.any((element) => error.contains(element));
|
||||
|
||||
static const List<String> _ignoredErrors = const [
|
||||
"errno = 103", // SocketException: Software caused connection abort
|
||||
"errno = 9", // SocketException: Bad file descriptor
|
||||
"errno = 32", // SocketException: Write failed (OS Error: Broken pipe)
|
||||
"errno = 60", // SocketException: Operation timed out
|
||||
"errno = 54", // SocketException: Connection reset by peer
|
||||
"errno = 49", // SocketException: Can't assign requested address
|
||||
"errno = 28", // OS Error: No space left on device
|
||||
"errno = 32", // SocketException: Write failed (OS Error: Broken pipe)
|
||||
"errno = 49", // SocketException: Can't assign requested address
|
||||
"errno = 54", // SocketException: Connection reset by peer
|
||||
"errno = 57", // SocketException: Read failed (OS Error: Socket is not connected)
|
||||
"errno = 60", // SocketException: Operation timed out
|
||||
"errno = 103", // SocketException: Software caused connection abort
|
||||
"errno = 104", // SocketException: Connection reset by peer
|
||||
"errno = 110", // SocketException: Connection timed out
|
||||
"PERMISSION_NOT_GRANTED",
|
||||
];
|
||||
|
||||
static Future<void> _addDeviceInfo(File file) async {
|
||||
final packageInfo = await PackageInfo.fromPlatform();
|
||||
final currentVersion = packageInfo.version;
|
||||
|
||||
final deviceInfoPlugin = DeviceInfoPlugin();
|
||||
Map<String, dynamic> deviceInfo = {};
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
deviceInfo = _readAndroidBuildData(await deviceInfoPlugin.androidInfo);
|
||||
deviceInfo["Platform"] = "Android";
|
||||
} else if (Platform.isIOS) {
|
||||
deviceInfo = _readIosDeviceInfo(await deviceInfoPlugin.iosInfo);
|
||||
deviceInfo["Platform"] = "iOS";
|
||||
} else if (Platform.isLinux) {
|
||||
deviceInfo = _readLinuxDeviceInfo(await deviceInfoPlugin.linuxInfo);
|
||||
deviceInfo["Platform"] = "Linux";
|
||||
} else if (Platform.isMacOS) {
|
||||
deviceInfo = _readMacOsDeviceInfo(await deviceInfoPlugin.macOsInfo);
|
||||
deviceInfo["Platform"] = "MacOS";
|
||||
} else if (Platform.isWindows) {
|
||||
deviceInfo = _readWindowsDeviceInfo(await deviceInfoPlugin.windowsInfo);
|
||||
deviceInfo["Platform"] = "Windows";
|
||||
}
|
||||
|
||||
await file.writeAsString(
|
||||
"App Version: $currentVersion\n\nDevice Info $deviceInfo",
|
||||
mode: FileMode.append,
|
||||
);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> _readAndroidBuildData(AndroidDeviceInfo build) {
|
||||
return <String, dynamic>{
|
||||
'brand': build.brand,
|
||||
'device': build.device,
|
||||
'manufacturer': build.manufacturer,
|
||||
'model': build.model,
|
||||
'product': build.product,
|
||||
};
|
||||
}
|
||||
|
||||
static Map<String, dynamic> _readIosDeviceInfo(IosDeviceInfo data) {
|
||||
return <String, dynamic>{
|
||||
'systemName': data.systemName,
|
||||
'systemVersion': data.systemVersion,
|
||||
'model': data.model,
|
||||
'localizedModel': data.localizedModel,
|
||||
};
|
||||
}
|
||||
|
||||
static Map<String, dynamic> _readLinuxDeviceInfo(LinuxDeviceInfo data) {
|
||||
return <String, dynamic>{
|
||||
'name': data.name,
|
||||
'version': data.version,
|
||||
'versionCodename': data.versionCodename,
|
||||
'versionId': data.versionId,
|
||||
'prettyName': data.prettyName,
|
||||
'buildId': data.buildId,
|
||||
'variant': data.variant,
|
||||
'variantId': data.variantId,
|
||||
};
|
||||
}
|
||||
|
||||
static Map<String, dynamic> _readMacOsDeviceInfo(MacOsDeviceInfo data) {
|
||||
return <String, dynamic>{
|
||||
'arch': data.arch,
|
||||
'model': data.model,
|
||||
'kernelVersion': data.kernelVersion,
|
||||
'osRelease': data.osRelease,
|
||||
};
|
||||
}
|
||||
|
||||
static Map<String, dynamic> _readWindowsDeviceInfo(WindowsDeviceInfo data) {
|
||||
return <String, dynamic>{
|
||||
'majorVersion': data.majorVersion,
|
||||
'minorVersion': data.minorVersion,
|
||||
'buildNumber': data.buildNumber,
|
||||
'productType': data.productType,
|
||||
'productName': data.productName,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,37 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:cross_file/cross_file.dart';
|
||||
|
||||
class ShareUtil {
|
||||
static void share({required String text, required BuildContext context}) {
|
||||
final box = context.findRenderObject() as RenderBox?;
|
||||
static const _mimeType = 'application/*';
|
||||
|
||||
static void share({required String text, required BuildContext context}) {
|
||||
Share.share(
|
||||
text,
|
||||
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
||||
sharePositionOrigin: _sharePosition(context),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> shareFile({
|
||||
required String filePath,
|
||||
required String fileName,
|
||||
required BuildContext context,
|
||||
}) async {
|
||||
Share.shareXFiles(
|
||||
<XFile>[
|
||||
XFile(
|
||||
filePath,
|
||||
name: fileName,
|
||||
mimeType: _mimeType,
|
||||
)
|
||||
],
|
||||
sharePositionOrigin: _sharePosition(context),
|
||||
);
|
||||
}
|
||||
|
||||
static Rect? _sharePosition(BuildContext context) {
|
||||
final box = context.findRenderObject() as RenderBox?;
|
||||
|
||||
return box!.localToGlobal(Offset.zero) & box.size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/view_model/settings/switcher_list_item.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
|
||||
part 'advanced_privacy_settings_view_model.g.dart';
|
||||
|
||||
@@ -11,46 +10,30 @@ class AdvancedPrivacySettingsViewModel = AdvancedPrivacySettingsViewModelBase
|
||||
with _$AdvancedPrivacySettingsViewModel;
|
||||
|
||||
abstract class AdvancedPrivacySettingsViewModelBase with Store {
|
||||
AdvancedPrivacySettingsViewModelBase(this.type, this._settingsStore)
|
||||
: _addCustomNode = false {
|
||||
settings = [
|
||||
SwitcherListItem(
|
||||
title: S.current.disable_fiat,
|
||||
value: () => _settingsStore.fiatApiMode == FiatApiMode.disabled,
|
||||
onValueChange: (_, bool value) => setFiatMode(value),
|
||||
),
|
||||
SwitcherListItem(
|
||||
title: S.current.disable_exchange,
|
||||
value: () => _settingsStore.disableExchange,
|
||||
onValueChange: (_, bool value) {
|
||||
_settingsStore.disableExchange = value;
|
||||
},
|
||||
),
|
||||
SwitcherListItem(
|
||||
title: S.current.add_custom_node,
|
||||
value: () => _addCustomNode,
|
||||
onValueChange: (_, bool value) => _addCustomNode = value,
|
||||
),
|
||||
];
|
||||
}
|
||||
AdvancedPrivacySettingsViewModelBase(this.type, this._settingsStore) : _addCustomNode = false;
|
||||
|
||||
late List<SwitcherListItem> settings;
|
||||
@computed
|
||||
ExchangeApiMode get exchangeStatus => _settingsStore.exchangeStatus;
|
||||
|
||||
@computed
|
||||
FiatApiMode get fiatApiMode => _settingsStore.fiatApiMode;
|
||||
|
||||
@observable
|
||||
bool _addCustomNode = false;
|
||||
|
||||
final WalletType type;
|
||||
|
||||
final SettingsStore _settingsStore;
|
||||
|
||||
@computed
|
||||
bool get addCustomNode => _addCustomNode;
|
||||
|
||||
@action
|
||||
void setFiatMode(bool value) {
|
||||
if (value) {
|
||||
_settingsStore.fiatApiMode = FiatApiMode.disabled;
|
||||
return;
|
||||
}
|
||||
_settingsStore.fiatApiMode = FiatApiMode.enabled;
|
||||
}
|
||||
void setFiatApiMode(FiatApiMode fiatApiMode) => _settingsStore.fiatApiMode = fiatApiMode;
|
||||
|
||||
@action
|
||||
void setExchangeApiMode(ExchangeApiMode value) => _settingsStore.exchangeStatus = value;
|
||||
|
||||
@action
|
||||
void toggleAddCustomNode() => _addCustomNode = !_addCustomNode;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:cake_wallet/wallet_type_utils.dart';
|
||||
import 'package:cw_core/transaction_history.dart';
|
||||
import 'package:cw_core/balance.dart';
|
||||
@@ -96,6 +98,11 @@ abstract class DashboardViewModelBase with Store {
|
||||
caption: ExchangeProviderDescription.simpleSwap.title,
|
||||
onChanged: () => tradeFilterStore
|
||||
.toggleDisplayExchange(ExchangeProviderDescription.simpleSwap)),
|
||||
FilterItem(
|
||||
value: () => tradeFilterStore.displayTrocador,
|
||||
caption: ExchangeProviderDescription.trocador.title,
|
||||
onChanged: () => tradeFilterStore
|
||||
.toggleDisplayExchange(ExchangeProviderDescription.trocador)),
|
||||
]
|
||||
},
|
||||
subname = '',
|
||||
@@ -268,7 +275,7 @@ abstract class DashboardViewModelBase with Store {
|
||||
settingsStore.shouldShowYatPopup = shouldShow;
|
||||
|
||||
@computed
|
||||
bool get isEnabledExchangeAction => !settingsStore.disableExchange;
|
||||
bool get isEnabledExchangeAction => settingsStore.exchangeStatus != ExchangeApiMode.disabled;
|
||||
|
||||
@observable
|
||||
bool hasExchangeAction;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'package:cake_wallet/exchange/sideshift/sideshift_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/simpleswap/simpleswap_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/trocador/trocador_exchange_provider.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cake_wallet/exchange/changenow/changenow_exchange_provider.dart';
|
||||
@@ -46,6 +47,9 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||
case ExchangeProviderDescription.simpleSwap:
|
||||
_provider = SimpleSwapExchangeProvider();
|
||||
break;
|
||||
case ExchangeProviderDescription.trocador:
|
||||
_provider = TrocadorExchangeProvider();
|
||||
break;
|
||||
}
|
||||
|
||||
_updateItems();
|
||||
|
||||
@@ -2,11 +2,15 @@ import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/preferences_key.dart';
|
||||
import 'package:cake_wallet/exchange/sideshift/sideshift_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/sideshift/sideshift_request.dart';
|
||||
import 'package:cake_wallet/exchange/simpleswap/simpleswap_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/simpleswap/simpleswap_request.dart';
|
||||
import 'package:cake_wallet/exchange/trocador/trocador_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/trocador/trocador_request.dart';
|
||||
import 'package:cw_core/transaction_priority.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
@@ -53,6 +57,7 @@ abstract class ExchangeViewModelBase with Store {
|
||||
isDepositAddressEnabled = false,
|
||||
isReceiveAddressEnabled = false,
|
||||
isReceiveAmountEditable = false,
|
||||
_useTorOnly = false,
|
||||
receiveCurrencies = <CryptoCurrency>[],
|
||||
depositCurrencies = <CryptoCurrency>[],
|
||||
limits = Limits(min: 0, max: 0),
|
||||
@@ -60,8 +65,10 @@ abstract class ExchangeViewModelBase with Store {
|
||||
limitsState = LimitsInitialState(),
|
||||
receiveCurrency = wallet.currency,
|
||||
depositCurrency = wallet.currency,
|
||||
providerList = [ChangeNowExchangeProvider(), SideShiftExchangeProvider(), SimpleSwapExchangeProvider()],
|
||||
providerList = [],
|
||||
selectedProviders = ObservableList<ExchangeProvider>() {
|
||||
_useTorOnly = _settingsStore.exchangeStatus == ExchangeApiMode.torOnly;
|
||||
_setProviders();
|
||||
const excludeDepositCurrencies = [CryptoCurrency.btt, CryptoCurrency.nano];
|
||||
const excludeReceiveCurrencies = [CryptoCurrency.xlm, CryptoCurrency.xrp,
|
||||
CryptoCurrency.bnb, CryptoCurrency.btt, CryptoCurrency.nano];
|
||||
@@ -117,13 +124,20 @@ abstract class ExchangeViewModelBase with Store {
|
||||
_calculateBestRate();
|
||||
});
|
||||
}
|
||||
|
||||
bool _useTorOnly;
|
||||
final WalletBase wallet;
|
||||
final Box<Trade> trades;
|
||||
final ExchangeTemplateStore _exchangeTemplateStore;
|
||||
final TradesStore tradesStore;
|
||||
final SharedPreferences sharedPreferences;
|
||||
|
||||
List<ExchangeProvider> get _allProviders => [
|
||||
ChangeNowExchangeProvider(),
|
||||
SideShiftExchangeProvider(),
|
||||
SimpleSwapExchangeProvider(),
|
||||
TrocadorExchangeProvider(useTorOnly: _useTorOnly),
|
||||
];
|
||||
|
||||
@observable
|
||||
ExchangeProvider? provider;
|
||||
|
||||
@@ -455,6 +469,18 @@ abstract class ExchangeViewModelBase with Store {
|
||||
amount = isFixedRateMode ? receiveAmount : depositAmount;
|
||||
}
|
||||
|
||||
if (provider is TrocadorExchangeProvider) {
|
||||
request = TrocadorRequest(
|
||||
from: depositCurrency,
|
||||
to: receiveCurrency,
|
||||
fromAmount: depositAmount.replaceAll(',', '.'),
|
||||
toAmount: receiveAmount.replaceAll(',', '.'),
|
||||
refundAddress: depositAddress,
|
||||
address: receiveAddress,
|
||||
isReverse: isFixedRateMode);
|
||||
amount = isFixedRateMode ? receiveAmount : depositAmount;
|
||||
}
|
||||
|
||||
amount = amount.replaceAll(',', '.');
|
||||
|
||||
if (limitsState is LimitsLoadedSuccessfully) {
|
||||
@@ -675,4 +701,12 @@ abstract class ExchangeViewModelBase with Store {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _setProviders(){
|
||||
if (_settingsStore.exchangeStatus == ExchangeApiMode.torOnly) {
|
||||
providerList = _allProviders.where((provider) => provider.supportsOnionAddress).toList();
|
||||
} else {
|
||||
providerList = _allProviders;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
@@ -12,27 +13,21 @@ abstract class PrivacySettingsViewModelBase with Store {
|
||||
final SettingsStore _settingsStore;
|
||||
|
||||
@computed
|
||||
bool get disableExchange => _settingsStore.disableExchange;
|
||||
ExchangeApiMode get exchangeStatus => _settingsStore.exchangeStatus;
|
||||
|
||||
@computed
|
||||
bool get shouldSaveRecipientAddress => _settingsStore.shouldSaveRecipientAddress;
|
||||
|
||||
@computed
|
||||
bool get isFiatDisabled => _settingsStore.fiatApiMode == FiatApiMode.disabled;
|
||||
FiatApiMode get fiatApiMode => _settingsStore.fiatApiMode;
|
||||
|
||||
@action
|
||||
void setShouldSaveRecipientAddress(bool value) => _settingsStore.shouldSaveRecipientAddress = value;
|
||||
|
||||
@action
|
||||
void setEnableExchange(bool value) => _settingsStore.disableExchange = value;
|
||||
void setExchangeApiMode(ExchangeApiMode value) => _settingsStore.exchangeStatus = value;
|
||||
|
||||
@action
|
||||
void setFiatMode(bool value) {
|
||||
if (value) {
|
||||
_settingsStore.fiatApiMode = FiatApiMode.disabled;
|
||||
return;
|
||||
}
|
||||
_settingsStore.fiatApiMode = FiatApiMode.enabled;
|
||||
}
|
||||
void setFiatMode(FiatApiMode fiatApiMode) => _settingsStore.fiatApiMode = fiatApiMode;
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:cake_wallet/wallet_type_utils.dart';
|
||||
import 'package:cake_wallet/wallet_type_utils.dart';
|
||||
|
||||
part 'support_view_model.g.dart';
|
||||
|
||||
@@ -19,7 +18,9 @@ abstract class SupportViewModelBase with Store {
|
||||
RegularListItem(
|
||||
title: S.current.faq,
|
||||
handler: (BuildContext context) async {
|
||||
if (await canLaunch(url)) await launch(url);
|
||||
try {
|
||||
await launch(url);
|
||||
} catch (e) {}
|
||||
},
|
||||
),
|
||||
LinkListItem(
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:cake_wallet/exchange/morphtoken/morphtoken_exchange_provider.dar
|
||||
import 'package:cake_wallet/exchange/sideshift/sideshift_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/simpleswap/simpleswap_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/trade.dart';
|
||||
import 'package:cake_wallet/exchange/trocador/trocador_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/xmrto/xmrto_exchange_provider.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/utils/date_formatter.dart';
|
||||
@@ -22,16 +23,15 @@ import 'package:cake_wallet/src/screens/trade_details/trade_details_status_item.
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
part 'trade_details_view_model.g.dart';
|
||||
|
||||
class TradeDetailsViewModel = TradeDetailsViewModelBase
|
||||
with _$TradeDetailsViewModel;
|
||||
class TradeDetailsViewModel = TradeDetailsViewModelBase with _$TradeDetailsViewModel;
|
||||
|
||||
abstract class TradeDetailsViewModelBase with Store {
|
||||
TradeDetailsViewModelBase({
|
||||
required Trade tradeForDetails,
|
||||
required this.trades,
|
||||
required this.settingsStore})
|
||||
: items = ObservableList<StandartListItem>(),
|
||||
trade = tradeForDetails {
|
||||
required this.settingsStore,
|
||||
}) : items = ObservableList<StandartListItem>(),
|
||||
trade = tradeForDetails {
|
||||
switch (trade.provider) {
|
||||
case ExchangeProviderDescription.xmrto:
|
||||
_provider = XMRTOExchangeProvider();
|
||||
@@ -45,9 +45,12 @@ abstract class TradeDetailsViewModelBase with Store {
|
||||
case ExchangeProviderDescription.sideShift:
|
||||
_provider = SideShiftExchangeProvider();
|
||||
break;
|
||||
case ExchangeProviderDescription.simpleSwap:
|
||||
case ExchangeProviderDescription.simpleSwap:
|
||||
_provider = SimpleSwapExchangeProvider();
|
||||
break;
|
||||
case ExchangeProviderDescription.trocador:
|
||||
_provider = TrocadorExchangeProvider();
|
||||
break;
|
||||
}
|
||||
|
||||
items = ObservableList<StandartListItem>();
|
||||
@@ -96,12 +99,7 @@ abstract class TradeDetailsViewModelBase with Store {
|
||||
items.clear();
|
||||
|
||||
items.add(
|
||||
DetailsListStatusItem(
|
||||
title: S.current.trade_details_state,
|
||||
value: trade.state != null
|
||||
? trade.state.toString()
|
||||
: S.current.trade_details_fetching)
|
||||
);
|
||||
DetailsListStatusItem(title: S.current.trade_details_state, value: trade.state.toString()));
|
||||
|
||||
items.add(TradeDetailsListCardItem.tradeDetails(
|
||||
id: trade.id,
|
||||
@@ -114,15 +112,11 @@ abstract class TradeDetailsViewModelBase with Store {
|
||||
},
|
||||
));
|
||||
|
||||
if (trade.provider != null) {
|
||||
items.add(StandartListItem(
|
||||
title: S.current.trade_details_provider,
|
||||
value: trade.provider.toString()));
|
||||
}
|
||||
items.add(StandartListItem(
|
||||
title: S.current.trade_details_provider, value: trade.provider.toString()));
|
||||
|
||||
if (trade.provider == ExchangeProviderDescription.changeNow) {
|
||||
final buildURL =
|
||||
'https://changenow.io/exchange/txs/${trade.id.toString()}';
|
||||
final buildURL = 'https://changenow.io/exchange/txs/${trade.id.toString()}';
|
||||
items.add(TrackTradeListItem(
|
||||
title: 'Track',
|
||||
value: buildURL,
|
||||
@@ -133,14 +127,25 @@ abstract class TradeDetailsViewModelBase with Store {
|
||||
|
||||
if (trade.provider == ExchangeProviderDescription.sideShift) {
|
||||
final buildURL = 'https://sideshift.ai/orders/${trade.id.toString()}';
|
||||
items.add(TrackTradeListItem(
|
||||
title: 'Track', value: buildURL, onTap: () => launch(buildURL)));
|
||||
items.add(TrackTradeListItem(title: 'Track', value: buildURL, onTap: () => launch(buildURL)));
|
||||
}
|
||||
|
||||
if (trade.provider == ExchangeProviderDescription.simpleSwap) {
|
||||
final buildURL = 'https://simpleswap.io/exchange?id=${trade.id.toString()}';
|
||||
items.add(TrackTradeListItem(
|
||||
title: 'Track', value: buildURL, onTap: () => launch(buildURL)));
|
||||
items.add(TrackTradeListItem(title: 'Track', value: buildURL, onTap: () => launch(buildURL)));
|
||||
}
|
||||
|
||||
if (trade.provider == ExchangeProviderDescription.trocador) {
|
||||
final buildURL = 'https://trocador.app/en/checkout/${trade.id.toString()}';
|
||||
items.add(TrackTradeListItem(title: 'Track', value: buildURL, onTap: () => launch(buildURL)));
|
||||
|
||||
items.add(StandartListItem(
|
||||
title: '${trade.providerName} ${S.current.id.toUpperCase()}',
|
||||
value: trade.providerId ?? ''));
|
||||
|
||||
if (trade.password != null && trade.password!.isNotEmpty)
|
||||
items.add(StandartListItem(
|
||||
title: '${trade.providerName} ${S.current.password}', value: trade.password ?? ''));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user