Consensys / ethereum-developer-tools-list

A guide to available tools and platforms for developing on Ethereum.
5.36k stars 1.33k forks source link

Metamask - Incorrect approval behaviour #402

Open naandonov opened 1 year ago

naandonov commented 1 year ago

Hello, I am developing a mobile dapp, that has a use case in which users can send crypto from one wallet to another. Let's say wallet A has 100 DAIs in it and wallet B doesn't have any assets. The problem is in regards to the usage of ERC20's approve method and in general upon trying to do an approval before the actual send transaction. I have observed the following behaviour:

1) From the mobile dapp the user tries to send 5 DAI from wallet A to wallet B, metamask gets open and the approval pop-up appears, prompting the user to approve the transfer with preselected amount 5 in the prompt. The user taps on approve and the approval succeeds without any issues.

2) From the mobile dapp the user tries to send 5 DAI from wallet A to wallet B, metamask gets open and the approval pop-up appears, prompting the user to approve the transfer with preselected amount 5 in the prompt. The user replaces the amount of "5" as they enter "100" in the field. Then they tap on approve and the approval fails, because the approve transaction has ran out of gas.

3) From the mobile dapp the user tries to send 100 DAI from wallet A to wallet B, metamask gets open and the approval pop-up appears, prompting the user to approve the transfer with preselected amount 100 in the prompt (as this is their max). The user taps on approve and the approval succeeds without any issues.

I believe that prior to showing the approval prompt in metamask the gas limit used for transaction is estimated based on the initial input and as the input is change the gas limit may be exceeded. I have tried entering fixed gas limit amounts, but without avail as metamask overrides my values. I believe that this is an issue as the behaviour, as described in scenario 2), shouldn't be happening for the end users