I'm building a staking function and hitting the following error after giving permission to access my token:
"MetaMask - RPC Error: Cannot set properties of undefined (setting 'loadingDefaults')"
Staking function Solidity contract:
// Staking function
function depositTokens(uint _amount) public {
require(_amount > 0, 'Amount has to be > 0');
// Transfer tether tokens to this contract
tether.transferFrom(msg.sender, address(this), _amount);
// Update Staking balance
stakingBalance[msg.sender] = stakingBalance[msg.sender] + _amount;
if(!hasStaked[msg.sender]) {
stakers.push(msg.sender);
}
// Update Staking balance
isStaking[msg.sender] = true;
hasStaked[msg.sender] = true;
}
Staking Frontend
stakeTokens = (amount) => {
this.setState({loading: true })
this.state.tether.methods.approve(this.state.deBank._address, amount).send({from: this.state.account}).on('transactionHash', (hash) => {
this.state.deBank.methods.depositTokens(amount).send({from: this.state.account}).on('transactionHash', (hash) => {
this.setState({loading:false})
})
})
}
What is weird is that in 25-30% of the case, I get to the second approval step and the transaction goes through.
Anyone has an idea what's causing this?