mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 12:09:43 +00:00
fetch fiat price in isolate again
This commit is contained in:
parent
62513bd933
commit
b5084c10ae
2 changed files with 12 additions and 5 deletions
|
@ -6,6 +6,7 @@ import 'package:cw_core/crypto_currency.dart';
|
||||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
const _fiatApiClearNetAuthority = 'fiat-api.cakewallet.com';
|
const _fiatApiClearNetAuthority = 'fiat-api.cakewallet.com';
|
||||||
const _fiatApiOnionAuthority = 'n4z7bdcmwk2oyddxvzaap3x2peqcplh3pzdy7tpkk5ejz5n4mhfvoxqd.onion';
|
const _fiatApiOnionAuthority = 'n4z7bdcmwk2oyddxvzaap3x2peqcplh3pzdy7tpkk5ejz5n4mhfvoxqd.onion';
|
||||||
|
@ -15,6 +16,7 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
||||||
final crypto = args['crypto'] as String;
|
final crypto = args['crypto'] as String;
|
||||||
final fiat = args['fiat'] as String;
|
final fiat = args['fiat'] as String;
|
||||||
final torOnly = args['apiMode'] as String == FiatApiMode.torOnly.toString();
|
final torOnly = args['apiMode'] as String == FiatApiMode.torOnly.toString();
|
||||||
|
final mainThreadProxyPort = args['port'] as int;
|
||||||
|
|
||||||
final Map<String, String> queryParams = {
|
final Map<String, String> queryParams = {
|
||||||
'interval_count': '1',
|
'interval_count': '1',
|
||||||
|
@ -29,7 +31,9 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
||||||
final Uri onionUri = Uri.http(_fiatApiOnionAuthority, _fiatApiPath, queryParams);
|
final Uri onionUri = Uri.http(_fiatApiOnionAuthority, _fiatApiPath, queryParams);
|
||||||
final Uri clearnetUri = Uri.https(_fiatApiClearNetAuthority, _fiatApiPath, queryParams);
|
final Uri clearnetUri = Uri.https(_fiatApiClearNetAuthority, _fiatApiPath, queryParams);
|
||||||
|
|
||||||
HttpClient client = await ProxyWrapper.instance.getProxyInstance();
|
HttpClient client = await ProxyWrapper.instance.getProxyInstance(
|
||||||
|
portOverride: mainThreadProxyPort,
|
||||||
|
);
|
||||||
late HttpClientResponse response;
|
late HttpClientResponse response;
|
||||||
late String responseBody;
|
late String responseBody;
|
||||||
|
|
||||||
|
@ -64,10 +68,11 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
||||||
|
|
||||||
Future<double> _fetchPriceAsync(
|
Future<double> _fetchPriceAsync(
|
||||||
CryptoCurrency crypto, FiatCurrency fiat, FiatApiMode apiMode) async =>
|
CryptoCurrency crypto, FiatCurrency fiat, FiatApiMode apiMode) async =>
|
||||||
_fetchPrice({
|
compute(_fetchPrice, {
|
||||||
'fiat': fiat.toString(),
|
'fiat': fiat.toString(),
|
||||||
'crypto': crypto.toString(),
|
'crypto': crypto.toString(),
|
||||||
'apiMode': apiMode.toString(),
|
'apiMode': apiMode.toString(),
|
||||||
|
'port': ProxyWrapper.port,
|
||||||
});
|
});
|
||||||
|
|
||||||
class FiatConversionService {
|
class FiatConversionService {
|
||||||
|
|
|
@ -17,8 +17,10 @@ class ProxyWrapper {
|
||||||
// Factory method to get the singleton instance of TorSingleton
|
// Factory method to get the singleton instance of TorSingleton
|
||||||
static ProxyWrapper get instance => _instance;
|
static ProxyWrapper get instance => _instance;
|
||||||
|
|
||||||
|
static int get port => Tor.instance.port;
|
||||||
|
|
||||||
// Method to get or create the Tor instance
|
// Method to get or create the Tor instance
|
||||||
Future<HttpClient> getProxyInstance() async {
|
Future<HttpClient> getProxyInstance({int? portOverride}) async {
|
||||||
if (!started) {
|
if (!started) {
|
||||||
started = true;
|
started = true;
|
||||||
_client = HttpClient();
|
_client = HttpClient();
|
||||||
|
@ -27,7 +29,7 @@ class ProxyWrapper {
|
||||||
SocksTCPClient.assignToHttpClient(_client!, [
|
SocksTCPClient.assignToHttpClient(_client!, [
|
||||||
ProxySettings(
|
ProxySettings(
|
||||||
InternetAddress.loopbackIPv4,
|
InternetAddress.loopbackIPv4,
|
||||||
Tor.instance.port,
|
portOverride ?? Tor.instance.port,
|
||||||
password: null,
|
password: null,
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in a new issue