Skip to content

Commit

Permalink
✨get exa
Browse files Browse the repository at this point in the history
  • Loading branch information
sebipap committed Sep 28, 2023
1 parent 980b15e commit ab8b1d8
Show file tree
Hide file tree
Showing 29 changed files with 1,888 additions and 84 deletions.
8 changes: 3 additions & 5 deletions components/BridgeContent/SocketPlugIn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import { optimism } from 'viem/chains';
import useAnalytics from 'hooks/useAnalytics';
import { hexToRgb } from './utils';
import useAssetAddresses from 'hooks/useAssetAddresses';
import { Asset, TokensResponse } from 'types/Bridge';
import { Asset, NATIVE_TOKEN_ADDRESS, TokensResponse } from 'types/Bridge';

const DynamicBridge = dynamic(() => import('@socket.tech/plugin').then((mod) => mod.Bridge), {
ssr: false,
});

const NATIVE_TOKEN = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';

type Props = {
updateRoutes: () => void;
};
Expand Down Expand Up @@ -53,7 +51,7 @@ const SocketPlugIn = ({ updateRoutes }: Props) => {
}, [fetchAssets]);

const tokenList = useMemo(() => {
const markets = [...assets, NATIVE_TOKEN];
const markets = [...assets, NATIVE_TOKEN_ADDRESS];
if (!tokens) return [];

return tokens
Expand Down Expand Up @@ -144,7 +142,7 @@ const SocketPlugIn = ({ updateRoutes }: Props) => {
API_KEY={process.env.NEXT_PUBLIC_SOCKET_API_KEY || ''}
defaultSourceNetwork={chain?.id || optimism.id}
defaultDestNetwork={optimism.id}
defaultDestToken={NATIVE_TOKEN}
defaultDestToken={NATIVE_TOKEN_ADDRESS}
customize={{
primary: hexToRgb(palette.components.bg),
secondary: hexToRgb(palette.components.bg),
Expand Down
9 changes: 7 additions & 2 deletions components/BridgeContent/SocketTxHistory/AssetAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import Image from 'next/image';
import formatNumber from 'utils/formatNumber';
import { formatUnits } from 'viem';

type Props = { asset: Asset; amount: number; mobile?: boolean; chains?: Chain[] };
type Props = {
asset: Pick<Asset, 'chainId' | 'decimals' | 'logoURI' | 'symbol'>;
amount: number;
mobile?: boolean;
chains?: Chain[];
};

const AssetAmount = ({ asset, amount, mobile, chains }: Props) => {
const chain = useMemo(() => {
Expand All @@ -17,7 +22,7 @@ const AssetAmount = ({ asset, amount, mobile, chains }: Props) => {
<Box display={'flex'} flexDirection={'column'} gap={1.5}>
<Box display={'flex'} alignItems={'center'} height={16} gap={0.5}>
<Image
src={asset.logoURI}
src={asset.logoURI || ''}
alt={asset.symbol}
width={mobile ? 24 : 16}
height={mobile ? 24 : 16}
Expand Down
2 changes: 1 addition & 1 deletion components/DropdownMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const DropdownMenu = <T,>({
},
}}
>
{Object.values(options).map((o) => (
{options.map((o) => (
<OptionItem
key={JSON.stringify(o, (_, value) => (typeof value === 'bigint' ? String(value) : value))}
onClick={() => {
Expand Down
6 changes: 3 additions & 3 deletions components/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,19 @@ function Navbar() {
pathname: '/security',
name: t('Security Hub'),
icon: <GppGoodRoundedIcon sx={{ fontSize: '13px' }} />,
isNew: true,
isNew: false,
},
{
pathname: '/activity',
name: t('Activity Monitor'),
icon: <MonitorHeartRoundedIcon sx={{ fontSize: '13px' }} />,
isNew: true,
isNew: false,
},
{
pathname: '/revoke',
name: t('Revoke Allowances'),
icon: <RemoveCircleOutlineRoundedIcon sx={{ fontSize: '13px' }} />,
isNew: true,
isNew: false,
},
]}
/>
Expand Down
3 changes: 1 addition & 2 deletions components/StakingModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { waitForTransaction } from '@wagmi/core';
import { ModalBox, ModalBoxCell, ModalBoxRow } from 'components/common/modal/ModalBox';
import SocketAssetSelector from 'components/SocketAssetSelector';
import useSocketAssets from 'hooks/useSocketAssets';
import { AssetBalance } from 'types/Bridge';
import { AssetBalance, NATIVE_TOKEN_ADDRESS } from 'types/Bridge';
import ModalInput from 'components/OperationsModal/ModalInput';
import Link from 'next/link';
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
Expand All @@ -64,7 +64,6 @@ import useDelayedEffect from 'hooks/useDelayedEffect';
import { gasLimit } from 'utils/gas';
import { useModal } from 'contexts/ModalContext';

const NATIVE_TOKEN_ADDRESS = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
const MIN_SUPPLY = parseEther('0.002');
const PROTO_STAKER_DOCS = 'https://docs.exact.ly/guides/periphery/proto-staker';

Expand Down
97 changes: 97 additions & 0 deletions components/getEXA/AssetSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React, { memo } from 'react';
import { useTranslation } from 'react-i18next';

import DropdownMenu from 'components/DropdownMenu';
import { Asset } from 'types/Bridge';
import { optimism } from 'wagmi/chains';
import { Box, Skeleton, Typography } from '@mui/material';
import Image from 'next/image';
import useBalance from 'hooks/useBalance';
import formatNumber from 'utils/formatNumber';
import { useGetEXA } from 'contexts/GetEXAContext';
import useSocketAssets from 'hooks/useSocketAssets';

type AssetOptionProps = {
asset?: Asset;
option?: boolean;
optionSize?: number;
selectedSize?: number;
chainId: number;
};

function AssetOption({ asset, option = false, optionSize = 17, selectedSize = 14, chainId }: AssetOptionProps) {
const size = option ? optionSize : selectedSize;
const balance = useBalance(asset?.symbol, asset?.address as `0x${string}`, true, chainId);

if (!asset) {
return <Skeleton width={80} />;
}

return (
<Box
display="flex"
gap={1}
my={0.5}
mx={option ? 0.5 : 0}
alignContent="center"
alignItems="center"
justifyContent="center"
>
{asset.logoURI && (
<Image
src={asset.logoURI}
alt={asset.symbol}
width={size}
height={size}
style={{
borderRadius: '100%',
}}
/>
)}
<>
{option ? (
<>
<Box display="flex" alignItems="center">
<Box>
<Typography fontWeight={600} fontSize={14} color="grey.900">
{asset.name}
</Typography>
<Typography fontSize={10} color="grey.900">
{asset.symbol}
</Typography>
</Box>
</Box>
<Box ml="auto">
<Typography fontSize={8}>{balance && Number(balance) ? formatNumber(balance) : ''}</Typography>
</Box>
</>
) : (
<Typography fontWeight={600} fontSize={14} color="grey.900">
{asset.symbol}
</Typography>
)}
</>
</Box>
);
}

function AssetSelector() {
const { t } = useTranslation();
const { setAsset, asset, chain } = useGetEXA();
const assets = useSocketAssets();

if (!assets) return null;

return (
<DropdownMenu
label={t('Asset')}
options={assets}
onChange={setAsset}
renderValue={<AssetOption asset={asset} chainId={chain?.chainId || optimism.id} />}
renderOption={(o: Asset) => <AssetOption option asset={o} chainId={chain?.chainId || optimism.id} />}
data-testid="modal-asset-selector"
/>
);
}

export default memo(AssetSelector);
79 changes: 79 additions & 0 deletions components/getEXA/ChainSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React, { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next';

import { Box, Skeleton, Typography } from '@mui/material';
import DropdownMenu from 'components/DropdownMenu';
import { useGetEXA } from 'contexts/GetEXAContext';
import Image from 'next/image';
import { Chain } from 'types/Bridge';
type AssetOptionProps = {
chain?: Chain;
option?: boolean;
optionSize?: number;
selectedSize?: number;
};

function ChainOption({ chain, option = false, optionSize = 17, selectedSize = 14 }: AssetOptionProps) {
const size = option ? optionSize : selectedSize;

if (!chain) {
return <Skeleton width={80} />;
}

return (
<Box
display="flex"
gap={0.5}
my={0.5}
mx={option ? 0.5 : 0}
alignContent="center"
alignItems="center"
justifyContent="center"
>
{chain.icon && (
<Image
src={chain.icon}
alt={chain.name}
width={size}
height={size}
style={{
borderRadius: '100%',
}}
/>
)}
<Typography fontWeight={600} fontSize={size} color="grey.900">
{chain.name}
</Typography>
</Box>
);
}

const ChainSelector = ({ disabled }: { disabled?: boolean }) => {
const { t } = useTranslation();

const { setChain: onChainChange, chains, chain } = useGetEXA();

const handleChainChange = useCallback(
(value: string) => {
const c = chains?.find(({ name }) => value === name);
if (c) onChainChange(c);
},
[chains, onChainChange],
);

if (!chains) return <Skeleton width={100} />;

return (
<DropdownMenu
label={t('Asset')}
options={chains.map(({ name }) => name)}
onChange={handleChainChange}
renderValue={<ChainOption chain={chain} />}
renderOption={(o: string) => <ChainOption option chain={chains.find(({ name }) => o === name)} />}
data-testid="modal-asset-selector"
disabled={disabled}
/>
);
};

export default memo(ChainSelector);
Loading

0 comments on commit ab8b1d8

Please sign in to comment.