Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
devchenyan committed Jan 14, 2025
1 parent 7249042 commit 814420e
Show file tree
Hide file tree
Showing 24 changed files with 786 additions and 159 deletions.
90 changes: 67 additions & 23 deletions packages/neuron-ui/src/components/DepositDialog/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { TFunction } from 'i18next'
import { Dispatch, SetStateAction, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import {
MultisigConfig,
generateDaoDepositAllTx as generateDaoDepositAllTxAPI,
generateDaoDepositTx as generateDaoDepositTxAPI,
generateMultisigDaoDepositTx as generateMultisigDaoDepositTxAPI,
generateMultisigDaoDepositAllTx as generateMultisigDaoDepositAllTxAPI,
} from 'services/remote'
import { AppActions, useDispatch } from 'states'
import {
Expand Down Expand Up @@ -45,17 +48,26 @@ function generateDaoDepositTx({
capacity,
suggestFeeRate,
t,
multisigConfig,
}: {
walletID: string
capacity: string
suggestFeeRate: number
t: TFunction
multisigConfig?: MultisigConfig
}): Promise<State.GeneratedTx | null> {
return generateDaoDepositTxAPI({
feeRate: `${suggestFeeRate}`,
capacity,
walletID,
}).then(res => {
const generateCall = multisigConfig
? generateMultisigDaoDepositTxAPI({
feeRate: `${suggestFeeRate}`,
capacity,
multisigConfig,
})
: generateDaoDepositTxAPI({
walletID,
feeRate: `${suggestFeeRate}`,
capacity,
})
return generateCall.then(res => {
if (isSuccessResponse(res)) {
return res.result
}
Expand All @@ -73,16 +85,25 @@ function generateDaoDepositAllTx({
suggestFeeRate,
isBalanceReserved,
walletID,
multisigConfig,
}: {
suggestFeeRate: number
isBalanceReserved: boolean
walletID: string
multisigConfig?: MultisigConfig
}): Promise<State.GeneratedTx | null> {
return generateDaoDepositAllTxAPI({
walletID,
feeRate: `${suggestFeeRate}`,
isBalanceReserved,
}).then(res => {
const generateAllCall = multisigConfig
? generateMultisigDaoDepositAllTxAPI({
feeRate: `${suggestFeeRate}`,
isBalanceReserved,
multisigConfig,
})
: generateDaoDepositAllTxAPI({
walletID,
feeRate: `${suggestFeeRate}`,
isBalanceReserved,
})
return generateAllCall.then(res => {
if (isSuccessResponse(res)) {
return res.result
}
Expand All @@ -97,13 +118,15 @@ export const useGenerateDaoDepositTx = ({
suggestFeeRate,
showDepositDialog,
slidePercent,
multisigConfig,
}: {
walletID: string
isBalanceReserved: boolean
depositValue: string
suggestFeeRate: number
showDepositDialog: boolean
slidePercent: number
multisigConfig?: MultisigConfig
}) => {
const timer = useRef<ReturnType<typeof setTimeout>>()
const [errorMessage, setErrorMessage] = useState('')
Expand All @@ -127,8 +150,14 @@ export const useGenerateDaoDepositTx = ({
}

const generateDaoDepositResult: Promise<State.GeneratedTx | null> = isDepositAll
? generateDaoDepositAllTx({ walletID, isBalanceReserved, suggestFeeRate })
: generateDaoDepositTx({ walletID, capacity: CKBToShannonFormatter(depositValue), suggestFeeRate, t })
? generateDaoDepositAllTx({ walletID, isBalanceReserved, suggestFeeRate, multisigConfig })
: generateDaoDepositTx({
walletID,
capacity: CKBToShannonFormatter(depositValue),
suggestFeeRate,
t,
multisigConfig,
})
generateDaoDepositResult
.then(res => {
dispatch({
Expand Down Expand Up @@ -239,22 +268,37 @@ export const useBalanceReserved = () => {

export const useOnDepositDialogSubmit = ({
onDepositSuccess,
walletID,
wallet,
multisigConfig,
}: {
onDepositSuccess: () => void
walletID: string
wallet: State.Wallet
multisigConfig?: MultisigConfig
}) => {
const dispatch = useDispatch()
return useCallback(() => {
dispatch({
type: AppActions.RequestPassword,
payload: {
walletID,
actionType: 'send',
onSuccess: onDepositSuccess,
},
})
}, [dispatch, walletID, onDepositSuccess])
if (multisigConfig) {
dispatch({
type: AppActions.RequestPassword,
payload: {
walletID: wallet.id,
actionType: multisigConfig.m === 1 ? 'send-from-multisig-need-one' : 'send-from-multisig',
multisigConfig,
onSuccess: onDepositSuccess,
title: 'password-request.verify-password',
},
})
} else {
dispatch({
type: AppActions.RequestPassword,
payload: {
walletID: wallet.id,
actionType: 'send',
onSuccess: onDepositSuccess,
},
})
}
}, [dispatch, wallet.id, onDepositSuccess, multisigConfig])
}

export const useOnDepositDialogCancel = ({
Expand Down
25 changes: 18 additions & 7 deletions packages/neuron-ui/src/components/DepositDialog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useCallback } from 'react'
import React, { useCallback, useMemo } from 'react'
import { Slider } from 'office-ui-fabric-react'
import { Trans, useTranslation } from 'react-i18next'
import TextField from 'widgets/TextField'
import Spinner, { SpinnerSize } from 'widgets/Spinner'
import { openExternal } from 'services/remote'
import { openExternal, MultisigConfig } from 'services/remote'
import { localNumberFormatter, shannonToCKBFormatter } from 'utils'
import getMultisigSignStatus from 'utils/getMultisigSignStatus'
import { Attention, Success } from 'widgets/Icons/icon'
import Dialog from 'widgets/Dialog'
import Tooltip from 'widgets/Tooltip'
Expand All @@ -30,9 +31,10 @@ interface DepositDialogProps {
isDepositing: boolean
isTxGenerated: boolean
suggestFeeRate: number
walletID: string
wallet: State.Wallet
globalAPC: number
onDepositSuccess: () => void
multisigConfig?: MultisigConfig
}

const RfcLink = React.memo(() => (
Expand All @@ -50,7 +52,7 @@ const RfcLink = React.memo(() => (
))

const DepositDialog = ({
walletID,
wallet,
balance,
show,
fee,
Expand All @@ -60,6 +62,7 @@ const DepositDialog = ({
suggestFeeRate,
globalAPC,
onDepositSuccess,
multisigConfig,
}: DepositDialogProps) => {
const [t, { language }] = useTranslation()
const disabled = !isTxGenerated
Expand All @@ -69,14 +72,22 @@ const DepositDialog = ({
show
)
const { errorMessage, maxDepositValue } = useGenerateDaoDepositTx({
walletID,
walletID: wallet.id,
isBalanceReserved,
depositValue,
suggestFeeRate,
showDepositDialog: show,
slidePercent,
multisigConfig,
})
const onConfirm = useOnDepositDialogSubmit({ onDepositSuccess, walletID })

const canSign = useMemo(() => {
if (!multisigConfig) return true
const multisigSignStatus = getMultisigSignStatus({ multisigConfig, addresses: wallet.addresses })
return multisigSignStatus.canSign
}, [multisigConfig, wallet.addresses])

const onConfirm = useOnDepositDialogSubmit({ onDepositSuccess, wallet, multisigConfig })
const onCancel = useOnDepositDialogCancel({ onCloseDepositDialog, resetDepositValue, setIsBalanceReserved })
const onSubmit = useCallback(
(e: React.FormEvent) => {
Expand Down Expand Up @@ -105,7 +116,7 @@ const DepositDialog = ({
onCancel={onCancel}
onConfirm={onConfirm}
cancelText={t('nervos-dao.cancel')}
confirmText={t('nervos-dao.proceed')}
confirmText={canSign ? t('nervos-dao.proceed') : t('nervos-dao-detail.export')}
className={styles.container}
>
{isDepositing ? (
Expand Down
35 changes: 16 additions & 19 deletions packages/neuron-ui/src/components/MultisigAddress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const MultisigAddress = () => {
},
settings: { networks = [] },
} = useGlobalState()
const { id: walletId, addresses, balance } = wallet
const { id: walletId, addresses } = wallet
const isMainnet = isMainnetUtil(networks, networkID)
const isLightClient = useMemo(
() => networks.find(n => n.id === networkID)?.type === NetworkType.Light,
Expand Down Expand Up @@ -273,23 +273,6 @@ const MultisigAddress = () => {
showPageNotice('nervos-dao.deposit-submitted')(dispatch)
}, [dispatch, daoDepositAction.closeDialog])

const MemoizedDepositDialog = useMemo(() => {
return (
<DepositDialog
balance={balance}
walletID={walletId}
show={daoDepositAction.isDialogOpen}
fee={fee}
onCloseDepositDialog={daoDepositAction.closeDialog}
isDepositing={sending}
isTxGenerated={!!send.generatedTx}
suggestFeeRate={suggestFeeRate}
globalAPC={globalAPC}
onDepositSuccess={onDepositSuccess}
/>
)
}, [balance, walletId, fee, sending, send.generatedTx, suggestFeeRate, globalAPC, daoDepositAction])

return (
<div>
<Dialog
Expand Down Expand Up @@ -594,7 +577,21 @@ const MultisigAddress = () => {
/>
) : null}

{MemoizedDepositDialog}
{daoDepositAction.depositFromMultisig && daoDepositAction.isDialogOpen ? (
<DepositDialog
balance={multisigBanlances[daoDepositAction.depositFromMultisig.fullPayload]}
wallet={wallet}
show
fee={fee}
onCloseDepositDialog={daoDepositAction.closeDialog}
isDepositing={sending}
isTxGenerated={!!send.generatedTx}
suggestFeeRate={suggestFeeRate}
globalAPC={globalAPC}
onDepositSuccess={onDepositSuccess}
multisigConfig={daoDepositAction.depositFromMultisig}
/>
) : null}

{daoWithdrawAction.withdrawFromMultisig && daoWithdrawAction.isDialogOpen ? (
<MultisigAddressNervosDAODialog
Expand Down
Loading

1 comment on commit 814420e

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

Please sign in to comment.