Skip to content

Commit 9654662

Browse files
committed
feat: discriminate chain type by the result of rpc.getBlockchainInfo method
1 parent 8113b3f commit 9654662

15 files changed

Lines changed: 135 additions & 16 deletions

File tree

packages/neuron-ui/src/components/Addresses/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const Addresses = ({
3232
history,
3333
dispatch,
3434
}: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps>) => {
35-
const isMainnet = (networks.find(n => n.id === networkID) || {}).type === 'mainnet'
35+
const isMainnet =
36+
(networks.find(n => n.id === networkID) || {}).chain === (process.env.REACT_APP_MAINNET_TAG || 'ckb')
3637
const [showMainnetAddress, setShowMainnetAddress] = useState(false)
3738
const [t] = useTranslation()
3839
useEffect(() => {

packages/neuron-ui/src/components/NetworkEditor/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import React, { useMemo, useRef } from 'react'
22
import { RouteComponentProps } from 'react-router-dom'
33
import { useTranslation } from 'react-i18next'
4-
import { Stack, PrimaryButton, DefaultButton, TextField } from 'office-ui-fabric-react'
4+
import { Stack, PrimaryButton, DefaultButton, TextField, Spinner } from 'office-ui-fabric-react'
55

66
import { StateWithDispatch } from 'states/stateProvider/reducer'
77
import { useGoBack } from 'utils/hooks'
88
import { useInitialize, useInputs, useNetworkEditor, useIsInputsValid, useHandleSubmit } from './hooks'
99

1010
const NetworkEditor = ({
11+
app: {
12+
loadings: { network: isUpdating = false },
13+
},
1114
settings: { networks = [] },
1215
match: {
1316
params: { id = '' },
@@ -42,7 +45,13 @@ const NetworkEditor = ({
4245
</Stack>
4346
<Stack horizontal horizontalAlign="end" tokens={{ childrenGap: 10 }}>
4447
<DefaultButton onClick={goBack} text={t('common.cancel')} />
45-
<PrimaryButton disabled={hasError || notModified} onClick={handleSubmit} text={t('common.save')} />
48+
{isUpdating ? (
49+
<PrimaryButton disabled>
50+
<Spinner />
51+
</PrimaryButton>
52+
) : (
53+
<PrimaryButton disabled={hasError || notModified} onClick={handleSubmit} text={t('common.save')} />
54+
)}
4655
</Stack>
4756
</Stack>
4857
)

packages/neuron-ui/src/components/NetworkSetting/index.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ const onContextMenu = (id: string = '') => () => {
1313
contextMenu({ type: 'networkList', id })
1414
}
1515

16+
const Label = ({ type, t }: { type: 'ckb' | 'ckb_testnet' | 'ckb_dev' | string; t: any }) => {
17+
switch (type) {
18+
case 'ckb': {
19+
return <span className="label primary">{t('settings.network.mainnet')}</span>
20+
}
21+
case 'ckb_testnet': {
22+
return <span className="label secondary">{t('settings.network.testnet')}</span>
23+
}
24+
default: {
25+
return <span className="label third">{t('settings.network.devnet')}</span>
26+
}
27+
}
28+
}
29+
1630
const NetworkSetting = ({
1731
chain = chainState,
1832
settings: { networks = [] },
@@ -53,6 +67,7 @@ const NetworkSetting = ({
5367
<Text as="span" style={{ color: '#999' }}>
5468
{`(${network.remote})`}
5569
</Text>
70+
<Label type={network.chain} t={t} />
5671
</Stack>
5772
)
5873
},

packages/neuron-ui/src/locales/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@
189189
"title": "Add or Edit Network",
190190
"rpc-url": "RPC URL",
191191
"name": "Name"
192-
}
192+
},
193+
"mainnet": "Mainnet",
194+
"testnet": "Testnet",
195+
"devnet": "Devnet"
193196
}
194197
},
195198
"password-request": {

packages/neuron-ui/src/locales/zh.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@
189189
"title": "添加或编辑网络",
190190
"rpc-url": "RPC地址",
191191
"name": "名称"
192-
}
192+
},
193+
"mainnet": "主网",
194+
"testnet": "测试网",
195+
"devnet": "开发网"
193196
}
194197
},
195198
"password-request": {

packages/neuron-ui/src/states/initStates/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const appState: State.App = {
3636
sending: false,
3737
addressList: false,
3838
transactionList: false,
39+
network: false,
3940
},
4041
showTopAlert: false,
4142
showAllNotifications: false,

packages/neuron-ui/src/states/stateProvider/actionCreators/settings.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,29 @@ export const createNetwork = (params: Controller.CreateNetworkParams) => (dispat
2626
}
2727

2828
export const updateNetwork = (params: Controller.UpdateNetworkParams) => (dispatch: StateDispatch, history: any) => {
29-
updateRemoteNetwork(params).then(res => {
30-
if (res.status === 1) {
31-
addPopup('update-network-successfully')(dispatch)
32-
history.push(Routes.SettingsNetworks)
33-
} else {
34-
addNotification(failureResToNotification(res))(dispatch)
35-
}
29+
dispatch({
30+
type: AppActions.UpdateLoadings,
31+
payload: {
32+
network: true,
33+
},
3634
})
35+
updateRemoteNetwork(params)
36+
.then(res => {
37+
if (res.status === 1) {
38+
addPopup('update-network-successfully')(dispatch)
39+
history.push(Routes.SettingsNetworks)
40+
} else {
41+
addNotification(failureResToNotification(res))(dispatch)
42+
}
43+
})
44+
.finally(() => {
45+
dispatch({
46+
type: AppActions.UpdateLoadings,
47+
payload: {
48+
network: false,
49+
},
50+
})
51+
})
3752
}
3853

3954
export default {

packages/neuron-ui/src/stories/NetworkSetting.stories.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@ import initStates from 'states/initStates'
88
const states: { [title: string]: State.Network[] } = {
99
'Empty List': [],
1010
'Content List': [
11+
{
12+
id: 'Mainnet',
13+
name: 'Mainnet',
14+
remote: 'http://localhost:8114',
15+
chain: 'ckb',
16+
},
1117
{
1218
id: 'Testnet',
1319
name: 'Testnet',
1420
remote: 'http://localhost:8114',
21+
chain: 'ckb_testnet',
1522
},
1623
{
1724
id: 'Local',
1825
name: 'Local',
1926
remote: 'http://localhost:8114',
27+
chain: 'ckb_devnet',
2028
},
2129
],
2230
}

packages/neuron-ui/src/stories/Overview.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const stateTemplate = {
3939
id: 'testnet',
4040
name: 'Testnet',
4141
remote: 'http://testnet.nervos.com',
42+
chain: 'ckb_testnet',
4243
},
4344
],
4445
},
@@ -111,6 +112,7 @@ stories.addDecorator(withKnobs).add('With knobs', () => {
111112
id: text('Network iD', 'testnet'),
112113
name: text('Network Name', 'Testnet'),
113114
remote: text('Network Address', 'http://testnet.nervos.com'),
115+
chain: text('Chain', 'ckb_testnet'),
114116
},
115117
],
116118
},

packages/neuron-ui/src/styles/index.scss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ navbar {
4242
background-color: white;
4343
}
4444

45+
.label {
46+
padding: 3px 4px;
47+
font-size: 12px;
48+
font-weight: 600;
49+
line-height: 1;
50+
color: #fff;
51+
border-radius: 2px;
52+
box-shadow: inset 0 -1px 0 rgba(27, 31, 35, .12);
53+
text-transform: capitalize;
54+
55+
&.primary {
56+
background-color: #6f42c1;
57+
}
58+
59+
&.secondary {
60+
background-color: #009688;
61+
}
62+
63+
&.third {
64+
background-color: #78909C;
65+
}
66+
}
67+
4568
.form-control,
4669
.btn {
4770
&:focus {

0 commit comments

Comments
 (0)