Skip to content

Commit

Permalink
fix: Fix network type label (#2811)
Browse files Browse the repository at this point in the history
* fix: Fix network type label

* fix: Confirm should be default onOK

* fix: Extract getNetworkLabelI18nkey to utils
  • Loading branch information
yanguoyu authored Aug 29, 2023
1 parent 541677c commit 8964e8e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 44 deletions.
4 changes: 2 additions & 2 deletions packages/neuron-ui/src/components/NetworkSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Toast from 'widgets/Toast'
import { chainState } from 'states'
import { setCurrentNetwork, deleteNetwork } from 'services/remote'
import RadioGroup from 'widgets/RadioGroup'
import { useOnWindowResize, useToggleChoiceGroupBorder } from 'utils'
import { useOnWindowResize, useToggleChoiceGroupBorder, getNetworkLabelI18nkey } from 'utils'
import { LIGHT_CLIENT_TESTNET } from 'utils/const'
import styles from './networkSetting.module.scss'

Expand Down Expand Up @@ -87,7 +87,7 @@ const NetworkSetting = ({ chain = chainState, settings: { networks = [] } }: Sta
label: (
<div className={styles.networkLabel}>
<p>{`${network.name} (${network.remote})`}</p>
<div className={styles.tag}>{network.chain}</div>
<div className={styles.tag}>{t(getNetworkLabelI18nkey(network.chain))}</div>
</div>
),
suffix: (
Expand Down
25 changes: 0 additions & 25 deletions packages/neuron-ui/src/components/NetworkTypeLabel/index.tsx

This file was deleted.

24 changes: 8 additions & 16 deletions packages/neuron-ui/src/components/PageContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React, { FC, PropsWithChildren, useCallback, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { ErrorCode, getExplorerUrl, isMainnet as isMainnetUtil, localNumberFormatter } from 'utils'
import {
ErrorCode,
getExplorerUrl,
isMainnet as isMainnetUtil,
localNumberFormatter,
getNetworkLabelI18nkey,
} from 'utils'
import Alert from 'widgets/Alert'
import { Close, NewTab } from 'widgets/Icons/icon'
import { ReactComponent as Sun } from 'widgets/Icons/Sun.svg'
Expand All @@ -25,20 +31,6 @@ const PageHeadNotice = ({ notice }: { notice: State.PageNotice }) => {
)
}

const getNetworkTypeLabel = (type: 'ckb' | 'ckb_testnet' | 'ckb_dev' | string) => {
switch (type) {
case 'ckb': {
return 'settings.network.mainnet'
}
case 'ckb_testnet': {
return 'settings.network.testnet'
}
default: {
return 'settings.network.devnet'
}
}
}

type ComponentProps = {
head: React.ReactNode
notice?: State.PageNotice
Expand Down Expand Up @@ -70,7 +62,7 @@ const PageContainer: React.FC<ComponentProps> = props => {
() => networks.find(n => n.id === networkID)?.type === LIGHT_NETWORK_TYPE,
[networkID, networks]
)
const netWorkTypeLabel = useMemo(() => (network ? getNetworkTypeLabel(network.chain) : ''), [network])
const netWorkTypeLabel = useMemo(() => (network ? getNetworkLabelI18nkey(network.chain) : ''), [network])
const [syncPercents, syncBlockNumbers] = useMemo(() => {
const bestBlockNumber = Math.max(cacheTipBlockNumber, bestKnownBlockNumber)
return [
Expand Down
20 changes: 20 additions & 0 deletions packages/neuron-ui/src/utils/getNetworkLabel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { LIGHT_CLIENT_TESTNET } from './const'

export const getNetworkLabelI18nkey = (type: 'ckb' | 'ckb_testnet' | 'ckb_dev' | string) => {
switch (type) {
case 'ckb': {
return 'settings.network.mainnet'
}
case 'ckb_testnet': {
return 'settings.network.testnet'
}
case LIGHT_CLIENT_TESTNET: {
return 'settings.network.lightTestnet'
}
default: {
return 'settings.network.devnet'
}
}
}

export default getNetworkLabelI18nkey
1 change: 1 addition & 0 deletions packages/neuron-ui/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ export * from './getSyncLeftTime'
export * from './baseActions'
export * from './getSUDTAmount'
export * from './multisig'
export * from './getNetworkLabel'

export { CONSTANTS }
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/widgets/AlertDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const AlertDialog = ({
v === 'cancel' ? (
<Button type="cancel" onClick={onCancel} label={t('common.cancel')} />
) : (
<Button type="confirm" onClick={onCancel || onOk} label={t('common.confirm')} />
<Button type="confirm" onClick={onOk || onCancel} label={t('common.confirm')} />
)
)}
</div>
Expand Down

2 comments on commit 8964e8e

@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 6007246679

@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 6007247636

Please sign in to comment.