diff --git a/packages/neuron-ui/src/components/NetworkEditor/index.tsx b/packages/neuron-ui/src/components/NetworkEditor/index.tsx index 62d22e76e3..4105007a81 100644 --- a/packages/neuron-ui/src/components/NetworkEditor/index.tsx +++ b/packages/neuron-ui/src/components/NetworkEditor/index.tsx @@ -105,7 +105,7 @@ const NetworkEditor = () => { onChange={onChange} label={t('settings.network.edit-network.rpc-url')} error={editor.urlError} - placeholder="http://localhost:8114" + placeholder="http://127.0.0.1:8114" required autoFocus /> diff --git a/packages/neuron-ui/src/stories/NetworkSetting.stories.tsx b/packages/neuron-ui/src/stories/NetworkSetting.stories.tsx index ce7cda1263..1fa4e8a932 100644 --- a/packages/neuron-ui/src/stories/NetworkSetting.stories.tsx +++ b/packages/neuron-ui/src/stories/NetworkSetting.stories.tsx @@ -10,21 +10,21 @@ const states: { [title: string]: State.Network[] } = { { id: 'Mainnet', name: 'Mainnet', - remote: 'http://localhost:8114', + remote: 'http://127.0.0.1:8114', chain: 'ckb', type: 0, }, { id: 'Testnet', name: 'Testnet', - remote: 'http://localhost:8114', + remote: 'http://127.0.0.1:8114', chain: 'ckb_testnet', type: 1, }, { id: 'Local', name: 'Local', - remote: 'http://localhost:8114', + remote: 'http://127.0.0.1:8114', chain: 'ckb_devnet', type: 1, }, diff --git a/packages/neuron-ui/src/stories/NetworkStatus.stories.tsx b/packages/neuron-ui/src/stories/NetworkStatus.stories.tsx index 48d16ef422..4f9572404e 100644 --- a/packages/neuron-ui/src/stories/NetworkStatus.stories.tsx +++ b/packages/neuron-ui/src/stories/NetworkStatus.stories.tsx @@ -6,7 +6,7 @@ import NetworkStatus, { NetworkStatusProps } from 'components/NetworkStatus' const defaultProps: Omit = { network: { name: 'network', - remote: 'http://localhost:3000', + remote: 'http://127.0.0.1:3000', type: 0, id: 'd', chain: 'ckb', @@ -67,7 +67,7 @@ stories.add('With knobs', () => { const props = { network: { name: text('Network name', 'network name'), - remote: text('Remote', 'http://localhost:3000'), + remote: text('Remote', 'http://127.0.0.1:3000'), type: select('Type', [0, 1], 0) as any, id: text('id', 'd'), chain: select('Chain', ['ckb', 'ckb_testnet', 'ckb_dev'], 'ckb'), diff --git a/packages/neuron-ui/src/tests/is/isMainnet/fixtures.ts b/packages/neuron-ui/src/tests/is/isMainnet/fixtures.ts index 739207c1dd..9749009a15 100644 --- a/packages/neuron-ui/src/tests/is/isMainnet/fixtures.ts +++ b/packages/neuron-ui/src/tests/is/isMainnet/fixtures.ts @@ -16,7 +16,7 @@ const fixtures = { 'Should return false when network id cannot be found in network list': { params: { networkID: 'testnet', - networks: [{ id: 'mainnet', chain: 'ckb', type: 0 as 0 | 1, name: 'Mainnet', remote: 'http://localhost:8114' }], + networks: [{ id: 'mainnet', chain: 'ckb', type: 0 as 0 | 1, name: 'Mainnet', remote: 'http://127.0.0.1:8114' }], }, expected: false, }, @@ -24,7 +24,7 @@ const fixtures = { params: { networkID: 'testnet', networks: [ - { id: 'testnet', chain: 'ckb_testnet', type: 0 as 0 | 1, name: 'Mainnet', remote: 'http://localhost:8114' }, + { id: 'testnet', chain: 'ckb_testnet', type: 0 as 0 | 1, name: 'Mainnet', remote: 'http://127.0.0.1:8114' }, ], }, expected: false, @@ -32,7 +32,7 @@ const fixtures = { "Should return true when network id can be found in network list and it's Mainnet": { params: { networkID: 'mainnet', - networks: [{ id: 'mainnet', chain: 'ckb', type: 0 as 0 | 1, name: 'Mainnet', remote: 'http://localhost:8114' }], + networks: [{ id: 'mainnet', chain: 'ckb', type: 0 as 0 | 1, name: 'Mainnet', remote: 'http://127.0.0.1:8114' }], }, expected: true, }, diff --git a/packages/neuron-wallet/src/services/networks.ts b/packages/neuron-wallet/src/services/networks.ts index 24be2b4bb4..cb5071b8dd 100644 --- a/packages/neuron-wallet/src/services/networks.ts +++ b/packages/neuron-wallet/src/services/networks.ts @@ -8,6 +8,7 @@ import { Validate, Required } from 'utils/validators' import { UsedName, NetworkNotFound, InvalidFormat } from 'exceptions' import { MAINNET_GENESIS_HASH, EMPTY_GENESIS_HASH, NetworkType, Network } from 'models/network' import CommonUtils from 'utils/common' +import { BUNDLED_CKB_URL } from 'utils/const' const presetNetworks: { selected: string; networks: Network[] } = { selected: 'mainnet', @@ -15,7 +16,7 @@ const presetNetworks: { selected: string; networks: Network[] } = { { id: 'mainnet', name: 'Default', - remote: 'http://localhost:8114', + remote: BUNDLED_CKB_URL, genesisHash: MAINNET_GENESIS_HASH, type: NetworkType.Default, chain: 'ckb' @@ -47,6 +48,12 @@ export default class NetworksService extends Store { public getAll = () => { const networks = this.readSync(NetworksKey.List) || presetNetworks.networks + networks.forEach((network) => { + // Currently, the RPC interface of the CKB node is bound to IPv4 by default. + // Starting from node17, its DNS resolution is no longer `ipv4first`. + // Therefore, to ensure normal connection to the ckb node, manual resolution needs to be done here. + network.remote = applyLocalhostIPv4Resolve(network.remote) + }) const defaultNetwork = networks[0] const isOldDefaultName = ['Default', 'Mainnet'].includes(networks[0].name) defaultNetwork.name = isOldDefaultName ? 'default node' : defaultNetwork.name @@ -176,3 +183,17 @@ export default class NetworksService extends Store { return network } } + +function applyLocalhostIPv4Resolve(url: string): string { + let urlObj + try { + urlObj = new URL(url) + } catch (err) { + return url + } + + if (urlObj.hostname !== 'localhost') return url + + urlObj.hostname = '127.0.0.1' + return urlObj.href +} diff --git a/packages/neuron-wallet/src/utils/const.ts b/packages/neuron-wallet/src/utils/const.ts index 0fe3ff2f81..9d1e694f9c 100644 --- a/packages/neuron-wallet/src/utils/const.ts +++ b/packages/neuron-wallet/src/utils/const.ts @@ -1,6 +1,6 @@ export const MIN_PASSWORD_LENGTH = 8 export const MAX_PASSWORD_LENGTH = 50 -export const BUNDLED_CKB_URL = 'http://localhost:8114' +export const BUNDLED_CKB_URL = 'http://127.0.0.1:8114' 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' diff --git a/packages/neuron-wallet/tests/controllers/export-debug.test.ts b/packages/neuron-wallet/tests/controllers/export-debug.test.ts index 9ab2b6b6d6..60458c3ea6 100644 --- a/packages/neuron-wallet/tests/controllers/export-debug.test.ts +++ b/packages/neuron-wallet/tests/controllers/export-debug.test.ts @@ -55,7 +55,7 @@ jest.mock('../../src/services/networks', () => { return { getCurrent() { return { - remote: 'http://localhost:8114' + remote: 'http://127.0.0.1:8114' } } } diff --git a/packages/neuron-wallet/tests/services/networks.test.ts b/packages/neuron-wallet/tests/services/networks.test.ts index ca0fd752dd..3277912a18 100644 --- a/packages/neuron-wallet/tests/services/networks.test.ts +++ b/packages/neuron-wallet/tests/services/networks.test.ts @@ -11,7 +11,7 @@ const ERROR_MESSAGE = { describe(`Unit tests of networks service`, () => { const newNetwork: Network = { name: `new network`, - remote: `http://localhost:8114`, + remote: `http://127.0.0.1:8114`, type: 0, genesisHash: '0x', id: '', @@ -20,7 +20,7 @@ describe(`Unit tests of networks service`, () => { const newNetworkWithDefaultTypeOf1 = { name: `new network with the default type of 1`, - remote: `http://localhost:8114`, + remote: `http://127.0.0.1:8114`, id: '', } @@ -82,7 +82,7 @@ describe(`Unit tests of networks service`, () => { it(`update the network' address`, async () => { const network = await service.create(newNetworkWithDefaultTypeOf1.name, newNetworkWithDefaultTypeOf1.remote) - const address = `http://localhost:8115` + const address = `http://127.0.0.1:8115` await service.update(network.id, { remote: address }) const updated = service.get(network.id) expect(updated && updated.remote).toBe(address) @@ -151,11 +151,11 @@ describe(`Unit tests of networks service`, () => { describe(`validation on network existence`, () => { beforeEach(async () => { - await service.create('Default', 'http://localhost:8114') + await service.create('Default', 'http://127.0.0.1:8114') }); it(`create network with existing name of Default`, () => { - expect(service.create('Default', 'http://localhost:8114')).rejects.toThrowError(t(ERROR_MESSAGE.NAME_USED)) + expect(service.create('Default', 'http://127.0.0.1:8114')).rejects.toThrowError(t(ERROR_MESSAGE.NAME_USED)) }) it(`update network which is not existing`, () => { diff --git a/packages/neuron-wallet/tests/services/node.test.ts b/packages/neuron-wallet/tests/services/node.test.ts index 5f89450b9d..54edad3da4 100644 --- a/packages/neuron-wallet/tests/services/node.test.ts +++ b/packages/neuron-wallet/tests/services/node.test.ts @@ -322,7 +322,7 @@ describe('NodeService', () => { expect(stubbedTipNumberSubjectCallback).toHaveBeenCalledWith('0') }) describe('targets to bundled node', () => { - const bundledNodeUrl = 'http://localhost:8114' + const bundledNodeUrl = 'http://127.0.0.1:8114' beforeEach(async () => { stubbedCKBSetNode.mockImplementation(() => { nodeService.ckb.node.url = bundledNodeUrl