Skip to content

Commit

Permalink
Merge branch 'feat-network' of https://github.com/yanguoyu/neuron int…
Browse files Browse the repository at this point in the history
…o feat-network
  • Loading branch information
yanguoyu committed Nov 7, 2023
2 parents 0e05c93 + f87f6b2 commit 09675fb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/NetworkSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const NetworkSetting = ({ chain = chainState, settings: { networks = [] } }: Sta
options={showNetworks.map(network => ({
value: network.id,
label:
currentId === network.id && network.readonly ? (
currentId === network.id && network.type === NetworkType.Light ? (
<div className={styles.networkLabel}>
<p>{`${network.name} (${network.remote})`}</p>
<Tooltip
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/types/App/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ declare namespace State {
name: string
remote: string
chain: 'ckb' | 'ckb_testnet' | 'ckb_dev' | string
type: 0 | 1 | 2
type: 0 | 1 | 2 // 0 for default node, 1 for full node, 2 for light client, ref: NetworkType in utils/const.ts
genesisHash: string
readonly: boolean
}
Expand Down
9 changes: 0 additions & 9 deletions packages/neuron-wallet/src/services/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ export const presetNetworks: { selected: string; networks: Network[] } = {
chain: 'ckb',
readonly: true,
},
{
id: 'testnet',
name: 'Internal Node',
remote: BUNDLED_CKB_URL,
genesisHash: TESTNET_GENESIS_HASH,
type: NetworkType.Default,
chain: 'ckb_testnet',
readonly: true,
},
],
}

Expand Down
11 changes: 6 additions & 5 deletions packages/neuron-wallet/tests/services/networks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ describe(`Unit tests of networks service`, () => {

it(`has preset networks`, () => {
const networks = service.getAll()
expect(networks.length).toBe(4)
expect(networks.length).toBe(3)
expect(networks[0].id).toEqual('mainnet')
expect(networks[1].id).toEqual('light_client')
expect(networks[2].id).toEqual('light_client_testnet')
})

it(`get the default network`, () => {
Expand Down Expand Up @@ -305,17 +307,16 @@ describe(`Unit tests of networks service`, () => {
expect(writeSyncMock).toHaveBeenNthCalledWith(2, 'AddInternalNetwork', true)
expect(updateAllMock).toBeCalledWith([...presetNetworks.networks, ...lightClientNetwork])
})
it('update internal current id to testnet', () => {
it('set readonly network options', () => {
readSyncMock.mockImplementation(v => {
if (v === 'selected') return presetNetworks.selected
if (v === 'networks') return [{ ...presetNetworks.networks[1], id: 'mainnet' }, ...lightClientNetwork]
if (v === 'networks') return lightClientNetwork
return false
})
writeSyncMock.mockReset()
//@ts-ignore private-method
service.addInternalNetwork()
expect(writeSyncMock).toHaveBeenNthCalledWith(1, 'selected', 'testnet')
expect(writeSyncMock).toHaveBeenNthCalledWith(2, 'AddInternalNetwork', true)
expect(writeSyncMock).toHaveBeenNthCalledWith(1, 'AddInternalNetwork', true)
expect(updateAllMock).toBeCalledWith([...presetNetworks.networks, ...lightClientNetwork])
})
})
Expand Down

1 comment on commit 09675fb

@github-actions
Copy link

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 6781214868

Please sign in to comment.