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
This commit is contained in:
Ben Kremer 2023-12-18 14:46:51 +00:00 committed by GitHub
parent cb9b820d06
commit d205e01fd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
76 changed files with 520 additions and 205 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

@ -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",
},
};
@ -20,9 +18,7 @@ export function getChainMetadata(chainId: string): ChainMetadata {
return metadata;
}
export function getChainRequestRender(
request: JsonRpcRequest
): ChainRequestRender[] {
export function getChainRequestRender(request: JsonRpcRequest): ChainRequestRender[] {
return [
{ label: "Method", value: request.method },
{

View File

@ -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,
},
};

View File

@ -1,5 +1,4 @@
import { JsonRpcRequest } from "@walletconnect/jsonrpc-utils";
import { BLOCKCHAIN_LOGO_BASE_URL } from "../constants";
import { NamespaceMetadata, ChainMetadata, ChainRequestRender } from "../helpers";

View File

@ -1,2 +1 @@
export * from "./default";
export * from "./logo";

View File

@ -1 +0,0 @@
export const BLOCKCHAIN_LOGO_BASE_URL = "https://blockchain-api.xyz/logos/";

View File

@ -1,45 +1,158 @@
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> => {
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;
};

View File

@ -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) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

@ -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",
},
};

View File

@ -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,
},
};

View File

@ -1,5 +1,4 @@
import { JsonRpcRequest } from "@walletconnect/jsonrpc-utils";
import { BLOCKCHAIN_LOGO_BASE_URL } from "../constants";
import { NamespaceMetadata, ChainMetadata, ChainRequestRender } from "../helpers";

View File

@ -1,2 +1 @@
export * from "./default";
export * from "./logo";

View File

@ -1 +0,0 @@
export const BLOCKCHAIN_LOGO_BASE_URL = "https://blockchain-api.xyz/logos/";

View File

@ -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;
};

View File

@ -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) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

@ -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",
},
};

View File

@ -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,
},
};

View File

@ -1,2 +1 @@
export * from "./default";
export * from "./logo";

View File

@ -1 +0,0 @@
export const BLOCKCHAIN_LOGO_BASE_URL = "https://blockchain-api.xyz/logos/";

View File

@ -179,14 +179,6 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
console.log("Enabling EthereumProvider for chainId: ", chainId);
const customRpcs = Object.keys(chainData.eip155).reduce(
(rpcs: Record<string, string>, chainId) => {
rpcs[chainId] = chainData.eip155[chainId].rpc[0];
return rpcs;
},
{},
);
const session = await ethereumProvider.connect({
namespaces: {
eip155: {
@ -199,7 +191,6 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
],
chains: [`eip155:${chainId}`],
events: ["chainChanged", "accountsChanged"],
rpcMap: customRpcs,
},
},
pairingTopic: pairing?.topic,
@ -214,7 +205,7 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
web3Modal?.closeModal();
},
[ethereumProvider, chainData.eip155, createWeb3Provider, web3Modal],
[ethereumProvider, createWeb3Provider, web3Modal],
);
const onSessionConnected = useCallback(

View File

@ -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;
};

View File

@ -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) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

Before

Width:  |  Height:  |  Size: 410 B

After

Width:  |  Height:  |  Size: 410 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

@ -1,7 +1,5 @@
import { JsonRpcRequest } from "@walletconnect/jsonrpc-utils";
import { BLOCKCHAIN_LOGO_BASE_URL } from "../constants";
import {
NamespaceMetadata,
ChainMetadata,
@ -42,7 +40,7 @@ export const CosmosChainData: ChainsMap = {
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",
},
};

View File

@ -8,7 +8,6 @@ import {
convertHexToUtf8,
ChainsMap,
} from "../helpers";
import { BLOCKCHAIN_LOGO_BASE_URL } from "../constants";
export const EIP155Colors = {
ethereum: "99, 125, 234",
@ -132,65 +131,65 @@ export const EIP155ChainData: ChainsMap = {
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:1.png",
logo: "/assets/" + "eip155:1.png",
rgb: EIP155Colors.ethereum,
},
"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,
},
"420": {
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:420.png",
logo: "/assets/" + "eip155:420.png",
rgb: EIP155Colors.optimism,
},
"100": {
logo: BLOCKCHAIN_LOGO_BASE_URL + "eip155:100.png",
logo: "/assets/" + "eip155:100.png",
rgb: EIP155Colors.xdai,
},
"280": {
name: "zkSync Era Testnet",
logo: "/assets/eip155-324.svg",
logo: "/assets/" + "eip155:324.svg",
rgb: EIP155Colors.zksync,
},
"324": {
name: "zkSync Era",
logo: "/assets/eip155-324.svg",
logo: "/assets/" + "eip155:324.svg",
rgb: EIP155Colors.zksync,
},
"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,
},
};

View File

@ -1,4 +1,3 @@
import { BLOCKCHAIN_LOGO_BASE_URL } from "../constants";
import { JsonRpcRequest } from "@walletconnect/jsonrpc-utils";
import {
NamespaceMetadata,

View File

@ -1,2 +1 @@
export * from "./default";
export * from "./logo";

View File

@ -1 +0,0 @@
export const BLOCKCHAIN_LOGO_BASE_URL = "https://blockchain-api.xyz/logos/";

View File

@ -4,10 +4,24 @@ import { apiGetKadenaAccountBalance } from "./kadena";
import { AssetData } from "./types";
import { PactCommand } from "@kadena/client";
export const rpcProvidersByChainId: Record<number, any> = {
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: "https://mainnet.infura.io/v3/5dc0df7abe4645dfb06a9a8c39ede422",
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:1",
token: {
name: "Ether",
symbol: "ETH",
@ -15,7 +29,7 @@ export const rpcProvidersByChainId: Record<number, any> = {
},
5: {
name: "Ethereum Goerli",
baseURL: "https://goerli.infura.io/v3/5dc0df7abe4645dfb06a9a8c39ede422",
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:5",
token: {
name: "Ether",
symbol: "ETH",
@ -23,7 +37,7 @@ export const rpcProvidersByChainId: Record<number, any> = {
},
137: {
name: "Polygon Mainnet",
baseURL: "https://polygon-rpc.com",
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:137",
token: {
name: "Matic",
symbol: "MATIC",
@ -31,7 +45,7 @@ export const rpcProvidersByChainId: Record<number, any> = {
},
280: {
name: "zkSync Era Testnet",
baseURL: "https://testnet.era.zksync.dev",
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:280",
token: {
name: "Ether",
symbol: "ETH",
@ -39,7 +53,7 @@ export const rpcProvidersByChainId: Record<number, any> = {
},
324: {
name: "zkSync Era",
baseURL: "https://mainnet.era.zksync.io",
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:324",
token: {
name: "Ether",
symbol: "ETH",
@ -47,7 +61,7 @@ export const rpcProvidersByChainId: Record<number, any> = {
},
80001: {
name: "Polygon Mumbai",
baseURL: "https://rpc-mumbai.maticvigil.com",
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:80001",
token: {
name: "Matic",
symbol: "MATIC",
@ -55,7 +69,7 @@ export const rpcProvidersByChainId: Record<number, any> = {
},
10: {
name: "Optimism",
baseURL: "https://mainnet.optimism.io",
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:10",
token: {
name: "Ether",
symbol: "ETH",
@ -63,7 +77,7 @@ export const rpcProvidersByChainId: Record<number, any> = {
},
420: {
name: "Optimism Goerli",
baseURL: "https://goerli.optimism.io",
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:420",
token: {
name: "Ether",
symbol: "ETH",
@ -71,7 +85,7 @@ export const rpcProvidersByChainId: Record<number, any> = {
},
42161: {
name: "Arbitrum",
baseURL: "https://arb1.arbitrum.io/rpc",
baseURL: WALLETCONNECT_RPC_BASE_URL + "&chainId=eip155:42161",
token: {
name: "Ether",
symbol: "ETH",
@ -95,14 +109,14 @@ export const rpcProvidersByChainId: Record<number, any> = {
},
42220: {
name: "Celo",
baseURL: "https://forno.celo.org",
baseURL: "https://rpc.walletconnect.com/v1",
token: {
name: "CELO",
symbol: "CELO",
},
},
44787: {
name: "Celo",
name: "Celo Alfajores",
baseURL: "https://alfajores-forno.celo-testnet.org",
token: {
name: "CELO",
@ -112,7 +126,7 @@ export const rpcProvidersByChainId: Record<number, any> = {
};
const api: AxiosInstance = axios.create({
baseURL: "https://ethereum-api.xyz",
baseURL: "https://rpc.walletconnect.com/v1",
timeout: 10000, // 10 secs
headers: {
Accept: "application/json",