Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you add a custom chain on mobile ? #23

Open
talha-trili opened this issue Nov 25, 2024 · 12 comments
Open

Can you add a custom chain on mobile ? #23

talha-trili opened this issue Nov 25, 2024 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@talha-trili
Copy link

This is for mobile platforms.

Is it possible to add custom chains ?

Below is an example implementation and it doesnt add custom chains.
On webgl however, it adds custom chains and overall handles network switches better.

var supportedChains = new List<Chain>
                      {
	                      customChain1,
	                      customChain2,
                      };

appKitConfig.supportedChains = supportedChains.ToArray();

await AppKit.InitializeAsync(appKitConfig);
await AppKit.ConnectorController.TryResumeSessionAsync();
AppKit.AccountConnected    += OnAccountConnected;
AppKit.AccountDisconnected += OnAccountDisconnected;
AppKit.AccountChanged      += OnAccountChanged;
@skibitsky
Copy link
Member

Hello,

The chains you set in supportedChains array should be available across all platforms. Here's a relevant section in the documentation.

Could you please share the code for customChain1 and customChain2? Maybe there's something in there that prevents them from appearing on mobile.

@skibitsky skibitsky added the question Further information is requested label Nov 26, 2024
@talha-trili
Copy link
Author

talha-trili commented Nov 26, 2024

It works on WebGL but not on android so that makes me think there might be a bug on android side.

Chain ETHERLINK_TESTNET = new(
                              ChainConstants.Namespaces.Evm,
                              "128123",
                              "Etherlink Testnet",
                              new Currency("Tez", "XTZ", 6),
                              new BlockExplorer("Explorer", "https://testnet.explorer.etherlink.com/"),
                              "https://node.ghostnet.etherlink.com",
                              true,
                              "https://etherlink.com/opengraph-image.png?4dd162b94a289c06",
                              "etherlinkTestnet"
                             );
Chain ETHERLINK_MAINNET = new(
                              ChainConstants.Namespaces.Evm,
                              "42793",
                              "Etherlink Mainnet",
                              new Currency("Tez", "XTZ", 6),
                              new BlockExplorer("Explorer", "https://mainnet.explorer.etherlink.com/"),
                              "https://node.mainnet.etherlink.com",
                              false,
                              "https://etherlink.com/opengraph-image.png?4dd162b94a289c06",
                              "etherlink"
                             );

Below functionality does not appear/work on android. Not at least for metamask.
image

@LukaszwBeamable
Copy link

@skibitsky do you have any possible release date for that switching chain fix?

@skibitsky
Copy link
Member

@LukaszwBeamable I'm aiming for tomorrow!

@skibitsky
Copy link
Member

@LukaszwBeamable @talha-trili the latest version v1.1.2 has a potential fix for this issue

@talha-trili
Copy link
Author

Hi @skibitsky It still behaves as it used to be. Meaning it doesnt prompt for adding/changing to custom network on mm mobile.

I've also tested couple of other wallets like trust mobile wallet. And on the trust you have to manually add custom networks before connection. Without doing it, it just throws unsupported chain error.

It would've make sense if i had the same behaviour on mm mobile but on mm it just connects without caring for the network. so maybe its related to mm mobile.

@skibitsky skibitsky added bug Something isn't working and removed question Further information is requested labels Dec 6, 2024
@skibitsky
Copy link
Member

I've reproduced the issue: some chains (including Etherlink) aren't getting added to MetaMask. If the chain is already in your wallet, switching between networks works fine.
I'm working on a solution, but for now you can either manually add Etherlink to MetaMask or use a different wallet.

@skibitsky skibitsky self-assigned this Dec 6, 2024
@talha-trili
Copy link
Author

Hi @skibitsky, any updates ?

@talha-trili
Copy link
Author

Also with the etherlink custom chain setup, i get null reference error at AccountController.cs line 167 after connecting to mm mobile. I believe this is because it doesnt enforce the custom chain and just connects to any other chains like ethereum, poly and etc.
image

@skibitsky
Copy link
Member

Hello @talha-trili,

Sorry for the delayed answer. The good news is that I've found the issue! In your network configuration set native token decimal value to 6, but it has to be 18.

Chain ETHERLINK_TESTNET = new(
                              ChainConstants.Namespaces.Evm,
                              "128123",
                              "Etherlink Testnet",
                              new Currency("Tez", "XTZ", 18), // 👈 use 18 here
                              new BlockExplorer("Explorer", "https://testnet.explorer.etherlink.com/"),
                              "https://node.ghostnet.etherlink.com",
                              true,
                              "https://etherlink.com/opengraph-image.png?4dd162b94a289c06",
                              "etherlinkTestnet"
                             );

I'll work on improving the error messages so you could get more useful information from MetaMask app!

@talha-trili
Copy link
Author

Hi @skibitsky, i do not see any changes after setting decimals to 18 🤔 Metamask android still doesn't add etherlink and just connects whatever network/s it has.

@skibitsky
Copy link
Member

@talha-trili, yes, MetaMask always connects the chain that is active in the MetaMask app, regardless of your app configuration. However, when you switch to the Etherlink in the dapp, AppKit will try to add that chain to the MetaMask. Basically, the AppKit chain will take priority over whatever is active in MetaMask when you make requests, but not during connection.

The problem is that there's a bug in latest version of MetaMask that essentially breaks chain switching 😔 We're in touch with the MetaMask team, I'll keep you posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants