Skip to content

Commit 334dd89

Browse files
authored
Merge pull request #5753 from EdgeApp/matthew/eslint-fixes
Re-enable no-misused-promises and no-dynamic-delete eslint rules
2 parents bc4e422 + cf195cc commit 334dd89

40 files changed

+1249
-1073
lines changed

eslint.config.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,6 @@ export default [
541541
rules: {
542542
'@typescript-eslint/ban-ts-comment': 'warn',
543543
'@typescript-eslint/explicit-function-return-type': 'warn',
544-
'@typescript-eslint/no-dynamic-delete': 'warn',
545-
'@typescript-eslint/no-misused-promises': 'warn',
546544
'@typescript-eslint/strict-boolean-expressions': 'warn',
547545
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'warn'
548546
}

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: 14 additions & 7 deletions
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'
@@ -101,7 +102,7 @@ const asServerDetails = asObject({
101102
const ENABLE_PERF_LOGGING = false
102103
const PERF_LOGGING_ONLY = false
103104

104-
const perfTimers: NumberMap = {}
105+
const perfTimers = new Map<string, number>()
105106
const perfCounters: NumberMap = {}
106107
const perfTotals: NumberMap = {}
107108

@@ -165,9 +166,9 @@ if (ENABLE_PERF_LOGGING) {
165166
perfTotals[label] = 0
166167
perfCounters[label] = 0
167168
}
168-
if (typeof perfTimers[label] === 'undefined') {
169+
if (typeof perfTimers.get(label) === 'undefined') {
169170
// @ts-expect-error
170-
perfTimers[label] = global.nativePerformanceNow()
171+
perfTimers.set(label, global.nativePerformanceNow())
171172
} else {
172173
clog(`${d}: PTIMER Error: PTimer already started: ${label}`)
173174
}
@@ -176,15 +177,16 @@ if (ENABLE_PERF_LOGGING) {
176177
// @ts-expect-error
177178
global.pend = function (label: string) {
178179
const d = makeDate()
179-
if (typeof perfTimers[label] === 'number') {
180+
const timer = perfTimers.get(label)
181+
if (typeof timer === 'number') {
180182
// @ts-expect-error
181-
const elapsed = global.nativePerformanceNow() - perfTimers[label]
183+
const elapsed = global.nativePerformanceNow() - timer
182184
perfTotals[label] += elapsed
183185
perfCounters[label]++
184186
clog(
185187
`${d}: PTIMER ${label}:${elapsed}ms total:${perfTotals[label]}ms count:${perfCounters[label]}`
186188
)
187-
delete perfTimers[label]
189+
perfTimers.delete(label)
188190
} else {
189191
clog(`${d}: PTIMER Error: PTimer not started: ${label}`)
190192
}
@@ -250,7 +252,7 @@ if (ENV.DEBUG_THEME) {
250252
method: 'GET'
251253
}
252254
let themeJson = ''
253-
setInterval(async () => {
255+
const updateTheme = async (): Promise<void> => {
254256
try {
255257
const response = await realFetch(url, getOptions)
256258
const overrideTheme = await response.json()
@@ -264,6 +266,11 @@ if (ENV.DEBUG_THEME) {
264266
} catch (e: any) {
265267
console.log(`Failed get theme`, e.message)
266268
}
269+
}
270+
setInterval(() => {
271+
updateTheme().catch((error: unknown) => {
272+
showError(error)
273+
})
267274
}, 3000)
268275
} catch (e: any) {
269276
console.log(`Failed to access theme server`)

src/components/FioAddress/ConnectWallets.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,20 @@ export const ConnectWallets = (props: FioConnectWalletsProps) => {
134134
): void => {
135135
if (value) {
136136
if (disconnectWalletsMap[item.key] != null) {
137-
delete disconnectWalletsMap[item.key]
137+
const { [item.key]: _, ...rest } = disconnectWalletsMap
138+
setDisconnectWalletsMap(rest)
138139
} else {
139-
connectWalletsMap[item.key] = item
140+
setConnectWalletsMap({ ...connectWalletsMap, [item.key]: item })
140141
}
141142
} else {
142143
if (connectWalletsMap[item.key] != null) {
143-
delete connectWalletsMap[item.key]
144+
const { [item.key]: _, ...rest } = connectWalletsMap
145+
setConnectWalletsMap(rest)
144146
} else {
145-
disconnectWalletsMap[item.key] = item
147+
setDisconnectWalletsMap({ ...disconnectWalletsMap, [item.key]: item })
146148
}
147149
}
148150

149-
setConnectWalletsMap({ ...connectWalletsMap })
150-
setDisconnectWalletsMap({ ...disconnectWalletsMap })
151151
flashListToggle = !flashListToggle
152152
}
153153

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>

0 commit comments

Comments
 (0)