Skip to content

Commit

Permalink
feat: update for swap
Browse files Browse the repository at this point in the history
  • Loading branch information
DenSmolonski committed Oct 8, 2024
1 parent e1bcc22 commit 35416e1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 58 deletions.
2 changes: 1 addition & 1 deletion lib/hooks/useNavItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default function useNavItems(): ReturnType {
icon: 'gear',
subItems: [
{
text: 'Swap',
text: 'Get ONE',
nextRoute: { pathname: '/swap' as const },
isActive: pathname.startsWith('/swap'),
},
Expand Down
2 changes: 1 addition & 1 deletion ui/shared/TextSeparator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { StyleProps } from '@chakra-ui/styled-system';
import React from 'react';

const TextSeparator = ({ id, ...props }: StyleProps & { id?: string }) => {
return <chakra.span mx={ 3 } id={ id } { ...props }>|</chakra.span>;
return <chakra.span mx={ props.mx || 3 } id={ id } { ...props }>|</chakra.span>;
};

export default React.memo(TextSeparator);
32 changes: 4 additions & 28 deletions ui/snippets/topBar/SwapButton.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,23 @@
import { Button, Box } from '@chakra-ui/react';
import { useRouter } from 'next/router';
import React from 'react';

import { route } from 'nextjs-routes';

import config from 'configs/app';
import getPageType from 'lib/mixpanel/getPageType';
import * as mixpanel from 'lib/mixpanel/index';
import IconSvg from 'ui/shared/IconSvg';

const feature = config.features.swapButton;

const SwapButton = () => {
const router = useRouter();
const source = getPageType(router.pathname);

const handleClick = React.useCallback(() => {
mixpanel.logEvent(mixpanel.EventTypes.BUTTON_CLICK, { Content: 'Swap button', Source: source });
}, [ source ]);

if (!feature.isEnabled) {
return null;
}

const href = 'url' in feature ?
feature.url :
route({ pathname: '/apps/[id]', query: { id: feature.dappId, action: 'connect' } });

return (
<Button
as="a"
href={ href }
target={ 'url' in feature ? '_blank' : '_self' }
href="/swap"
target="_self"
variant="solid"
size="xs"
borderRadius="sm"
height={ 5 }
px={ 1.5 }
onClick={ handleClick }
>
<IconSvg name="swap" boxSize={ 3 } mr={{ base: 0, sm: 1 }}/>
<Box display={{ base: 'none', sm: 'inline' }}>
Swap
<Box display={{ base: 'none', md: 'inline' }}>
Get ONE
</Box>
</Button>
);
Expand Down
45 changes: 21 additions & 24 deletions ui/snippets/topBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import ColorModeSwitch from './ColorModeSwitch';
import SwapButton from './SwapButton';
import TopBarStats from './TopBarStats';

const feature = config.features.swapButton;

const AddressSwitcher = () => {
const { setFormat, isEthFormat } = useAddressFormatContext();

Expand All @@ -26,15 +24,14 @@ const AddressSwitcher = () => {

return (
<>
<Text fontSize="sm" mr={ 2 }>
ONE / ETH address
<Text fontSize="xs" mr={ 2 } color="text_secondary">
ONE/ETH
</Text>
<Switch
isChecked={ isEthFormat }
onChange={ handleSwitchChange }
colorScheme="teal"
size="md"
mr={ 3 }
size={{ base: 'sm', sm: 'md' }}
/>
</>
);
Expand Down Expand Up @@ -71,24 +68,24 @@ const TopBar = () => {
>
<TopBarStats/>
<Flex alignItems="center">
<AddressSwitcher/>
<Divider
mr={ 3 }
ml={{ base: 2, sm: 3 }}
height={ 4 }
orientation="vertical"
/>
{ feature.isEnabled && (
<>
<SwapButton/>
<Divider
mr={ 3 }
ml={{ base: 2, sm: 3 }}
height={ 4 }
orientation="vertical"
/>
</>
) }
<>
<AddressSwitcher/>
<Divider
mr={ 3 }
ml={{ base: 2, sm: 3 }}
height={ 4 }
orientation="vertical"
/>
</>
<>
<SwapButton/>
<Divider
mr={ 3 }
ml={{ base: 2, sm: 3 }}
height={ 4 }
orientation="vertical"
/>
</>
<ColorModeSwitch/>
</Flex>
</Flex>
Expand Down
10 changes: 6 additions & 4 deletions ui/snippets/topBar/TopBarStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ const TopBarStats = () => {
{ data?.coin_price && (
<Flex columnGap={ 1 }>
<Skeleton isLoaded={ !isPlaceholderData }>
<chakra.span color="text_secondary">{ config.chain.governanceToken.symbol || config.chain.currency.symbol } </chakra.span>
<span>${ Number(data.coin_price).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 6 }) }</span>
<chakra.span color="text_secondary" mr={ 1 } display={{ base: 'none', md: 'initial' }}>
{ config.chain.governanceToken.symbol || config.chain.currency.symbol }
</chakra.span>
<span>${ Number(data.coin_price).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 4 }) }</span>
</Skeleton>
{ data.coin_price_change_percentage && (
<Skeleton isLoaded={ !isPlaceholderData }>
<Skeleton isLoaded={ !isPlaceholderData } display={{ base: 'none', md: 'initial' }}>
<chakra.span color={ Number(data.coin_price_change_percentage) >= 0 ? 'green.500' : 'red.500' }>
{ Number(data.coin_price_change_percentage).toFixed(2) }%
</chakra.span>
</Skeleton>
) }
</Flex>
) }
{ data?.coin_price && config.features.gasTracker.isEnabled && <TextSeparator color="divider"/> }
{ data?.coin_price && config.features.gasTracker.isEnabled && <TextSeparator mx={{ base: 1, md: 3 }} color="divider"/> }
{ data?.gas_prices && data.gas_prices.average !== null && config.features.gasTracker.isEnabled && (
<Skeleton isLoaded={ !isPlaceholderData }>
<chakra.span color="text_secondary">Gas </chakra.span>
Expand Down

0 comments on commit 35416e1

Please sign in to comment.