refactor(apis): replace to-be-deprecated ethereum-api.xyz and blockchain-api.xyz calls (#349)
* refactor(dapp-v2): `ethereum-api.xyz` to `rpc.walletconnect.com` * refactor(with-ethers): `ethereum-api.xyz` -> `rpc.walletconnect.com` * refactor(with-web3js): `ethereum-api.xyz` -> `rpc.walletconnect.com` * refactor(cosmos-provider): `ethereum-api.xyz` -> `rpc.walletconnect.com` * refactor(apis): replace remaining `blockchain-api.xyz` calls with assets * chore: add leftover assets for test chains
|
After Width: | Height: | Size: 676 KiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 65 KiB |
@@ -1,12 +1,10 @@
|
||||
import { JsonRpcRequest } from "@walletconnect/jsonrpc-utils";
|
||||
|
||||
import { BLOCKCHAIN_LOGO_BASE_URL } from "../constants";
|
||||
|
||||
import { NamespaceMetadata, ChainMetadata, ChainRequestRender } from "../helpers";
|
||||
|
||||
export const CosmosMetadata: NamespaceMetadata = {
|
||||
"cosmoshub-4": {
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "cosmos:cosmoshub-4.png",
|
||||
logo: "/assets/" + "cosmos:cosmoshub-4.png",
|
||||
rgb: "27, 31, 53",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
convertHexToNumber,
|
||||
convertHexToUtf8,
|
||||
} from "../helpers";
|
||||
import { BLOCKCHAIN_LOGO_BASE_URL } from "../constants";
|
||||
|
||||
export const EIP155Colors = {
|
||||
ethereum: "99, 125, 234",
|
||||
@@ -22,55 +21,55 @@ export const EIP155Colors = {
|
||||
export const EIP155Metadata: NamespaceMetadata = {
|
||||
"1": {
|
||||
name: "Ethereum",
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:1.png",
|
||||
logo: "/assets/" + "eip155:1.png",
|
||||
rgb: EIP155Colors.ethereum,
|
||||
},
|
||||
"5": {
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:5.png",
|
||||
logo: "/assets/" + "eip155:5.png",
|
||||
rgb: EIP155Colors.goerli,
|
||||
},
|
||||
"10": {
|
||||
name: "Optimism",
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:10.png",
|
||||
logo: "/assets/" + "eip155:10.png",
|
||||
rgb: EIP155Colors.optimism,
|
||||
},
|
||||
"42": {
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:42.png",
|
||||
logo: "/assets/" + "eip155:42.png",
|
||||
rgb: EIP155Colors.ethereum,
|
||||
},
|
||||
"69": {
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:69.png",
|
||||
logo: "/assets/" + "eip155:69.png",
|
||||
rgb: EIP155Colors.optimism,
|
||||
},
|
||||
"100": {
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:100.png",
|
||||
logo: "/assets/" + "eip155:100.png",
|
||||
rgb: EIP155Colors.xdai,
|
||||
},
|
||||
"137": {
|
||||
name: "Polygon",
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:137.png",
|
||||
logo: "/assets/" + "eip155:137.png",
|
||||
rgb: EIP155Colors.polygon,
|
||||
},
|
||||
"80001": {
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:80001.png",
|
||||
logo: "/assets/" + "eip155:80001.png",
|
||||
rgb: EIP155Colors.polygon,
|
||||
},
|
||||
"42161": {
|
||||
name: "Arbitrum",
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:42161.png",
|
||||
logo: "/assets/" + "eip155:42161.png",
|
||||
rgb: EIP155Colors.arbitrum,
|
||||
},
|
||||
"42220": {
|
||||
name: "Celo",
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:42220.png",
|
||||
logo: "/assets/" + "eip155:42220.png",
|
||||
rgb: EIP155Colors.celo,
|
||||
},
|
||||
"44787": {
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:44787.png",
|
||||
logo: "/assets/" + "eip155:44787.png",
|
||||
rgb: EIP155Colors.celo,
|
||||
},
|
||||
"421611": {
|
||||
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:421611.png",
|
||||
logo: "/assets/" + "eip155:421611.png",
|
||||
rgb: EIP155Colors.arbitrum,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { JsonRpcRequest } from "@walletconnect/jsonrpc-utils";
|
||||
import { BLOCKCHAIN_LOGO_BASE_URL } from "../constants";
|
||||
|
||||
import { NamespaceMetadata, ChainMetadata, ChainRequestRender } from "../helpers";
|
||||
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
export * from "./default";
|
||||
export * from "./logo";
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export const BLOCKCHAIN_LOGO_BASE_URL = "https://blockchain-api.xyz/logos/";
|
||||
@@ -1,45 +1,159 @@
|
||||
import axios, { AxiosInstance } from "axios";
|
||||
import { AssetData, GasPrices, ParsedTx } from "./types";
|
||||
|
||||
const ethereumApi: AxiosInstance = axios.create({
|
||||
baseURL: "https://ethereum-api.xyz",
|
||||
timeout: 30000, // 30 secs
|
||||
export type RpcProvidersByChainId = Record<
|
||||
number,
|
||||
{
|
||||
name: string;
|
||||
baseURL: string;
|
||||
token: {
|
||||
name: string;
|
||||
symbol: string;
|
||||
};
|
||||
}
|
||||
>;
|
||||
|
||||
const WALLETCONNECT_RPC_BASE_URL = `https://rpc.walletconnect.com/v1?projectId=${process.env.NEXT_PUBLIC_PROJECT_ID}`;
|
||||
|
||||
export const rpcProvidersByChainId: RpcProvidersByChainId = {
|
||||
1: {
|
||||
name: "Ethereum Mainnet",
|
||||
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:1",
|
||||
token: {
|
||||
name: "Ether",
|
||||
symbol: "ETH",
|
||||
},
|
||||
},
|
||||
5: {
|
||||
name: "Ethereum Goerli",
|
||||
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:5",
|
||||
token: {
|
||||
name: "Ether",
|
||||
symbol: "ETH",
|
||||
},
|
||||
},
|
||||
137: {
|
||||
name: "Polygon Mainnet",
|
||||
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:137",
|
||||
token: {
|
||||
name: "Matic",
|
||||
symbol: "MATIC",
|
||||
},
|
||||
},
|
||||
280: {
|
||||
name: "zkSync Era Testnet",
|
||||
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:280",
|
||||
token: {
|
||||
name: "Ether",
|
||||
symbol: "ETH",
|
||||
},
|
||||
},
|
||||
324: {
|
||||
name: "zkSync Era",
|
||||
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:324",
|
||||
token: {
|
||||
name: "Ether",
|
||||
symbol: "ETH",
|
||||
},
|
||||
},
|
||||
80001: {
|
||||
name: "Polygon Mumbai",
|
||||
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:80001",
|
||||
token: {
|
||||
name: "Matic",
|
||||
symbol: "MATIC",
|
||||
},
|
||||
},
|
||||
10: {
|
||||
name: "Optimism",
|
||||
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:10",
|
||||
token: {
|
||||
name: "Ether",
|
||||
symbol: "ETH",
|
||||
},
|
||||
},
|
||||
420: {
|
||||
name: "Optimism Goerli",
|
||||
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:420",
|
||||
token: {
|
||||
name: "Ether",
|
||||
symbol: "ETH",
|
||||
},
|
||||
},
|
||||
42161: {
|
||||
name: "Arbitrum",
|
||||
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:42161",
|
||||
token: {
|
||||
name: "Ether",
|
||||
symbol: "ETH",
|
||||
},
|
||||
},
|
||||
421611: {
|
||||
name: "Arbitrum Rinkeby",
|
||||
baseURL: "https://rinkeby.arbitrum.io/rpc",
|
||||
token: {
|
||||
name: "Ether",
|
||||
symbol: "ETH",
|
||||
},
|
||||
},
|
||||
100: {
|
||||
name: "xDAI",
|
||||
baseURL: "https://xdai-archive.blockscout.com",
|
||||
token: {
|
||||
name: "xDAI",
|
||||
symbol: "xDAI",
|
||||
},
|
||||
},
|
||||
42220: {
|
||||
name: "Celo",
|
||||
baseURL: "https://rpc.walletconnect.com/v1",
|
||||
token: {
|
||||
name: "CELO",
|
||||
symbol: "CELO",
|
||||
},
|
||||
},
|
||||
44787: {
|
||||
name: "Celo Alfajores",
|
||||
baseURL: "https://alfajores-forno.celo-testnet.org",
|
||||
token: {
|
||||
name: "CELO",
|
||||
symbol: "CELO",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const api: AxiosInstance = axios.create({
|
||||
baseURL: "https://rpc.walletconnect.com/v1",
|
||||
timeout: 10000, // 10 secs
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
export async function apiGetAccountAssets(address: string, chainId: string): Promise<AssetData[]> {
|
||||
const ethChainId = chainId.split(":")[1];
|
||||
const response = await ethereumApi.get(
|
||||
`/account-assets?address=${address}&chainId=${ethChainId}`,
|
||||
);
|
||||
const { result } = response.data;
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function apiGetAccountTransactions(
|
||||
address: string,
|
||||
chainId: string,
|
||||
): Promise<ParsedTx[]> {
|
||||
const ethChainId = chainId.split(":")[1];
|
||||
const response = await ethereumApi.get(
|
||||
`/account-transactions?address=${address}&chainId=${ethChainId}`,
|
||||
);
|
||||
const { result } = response.data;
|
||||
return result;
|
||||
}
|
||||
|
||||
export const apiGetAccountNonce = async (address: string, chainId: string): Promise<number> => {
|
||||
debugger;
|
||||
const ethChainId = chainId.split(":")[1];
|
||||
const response = await ethereumApi.get(`/account-nonce?address=${address}&chainId=${ethChainId}`);
|
||||
const { baseURL } = rpcProvidersByChainId[Number(ethChainId)];
|
||||
const response = await api.post(baseURL, {
|
||||
jsonrpc: "2.0",
|
||||
method: "eth_getTransactionCount",
|
||||
params: [address, "latest"],
|
||||
id: 1,
|
||||
});
|
||||
const { result } = response.data;
|
||||
return result;
|
||||
const nonce = parseInt(result, 16);
|
||||
return nonce;
|
||||
};
|
||||
|
||||
export const apiGetGasPrices = async (): Promise<GasPrices> => {
|
||||
const response = await ethereumApi.get(`/gas-prices`);
|
||||
export const apiGetGasPrice = async (chainId: string): Promise<string> => {
|
||||
const ethChainId = chainId.split(":")[1];
|
||||
const { baseURL } = rpcProvidersByChainId[Number(ethChainId)];
|
||||
const response = await api.post(baseURL, {
|
||||
jsonrpc: "2.0",
|
||||
method: "eth_gasPrice",
|
||||
params: [],
|
||||
id: 1,
|
||||
});
|
||||
const { result } = response.data;
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import * as encoding from "@walletconnect/encoding";
|
||||
|
||||
import { apiGetAccountNonce, apiGetGasPrices } from "./api";
|
||||
import { toWad } from "./utilities";
|
||||
import { apiGetAccountNonce, apiGetGasPrice } from "./api";
|
||||
|
||||
export async function getGasPrice(chainId: string): Promise<string> {
|
||||
if (chainId === "eip155:1") return toWad("20", 9).toHexString();
|
||||
const gasPrices = await apiGetGasPrices();
|
||||
return toWad(`${gasPrices.slow.price}`, 9).toHexString();
|
||||
const gasPrice = await apiGetGasPrice(chainId);
|
||||
return gasPrice;
|
||||
}
|
||||
|
||||
export async function formatTestTransaction(account: string) {
|
||||
|
||||