Doesn't Return from Metamask? #160
Unanswered
jrkosinski
asked this question in
Q&A
Replies: 4 comments 5 replies
-
Hey @jrkosinski, What version of MetaMask do you have? I have v7.14.0 and it redirects back to the modal sample app. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Gleb,
Thanks for replying!
I'm also using 7.14.0 on Android v10. I will attach the code that I'm
using; it's almost identical to the sample with small changes, but I don't
think that the changes could have any bearing on the outcome (I removed
some of the graphical elements that I didn't need).
Thanks,
John
On Fri, Feb 16, 2024 at 3:20 PM Gleb Skibitsky ***@***.***> wrote:
Hey @jrkosinski <https://github.com/jrkosinski>,
What version of MetaMask do you have? I have v7.14.0 and it redirects back
to the modal sample app.
—
Reply to this email directly, view it on GitHub
<#160 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AATG4NQW4IAOQAHAYEJSBYLYT4JEDAVCNFSM6AAAAABDLPDLE6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DIOBZGQZTM>
.
You are receiving this because you were mentioned.Message ID:
<WalletConnect/WalletConnectUnity/repo-discussions/160/comments/8489436@
github.com>
using System.Collections.Generic;
using System;
using TMPro;
using System.Linq;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Scripting;
using UnityEngine.UI;
using WalletConnectSharp.Common.Model.Errors;
using WalletConnectSharp.Sign.Models;
using WalletConnectSharp.Sign.Models.Engine;
using WalletConnectSharp.Common.Utils;
using WalletConnectSharp.Network.Models;
using WalletConnectUnity.Core;
using WalletConnectUnity.Modal;
using UnityEngine.EventSystems;
using WalletConnectUnity.UI;
public class ClickEvent : MonoBehaviour
{
[Space, SerializeField] private NetworkListItem _networkListItemPrefab;
[Space, SerializeField] private Transform _networkListContainer;
[SerializeField] private GameObject _networkList;
private readonly HashSet<Chain> _selectedChains = new();
private bool connected = false;
private bool initialized = false;
private string walletAddress;
NetworkManager networkManager;
// Start is called before the first frame update
void Start()
{
Application.targetFrameRate = Screen.currentResolution.refreshRate;
EnableNetworksList();
networkManager = gameObject.AddComponent(typeof(NetworkManager)) as NetworkManager;
// When WalletConnectModal is ready, enable buttons and subscribe to other events.
// WalletConnectModal.SignClient can be null if WalletConnectModal is not ready.
WalletConnectModal.Ready += (sender, args) =>
{
Debug.Log("WalletConnectModal.Ready!");
// SessionResumed is true if Modal resumed session from storage
if (args.SessionResumed)
{
Debug.Log("Session Resumeed!");
//EnableDappButtons();
}
else
{
EnableNetworksList();
}
// Invoked after wallet connected
WalletConnect.Instance.ActiveSessionChanged += (_, @struct) =>
{
Debug.Log("WalletConnectModal.Instance.ActiveSessionChanged!");
if ***@***.***))
return;
Debug.Log($"[WalletConnectModalSample] Session connected. Topic: ***@***.***}");
//EnableDappButtons();
};
// Invoked after wallet disconnected
WalletConnect.Instance.ActiveSessionChanged += (_, _) =>
{
Debug.Log($"[WalletConnectModalSample] event ActiveSessionChanged.");
EnableNetworksList();
};
};
}
private void EnableNetworksList()
{
Debug.Log("EnableNetworksList");
// _networkList.SetActive(true);
//if (_networkListContainer.childCount == 0)
if (!initialized)
{
initialized = true;
var chains = Chain.All;
_selectedChains.Add(chains[0]);
Debug.Log("A network item from list: " + chains[0].FullChainId);
for (int n = 0; n < chains.Length; n++)
{
//var item = Instantiate(_networkListItemPrefab, _networkListContainer);
//item.Initialize(chain, OnNetworkSelected);
if (/*_selectedChains.Count == 0 &&*/ n < chains.Length)
{
//Debug.Log("A network item from list: " + chains[n].FullChainId);
}
}
}
}
private void OnNetworkSelected(Chain chain, bool selected)
{
Debug.Log("OnNetworkSelected");
if (selected)
{
Debug.Log("Network selected: " + chain.ChainId);
_selectedChains.Add(chain);
}
else
_selectedChains.Remove(chain);
}
// Update is called once per frame
void Update()
{
}
public void Connect_Click()
{
try
{
if (WalletConnectModal.IsReady)
{
EnableNetworksList();
WalletConnect.Instance.ActiveSessionChanged += (_, @struct) =>
{
Debug.Log("WalletConnectModal.Instance.ActiveSessionChanged? Connected?");
connected = true;
};
Debug.Log("CONNECTING");
Connect();
var session = WalletConnect.Instance.ActiveSession;
var sessionNamespace = session.Namespaces;
/*
Debug.Log("session: " + session.Acknowledged.Value);
Debug.Log("sessionNamespace: " + sessionNamespace.ToString());
var chainId = WalletConnect.Instance.ActiveSession.CurrentAddress(sessionNamespace.Keys.FirstOrDefault()).ChainId;
Debug.Log("chainId: " + chainId);
*/
this.walletAddress = WalletConnect.Instance.ActiveSession.CurrentAddress(sessionNamespace.Keys.FirstOrDefault()).Address;
Debug.Log("address: " + this.walletAddress);
this.connected = true;
Debug.Log("IsInitialized: " + WalletConnect.Instance.IsInitialized);
Debug.Log("IsConnected: " + WalletConnect.Instance.IsConnected);
RequestSign();
}
else
{
Debug.Log("WalletConnectModal not ready");
WalletConnectModal.InitializeAsync();
}
}
catch(Exception e)
{
Debug.LogError(e);
}
}
public async void RequestSign()
{
Debug.Log("RequestSign()");
try
{
var session = WalletConnect.Instance.ActiveSession;
var sessionNamespace = session.Namespaces;
var address = this.walletAddress; // WalletConnect.Instance.ActiveSession.CurrentAddress(sessionNamespace.Keys.FirstOrDefault()).Address;
var data = new PersonalSign("Hello world", address);
var instance = WalletConnect.Instance;
Debug.Log(_selectedChains.Count.ToString() + " SELECTED CHAINS");
var result = await instance.RequestAsync<PersonalSign, string>(data); //THIS CALL IS FAILING
Debug.Log( $"Response: {result}");
AccountsRequest request = new AccountsRequest(this.networkManager);
request.RegisterAccountEvm(address);
}
catch (WalletConnectException e)
{
Debug.Log($"Personal Sign Request Error: {e.Message}");
Debug.Log($"[WalletConnectModalSample] Personal Sign Error: {e.Message}");
}
}
public async void Sign_Click()
{
RequestSign();
/*
Debug.Log("[WalletConnectModalSample] OnPersonalSignButton");
var session = WalletConnect.Instance.ActiveSession;
var sessionNamespace = session.Namespaces;
var address = this.walletAddress; // WalletConnect.Instance.ActiveSession.CurrentAddress(sessionNamespace.Keys.FirstOrDefault()).Address;
var data = new PersonalSign("Hello world!", address);
try
{
var result = await WalletConnect.Instance.RequestAsync<PersonalSign, string>(data);
Notification.ShowMessage(
$"Received response.\nThis app cannot validate signatures yet.\n\nResponse: {result}");
}
catch (WalletConnectException e)
{
Notification.ShowMessage($"Personal Sign Request Error: {e.Message}");
Debug.Log($"[WalletConnectModalSample] Personal Sign Error: {e.Message}");
}
*/
}
public void Connect()
{
Debug.Log("Connect");
var options = new WalletConnectModalOptions
{
ConnectOptions = BuildConnectOptions()
};
WalletConnectModal.Open(options);
}
private ConnectOptions BuildConnectOptions()
{
Debug.Log("BuildConnectOptions");
var requiredNamespaces = new RequiredNamespaces();
if (_selectedChains.Any(c => c.ChainNamespace == Chain.EvmNamespace))
{
var eipChains = _selectedChains.Where(c => c.ChainNamespace == Chain.EvmNamespace);
// TODO: make configurable
var methods = new[]
{
"eth_sendTransaction",
"personal_sign",
};
var events = new[]
{
"chainChanged", "accountsChanged"
};
var chainIds = eipChains.Select(c => c.FullChainId).ToArray();
requiredNamespaces.Add(Chain.EvmNamespace, new ProposedNamespace()
{
Chains = chainIds,
Events = events,
Methods = methods
});
}
else
{
throw new Exception("No EVM chains selected.");
}
return new ConnectOptions
{
RequiredNamespaces = requiredNamespaces
};
}
}
public class SuiNamespace : ProposedNamespace
{
public SuiNamespace() : base() { }
}
public class Chain
{
private static Dictionary<int, string> Eip155NetworkImageIds { get; } = new()
{
// Ethereum
{ 1, "692ed6ba-e569-459a-556a-776476829e00" },
// Arbitrum
{ 42161, "600a9a04-c1b9-42ca-6785-9b4b6ff85200" },
// Avalanche
{ 43114, "30c46e53-e989-45fb-4549-be3bd4eb3b00" },
// Binance Smart Chain
{ 56, "93564157-2e8e-4ce7-81df-b264dbee9b00" },
// Fantom
{ 250, "06b26297-fe0c-4733-5d6b-ffa5498aac00" },
// Optimism
{ 10, "ab9c186a-c52f-464b-2906-ca59d760a400" },
// Polygon
{ 137, "41d04d42-da3b-4453-8506-668cc0727900" },
// Gnosis
{ 100, "02b53f6a-e3d4-479e-1cb4-21178987d100" },
// EVMos
{ 9001, "f926ff41-260d-4028-635e-91913fc28e00" },
// ZkSync
{ 324, "b310f07f-4ef7-49f3-7073-2a0a39685800" },
// Filecoin
{ 314, "5a73b3dd-af74-424e-cae0-0de859ee9400" },
// Iotx
{ 4689, "34e68754-e536-40da-c153-6ef2e7188a00" },
// Metis
{ 1088, "3897a66d-40b9-4833-162f-a2c90531c900" },
// Moonbeam
{ 1284, "161038da-44ae-4ec7-1208-0ea569454b00" },
// Moonriver
{ 1285, "f1d73bb6-5450-4e18-38f7-fb6484264a00" },
// Zora
{ 7777777, "845c60df-d429-4991-e687-91ae45791600" },
// Celo
{ 42220, "ab781bbc-ccc6-418d-d32d-789b15da1f00" },
// Base
{ 8453, "7289c336-3981-4081-c5f4-efc26ac64a00" },
// Aurora
{ 1313161554, "3ff73439-a619-4894-9262-4470c773a100" }
};
public static readonly string EvmNamespace = "eip155";
public static readonly Chain
Ethereum = new(EvmNamespace, "1", nameof(Ethereum), new Color(0.38f, 0.49f, 0.92f));
public static readonly Chain Optimism = new(EvmNamespace, "10", nameof(Optimism), new Color(0.91f, 0f, 0f));
public static readonly Chain
xDai = new(EvmNamespace, "100", nameof(xDai), new Color(0.28f, 0.66f, 0.65f));
public static readonly Chain Polygon = new(EvmNamespace, "137", nameof(Polygon), new Color(0.51f, 0.28f, 0.9f));
public static readonly Chain Arbitrum =
new(EvmNamespace, "42161", nameof(Arbitrum), new Color(0.17f, 0.22f, 0.29f));
public static readonly Chain Celo = new(EvmNamespace, "42220", nameof(Celo),
new Color(0.21f, 0.82f, 0.5f));
public static readonly Chain EthereumGoerli =
new(EvmNamespace, "5", "Ethereum Goerli", new Color(0.38f, 0.49f, 0.92f), true, Eip155NetworkImageIds[1]);
public static readonly Chain OptimismGoerli =
new(EvmNamespace, "420", "Optimism Goerli", new Color(0.91f, 0f, 0f), true, Eip155NetworkImageIds[10]);
public static readonly Chain ArbitrumRinkeby =
new(EvmNamespace, "421611", "Arbitrum Rinkeby", new Color(0.17f, 0.22f, 0.29f), true,
Eip155NetworkImageIds[42161]);
public static readonly Chain CeloAlfajores =
new(EvmNamespace, "44787", "Celo Alfajores", new Color(0.21f, 0.82f, 0.5f), true,
Eip155NetworkImageIds[42220]);
public static readonly Chain Base =
new(EvmNamespace, "8453", "Base", new Color(0.28f, 0.39f, 0.98f), true);
public static readonly Chain[] All =
{
Ethereum,
EthereumGoerli,
Optimism,
OptimismGoerli,
Polygon,
Arbitrum,
ArbitrumRinkeby,
Celo,
CeloAlfajores,
xDai,
Base
};
public Chain(string chainNamespace,
string chainId,
string name,
Color primaryColor,
bool testnet = false,
string overrideImageId = null)
{
ChainNamespace = chainNamespace;
Name = name;
PrimaryColor = primaryColor;
ChainId = chainId;
IsTestnet = testnet;
try
{
ImageId = overrideImageId ?? Eip155NetworkImageIds[int.Parse(chainId)];
}
catch (KeyNotFoundException e)
{
Debug.LogError($"[WalletConnectUnity] Chain image not found for chain {chainId}");
}
}
public Color PrimaryColor { get; }
public string ChainId { get; }
public string Name { get; }
public string IconUrl => $"https://api.web3modal.com/public/getAssetImage/{ImageId}";
public string ChainNamespace { get; }
public bool IsTestnet { get; }
public string FullChainId => $"{ChainNamespace}:{ChainId}";
public string ImageId { get; }
}
[RpcMethod("personal_sign")]
[RpcRequestOptions(Clock.ONE_MINUTE, 99998)]
public class PersonalSign : List<string>
{
public PersonalSign(string hexUtf8, string account) : base(new[] { hexUtf8, account })
{
}
[Preserve]
public PersonalSign()
{
}
}
public class Notification : MonoBehaviour
{
[SerializeField] private GameObject _root;
[SerializeField] private TMP_Text _messageText;
public static Notification Instance
{
get
{
if (_instance == null)
{
_instance = FindObjectOfType<Notification>(true);
}
return _instance;
}
}
private static Notification _instance;
public static void ShowMessage(string message)
{
Instance.Show(message);
}
public void Show(string message)
{
Debug.Log(message);
_messageText.text = message;
_root.SetActive(true);
}
public void OnButtonHide()
{
_root.SetActive(false);
}
}
public class NetworkListItem : MonoBehaviour, IPointerClickHandler
{
[SerializeField] private Outline _outline;
[SerializeField] private Image _iconImage;
[SerializeField] private TMP_Text _nameText;
public event Action<Chain, bool> Selected;
private Chain _chain;
private bool _selected;
public void Initialize(Chain chain, Action<Chain, bool> onSelected)
{
_chain = chain;
_nameText.text = chain.Name;
_outline.effectColor = chain.PrimaryColor;
Selected += onSelected;
}
public void OnPointerClick(PointerEventData eventData)
{
_selected = !_selected;
UpdateSelectedState();
Selected?.Invoke(_chain, _selected);
}
private void UpdateSelectedState()
{
_outline.enabled = _selected;
}
}
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Gleb,
Oh, I don't think I did that, I'll try it.
Thanks!
John
…On Mon, Feb 19, 2024 at 5:51 PM Gleb Skibitsky ***@***.***> wrote:
In Unity, did you add URL schema of your app to AndroidManifest (unity
docs <https://docs.unity3d.com/Manual/deep-linking-android.html>)?
This repository has a Unity project under project/modal-sample branch
with configured AndroidManifest
<https://github.com/WalletConnect/WalletConnectUnity/blob/project/modal-sample/Assets/Plugins/Android/AndroidManifest.xml#L18>
.
After specifying url in the manifest, you will also need to add it to the
Redirect metadata of WalletConnect project config scriptable object:
***@***.*** (view on web)
<https://github.com/WalletConnect/WalletConnectUnity/assets/15127974/b59d1b6d-9e1a-4e30-8f85-491ec099bcce>
—
Reply to this email directly, view it on GitHub
<#160 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AATG4NTWFR7BPHMRPGKHKRLYUMVDVAVCNFSM6AAAAABDLPDLE6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DKMJVG43TS>
.
You are receiving this because you were mentioned.Message ID:
<WalletConnect/WalletConnectUnity/repo-discussions/160/comments/8515779@
github.com>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi Gleb,
I added a deeplink to the Android manifest, following all the steps in the
Unity docs that you linked.
I also enabled Custom Main Manifest in settings.
[image: image.png]
Then I referenced that deeplink in the WalletConnect Resources settings:
[image: image.png]
The problem though, I think might be something else. I still get the same
result as before. When the app opens Metamask, there is no Connect button.
The screen just looks like this:
[image: 428122564_387335643898099_7915445661322535307_n.jpg]
Note the lack of any "Connect" button or any context about what the user
might want to do. It's just the standard home screen.
With TrustWallet though, it does show a Connect button. It always has; this
works the same both before & after I added the deep-linking. It is
seemingly unaffected by the deep-linking changes. Any thoughts?
Thanks,
John
On Mon, Feb 19, 2024 at 8:14 PM John Kosinski ***@***.***>
wrote:
… Gleb,
Oh, I don't think I did that, I'll try it.
Thanks!
John
On Mon, Feb 19, 2024 at 5:51 PM Gleb Skibitsky ***@***.***>
wrote:
> In Unity, did you add URL schema of your app to AndroidManifest (unity
> docs <https://docs.unity3d.com/Manual/deep-linking-android.html>)?
>
> This repository has a Unity project under project/modal-sample branch
> with configured AndroidManifest
> <https://github.com/WalletConnect/WalletConnectUnity/blob/project/modal-sample/Assets/Plugins/Android/AndroidManifest.xml#L18>
> .
>
> After specifying url in the manifest, you will also need to add it to the
> Redirect metadata of WalletConnect project config scriptable object:
> ***@***.*** (view on web)
> <https://github.com/WalletConnect/WalletConnectUnity/assets/15127974/b59d1b6d-9e1a-4e30-8f85-491ec099bcce>
>
> —
> Reply to this email directly, view it on GitHub
> <#160 (reply in thread)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AATG4NTWFR7BPHMRPGKHKRLYUMVDVAVCNFSM6AAAAABDLPDLE6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DKMJVG43TS>
> .
> You are receiving this because you were mentioned.Message ID:
> <WalletConnect/WalletConnectUnity/repo-discussions/160/comments/8515779@
> github.com>
>
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm running the WalletConnectModal sample from the repo, in Android (Unity). The Connect function, when I connect to Trust Wallet or Rainbow, returns back to my application after connecting. However, for Metamask, it doesn't. The behavior for Metamask (only) is like this:
Is there something I'm missing? Again, this is just the basic WalletConnectModal sample.
Beta Was this translation helpful? Give feedback.
All reactions