Hello, I have a problem with function useWeb3Transfer().
How can i input amount as an dynamic param when i call function Confirm. I tried useState setAmount but not working.
function useWeb3Transfer just run before i setAmount.
How to input this amount from outsite in here:
amount: Moralis.Units.Token(amount, process.env.NEXT_PUBLIC_CONTRACT_ADDRESS_DECIMAL),
I have this code snippet below on what I want to achieve
const {fetch, error, isFetching} = useWeb3Transfer({
amount: Moralis.Units.Token(amount, process.env.NEXT_PUBLIC_CONTRACT_ADDRESS_DECIMAL),
receiver: receiver,
type: 'erc20',
contractAddress: process.env.NEXT_PUBLIC_CONTRACT_ADDRESS_ERC20,
});
const Confirm = async (amount, gem, gem_origin) => {
setAmount(amount);
setIsFetchingButton(true);
await Moralis.enableWeb3({
provider: 'web3Auth',
clientId: process.env.NEXT_PUBLIC_API_KEY_WEB3AUTH,
chainId: process.env.NEXT_PUBLIC_MAIN_NET_CHAINID,
rpcTarget: process.env.NEXT_PUBLIC_RPC_TARGET,
appLogo: process.env.NEXT_PUBLIC_URL + '/logo.png',
});
fetch({
onSuccess: (tx) =>
tx.wait().then(() => {
addTx(tx.hash, amount, gem, gem_origin);
setIsFetchingButton(false);
}),
onError: (error) => {
setIsFetchingButton(false);
console.log('amount', amount);
console.log(error);
toast.error('Error 🤯', {
position: toast.POSITION.BOTTOM_RIGHT,
theme: 'dark',
});
},
});
};