WalletConnectFlutterV2 icon indicating copy to clipboard operation
WalletConnectFlutterV2 copied to clipboard

Need chains array in Namespace class

Open muhammad-hassan-shakeel opened this issue 1 year ago • 6 comments
trafficstars

@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?

muhammad-hassan-shakeel avatar Feb 20 '24 10:02 muhammad-hassan-shakeel

Hello @muhammad-hassan-shakeel! I didn't understand your concern but for session proposals these are the models: https://github.com/WalletConnect/WalletConnectFlutterV2/blob/master/lib/apis/sign_api/models/proposal_models.dart

Docs: https://docs.walletconnect.com/web3wallet/wallet-usage#session-approval

quetool avatar Feb 20 '24 10:02 quetool

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?

muhammad-hassan-shakeel avatar Feb 20 '24 10:02 muhammad-hassan-shakeel

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');
}

quetool avatar Feb 20 '24 11:02 quetool

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

muhammad-hassan-shakeel avatar Feb 23 '24 09:02 muhammad-hassan-shakeel

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

hoangbtmrk avatar Mar 25 '24 07:03 hoangbtmrk

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

quetool avatar Mar 25 '24 09:03 quetool