Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: delete evmtestnet #681

Merged
merged 2 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .yarn/versions/fb113636.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declined:
- dapp-cross-space
1 change: 0 additions & 1 deletion packages/dapp-cross-space/src/manage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export {
connect,
sendTransaction,
trackBalanceChangeOnce,
addEVMChain,
} from './useFluent'
export {
useConflux,
Expand Down
17 changes: 10 additions & 7 deletions packages/dapp-cross-space/src/manage/useConflux/ConfluxManage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions packages/dapp-cross-space/src/manage/useEvm/EvmManage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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],
},
],
})
Expand Down
22 changes: 0 additions & 22 deletions packages/dapp-cross-space/src/manage/useFluent/FluentManage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion packages/dapp-cross-space/src/manage/useFluent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ export {
connect,
sendTransaction,
trackBalanceChangeOnce,
addEVMChain,
} from './FluentManage'
64 changes: 4 additions & 60 deletions packages/dapp-cross-space/src/pages/Nav/index.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,14 @@
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'
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) {
Expand Down Expand Up @@ -102,22 +54,14 @@ const Nav: React.FC = () => {
</div>

<div className="flex items-center justify-center">
{isConnected && showAddedEvmChainToMetaMask && (
{isConnected && chainId === '1' && (
<button
className="button text-[14px] h-[40px]"
onClick={handleClickAddEVMChainToMetaMask}
>
Add EVM-Space To MetaMask
</button>
)}
{isConnected && showAddedEvmChainToFluent && chainId !== '12000' && (
<button
className="button text-[14px] h-[40px] ml-[12px]"
onClick={handleClickAddEVMChainToFluent}
>
Add EVM-Space To Fluent
</button>
)}
{!isConnected && (
<button
id="btn-connect-nav"
Expand Down
2 changes: 0 additions & 2 deletions packages/dapp-cross-space/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
type ConfluxMainNetwork = '1029'
type ConfluxTestNetwork = '1'
type ConfluxTest2Network = '12000'
type ConfluxChainId =
| ConfluxMainNetwork
| ConfluxTestNetwork
| ConfluxTest2Network

type FluentEvents =
| 'chainChanged'
Expand Down