Skip to content

Commit

Permalink
Merge pull request #1337 from Conflux-Chain/dev
Browse files Browse the repository at this point in the history
feat: Release version:2.5.1
  • Loading branch information
zctocm authored Nov 29, 2022
2 parents 7ff133f + 447c60d commit 26ee77f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shared basic environment variable
# the build tool will load this file with any NODE_ENV
SNOWPACK_PUBLIC_FLUENT_VERSION=2.5.0
SNOWPACK_PUBLIC_FLUENT_VERSION=2.5.1

9 changes: 7 additions & 2 deletions packages/popup/src/pages/DappSwitchNetwork/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {useMemo} from 'react'
import {useTranslation} from 'react-i18next'
import {formatHexToDecimal} from '@fluent-wallet/data-format'
import {DappFooter, DappProgressHeader, CustomTag} from '../../components'
import {RPC_METHODS, NETWORK_TYPE} from '../../constants'
import {getInnerUrlWithoutLimitKey} from '../../utils'
import {usePendingAuthReq, useNetworkByChainId} from '../../hooks/useApi'
const {WALLET_SWITCH_CONFLUX_CHAIN} = RPC_METHODS

Expand All @@ -15,11 +17,14 @@ function DappSwitchNetwork() {
? NETWORK_TYPE.CFX
: NETWORK_TYPE.ETH,
)

const [{isTestnet, name, endpoint, icon}] = networkData.length
? networkData
: [{}]

const disPlayRpcURL = useMemo(() => {
return getInnerUrlWithoutLimitKey(name) || endpoint
}, [name, endpoint])

return (
<div
className="flex flex-col h-full w-full justify-between bg-blue-circles bg-no-repeat pb-4"
Expand Down Expand Up @@ -68,7 +73,7 @@ function DappSwitchNetwork() {
<div id="networkUrl">
<div className="text-xs text-gray-40">{t('networkUrl')}</div>
<div className="text-sm text-gray-80 font-medium mt-0.5 text-ellipsis">
{endpoint}
{disPlayRpcURL}
</div>
</div>
<div className="mt-3" id="chainId">
Expand Down
55 changes: 35 additions & 20 deletions packages/popup/src/pages/NetworkDetail/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import validUrl from 'valid-url'
import {useState, useEffect, useRef} from 'react'
import {useState, useEffect, useRef, useMemo} from 'react'
import {isUndefined} from '@fluent-wallet/checks'
import {useHistory} from 'react-router-dom'
import {useTranslation} from 'react-i18next'
Expand All @@ -13,7 +13,7 @@ import {
ETH_MAINNET_CURRENCY_NAME,
} from '@fluent-wallet/consts'
import {TitleNav, CompWithLabel, ConfirmPassword} from '../../components'
import {request} from '../../utils'
import {request, getInnerUrlWithoutLimitKey} from '../../utils'
import {useCurrentAddress} from '../../hooks/useApi'
import {
ROUTES,
Expand Down Expand Up @@ -80,10 +80,23 @@ function NetworkDetail() {
const rpcUrlInputRef = useRef(null)

const {networkInfo, setNetworkInfo} = useGlobalStore()

const isAddingChain = !Object.keys(networkInfo).length
const isCustom = networkInfo?.networkType === 'custom'
const isBuiltin = !isAddingChain && !isCustom
const defaultOrigin = useMemo(() => {
return getInnerUrlWithoutLimitKey(networkInfo?.networkName)
}, [networkInfo?.networkName])

const [networkFieldValues, setNetworkFieldValues] = useState(() => {
return {
chainName: networkInfo?.networkName ?? '',
rpcUrl: networkInfo?.rpcUrl ?? '',
rpcUrl: networkInfo?.rpcUrl
? networkInfo.rpcUrl ===
BUILTIN_NETWORK_ENDPOINTS?.[networkInfo?.networkName]
? defaultOrigin
: networkInfo.rpcUrl
: '',
chainId: networkInfo?.chainId ?? '',
networkType: getNetworkType(networkInfo?.type),
symbol: networkInfo?.symbol ?? '',
Expand All @@ -103,20 +116,12 @@ function NetworkDetail() {
const [rpcUrlChecked, setRpcUrlChecked] = useState(false)
const [rpcUrlResetAble, setRpcUrlResetAble] = useState(false)

const isAddingChain = !Object.keys(networkInfo).length
const isCustom = networkInfo?.networkType === 'custom'
const isBuiltin = !isAddingChain && !isCustom

const {data} = useCurrentAddress(isAddingChain)
const currentNetworkId = data?.network?.eid

useEffect(() => {
setRpcUrlResetAble(
isBuiltin &&
networkFieldValues.rpcUrl !==
BUILTIN_NETWORK_ENDPOINTS[networkInfo.networkName],
)
}, [isBuiltin, networkFieldValues.rpcUrl, networkInfo.networkName])
setRpcUrlResetAble(isBuiltin && networkFieldValues.rpcUrl !== defaultOrigin)
}, [isBuiltin, defaultOrigin, networkFieldValues.rpcUrl])

useEffect(() => {
return () => {
Expand Down Expand Up @@ -167,7 +172,11 @@ function NetworkDetail() {
const onValidateRpcUrl = async () => {
try {
const res = await request(WALLET_DETECT_NETWORK_TYPE, {
url: networkFieldValues.rpcUrl,
url:
networkFieldValues.rpcUrl === defaultOrigin ||
networkFieldValues.rpcUrl === `${defaultOrigin}/`
? BUILTIN_NETWORK_ENDPOINTS?.[networkInfo?.networkName]
: networkFieldValues.rpcUrl,
})
// validated url
if (res?.chainId && res?.type) {
Expand Down Expand Up @@ -262,7 +271,12 @@ function NetworkDetail() {
const onSave = async (type = 'add') => {
const {chainId, chainName, symbol, rpcUrl, blockExplorerUrl} =
networkFieldValues
if (type === 'innerEdit' && rpcUrl === networkInfo?.rpcUrl) {
if (
type === 'innerEdit' &&
(rpcUrl === networkInfo?.rpcUrl ||
rpcUrl === defaultOrigin ||
rpcUrl === `${defaultOrigin}/`)
) {
return history.push(HOME)
}
setLoading(true)
Expand All @@ -285,7 +299,11 @@ function NetworkDetail() {
symbol: symbol || detectedChainType.toUpperCase(),
decimals: COMMON_DECIMALS,
},
rpcUrls: [rpcUrl],
rpcUrls: [
rpcUrl === defaultOrigin || rpcUrl === `${defaultOrigin}/`
? BUILTIN_NETWORK_ENDPOINTS?.[networkInfo?.networkName]
: rpcUrl,
],
}

if (blockExplorerUrl) {
Expand Down Expand Up @@ -324,10 +342,7 @@ function NetworkDetail() {
className="text-xs text-primary cursor-pointer"
onMouseDown={e => {
e.preventDefault()
onNetworkInputChange(
BUILTIN_NETWORK_ENDPOINTS[networkInfo.networkName],
'rpcUrl',
)
onNetworkInputChange(defaultOrigin, 'rpcUrl')
rpcUrlInputRef?.current?.focus()
}}
>
Expand Down
11 changes: 11 additions & 0 deletions packages/popup/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
NETWORK_TYPE,
LANGUAGES,
PAGE_LIMIT,
BUILTIN_NETWORK_ENDPOINTS,
} from '../constants'
const globalThis = window ?? global
const {
Expand Down Expand Up @@ -313,3 +314,13 @@ export const getAvatarAddress = addresses => {
export const addUnitForValue = (value, isCfxChain = false) => {
return value ? `${value} ${isCfxChain ? 'GDrip' : 'GWei'}` : 'loading'
}

// hide inner api limit key
export const getInnerUrlWithoutLimitKey = innerNetworkName => {
if (BUILTIN_NETWORK_ENDPOINTS?.[innerNetworkName]) {
let arr = BUILTIN_NETWORK_ENDPOINTS[innerNetworkName].split('/')
arr.pop()
return arr.join('/')
}
return ''
}

0 comments on commit 26ee77f

Please sign in to comment.