diff --git a/packages/neuron-ui/src/components/Addresses/index.tsx b/packages/neuron-ui/src/components/Addresses/index.tsx index 2ef12764cb..0afdffb770 100644 --- a/packages/neuron-ui/src/components/Addresses/index.tsx +++ b/packages/neuron-ui/src/components/Addresses/index.tsx @@ -20,6 +20,7 @@ import { StateWithDispatch } from 'states/stateProvider/reducer' import { useLocalDescription } from 'utils/hooks' import { localNumberFormatter, shannonToCKBFormatter } from 'utils/formatters' import { onRenderRow } from 'utils/fabricUIRender' +import { MAINNET_TAG } from 'utils/const' const Addresses = ({ app: { @@ -30,8 +31,7 @@ const Addresses = ({ settings: { networks = [] }, dispatch, }: React.PropsWithoutRef) => { - const isMainnet = - (networks.find(n => n.id === networkID) || {}).chain === (process.env.REACT_APP_MAINNET_TAG || 'ckb') + const isMainnet = (networks.find(n => n.id === networkID) || {}).chain === MAINNET_TAG const [showMainnetAddress, setShowMainnetAddress] = useState(false) const [t] = useTranslation() diff --git a/packages/neuron-ui/src/components/Transaction/index.tsx b/packages/neuron-ui/src/components/Transaction/index.tsx index 54b83c0b54..8aa66a5740 100644 --- a/packages/neuron-ui/src/components/Transaction/index.tsx +++ b/packages/neuron-ui/src/components/Transaction/index.tsx @@ -8,7 +8,7 @@ import { ckbCore } from 'services/chain' import { transactionState } from 'states/initStates/chain' import { localNumberFormatter, uniformTimeFormatter, shannonToCKBFormatter } from 'utils/formatters' -import { ErrorCode } from 'utils/const' +import { ErrorCode, MAINNET_TAG } from 'utils/const' import { explorerNavButton } from './style.module.scss' const MIN_CELL_WIDTH = 70 @@ -30,9 +30,11 @@ const CompactAddress = ({ address }: { address: string }) => ( const Transaction = () => { const [t] = useTranslation() const [transaction, setTransaction] = useState(transactionState) - const [addressPrefix, setAddressPrefix] = useState(ckbCore.utils.AddressPrefix.Mainnet) + const [isMainnet, setIsMainnet] = useState(false) const [error, setError] = useState({ code: '', message: '' }) + const addressPrefix = isMainnet ? ckbCore.utils.AddressPrefix.Mainnet : ckbCore.utils.AddressPrefix.Testnet + const inputColumns: IColumn[] = useMemo( () => [ @@ -198,11 +200,7 @@ const Transaction = () => { throw new Error('Cannot find current network in the network list') } - setAddressPrefix( - network.chain === process.env.REACT_APP_MAINNET_TAG - ? ckbCore.utils.AddressPrefix.Mainnet - : ckbCore.utils.AddressPrefix.Testnet - ) + setIsMainnet(network.chain === MAINNET_TAG) } }) .catch(err => console.warn(err)) @@ -246,10 +244,10 @@ const Transaction = () => { }) }, []) - // TODO: add conditional branch on mainnet and testnet const onExplorerBtnClick = useCallback(() => { - openExternal(`https://explorer.nervos.org/transaction/${transaction.hash}`) - }, [transaction.hash]) + const explorerUrl = isMainnet ? 'https://explorer.nervos.org' : 'https://explorer.nervos.org/testnet' + openExternal(`${explorerUrl}/transaction/${transaction.hash}`) + }, [transaction.hash, isMainnet]) const basicInfoItems = useMemo( () => [ diff --git a/packages/neuron-ui/src/utils/const.ts b/packages/neuron-ui/src/utils/const.ts index 135ae4ab4f..f6d812a7d7 100644 --- a/packages/neuron-ui/src/utils/const.ts +++ b/packages/neuron-ui/src/utils/const.ts @@ -10,6 +10,7 @@ export const UNREMOVABLE_NETWORK_ID = '0' export const CONFIRMATION_THRESHOLD = 30 export const MAX_DECIMAL_DIGITS = 8 +export const MAINNET_TAG = 'ckb' export enum ConnectionStatus { Online = 'online', diff --git a/packages/neuron-wallet/src/models/chain-info.ts b/packages/neuron-wallet/src/models/chain-info.ts index d5fbf6394b..630fc3ac22 100644 --- a/packages/neuron-wallet/src/models/chain-info.ts +++ b/packages/neuron-wallet/src/models/chain-info.ts @@ -27,6 +27,6 @@ export default class ChainInfo { if (this.isMainnet()) { return "https://explorer.nervos.org" } - return "https://explorer.nervos.org" // TODO: change this to proper testnet explorer URL + return "https://explorer.nervos.org/testnet" } }