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

Need chains array in Namespace class #268

Open
muhammad-hassan-shakeel opened this issue Feb 20, 2024 · 6 comments
Open

Need chains array in Namespace class #268

muhammad-hassan-shakeel opened this issue Feb 20, 2024 · 6 comments

Comments

@muhammad-hassan-shakeel
@freezed
class Namespace with _$Namespace {
  @JsonSerializable()
  const factory Namespace({
    required List<String> accounts,
    required List<String> methods,
    required List<String> events,
  }) = _Namespace;

  factory Namespace.fromJson(Map<String, dynamic> json) =>
      _$NamespaceFromJson(json);
}

This is the Namespace class, we are developing some application where I need to connect with the Unity app of ours via WalletConnect. Unity team is looking for chains list in Namespace but unfortunately it doesn't have it. Can you please tell me what can I do on flutter end to send that to them at the time of Session approval?

@quetool
Copy link
Collaborator

quetool commented Feb 20, 2024

@muhammad-hassan-shakeel
Copy link
Author

approveSession method takes namespaces argument of Namespace type. Namespace type has three attributes accounts, events and methods.

On unity end, namespace object looks like this:

public class Namespace
  {
    [JsonProperty("accounts")]
    public string[] Accounts;
    [JsonProperty("methods")]
    public string[] Methods;
    [JsonProperty("events")]
    public string[] Events;
    [JsonProperty("chains")]
    public string[] Chains;

the unity guys are looking for "chains" list from flutter side.

how can I send them the chains list?

@quetool
Copy link
Collaborator

quetool commented Feb 20, 2024

An account is just the union of the chainId and the address, so for instance, eip155:1:0xsa087dfs96gd85f6sd7a0a9fs68dg5. Furthermore, you have a handy method inside NamespaceUtils called getChainsFromAccounts.
So, if I get you correctly this is what you are looking for:

void _onSessionProposal(SessionProposalEvent? args) async {
    final accounts = args?.params.generatedNamespaces?['eip155']?.accounts;
    final allChains = NamespaceUtils.getChainsFromAccounts(accounts ?? []);
    debugPrint('All eip155 chains requested: $allChains');
}

@muhammad-hassan-shakeel
Copy link
Author

is there a way for me to add "chains" key in the map? with information related to chains only? excluding the address part

@hoangbtmrk
Copy link

Hi @quetool
I am facing with the same issue with Wagmi V2, they use the chains returned from session namespace to validate chain and then request method wallet_addEthereumChain. Because there is no chains in session name space, that method is always called event it's unnecessary.

The code is here: https://github.com/wevm/wagmi/blob/c403563be5dd3ab36d8582e69071ce87294468c2/packages/connectors/src/walletConnect.ts#L261

@quetool
Copy link
Collaborator

quetool commented Mar 25, 2024

Hello @hoangbtmrk , you should open your issue under web repository https://github.com/WalletConnect/web3modal, this is the Flutter one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants