Skip to content

Commit

Permalink
Enable exhaustive switch checking
Browse files Browse the repository at this point in the history
  • Loading branch information
swansontec authored and Jon-edge committed Dec 9, 2022
1 parent 6fce7ca commit 7ccc21b
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 33 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
"globals": {
"fetch": true
},
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"rules": {
"@typescript-eslint/switch-exhaustiveness-check": "error"
}
}
],
"parserOptions": {
"project": "tsconfig.json"
},
Expand Down
24 changes: 11 additions & 13 deletions src/actions/CryptoExchangeActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ export function getQuoteForTransaction(info: SetNativeAmountInfo, onApprove: ()
dispatch(selectWalletForExchange(fromWalletId, currencyCode, 'to'))
}
break
case 'cancel':
case undefined:
break
}
}
dispatch(processSwapQuoteError(error))
Expand Down Expand Up @@ -294,28 +297,23 @@ function processSwapQuoteError(error: unknown): ThunkAction<void> {
}

const permissionError = asMaybeSwapPermissionError(error)
if (permissionError != null) {
switch (permissionError.reason) {
case 'geoRestriction': {
return dispatch({
type: 'GENERIC_SHAPE_SHIFT_ERROR',
data: s.strings.ss_geolock
})
}
}
if (permissionError?.reason === 'geoRestriction') {
return dispatch({
type: 'GENERIC_SHAPE_SHIFT_ERROR',
data: s.strings.ss_geolock
})
}

// Some plugins get this error wrong:
// @ts-expect-error
if (error.message === 'InsufficientFundsError') {
const message = error instanceof Error ? error.message : String(error)
if (message === 'InsufficientFundsError') {
return dispatch({ type: 'RECEIVED_INSUFFICIENT_FUNDS_ERROR' })
}

// Anything else:
const typeHack: any = error
return dispatch({
type: 'GENERIC_SHAPE_SHIFT_ERROR',
data: typeHack.message
data: message
})
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/actions/SendConfirmationActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ export function sendConfirmationUpdateTx(
dispatch(selectWalletForExchange(walletId, currencyCode, 'to'))
Actions.jump('exchangeScene', {})
break
case 'cancel':
case undefined:
break
}
}
const typeHack: any = error
Expand Down
21 changes: 12 additions & 9 deletions src/actions/WalletListMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,29 @@ export function walletListMenuAction(
label: s.strings.transaction_details_show_advanced_block_explorer,
type: 'secondary'
}
Airship.show(bridge => (
const buttons = xpubExplorer != null ? { copy, link } : { copy }

Airship.show<'copy' | 'link' | undefined>(bridge => (
<ButtonsModal
// @ts-expect-error
bridge={bridge}
buttons={xpubExplorer != null ? { copy, link } : { copy }}
buttons={buttons as { copy: ButtonInfo; link: ButtonInfo }}
closeArrow
message={displayPublicSeed ?? ''}
title={s.strings.fragment_wallets_view_xpub}
/>
// @ts-expect-error
)).then((result: 'copy' | 'link' | undefined) => {
)).then(result => {
switch (result) {
case 'copy':
// @ts-expect-error
Clipboard.setString(displayPublicSeed)
Clipboard.setString(displayPublicSeed ?? '')
showToast(s.strings.fragment_wallets_pubkey_copied_title)
break
case 'link':
// @ts-expect-error
if (xpubExplorer != null) Linking.openURL(sprintf(currencyInfo.xpubExplorer, displayPublicSeed))
if (xpubExplorer != null) {
Linking.openURL(sprintf(xpubExplorer, displayPublicSeed))
}
break
case undefined:
break
}
})
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/scenes/SettingsScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ export class SettingsSceneComponent extends React.Component<Props, State> {
case 'TouchID':
this.setState({ touchIdText: s.strings.settings_button_use_touchID })
break
// @ts-expect-error
// @ts-expect-error This is supposed to handle Android:
case 'Fingerprint':
this.setState({ touchIdText: s.strings.settings_button_use_biometric })
break

case false:
break
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/components/services/SortedWalletList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ export function SortedWalletList(props: Props) {
)
break

case 'manual':
break

case 'name':
sorted = stableSort(
wallets,
Expand Down
6 changes: 4 additions & 2 deletions src/controllers/loan-manager/redux/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ export const loanManager = combineReducers<LoanManagerState, Action>({
case 'LOAN_MANAGER/SET_SYNC_RATIO': {
return Date.now()
}
default:
return state
}
return state
},
syncRatio(state: number = 0, action: Action): number {
switch (action.type) {
case 'LOAN_MANAGER/SET_SYNC_RATIO': {
return action.syncRatio
}
default:
return state
}
return state
}
})
6 changes: 4 additions & 2 deletions src/reducers/AccountReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ const accountInner = combineReducers<AccountState, Action>({
const promotions = state.promotions.filter(promo => promo.installerId !== installerId)
return { ...state, promotions }
}
default:
return state
}
return state
},

accountReferralLoaded(state: boolean = false, action: Action): boolean {
Expand All @@ -79,8 +80,9 @@ const accountInner = combineReducers<AccountState, Action>({
const cache = action.data
return cache
}
default:
return state
}
return state
}
})

Expand Down
6 changes: 4 additions & 2 deletions src/reducers/CoreReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export const core = combineReducers<CoreState, Action>({
return action.data.account
case 'LOGOUT':
return defaultAccount
default:
return state
}
return state
},

context(state: EdgeContext = defaultContext, action: Action): EdgeContext {
Expand All @@ -51,8 +52,9 @@ export const core = combineReducers<CoreState, Action>({
return true
case 'LOGOUT':
return false
default:
return state
}
return state
},

// Nested reducers:
Expand Down
12 changes: 8 additions & 4 deletions src/reducers/RootReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ export const rootReducer = combineReducers<RootState, Action>({
return action.data.exchangeRates
case 'LOGOUT':
return {}
default:
return state
}
return state
},

nextUsername(state: string | null = null, action: Action): string | null {
Expand All @@ -69,8 +70,9 @@ export const rootReducer = combineReducers<RootState, Action>({
const { username = null } = action.data
return username
}
default:
return state
}
return state
},

pendingDeepLink(state: DeepLink | null = null, action: Action): DeepLink | null {
Expand All @@ -79,8 +81,9 @@ export const rootReducer = combineReducers<RootState, Action>({
return action.data
case 'DEEP_LINK_HANDLED':
return null
default:
return state
}
return state
},

priceChangeNotifications(
Expand All @@ -91,8 +94,9 @@ export const rootReducer = combineReducers<RootState, Action>({
switch (action.type) {
case 'PRICE_CHANGE_NOTIFICATIONS_UPDATE':
return action.data
default:
return state
}
return state
},

sortedWalletList(state: WalletListItem[] = [], action: Action): WalletListItem[] {
Expand Down

0 comments on commit 7ccc21b

Please sign in to comment.