Skip to content

Commit

Permalink
fix: set correct header name for token selection
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Feb 21, 2022
1 parent 6996495 commit 68d20e9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/widget/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const App: React.FC<AppProps> = ({ config }) => {
path={routes.home}
element={<SwapPage settingsRef={settingsRef} />}
>
<Route path={routes.selectToken} element={null} />
<Route path={routes.fromToken} element={null} />
<Route path={routes.toToken} element={null} />
<Route path={routes.settings} element={null} />
</Route>
</Routes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
useState,
} from 'react';
import { useMatch, useNavigate } from 'react-router-dom';
import { SwapFormDirection } from '../../providers/SwapFormProvider';
import { ElementId } from '../../utils/elements';
import { routes } from '../../utils/routes';
import { routes, RouteType } from '../../utils/routes';
import { ContainerDrawerBase, ContainerDrawerProps } from './types';

export const ContainerDrawer = forwardRef<
Expand All @@ -23,9 +24,12 @@ export const ContainerDrawer = forwardRef<
);

const openDrawer = useCallback(
(args) => {
navigate(routes[route], { replace: true });
onOpen?.(args);
(formType?: SwapFormDirection, routeKey?: RouteType) => {
const to = routeKey ? routes[routeKey] : route ? routes[route] : null;
if (to) {
navigate(to, { replace: true });
}
onOpen?.(formType);
setOpen(true);
},
[navigate, onOpen, route],
Expand Down
6 changes: 3 additions & 3 deletions packages/widget/src/components/ContainerDrawer/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { DrawerProps } from '@mui/material';
import { RefObject } from 'react';
import { SwapFormDirection } from '../../providers/SwapFormProvider';
import { routes } from '../../utils/routes';
import { RouteType } from '../../utils/routes';

export type ContainerDrawerProps = DrawerProps & {
elementRef?: RefObject<HTMLDivElement>;
onOpen?(args: any): void;
route: keyof typeof routes;
route?: RouteType;
};

export interface ContainerDrawerBase {
openDrawer(formType: SwapFormDirection): void;
openDrawer(formType?: SwapFormDirection, route?: RouteType): void;
closeDrawer(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NavigationHeaderProps } from '.';
import { routes } from '../../utils/routes';
import { Header } from '../Header';

const routesWithBack = [routes.settings, routes.selectToken];
const routesWithBack = [routes.settings, routes.fromToken, routes.toToken];

export const NavigationHeader: React.FC<NavigationHeaderProps> = ({
settingsRef,
Expand All @@ -30,8 +30,10 @@ export const NavigationHeader: React.FC<NavigationHeaderProps> = ({
switch (location.pathname) {
case routes.settings:
return t(`header.settings`);
case routes.selectToken:
return t(`header.wouldLikeToSwap`);
case routes.fromToken:
return t(`swap.from`);
case routes.toToken:
return t(`swap.to`);
default:
return t(`header.swap`);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/widget/src/components/SelectTokenDrawer/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { SwapFormDirection } from '../../providers/SwapFormProvider';
import { RouteType } from '../../utils/routes';

export interface SelectTokenDrawerBase {
openDrawer(formType: SwapFormDirection): void;
openDrawer(formType: SwapFormDirection, route: RouteType): void;
closeDrawer(): void;
}

Expand Down
5 changes: 4 additions & 1 deletion packages/widget/src/utils/routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export const routes = {
home: '/',
settings: '/settings',
selectToken: '/select-token',
fromToken: '/select-from-token',
toToken: '/select-to-token',
};

export type RouteType = keyof typeof routes;

0 comments on commit 68d20e9

Please sign in to comment.