mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
12e3001b3a
* Disable Ledger for MacOS * increase update duration for Solana [skip ci] * change tron default Node Update build number * Add disabling tron grid to privacy settings * update monero.com versions [skip ci]
41 lines
1.4 KiB
Dart
41 lines
1.4 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:on_chain/tron/tron.dart';
|
|
import '.secrets.g.dart' as secrets;
|
|
|
|
class TronHTTPProvider implements TronServiceProvider {
|
|
TronHTTPProvider(
|
|
{required this.url,
|
|
http.Client? client,
|
|
this.defaultRequestTimeout = const Duration(seconds: 30)})
|
|
: client = client ?? http.Client();
|
|
@override
|
|
final String url;
|
|
final http.Client client;
|
|
final Duration defaultRequestTimeout;
|
|
|
|
@override
|
|
Future<Map<String, dynamic>> get(TronRequestDetails params, [Duration? timeout]) async {
|
|
final response = await client.get(Uri.parse(params.url(url)), headers: {
|
|
'Content-Type': 'application/json',
|
|
if (url.contains("trongrid")) 'TRON-PRO-API-KEY': secrets.tronGridApiKey,
|
|
}).timeout(timeout ?? defaultRequestTimeout);
|
|
final data = json.decode(response.body) as Map<String, dynamic>;
|
|
return data;
|
|
}
|
|
|
|
@override
|
|
Future<Map<String, dynamic>> post(TronRequestDetails params, [Duration? timeout]) async {
|
|
final response = await client
|
|
.post(Uri.parse(params.url(url)),
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
if (url.contains("trongrid")) 'TRON-PRO-API-KEY': secrets.tronGridApiKey,
|
|
},
|
|
body: params.toRequestBody())
|
|
.timeout(timeout ?? defaultRequestTimeout);
|
|
final data = json.decode(response.body) as Map<String, dynamic>;
|
|
return data;
|
|
}
|
|
}
|