How to use the @shapeshiftoss/hdwallet-core.WrongApp function in @shapeshiftoss/hdwallet-core

To help you get started, we’ve selected a few @shapeshiftoss/hdwallet-core 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 shapeshift / hdwallet / packages / hdwallet-ledger / src / utils.ts View on Github external
export function handleError (result: any, transport?: LedgerTransport, message?: string): void | Error {
  if (result.success)
    return

  if (result.payload && result.payload.error) {

    // No app selected
    if (result.payload.error.includes('0x6700') ||
        result.payload.error.includes('0x6982')) {
      throw new core.SelectApp('Ledger', result.coin)
    }

    // Wrong app selected
    if (result.payload.error.includes('0x6d00')) {
      if (result.coin) {
        throw new core.WrongApp('Ledger', result.coin)
      }
      // Navigate to Ledger Dashboard
      throw new core.NavigateToDashboard('Ledger')
    }

    // User selected x instead of ✓
    if (result.payload.error.includes('0x6985')) {
      throw new core.ActionCancelled()
    }

    // Device is on the lock screen
    if (result.payload.error.includes('0x6f04')) {
      throw new core.DeviceLocked()
    }

    // Device disconnected during operation, typically due to app navigation
github shapeshift / hdwallet / packages / hdwallet-ledger / src / ledger.ts View on Github external
public async validateCurrentApp (coin: core.Coin): Promise {
    if (!coin) {
      throw new Error(`No coin provided`)
    }

    const appName = get(networksUtil[core.slip44ByCoin(coin)], 'appName')
    if (!appName) {
      throw new Error(`Unable to find associated app name for coin: ${coin}`)
    }

    const res = await this.transport.call(null, 'getAppAndVersion')
    handleError(res, this.transport)

    const { payload: { name: currentApp } } = res
    if (currentApp !== appName) {
      throw new core.WrongApp('Ledger', appName)
    }
  }