Skip to content

Commit

Permalink
chore(deps): Upgrade typescript to 4.7.4 (#4009)
Browse files Browse the repository at this point in the history
### Description

Almost the entire PR is handling errors from `try...catch` statements
which are now type `unknown` but we often assume them to be type
`Error`. I wrote a small helper function, `ensureError` to handle these
cases.

4.7.X is the minimum version we need for typechain
https://github.com/dethcrypto/TypeChain/tree/master/packages/target-ethers-v6

### Test plan

Updated all unit tests

---------

Co-authored-by: Tom McGuire <Mcgtom10@gmail.com>
  • Loading branch information
jh2oman and MuckT authored Jul 31, 2023
1 parent 4112284 commit 4b14031
Show file tree
Hide file tree
Showing 38 changed files with 961 additions and 880 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
"@types/utf8": "^2.1.6",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@valora/eslint-config-typescript": "^1.0.0",
"@valora/eslint-config-typescript": "^1.0.2",
"@valora/resolve-kit": "^1.0.1",
"@walletconnect/legacy-types": "^2.0.0",
"@walletconnect/sign-client": "^2.9.1",
Expand Down Expand Up @@ -286,8 +286,8 @@
"ts-node": "10.7.0",
"ts-retry-promise": "^0.6.0",
"twilio": "^3.69.0",
"typescript": "4.1.6",
"typescript-json-schema": "^0.53.0"
"typescript": "4.7.4",
"typescript-json-schema": "^0.59.0"
},
"resolutions": {
"ethers": "5.7.2",
Expand Down
10 changes: 5 additions & 5 deletions src/account/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export interface State {
pincodeType: PincodeType
backupCompleted: boolean
accountCreationTime: number
startOnboardingTime: number | undefined
startOnboardingTime?: number
dismissedGetVerified: boolean
dismissedGoldEducation: boolean
acceptedTerms: boolean
hasMigratedToNewBip39: boolean
choseToRestoreAccount: boolean | undefined
profileUploaded: boolean | undefined
recoveringFromStoreWipe: boolean | undefined
accountToRecoverFromStoreWipe: string | undefined
choseToRestoreAccount?: boolean
profileUploaded?: boolean
recoveringFromStoreWipe?: boolean
accountToRecoverFromStoreWipe?: string
dismissedKeepSupercharging: boolean
dismissedStartSupercharging: boolean
celoEducationCompleted: boolean
Expand Down
8 changes: 5 additions & 3 deletions src/account/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { persistor } from 'src/redux/store'
import { patchUpdateStatsigUser } from 'src/statsig'
import { restartApp } from 'src/utils/AppRestart'
import Logger from 'src/utils/Logger'
import { ensureError } from 'src/utils/ensureError'
import { safely } from 'src/utils/safely'
import { clearStoredAccounts } from 'src/web3/KeychainSigner'
import { getContractKit, getWallet } from 'src/web3/contracts'
Expand Down Expand Up @@ -94,9 +95,10 @@ export function* initializeAccountSaga() {
Logger.debug(TAG + '@initializeAccountSaga', 'Account creation success')
ValoraAnalytics.track(OnboardingEvents.initialize_account_complete)
yield* put(initializeAccountSuccess())
} catch (e) {
Logger.error(TAG, 'Failed to initialize account', e)
ValoraAnalytics.track(OnboardingEvents.initialize_account_error, { error: e.message })
} catch (err) {
const error = ensureError(err)
Logger.error(TAG, 'Failed to initialize account', error)
ValoraAnalytics.track(OnboardingEvents.initialize_account_error, { error: error.message })
navigateClearingStack(Screens.AccounSetupFailureScreen)
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/analytics/ValoraAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from 'src/config'
import { store } from 'src/redux/store'
import { getDefaultStatsigUser } from 'src/statsig'
import { ensureError } from 'src/utils/ensureError'
import Logger from 'src/utils/Logger'
import { Statsig } from 'statsig-react-native'

Expand Down Expand Up @@ -138,7 +139,8 @@ class ValoraAnalytics {
}

Logger.info(TAG, 'Segment Analytics Integration initialized!')
} catch (error) {
} catch (err) {
const error = ensureError(err)
Logger.error(TAG, `Segment setup error: ${error.message}\n`, error)
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export interface State {
// In 1.13 we had a critical error which requires a migration to fix. See |verificationMigration.ts|
// for the migration code. We can remove all the code associated with this after some time has passed.
logPhoneNumberTypeEnabled: boolean
googleMobileServicesAvailable: boolean | undefined
huaweiMobileServicesAvailable: boolean | undefined
googleMobileServicesAvailable?: boolean
huaweiMobileServicesAvailable?: boolean
pincodeUseExpandedBlocklist: boolean
rewardPillText?: {
[lang: string]: string
Expand Down
7 changes: 5 additions & 2 deletions src/app/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import { getFeatureGate, patchUpdateStatsigUser } from 'src/statsig'
import { StatsigFeatureGates } from 'src/statsig/types'
import { swapSuccess } from 'src/swap/slice'
import Logger from 'src/utils/Logger'
import { ensureError } from 'src/utils/ensureError'
import { isDeepLink, navigateToURI } from 'src/utils/linking'
import { safely } from 'src/utils/safely'
import { ONE_DAY_IN_MILLIS } from 'src/utils/time'
Expand Down Expand Up @@ -425,7 +426,8 @@ function* watchAppState() {
const newState = (yield* take(appStateChannel)) as string
Logger.debug(`${TAG}@monitorAppState`, `App changed state: ${newState}`)
yield* put(setAppState(newState))
} catch (error) {
} catch (err) {
const error = ensureError(err)
ValoraAnalytics.track(AppEvents.app_state_error, { error: error.message })
Logger.error(`${TAG}@monitorAppState`, `App state Error`, error)
} finally {
Expand Down Expand Up @@ -554,7 +556,8 @@ export function* requestInAppReview() {
yield* call(InAppReview.RequestInAppReview)
yield* put(inAppReviewRequested(now))
ValoraAnalytics.track(AppEvents.in_app_review_impression)
} catch (error) {
} catch (err) {
const error = ensureError(err)
Logger.error(TAG, `Error while calling InAppReview.RequestInAppReview`, error)
ValoraAnalytics.track(AppEvents.in_app_review_error, { error: error.message })
}
Expand Down
10 changes: 7 additions & 3 deletions src/dappkit/dappkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { navigate, navigateBack } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import { SentryTransactionHub } from 'src/sentry/SentryTransactionHub'
import { SentryTransaction } from 'src/sentry/SentryTransactions'
import { ensureError } from 'src/utils/ensureError'
import { navigateToURI } from 'src/utils/linking'
import Logger from 'src/utils/Logger'
import { safely } from 'src/utils/safely'
Expand Down Expand Up @@ -116,7 +117,8 @@ function* respondToAccountAuth(action: ApproveAccountAuthAction) {

ValoraAnalytics.track(DappKitEvents.dappkit_request_accept_success, defaultTrackedProperties)
SentryTransactionHub.finishTransaction(SentryTransaction.dappkit_connection)
} catch (error) {
} catch (err) {
const error = ensureError(err)
Logger.error(TAG, 'Failed to respond to account auth', error)
ValoraAnalytics.track(DappKitEvents.dappkit_request_accept_error, {
...defaultTrackedProperties,
Expand Down Expand Up @@ -176,7 +178,8 @@ function* produceTxSignature(action: RequestTxSignatureAction) {
yield* call(handleNavigationWithDeeplink, responseDeeplink)
ValoraAnalytics.track(DappKitEvents.dappkit_request_accept_success, defaultTrackedProperties)
SentryTransactionHub.finishTransaction(SentryTransaction.dappkit_transaction)
} catch (error) {
} catch (err) {
const error = ensureError(err)
Logger.error(TAG, 'Failed to produce tx signature', error)
ValoraAnalytics.track(DappKitEvents.dappkit_request_accept_error, {
...defaultTrackedProperties,
Expand Down Expand Up @@ -213,7 +216,8 @@ export function* handleDappkitDeepLink(deeplink: string) {
navigate(Screens.ErrorScreen, { errorMessage: 'Unsupported dapp request type' })
Logger.warn(TAG, 'Unsupported dapp request type')
}
} catch (error) {
} catch (err) {
const error = ensureError(err)
navigate(Screens.ErrorScreen, { errorMessage: `Deep link not valid for dappkit: ${error}` })
Logger.debug(TAG, `Deep link not valid for dappkit: ${error}`)
ValoraAnalytics.track(DappKitEvents.dappkit_parse_deeplink_error, {
Expand Down
17 changes: 10 additions & 7 deletions src/escrow/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { sendTransaction } from 'src/transactions/send'
import { newTransactionContext } from 'src/transactions/types'
import Logger from 'src/utils/Logger'
import { Currency } from 'src/utils/currencies'
import { ensureError } from 'src/utils/ensureError'
import { safely } from 'src/utils/safely'
import { getContractKit, getContractKitAsync } from 'src/web3/contracts'
import { getConnectedAccount, getConnectedUnlockedAccount } from 'src/web3/saga'
Expand Down Expand Up @@ -84,10 +85,11 @@ export function* reclaimFromEscrow({ paymentID }: EscrowReclaimPaymentAction) {

yield* call(navigateHome)
ValoraAnalytics.track(EscrowEvents.escrow_reclaim_complete)
} catch (e) {
Logger.error(TAG + '@reclaimFromEscrow', 'Error reclaiming payment from escrow', e)
ValoraAnalytics.track(EscrowEvents.escrow_reclaim_error, { error: e.message })
yield* put(showErrorOrFallback(e, ErrorMessages.RECLAIMING_ESCROWED_PAYMENT_FAILED))
} catch (err) {
const error = ensureError(err)
Logger.error(TAG + '@reclaimFromEscrow', 'Error reclaiming payment from escrow', error)
ValoraAnalytics.track(EscrowEvents.escrow_reclaim_error, { error: error.message })
yield* put(showErrorOrFallback(error, ErrorMessages.RECLAIMING_ESCROWED_PAYMENT_FAILED))
yield* put(reclaimEscrowPaymentFailure())
} finally {
yield* put(fetchSentEscrowPayments())
Expand Down Expand Up @@ -160,9 +162,10 @@ function* doFetchSentPayments() {

yield* put(storeSentEscrowPayments(sentPayments))
ValoraAnalytics.track(EscrowEvents.escrow_fetch_complete)
} catch (e) {
ValoraAnalytics.track(EscrowEvents.escrow_fetch_error, { error: e.message })
Logger.error(TAG + '@doFetchSentPayments', 'Error fetching sent escrowed payments', e)
} catch (err) {
const error = ensureError(err)
ValoraAnalytics.track(EscrowEvents.escrow_fetch_error, { error: error.message })
Logger.error(TAG + '@doFetchSentPayments', 'Error fetching sent escrowed payments', error)
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/exchange/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import Logger from 'src/utils/Logger'
import { Currency } from 'src/utils/currencies'
import { getRateForMakerToken, goldToDollarAmount } from 'src/utils/currencyExchange'
import { ensureError } from 'src/utils/ensureError'
import { safely } from 'src/utils/safely'
import { getConnectedUnlockedAccount } from 'src/web3/saga'
import { call, put, select, spawn, takeEvery } from 'typed-redux-saga'
Expand Down Expand Up @@ -94,7 +95,8 @@ export function* withdrawCelo(action: WithdrawCeloAction) {
ValoraAnalytics.track(CeloExchangeEvents.celo_withdraw_completed, {
amount: amount.toString(),
})
} catch (error) {
} catch (err) {
const error = ensureError(err)
if (error.message === ErrorMessages.PIN_INPUT_CANCELED) {
yield* put(withdrawCeloCanceled())
return
Expand All @@ -108,7 +110,7 @@ export function* withdrawCelo(action: WithdrawCeloAction) {
yield* put(withdrawCeloFailed(context?.id, errorToShow))

ValoraAnalytics.track(CeloExchangeEvents.celo_withdraw_error, {
error,
error: error.message,
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/fees/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { TokenBalance, TokenBalances } from 'src/tokens/slice'
import Logger from 'src/utils/Logger'
import { Currency } from 'src/utils/currencies'
import { ensureError } from 'src/utils/ensureError'
import { safely } from 'src/utils/safely'
import { getContractKit } from 'src/web3/contracts'
import { getGasPrice } from 'src/web3/gas'
Expand Down Expand Up @@ -113,7 +114,8 @@ export function* estimateFeeSaga({
usdFee: usdFee.toString(),
})
}
} catch (error) {
} catch (err) {
const error = ensureError(err)
Logger.error(`${TAG}/estimateFeeSaga`, 'Error estimating fee', error)
ValoraAnalytics.track(FeeEvents.estimate_fee_failed, {
error: error.message,
Expand Down
17 changes: 10 additions & 7 deletions src/fiatconnect/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import { isTxPossiblyPending } from 'src/transactions/send'
import { newTransactionContext } from 'src/transactions/types'
import Logger from 'src/utils/Logger'
import { CiCoCurrency, resolveCICOCurrency } from 'src/utils/currencies'
import { ensureError } from 'src/utils/ensureError'
import { safely } from 'src/utils/safely'
import { walletAddressSelector } from 'src/web3/selectors'
import { call, delay, put, select, spawn, takeLeading } from 'typed-redux-saga'
Expand Down Expand Up @@ -970,9 +971,10 @@ export function* _initiateSendTxToProvider({
)
return receipt.transactionHash
}
const err = ensureError(error)
ValoraAnalytics.track(FiatExchangeEvents.cico_fc_transfer_tx_error, {
flow: CICOFlow.CashOut,
error: error.message,
error: err.message,
transferAddress: transferAddress,
provider: fiatConnectQuote.getProviderId(),
})
Expand All @@ -981,8 +983,8 @@ export function* _initiateSendTxToProvider({
// this check is not perfect; there may be false positives/negatives.
throw new FiatConnectTxError(
'Error while attempting to send funds for FiatConnect transfer out',
isTxPossiblyPending(error),
error
isTxPossiblyPending(err),
err
)
}

Expand Down Expand Up @@ -1034,15 +1036,16 @@ export function* handleCreateFiatConnectTransfer(
})
)
} catch (err) {
Logger.error(TAG, `Transfer for ${flow} failed..`, err)
const error = ensureError(err)
Logger.error(TAG, `Transfer for ${flow} failed..`, error)
ValoraAnalytics.track(FiatExchangeEvents.cico_fc_transfer_error, {
flow: CICOFlow.CashOut,
error: err.message,
error: error.message,
provider: fiatConnectQuote.getProviderId(),
})

if (err instanceof FiatConnectTxError) {
if (err.txPossiblyPending) {
if (error instanceof FiatConnectTxError) {
if (error.txPossiblyPending) {
yield* put(createFiatConnectTransferTxProcessing({ flow, quoteId }))
return
}
Expand Down
7 changes: 5 additions & 2 deletions src/identity/contactMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { SentryTransactionHub } from 'src/sentry/SentryTransactionHub'
import { SentryTransaction } from 'src/sentry/SentryTransactions'
import Logger from 'src/utils/Logger'
import { getAllContacts } from 'src/utils/contacts'
import { ensureError } from 'src/utils/ensureError'
import { checkContactsPermission } from 'src/utils/permissions'
import { getContractKit } from 'src/web3/contracts'
import networkConfig from 'src/web3/networkConfig'
Expand Down Expand Up @@ -78,7 +79,8 @@ export function* doImportContactsWrapper() {

Logger.debug(TAG, 'Done importing user contacts')
yield* put(endImportContacts(true))
} catch (error) {
} catch (err) {
const error = ensureError(err)
Logger.error(TAG, 'Error importing user contacts', error)
ValoraAnalytics.track(IdentityEvents.contacts_import_error, { error: error.message })
yield* put(showErrorOrFallback(error, ErrorMessages.IMPORT_CONTACTS_FAILED))
Expand Down Expand Up @@ -203,7 +205,8 @@ export function* fetchAddressesAndValidateSaga({
)
yield* put(endFetchingAddresses(e164Number, true))
ValoraAnalytics.track(IdentityEvents.phone_number_lookup_complete)
} catch (error) {
} catch (err) {
const error = ensureError(err)
Logger.debug(TAG + '@fetchAddressesAndValidate', `Error fetching addresses`, error)
yield* put(showErrorOrFallback(error, ErrorMessages.ADDRESS_LOOKUP_FAILURE))
yield* put(endFetchingAddresses(e164Number, false))
Expand Down
9 changes: 6 additions & 3 deletions src/identity/privateHashing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { waitForTransactionWithId } from 'src/transactions/saga'
import { newTransactionContext } from 'src/transactions/types'
import Logger from 'src/utils/Logger'
import { Currency } from 'src/utils/currencies'
import { ensureError } from 'src/utils/ensureError'
import { getAuthSignerForAccount } from 'src/web3/dataEncryptionKey'
import networkConfig from 'src/web3/networkConfig'
import { UnlockResult, getAccount, getAccountAddress, unlockAccount } from 'src/web3/saga'
Expand All @@ -40,7 +41,8 @@ export function* fetchPhoneHashPrivate(e164Number: string) {
try {
const details: PhoneNumberHashDetails = yield* call(doFetchPhoneHashPrivate, e164Number)
return details
} catch (error) {
} catch (err) {
const error = ensureError(err)
if (error.message === ErrorMessages.SALT_QUOTA_EXCEEDED) {
Logger.warn(`${TAG}@fetchPhoneHashPrivate`, 'Salt quota exceeded')

Expand Down Expand Up @@ -149,7 +151,8 @@ function* getPhoneHashPrivate(e164Number: string) {
unblindedSignature: identifierHashDetails.unblindedSignature,
}
return phoneNumberHashDetails
} catch (error) {
} catch (err) {
const error = ensureError(err)
if (error.message === ErrorMessages.ODIS_QUOTA_ERROR) {
throw new Error(ErrorMessages.SALT_QUOTA_EXCEEDED)
}
Expand Down Expand Up @@ -229,7 +232,7 @@ function* navigateToQuotaPurchaseScreen() {
ValoraAnalytics.track(IdentityEvents.phone_number_lookup_purchase_skip)
} else {
ValoraAnalytics.track(IdentityEvents.phone_number_lookup_purchase_error, {
error: error.message,
error: ensureError(error).message,
})
}
Logger.error(
Expand Down
6 changes: 4 additions & 2 deletions src/identity/revoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { fetchPhoneHashPrivate } from 'src/identity/privateHashing'
import { sendTransaction } from 'src/transactions/send'
import { newTransactionContext } from 'src/transactions/types'
import Logger from 'src/utils/Logger'
import { ensureError } from 'src/utils/ensureError'
import { setMtwAddress } from 'src/web3/actions'
import { getContractKit } from 'src/web3/contracts'
import { getAccountAddress, getConnectedUnlockedAccount } from 'src/web3/saga'
Expand Down Expand Up @@ -91,9 +92,10 @@ export function* revokeVerificationSaga() {
ValoraAnalytics.track(VerificationEvents.verification_revoke_finish, { feeless: !!mtwAddress })
Logger.showMessage('Address revoke was successful')
} catch (err) {
Logger.error(TAG + '@revokeVerification', 'Error revoking verification', err)
const error = ensureError(err)
Logger.error(TAG + '@revokeVerification', 'Error revoking verification', error)
ValoraAnalytics.track(VerificationEvents.verification_revoke_error, {
error: err.message,
error: error.message,
feeless: !!mtwAddress,
})

Expand Down
Loading

0 comments on commit 4b14031

Please sign in to comment.