Skip to content

Commit

Permalink
feat: add reverse tokens button
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Apr 20, 2022
1 parent 383a8a5 commit b0f826d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/widget/src/components/Header/NavigationHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const NavigationHeader: React.FC = () => {
> */}
{backButtonRoutes.includes(pathname) ? (
<IconButton
size="large"
size="medium"
aria-label="settings"
color="inherit"
edge="start"
Expand All @@ -80,7 +80,7 @@ export const NavigationHeader: React.FC = () => {
</Typography>
{pathname === '/' ? (
<IconButton
size="large"
size="medium"
aria-label="settings"
color="inherit"
edge="end"
Expand Down
4 changes: 2 additions & 2 deletions packages/widget/src/components/Header/WalletHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const WalletHeader: React.FC = () => {
</Typography>
</Box>
<IconButton
size="large"
size="medium"
aria-label="disconnect"
color="inherit"
edge="end"
Expand Down Expand Up @@ -79,7 +79,7 @@ const ConnectButton = () => {
};
return (
<IconButton
size="large"
size="medium"
aria-label="disconnect"
color="inherit"
edge="end"
Expand Down
31 changes: 31 additions & 0 deletions packages/widget/src/components/ReverseTokensButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { SwapVert as SwapVertIcon } from '@mui/icons-material';
import { IconButton } from '@mui/material';
import { useFormContext } from 'react-hook-form';
import { SwapFormKey } from '../providers/SwapFormProvider';

export const ReverseTokensButton: React.FC = () => {
const { setValue, getValues } = useFormContext();
const handleClick = () => {
const [fromChain, fromToken, toChain, toToken] = getValues([
SwapFormKey.FromChain,
SwapFormKey.FromToken,
SwapFormKey.ToChain,
SwapFormKey.ToToken,
]);
setValue(SwapFormKey.FromChain, toChain);
setValue(SwapFormKey.FromToken, toToken);
setValue(SwapFormKey.ToChain, fromChain);
setValue(SwapFormKey.ToToken, fromToken);
setValue(SwapFormKey.FromAmount, '');
};
return (
<IconButton
onClick={handleClick}
size="medium"
aria-label="swap-destinations"
color="inherit"
>
<SwapVertIcon />
</IconButton>
);
};
2 changes: 1 addition & 1 deletion packages/widget/src/hooks/useSwapRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const useSwapRoutes = () => {
{
enabled: isEnabled,
refetchIntervalInBackground: true,
refetchInterval: 60_000,
refetchInterval: 30_000,
staleTime: 30_000,
// TODO: probably should be removed
cacheTime: 30_000,
Expand Down
4 changes: 2 additions & 2 deletions packages/widget/src/pages/SwapPage/SwapPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SwapVert as SwapVertIcon } from '@mui/icons-material';
import { Box } from '@mui/material';
import { ReverseTokensButton } from '../../components/ReverseTokensButton';
import { SelectTokenButton } from '../../components/SelectTokenButton';
import { SwapButton } from '../../components/SwapButton';
import { SwapRoutes } from '../../components/SwapRoutes';
Expand All @@ -15,7 +15,7 @@ export const SwapPage: React.FC = () => {
sx={{ display: 'flex', justifyContent: 'center', height: 40 }}
py={0.5}
>
<SwapVertIcon sx={{ alignSelf: 'center', padding: '0 16px' }} />
<ReverseTokensButton />
</Box>
<Box mb={3}>
<SelectTokenButton formType="to" />
Expand Down

0 comments on commit b0f826d

Please sign in to comment.