forked from binary-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maryia/DTRA-403/feat: migrate Routes files in Trader package to TS (#38)
* feat: migrate routes files to ts * fix: routes extension * refactor: for consistency * refactor: import order * refactor: renamed prop types * refactor: type for consistency * refactor: remove index as key
- Loading branch information
1 parent
a6cd500
commit 729947f
Showing
17 changed files
with
159 additions
and
103 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
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
16 changes: 0 additions & 16 deletions
16
packages/trader/src/App/Components/Routes/binary-routes.jsx
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
packages/trader/src/App/Components/Routes/binary-routes.tsx
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,17 @@ | ||
import React from 'react'; | ||
import { Switch } from 'react-router-dom'; | ||
import getRoutesConfig from 'App/Constants/routes-config'; | ||
import { TBinaryRoutesProps, TRouteConfig } from 'Types'; | ||
import RouteWithSubRoutes from './route-with-sub-routes'; | ||
|
||
const BinaryRoutes = (props: TBinaryRoutesProps) => ( | ||
<React.Suspense fallback={<div />}> | ||
<Switch> | ||
{getRoutesConfig().map((route: TRouteConfig) => ( | ||
<RouteWithSubRoutes key={route.getTitle?.()} {...route} {...props} /> | ||
))} | ||
</Switch> | ||
</React.Suspense> | ||
); | ||
|
||
export default BinaryRoutes; |
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
import { matchPath, RouteProps } from 'react-router'; | ||
import { routes } from '@deriv/shared'; | ||
import { TRouteConfig } from 'Types'; | ||
|
||
export const normalizePath = (path = '') => (/^\//.test(path) ? path : `/${path || ''}`); // Default to '/' | ||
|
||
export const findRouteByPath = (path: string, routes_config?: TRouteConfig[]): RouteProps | undefined => { | ||
let result: RouteProps | undefined; | ||
|
||
routes_config?.some(route_info => { | ||
let match_path; | ||
try { | ||
match_path = matchPath(path, route_info); | ||
} catch (e: unknown) { | ||
if (/undefined/.test((e as Error).message)) { | ||
return undefined; | ||
} | ||
} | ||
|
||
if (match_path) { | ||
result = route_info; | ||
return true; | ||
} else if (route_info.routes) { | ||
result = findRouteByPath(path, route_info.routes); | ||
return result; | ||
} | ||
return false; | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
export const isRouteVisible = (route?: TRouteConfig, is_logged_in?: boolean) => | ||
!(route && route.is_authenticated && !is_logged_in); | ||
|
||
export const getPath = (route_path: string, params: { [key: string]: string } = {}) => | ||
Object.keys(params).reduce((p, name) => p.replace(`:${name}`, params[name]), route_path); | ||
|
||
export const getContractPath = (contract_id = '') => getPath(routes.contract, { contract_id }); |
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
import BinaryLink from './binary-link'; | ||
import RouteWithSubRoutes from './route-with-sub-routes'; | ||
import BinaryRoutes from './binary-routes'; | ||
|
||
export * from './helpers'; | ||
export { BinaryLink, RouteWithSubRoutes }; | ||
export default BinaryRoutes; |
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.