Skip to content

Commit

Permalink
Merge pull request #38 from near-ndc/fix-storage-deposit
Browse files Browse the repository at this point in the history
Fix storage deposit
  • Loading branch information
Megha-Dev-19 authored Feb 13, 2024
2 parents f9bfa26 + 0099ff8 commit a1a3fb2
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions apps/astraplusplus/widget/DAO/Proposal/Create/Transfer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ State.init({
tokenAddress: state.tokenAddress || "",
error: state.error,
description: state.description,
notificationsData: {}
notificationsData: {},
ftMetadata: null,
storage: undefined
});

function isNearAddress(address) {
Expand Down Expand Up @@ -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)
Expand All @@ -85,13 +86,48 @@ 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);
}

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,
Expand Down

0 comments on commit a1a3fb2

Please sign in to comment.