Skip to content

Commit

Permalink
feat: Nervos DAO
Browse files Browse the repository at this point in the history
  • Loading branch information
devchenyan committed Apr 20, 2024
1 parent 3d441bd commit 7c5b1ef
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
import { isSuccessResponse, ErrorCode } from 'utils'

export const useInitialize = ({
hash,
tx,
walletID,
t,
onClose,
}: {
hash: string
tx: State.Transaction
walletID: string
t: TFunction
onClose: () => void
Expand All @@ -43,7 +43,7 @@ export const useInitialize = ({
}, [price, size])

const fetchInitData = useCallback(async () => {
const res = await getOnChainTransaction(hash)
const res = await getOnChainTransaction(tx.hash)
const {
// @ts-expect-error Replace-By-Fee (RBF)
min_replace_fee: minFee,
Expand All @@ -54,16 +54,16 @@ export const useInitialize = ({
setShowConfirmedAlert(true)
}

const txRes = await getSentTransaction({ hash, walletID })
const txRes = await getSentTransaction({ hash: tx.hash, walletID })

if (isSuccessResponse(txRes)) {
const tx = txRes.result
const txResult = txRes.result
setTransaction({
...tx,
...txResult,
outputsData,
})

const sizeRes = await getTransactionSize(tx)
const sizeRes = await getTransactionSize(txResult)

if (isSuccessResponse(sizeRes) && typeof sizeRes.result === 'number') {
setSize(sizeRes.result)
Expand All @@ -74,7 +74,7 @@ export const useInitialize = ({
}
}
}
}, [hash, setShowConfirmedAlert, setPrice, setTransaction, setSize, setMinPrice])
}, [tx, setShowConfirmedAlert, setPrice, setTransaction, setSize, setMinPrice])

useEffect(() => {
fetchInitData()
Expand All @@ -92,7 +92,7 @@ export const useInitialize = ({
const onSubmit = useCallback(async () => {
try {
// @ts-expect-error Replace-By-Fee (RBF)
const { min_replace_fee: minFee } = await getOnChainTransaction(hash)
const { min_replace_fee: minFee } = await getOnChainTransaction(tx.hash)
if (!minFee) {
setShowConfirmedAlert(true)
return
Expand All @@ -106,7 +106,7 @@ export const useInitialize = ({
try {
const skipLastInputs = generatedTx.inputs.length > generatedTx.witnesses.length

const res = await sendTx({ walletID, tx: generatedTx, password, skipLastInputs, amendHash: hash })
const res = await sendTx({ walletID, tx: generatedTx, password, skipLastInputs, amendHash: tx.hash })

if (isSuccessResponse(res)) {
onClose()
Expand All @@ -126,7 +126,7 @@ export const useInitialize = ({
} catch {
// ignore
}
}, [walletID, hash, setShowConfirmedAlert, setPwdError, password, generatedTx, setSending])
}, [walletID, tx, setShowConfirmedAlert, setPwdError, password, generatedTx, setSending])

return {
fee,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import AlertDialog from 'widgets/AlertDialog'
import styles from './amendPendingTransactionDialog.module.scss'
import { useInitialize } from './hooks'

const AmendPendingTransactionDialog = ({ hash, onClose }: { hash: string; onClose: () => void }) => {
const AmendPendingTransactionDialog = ({ tx, onClose }: { tx: State.Transaction; onClose: () => void }) => {
const {
wallet: { id: walletID = '', addresses },
chain: { networkID },
Expand All @@ -36,7 +36,7 @@ const AmendPendingTransactionDialog = ({ hash, onClose }: { hash: string; onClos
setGeneratedTx,
sending,
} = useInitialize({
hash,
tx,
walletID,
t,
onClose,
Expand All @@ -52,7 +52,7 @@ const AmendPendingTransactionDialog = ({ hash, onClose }: { hash: string; onClos
(e: React.SyntheticEvent<HTMLInputElement>) => {
const { value: inputValue } = e.currentTarget

const value = inputValue.split('.')[0].replace(/[^\d]/, '')
const value = inputValue.split('.')[0].replace(/[^\d]/g, '')
setPrice(value)
},
[setPrice]
Expand Down Expand Up @@ -141,11 +141,16 @@ const AmendPendingTransactionDialog = ({ hash, onClose }: { hash: string; onClos
if (transaction) {
const outputs = items.map(item => {
const capacity = item.isLastOutput ? lastOutputsCapacity.toString() : item.capacity
if (item.output.data === '0x0000000000000000') {
// eslint-disable-next-line no-param-reassign
item.output.daoData = '0x0000000000000000'
}
return {
...item.output,
capacity,
}
})

setGeneratedTx({
...transaction,
outputs,
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/AmendSUDTSend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const AmendSUDTSend = () => {
(e: React.SyntheticEvent<HTMLInputElement>) => {
const { value: inputValue } = e.currentTarget

const value = inputValue.split('.')[0].replace(/[^\d]/, '')
const value = inputValue.split('.')[0].replace(/[^\d]/g, '')
setPrice(value)
},
[setPrice]
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/AmendSend/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const clear = (dispatch: StateDispatch) => {
const useUpdateTransactionPrice = (dispatch: StateDispatch) =>
useCallback(
(value: string) => {
const price = value.split('.')[0].replace(/[^\d]/, '')
const price = value.split('.')[0].replace(/[^\d]/g, '')
dispatch({
type: AppActions.UpdateSendPrice,
payload: price,
Expand Down
22 changes: 9 additions & 13 deletions packages/neuron-ui/src/components/History/RowExtend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const RowExtend = ({ column, columns, isMainnet, id, bestBlockNumber, isWatchOnl
const navigate = useNavigate()
const [t] = useTranslation()
const [amendabled, setAmendabled] = useState(false)
const [amendPendingTxHash, setAmendPendingTxHash] = useState('')
const [amendPendingTx, setAmendPendingTx] = useState<State.Transaction>()

const { onChangeEditStatus, onSubmitDescription } = useLocalDescription('transaction', id, dispatch)

Expand All @@ -48,14 +48,12 @@ const RowExtend = ({ column, columns, isMainnet, id, bestBlockNumber, isWatchOnl
}
case 'amend': {
if (column.type === 'send' && !column.nftInfo && !column.nervosDao) {
if (column?.sudtInfo) {
navigate(`${RoutePath.History}/amendSUDTSend/${btn.dataset.hash}`)
}
navigate(`${RoutePath.History}/amend/${btn.dataset.hash}`)
return
}
if (column?.sudtInfo) {
navigate(`${RoutePath.History}/amendSUDTSend/${btn.dataset.hash}`)
return
}
setAmendPendingTxHash(btn.dataset.hash)
setAmendPendingTx(column)

break
}
Expand Down Expand Up @@ -83,7 +81,7 @@ const RowExtend = ({ column, columns, isMainnet, id, bestBlockNumber, isWatchOnl
}, [hash, dispatch])

useEffect(() => {
if (status !== 'success' && !isWatchOnly) {
if (status !== 'success' && column.type !== 'receive' && !isWatchOnly) {
getOnChainTransaction(hash).then(tx => {
// @ts-expect-error Replace-By-Fee (RBF)
const { min_replace_fee: minReplaceFee } = tx
Expand All @@ -96,8 +94,8 @@ const RowExtend = ({ column, columns, isMainnet, id, bestBlockNumber, isWatchOnl
}, [status, hash, setAmendabled])

const onCloseAmendDialog = useCallback(() => {
setAmendPendingTxHash('')
}, [setAmendPendingTxHash])
setAmendPendingTx(undefined)
}, [setAmendPendingTx])

return (
<>
Expand Down Expand Up @@ -173,9 +171,7 @@ const RowExtend = ({ column, columns, isMainnet, id, bestBlockNumber, isWatchOnl
</div>
</td>
</tr>
{amendPendingTxHash ? (
<AmendPendingTransactionDialog hash={amendPendingTxHash} onClose={onCloseAmendDialog} />
) : null}
{amendPendingTx ? <AmendPendingTransactionDialog tx={amendPendingTx} onClose={onCloseAmendDialog} /> : null}
</>
)
}
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/types/App/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ declare namespace State {
outPoint: CKBComponents.OutPoint
type?: CKBComponents.Script
data?: string
daoData?: string
isChangeCell?: boolean
}
interface DetailedTransaction extends Transaction {
Expand Down

1 comment on commit 7c5b1ef

@github-actions
Copy link
Contributor

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 8764088087

Please sign in to comment.