getAccounts method

List<String>? getAccounts({
  1. String? namespace,
})

Implementation

List<String>? getAccounts({String? namespace}) {
  final accountList = <String>[];

  if (sessionService.noSession) {
    return null;
  }

  if (sessionService.isCoinbase) {
    final ns = NetworkUtils.eip155;
    return ReownAppKitModalNetworks.getAllSupportedNetworks(namespace: ns)
        .map((e) => '$ns:${e.chainId}:${getAddress(ns)}')
        .toList();
  }

  if (sessionService.isMagic) {
    final ns = namespace ?? NetworkUtils.eip155;
    return ReownAppKitModalNetworks.getAllSupportedNetworks(namespace: ns)
        .map((e) => '$ns:${e.chainId}:${getAddress(ns)}')
        .toList();
  }

  final sessionNamespaces = _sessionData!.namespaces;
  if ((namespace ?? '').isEmpty) {
    for (var namespace in sessionNamespaces.keys) {
      final accounts = sessionNamespaces[namespace]?.accounts ?? [];
      accountList.addAll(accounts);
    }

    return accountList;
  }

  return sessionNamespaces[namespace]?.accounts ?? [];
}