From 2393ff47252bb877715cda964b11a2a2813c1592 Mon Sep 17 00:00:00 2001 From: Evan Gray Date: Sat, 4 Mar 2023 17:53:17 +0000 Subject: [PATCH] optimism support --- src/components/ShowTx.tsx | 5 +++++ src/components/SmartAddress.tsx | 5 +++++ src/components/TransactionProgress.tsx | 5 +++++ src/icons/optimism.svg | 5 +++++ src/utils/consts.ts | 19 ++++++++++++++++++- src/utils/metaMaskChainParameters.ts | 7 +++++++ 6 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/icons/optimism.svg diff --git a/src/components/ShowTx.tsx b/src/components/ShowTx.tsx index f292437..160dc8b 100644 --- a/src/components/ShowTx.tsx +++ b/src/components/ShowTx.tsx @@ -22,6 +22,7 @@ import { CHAIN_ID_ARBITRUM, CHAIN_ID_INJECTIVE, CHAIN_ID_BASE, + CHAIN_ID_OPTIMISM, } from "@certusone/wormhole-sdk"; import { Button, makeStyles, Typography } from "@material-ui/core"; import { Transaction } from "../store/transferSlice"; @@ -126,6 +127,10 @@ export default function ShowTx({ ? `https://${CLUSTER === "testnet" ? "goerli." : ""}basescan.org/tx/${ tx?.id }` + : chainId === CHAIN_ID_OPTIMISM + ? `https://${ + CLUSTER === "testnet" ? "goerli-" : "" + }optimism.etherscan.io/tx/${tx?.id}` : chainId === CHAIN_ID_XPLA ? `https://explorer.xpla.io/${ CLUSTER === "testnet" ? "testnet/" : "" diff --git a/src/components/SmartAddress.tsx b/src/components/SmartAddress.tsx index 521a9a3..90fbfce 100644 --- a/src/components/SmartAddress.tsx +++ b/src/components/SmartAddress.tsx @@ -25,6 +25,7 @@ import { terra, CHAIN_ID_NEAR, CHAIN_ID_BASE, + CHAIN_ID_OPTIMISM, } from "@certusone/wormhole-sdk"; import { Button, makeStyles, Tooltip, Typography } from "@material-ui/core"; import { FileCopy, OpenInNew } from "@material-ui/icons"; @@ -160,6 +161,10 @@ export default function SmartAddress({ ? `https://${CLUSTER === "testnet" ? "goerli." : ""}basescan.org/${ isAsset ? "token" : "address" }/${useableAddress}` + : chainId === CHAIN_ID_OPTIMISM + ? `https://${CLUSTER === "testnet" ? "goerli-" : ""}optimism.etherscan.io/${ + isAsset ? "token" : "address" + }/${useableAddress}` : chainId === CHAIN_ID_KARURA ? `https://${ CLUSTER === "testnet" diff --git a/src/components/TransactionProgress.tsx b/src/components/TransactionProgress.tsx index f3b97ce..bf8c3f1 100644 --- a/src/components/TransactionProgress.tsx +++ b/src/components/TransactionProgress.tsx @@ -10,6 +10,7 @@ import { CHAIN_ID_KLAYTN, CHAIN_ID_MOONBEAM, CHAIN_ID_OASIS, + CHAIN_ID_OPTIMISM, CHAIN_ID_POLYGON, CHAIN_ID_SOLANA, isEVMChain, @@ -100,6 +101,8 @@ export default function TransactionProgress({ ? 64 // something to show progress : chainId === CHAIN_ID_BASE ? 124 // something to show progress + : chainId === CHAIN_ID_OPTIMISM + ? 124 // something to show progress : isEVMChain(chainId) ? 15 : 1; @@ -121,6 +124,8 @@ export default function TransactionProgress({ ? `Waiting for Ethereum finality on Arbitrum block ${tx?.block}` //TODO: more advanced finality checking for Arbitrum : chainId === CHAIN_ID_BASE ? `Waiting for Ethereum finality on Base block ${tx?.block}` //TODO: more advanced finality checking for Base + : chainId === CHAIN_ID_OPTIMISM + ? `Waiting for Ethereum finality on Optimism block ${tx?.block}` //TODO: more advanced finality checking for Optimism : blockDiff < expectedBlocks ? `Waiting for ${blockDiff} / ${expectedBlocks} confirmations on ${CHAINS_BY_ID[chainId].name}...` : `Waiting for Wormhole Network consensus...`} diff --git a/src/icons/optimism.svg b/src/icons/optimism.svg new file mode 100644 index 0000000..78db8a8 --- /dev/null +++ b/src/icons/optimism.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/utils/consts.ts b/src/utils/consts.ts index 709f637..2fd3754 100644 --- a/src/utils/consts.ts +++ b/src/utils/consts.ts @@ -18,6 +18,7 @@ import { CHAIN_ID_NEAR, CHAIN_ID_NEON, CHAIN_ID_OASIS, + CHAIN_ID_OPTIMISM, CHAIN_ID_POLYGON, CHAIN_ID_SOLANA, CHAIN_ID_TERRA, @@ -48,6 +49,7 @@ import klaytnIcon from "../icons/klaytn.svg"; import moonbeamIcon from "../icons/moonbeam.svg"; import neonIcon from "../icons/neon.svg"; import oasisIcon from "../icons/oasis-network-rose-logo.svg"; +import optimismIcon from "../icons/optimism.svg"; import polygonIcon from "../icons/polygon.svg"; import solanaIcon from "../icons/solana.svg"; import terraIcon from "../icons/terra.svg"; @@ -162,6 +164,11 @@ export const CHAINS: ChainInfo[] = name: "Oasis", logo: oasisIcon, }, + { + id: CHAIN_ID_OPTIMISM, + name: "Optimism (Goerli)", + logo: optimismIcon, + }, { id: CHAIN_ID_POLYGON, name: "Polygon", @@ -247,7 +254,8 @@ export const CHAINS_WITH_NFT_SUPPORT = CHAINS.filter( id === CHAIN_ID_NEON || id === CHAIN_ID_ARBITRUM || id === CHAIN_ID_MOONBEAM || - id === CHAIN_ID_BASE + id === CHAIN_ID_BASE || + id === CHAIN_ID_OPTIMISM ); export type ChainsById = { [key in ChainId]: ChainInfo }; export const CHAINS_BY_ID: ChainsById = CHAINS.reduce((obj, chain) => { @@ -299,6 +307,8 @@ export const getDefaultNativeCurrencySymbol = (chainId: ChainId) => ? "GLMR" : chainId === CHAIN_ID_BASE ? "ETH" + : chainId === CHAIN_ID_OPTIMISM + ? "ETH" : ""; export const getDefaultNativeCurrencyAddressEvm = (chainId: ChainId) => { @@ -379,6 +389,7 @@ export const NEON_NETWORK_CHAIN_ID = CLUSTER === "testnet" ? 245022926 : 1381; export const ARBITRUM_NETWORK_CHAIN_ID = CLUSTER === "testnet" ? 421613 : 1381; export const MOONBEAM_NETWORK_CHAIN_ID = CLUSTER === "testnet" ? 1287 : 1381; export const BASE_NETWORK_CHAIN_ID = CLUSTER === "testnet" ? 84531 : 1381; +export const OPTIMISM_NETWORK_CHAIN_ID = CLUSTER === "testnet" ? 420 : 1381; export const getEvmChainId = (chainId: ChainId) => chainId === CHAIN_ID_ETH ? ETH_NETWORK_CHAIN_ID @@ -410,6 +421,8 @@ export const getEvmChainId = (chainId: ChainId) => ? MOONBEAM_NETWORK_CHAIN_ID : chainId === CHAIN_ID_BASE ? BASE_NETWORK_CHAIN_ID + : chainId === CHAIN_ID_OPTIMISM + ? OPTIMISM_NETWORK_CHAIN_ID : undefined; export const SOLANA_HOST = process.env.REACT_APP_SOLANA_API_URL ? process.env.REACT_APP_SOLANA_API_URL @@ -544,6 +557,8 @@ export const COVALENT_MOONBEAM = CLUSTER === "devnet" ? null : MOONBEAM_NETWORK_CHAIN_ID; // Covalent only supports mainnet export const COVALENT_BASE = CLUSTER === "devnet" ? null : BASE_NETWORK_CHAIN_ID; +export const COVALENT_OPTIMISM = + CLUSTER === "devnet" ? null : OPTIMISM_NETWORK_CHAIN_ID; export const COVALENT_GET_TOKENS_URL = ( chainId: ChainId, @@ -574,6 +589,8 @@ export const COVALENT_GET_TOKENS_URL = ( ? COVALENT_MOONBEAM : chainId === CHAIN_ID_BASE ? COVALENT_BASE + : chainId === CHAIN_ID_OPTIMISM + ? COVALENT_OPTIMISM : ""; // https://www.covalenthq.com/docs/api/#get-/v1/{chain_id}/address/{address}/balances_v2/ return chainNum diff --git a/src/utils/metaMaskChainParameters.ts b/src/utils/metaMaskChainParameters.ts index 88f1f87..2049f8b 100644 --- a/src/utils/metaMaskChainParameters.ts +++ b/src/utils/metaMaskChainParameters.ts @@ -132,6 +132,13 @@ export const METAMASK_CHAIN_PARAMETERS: { rpcUrls: ["https://goerli.base.org"], blockExplorerUrls: ["https://goerli.basescan.org"], }, + 420: { + chainId: "0x1056", + chainName: "Optimism Goerli", + nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 }, + rpcUrls: ["https://goerli.optimism.io"], + blockExplorerUrls: ["https://goerli-optimism.etherscan.io"], + }, }; export interface EvmRpcMap {