Skip to content

Commit

Permalink
fix: Disable unlock when there is no ckb.
Browse files Browse the repository at this point in the history
  • Loading branch information
yanguoyu committed Jan 12, 2024
1 parent 4907867 commit a21ee7f
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/neuron-ui/src/components/NervosDAO/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ const NervosDAO = () => {
genesisBlockTimestamp,
connectionStatus,
isPrivacyMode,
hasCkbBalance: !!wallet.balance && wallet.balance !== '0',
}
return <DAORecord key={key} {...props} />
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,10 @@
line-height: 56px;
padding: 0;
}

.tip {
width: 220px;
white-space: normal;
}
}
}
41 changes: 32 additions & 9 deletions packages/neuron-ui/src/components/NervosDAORecord/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Clock } from 'widgets/Icons/icon'
import { Link } from 'react-router-dom'
import { HIDE_BALANCE } from 'utils/const'

import Tooltip from 'widgets/Tooltip'
import styles from './daoRecordRow.module.scss'
import hooks from './hooks'

Expand All @@ -42,6 +43,7 @@ export interface DAORecordProps extends State.NervosDAORecord {
tipBlockTimestamp: number // tip block timestamp, used to calculate apc, dovetails with current epoch
genesisBlockTimestamp: number | undefined // genesis block timestamp, used to calculate apc
isPrivacyMode?: boolean
hasCkbBalance?: boolean
}

export const DAORecord = ({
Expand All @@ -62,6 +64,7 @@ export const DAORecord = ({
withdrawInfo,
unlockInfo,
isPrivacyMode,
hasCkbBalance,
}: DAORecordProps) => {
const [t] = useTranslation()
const [withdrawEpoch, setWithdrawEpoch] = useState('')
Expand Down Expand Up @@ -143,8 +146,11 @@ export const DAORecord = ({
const compensatedPeriod =
withdrawInfo?.timestamp && depositInfo?.timestamp ? +withdrawInfo.timestamp - +depositInfo.timestamp : undefined

const isWithdrawnDisabled = CellStatus.Deposited === cellStatus && !hasCkbBalance
const isActionAvailable =
connectionStatus === 'online' && [CellStatus.Deposited, CellStatus.Unlockable].includes(cellStatus)
connectionStatus === 'online' &&
[CellStatus.Deposited, CellStatus.Unlockable].includes(cellStatus) &&
!isWithdrawnDisabled

const depositOutPointKey = depositOutPoint
? `${depositOutPoint.txHash}-${depositOutPoint.index}`
Expand Down Expand Up @@ -277,14 +283,31 @@ export const DAORecord = ({
</div>

<div className={styles.action}>
<Button
type="primary"
data-tx-hash={txHash}
data-index={index}
onClick={onClick}
disabled={!isActionAvailable}
label={t(`nervos-dao.deposit-record.${isWithdrawn ? 'unlock' : 'withdraw'}-action-label`)}
/>
{isWithdrawnDisabled ? (
<Tooltip
tip={<div>{t('nervos-dao.deposit-record.no-ckb')}</div>}
placement="top"
tipClassName={styles.tip}
>
<Button
type="primary"
data-tx-hash={txHash}
data-index={index}
onClick={onClick}
disabled={!isActionAvailable}
label={t(`nervos-dao.deposit-record.${isWithdrawn ? 'unlock' : 'withdraw'}-action-label`)}
/>
</Tooltip>
) : (
<Button
type="primary"
data-tx-hash={txHash}
data-index={index}
onClick={onClick}
disabled={!isActionAvailable}
label={t(`nervos-dao.deposit-record.${isWithdrawn ? 'unlock' : 'withdraw'}-action-label`)}
/>
)}
</div>
</div>
)}
Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,8 @@
"compensated-period": "Compensation Period",
"days-hours": "{{days}} days {{hours}} hours",
"no-deposit": "No Deposit",
"no-completed": "No Completed"
"no-completed": "No Completed",
"no-ckb": "No other CKB to pay for transaction fee that unlock DAO"
},
"compensation-period": {
"tooltip": {
Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-ui/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,8 @@
"compensated-period": "Période de compensation",
"days-hours": "{{days}} jours {{hours}} heures",
"no-deposit": "Aucun dépôt",
"no-completed": "Aucun terminé"
"no-completed": "Aucun terminé",
"no-ckb": "Pas de ckb supplémentaire pour payer les frais de traitement pour déverrouiller le DAO"
},
"compensation-period": {
"tooltip": {
Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-ui/src/locales/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,8 @@
"compensated-period": "補貼時間",
"days-hours": "{{days}} 天 {{hours}} 小時",
"no-deposit": "沒有存入記錄",
"no-completed": "沒有解鎖記錄"
"no-completed": "沒有解鎖記錄",
"no-ckb": "沒有額外的 CKB 用於支付解鎖 DAO 的手續費"
},
"compensation-period": {
"tooltip": {
Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,8 @@
"compensated-period": "补贴时间",
"days-hours": "{{days}} 天 {{hours}} 小时",
"no-deposit": "没有存入记录",
"no-completed": "没有解锁记录"
"no-completed": "没有解锁记录",
"no-ckb": "没有额外的 CKB 用于支付解锁 DAO 的手续费"
},
"compensation-period": {
"tooltip": {
Expand Down
2 changes: 2 additions & 0 deletions packages/neuron-wallet/src/controllers/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export default class AppController {
devTools: env.isDevMode,
contextIsolation: false,
preload: path.join(__dirname, './preload.js'),
// disable webSecurity for dev, do not set webSecurity as true, because electron has default set other value when webSecurity is not set by developer
...(app.isPackaged ? {} : { webSecurity: false }),
},
})

Expand Down

1 comment on commit a21ee7f

@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 7499758274

Please sign in to comment.