updateSession method

Future updateSession(
  1. SessionStatus sessionStatus
)

Updates the actual session requesting the peer to change some session data Only chainId and/or accounts can be changed. https://docs.walletconnect.com/client-api#update-session-session_update

Implementation

Future updateSession(SessionStatus sessionStatus) async {
  if (!connected) {
    throw WalletConnectException('Session currently disconnected');
  }

  session.chainId = sessionStatus.chainId;
  session.accounts = sessionStatus.accounts;
  session.networkId = sessionStatus.networkId ?? 0;
  session.rpcUrl = sessionStatus.rpcUrl ?? '';

  final params = {
    'approved': true,
    'chainId': session.chainId,
    'networkId': session.networkId,
    'accounts': session.accounts,
    'rpcUrl': session.rpcUrl,
  };

  final request = JsonRpcRequest(
    id: payloadId,
    method: 'wc_sessionUpdate',
    params: [params],
  );

  // Send the request
  final response = await _sendRequest(request);

  // Notify listeners
  await _handleSessionResponse(response);
}