How to use the @walletconnect/utils.isJsonRpcRequest function in @walletconnect/utils

To help you get started, we’ve selected a few @walletconnect/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WalletConnect / walletconnect-monorepo / packages / channel-provider / src / provider.ts View on Github external
public sendAsync (payload: JsonRpc, cb: any) {
    // Backwards Compatibility
    if (!cb || typeof cb !== 'function') {
      return cb(
        new Error('Invalid or undefined callback provided to sendAsync')
      )
    }
    if (!payload) {
      return cb(new Error('Invalid Payload'))
    }
    // sendAsync can be called with an array for batch requests used by web3.js 0.x
    // this is not part of EIP-1193's backwards compatibility but we still want to support it
    if (payload instanceof Array) {
      return this.sendAsyncBatch(payload, cb)
    } else if (isJsonRpcRequest(payload)) {
      return this._send(payload.method, payload.params)
        .then(result => {
          cb(null, { id: payload.id, jsonrpc: payload.jsonrpc, result })
        })
        .catch(err => {
          cb(err)
        })
    }
  }
  public sendAsyncBatch (requests: JsonRpc[], cb: any) {
github WalletConnect / walletconnect-monorepo / packages / eth-provider / src / provider.ts View on Github external
public sendAsync (payload: JsonRpc, cb: any) {
    // Backwards Compatibility
    if (!cb || typeof cb !== 'function') {
      return cb(
        new Error('Invalid or undefined callback provided to sendAsync')
      )
    }
    if (!payload) {
      return cb(new Error('Invalid Payload'))
    }
    // sendAsync can be called with an array for batch requests used by web3.js 0.x
    // this is not part of EIP-1193's backwards compatibility but we still want to support it
    if (payload instanceof Array) {
      return this.sendAsyncBatch(payload, cb)
    } else if (isJsonRpcRequest(payload)) {
      return this._send(payload.method, payload.params)
        .then(result => {
          cb(null, { id: payload.id, jsonrpc: payload.jsonrpc, result })
        })
        .catch(err => {
          cb(err)
        })
    }
  }
  public sendAsyncBatch (requests: JsonRpc[], cb: any) {
github WalletConnect / walletconnect-monorepo / packages / eth-provider / src / provider.ts View on Github external
requests.map(payload => {
        if (isJsonRpcRequest(payload)) {
          this._send(payload.method, payload.params)
        }
      })
    )
github WalletConnect / walletconnect-monorepo / packages / channel-provider / src / provider.ts View on Github external
requests.map(payload => {
        if (isJsonRpcRequest(payload)) {
          this._send(payload.method, payload.params)
        }
      })
    )
github WalletConnect / walletconnect-monorepo / packages / core / src / events.ts View on Github external
public trigger (
    payload:
      | IJsonRpcRequest
      | IJsonRpcResponseSuccess
      | IJsonRpcResponseError
      | IInternalEvent
  ): void {
    let eventEmitters: IEventEmitter[] = []
    let event: string

    if (isJsonRpcRequest(payload)) {
      event = payload.method
    } else if (
      isJsonRpcResponseSuccess(payload) ||
      isJsonRpcResponseError(payload)
    ) {
      event = `response:${payload.id}`
    } else if (isInternalEvent(payload)) {
      event = payload.event
    } else {
      event = ''
    }

    if (event) {
      eventEmitters = this._eventEmitters.filter(
        (eventEmitter: IEventEmitter) => eventEmitter.event === event
      )