WalletConnect / WalletConnectFlutterV2

WalletConnect v2 client made in Dart for Flutter.
https://pub.dev/packages/walletconnect_flutter_v2
Apache License 2.0
114 stars 60 forks source link

Need chains array in Namespace class #268

Open muhammad-hassan-shakeel opened 7 months ago

muhammad-hassan-shakeel commented 7 months ago
@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 commented 7 months ago

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

muhammad-hassan-shakeel commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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

hoangbtmrk commented 6 months ago

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 commented 6 months ago

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