From f8d7e795f23027e3321138b808cf1ad8022656fd Mon Sep 17 00:00:00 2001 From: SSSensational Date: Thu, 27 Jan 2022 12:56:39 +0800 Subject: [PATCH] feat: delete evmtestnet --- .yarn/versions/fb113636.yml | 2 + .../dapp-cross-space/src/manage/index.tsx | 1 - .../src/manage/useConflux/ConfluxManage.ts | 17 +++-- .../src/manage/useEvm/EvmManage.ts | 12 ++-- .../src/manage/useFluent/FluentManage.ts | 22 ------- .../src/manage/useFluent/index.tsx | 1 - .../dapp-cross-space/src/pages/Nav/index.tsx | 64 ++----------------- packages/dapp-cross-space/types/index.ts | 2 - 8 files changed, 22 insertions(+), 99 deletions(-) create mode 100644 .yarn/versions/fb113636.yml diff --git a/.yarn/versions/fb113636.yml b/.yarn/versions/fb113636.yml new file mode 100644 index 000000000..cbfe513b8 --- /dev/null +++ b/.yarn/versions/fb113636.yml @@ -0,0 +1,2 @@ +declined: + - dapp-cross-space diff --git a/packages/dapp-cross-space/src/manage/index.tsx b/packages/dapp-cross-space/src/manage/index.tsx index 5fa76ee33..4fce7fdea 100644 --- a/packages/dapp-cross-space/src/manage/index.tsx +++ b/packages/dapp-cross-space/src/manage/index.tsx @@ -27,7 +27,6 @@ export { connect, sendTransaction, trackBalanceChangeOnce, - addEVMChain, } from './useFluent' export { useConflux, diff --git a/packages/dapp-cross-space/src/manage/useConflux/ConfluxManage.ts b/packages/dapp-cross-space/src/manage/useConflux/ConfluxManage.ts index 51e95864e..48bd1860a 100644 --- a/packages/dapp-cross-space/src/manage/useConflux/ConfluxManage.ts +++ b/packages/dapp-cross-space/src/manage/useConflux/ConfluxManage.ts @@ -9,20 +9,23 @@ export interface CrossSpaceContract { } export const confluxNetworkConfig = { - '12000': { - networkId: 12000, - url: 'https://net12000cfx.confluxrpc.com', - evmSpaceUrl: 'https://net12001eth.confluxrpc.com' - }, '1029': { networkId: 1029, url: 'https://main.confluxrpc.com', - evmSpaceUrl: 'https://main.confluxrpc.com' + EvmSpace: { + url: 'https://evm.confluxrpc.com', + networkId: 1030, + scan: 'https://evm.confluxscan.net' + } }, '1': { networkId: 1, url: 'https://test.confluxrpc.com', - evmSpaceUrl: 'https://test.confluxrpc.com' + EvmSpace: { + url: 'https://evmtest.confluxrpc.com', + networkId: 71, + scan: 'https://evmtestnet.confluxscan.net' + } }, } as const diff --git a/packages/dapp-cross-space/src/manage/useEvm/EvmManage.ts b/packages/dapp-cross-space/src/manage/useEvm/EvmManage.ts index 7300c5058..5bad482aa 100644 --- a/packages/dapp-cross-space/src/manage/useEvm/EvmManage.ts +++ b/packages/dapp-cross-space/src/manage/useEvm/EvmManage.ts @@ -40,7 +40,7 @@ class EvmManage { } try { - const balance = await fetch(this.networkConfig.value.evmSpaceUrl, { + const balance = await fetch(this.networkConfig.value.EvmSpace.url, { body: JSON.stringify({ jsonrpc: '2.0', method: 'eth_getBalance', @@ -107,21 +107,21 @@ class EvmManage { } addEVMChain = async () => { - if (!window.ethereum) return + if (!window.ethereum || !this.networkConfig.value) return return window.ethereum.request({ method: 'wallet_addEthereumChain', params: [ { - chainId: '0x2ee1', - chainName: 'EVM Conflux', + chainId: `0x${this.networkConfig.value.EvmSpace.networkId.toString(16)}`, + chainName: 'Conflux', nativeCurrency: { name: 'Conflux', symbol: 'CFX', decimals: 18, }, - rpcUrls: ['https://net12001eth.confluxrpc.com'], - blockExplorerUrls: ['https://confluxscan.io'], + rpcUrls: [this.networkConfig.value.EvmSpace.url], + blockExplorerUrls: [this.networkConfig.value.EvmSpace.scan], }, ], }) diff --git a/packages/dapp-cross-space/src/manage/useFluent/FluentManage.ts b/packages/dapp-cross-space/src/manage/useFluent/FluentManage.ts index b894ca079..a2f74fdfc 100644 --- a/packages/dapp-cross-space/src/manage/useFluent/FluentManage.ts +++ b/packages/dapp-cross-space/src/manage/useFluent/FluentManage.ts @@ -173,27 +173,6 @@ class FluentManage { }) } - addEVMChain = async () => { - if (!this.account.value) return - - return window.conflux!.request({ - method: 'wallet_addConfluxChain', - params: [ - { - chainId: '0x2ee0', - chainName: 'EVM Conflux', - nativeCurrency: { - name: 'Conflux', - symbol: 'CFX', - decimals: 18, - }, - rpcUrls: ['https://net12000cfx.confluxrpc.com'], - blockExplorerUrls: ['https://confluxscan.io'], - }, - ], - }) - } - estimateMaxAvailableBalance = async () => { if ( !this.account.value || @@ -238,6 +217,5 @@ export const startTrackBalance = Manage.startTrackBalance export const stopTrackBalance = Manage.stopTrackBalance export const sendTransaction = Manage.sendTransaction export const trackBalanceChangeOnce = Manage.trackBalanceChangeOnce -export const addEVMChain = Manage.addEVMChain export default Manage diff --git a/packages/dapp-cross-space/src/manage/useFluent/index.tsx b/packages/dapp-cross-space/src/manage/useFluent/index.tsx index d7e6c035f..47d84f518 100644 --- a/packages/dapp-cross-space/src/manage/useFluent/index.tsx +++ b/packages/dapp-cross-space/src/manage/useFluent/index.tsx @@ -4,5 +4,4 @@ export { connect, sendTransaction, trackBalanceChangeOnce, - addEVMChain, } from './FluentManage' diff --git a/packages/dapp-cross-space/src/pages/Nav/index.tsx b/packages/dapp-cross-space/src/pages/Nav/index.tsx index 76ecb939a..242e4d8a6 100644 --- a/packages/dapp-cross-space/src/pages/Nav/index.tsx +++ b/packages/dapp-cross-space/src/pages/Nav/index.tsx @@ -1,7 +1,7 @@ -import React, {useState, useEffect, useCallback} from 'react' -import {useFluent, connect, addEVMChain} from '../../manage/useFluent' +import React, {useCallback} from 'react' +import {useFluent, connect} from '../../manage/useFluent' import {addEVMChainToMetaMask} from '../../manage/useEvm' -import showToast, {hideToast} from '../../components/tools/Toast' +import showToast from '../../components/tools/Toast' import ShortenAddress from '../../components/ShortenAddress' import ConfluxIcon from '../../assets/icon.svg' import FluentIcon from '../../assets/fluent.svg' @@ -9,54 +9,6 @@ import './index.css' const Nav: React.FC = () => { const {account, isConnected, chainId} = useFluent() - const [showAddedEvmChainToFluent, setShowAddedEvmChainToFluent] = useState(false) - const [showAddedEvmChainToMetaMask, setShowAddedEvmChainToMetaMask] = useState(true) - - // delete this after testnet ready - const checkNetwork = useCallback(async () => { - try { - await window.conflux!.request({ - method: 'wallet_switchConfluxChain', - params: [{chainId: '0x2ee0'}], - }) - } catch (err) { - if (!((err as {code: number})?.code === 4001 && (err as any)?.message?.indexOf('UserRejected') !== -1)) { - showToast("You haven't add EVM-Space in fluent, Please click the top button to add.", {key: 'switch-fluent'}); - setShowAddedEvmChainToFluent(true); - } - } - - if (!window.ethereum) { - showToast("You don't have MetaMask installed", {key: 'not-installed-metamask'}); - setShowAddedEvmChainToFluent(false) - return; - } - setShowAddedEvmChainToFluent(true) - }, []); - - useEffect(() => { - if (!isConnected) { - setShowAddedEvmChainToMetaMask(false) - setShowAddedEvmChainToFluent(false) - } else { - checkNetwork(); - } - }, [isConnected]) - - const handleClickAddEVMChainToFluent = useCallback(async () => { - try { - await addEVMChain() - hideToast('switch-fluent') - showToast('Added EVM-Space to Fluent Success!') - setShowAddedEvmChainToFluent(false) - await window.conflux!.request({ - method: 'wallet_switchConfluxChain', - params: [{chainId: '0x2ee0'}], - }) - } catch (err) { - console.error(err) - } - }, []) const handleClickAddEVMChainToMetaMask = useCallback(async () => { if (!window.ethereum) { @@ -102,7 +54,7 @@ const Nav: React.FC = () => {
- {isConnected && showAddedEvmChainToMetaMask && ( + {isConnected && chainId === '1' && ( )} - {isConnected && showAddedEvmChainToFluent && chainId !== '12000' && ( - - )} {!isConnected && (