Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

William/strict boolean #4091

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{
"files": ["*.ts", "*.tsx"],
"rules": {
"@typescript-eslint/strict-boolean-expressions": "warn",
"@typescript-eslint/switch-exhaustiveness-check": "error"
}
}
Expand All @@ -36,7 +37,6 @@
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/return-await": "off",
"@typescript-eslint/strict-boolean-expressions": "off",

"react-native/no-inline-styles": "off",
"react-native/no-raw-text": [
Expand Down
4 changes: 2 additions & 2 deletions src/components/progress-indicators/FillLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ interface Props {

export class FillLoader extends React.Component<Props> {
render() {
const { size, indicatorStyles } = this.props
const { size = 'large', indicatorStyles } = this.props
return (
<View style={styles.loadingContainer}>
<ActivityIndicator color={THEME.COLORS.ACCENT_MINT} style={[styles.indicator, indicatorStyles]} size={size || 'large'} />
<ActivityIndicator color={THEME.COLORS.ACCENT_MINT} style={[styles.indicator, indicatorStyles]} size={size} />
</View>
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/progress-indicators/FullScreenLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ interface Props {

export class FullScreenLoader extends React.Component<Props> {
render() {
const { size, indicatorStyles } = this.props
const { size = 'large', indicatorStyles } = this.props
return (
<View style={styles.loadingContainer}>
<ActivityIndicator color={THEME.COLORS.ACCENT_MINT} style={[styles.indicator, indicatorStyles]} size={size || 'large'} />
<ActivityIndicator color={THEME.COLORS.ACCENT_MINT} style={[styles.indicator, indicatorStyles]} size={size} />
</View>
)
}
Expand Down
29 changes: 15 additions & 14 deletions src/components/scenes/RequestScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class RequestSceneComponent extends React.Component<Props, State> {
super(props)
const minimumPopupModalState: CurrencyMinimumPopupState = {}
Object.keys(SPECIAL_CURRENCY_INFO).forEach(pluginId => {
if (getSpecialCurrencyInfo(pluginId).minimumPopupModals) {
if (getSpecialCurrencyInfo(pluginId).minimumPopupModals != null) {
minimumPopupModalState[pluginId] = 'NOT_YET_SHOWN'
}
})
Expand Down Expand Up @@ -165,7 +165,7 @@ export class RequestSceneComponent extends React.Component<Props, State> {
const { pluginId } = wallet.currencyInfo

const didAddressChange = prevState.selectedAddress !== this.state.selectedAddress
const didWalletChange = prevProps.wallet && wallet.id !== prevProps.wallet.id
const didWalletChange = prevProps.wallet != null && wallet.id !== prevProps.wallet.id

if (didWalletChange) {
this.getAddressItems()
Expand Down Expand Up @@ -219,7 +219,7 @@ export class RequestSceneComponent extends React.Component<Props, State> {
}

flipInputRef = (ref: ExchangedFlipInput | null) => {
if (ref?.flipInput) {
if (ref?.flipInput != null) {
this.flipInput = ref.flipInput
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ export class RequestSceneComponent extends React.Component<Props, State> {
const { account } = this.props
Airship.show<WalletListResult>(bridge => <WalletListModal bridge={bridge} headerTitle={s.strings.select_wallet} navigation={this.props.navigation} />).then(
({ walletId, currencyCode }: WalletListResult) => {
if (walletId && currencyCode) {
if (walletId != null && currencyCode != null) {
const wallet = account.currencyWallets[walletId]
const tokenId = getTokenId(account, wallet.currencyInfo.pluginId, currencyCode)
this.props.onSelectWallet(this.props.navigation, walletId, tokenId)
Expand Down Expand Up @@ -413,7 +413,7 @@ export class RequestSceneComponent extends React.Component<Props, State> {
if (currencyCode !== wallet.currencyInfo.currencyCode) return false
const { pluginId } = wallet.currencyInfo

if (this.state.minimumPopupModalState[pluginId]) {
if (this.state.minimumPopupModalState[pluginId] != null) {
if (this.state.minimumPopupModalState[pluginId] === 'NOT_YET_SHOWN') {
const { minimumPopupModals } = getSpecialCurrencyInfo(pluginId)
const minBalance = minimumPopupModals != null ? minimumPopupModals.minimumNativeBalance : '0'
Expand All @@ -436,7 +436,8 @@ export class RequestSceneComponent extends React.Component<Props, State> {
let edgePayUri = 'https://deep.edge.app/'
let addOnMessage = ''
// if encoded (like XTZ), only share the public address
if (getSpecialCurrencyInfo(wallet.currencyInfo.pluginId).isUriEncodedStructure) {
const { isUriEncodedStructure = false } = getSpecialCurrencyInfo(wallet.currencyInfo.pluginId)
if (isUriEncodedStructure) {
sharedAddress = publicAddress
} else {
// Rebuild uri to preserve uriPrefix if amount is 0
Expand Down Expand Up @@ -467,12 +468,12 @@ export class RequestSceneComponent extends React.Component<Props, State> {
}

fioAddressModal = () => {
const { navigation } = this.props
const { navigation, fioAddressesExist = false } = this.props
if (!this.props.isConnected) {
showError(s.strings.fio_network_alert_text)
return
}
if (!this.props.fioAddressesExist) {
if (fioAddressesExist) {
showError(`${s.strings.title_register_fio_address}. ${s.strings.fio_request_by_fio_address_error_no_address}`)
return
}
Expand All @@ -491,25 +492,25 @@ export class RequestSceneComponent extends React.Component<Props, State> {
}

fioMode = () => {
if (this.flipInput && Platform.OS === 'ios') {
if (this.flipInput != null && Platform.OS === 'ios') {
this.flipInput.textInputBottomFocus()
this.setState({ isFioMode: true })
}
}

cancelFioMode = () => {
this.setState({ isFioMode: false }, () => {
if (this.flipInput) {
if (this.flipInput != null) {
this.flipInput.textInputBottomBlur()
}
})
}

nextFioMode = () => {
if (this.state.isFioMode && (!this.state.amounts || lte(this.state.amounts.nativeAmount, '0'))) {
if (this.state.isFioMode && (this.state.amounts == null || lte(this.state.amounts.nativeAmount, '0'))) {
showError(`${s.strings.fio_request_by_fio_address_error_invalid_amount_header}. ${s.strings.fio_request_by_fio_address_error_invalid_amount}`)
} else {
if (this.flipInput) {
if (this.flipInput != null) {
this.flipInput.textInputBottomBlur()
}
this.onNext()
Expand Down Expand Up @@ -603,7 +604,7 @@ export const RequestScene = connect<StateProps, DispatchProps, OwnProps>(
const secondaryExchangeDenomination: GuiDenomination = getDenomFromIsoCode(wallet.fiatCurrencyCode.replace('iso:', ''))
const secondaryDisplayDenomination: GuiDenomination = secondaryExchangeDenomination
const primaryExchangeCurrencyCode: string = primaryExchangeDenomination.name
const secondaryExchangeCurrencyCode: string = secondaryExchangeDenomination.name ? secondaryExchangeDenomination.name : ''
const secondaryExchangeCurrencyCode: string = secondaryExchangeDenomination.name
const tokenId = getTokenId(state.core.account, pluginId, currencyCode)

const primaryCurrencyInfo: GuiCurrencyInfo = {
Expand All @@ -624,7 +625,7 @@ export const RequestScene = connect<StateProps, DispatchProps, OwnProps>(
}
const isoFiatCurrencyCode: string = wallet.fiatCurrencyCode
const exchangeSecondaryToPrimaryRatio = getExchangeRate(state, currencyCode, isoFiatCurrencyCode)
const fioAddressesExist = !!state.ui.scenes.fioAddress.fioAddresses.length
const fioAddressesExist = !(state.ui.scenes.fioAddress.fioAddresses.length === 0)

return {
account,
Expand Down
2 changes: 1 addition & 1 deletion src/components/themed/FlipInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ export class FlipInputComponent extends React.PureComponent<Props, State> {
const onFocus = isFront ? this.textInputFrontFocusTrue : this.textInputBackFocusTrue
const onBlur = isFront ? this.textInputFrontFocusFalse : this.textInputBackFocusFalse
const ref = isFront ? this.getTextInputFrontRef : this.getTextInputBackRef
const displayAmountCheck = (decimalAmount.match(/^0*$/) && !showCursor) || displayAmount === ''
const displayAmountCheck = (/^0*$/.test(decimalAmount) && !showCursor) || displayAmount === ''
const displayAmountString = displayAmountCheck ? s.strings.string_amount : displayAmount
const displayAmountStyle = displayAmountCheck ? styles.bottomAmountMuted : styles.bottomAmount
const currencyNameStyle = displayAmountCheck ? styles.bottomCurrencyMuted : styles.bottomCurrency
Expand Down
14 changes: 10 additions & 4 deletions src/components/themed/SafeSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@ interface Props {
}

export const SafeSlider = (props: Props) => {
const { disabledText, disabled, onSlidingComplete, parentStyle, completePoint = COMPLETE_POINT } = props

const theme = useTheme()
const styles = getStyles(theme)
const {
completePoint = COMPLETE_POINT,
disabled,
disabledText = s.strings.select_exchange_amount_short,
onSlidingComplete,
parentStyle,
width = theme.confirmationSliderWidth
} = props

const [completed, setCompleted] = React.useState(false)

const { width = theme.confirmationSliderWidth } = props
const upperBound = width - theme.confirmationSliderThumbWidth
const widthStyle = { width }
const sliderDisabled = disabled || completed
const sliderText = !sliderDisabled ? s.strings.send_confirmation_slide_to_confirm : disabledText || s.strings.select_exchange_amount_short
const sliderText = !sliderDisabled ? s.strings.send_confirmation_slide_to_confirm : disabledText

const translateX = useSharedValue(upperBound)
const isSliding = useSharedValue(false)
Expand Down
46 changes: 23 additions & 23 deletions src/components/themed/SelectFioAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class SelectFioAddressComponent extends React.PureComponent<Props, LocalS
}
const fioAddress = fioAddresses.find(({ name }) => name === selected)
const prevFioAddress = prevFioAddresses.find(({ name }) => name === selected)
if (fioAddress && prevFioAddress && fioAddress.bundledTxs !== prevFioAddress.bundledTxs) {
if (fioAddress != null && prevFioAddress != null && fioAddress.bundledTxs !== prevFioAddress.bundledTxs) {
return {
bundledTxsUpdated: true,
prevFioAddresses: fioAddresses
Expand All @@ -78,24 +78,24 @@ export class SelectFioAddressComponent extends React.PureComponent<Props, LocalS
}

componentDidMount() {
const { fioRequest, isSendUsingFioAddress, refreshAllFioAddresses } = this.props
if (fioRequest || isSendUsingFioAddress) refreshAllFioAddresses()
if (fioRequest) {
const { fioRequest, isSendUsingFioAddress = false, refreshAllFioAddresses } = this.props
if (fioRequest == null || isSendUsingFioAddress) refreshAllFioAddresses()
if (fioRequest != null) {
this.setFioAddress(fioRequest.payer_fio_address)
} else if (isSendUsingFioAddress) {
this.setDefaultFioAddress()
}
}

componentDidUpdate(prevProps: Props) {
const { fioRequest, isSendUsingFioAddress } = this.props
const { fioRequest, isSendUsingFioAddress = false } = this.props
const { bundledTxsUpdated } = this.state
if (bundledTxsUpdated) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({ bundledTxsUpdated: false })
this.setFioAddress(this.props.selected)
}
if (isSendUsingFioAddress !== prevProps.isSendUsingFioAddress && !fioRequest && isSendUsingFioAddress) {
if (isSendUsingFioAddress !== prevProps.isSendUsingFioAddress && fioRequest == null && isSendUsingFioAddress) {
this.setDefaultFioAddress()
}
}
Expand All @@ -105,7 +105,7 @@ export class SelectFioAddressComponent extends React.PureComponent<Props, LocalS
this.setState({ loading: true })
for (const fioWallet of fioWallets) {
const fioNames = await fioWallet.otherMethods.getFioAddressNames()
if (fioNames.length) {
if (fioNames.length > 0) {
this.setState({ loading: false }, () => {
this.setFioAddress(fioNames[0], fioWallet)
})
Expand All @@ -119,7 +119,7 @@ export class SelectFioAddressComponent extends React.PureComponent<Props, LocalS
Airship.show<string | undefined>(bridge => (
<AddressModal bridge={bridge} title={s.strings.fio_select_address} currencyCode={currencyCode} walletId={selectedWalletId} useUserFioAddressesOnly />
)).then(response => {
if (response) {
if (response != null) {
this.setFioAddress(response)
}
})
Expand All @@ -143,31 +143,31 @@ export class SelectFioAddressComponent extends React.PureComponent<Props, LocalS

setFioAddress = async (fioAddress: string, fioWallet?: EdgeCurrencyWallet | null) => {
const { navigation, fioWallets, fioAddresses, fioRequest, currencyCode } = this.props
if (!fioWallet) {
if (fioAddresses && fioAddress.length) {
if (fioWallet == null) {
if (fioAddresses != null && fioAddress.length > 0) {
const selectedFioAddress = fioAddresses.find(({ name }) => name === fioAddress)
if (selectedFioAddress) {
if (selectedFioAddress != null) {
fioWallet = fioWallets.find(({ id }) => id === selectedFioAddress.walletId)
}
}
if (!fioWallet) {
if (fioWallet == null) {
fioWallet = await findWalletByFioAddress(fioWallets, fioAddress)
}
}
let error = ''

if (!fioWallet) {
if (fioWallet == null) {
error = s.strings.fio_select_address_no_wallet_err
showError(error)
return
}

try {
if (fioRequest || currencyCode === FIO_STR) {
if (fioRequest != null || currencyCode === FIO_STR) {
await checkRecordSendFee(fioWallet, fioAddress)
}
} catch (e: any) {
if (e.code && e.code === FIO_NO_BUNDLED_ERR_CODE) {
if (e?.code != null && e.code === FIO_NO_BUNDLED_ERR_CODE) {
this.props.onSelect(fioAddress, fioWallet, e.message)
const answer = await Airship.show<'ok' | 'cancel' | undefined>(bridge => (
<ButtonsModal
Expand Down Expand Up @@ -198,10 +198,10 @@ export class SelectFioAddressComponent extends React.PureComponent<Props, LocalS

handleMemoChange = (memo: string) => {
let memoError = ''
if (memo && memo.length > 64) {
if (memo !== '' && memo.length > 64) {
memoError = s.strings.send_fio_request_error_memo_inline
}
if (memo && !/^[\x20-\x7E]*$/.test(memo)) {
if (memo !== '' && !/^[\x20-\x7E]*$/.test(memo)) {
memoError = s.strings.send_fio_request_error_memo_invalid_character
}
this.props.onMemoChange(memo, memoError)
Expand All @@ -213,10 +213,10 @@ export class SelectFioAddressComponent extends React.PureComponent<Props, LocalS

return (
<Tile
type={loading && !selected ? 'loading' : fioRequest ? 'static' : 'touchable'}
type={loading && selected === '' ? 'loading' : fioRequest != null ? 'static' : 'touchable'}
title={s.strings.select_fio_address_address_from}
body={selected}
onPress={fioRequest ? undefined : this.selectAddress}
onPress={fioRequest != null ? undefined : this.selectAddress}
/>
)
}
Expand All @@ -229,7 +229,7 @@ export class SelectFioAddressComponent extends React.PureComponent<Props, LocalS
return null
}

if (memoError) {
if (memoError !== '') {
return (
<Tile type="touchable" title={s.strings.select_fio_address_address_memo_error} onPress={this.openMessageInput}>
<EdgeText style={{ color: theme.dangerText }}>{memoError}</EdgeText>
Expand All @@ -248,9 +248,9 @@ export class SelectFioAddressComponent extends React.PureComponent<Props, LocalS
}

render() {
const { fioRequest, isSendUsingFioAddress } = this.props
const { fioRequest, isSendUsingFioAddress = false } = this.props

if (!fioRequest && !isSendUsingFioAddress) {
if (fioRequest == null && !isSendUsingFioAddress) {
return null
}

Expand All @@ -269,7 +269,7 @@ export const SelectFioAddress = connect<StateProps, DispatchProps, OwnProps>(
const currencyCode: string = state.ui.wallets.selectedCurrencyCode

return {
loading: selectedWallet == null || !currencyCode,
loading: selectedWallet == null || currencyCode === '',
fioAddresses: state.ui.scenes.fioAddress.fioAddresses,
fioWallets: state.ui.wallets.fioWallets,
currencyCode,
Expand Down
Loading