Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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)
}
}