Skip to content

Commit

Permalink
Merge branch 'nervosnetwork:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY authored Jul 25, 2024
2 parents ecce6fb + fce7d94 commit 13e7073
Show file tree
Hide file tree
Showing 28 changed files with 248 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Changed Files
id: changed-files
uses: tj-actions/changed-files@v41
uses: tj-actions/changed-files@v44
with:
files: "packages/**/*.{js,cjs,mjs,jsx,ts,tsx,css,scss}"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check_storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
node:
- 18.12.0
- 20.15.1
os:
- macos-latest
- ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/merge_released_into_develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
permissions:
pull-requests: write
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
- name: Request
uses: repo-sync/pull-request@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
node:
- 18.12.0
- 20.15.1
os:
- macos-latest
- ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package_for_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
node:
- 18.12.0
- 20.15.1
os:
- macos-latest
- ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
node:
- 20.11.1
- 20.15.1
os:
- macos-latest
- ubuntu-20.04
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update_ckb_client_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 20.15.1

- name: Update versions
id: update_versions
Expand All @@ -37,7 +37,7 @@ jobs:
git_commit_gpgsign: true

- name: Open PR to develop branch
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6
with:
title: Update ckb client versions
commit-message: 'feat: update ckb client versions'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update_neuron_compatible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 20.15.1

- name: Update versions
id: update_versions
Expand All @@ -40,7 +40,7 @@ jobs:
git_commit_gpgsign: true

- name: Open PR to RC branch
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6
with:
title: Update Neuron compatibility table
commit-message: 'feat: Update Neuron compatibility table'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/update_wallet_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
if: ${{ startsWith(github.ref_name, 'rc/') }}
steps:
- name: Create Branch
uses: peterjgrainger/action-create-branch@v2.4.0
uses: peterjgrainger/action-create-branch@v3.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand All @@ -25,11 +25,11 @@ jobs:
uses: actions/checkout@v4
with:
ref: 'chore-update-wallet-env/${{github.ref_name}}'

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18.12.0
node-version: 20.15.1

- name: Write env file
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const useOnSubmit = ({
id = '',
name = '',
remote = '',
networkType,
networks = [],
callback,
dispatch,
Expand All @@ -18,14 +19,15 @@ export const useOnSubmit = ({
id: string
name: string
remote: string
networkType: Controller.NetworkType
networks: Readonly<State.Network[]>
callback: () => void
dispatch: StateDispatch
disabled: boolean
setIsUpdating: React.Dispatch<boolean>
}) =>
useCallback((): void => {
if (disabled) {
if (disabled || !networkType) {
return
}
let errorMessage: State.Message<ErrorCode, { fieldName: string; fieldValue?: string; length?: string }> | undefined
Expand Down Expand Up @@ -98,6 +100,7 @@ export const useOnSubmit = ({
createNetwork({
name,
remote,
type: networkType,
})(dispatch, callback)
return
}
Expand Down
32 changes: 31 additions & 1 deletion packages/neuron-ui/src/components/NetworkEditorDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Dialog from 'widgets/Dialog'
import { validateNetworkName, validateURL } from 'utils'
import { useState as useGlobalState, useDispatch } from 'states'
import { isErrorWithI18n } from 'exceptions'
import { NetworkType } from 'utils/const'
import { useOnSubmit } from './hooks'
import styles from './networkEditorDialog.module.scss'

Expand All @@ -31,6 +32,7 @@ const NetworkEditorDialog = ({
)
const [t] = useTranslation()
const [editor, setEditor] = useState({
type: 0,
name: '',
nameError: '',
url: url ?? '',
Expand All @@ -39,6 +41,7 @@ const NetworkEditorDialog = ({
const [isUpdating, setIsUpdating] = useState(false)

const disabled = !!(
!editor.type ||
!editor.name ||
!editor.url ||
editor.nameError ||
Expand All @@ -50,6 +53,7 @@ const NetworkEditorDialog = ({
useEffect(() => {
if (cachedNetwork) {
setEditor({
type: cachedNetwork.type,
name: cachedNetwork.name,
nameError: '',
url: cachedNetwork.remote,
Expand All @@ -65,11 +69,14 @@ const NetworkEditorDialog = ({
dataset: { field = '' },
} = e.target as HTMLInputElement
let error = ''
let fieldValue: string | number = value
try {
if (field === 'name') {
validateNetworkName(value, usedNetworkNames)
} else if (field === 'url') {
validateURL(value)
} else if (field === 'type') {
fieldValue = Number(value)
}
} catch (err) {
if (isErrorWithI18n(err)) {
Expand All @@ -79,7 +86,7 @@ const NetworkEditorDialog = ({

setEditor(state => ({
...state,
[field]: value,
[field]: fieldValue,
[`${field}Error`]: error,
}))
},
Expand All @@ -90,6 +97,7 @@ const NetworkEditorDialog = ({
id: id!,
name: editor.name,
remote: editor.url,
networkType: editor.type,
networks,
callback: onSuccess,
dispatch,
Expand All @@ -109,6 +117,27 @@ const NetworkEditorDialog = ({
isLoading={isUpdating}
>
<div className={styles.container}>
<div className={styles.radioGroup}>
<p className={styles.label}>{t('settings.network.type')}</p>
{[
{ value: `${NetworkType.Normal}`, label: t('settings.network.full-node') },
{ value: `${NetworkType.Light}`, label: t('settings.network.light-client-node') },
].map(item => (
<div className={styles.radioItem} key={item.value}>
<label htmlFor={item.value}>
<input
id={item.value}
type="radio"
value={item.value}
data-field="type"
checked={Number(item.value) === editor.type}
onChange={onChange}
/>
<span>{item.label}</span>
</label>
</div>
))}
</div>
<TextField
value={editor.url}
field="url"
Expand All @@ -118,6 +147,7 @@ const NetworkEditorDialog = ({
placeholder={t('settings.network.edit-network.input-rpc')}
autoFocus
disabled={!!url}
className={styles.rpcItem}
/>
<TextField
value={editor.name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,48 @@

.container {
width: 648px;

.rpcItem {
margin-bottom: 10px;
}

.radioGroup {
display: flex;
align-items: center;
margin-bottom: 10px;
gap: 70px;

.label {
color: var(--secondary-text-color);
}

.radioItem {
display: flex;
justify-content: space-between;
align-items: center;
padding: 14px 16px;
label {
padding: 0;
cursor: pointer;
color: var(--main-text-color);
}
input[type='radio'] {
display: none;
margin-right: 8px;
}
input[type='radio'] + span {
display: inline-block;
padding-left: 26px;
font-size: 14px;
line-height: 20px;
background: url('../../widgets/Icons/Radio.svg') no-repeat left top;
user-select: none;
}
input[type='radio']:checked + span {
background: url('../../widgets/Icons/RadioSelected.svg') no-repeat left top;
}
}
}
}

.actions {
Expand Down
12 changes: 10 additions & 2 deletions packages/neuron-ui/src/components/NetworkSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,17 @@ const NetworkSetting = ({ chain = chainState, settings: { networks = [] } }: Sta
}
}, [currentId, networks])

const isInternalLightClient = (network?: State.Network) =>
network && network.readonly && network.type === NetworkType.Light

const showNetworks = useMemo(() => {
const internalLightNodeId = lastShowInternalNodeIds.get(NetworkType.Light)
return networks.filter(v => v.type !== NetworkType.Light || v.id === internalLightNodeId)
const lastShowNetwork = networks.find(v => v.id === internalLightNodeId)
if (isInternalLightClient(lastShowNetwork)) {
return networks.filter(network => !isInternalLightClient(network) || network.id === internalLightNodeId)
}
const index = networks.findIndex(network => isInternalLightClient(network))
return networks.filter((network, i) => !isInternalLightClient(network) || index === i)
}, [currentId, networks])

return (
Expand All @@ -111,7 +119,7 @@ const NetworkSetting = ({ chain = chainState, settings: { networks = [] } }: Sta
),
suffix: (
<div className={styles.suffix}>
{currentId === network.id && network.type === NetworkType.Light ? (
{currentId === network.id && isInternalLightClient(network) ? (
<Tooltip
tip={
<div>
Expand Down
16 changes: 7 additions & 9 deletions packages/neuron-ui/src/containers/Main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ const MainContent = () => {
[network, networks]
)

const isLightClientNetwork = network?.type === 2

useSyncChainData({
chainURL: network?.remote ?? '',
dispatch,
Expand Down Expand Up @@ -100,12 +98,6 @@ const MainContent = () => {
}, [])

const dialogProps = (function getDialogProps() {
if (isLightClientNetwork) {
return {
onConfirm: onCloseSwitchNetwork,
children: t('main.external-node-detected-dialog.external-node-is-light'),
}
}
if (sameUrlNetworks.length) {
return {
onConfirm: onSwitchNetwork,
Expand Down Expand Up @@ -137,7 +129,11 @@ const MainContent = () => {
return {
onConfirm: onOpenEditorDialog,
confirmText: t('main.external-node-detected-dialog.add-network'),
children: t('main.external-node-detected-dialog.body-tips-without-network'),
children: (
<span className={styles.chooseNetworkTip}>
{t('main.external-node-detected-dialog.body-tips-without-network')}
</span>
),
}
})()

Expand Down Expand Up @@ -172,6 +168,8 @@ const MainContent = () => {
cancelText={t('main.external-node-detected-dialog.ignore-external-node')}
title={t('main.external-node-detected-dialog.title')}
className={styles.networkDialog}
confirmProps={{ type: 'dashed' }}
cancelProps={{ type: 'dashed' }}
>
{dialogProps.children}
</Dialog>
Expand Down
14 changes: 8 additions & 6 deletions packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,10 @@
"lightTestnet": "Light Testnet",
"lightMainnet": "Light Mainnet",
"devnet": "Devnet",
"switch-network-type": "Switch to {{type}}"
"switch-network-type": "Switch to {{type}}",
"type": "Type",
"full-node": "Full Node",
"light-client-node": "Light Client Node"
},
"locale": {
"en": "English",
Expand Down Expand Up @@ -1221,12 +1224,11 @@
},
"main": {
"external-node-detected-dialog": {
"title": "External node detected",
"body-tips-without-network": "\"Internal Node\" is reserved for the built-in CKB node, please add a new network option for the external node.",
"body-tips-with-network": "\"Internal Node\" is reserved for the built-in CKB node, please select from the following network options or add a new one for the external node.",
"title": "Detected external node",
"body-tips-without-network": "You have selected the internal node but started the external node, if you want to continue to use an external node, please add a new network.",
"body-tips-with-network": "You have currently selected an internal node but started an external node, if you need to continu using the external node please switch to another external network or add a new network.",
"add-network": "Add Network",
"ignore-external-node": "Ignore external node",
"external-node-is-light": "Neuron does not support external light client nodes due to different security assumptions for light clients. Would you like to connect to the \"Light Client\" ?"
"ignore-external-node": "Ignore external node"
},
"no-disk-space-dialog": {
"tip": "Due to insufficient disk space, synchronization has been stopped. <br /> Please allocate more disk space or migrate the data to another disk.",
Expand Down
Loading

0 comments on commit 13e7073

Please sign in to comment.