Skip to content

Commit fb860c4

Browse files
authored
Merge pull request #1904 from nervosnetwork/refactor/disabled-sign-and-export-button
Disable sign and export button when the device is not connected
2 parents 51cf994 + 4317467 commit fb860c4

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,16 @@ const HardwareSign = ({
315315

316316
const dialogClass = `${styles.dialog} ${wallet.isHD ? styles.hd : ''}`
317317

318-
const dropdownList = [
319-
{
320-
text: t('offline-sign.sign-and-export'),
321-
onClick: signAndExportFromGenerateTx,
322-
},
323-
]
318+
const dropdownList = useMemo(() => {
319+
return [
320+
{
321+
text: t('offline-sign.sign-and-export'),
322+
onClick: signAndExportFromGenerateTx,
323+
disabled: status === disconnectStatus,
324+
disabledMsg: disconnectStatus,
325+
},
326+
]
327+
}, [signAndExportFromGenerateTx, status, disconnectStatus, t])
324328

325329
let container = (
326330
<div className={styles.container}>

packages/neuron-ui/src/widgets/DropdownButton/dropdownButton.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
background-color: #d1d1d1;
2727
font-weight: bold;
2828
}
29+
30+
&:disabled {
31+
cursor: not-allowed !important;
32+
}
2933
}
3034
}
3135

packages/neuron-ui/src/widgets/DropdownButton/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface DropdownButtonProps {
77
mainBtnOnClick: () => void
88
mainBtnLabel: string
99
mainBtnDisabled: boolean
10-
list: { text: string; onClick: () => void }[]
10+
list: { text: string; onClick: () => void; disabled?: boolean; disabledMsg?: string }[]
1111
}
1212

1313
const DropdownButton = ({ mainBtnLabel, mainBtnOnClick, mainBtnDisabled, list }: DropdownButtonProps) => {
@@ -20,9 +20,15 @@ const DropdownButton = ({ mainBtnLabel, mainBtnOnClick, mainBtnDisabled, list }:
2020
</button>
2121
{!mainBtnDisabled ? (
2222
<div className={styles.content}>
23-
{list.map(({ text, onClick }) => {
23+
{list.map(({ text, onClick, disabled, disabledMsg }) => {
2424
return (
25-
<button type="button" onClick={onClick} key={text}>
25+
<button
26+
title={disabled ? disabledMsg : text}
27+
type="button"
28+
onClick={onClick}
29+
key={text}
30+
disabled={disabled}
31+
>
2632
{text}
2733
</button>
2834
)

0 commit comments

Comments
 (0)