In Trade.tsx, our code currently calls approve() before every single trade.
Improvement :
- Add a check to see if the current allowance is already greater than or equal to the amountIn. If it is, skip the approve transaction. This saves the user gas and time.
const currentAllowance = await tokenInContract.allowance(await signer.getAddress(), dex.address);
if (currentAllowance < trade.amountIn) {
const tx = await tokenInContract.approve(dex.address, amountInMax);
await tx.wait();
}
In Trade.tsx, our code currently calls approve() before every single trade.
Improvement :