[Bug]: Exception Clears Wallet Addresses
Closed this issue · 2 comments
WoodsFiend commented
SDK
Unity
Provide environment information
Unity version 2022.3
Unity Editor
Windows OS
MetaMask SDK Version
2.0.0
MetaMask Mobile app Version
N/A
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
When an exception is thrown inside a function listening to Wallet.AccountChanged the SelectedAddress, ConnectedAddress, and ConnectedAddresses are cleared. This causes all contract interaction functionality to fail.
Expected Behavior
Exceptions inside listeners should not clear all addresses, or it should at least throw a warning/error internally so that it is know to have done so.
Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster
No response
To Reproduce
public class MetaMaskExceptionTest: MonoBehaviour
{
protected void Start()
{
if (MetaMaskSDK.Instance != null)
{
//Add listeners
MetaMaskSDK.Instance.Initialize();
MetaMaskSDK.Instance.Wallet.AccountChanged += OnMetamaskAccountChanged;
}
}
private void OnMetamaskAccountChanged(object sender, EventArgs e)
{
// Logs the expected wallet address that connected
Debug.Log("Wallet Address: " + MetaMaskSDK.Instance.Wallet.SelectedAddress);
throw new Exception("Test Exception");
// The SelectedAddress, ConnectedAddress, and ConnectedAddresses are now cleared
// Contract interactions will now fail if they use the above params (ex. ERC20.Allowance)
}
private void Update()
{
if(MetaMaskSDK.Instance != null && MetaMaskSDK.Instance.Wallet != null)
{
Debug.Log("Selected Address: " + MetaMaskSDK.Instance.Wallet.SelectedAddress);
Debug.Log("Connected Address: " + MetaMaskSDK.Instance.Wallet.ConnectedAddress);
Debug.Log("Connected Addresses Count: " + MetaMaskSDK.Instance.Wallet.ConnectedAddresses.Length);
}
}
}
- Connect your wallet with the above script included
- Wallet Address logs as expected before exception
- SelectedAddress, ConnectedAddress, ConnectedAddresses are empty after the exception
christopherferreira9 commented
Hi @WoodsFiend this has been fixed on the upcoming release that should be released soon.
christopherferreira9 commented
Hi! This should be fixed with the latest release 2.0.1
.