Skip to content

Commit

Permalink
Audit every catch statement in the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
swansontec committed Sep 3, 2019
1 parent 253cac7 commit f141829
Show file tree
Hide file tree
Showing 28 changed files with 157 additions and 229 deletions.
7 changes: 4 additions & 3 deletions src/actions/CryptoExchangeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Actions } from 'react-native-router-flux'
import { sprintf } from 'sprintf-js'

import { SwapVerifyShapeshiftModal } from '../components/modals/SwapVerifyShapeshiftModal.js'
import { Airship } from '../components/services/AirshipInstance.js'
import { Airship, showError } from '../components/services/AirshipInstance.js'
import * as Constants from '../constants/indexConstants'
import { intl } from '../locales/intl'
import s from '../locales/strings.js'
Expand Down Expand Up @@ -107,8 +107,8 @@ export const exchangeMax = () => async (dispatch: Dispatch, getState: GetState)
spendTargets: [{ publicAddress }]
}
primaryNativeAmount = await wallet.getMaxSpendable(edgeSpendInfo)
} catch (e) {
console.log(e.name, e.message)
} catch (error) {
showError(error)
}
dispatch({ type: 'SET_FROM_WALLET_MAX', data: primaryNativeAmount })
}
Expand Down Expand Up @@ -318,6 +318,7 @@ export const shiftCryptoCurrency = (swapInfo: GuiSwapInfo) => async (dispatch: D
}, 1)
global.firebase && global.firebase.analytics().logEvent(`Exchange_Shift_Success`)
} catch (error) {
console.log(error)
global.firebase && global.firebase.analytics().logEvent(`Exchange_Shift_Failed`)
dispatch({ type: 'DONE_SHIFT_TRANSACTION' })
setTimeout(() => {
Expand Down
26 changes: 8 additions & 18 deletions src/actions/OtpActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,20 @@ import type { Dispatch, GetState } from '../types/reduxTypes.js'
export const enableOtp = () => async (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const account = CORE_SELECTORS.getAccount(state)
try {
await account.enableOtp()
dispatch(SETTINGS_ACTIONS.updateOtpInfo({ enabled: true, otpKey: account.otpKey }))
} catch (error) {
console.log(error)
}
await account.enableOtp()
dispatch(SETTINGS_ACTIONS.updateOtpInfo({ enabled: true, otpKey: account.otpKey }))
}

export const disableOtp = () => async (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const account = CORE_SELECTORS.getAccount(state)
try {
await account.disableOtp()
dispatch(SETTINGS_ACTIONS.updateOtpInfo({ enabled: false, otpKey: null, otpResetPending: false }))
} catch (error) {
console.log(error)
}
await account.disableOtp()
dispatch(SETTINGS_ACTIONS.updateOtpInfo({ enabled: false, otpKey: null, otpResetPending: false }))
}

export const keepOtp = () => async (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const account = CORE_SELECTORS.getAccount(state)
try {
await account.cancelOtpReset()
dispatch({ type: 'DISABLE_OTP_RESET' })
} catch (error) {
throw new Error(error)
}
await account.cancelOtpReset()
dispatch({ type: 'DISABLE_OTP_RESET' })
}
11 changes: 2 additions & 9 deletions src/actions/RequestActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ export const saveReceiveAddress = (receiveAddress: Object) => (dispatch: Dispatc
const selectedCurrencyCode = UI_SELECTORS.getSelectedCurrencyCode(state)
const wallet = CORE_SELECTORS.getWallet(state, selectedWalletId)

const onSuccess = () => {
dispatch(updateReceiveAddress(selectedWalletId, selectedCurrencyCode))
}
const onError = e => {
console.log(e)
}

wallet
.saveReceiveAddress(receiveAddress)
.then(onSuccess)
.catch(onError)
.then(() => dispatch(updateReceiveAddress(selectedWalletId, selectedCurrencyCode)))
.catch(showError)
}
6 changes: 1 addition & 5 deletions src/actions/ResyncWalletModalActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export const showResyncWalletModal = (walletId: string) => async (dispatch: Disp
const resolveValue = await launchModal(modal)

if (resolveValue) {
try {
wallet.resyncBlockchain()
} catch (e) {
throw new Error(e)
}
await wallet.resyncBlockchain()
}
}
112 changes: 52 additions & 60 deletions src/actions/ScanActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ const doRequestAddress = (dispatch: Dispatch, edgeWallet: EdgeCurrencyWallet, gu
const addr = guiWallet.receiveAddress.publicAddress
const url = decodeURIComponent(requestAddress.callbackUrl)
const finalUrl = url + '?address=' + encodeURIComponent(addr)
try {
Linking.openURL(finalUrl)
} catch (e) {
throw new Error(e)
}
Linking.openURL(finalUrl)
}
})
.catch(e => {
Expand Down Expand Up @@ -314,60 +310,56 @@ export const privateKeyModalActivated = () => async (dispatch: Dispatch, getStat
const shownWalletGetCryptoModals = []

export const checkAndShowGetCryptoModal = () => async (dispatch: Dispatch, getState: GetState) => {
try {
const state = getState()
const currencyCode = UI_SELECTORS.getSelectedCurrencyCode(state)
const wallet = UI_SELECTORS.getSelectedWallet(state)
// check if balance is zero
const balance = wallet.nativeBalances[currencyCode]
if (balance !== '0' || shownWalletGetCryptoModals.includes(wallet.id)) return // if there's a balance then early exit
shownWalletGetCryptoModals.push(wallet.id) // add to list of wallets with modal shown this session
let threeButtonModal
const SPECIAL_CURRENCY_INFO = getSpecialCurrencyInfo(currencyCode)
if (SPECIAL_CURRENCY_INFO.displayBuyCrypto) {
const messageSyntax = sprintf(s.strings.buy_crypto_modal_message, currencyCode, currencyCode, currencyCode)
threeButtonModal = createThreeButtonModal({
title: s.strings.buy_crypto_modal_title,
message: messageSyntax,
icon: <Icon name={SHOPPING_CART} type={MATERIAL_ICONS} size={32} color={COLORS.primary} />,
primaryButton: {
text: sprintf(s.strings.buy_crypto_modal_buy_action, currencyCode),
returnValue: 'buy'
},
secondaryButton: {
text: s.strings.buy_crypto_modal_exchange,
returnValue: 'exchange'
},
tertiaryButton: {
text: s.strings.buy_crypto_decline,
returnValue: 'decline'
}
})
} else {
// if we're not targetting for buying, but rather exchange
const messageSyntax = sprintf(s.strings.exchange_crypto_modal_message, currencyCode, currencyCode, currencyCode)
threeButtonModal = createThreeButtonModal({
title: s.strings.buy_crypto_modal_title,
message: messageSyntax,
icon: <Icon name={SHOPPING_CART} type={MATERIAL_ICONS} size={32} color={COLORS.primary} />,
primaryButton: {
text: sprintf(s.strings.buy_crypto_modal_exchange),
returnValue: 'exchange'
},
secondaryButton: {
text: s.strings.buy_crypto_decline,
returnValue: 'decline'
}
})
}
const value = await launchModal(threeButtonModal)
if (value === 'buy') {
Actions[BUY_SELL]()
} else if (value === 'exchange') {
dispatch(selectWalletForExchange(wallet.id, currencyCode, 'to'))
Actions[EXCHANGE_SCENE]()
}
} catch (e) {
console.log('error generating encodedURI: ', e)
const state = getState()
const currencyCode = UI_SELECTORS.getSelectedCurrencyCode(state)
const wallet = UI_SELECTORS.getSelectedWallet(state)
// check if balance is zero
const balance = wallet.nativeBalances[currencyCode]
if (balance !== '0' || shownWalletGetCryptoModals.includes(wallet.id)) return // if there's a balance then early exit
shownWalletGetCryptoModals.push(wallet.id) // add to list of wallets with modal shown this session
let threeButtonModal
const SPECIAL_CURRENCY_INFO = getSpecialCurrencyInfo(currencyCode)
if (SPECIAL_CURRENCY_INFO.displayBuyCrypto) {
const messageSyntax = sprintf(s.strings.buy_crypto_modal_message, currencyCode, currencyCode, currencyCode)
threeButtonModal = createThreeButtonModal({
title: s.strings.buy_crypto_modal_title,
message: messageSyntax,
icon: <Icon name={SHOPPING_CART} type={MATERIAL_ICONS} size={32} color={COLORS.primary} />,
primaryButton: {
text: sprintf(s.strings.buy_crypto_modal_buy_action, currencyCode),
returnValue: 'buy'
},
secondaryButton: {
text: s.strings.buy_crypto_modal_exchange,
returnValue: 'exchange'
},
tertiaryButton: {
text: s.strings.buy_crypto_decline,
returnValue: 'decline'
}
})
} else {
// if we're not targetting for buying, but rather exchange
const messageSyntax = sprintf(s.strings.exchange_crypto_modal_message, currencyCode, currencyCode, currencyCode)
threeButtonModal = createThreeButtonModal({
title: s.strings.buy_crypto_modal_title,
message: messageSyntax,
icon: <Icon name={SHOPPING_CART} type={MATERIAL_ICONS} size={32} color={COLORS.primary} />,
primaryButton: {
text: sprintf(s.strings.buy_crypto_modal_exchange),
returnValue: 'exchange'
},
secondaryButton: {
text: s.strings.buy_crypto_decline,
returnValue: 'decline'
}
})
}
const value = await launchModal(threeButtonModal)
if (value === 'buy') {
Actions[BUY_SELL]()
} else if (value === 'exchange') {
dispatch(selectWalletForExchange(wallet.id, currencyCode, 'to'))
Actions[EXCHANGE_SCENE]()
}
}
3 changes: 2 additions & 1 deletion src/actions/SendConfirmationActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Actions } from 'react-native-router-flux'
import { sprintf } from 'sprintf-js'

import { launchModal } from '../components/common/ModalProvider.js'
import { showError } from '../components/services/AirshipInstance.js'
import { EXCLAMATION, FEE_ALERT_THRESHOLD, MATERIAL_COMMUNITY, SEND_CONFIRMATION, TRANSACTION_DETAILS } from '../constants/indexConstants'
import { getSpecialCurrencyInfo, getSymbolFromCurrency } from '../constants/WalletAndCurrencyConstants.js'
import s from '../locales/strings.js'
Expand Down Expand Up @@ -169,7 +170,7 @@ export const updateMaxSpend = () => (dispatch: Dispatch, getState: GetState) =>

dispatch(updateAmount(nativeAmount, exchangeAmount, fiatPerCrypto.toString(), true))
})
.catch(e => console.log(e))
.catch(showError)
}

export const signBroadcastAndSave = () => async (dispatch: Dispatch, getState: GetState) => {
Expand Down
43 changes: 15 additions & 28 deletions src/actions/SettingsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export const setPINModeRequest = (pinMode: boolean) => (dispatch: Dispatch, getS
const account = CORE_SELECTORS.getAccount(state)
ACCOUNT_SETTINGS.setPINModeRequest(account, pinMode)
.then(() => dispatch(SETTINGS_ACTIONS.setPINMode(pinMode)))
.catch(error => {
console.error(error)
})
.catch(showError)
}

export const setAutoLogoutTimeInMinutesRequest = (autoLogoutTimeInMinutes: number) => {
Expand All @@ -55,9 +53,7 @@ export const setAutoLogoutTimeInSecondsRequest = (autoLogoutTimeInSeconds: numbe
const account = CORE_SELECTORS.getAccount(state)
ACCOUNT_SETTINGS.setAutoLogoutTimeInSecondsRequest(account, autoLogoutTimeInSeconds)
.then(() => dispatch(SETTINGS_ACTIONS.setAutoLogoutTimeInSeconds(autoLogoutTimeInSeconds)))
.catch(error => {
console.error(error)
})
.catch(showError)
}

export const setDefaultFiatRequest = (defaultFiat: string) => (dispatch: Dispatch, getState: GetState) => {
Expand Down Expand Up @@ -96,27 +92,23 @@ export const setDefaultFiatRequest = (defaultFiat: string) => (dispatch: Dispatc
dispatch(newSpendingLimits(nextSpendingLimits))
dispatch(updateExchangeRates())
})
.catch(e => console.log(e))
.catch(showError)
}

export const setMerchantModeRequest = (merchantMode: boolean) => (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const account = CORE_SELECTORS.getAccount(state)
ACCOUNT_SETTINGS.setMerchantModeRequest(account, merchantMode)
.then(() => dispatch(SETTINGS_ACTIONS.setMerchantMode(merchantMode)))
.catch(error => {
console.error(error)
})
.catch(showError)
}

export const setBluetoothModeRequest = (bluetoothMode: boolean) => (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const account = CORE_SELECTORS.getAccount(state)
ACCOUNT_SETTINGS.setBluetoothModeRequest(account, bluetoothMode)
.then(() => dispatch(SETTINGS_ACTIONS.setBluetoothMode(bluetoothMode)))
.catch(error => {
console.error(error)
})
.catch(showError)
}

export const checkCurrentPassword = (arg: string) => async (dispatch: Dispatch, getState: GetState) => {
Expand All @@ -139,12 +131,10 @@ export const lockSettings = () => async (dispatch: Dispatch) => {
export const setDenominationKeyRequest = (currencyCode: string, denominationKey: string) => (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const account = CORE_SELECTORS.getAccount(state)
const onSuccess = () => dispatch(SETTINGS_ACTIONS.setDenominationKey(currencyCode, denominationKey))
const onError = e => console.log(e)

return ACCOUNT_SETTINGS.setDenominationKeyRequest(account, currencyCode, denominationKey)
.then(onSuccess)
.catch(onError)
.then(() => dispatch(SETTINGS_ACTIONS.setDenominationKey(currencyCode, denominationKey)))
.catch(showError)
}

// touch id interaction
Expand Down Expand Up @@ -205,9 +195,8 @@ export const enableCustomNodes = (currencyCode: string) => async (dispatch: Disp
const currencyPlugin = account.currencyConfig[currencyPluginName]
try {
await currencyPlugin.changeUserSettings({ ...currencyPlugin.userSettings, disableFetchingServers: true })
} catch (e) {
console.log(e)
throw new Error(e)
} catch (error) {
showError(error)
}
}

Expand All @@ -218,9 +207,8 @@ export const disableCustomNodes = (currencyCode: string) => async (dispatch: Dis
const currencyPlugin = account.currencyConfig[currencyPluginName]
try {
await currencyPlugin.changeUserSettings({ ...currencyPlugin.userSettings, disableFetchingServers: false })
} catch (e) {
console.log(e)
throw new Error(e)
} catch (error) {
showError(error)
}
}

Expand All @@ -231,9 +219,8 @@ export const saveCustomNodesList = (currencyCode: string, nodesList: Array<strin
const currencyPlugin = account.currencyConfig[currencyPluginName]
try {
await currencyPlugin.changeUserSettings({ ...currencyPlugin.userSettings, electrumServers: nodesList })
} catch (e) {
console.log(e)
throw new Error('Unable to save plugin setting')
} catch (error) {
showError(error)
}
}

Expand Down Expand Up @@ -281,8 +268,8 @@ export const showUnlockSettingsModal = () => async (dispatch: Dispatch, getState
if (resolveValue) {
dispatch(SETTINGS_ACTIONS.setSettingsLock(false))
}
} catch (e) {
throw new Error('Unable to unlock settings')
} catch (error) {
showError(error)
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/actions/SplitWalletModalActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createYesNoModal } from 'edge-components'
import React from 'react'

import { launchModal } from '../components/common/ModalProvider.js'
import { showError } from '../components/services/AirshipInstance.js'
import { SPLIT } from '../constants/indexConstants.js'
import s from '../locales/strings.js'
import { getAccount, getWallet, getWalletName } from '../modules/Core/selectors.js'
Expand Down Expand Up @@ -47,8 +48,8 @@ export const showSplitWalletModal = (walletId: string) => async (dispatch: Dispa
const splitType = getSplitType(wallet.currencyInfo.currencyCode)
await account.splitWalletInfo(walletId, splitType)
dispatch(refreshWallet(walletId))
} catch (e) {
throw new Error(e)
} catch (error) {
showError(error)
}
}
}
Loading

0 comments on commit f141829

Please sign in to comment.