From bf0c31ab698e8b21d61d55d29b4dd075ee49a313 Mon Sep 17 00:00:00 2001 From: Ben Kremer Date: Thu, 4 Jan 2024 11:49:59 +0100 Subject: [PATCH] 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 --- .../package.json | 17 ++- .../src/chains/cosmos.ts | 31 +++++ .../src/components/Blockchain.tsx | 6 +- .../src/contexts/ClientContext.tsx | 19 +-- .../src/helpers/types.ts | 12 +- .../react-dapp-v2-cosmos-provider/yarn.lock | 30 +---- .../react-dapp-v2-with-ethers/package.json | 13 +-- .../src/chains/eip155.ts | 108 ++++++++++++++++++ .../src/components/Blockchain.tsx | 5 +- .../src/contexts/ClientContext.tsx | 20 ++-- .../src/helpers/api.ts | 1 - .../src/helpers/types.ts | 13 ++- .../dapps/react-dapp-v2-with-ethers/yarn.lock | 30 +---- .../react-dapp-v2-with-web3js/package.json | 1 - .../src/chains/eip155.ts | 108 ++++++++++++++++++ .../src/components/Blockchain.tsx | 5 +- .../src/contexts/ClientContext.tsx | 16 ++- .../src/helpers/api.ts | 1 - .../src/helpers/types.ts | 12 +- .../dapps/react-dapp-v2-with-web3js/yarn.lock | 30 +---- 20 files changed, 333 insertions(+), 145 deletions(-) diff --git a/advanced/dapps/react-dapp-v2-cosmos-provider/package.json b/advanced/dapps/react-dapp-v2-cosmos-provider/package.json index 552016e..695ac4e 100644 --- a/advanced/dapps/react-dapp-v2-cosmos-provider/package.json +++ b/advanced/dapps/react-dapp-v2-cosmos-provider/package.json @@ -28,15 +28,19 @@ "react-error-overlay": "6.0.11" }, "dependencies": { + "@ethereumjs/tx": "^3.5.0", + "@walletconnect/encoding": "^1.0.1", "@walletconnect/types": "2.10.0", + "@walletconnect/universal-provider": "2.10.0", "@walletconnect/utils": "2.10.0", + "@web3modal/standalone": "^2.3.7", "axios": "^1.0.0", "blockies-ts": "^1.0.0", - "caip-api": "^2.0.0-beta.1", "cosmos-wallet": "^1.2.0", "eth-sig-util": "^2.5.3", "ethereumjs-util": "^7.0.6", "ethers": "^5.3.0", + "next": "12.3.4", "prop-types": "^15.7.2", "qr-image": "^3.2.0", "react": "^17.0.2", @@ -44,12 +48,7 @@ "react-scripts": "^4.0.3", "styled-components": "^5.2.0", "typescript": "^4.3.2", - "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" + "web-vitals": "^0.2.4" }, "devDependencies": { "@testing-library/jest-dom": "^5.16.1", @@ -65,8 +64,8 @@ "@types/react": "18.0.15", "@types/react-dom": "18.0.6", "@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": { "extends": [ diff --git a/advanced/dapps/react-dapp-v2-cosmos-provider/src/chains/cosmos.ts b/advanced/dapps/react-dapp-v2-cosmos-provider/src/chains/cosmos.ts index 90cf0ed..6438702 100644 --- a/advanced/dapps/react-dapp-v2-cosmos-provider/src/chains/cosmos.ts +++ b/advanced/dapps/react-dapp-v2-cosmos-provider/src/chains/cosmos.ts @@ -2,6 +2,37 @@ import { JsonRpcRequest } from "@walletconnect/jsonrpc-utils"; 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 = { "cosmoshub-4": { logo: "/assets/" + "cosmos:cosmoshub-4.png", diff --git a/advanced/dapps/react-dapp-v2-cosmos-provider/src/components/Blockchain.tsx b/advanced/dapps/react-dapp-v2-cosmos-provider/src/components/Blockchain.tsx index 0ca366f..ee07797 100644 --- a/advanced/dapps/react-dapp-v2-cosmos-provider/src/components/Blockchain.tsx +++ b/advanced/dapps/react-dapp-v2-cosmos-provider/src/components/Blockchain.tsx @@ -1,6 +1,5 @@ import React, { PropsWithChildren, FC } from "react"; import styled from "styled-components"; -import { ChainData } from "caip-api"; import Asset from "./Asset"; import Button from "./Button"; @@ -93,7 +92,7 @@ interface BlockchainProps { } interface BlockchainDisplayData { - data: ChainData; + data: any; meta: ChainMetadata; } @@ -108,7 +107,8 @@ function getBlockchainDisplayData( } catch (e) { 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; return { data, meta }; } diff --git a/advanced/dapps/react-dapp-v2-cosmos-provider/src/contexts/ClientContext.tsx b/advanced/dapps/react-dapp-v2-cosmos-provider/src/contexts/ClientContext.tsx index c254016..a791b69 100644 --- a/advanced/dapps/react-dapp-v2-cosmos-provider/src/contexts/ClientContext.tsx +++ b/advanced/dapps/react-dapp-v2-cosmos-provider/src/contexts/ClientContext.tsx @@ -1,4 +1,3 @@ -import SignClient from "@walletconnect/sign-client"; import { ISignClient, PairingTypes, SessionTypes } from "@walletconnect/types"; import UniversalProvider, { IUniversalProvider } from "@walletconnect/universal-provider"; import { Web3Modal } from "@web3modal/standalone"; @@ -18,7 +17,7 @@ import { DEFAULT_RELAY_URL, } from "../constants"; import { AccountBalances, ChainNamespaces, getAllChainNamespaces } from "../helpers"; -import { apiGetChainNamespace, ChainsMap } from "caip-api"; +import { CosmosChainData } from "../chains/cosmos"; /** * Types @@ -74,12 +73,16 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac const chainData: ChainNamespaces = {}; await Promise.all( namespaces.map(async namespace => { - let chains: ChainsMap | undefined; - try { - chains = await apiGetChainNamespace(namespace); - } catch (e) { - // ignore error + let chains; + switch (namespace) { + case "cosmos": + chains = CosmosChainData; + break; + + default: + console.error("Unknown chain namespace: ", namespace); } + if (typeof chains !== "undefined") { chainData[namespace] = chains; } @@ -161,7 +164,7 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac cosmos: { methods: DEFAULT_COSMOS_METHODS, chains: [caipChainId], - events: ["chainChanged", "accountsChanged"], + events: [], }, }, }); diff --git a/advanced/dapps/react-dapp-v2-cosmos-provider/src/helpers/types.ts b/advanced/dapps/react-dapp-v2-cosmos-provider/src/helpers/types.ts index ab9ccca..16b1d33 100644 --- a/advanced/dapps/react-dapp-v2-cosmos-provider/src/helpers/types.ts +++ b/advanced/dapps/react-dapp-v2-cosmos-provider/src/helpers/types.ts @@ -1,5 +1,3 @@ -import { ChainsMap } from "caip-api"; - export interface AssetData { account: string; symbol: string; @@ -145,7 +143,15 @@ export interface NamespaceMetadata { [reference: string]: ChainMetadata; } export interface ChainNamespaces { - [namespace: string]: ChainsMap; + [namespace: string]: { + [reference: string]: { + name: string; + id: string; + rpc: string[]; + slip44: number; + testnet: boolean; + }; + }; } export interface AccountAction { diff --git a/advanced/dapps/react-dapp-v2-cosmos-provider/yarn.lock b/advanced/dapps/react-dapp-v2-cosmos-provider/yarn.lock index 186c8d6..2b1e79c 100644 --- a/advanced/dapps/react-dapp-v2-cosmos-provider/yarn.lock +++ b/advanced/dapps/react-dapp-v2-cosmos-provider/yarn.lock @@ -1968,13 +1968,6 @@ "@jridgewell/resolve-uri" "3.1.0" "@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": version "1.1.2" 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" 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: version "1.6.3" 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" 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: version "1.0.2" 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" readable-stream "^2.3.6" -follow-redirects@^1.0.0, follow-redirects@^1.14.0: +follow-redirects@^1.0.0: version "1.15.2" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== diff --git a/advanced/dapps/react-dapp-v2-with-ethers/package.json b/advanced/dapps/react-dapp-v2-with-ethers/package.json index a81a393..ed3ac8a 100644 --- a/advanced/dapps/react-dapp-v2-with-ethers/package.json +++ b/advanced/dapps/react-dapp-v2-with-ethers/package.json @@ -29,21 +29,20 @@ }, "dependencies": { "@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/types": "^2.7.6", "@walletconnect/universal-provider": "^2.7.6", "@walletconnect/utils": "^2.7.6", "@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", + "next": "12.3.4", "prop-types": "^15.7.2", "qr-image": "^3.2.0", - "next": "12.3.4", "react": "^17.0.2", "react-dom": "^17.0.2", "react-scripts": "^4.0.3", diff --git a/advanced/dapps/react-dapp-v2-with-ethers/src/chains/eip155.ts b/advanced/dapps/react-dapp-v2-with-ethers/src/chains/eip155.ts index 925e603..d60698a 100644 --- a/advanced/dapps/react-dapp-v2-with-ethers/src/chains/eip155.ts +++ b/advanced/dapps/react-dapp-v2-with-ethers/src/chains/eip155.ts @@ -18,6 +18,114 @@ export const EIP155Colors = { 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 = { "1": { name: "Ethereum", diff --git a/advanced/dapps/react-dapp-v2-with-ethers/src/components/Blockchain.tsx b/advanced/dapps/react-dapp-v2-with-ethers/src/components/Blockchain.tsx index ac3bb41..9e7bac3 100644 --- a/advanced/dapps/react-dapp-v2-with-ethers/src/components/Blockchain.tsx +++ b/advanced/dapps/react-dapp-v2-with-ethers/src/components/Blockchain.tsx @@ -1,6 +1,5 @@ import React, { PropsWithChildren, FC } from "react"; import styled from "styled-components"; -import { ChainData } from "caip-api"; import Asset from "./Asset"; import Button from "./Button"; @@ -93,7 +92,7 @@ interface BlockchainProps { } interface BlockchainDisplayData { - data: ChainData; + data: any; meta: ChainMetadata; } @@ -108,7 +107,7 @@ function getBlockchainDisplayData( } catch (e) { return undefined; } - const data: ChainData = chainData[namespace][reference]; + const data = chainData[namespace][reference]; if (typeof data === "undefined") return undefined; return { data, meta }; } diff --git a/advanced/dapps/react-dapp-v2-with-ethers/src/contexts/ClientContext.tsx b/advanced/dapps/react-dapp-v2-with-ethers/src/contexts/ClientContext.tsx index 1a2a4c2..f1e4fdf 100644 --- a/advanced/dapps/react-dapp-v2-with-ethers/src/contexts/ClientContext.tsx +++ b/advanced/dapps/react-dapp-v2-with-ethers/src/contexts/ClientContext.tsx @@ -9,7 +9,6 @@ import { } from "react"; import { Web3Modal } from "@web3modal/standalone"; -import { apiGetChainNamespace, ChainsMap } from "caip-api"; import UniversalProvider from "@walletconnect/universal-provider"; import { PairingTypes, SessionTypes } from "@walletconnect/types"; 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 { providers, utils } from "ethers"; import { AccountBalances, ChainNamespaces, getAllChainNamespaces } from "../helpers"; +import { EIP155ChainData } from "../chains/eip155"; /** * Types */ @@ -77,12 +77,16 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac const chainData: ChainNamespaces = {}; await Promise.all( namespaces.map(async namespace => { - let chains: ChainsMap | undefined; - try { - chains = await apiGetChainNamespace(namespace); - } catch (e) { - // ignore error + let chains; + switch (namespace) { + case "eip155": + chains = EIP155ChainData; + break; + + default: + console.error("Unknown chain namespace: ", namespace); } + if (typeof chains !== "undefined") { chainData[namespace] = chains; } @@ -195,7 +199,9 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac ], chains: [`eip155:${chainId}`], 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, diff --git a/advanced/dapps/react-dapp-v2-with-ethers/src/helpers/api.ts b/advanced/dapps/react-dapp-v2-with-ethers/src/helpers/api.ts index 9dce8e2..d5a3cff 100644 --- a/advanced/dapps/react-dapp-v2-with-ethers/src/helpers/api.ts +++ b/advanced/dapps/react-dapp-v2-with-ethers/src/helpers/api.ts @@ -131,7 +131,6 @@ const api: AxiosInstance = axios.create({ }); export const apiGetAccountNonce = async (address: string, chainId: string): Promise => { - debugger; const ethChainId = chainId.split(":")[1]; const { baseURL } = rpcProvidersByChainId[Number(ethChainId)]; const response = await api.post(baseURL, { diff --git a/advanced/dapps/react-dapp-v2-with-ethers/src/helpers/types.ts b/advanced/dapps/react-dapp-v2-with-ethers/src/helpers/types.ts index 71fc62b..59da626 100644 --- a/advanced/dapps/react-dapp-v2-with-ethers/src/helpers/types.ts +++ b/advanced/dapps/react-dapp-v2-with-ethers/src/helpers/types.ts @@ -1,5 +1,3 @@ -import { ChainsMap } from "caip-api"; - export interface AssetData { account: string; symbol: string; @@ -144,8 +142,17 @@ export interface ChainMetadata { export interface NamespaceMetadata { [reference: string]: ChainMetadata; } + export interface ChainNamespaces { - [namespace: string]: ChainsMap; + [namespace: string]: { + [reference: string]: { + name: string; + id: string; + rpc: string[]; + slip44: number; + testnet: boolean; + }; + }; } export interface AccountAction { diff --git a/advanced/dapps/react-dapp-v2-with-ethers/yarn.lock b/advanced/dapps/react-dapp-v2-with-ethers/yarn.lock index 2b73c21..1159e61 100644 --- a/advanced/dapps/react-dapp-v2-with-ethers/yarn.lock +++ b/advanced/dapps/react-dapp-v2-with-ethers/yarn.lock @@ -1975,13 +1975,6 @@ "@jridgewell/resolve-uri" "3.1.0" "@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": version "1.1.2" 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" 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: version "1.6.3" 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" 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: version "1.0.2" 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" readable-stream "^2.3.6" -follow-redirects@^1.0.0, follow-redirects@^1.14.0: +follow-redirects@^1.0.0: version "1.15.2" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== diff --git a/advanced/dapps/react-dapp-v2-with-web3js/package.json b/advanced/dapps/react-dapp-v2-with-web3js/package.json index b2a60c5..5a46e5f 100644 --- a/advanced/dapps/react-dapp-v2-with-web3js/package.json +++ b/advanced/dapps/react-dapp-v2-with-web3js/package.json @@ -36,7 +36,6 @@ "@web3modal/standalone": "^2.3.7", "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", diff --git a/advanced/dapps/react-dapp-v2-with-web3js/src/chains/eip155.ts b/advanced/dapps/react-dapp-v2-with-web3js/src/chains/eip155.ts index 925e603..d60698a 100644 --- a/advanced/dapps/react-dapp-v2-with-web3js/src/chains/eip155.ts +++ b/advanced/dapps/react-dapp-v2-with-web3js/src/chains/eip155.ts @@ -18,6 +18,114 @@ export const EIP155Colors = { 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 = { "1": { name: "Ethereum", diff --git a/advanced/dapps/react-dapp-v2-with-web3js/src/components/Blockchain.tsx b/advanced/dapps/react-dapp-v2-with-web3js/src/components/Blockchain.tsx index ac3bb41..9e7bac3 100644 --- a/advanced/dapps/react-dapp-v2-with-web3js/src/components/Blockchain.tsx +++ b/advanced/dapps/react-dapp-v2-with-web3js/src/components/Blockchain.tsx @@ -1,6 +1,5 @@ import React, { PropsWithChildren, FC } from "react"; import styled from "styled-components"; -import { ChainData } from "caip-api"; import Asset from "./Asset"; import Button from "./Button"; @@ -93,7 +92,7 @@ interface BlockchainProps { } interface BlockchainDisplayData { - data: ChainData; + data: any; meta: ChainMetadata; } @@ -108,7 +107,7 @@ function getBlockchainDisplayData( } catch (e) { return undefined; } - const data: ChainData = chainData[namespace][reference]; + const data = chainData[namespace][reference]; if (typeof data === "undefined") return undefined; return { data, meta }; } diff --git a/advanced/dapps/react-dapp-v2-with-web3js/src/contexts/ClientContext.tsx b/advanced/dapps/react-dapp-v2-with-web3js/src/contexts/ClientContext.tsx index 9798671..ab50bbe 100644 --- a/advanced/dapps/react-dapp-v2-with-web3js/src/contexts/ClientContext.tsx +++ b/advanced/dapps/react-dapp-v2-with-web3js/src/contexts/ClientContext.tsx @@ -9,7 +9,6 @@ import { } from "react"; import { Web3Modal } from "@web3modal/standalone"; -import { apiGetChainNamespace, ChainsMap } from "caip-api"; import UniversalProvider from "@walletconnect/universal-provider"; import Client from "@walletconnect/sign-client"; import Web3 from "web3"; @@ -17,6 +16,7 @@ import { DEFAULT_LOGGER, DEFAULT_PROJECT_ID, DEFAULT_RELAY_URL } from "../consta import { utils } from "ethers"; import { AccountBalances, ChainNamespaces, getAllChainNamespaces } from "../helpers"; import { PairingTypes, SessionTypes } from "@walletconnect/types"; +import { EIP155ChainData } from "../chains/eip155"; /** * Types @@ -75,12 +75,16 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac const chainData: ChainNamespaces = {}; await Promise.all( namespaces.map(async namespace => { - let chains: ChainsMap | undefined; - try { - chains = await apiGetChainNamespace(namespace); - } catch (e) { - // ignore error + let chains; + switch (namespace) { + case "eip155": + chains = EIP155ChainData; + break; + + default: + console.error("Unknown chain namespace: ", namespace); } + if (typeof chains !== "undefined") { chainData[namespace] = chains; } diff --git a/advanced/dapps/react-dapp-v2-with-web3js/src/helpers/api.ts b/advanced/dapps/react-dapp-v2-with-web3js/src/helpers/api.ts index 9dce8e2..d5a3cff 100644 --- a/advanced/dapps/react-dapp-v2-with-web3js/src/helpers/api.ts +++ b/advanced/dapps/react-dapp-v2-with-web3js/src/helpers/api.ts @@ -131,7 +131,6 @@ const api: AxiosInstance = axios.create({ }); export const apiGetAccountNonce = async (address: string, chainId: string): Promise => { - debugger; const ethChainId = chainId.split(":")[1]; const { baseURL } = rpcProvidersByChainId[Number(ethChainId)]; const response = await api.post(baseURL, { diff --git a/advanced/dapps/react-dapp-v2-with-web3js/src/helpers/types.ts b/advanced/dapps/react-dapp-v2-with-web3js/src/helpers/types.ts index 722c9fe..5c059b5 100644 --- a/advanced/dapps/react-dapp-v2-with-web3js/src/helpers/types.ts +++ b/advanced/dapps/react-dapp-v2-with-web3js/src/helpers/types.ts @@ -1,5 +1,3 @@ -import { ChainsMap } from "caip-api"; - export interface AssetData { symbol: string; balance: string; @@ -144,7 +142,15 @@ export interface NamespaceMetadata { [reference: string]: ChainMetadata; } export interface ChainNamespaces { - [namespace: string]: ChainsMap; + [namespace: string]: { + [reference: string]: { + name: string; + id: string; + rpc: string[]; + slip44: number; + testnet: boolean; + }; + }; } export interface AccountAction { diff --git a/advanced/dapps/react-dapp-v2-with-web3js/yarn.lock b/advanced/dapps/react-dapp-v2-with-web3js/yarn.lock index cf37842..4607f37 100644 --- a/advanced/dapps/react-dapp-v2-with-web3js/yarn.lock +++ b/advanced/dapps/react-dapp-v2-with-web3js/yarn.lock @@ -1986,13 +1986,6 @@ "@jridgewell/resolve-uri" "3.1.0" "@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": version "1.1.2" 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" 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: version "1.6.3" 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" 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: version "1.0.5" 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" readable-stream "^2.3.6" -follow-redirects@^1.0.0, follow-redirects@^1.14.0: +follow-redirects@^1.0.0: version "1.15.2" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==