@@ -6,13 +6,18 @@ import {
66 useExitOnWalletChange ,
77 useGoBack ,
88 useOnWindowResize ,
9+ calculateFee ,
10+ useClearGeneratedTx ,
911} from 'utils'
10- import { useState as useGlobalState } from 'states'
12+ import appState from 'states/init/app'
13+ import { useState as useGlobalState , useDispatch , showPageNotice } from 'states'
1114import MultisigAddressCreateDialog from 'components/MultisigAddressCreateDialog'
1215import MultisigAddressInfo from 'components/MultisigAddressInfo'
1316import SendFromMultisigDialog from 'components/SendFromMultisigDialog'
1417import { MultisigConfig , changeMultisigSyncStatus , openExternal } from 'services/remote'
1518import ApproveMultisigTxDialog from 'components/ApproveMultisigTxDialog'
19+ import DepositDialog from 'components/DepositDialog'
20+ import MultisigAddressNervosDAODialog from 'components/MultisigAddressNervosDAODialog'
1621import Dialog from 'widgets/Dialog'
1722import Table from 'widgets/Table'
1823import Tooltip from 'widgets/Tooltip'
@@ -37,9 +42,11 @@ import AttentionCloseDialog from 'widgets/Icons/Attention.png'
3742import { HIDE_BALANCE , NetworkType } from 'utils/const'
3843import { onEnter } from 'utils/inputDevice'
3944import getMultisigSignStatus from 'utils/getMultisigSignStatus'
45+ import useGetCountDownAndFeeRateStats from 'utils/hooks/useGetCountDownAndFeeRateStats'
4046import Button from 'widgets/Button'
4147import SetStartBlockNumberDialog from 'components/SetStartBlockNumberDialog'
4248import { type TFunction } from 'i18next'
49+ import hooks from 'components/NervosDAO/hooks'
4350import {
4451 useSearch ,
4552 useConfigManage ,
@@ -97,14 +104,19 @@ const MultisigAddress = () => {
97104 const [ t ] = useTranslation ( )
98105 useExitOnWalletChange ( )
99106 const {
100- wallet : { id : walletId , addresses } ,
107+ app : {
108+ send = appState . send ,
109+ loadings : { sending = false } ,
110+ } ,
111+ wallet,
101112 chain : {
102- syncState : { bestKnownBlockNumber } ,
113+ syncState : { bestKnownBlockNumber, bestKnownBlockTimestamp } ,
103114 networkID,
104115 connectionStatus,
105116 } ,
106117 settings : { networks = [ ] } ,
107118 } = useGlobalState ( )
119+ const { id : walletId , addresses, balance } = wallet
108120 const isMainnet = isMainnetUtil ( networks , networkID )
109121 const isLightClient = useMemo (
110122 ( ) => networks . find ( n => n . id === networkID ) ?. type === NetworkType . Light ,
@@ -134,6 +146,11 @@ const MultisigAddress = () => {
134146 deleteConfigById,
135147 } )
136148 const [ showDeleteDialog , setShowDeleteDialog ] = useState ( false )
149+ const { suggestFeeRate } = useGetCountDownAndFeeRateStats ( )
150+ const clearGeneratedTx = useClearGeneratedTx ( )
151+ const dispatch = useDispatch ( )
152+ const [ globalAPC , setGlobalAPC ] = useState ( 0 )
153+ const [ genesisBlockTimestamp , setGenesisBlockTimestamp ] = useState < number | undefined > ( undefined )
137154
138155 const onClickItem = useCallback (
139156 ( multisigConfig : MultisigConfig ) => ( e : React . SyntheticEvent < HTMLButtonElement > ) => {
@@ -237,6 +254,42 @@ const MultisigAddress = () => {
237254 } , [ updateTipPosition ] )
238255 useOnWindowResize ( updateTipPosition )
239256
257+ const genesisBlockHash = useMemo ( ( ) => networks . find ( v => v . id === networkID ) ?. genesisHash , [ networkID , networks ] )
258+ hooks . useInitData ( {
259+ clearGeneratedTx,
260+ dispatch,
261+ wallet,
262+ setGenesisBlockTimestamp,
263+ genesisBlockHash,
264+ } )
265+ hooks . useUpdateGlobalAPC ( { bestKnownBlockTimestamp, genesisBlockTimestamp, setGlobalAPC } )
266+
267+ const fee = `${ shannonToCKBFormatter (
268+ send . generatedTx ? send . generatedTx . fee || calculateFee ( send . generatedTx ) : '0'
269+ ) } CKB`
270+
271+ const onDepositSuccess = useCallback ( ( ) => {
272+ daoDepositAction . closeDialog ( )
273+ showPageNotice ( 'nervos-dao.deposit-submitted' ) ( dispatch )
274+ } , [ dispatch , daoDepositAction . closeDialog ] )
275+
276+ const MemoizedDepositDialog = useMemo ( ( ) => {
277+ return (
278+ < DepositDialog
279+ balance = { balance }
280+ walletID = { walletId }
281+ show = { daoDepositAction . isDialogOpen }
282+ fee = { fee }
283+ onCloseDepositDialog = { daoDepositAction . closeDialog }
284+ isDepositing = { sending }
285+ isTxGenerated = { ! ! send . generatedTx }
286+ suggestFeeRate = { suggestFeeRate }
287+ globalAPC = { globalAPC }
288+ onDepositSuccess = { onDepositSuccess }
289+ />
290+ )
291+ } , [ balance , walletId , fee , sending , send . generatedTx , suggestFeeRate , globalAPC , daoDepositAction ] )
292+
240293 return (
241294 < div >
242295 < Dialog
@@ -541,19 +594,12 @@ const MultisigAddress = () => {
541594 />
542595 ) : null }
543596
544- { daoDepositAction . sendFromMultisig && daoDepositAction . isDialogOpen ? (
545- < SendFromMultisigDialog
546- closeDialog = { daoDepositAction . closeDialog }
547- multisigConfig = { daoDepositAction . sendFromMultisig }
548- balance = { sendTotalBalance }
549- />
550- ) : null }
597+ { MemoizedDepositDialog }
551598
552- { daoWithdrawAction . sendFromMultisig && daoWithdrawAction . isDialogOpen ? (
553- < SendFromMultisigDialog
599+ { daoWithdrawAction . withdrawFromMultisig && daoWithdrawAction . isDialogOpen ? (
600+ < MultisigAddressNervosDAODialog
554601 closeDialog = { daoWithdrawAction . closeDialog }
555- multisigConfig = { daoWithdrawAction . sendFromMultisig }
556- balance = { sendTotalBalance }
602+ multisigConfig = { daoWithdrawAction . withdrawFromMultisig }
557603 />
558604 ) : null }
559605 </ div >
0 commit comments