Skip to content

Commit

Permalink
fix: fix isMainnet method
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Nov 6, 2023
1 parent 7f88534 commit 67a00bb
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/neuron-ui/src/components/HDWalletSign/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DeviceSignIndex as DeviceSignIndexSubject } from 'services/subjects'

import styles from '../HardwareSign/hardwareSign.module.scss'

const { MAINNET_TAG } = CONSTANTS
const { MAINNET_CLIENT_LIST } = CONSTANTS

const HDWalletSign = ({ tx }: { tx: State.DetailedTransaction }) => {
const [t] = useTranslation()
Expand All @@ -33,7 +33,7 @@ const HDWalletSign = ({ tx }: { tx: State.DetailedTransaction }) => {
throw new Error('Cannot find current network in the network list')
}

setIsMainnet(network.chain === MAINNET_TAG)
setIsMainnet(MAINNET_CLIENT_LIST.includes(network.chain))
}
})
.catch(err => console.warn(err))
Expand Down
7 changes: 2 additions & 5 deletions packages/neuron-ui/src/components/HistoryDetailPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ import Tooltip from 'widgets/Tooltip'

import {
ErrorCode,
CONSTANTS,
localNumberFormatter,
uniformTimeFormatter,
shannonToCKBFormatter,
isSuccessResponse,
isMainnet as isMainnetUtil,
} from 'utils'
import { HIDE_BALANCE } from 'utils/const'

import styles from './historyDetailPage.module.scss'

const { MAINNET_TAG } = CONSTANTS

type InputOrOutputType = (State.DetailedInput | State.DetailedOutput) & { idx: number }

const InfoItem = ({ label, value, className }: { label: string; value: React.ReactNode; className?: string }) => (
Expand All @@ -46,8 +44,7 @@ const HistoryDetailPage = () => {
settings: { networks },
wallet: currentWallet,
} = useGlobalState()
const network = networks.find(n => n.id === networkID)
const isMainnet = network != null && network.chain === MAINNET_TAG
const isMainnet = isMainnetUtil(networks, networkID)
const [t] = useTranslation()
const [transaction, setTransaction] = useState(transactionState)
const [error, setError] = useState({ code: '', message: '' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { FC, useMemo, useState } from 'react'
import Tabs, { VariantProps } from 'widgets/Tabs'
import { clsx, localNumberFormatter, shannonToCKBFormatter } from 'utils'
import { clsx, localNumberFormatter, shannonToCKBFormatter, isMainnet as isMainnetUtils } from 'utils'
import { useTranslation } from 'react-i18next'
import { scriptToAddress } from '@nervosnetwork/ckb-sdk-utils'
import { onEnter } from 'utils/inputDevice'
import { EyesClose, EyesOpen } from 'widgets/Icons/icon'
import { HIDE_BALANCE, MAINNET_TAG } from 'utils/const'
import { HIDE_BALANCE } from 'utils/const'
import ScriptTag from 'components/ScriptTag'
import LockInfoDialog from 'components/LockInfoDialog'
import { useState as useGlobalState } from 'states'
Expand All @@ -24,8 +24,7 @@ const TabsVariantWithCellsCard: FC<
chain: { networkID },
settings: { networks },
} = useGlobalState()
const network = networks.find(n => n.id === networkID)
const isMainnet = network != null && network.chain === MAINNET_TAG
const isMainnet = isMainnetUtils(networks, networkID)

const [isPrivacyMode, setIsPrivacyMode] = useState(false)
const [showingLockInfo, setShowingLockInfo] = useState<CKBComponents.Script | null>(null)
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/Receive/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const useCopyAndDownloadQrCode = () => {
const toShortAddr = (addr: string) => {
try {
const script = addressToScript(addr)
const isMainnet = addr.startsWith('ckb')
const isMainnet = addr.startsWith(AddressPrefix.Mainnet)
return bech32Address(script.args, { prefix: isMainnet ? AddressPrefix.Mainnet : AddressPrefix.Testnet })
} catch {
return ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { DEFAULT_SUDT_FIELDS } = CONSTANTS
const toShortAddr = (addr: string) => {
try {
const script = addressToScript(addr)
const isMainnet = addr.startsWith('ckb')
const isMainnet = addr.startsWith(AddressPrefix.Mainnet)
return bech32Address(script.args, {
prefix: isMainnet ? AddressPrefix.Mainnet : AddressPrefix.Testnet,
codeHashOrCodeHashIndex: '0x02',
Expand Down
8 changes: 4 additions & 4 deletions packages/neuron-ui/src/utils/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export const MAX_TIP_BLOCK_DELAY = 180000
export const BUFFER_BLOCK_NUMBER = 10

export const MAX_DECIMAL_DIGITS = 8
export const MAINNET_TAG = 'ckb'
export const LIGHT_MAINNET_TAG = 'light_client_mainnet'
export const FULL_NODE_MAINNET = 'ckb'
export const LIGHT_CLIENT_MAINNET = 'light_client_mainnet'
export const LIGHT_CLIENT_TESTNET = 'light_client_testnet'
export const MAINNET_CLIENT_LIST = [FULL_NODE_MAINNET, LIGHT_CLIENT_MAINNET]

export const MIN_DEPOSIT_AMOUNT = 102
export const TOKEN_ID_LENGTH = 66
Expand Down Expand Up @@ -67,8 +69,6 @@ export const DEPRECATED_CODE_HASH: Record<string, string> = {
}

export const HIDE_BALANCE = '******'
export const LIGHT_CLIENT_TESTNET = 'light_client_testnet'
export const LIGHT_CLIENT_MAINNET = 'light_client_mainnet'
export enum NetworkType {
Default, // internal full node
Normal,
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-ui/src/utils/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
PwAcpLockInfoOnMainNet,
PwAcpLockInfoOnTestNet,
} from 'utils/enums'
import { LIGHT_MAINNET_TAG, MAINNET_TAG } from './const'
import { MAINNET_CLIENT_LIST } from './const'

export const isMainnet = (networks: Readonly<State.Network[]>, networkID: string) => {
const network = networks.find(n => n.id === networkID)
return network?.chain === MAINNET_TAG || network?.chain === LIGHT_MAINNET_TAG
return MAINNET_CLIENT_LIST.includes(network?.chain ?? '')
}

export const isSuccessResponse = (res: Pick<ControllerResponse, 'status'>): res is SuccessFromController => {
Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-wallet/src/services/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
BUNDLED_URL_PREFIX,
LIGHT_CLIENT_MAINNET,
LIGHT_CLIENT_TESTNET,
MAINNET_CLIENT_LIST,
} from '../utils/const'
import { generateRPC } from '../utils/ckb-rpc'
import { CKBLightRunner } from './light-runner'
Expand Down Expand Up @@ -230,7 +231,7 @@ export default class NetworksService extends Store {
}

public isMainnet = (): boolean => {
return this.getCurrent().chain === 'ckb'
return MAINNET_CLIENT_LIST.includes(this.getCurrent().chain)
}

public explorerUrl = (): string => {
Expand Down
4 changes: 3 additions & 1 deletion packages/neuron-wallet/src/utils/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ export const BUNDLED_CKB_DEFAULT_PORT = 8114
export const BUNDLED_LIGHT_DEFAULT_PORT = 9000
export const BUNDLED_CKB_URL = 'http://127.0.0.1:8114'
export const BUNDLED_LIGHT_CKB_URL = 'http://127.0.0.1:9000'
export const LIGHT_CLIENT_TESTNET = 'light_client_testnet'
export const FULL_NODE_MAINNET = 'ckb'
export const LIGHT_CLIENT_MAINNET = 'light_client_mainnet'
export const LIGHT_CLIENT_TESTNET = 'light_client_testnet'
export const MAINNET_CLIENT_LIST = [FULL_NODE_MAINNET, LIGHT_CLIENT_MAINNET]
export const SETTINGS_WINDOW_TITLE = process.platform === 'darwin' ? 'settings.title.mac' : 'settings.title.normal'
export const SETTINGS_WINDOW_WIDTH = 900
export const DEFAULT_UDT_SYMBOL = 'Unknown'
Expand Down

1 comment on commit 67a00bb

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 6773921676

Please sign in to comment.