-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finalize implementation for send assets action template
- Loading branch information
Showing
3 changed files
with
69 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useTranslation } from "react-i18next"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { ModalType } from "../../components/ui/modals/ModalProvider"; | ||
import { SendAssetsData } from "../../components/ui/modals/SendAssetsModal"; | ||
import { useDecentModal } from "../../components/ui/modals/useDecentModal"; | ||
import { DAO_ROUTES } from "../../constants/routes"; | ||
import { useFractal } from "../../providers/App/AppProvider"; | ||
import { useNetworkConfigStore } from "../../providers/NetworkConfig/useNetworkConfigStore"; | ||
import { useProposalActionsStore } from "../../store/actions/useProposalActionsStore"; | ||
import { useDaoInfoStore } from "../../store/daoInfo/useDaoInfoStore"; | ||
import { ProposalActionType } from "../../types/proposalBuilder"; | ||
import { isNativeAsset, prepareSendAssetsActionData } from "../../utils/dao/prepareSendAssetsActionData"; | ||
|
||
export default function useSendAssetsActionModal() { | ||
const { safe } = useDaoInfoStore(); | ||
const { addressPrefix } = useNetworkConfigStore(); | ||
const { t } = useTranslation(['modals']); | ||
const { addAction } = useProposalActionsStore(); | ||
const navigate = useNavigate(); | ||
const { governance: { isAzorius } } = useFractal(); | ||
const sendAssetsAction = async (sendAssetsData: SendAssetsData) => { | ||
if (!safe?.address) { | ||
return; | ||
} | ||
const isNative = isNativeAsset(sendAssetsData.asset); | ||
const transactionData = prepareSendAssetsActionData({ | ||
transferAmount: sendAssetsData.transferAmount, | ||
asset: sendAssetsData.asset, | ||
destinationAddress: sendAssetsData.destinationAddress, | ||
}); | ||
addAction({ | ||
actionType: ProposalActionType.TRANSFER, | ||
content: <></>, | ||
transactions: [ | ||
{ | ||
targetAddress: transactionData.calldata, | ||
ethValue: { | ||
bigintValue: transactionData.value, | ||
value: transactionData.value.toString(), | ||
}, | ||
functionName: isNative ? '' : 'transfer', | ||
parameters: isNative | ||
? [] | ||
: [ | ||
{ signature: 'address', value: sendAssetsData.destinationAddress }, | ||
{ signature: 'uint256', value: sendAssetsData.transferAmount.toString() }, | ||
], | ||
}, | ||
], | ||
}); | ||
navigate(DAO_ROUTES.proposalWithActionsNew.relative(addressPrefix, safe.address)); | ||
}; | ||
|
||
const openSendAssetsModal = useDecentModal(ModalType.SEND_ASSETS, { | ||
onSubmit: sendAssetsAction, | ||
submitButtonText: t('submitProposal', { ns: 'modals' }), | ||
showNonceInput: !isAzorius, | ||
}); | ||
|
||
return { | ||
openSendAssetsModal, | ||
}; | ||
} |
This file contains 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
This file contains 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