-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
freeze enabled, memoization, refactor
- Loading branch information
Showing
26 changed files
with
218 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/navigator/navigation-bar/hooks/use-navigation-bar-button.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import { emptyFn } from 'src/config/general'; | ||
import { ScreensEnum } from 'src/navigator/enums/screens.enum'; | ||
import { useNavigation } from 'src/navigator/hooks/use-navigation.hook'; | ||
import { useColors } from 'src/styles/use-colors'; | ||
|
||
import { NavigationBarButton } from '../interfaces/navigation-bar-button.interface'; | ||
|
||
export const useNavigationBarButton = ({ | ||
focused, | ||
routeName, | ||
swapScreenParams, | ||
disabled = false, | ||
disabledOnPress = emptyFn | ||
}: Omit<NavigationBarButton, 'iconWidth'>) => { | ||
const colors = useColors(); | ||
const { navigate } = useNavigation(); | ||
|
||
const color = useMemo(() => { | ||
let value = colors.gray1; | ||
focused && (value = colors.orange); | ||
disabled && (value = colors.disabled); | ||
|
||
return value; | ||
}, [colors, focused, disabled]); | ||
|
||
const handlePress = () => { | ||
if (disabled) { | ||
disabledOnPress(); | ||
} else { | ||
if (routeName === ScreensEnum.SwapScreen) { | ||
navigate(routeName, swapScreenParams); | ||
} else { | ||
navigate(routeName); | ||
} | ||
} | ||
}; | ||
|
||
return { | ||
color, | ||
colors, | ||
handlePress | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import { useNetworkInfo } from 'src/hooks/use-network-info.hook'; | ||
import { ScreensEnum } from 'src/navigator/enums/screens.enum'; | ||
import { useNavigation } from 'src/navigator/hooks/use-navigation.hook'; | ||
import { showErrorToast } from 'src/toast/error-toast.utils'; | ||
import { TokenInterface } from 'src/token/interfaces/token.interface'; | ||
import { isDefined } from 'src/utils/is-defined'; | ||
|
||
const NOT_AVAILABLE_MESSAGE = 'Not available on this RPC node'; | ||
|
||
type RouteType = { params?: { token: TokenInterface } }; | ||
export type RouteParams = { name: string } & RouteType; | ||
|
||
export const useNavigationBar = (currentRouteName: ScreensEnum) => { | ||
const { isDcpNode } = useNetworkInfo(); | ||
const { getState } = useNavigation(); | ||
|
||
const routes = getState().routes[0].state?.routes; | ||
const route = getTokenParams(routes as RouteParams[]); | ||
const swapScreenParams = | ||
isDefined(route) && currentRouteName === ScreensEnum.TokenScreen ? { inputToken: route.params?.token } : undefined; | ||
|
||
const isStackFocused = useCallback( | ||
(screensStack: ScreensEnum[]) => isDefined(currentRouteName) && screensStack.includes(currentRouteName), | ||
[currentRouteName] | ||
); | ||
|
||
const handleDisabledPress = useCallback(() => showErrorToast({ description: NOT_AVAILABLE_MESSAGE }), []); | ||
|
||
return { | ||
isDcpNode, | ||
swapScreenParams, | ||
isStackFocused, | ||
handleDisabledPress | ||
}; | ||
}; | ||
|
||
const getTokenParams = (routes: RouteParams[] | undefined): null | RouteType => { | ||
let result = null; | ||
if (Array.isArray(routes) && isDefined(routes)) { | ||
for (const route of routes) { | ||
if (route.name === ScreensEnum.TokenScreen) { | ||
result = route; | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
}; |
19 changes: 19 additions & 0 deletions
19
src/navigator/navigation-bar/interfaces/navigation-bar-button.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { IconNameEnum } from 'src/components/icon/icon-name.enum'; | ||
import { ScreensEnum, ScreensParamList } from 'src/navigator/enums/screens.enum'; | ||
|
||
export interface NavigationBarButton { | ||
label: string; | ||
iconName: IconNameEnum; | ||
iconWidth: number; | ||
routeName: | ||
| ScreensEnum.Wallet | ||
| ScreensEnum.DApps | ||
| ScreensEnum.SwapScreen | ||
| ScreensEnum.Market | ||
| ScreensEnum.CollectiblesHome; | ||
focused: boolean; | ||
disabled?: boolean; | ||
showNotificationDot?: boolean; | ||
swapScreenParams?: ScreensParamList[ScreensEnum.SwapScreen]; | ||
disabledOnPress?: EmptyFn; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/navigator/navigation-bar/side-bar/side-bar-button/side-bar-button.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.