Skip to content

Commit

Permalink
refactor: statuses to const
Browse files Browse the repository at this point in the history
  • Loading branch information
TravellerOnTheRun committed Mar 1, 2024
1 parent cab235d commit 91d075e
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/screens/profile/ProfileCreateScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ import {
ProfileStackScreenProps,
ProfileStatus,
} from 'navigation/profileNavigator/types'
import {
defaultIconSize,
sharedColors,
sharedStyles as sharedStylesConstants,
} from 'shared/constants'
import { defaultIconSize, sharedColors } from 'shared/constants'
import { sharedStyles } from 'shared/styles'
import { castStyle } from 'shared/utils'
import {
Expand All @@ -41,7 +37,6 @@ import {
import { selectProfile } from 'store/slices/profileSlice/selector'
import { selectChainId, selectRequests } from 'store/slices/settingsSlice'
import { useAppDispatch, useAppSelector } from 'store/storeUtils'
import { AppSpinner } from 'components/index'
import { AvatarIcon } from 'components/icons/AvatarIcon'
import { rootTabsRouteNames } from 'navigation/rootNavigator'
import { useGetRnsProcessor, useWallet } from 'shared/wallet'
Expand Down Expand Up @@ -73,6 +68,8 @@ export const ProfileCreateScreen = ({

const { displayAddress } = getAddressDisplayText(address, chainId)
const isRequestingAlias = status === ProfileStatus.REQUESTING
const isPurchasingProfile = status === ProfileStatus.PURCHASING
const isWaitingForCommit = status === ProfileStatus.WAITING_FOR_USER_COMMIT

const onSetEmail = useCallback(
(_email: string) => {
Expand Down Expand Up @@ -139,7 +136,7 @@ export const ProfileCreateScreen = ({

useEffect(() => {
const fn = async () => {
if (alias && status === ProfileStatus.REQUESTING) {
if (alias && isRequestingAlias) {
await dispatch(
commitment({
alias: alias.split('.rsk')[0],
Expand All @@ -149,18 +146,26 @@ export const ProfileCreateScreen = ({
}

if (requests.length === 0) {
if (status === ProfileStatus.WAITING_FOR_USER_COMMIT) {
if (isWaitingForCommit) {
// User got stuck in requesting the commit - set profileStatus back to 0
dispatch(setStatus(ProfileStatus.NONE))
}
if (status === ProfileStatus.PURCHASING) {
if (isPurchasingProfile) {
// User got stuck in requesting the purchase - set profileStatus back to 3
dispatch(setStatus(ProfileStatus.READY_TO_PURCHASE))
}
}
}
fn()
}, [dispatch, getRnsProcessor, alias, status, requests.length])
}, [
dispatch,
getRnsProcessor,
alias,
isRequestingAlias,
isWaitingForCommit,
isPurchasingProfile,
requests.length,
])

return (
<ScrollView
Expand Down Expand Up @@ -267,7 +272,7 @@ export const ProfileCreateScreen = ({
accessibilityLabel={'registerYourUserName'}
color={sharedColors.white}
textColor={sharedColors.black}
disabled={status === ProfileStatus.PURCHASING ? false : !!username}
disabled={isPurchasingProfile ? false : !!username}
onPress={() => {
navigation.navigate(profileStackRouteNames.SearchDomain)
}}
Expand Down

0 comments on commit 91d075e

Please sign in to comment.