I am trying to implement collect all button where user will be able to harvest all profit from farms/pools so that he will not need to go and click every harvest button manually,and it works fine. But when i click collect all button then i need to approve every transaction manually in my metamask. I tried to solve this problem using web3BatchRequest. I am working on react my component where is collect all button
const handleHarvestAll = () => {
ref.current.getCollectAll();
};
and my component where arepools/farms
const Web3 = require("web3");
const web3 = new Web3(Web3.givenProvider || "ws://localhost:8800");
const batch = new web3.BatchRequest();
const onHarvest = (pid, chain, contract) => {actions[farmsEffects.actionTypes.FARMS_REWARD_HARVEST_INVOKED]({ pid, from: userWallet, chain, cheff: contract }); };
useImperativeHandle(ref, () => ({
getCollectAll() {
data.map((index) => {
batch.add(onHarvest(index.pid, state.chain, index.cheffAddress));
});
console.log("batch content: ", batch);
batch.execute();
},
}));
and my actions:
try {
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: `0x${chainId.toString(16)}` }],
});
const params = dataHelper.getHarvestParams(pid, from, cheff);
const result = await window.ethereum.request({ method: 'eth_sendTransaction', params: [params] });
actions[actionTypes.FARMS_TX_SUCCEEDED]({ hash: result, from });
updateState({ path: 'currentTxStatus', value: 1 });
But nothing happened and my request are undefined and i still in my metamask need to approve every transaction individually and getting Uncaught TypeError: Cannot read properties of undefined (reading 'method')
error? Is this even a possible? If not what you guys suggest me to try next?