cake_wallet/cw_tron/lib/tron_http_provider.dart
Adegoke David a319e10156
Some checks failed
Cache Dependencies / test (push) Has been cancelled
CW-653-Migrate-Tron-And-Solana-To-NowNodes (#1492)
* chore: Setup

* feat: Add NowNodes for Tron Wallet and switch it to be the default node for Tron

* feat: Add NowNodes for Solana Wallet and switch it to be the default node for Solana

* fix: Add nownodes entry to secrets

* fix: Remove pubspec.lock in shared external

* fix conflicts with main

* change secrets names

* feat: Remove Solana NowNodes config

* feat: Remove Solana NowNodes config

* feat: Revert commented out code

---------

Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-06-29 00:36:12 +03:00

43 lines
1.6 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,
if (url.contains("nownodes")) 'api-key': secrets.tronNowNodesApiKey,
}).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,
if (url.contains("nownodes")) 'api-key': secrets.tronNowNodesApiKey,
},
body: params.toRequestBody())
.timeout(timeout ?? defaultRequestTimeout);
final data = json.decode(response.body) as Map<String, dynamic>;
return data;
}
}