Skip to content

Commit

Permalink
[chore] Added error handler API+Network
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed May 24, 2022
1 parent e320f6a commit 52213d4
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/Send/ConfirmScreen/ConfirmScreen.tsx
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {BigNumber} from 'bignumber.js'
import React from 'react'
import {useIntl} from 'react-intl'
import {IntlShape, useIntl} from 'react-intl'
import {Platform, ScrollView, StyleSheet, View, ViewProps} from 'react-native'
import {useDispatch, useSelector} from 'react-redux'

Expand All @@ -14,6 +14,7 @@ import {
setLedgerDeviceId as _setLedgerDeviceId,
setLedgerDeviceObj as _setLedgerDeviceObj,
} from '../../../legacy/actions/hwWallet'
import {ApiError, NetworkError} from '../../../legacy/api/errors'
import ErrorModal from '../../../legacy/components/Common/ErrorModal'
import HWInstructions from '../../../legacy/components/Ledger/HWInstructions'
import LedgerConnect from '../../../legacy/components/Ledger/LedgerConnect'
Expand Down Expand Up @@ -168,10 +169,14 @@ export const ConfirmScreen = () => {
const onConfirm = async () => {
const submitTx = async (tx: string | ISignRequest, decryptedKey?: string) => {
await withPleaseWaitModal(async () => {
if (decryptedKey != null) {
await submitTransaction(tx, decryptedKey)
} else {
await submitSignedTx(tx)
try {
if (decryptedKey != null) {
await submitTransaction(tx, decryptedKey)
} else {
await submitSignedTx(tx)
}
} catch (e) {
await handleSubmitTxError(e, intl)
}
resetToTxHistory()
})
Expand Down Expand Up @@ -387,3 +392,13 @@ const useStrings = () => {
},
}
}

export async function handleSubmitTxError(error: any, intl: IntlShape) {
if (error instanceof ApiError) {
return await showErrorDialog(errorMessages.apiError, intl)
}
if (error instanceof NetworkError) {
return await showErrorDialog(errorMessages.networkError, intl)
}
throw error
}

0 comments on commit 52213d4

Please sign in to comment.