How to use the @walletconnect/utils.isJsonRpcResponseError 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 / eth-provider / src / provider.ts View on Github external
public async onConnectionPayload (payload: JsonRpc) {
    const { id } = payload
    if (typeof id !== 'undefined') {
      if (this.promises[id]) {
        if (isJsonRpcResponseError(payload)) {
          this.promises[id].reject(payload.error)
        } else if (isJsonRpcResponseSuccess(payload)) {
          this.promises[id].resolve(payload.result)
        }
        delete this.promises[id]
      }
    } else if (isJsonRpcSubscription(payload)) {
      if (payload.method && payload.method.indexOf('_subscription') > -1) {
        // Emit subscription result
        this.emit(payload.params.subscription, payload.params.result)
        this.emit(payload.method, payload.params) // Latest EIP-1193
        this.emit('data', payload) // Backwards Compatibility
      }
    }
  }
  public async checkConnection () {
github WalletConnect / walletconnect-monorepo / packages / channel-provider / src / provider.ts View on Github external
public async onConnectionPayload (payload: JsonRpc) {
    const { id } = payload
    if (typeof id !== 'undefined') {
      if (this.promises[id]) {
        if (isJsonRpcResponseError(payload)) {
          this.promises[id].reject(payload.error)
        } else if (isJsonRpcResponseSuccess(payload)) {
          this.promises[id].resolve(payload.result)
        }
        delete this.promises[id]
      }
    } else if (isJsonRpcSubscription(payload)) {
      if (payload.method && payload.method.indexOf('_subscription') > -1) {
        // Emit subscription result
        this.emit(payload.params.subscription, payload.params.result)
        this.emit(payload.method, payload.params) // Latest EIP-1193
        this.emit('data', payload) // Backwards Compatibility
      }
    }
  }
  public async checkConnection () {
github WalletConnect / walletconnect-monorepo / packages / core / src / index.ts View on Github external
public rejectRequest (response: Partial) {
    if (isJsonRpcResponseError(response)) {
      const formattedResponse = this._formatResponse(response)
      this._sendResponse(formattedResponse)
    } else {
      throw new Error(ERROR_MISSING_ERROR)
    }
  }
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
      )
    }

    if (
      (!eventEmitters || !eventEmitters.length) &&
github WalletConnect / walletconnect-monorepo / packages / core / src / index.ts View on Github external
protected _formatResponse (
    response: Partial
  ): IJsonRpcResponseSuccess | IJsonRpcResponseError {
    if (typeof response.id === 'undefined') {
      throw new Error(ERROR_MISSING_ID)
    }

    if (isJsonRpcResponseError(response)) {
      const error = formatRpcError(response.error)

      const errorResponse: IJsonRpcResponseError = {
        id: response.id,
        jsonrpc: '2.0',
        ...response,
        error
      }
      return errorResponse
    } else if (isJsonRpcResponseSuccess(response)) {
      const successResponse: IJsonRpcResponseSuccess = {
        id: response.id,
        jsonrpc: '2.0',
        ...response
      }
github WalletConnect / walletconnect-monorepo / packages / core / src / events.ts View on Github external
eventEmitters.forEach((eventEmitter: IEventEmitter) => {
      if (isJsonRpcResponseError(payload)) {
        const error = new Error(payload.error.message)
        eventEmitter.callback(error, null)
      } else {
        eventEmitter.callback(null, payload)
      }
    })
  }