refactor: factor out remaining caip-api imports (#377)

* refactor(with-ethers): factor out remaining caip-api imports

* chore(with-web3js): factor out remaining caip-api pkg references

* refactor(with-cosmos): factor out remaining caip-api references
This commit is contained in:
Ben Kremer 2024-01-04 11:49:59 +01:00 committed by GitHub
parent 8614f2fecd
commit bf0c31ab69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 333 additions and 145 deletions

View File

@ -28,15 +28,19 @@
"react-error-overlay": "6.0.11" "react-error-overlay": "6.0.11"
}, },
"dependencies": { "dependencies": {
"@ethereumjs/tx": "^3.5.0",
"@walletconnect/encoding": "^1.0.1",
"@walletconnect/types": "2.10.0", "@walletconnect/types": "2.10.0",
"@walletconnect/universal-provider": "2.10.0",
"@walletconnect/utils": "2.10.0", "@walletconnect/utils": "2.10.0",
"@web3modal/standalone": "^2.3.7",
"axios": "^1.0.0", "axios": "^1.0.0",
"blockies-ts": "^1.0.0", "blockies-ts": "^1.0.0",
"caip-api": "^2.0.0-beta.1",
"cosmos-wallet": "^1.2.0", "cosmos-wallet": "^1.2.0",
"eth-sig-util": "^2.5.3", "eth-sig-util": "^2.5.3",
"ethereumjs-util": "^7.0.6", "ethereumjs-util": "^7.0.6",
"ethers": "^5.3.0", "ethers": "^5.3.0",
"next": "12.3.4",
"prop-types": "^15.7.2", "prop-types": "^15.7.2",
"qr-image": "^3.2.0", "qr-image": "^3.2.0",
"react": "^17.0.2", "react": "^17.0.2",
@ -44,12 +48,7 @@
"react-scripts": "^4.0.3", "react-scripts": "^4.0.3",
"styled-components": "^5.2.0", "styled-components": "^5.2.0",
"typescript": "^4.3.2", "typescript": "^4.3.2",
"web-vitals": "^0.2.4", "web-vitals": "^0.2.4"
"next": "12.3.4",
"@ethereumjs/tx": "^3.5.0",
"@walletconnect/encoding": "^1.0.1",
"@walletconnect/universal-provider": "2.10.0",
"@web3modal/standalone": "^2.3.7"
}, },
"devDependencies": { "devDependencies": {
"@testing-library/jest-dom": "^5.16.1", "@testing-library/jest-dom": "^5.16.1",
@ -65,8 +64,8 @@
"@types/react": "18.0.15", "@types/react": "18.0.15",
"@types/react-dom": "18.0.6", "@types/react-dom": "18.0.6",
"@types/styled-components": "^5.1.21", "@types/styled-components": "^5.1.21",
"prettier": "^2.5.1", "eslint-config-next": "12.2.4",
"eslint-config-next": "12.2.4" "prettier": "^2.5.1"
}, },
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [

View File

@ -2,6 +2,37 @@ import { JsonRpcRequest } from "@walletconnect/jsonrpc-utils";
import { NamespaceMetadata, ChainMetadata, ChainRequestRender } from "../helpers"; import { NamespaceMetadata, ChainMetadata, ChainRequestRender } from "../helpers";
export const CosmosChainData = {
"cosmoshub-4": {
name: "Cosmos Hub",
id: "cosmos:cosmoshub-4",
rpc: ["https://rpc.cosmos.network"],
slip44: 118,
testnet: false,
},
"irishub-1": {
name: "Irisnet",
id: "cosmos:irishub-1",
rpc: ["https://rpc.irisnet.org"],
slip44: 566,
testnet: false,
},
"kava-4": {
name: "Kava",
id: "cosmos:kava-4",
rpc: ["https://kava4.data.kava.io"],
slip44: 459,
testnet: false,
},
"columbus-4": {
name: "Terra",
id: "cosmos:columbus-4",
rpc: [],
slip44: 330,
testnet: false,
},
};
export const CosmosMetadata: NamespaceMetadata = { export const CosmosMetadata: NamespaceMetadata = {
"cosmoshub-4": { "cosmoshub-4": {
logo: "/assets/" + "cosmos:cosmoshub-4.png", logo: "/assets/" + "cosmos:cosmoshub-4.png",

View File

@ -1,6 +1,5 @@
import React, { PropsWithChildren, FC } from "react"; import React, { PropsWithChildren, FC } from "react";
import styled from "styled-components"; import styled from "styled-components";
import { ChainData } from "caip-api";
import Asset from "./Asset"; import Asset from "./Asset";
import Button from "./Button"; import Button from "./Button";
@ -93,7 +92,7 @@ interface BlockchainProps {
} }
interface BlockchainDisplayData { interface BlockchainDisplayData {
data: ChainData; data: any;
meta: ChainMetadata; meta: ChainMetadata;
} }
@ -108,7 +107,8 @@ function getBlockchainDisplayData(
} catch (e) { } catch (e) {
return undefined; return undefined;
} }
const data: ChainData = chainData[namespace][reference]; if (typeof chainData[namespace] === "undefined") return undefined;
const data = chainData[namespace][reference];
if (typeof data === "undefined") return undefined; if (typeof data === "undefined") return undefined;
return { data, meta }; return { data, meta };
} }

View File

@ -1,4 +1,3 @@
import SignClient from "@walletconnect/sign-client";
import { ISignClient, PairingTypes, SessionTypes } from "@walletconnect/types"; import { ISignClient, PairingTypes, SessionTypes } from "@walletconnect/types";
import UniversalProvider, { IUniversalProvider } from "@walletconnect/universal-provider"; import UniversalProvider, { IUniversalProvider } from "@walletconnect/universal-provider";
import { Web3Modal } from "@web3modal/standalone"; import { Web3Modal } from "@web3modal/standalone";
@ -18,7 +17,7 @@ import {
DEFAULT_RELAY_URL, DEFAULT_RELAY_URL,
} from "../constants"; } from "../constants";
import { AccountBalances, ChainNamespaces, getAllChainNamespaces } from "../helpers"; import { AccountBalances, ChainNamespaces, getAllChainNamespaces } from "../helpers";
import { apiGetChainNamespace, ChainsMap } from "caip-api"; import { CosmosChainData } from "../chains/cosmos";
/** /**
* Types * Types
@ -74,12 +73,16 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
const chainData: ChainNamespaces = {}; const chainData: ChainNamespaces = {};
await Promise.all( await Promise.all(
namespaces.map(async namespace => { namespaces.map(async namespace => {
let chains: ChainsMap | undefined; let chains;
try { switch (namespace) {
chains = await apiGetChainNamespace(namespace); case "cosmos":
} catch (e) { chains = CosmosChainData;
// ignore error break;
default:
console.error("Unknown chain namespace: ", namespace);
} }
if (typeof chains !== "undefined") { if (typeof chains !== "undefined") {
chainData[namespace] = chains; chainData[namespace] = chains;
} }
@ -161,7 +164,7 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
cosmos: { cosmos: {
methods: DEFAULT_COSMOS_METHODS, methods: DEFAULT_COSMOS_METHODS,
chains: [caipChainId], chains: [caipChainId],
events: ["chainChanged", "accountsChanged"], events: [],
}, },
}, },
}); });

View File

@ -1,5 +1,3 @@
import { ChainsMap } from "caip-api";
export interface AssetData { export interface AssetData {
account: string; account: string;
symbol: string; symbol: string;
@ -145,7 +143,15 @@ export interface NamespaceMetadata {
[reference: string]: ChainMetadata; [reference: string]: ChainMetadata;
} }
export interface ChainNamespaces { export interface ChainNamespaces {
[namespace: string]: ChainsMap; [namespace: string]: {
[reference: string]: {
name: string;
id: string;
rpc: string[];
slip44: number;
testnet: boolean;
};
};
} }
export interface AccountAction { export interface AccountAction {

View File

@ -1968,13 +1968,6 @@
"@jridgewell/resolve-uri" "3.1.0" "@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14" "@jridgewell/sourcemap-codec" "1.4.14"
"@json-rpc-tools/types@^2.0.0-beta.0":
version "2.0.0-beta.12"
resolved "https://registry.npmjs.org/@json-rpc-tools/types/-/types-2.0.0-beta.12.tgz"
integrity sha512-UM8w0RnD4DjYql/HlThe051ivW2Q8ulWarr7ux5Aas1UsOmcGQEg4slQo46p+BXgh1Nth7SHWS2tVnW/UUnCwQ==
dependencies:
keyvaluestorage-interface "^1.0.0"
"@lit-labs/ssr-dom-shim@^1.0.0", "@lit-labs/ssr-dom-shim@^1.1.0": "@lit-labs/ssr-dom-shim@^1.0.0", "@lit-labs/ssr-dom-shim@^1.1.0":
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.2.tgz#d693d972974a354034454ec1317eb6afd0b00312" resolved "https://registry.yarnpkg.com/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.2.tgz#d693d972974a354034454ec1317eb6afd0b00312"
@ -3963,13 +3956,6 @@ axe-core@^4.6.2:
resolved "https://registry.npmjs.org/axe-core/-/axe-core-4.6.2.tgz" resolved "https://registry.npmjs.org/axe-core/-/axe-core-4.6.2.tgz"
integrity sha512-b1WlTV8+XKLj9gZy2DZXgQiyDp9xkkoe2a6U6UbYccScq2wgH/YwCeI2/Jq2mgo0HzQxqJOjWZBLeA/mqsk5Mg== integrity sha512-b1WlTV8+XKLj9gZy2DZXgQiyDp9xkkoe2a6U6UbYccScq2wgH/YwCeI2/Jq2mgo0HzQxqJOjWZBLeA/mqsk5Mg==
axios@^0.21.1:
version "0.21.4"
resolved "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz"
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
dependencies:
follow-redirects "^1.14.0"
axios@^1.0.0: axios@^1.0.0:
version "1.6.3" version "1.6.3"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.3.tgz#7f50f23b3aa246eff43c54834272346c396613f4" resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.3.tgz#7f50f23b3aa246eff43c54834272346c396613f4"
@ -4583,20 +4569,6 @@ cache-base@^1.0.1:
union-value "^1.0.0" union-value "^1.0.0"
unset-value "^1.0.0" unset-value "^1.0.0"
caip-api@^2.0.0-beta.1:
version "2.0.0-beta.1"
resolved "https://registry.npmjs.org/caip-api/-/caip-api-2.0.0-beta.1.tgz"
integrity sha512-pwVXYfAIV3V0QhsKfvamIvsnn7lSmrotukmbXndOE2EsA0dos5W8MLadlpG2U+VSDghCVWI6cY9oJbBuXWj2gg==
dependencies:
"@json-rpc-tools/types" "^2.0.0-beta.0"
axios "^0.21.1"
caip "^0.9.2"
caip@^0.9.2:
version "0.9.2"
resolved "https://registry.npmjs.org/caip/-/caip-0.9.2.tgz"
integrity sha512-o4aIUSR9lkn7B9lIw8Xgkj+hDh+S1PtsBphoSqP2Dt95gRWPniaqEpnPwiUEhaPQr84JzWIEm4Cck3lMZtIkTA==
call-bind@^1.0.0, call-bind@^1.0.2: call-bind@^1.0.0, call-bind@^1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz" resolved "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz"
@ -6867,7 +6839,7 @@ flush-write-stream@^1.0.0:
inherits "^2.0.3" inherits "^2.0.3"
readable-stream "^2.3.6" readable-stream "^2.3.6"
follow-redirects@^1.0.0, follow-redirects@^1.14.0: follow-redirects@^1.0.0:
version "1.15.2" version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

View File

@ -29,21 +29,20 @@
}, },
"dependencies": { "dependencies": {
"@ethereumjs/tx": "^3.5.0", "@ethereumjs/tx": "^3.5.0",
"axios": "^1.0.0",
"blockies-ts": "^1.0.0",
"caip-api": "^2.0.0-beta.1",
"cosmos-wallet": "^1.1.0",
"eth-sig-util": "^2.5.3",
"ethereumjs-util": "^7.0.6",
"@walletconnect/encoding": "^1.0.2", "@walletconnect/encoding": "^1.0.2",
"@walletconnect/types": "^2.7.6", "@walletconnect/types": "^2.7.6",
"@walletconnect/universal-provider": "^2.7.6", "@walletconnect/universal-provider": "^2.7.6",
"@walletconnect/utils": "^2.7.6", "@walletconnect/utils": "^2.7.6",
"@web3modal/standalone": "^2.3.7", "@web3modal/standalone": "^2.3.7",
"axios": "^1.0.0",
"blockies-ts": "^1.0.0",
"cosmos-wallet": "^1.1.0",
"eth-sig-util": "^2.5.3",
"ethereumjs-util": "^7.0.6",
"ethers": "5.7.2", "ethers": "5.7.2",
"next": "12.3.4",
"prop-types": "^15.7.2", "prop-types": "^15.7.2",
"qr-image": "^3.2.0", "qr-image": "^3.2.0",
"next": "12.3.4",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"react-scripts": "^4.0.3", "react-scripts": "^4.0.3",

View File

@ -18,6 +18,114 @@ export const EIP155Colors = {
arbitrum: "44, 55, 75", arbitrum: "44, 55, 75",
}; };
export const EIP155ChainData = {
"1": {
name: "Ethereum Mainnet",
id: "eip155:1",
rpc: ["https://api.mycryptoapi.com/eth"],
slip44: 60,
testnet: false,
},
"5": {
name: "Ethereum Goerli",
id: "eip155:5",
rpc: ["https://rpc.goerli.mudit.blog"],
slip44: 60,
testnet: true,
},
"10": {
name: "Optimism Mainnet",
id: "eip155:10",
rpc: ["https://mainnet.optimism.io"],
slip44: 60,
testnet: false,
},
"42": {
name: "Ethereum Kovan",
id: "eip155:42",
rpc: ["https://kovan.poa.network"],
slip44: 60,
testnet: true,
},
"69": {
name: "Optimism Kovan",
id: "eip155:69",
rpc: ["https://kovan.optimism.io"],
slip44: 60,
testnet: true,
},
"100": {
name: "xDAI",
id: "eip155:100",
rpc: ["https://dai.poa.network"],
slip44: 60,
testnet: false,
},
"280": {
name: "zkSync Era Testnet",
id: "eip155:280",
rpc: ["https://testnet.era.zksync.dev"],
slip44: 60,
testnet: true,
},
"324": {
name: "zkSync Era",
id: "eip155:324",
rpc: ["https://mainnet.era.zksync.io"],
slip44: 60,
testnet: false,
},
"137": {
name: "Polygon Mainnet",
id: "eip155:137",
rpc: ["https://rpc-mainnet.matic.network"],
slip44: 60,
testnet: false,
},
"420": {
name: "Optimism Goerli",
id: "eip155:420",
rpc: ["https://goerli.optimism.io"],
slip44: 60,
testnet: true,
},
"42161": {
name: "Arbitrum One",
id: "eip155:42161",
rpc: ["https://arb1.arbitrum.io/rpc"],
slip44: 60,
testnet: false,
},
"42220": {
name: "Celo Mainnet",
id: "eip155:42220",
rpc: ["https://forno.celo.org"],
slip44: 52752,
testnet: false,
},
"44787": {
name: "Celo Alfajores",
id: "eip155:44787",
rpc: ["https://alfajores-forno.celo-testnet.org"],
slip44: 52752,
testnet: true,
},
"80001": {
name: "Polygon Mumbai",
id: "eip155:80001",
rpc: ["https://rpc-mumbai.matic.today"],
slip44: 60,
testnet: true,
},
"421611": {
name: "Arbitrum Rinkeby",
id: "eip155:421611",
rpc: ["https://rinkeby.arbitrum.io/rpc"],
slip44: 60,
testnet: true,
},
};
export const EIP155Metadata: NamespaceMetadata = { export const EIP155Metadata: NamespaceMetadata = {
"1": { "1": {
name: "Ethereum", name: "Ethereum",

View File

@ -1,6 +1,5 @@
import React, { PropsWithChildren, FC } from "react"; import React, { PropsWithChildren, FC } from "react";
import styled from "styled-components"; import styled from "styled-components";
import { ChainData } from "caip-api";
import Asset from "./Asset"; import Asset from "./Asset";
import Button from "./Button"; import Button from "./Button";
@ -93,7 +92,7 @@ interface BlockchainProps {
} }
interface BlockchainDisplayData { interface BlockchainDisplayData {
data: ChainData; data: any;
meta: ChainMetadata; meta: ChainMetadata;
} }
@ -108,7 +107,7 @@ function getBlockchainDisplayData(
} catch (e) { } catch (e) {
return undefined; return undefined;
} }
const data: ChainData = chainData[namespace][reference]; const data = chainData[namespace][reference];
if (typeof data === "undefined") return undefined; if (typeof data === "undefined") return undefined;
return { data, meta }; return { data, meta };
} }

View File

@ -9,7 +9,6 @@ import {
} from "react"; } from "react";
import { Web3Modal } from "@web3modal/standalone"; import { Web3Modal } from "@web3modal/standalone";
import { apiGetChainNamespace, ChainsMap } from "caip-api";
import UniversalProvider from "@walletconnect/universal-provider"; import UniversalProvider from "@walletconnect/universal-provider";
import { PairingTypes, SessionTypes } from "@walletconnect/types"; import { PairingTypes, SessionTypes } from "@walletconnect/types";
import Client from "@walletconnect/sign-client"; import Client from "@walletconnect/sign-client";
@ -17,6 +16,7 @@ import Client from "@walletconnect/sign-client";
import { DEFAULT_LOGGER, DEFAULT_PROJECT_ID, DEFAULT_RELAY_URL } from "../constants"; import { DEFAULT_LOGGER, DEFAULT_PROJECT_ID, DEFAULT_RELAY_URL } from "../constants";
import { providers, utils } from "ethers"; import { providers, utils } from "ethers";
import { AccountBalances, ChainNamespaces, getAllChainNamespaces } from "../helpers"; import { AccountBalances, ChainNamespaces, getAllChainNamespaces } from "../helpers";
import { EIP155ChainData } from "../chains/eip155";
/** /**
* Types * Types
*/ */
@ -77,12 +77,16 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
const chainData: ChainNamespaces = {}; const chainData: ChainNamespaces = {};
await Promise.all( await Promise.all(
namespaces.map(async namespace => { namespaces.map(async namespace => {
let chains: ChainsMap | undefined; let chains;
try { switch (namespace) {
chains = await apiGetChainNamespace(namespace); case "eip155":
} catch (e) { chains = EIP155ChainData;
// ignore error break;
default:
console.error("Unknown chain namespace: ", namespace);
} }
if (typeof chains !== "undefined") { if (typeof chains !== "undefined") {
chainData[namespace] = chains; chainData[namespace] = chains;
} }
@ -195,7 +199,9 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
], ],
chains: [`eip155:${chainId}`], chains: [`eip155:${chainId}`],
events: ["chainChanged", "accountsChanged"], events: ["chainChanged", "accountsChanged"],
rpcMap: {chainId: `https://rpc.walletconnect.com?chainId=eip155:${chainId}&projectId=${DEFAULT_PROJECT_ID}`,}, rpcMap: {
chainId: `https://rpc.walletconnect.com?chainId=eip155:${chainId}&projectId=${DEFAULT_PROJECT_ID}`,
},
}, },
}, },
pairingTopic: pairing?.topic, pairingTopic: pairing?.topic,

View File

@ -131,7 +131,6 @@ const api: AxiosInstance = axios.create({
}); });
export const apiGetAccountNonce = async (address: string, chainId: string): Promise<number> => { export const apiGetAccountNonce = async (address: string, chainId: string): Promise<number> => {
debugger;
const ethChainId = chainId.split(":")[1]; const ethChainId = chainId.split(":")[1];
const { baseURL } = rpcProvidersByChainId[Number(ethChainId)]; const { baseURL } = rpcProvidersByChainId[Number(ethChainId)];
const response = await api.post(baseURL, { const response = await api.post(baseURL, {

View File

@ -1,5 +1,3 @@
import { ChainsMap } from "caip-api";
export interface AssetData { export interface AssetData {
account: string; account: string;
symbol: string; symbol: string;
@ -144,8 +142,17 @@ export interface ChainMetadata {
export interface NamespaceMetadata { export interface NamespaceMetadata {
[reference: string]: ChainMetadata; [reference: string]: ChainMetadata;
} }
export interface ChainNamespaces { export interface ChainNamespaces {
[namespace: string]: ChainsMap; [namespace: string]: {
[reference: string]: {
name: string;
id: string;
rpc: string[];
slip44: number;
testnet: boolean;
};
};
} }
export interface AccountAction { export interface AccountAction {

View File

@ -1975,13 +1975,6 @@
"@jridgewell/resolve-uri" "3.1.0" "@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14" "@jridgewell/sourcemap-codec" "1.4.14"
"@json-rpc-tools/types@^2.0.0-beta.0":
version "2.0.0-beta.12"
resolved "https://registry.yarnpkg.com/@json-rpc-tools/types/-/types-2.0.0-beta.12.tgz#358f77c48a844a3f55169c2db3b35c6af1cf4e8b"
integrity sha512-UM8w0RnD4DjYql/HlThe051ivW2Q8ulWarr7ux5Aas1UsOmcGQEg4slQo46p+BXgh1Nth7SHWS2tVnW/UUnCwQ==
dependencies:
keyvaluestorage-interface "^1.0.0"
"@lit-labs/ssr-dom-shim@^1.0.0", "@lit-labs/ssr-dom-shim@^1.1.0": "@lit-labs/ssr-dom-shim@^1.0.0", "@lit-labs/ssr-dom-shim@^1.1.0":
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.2.tgz#d693d972974a354034454ec1317eb6afd0b00312" resolved "https://registry.yarnpkg.com/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.2.tgz#d693d972974a354034454ec1317eb6afd0b00312"
@ -3903,13 +3896,6 @@ axe-core@^4.6.2:
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.6.3.tgz#fc0db6fdb65cc7a80ccf85286d91d64ababa3ece" resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.6.3.tgz#fc0db6fdb65cc7a80ccf85286d91d64ababa3ece"
integrity sha512-/BQzOX780JhsxDnPpH4ZiyrJAzcd8AfzFPkv+89veFSr1rcMjuq2JDCwypKaPeB6ljHp9KjXhPpjgCvQlWYuqg== integrity sha512-/BQzOX780JhsxDnPpH4ZiyrJAzcd8AfzFPkv+89veFSr1rcMjuq2JDCwypKaPeB6ljHp9KjXhPpjgCvQlWYuqg==
axios@^0.21.1:
version "0.21.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
dependencies:
follow-redirects "^1.14.0"
axios@^1.0.0: axios@^1.0.0:
version "1.6.3" version "1.6.3"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.3.tgz#7f50f23b3aa246eff43c54834272346c396613f4" resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.3.tgz#7f50f23b3aa246eff43c54834272346c396613f4"
@ -4520,20 +4506,6 @@ cache-base@^1.0.1:
union-value "^1.0.0" union-value "^1.0.0"
unset-value "^1.0.0" unset-value "^1.0.0"
caip-api@^2.0.0-beta.1:
version "2.0.0-beta.1"
resolved "https://registry.yarnpkg.com/caip-api/-/caip-api-2.0.0-beta.1.tgz#23877b880396f855fc2cd7892d02c597f2d62ba7"
integrity sha512-pwVXYfAIV3V0QhsKfvamIvsnn7lSmrotukmbXndOE2EsA0dos5W8MLadlpG2U+VSDghCVWI6cY9oJbBuXWj2gg==
dependencies:
"@json-rpc-tools/types" "^2.0.0-beta.0"
axios "^0.21.1"
caip "^0.9.2"
caip@^0.9.2:
version "0.9.2"
resolved "https://registry.yarnpkg.com/caip/-/caip-0.9.2.tgz#6aec668e459dc3a1830530f7bb8d06f0044a5391"
integrity sha512-o4aIUSR9lkn7B9lIw8Xgkj+hDh+S1PtsBphoSqP2Dt95gRWPniaqEpnPwiUEhaPQr84JzWIEm4Cck3lMZtIkTA==
call-bind@^1.0.0, call-bind@^1.0.2: call-bind@^1.0.0, call-bind@^1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c" resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c"
@ -6783,7 +6755,7 @@ flush-write-stream@^1.0.0:
inherits "^2.0.3" inherits "^2.0.3"
readable-stream "^2.3.6" readable-stream "^2.3.6"
follow-redirects@^1.0.0, follow-redirects@^1.14.0: follow-redirects@^1.0.0:
version "1.15.2" version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

View File

@ -36,7 +36,6 @@
"@web3modal/standalone": "^2.3.7", "@web3modal/standalone": "^2.3.7",
"axios": "^1.0.0", "axios": "^1.0.0",
"blockies-ts": "^1.0.0", "blockies-ts": "^1.0.0",
"caip-api": "^2.0.0-beta.1",
"cosmos-wallet": "^1.1.0", "cosmos-wallet": "^1.1.0",
"eth-sig-util": "^2.5.3", "eth-sig-util": "^2.5.3",
"ethereumjs-util": "^7.0.6", "ethereumjs-util": "^7.0.6",

View File

@ -18,6 +18,114 @@ export const EIP155Colors = {
arbitrum: "44, 55, 75", arbitrum: "44, 55, 75",
}; };
export const EIP155ChainData = {
"1": {
name: "Ethereum Mainnet",
id: "eip155:1",
rpc: ["https://api.mycryptoapi.com/eth"],
slip44: 60,
testnet: false,
},
"5": {
name: "Ethereum Goerli",
id: "eip155:5",
rpc: ["https://rpc.goerli.mudit.blog"],
slip44: 60,
testnet: true,
},
"10": {
name: "Optimism Mainnet",
id: "eip155:10",
rpc: ["https://mainnet.optimism.io"],
slip44: 60,
testnet: false,
},
"42": {
name: "Ethereum Kovan",
id: "eip155:42",
rpc: ["https://kovan.poa.network"],
slip44: 60,
testnet: true,
},
"69": {
name: "Optimism Kovan",
id: "eip155:69",
rpc: ["https://kovan.optimism.io"],
slip44: 60,
testnet: true,
},
"100": {
name: "xDAI",
id: "eip155:100",
rpc: ["https://dai.poa.network"],
slip44: 60,
testnet: false,
},
"280": {
name: "zkSync Era Testnet",
id: "eip155:280",
rpc: ["https://testnet.era.zksync.dev"],
slip44: 60,
testnet: true,
},
"324": {
name: "zkSync Era",
id: "eip155:324",
rpc: ["https://mainnet.era.zksync.io"],
slip44: 60,
testnet: false,
},
"137": {
name: "Polygon Mainnet",
id: "eip155:137",
rpc: ["https://rpc-mainnet.matic.network"],
slip44: 60,
testnet: false,
},
"420": {
name: "Optimism Goerli",
id: "eip155:420",
rpc: ["https://goerli.optimism.io"],
slip44: 60,
testnet: true,
},
"42161": {
name: "Arbitrum One",
id: "eip155:42161",
rpc: ["https://arb1.arbitrum.io/rpc"],
slip44: 60,
testnet: false,
},
"42220": {
name: "Celo Mainnet",
id: "eip155:42220",
rpc: ["https://forno.celo.org"],
slip44: 52752,
testnet: false,
},
"44787": {
name: "Celo Alfajores",
id: "eip155:44787",
rpc: ["https://alfajores-forno.celo-testnet.org"],
slip44: 52752,
testnet: true,
},
"80001": {
name: "Polygon Mumbai",
id: "eip155:80001",
rpc: ["https://rpc-mumbai.matic.today"],
slip44: 60,
testnet: true,
},
"421611": {
name: "Arbitrum Rinkeby",
id: "eip155:421611",
rpc: ["https://rinkeby.arbitrum.io/rpc"],
slip44: 60,
testnet: true,
},
};
export const EIP155Metadata: NamespaceMetadata = { export const EIP155Metadata: NamespaceMetadata = {
"1": { "1": {
name: "Ethereum", name: "Ethereum",

View File

@ -1,6 +1,5 @@
import React, { PropsWithChildren, FC } from "react"; import React, { PropsWithChildren, FC } from "react";
import styled from "styled-components"; import styled from "styled-components";
import { ChainData } from "caip-api";
import Asset from "./Asset"; import Asset from "./Asset";
import Button from "./Button"; import Button from "./Button";
@ -93,7 +92,7 @@ interface BlockchainProps {
} }
interface BlockchainDisplayData { interface BlockchainDisplayData {
data: ChainData; data: any;
meta: ChainMetadata; meta: ChainMetadata;
} }
@ -108,7 +107,7 @@ function getBlockchainDisplayData(
} catch (e) { } catch (e) {
return undefined; return undefined;
} }
const data: ChainData = chainData[namespace][reference]; const data = chainData[namespace][reference];
if (typeof data === "undefined") return undefined; if (typeof data === "undefined") return undefined;
return { data, meta }; return { data, meta };
} }

View File

@ -9,7 +9,6 @@ import {
} from "react"; } from "react";
import { Web3Modal } from "@web3modal/standalone"; import { Web3Modal } from "@web3modal/standalone";
import { apiGetChainNamespace, ChainsMap } from "caip-api";
import UniversalProvider from "@walletconnect/universal-provider"; import UniversalProvider from "@walletconnect/universal-provider";
import Client from "@walletconnect/sign-client"; import Client from "@walletconnect/sign-client";
import Web3 from "web3"; import Web3 from "web3";
@ -17,6 +16,7 @@ import { DEFAULT_LOGGER, DEFAULT_PROJECT_ID, DEFAULT_RELAY_URL } from "../consta
import { utils } from "ethers"; import { utils } from "ethers";
import { AccountBalances, ChainNamespaces, getAllChainNamespaces } from "../helpers"; import { AccountBalances, ChainNamespaces, getAllChainNamespaces } from "../helpers";
import { PairingTypes, SessionTypes } from "@walletconnect/types"; import { PairingTypes, SessionTypes } from "@walletconnect/types";
import { EIP155ChainData } from "../chains/eip155";
/** /**
* Types * Types
@ -75,12 +75,16 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
const chainData: ChainNamespaces = {}; const chainData: ChainNamespaces = {};
await Promise.all( await Promise.all(
namespaces.map(async namespace => { namespaces.map(async namespace => {
let chains: ChainsMap | undefined; let chains;
try { switch (namespace) {
chains = await apiGetChainNamespace(namespace); case "eip155":
} catch (e) { chains = EIP155ChainData;
// ignore error break;
default:
console.error("Unknown chain namespace: ", namespace);
} }
if (typeof chains !== "undefined") { if (typeof chains !== "undefined") {
chainData[namespace] = chains; chainData[namespace] = chains;
} }

View File

@ -131,7 +131,6 @@ const api: AxiosInstance = axios.create({
}); });
export const apiGetAccountNonce = async (address: string, chainId: string): Promise<number> => { export const apiGetAccountNonce = async (address: string, chainId: string): Promise<number> => {
debugger;
const ethChainId = chainId.split(":")[1]; const ethChainId = chainId.split(":")[1];
const { baseURL } = rpcProvidersByChainId[Number(ethChainId)]; const { baseURL } = rpcProvidersByChainId[Number(ethChainId)];
const response = await api.post(baseURL, { const response = await api.post(baseURL, {

View File

@ -1,5 +1,3 @@
import { ChainsMap } from "caip-api";
export interface AssetData { export interface AssetData {
symbol: string; symbol: string;
balance: string; balance: string;
@ -144,7 +142,15 @@ export interface NamespaceMetadata {
[reference: string]: ChainMetadata; [reference: string]: ChainMetadata;
} }
export interface ChainNamespaces { export interface ChainNamespaces {
[namespace: string]: ChainsMap; [namespace: string]: {
[reference: string]: {
name: string;
id: string;
rpc: string[];
slip44: number;
testnet: boolean;
};
};
} }
export interface AccountAction { export interface AccountAction {

View File

@ -1986,13 +1986,6 @@
"@jridgewell/resolve-uri" "3.1.0" "@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14" "@jridgewell/sourcemap-codec" "1.4.14"
"@json-rpc-tools/types@^2.0.0-beta.0":
version "2.0.0-beta.12"
resolved "https://registry.yarnpkg.com/@json-rpc-tools/types/-/types-2.0.0-beta.12.tgz#358f77c48a844a3f55169c2db3b35c6af1cf4e8b"
integrity sha512-UM8w0RnD4DjYql/HlThe051ivW2Q8ulWarr7ux5Aas1UsOmcGQEg4slQo46p+BXgh1Nth7SHWS2tVnW/UUnCwQ==
dependencies:
keyvaluestorage-interface "^1.0.0"
"@lit-labs/ssr-dom-shim@^1.0.0", "@lit-labs/ssr-dom-shim@^1.1.0": "@lit-labs/ssr-dom-shim@^1.0.0", "@lit-labs/ssr-dom-shim@^1.1.0":
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.2.tgz#d693d972974a354034454ec1317eb6afd0b00312" resolved "https://registry.yarnpkg.com/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.2.tgz#d693d972974a354034454ec1317eb6afd0b00312"
@ -4048,13 +4041,6 @@ axe-core@^4.4.3:
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.5.1.tgz#04d561c11b6d76d096d34e9d14ba2c294fb20cdc" resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.5.1.tgz#04d561c11b6d76d096d34e9d14ba2c294fb20cdc"
integrity sha512-1exVbW0X1O/HSr/WMwnaweyqcWOgZgLiVxdLG34pvSQk4NlYQr9OUy0JLwuhFfuVNQzzqgH57eYzkFBCb3bIsQ== integrity sha512-1exVbW0X1O/HSr/WMwnaweyqcWOgZgLiVxdLG34pvSQk4NlYQr9OUy0JLwuhFfuVNQzzqgH57eYzkFBCb3bIsQ==
axios@^0.21.1:
version "0.21.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
dependencies:
follow-redirects "^1.14.0"
axios@^1.0.0: axios@^1.0.0:
version "1.6.3" version "1.6.3"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.3.tgz#7f50f23b3aa246eff43c54834272346c396613f4" resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.3.tgz#7f50f23b3aa246eff43c54834272346c396613f4"
@ -4744,20 +4730,6 @@ cacheable-request@^7.0.2:
normalize-url "^6.0.1" normalize-url "^6.0.1"
responselike "^2.0.0" responselike "^2.0.0"
caip-api@^2.0.0-beta.1:
version "2.0.0-beta.1"
resolved "https://registry.yarnpkg.com/caip-api/-/caip-api-2.0.0-beta.1.tgz#23877b880396f855fc2cd7892d02c597f2d62ba7"
integrity sha512-pwVXYfAIV3V0QhsKfvamIvsnn7lSmrotukmbXndOE2EsA0dos5W8MLadlpG2U+VSDghCVWI6cY9oJbBuXWj2gg==
dependencies:
"@json-rpc-tools/types" "^2.0.0-beta.0"
axios "^0.21.1"
caip "^0.9.2"
caip@^0.9.2:
version "0.9.2"
resolved "https://registry.yarnpkg.com/caip/-/caip-0.9.2.tgz#6aec668e459dc3a1830530f7bb8d06f0044a5391"
integrity sha512-o4aIUSR9lkn7B9lIw8Xgkj+hDh+S1PtsBphoSqP2Dt95gRWPniaqEpnPwiUEhaPQr84JzWIEm4Cck3lMZtIkTA==
call-bind@^1.0.0, call-bind@^1.0.2, call-bind@^1.0.4: call-bind@^1.0.0, call-bind@^1.0.2, call-bind@^1.0.4:
version "1.0.5" version "1.0.5"
resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.5.tgz#6fa2b7845ce0ea49bf4d8b9ef64727a2c2e2e513" resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.5.tgz#6fa2b7845ce0ea49bf4d8b9ef64727a2c2e2e513"
@ -7163,7 +7135,7 @@ flush-write-stream@^1.0.0:
inherits "^2.0.3" inherits "^2.0.3"
readable-stream "^2.3.6" readable-stream "^2.3.6"
follow-redirects@^1.0.0, follow-redirects@^1.14.0: follow-redirects@^1.0.0:
version "1.15.2" version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==