From 0099ff8bbbbb6b505df9ee600c84249241cff255 Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 Date: Tue, 13 Feb 2024 15:22:49 +0530 Subject: [PATCH] fix storage deposit --- .../widget/DAO/Proposal/Create/Transfer.jsx | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/apps/astraplusplus/widget/DAO/Proposal/Create/Transfer.jsx b/apps/astraplusplus/widget/DAO/Proposal/Create/Transfer.jsx index ca49fa5..880e65c 100644 --- a/apps/astraplusplus/widget/DAO/Proposal/Create/Transfer.jsx +++ b/apps/astraplusplus/widget/DAO/Proposal/Create/Transfer.jsx @@ -13,7 +13,9 @@ State.init({ tokenAddress: state.tokenAddress || "", error: state.error, description: state.description, - notificationsData: {} + notificationsData: {}, + ftMetadata: null, + storage: undefined }); function isNearAddress(address) { @@ -57,8 +59,7 @@ const handleProposal = () => { decimals: 24 }; if (state.tokenAddress !== "") { - ftMetadata = Near.view(state.tokenAddress, "ft_metadata", {}); - if (ftMetadata === null) return null; + ftMetadata = state.ftMetadata; } const amountInYocto = Big(state.amount) @@ -85,6 +86,20 @@ const handleProposal = () => { deposit: deposit } ]; + if (state.storage === null && state.tokenAddress) { + const depositInYocto = Big(0.0125) + .mul(Big(10).pow(ftMetadata.decimals)) + .toFixed(); + calls.push({ + contractName: state.tokenAddress, + methodName: "storage_deposit", + args: { + account_id: state.receiver_id + }, + gas: gas, + deposit: depositInYocto + }); + } if (state.notificationsData) { calls.push(state.notificationsData); } @@ -92,6 +107,27 @@ const handleProposal = () => { Near.call(calls); }; +useEffect(() => { + if ( + state.tokenAddress && + state.receiver_id && + isNearAddress(state.receiver_id) + ) { + Near.asyncView(state.tokenAddress, "ft_metadata", {}).then((ftMetadata) => { + State.update({ + ftMetadata + }); + }); + Near.asyncView(state.tokenAddress, "storage_balance_of", { + account_id: state.receiver_id + }).then((storage) => { + State.update({ + storage + }); + }); + } +}, [state.receiver_id, state.tokenAddress]); + const onChangeRecipient = (receiver_id) => { State.update({ receiver_id,