mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 20:39:51 +00:00
feat: Migrate to EtherScan v2 API for supported EVM chains (#2264)
This commit is contained in:
parent
d356d5bfcb
commit
1aac17676d
3 changed files with 18 additions and 12 deletions
|
@ -19,7 +19,8 @@ class EthereumClient extends EVMChainClient {
|
|||
Future<List<EVMChainTransactionModel>> fetchTransactions(String address,
|
||||
{String? contractAddress}) async {
|
||||
try {
|
||||
final response = await httpClient.get(Uri.https("api.etherscan.io", "/api", {
|
||||
final response = await httpClient.get(Uri.https("api.etherscan.io", "/v2/api", {
|
||||
"chainid": "$chainId",
|
||||
"module": "account",
|
||||
"action": contractAddress != null ? "tokentx" : "txlist",
|
||||
if (contractAddress != null) "contractaddress": contractAddress,
|
||||
|
@ -50,7 +51,8 @@ class EthereumClient extends EVMChainClient {
|
|||
@override
|
||||
Future<List<EVMChainTransactionModel>> fetchInternalTransactions(String address) async {
|
||||
try {
|
||||
final response = await httpClient.get(Uri.https("api.etherscan.io", "/api", {
|
||||
final response = await httpClient.get(Uri.https("api.etherscan.io", "/v2/api", {
|
||||
"chainid": "$chainId",
|
||||
"module": "account",
|
||||
"action": "txlistinternal",
|
||||
"address": address,
|
||||
|
|
|
@ -40,12 +40,13 @@ class PolygonClient extends EVMChainClient {
|
|||
Future<List<EVMChainTransactionModel>> fetchTransactions(String address,
|
||||
{String? contractAddress}) async {
|
||||
try {
|
||||
final response = await httpClient.get(Uri.https("api.polygonscan.com", "/api", {
|
||||
final response = await httpClient.get(Uri.https("api.etherscan.io", "/v2/api", {
|
||||
"chainid": "$chainId",
|
||||
"module": "account",
|
||||
"action": contractAddress != null ? "tokentx" : "txlist",
|
||||
if (contractAddress != null) "contractaddress": contractAddress,
|
||||
"address": address,
|
||||
"apikey": secrets.polygonScanApiKey,
|
||||
"apikey": secrets.etherScanApiKey,
|
||||
}));
|
||||
|
||||
final jsonResponse = json.decode(response.body) as Map<String, dynamic>;
|
||||
|
@ -67,11 +68,12 @@ class PolygonClient extends EVMChainClient {
|
|||
@override
|
||||
Future<List<EVMChainTransactionModel>> fetchInternalTransactions(String address) async {
|
||||
try {
|
||||
final response = await httpClient.get(Uri.https("api.polygonscan.io", "/api", {
|
||||
final response = await httpClient.get(Uri.https("api.etherscan.io", "/v2/api", {
|
||||
"chainid": "$chainId",
|
||||
"module": "account",
|
||||
"action": "txlistinternal",
|
||||
"address": address,
|
||||
"apikey": secrets.polygonScanApiKey,
|
||||
"apikey": secrets.etherScanApiKey,
|
||||
}));
|
||||
|
||||
final jsonResponse = json.decode(response.body) as Map<String, dynamic>;
|
||||
|
|
|
@ -297,13 +297,14 @@ abstract class HomeSettingsViewModelBase with Store {
|
|||
required bool isEthereum,
|
||||
}) async {
|
||||
final uri = Uri.https(
|
||||
isEthereum ? "api.etherscan.io" : "api.polygonscan.com",
|
||||
"/api",
|
||||
"api.etherscan.io",
|
||||
"/v2/api",
|
||||
{
|
||||
"chainid": isEthereum ? "1" : "137",
|
||||
"module": "token",
|
||||
"action": "tokeninfo",
|
||||
"contractaddress": contractAddress,
|
||||
"apikey": isEthereum ? secrets.etherScanApiKey : secrets.polygonScanApiKey,
|
||||
"apikey": secrets.etherScanApiKey,
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -338,13 +339,14 @@ abstract class HomeSettingsViewModelBase with Store {
|
|||
required bool isEthereum,
|
||||
}) async {
|
||||
final uri = Uri.https(
|
||||
isEthereum ? "api.etherscan.io" : "api.polygonscan.com",
|
||||
"/api",
|
||||
"api.etherscan.io",
|
||||
"/v2/api",
|
||||
{
|
||||
"chainid": isEthereum ? "1" : "137",
|
||||
"module": "contract",
|
||||
"action": "getsourcecode",
|
||||
"address": contractAddress,
|
||||
"apikey": isEthereum ? secrets.etherScanApiKey : secrets.polygonScanApiKey,
|
||||
"apikey": secrets.etherScanApiKey,
|
||||
},
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue