Skip to content

Commit eb50a17

Browse files
peachbitsswansontec
authored andcommitted
Fix @typescript-eslint/no-misused-promises
1 parent bc4e422 commit eb50a17

33 files changed

+1185
-1021
lines changed

eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ export default [
542542
'@typescript-eslint/ban-ts-comment': 'warn',
543543
'@typescript-eslint/explicit-function-return-type': 'warn',
544544
'@typescript-eslint/no-dynamic-delete': 'warn',
545-
'@typescript-eslint/no-misused-promises': 'warn',
546545
'@typescript-eslint/strict-boolean-expressions': 'warn',
547546
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'warn'
548547
}

src/actions/CountryListActions.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,26 @@ export const checkAndSetRegion = (props: {
2828
countryCode: string
2929
stateProvinceCode?: string
3030
}): ThunkAction<void> => {
31-
return async (dispatch, getState) => {
31+
return (dispatch, getState) => {
3232
const { countryCode, stateProvinceCode } = props
3333

3434
if (countryCode == null || countryCode === '') {
3535
// If no countryCode, always show country selection
36-
await dispatch(showCountrySelectionModal(props))
36+
dispatch(showCountrySelectionModal(props)).catch((error: unknown) => {
37+
showError(error)
38+
})
3739
} else {
3840
// Show state province selection if stateProvinceCode is required according
3941
// to the country data
4042
const countryData = COUNTRY_CODES.find(
4143
cc => cc['alpha-2'] === countryCode
4244
)
4345
if (countryData != null && stateProvinceCode == null) {
44-
await dispatch(
46+
dispatch(
4547
showCountrySelectionModal({ ...props, skipCountry: true })
46-
)
48+
).catch((error: unknown) => {
49+
showError(error)
50+
})
4751
}
4852
}
4953
}

src/actions/LoginActions.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,15 @@ export function initializeAccount(
216216
)}
217217
/>
218218
))
219-
.finally(async () => {
219+
.finally(() => {
220220
for (const pluginId of pluginIdsNeedingUserAction) {
221221
const currencyConfig = account.currencyConfig[pluginId]
222222
const { userSettings = {} } = currencyConfig
223-
await currencyConfig.changeUserSettings(userSettings)
223+
currencyConfig
224+
.changeUserSettings(userSettings)
225+
.catch((error: unknown) => {
226+
showError(error)
227+
})
224228
}
225229
})
226230
.catch(err => {

src/actions/PaymentProtoActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export async function launchPaymentProto(
405405
tokenId,
406406
lockTilesMap: { amount: true, address: true, fee: requiredFeeRate != null },
407407
onBack,
408-
onDone: async (error: Error | null, edgeTransaction?: EdgeTransaction) => {
408+
onDone: (error: Error | null, edgeTransaction?: EdgeTransaction) => {
409409
if (error)
410410
showError(
411411
`${lstrings.create_wallet_account_error_sending_transaction}: ${error.message}`

src/app.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getVersion } from 'react-native-device-info'
1414
import RNFS from 'react-native-fs'
1515

1616
import { initDeviceSettings } from './actions/DeviceSettingsActions'
17+
import { showError } from './components/services/AirshipInstance'
1718
import { changeTheme, getTheme } from './components/services/ThemeContext'
1819
import { ENV } from './env'
1920
import type { NumberMap } from './types/types'
@@ -250,7 +251,7 @@ if (ENV.DEBUG_THEME) {
250251
method: 'GET'
251252
}
252253
let themeJson = ''
253-
setInterval(async () => {
254+
const updateTheme = async (): Promise<void> => {
254255
try {
255256
const response = await realFetch(url, getOptions)
256257
const overrideTheme = await response.json()
@@ -264,6 +265,11 @@ if (ENV.DEBUG_THEME) {
264265
} catch (e: any) {
265266
console.log(`Failed get theme`, e.message)
266267
}
268+
}
269+
setInterval(() => {
270+
updateTheme().catch((error: unknown) => {
271+
showError(error)
272+
})
267273
}, 3000)
268274
} catch (e: any) {
269275
console.log(`Failed to access theme server`)

src/components/cards/EarnOptionCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface Props {
2222
/** If false, show "Stake"/"Earn"
2323
* If true, show "Staked"/"Earned" */
2424
isOpenPosition?: boolean
25-
onPress?: () => void
25+
onPress?: () => Promise<void>
2626
}
2727

2828
export function EarnOptionCard(props: Props) {

src/components/modals/CategoryModal.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { useDispatch, useSelector } from '../../types/reactRedux'
2020
import { scale } from '../../util/scaling'
2121
import { MinimalButton } from '../buttons/MinimalButton'
2222
import { EdgeTouchableOpacity } from '../common/EdgeTouchableOpacity'
23+
import { showError } from '../services/AirshipInstance'
2324
import { cacheStyles, type Theme, useTheme } from '../services/ThemeContext'
2425
import { DividerLine } from '../themed/DividerLine'
2526
import { EdgeText } from '../themed/EdgeText'
@@ -117,9 +118,11 @@ export function CategoryModal(props: Props) {
117118
bridge.resolve(fullCategory)
118119
}
119120

120-
const handleSubmit = useHandler(async () => {
121+
const handleSubmit = useHandler(() => {
121122
const fullCategory = joinCategory({ category, subcategory })
122-
await handleCategoryUpdate(fullCategory)
123+
handleCategoryUpdate(fullCategory).catch((error: unknown) => {
124+
showError(error)
125+
})
123126
})
124127

125128
const keyExtractor = useHandler((row: CategoryRow) => row.raw)

src/components/modals/PasswordReminderModal.tsx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,32 @@ export class PasswordReminderModalComponent extends React.PureComponent<
6464
}
6565
}
6666

67-
handleSubmit = async () => {
67+
handleSubmit = (): void => {
6868
const { bridge, account } = this.props
6969
const { password } = this.state
7070

71-
const isValidPassword = await account.checkPassword(password).catch(err => {
72-
showError(err)
73-
})
74-
if (isValidPassword) {
75-
this.props.dispatch({
76-
type: 'PASSWORD_REMINDER_MODAL/CHECK_PASSWORD_SUCCESS'
71+
account
72+
.checkPassword(password)
73+
.then(isValidPassword => {
74+
if (isValidPassword) {
75+
this.props.dispatch({
76+
type: 'PASSWORD_REMINDER_MODAL/CHECK_PASSWORD_SUCCESS'
77+
})
78+
this.setState({ checkingPassword: false })
79+
showToast(lstrings.password_reminder_great_job)
80+
setTimeout(() => {
81+
bridge.resolve()
82+
}, 10)
83+
} else {
84+
this.setState({
85+
errorMessage: lstrings.password_reminder_invalid,
86+
checkingPassword: false
87+
})
88+
}
7789
})
78-
this.setState({ checkingPassword: false })
79-
showToast(lstrings.password_reminder_great_job)
80-
setTimeout(() => {
81-
bridge.resolve()
82-
}, 10)
83-
} else {
84-
this.setState({
85-
errorMessage: lstrings.password_reminder_invalid,
86-
checkingPassword: false
90+
.catch(err => {
91+
showError(err)
8792
})
88-
}
8993
}
9094

9195
handleChangeText = (password: string) => {

src/components/modals/SwapVerifyTermsModal.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import FastImage from 'react-native-fast-image'
66

77
import { lstrings } from '../../locales/strings'
88
import { getSwapPluginIconUri } from '../../util/CdnUris'
9-
import { Airship } from '../services/AirshipInstance'
9+
import { Airship, showError } from '../services/AirshipInstance'
1010
import { cacheStyles, type Theme, useTheme } from '../services/ThemeContext'
1111
import { UnscaledText } from '../text/UnscaledText'
1212
import { Paragraph } from '../themed/EdgeText'
@@ -88,6 +88,12 @@ function SwapVerifyTermsModal(props: Props) {
8888
const theme = useTheme()
8989
const styles = getStyles(theme)
9090

91+
const handleLink = (url: string): void => {
92+
Linking.openURL(url).catch((error: unknown) => {
93+
showError(error)
94+
})
95+
}
96+
9197
return (
9298
<EdgeModal
9399
bridge={bridge}
@@ -125,23 +131,29 @@ function SwapVerifyTermsModal(props: Props) {
125131
{termsUri == null ? null : (
126132
<UnscaledText
127133
style={styles.linkText}
128-
onPress={async () => await Linking.openURL(termsUri)}
134+
onPress={() => {
135+
handleLink(termsUri)
136+
}}
129137
>
130138
{lstrings.swap_terms_terms_link}
131139
</UnscaledText>
132140
)}
133141
{privacyUri == null ? null : (
134142
<UnscaledText
135143
style={styles.linkText}
136-
onPress={async () => await Linking.openURL(privacyUri)}
144+
onPress={() => {
145+
handleLink(privacyUri)
146+
}}
137147
>
138148
{lstrings.swap_terms_privacy_link}
139149
</UnscaledText>
140150
)}
141151
{kycUri == null ? null : (
142152
<UnscaledText
143153
style={styles.linkText}
144-
onPress={async () => await Linking.openURL(kycUri)}
154+
onPress={() => {
155+
handleLink(kycUri)
156+
}}
145157
>
146158
{lstrings.swap_terms_kyc_link}
147159
</UnscaledText>

src/components/modals/TransferModal.tsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useHandler } from '../../hooks/useHandler'
1212
import { lstrings } from '../../locales/strings'
1313
import { config } from '../../theme/appConfig'
1414
import { useDispatch } from '../../types/reactRedux'
15-
import { Airship } from '../services/AirshipInstance'
15+
import { Airship, showError } from '../services/AirshipInstance'
1616
import { type Theme, useTheme } from '../services/ThemeContext'
1717
import { SelectableRow } from '../themed/SelectableRow'
1818
import { EdgeModal } from './EdgeModal'
@@ -55,42 +55,51 @@ export const TransferModal = ({
5555
Airship.clear()
5656
})
5757

58-
const handleSend = useHandler(async () => {
59-
const result = await Airship.show<WalletListResult>(bridge => (
58+
const handleSend = useHandler(() => {
59+
Airship.show<WalletListResult>(bridge => (
6060
<WalletListModal
6161
bridge={bridge}
6262
headerTitle={lstrings.select_wallet_to_send_from}
6363
navigation={navigation}
6464
/>
6565
))
66-
if (result?.type === 'wallet') {
67-
const { walletId, tokenId } = result
68-
navigation.push('send2', {
69-
walletId,
70-
tokenId,
71-
hiddenFeaturesMap: { scamWarning: false }
66+
.then(result => {
67+
if (result?.type === 'wallet') {
68+
const { walletId, tokenId } = result
69+
navigation.push('send2', {
70+
walletId,
71+
tokenId,
72+
hiddenFeaturesMap: { scamWarning: false }
73+
})
74+
}
75+
Airship.clear()
76+
})
77+
.catch((error: unknown) => {
78+
showError(error)
7279
})
73-
}
74-
Airship.clear()
7580
})
7681

77-
const handleReceive = useHandler(async () => {
82+
const handleReceive = useHandler(() => {
7883
Airship.clear()
7984

80-
const result = await Airship.show<WalletListResult>(bridge => (
85+
Airship.show<WalletListResult>(bridge => (
8186
<WalletListModal
8287
bridge={bridge}
8388
headerTitle={lstrings.select_receive_asset}
8489
navigation={navigation}
8590
showCreateWallet
8691
/>
8792
))
88-
89-
if (result?.type === 'wallet') {
90-
const { walletId, tokenId } = result
91-
await dispatch(selectWalletToken({ navigation, walletId, tokenId }))
92-
navigation.navigate('request', { tokenId, walletId })
93-
}
93+
.then(async result => {
94+
if (result?.type === 'wallet') {
95+
const { walletId, tokenId } = result
96+
await dispatch(selectWalletToken({ navigation, walletId, tokenId }))
97+
navigation.navigate('request', { tokenId, walletId })
98+
}
99+
})
100+
.catch((error: unknown) => {
101+
showError(error)
102+
})
94103
})
95104

96105
const handleCancel = useHandler(() => {

0 commit comments

Comments
 (0)