Last active
December 10, 2021 21:58
-
-
Save witalobenicio/769b6817a814e1fb51abadb021d9479d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function useQiProposalActions({ | |
contractId, | |
qiProposalId, | |
qiActionProposalId, | |
}) { | |
const [ | |
listProposalsControl, | |
listActionsControl, | |
listHistoricControl, | |
cancelControl, | |
revokeControl, | |
signControl, | |
resubmitControl, | |
] = useAwaitControl([ | |
listQiProposals, | |
listQiActionProposals, | |
listQiActionHistoric, | |
cancelQiProposal, | |
revokeCancelQiProposal, | |
signQiContract, | |
forceResubmitPaymentQiContract, | |
]); | |
const proposals = listProposalsControl.result(contractId); | |
const actions = listActionsControl.result(qiProposalId); | |
const historic = listHistoricControl.result(qiActionProposalId); | |
const proposalsLoading = listProposalsControl.isRunning(contractId); | |
const actionsLoading = listActionsControl.isRunning(qiProposalId); | |
const historicLoading = listHistoricControl.isRunning(qiActionProposalId); | |
const cancelLoading = cancelControl.isRunning(qiProposalId); | |
const revokeLoading = revokeControl.isRunning(qiProposalId); | |
const signLoading = signControl.isRunning(qiProposalId); | |
const resubmitLoading = resubmitControl.isRunning(qiProposalId); | |
const getProposals = useCallback(() => { | |
if (contractId) { | |
listProposalsControl.start({ contractId }, { actionId: contractId }); | |
} | |
}, [listProposalsControl]); | |
const getActions = useCallback(() => { | |
if (qiProposalId && (!actions || !actions.length)) { | |
listActionsControl.start({ qiProposalId }, { actionId: qiProposalId }); | |
} | |
}, [listActionsControl]); | |
const getHistoric = useCallback(() => { | |
if (qiActionProposalId && (!historic || !historic.length)) { | |
listHistoricControl.start( | |
{ qiActionProposalId }, | |
{ actionId: qiActionProposalId }, | |
); | |
} | |
}, [listHistoricControl]); | |
useDidUpdateEffect(() => { | |
if (cancelControl.isSuccessful(qiProposalId)) { | |
getProposals(); | |
} | |
}, [cancelQiProposal]); | |
useDidUpdateEffect(() => { | |
if (revokeControl.isSuccessful(qiProposalId)) { | |
getProposals(); | |
} | |
}, [revokeCancelQiProposal]); | |
useDidUpdateEffect(() => { | |
if (signControl.isSuccessful(qiProposalId)) { | |
getProposals(); | |
} | |
}, [signControl]); | |
useDidUpdateEffect(() => { | |
if (resubmitControl.isSuccessful(qiProposalId)) { | |
getProposals(); | |
} | |
}, [resubmitControl]); | |
return { | |
getProposals, | |
getActions, | |
getHistoric, | |
proposals, | |
actions, | |
historic, | |
proposalsLoading, | |
actionsLoading, | |
historicLoading, | |
isProposalLoading: | |
proposalsLoading || | |
cancelLoading || | |
revokeLoading || | |
signLoading || | |
resubmitLoading, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment