Skip to content

Commit

Permalink
feat: add skeleton to chain select
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Apr 5, 2022
1 parent 49260fb commit af62515
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions packages/widget/src/components/SelectTokenDrawer/ChainSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ListItemIcon,
MenuItem,
SelectChangeEvent,
Skeleton,
} from '@mui/material';
import { useFormContext, useWatch } from 'react-hook-form';
import { useChains } from '../../hooks/useChains';
Expand All @@ -18,7 +19,7 @@ import { Select } from '../Select';
export const ChainSelect = ({ formType }: SwapFormTypeProps) => {
const { setValue } = useFormContext();
const { fromChain, toChain } = useWidgetConfig();
const { chains } = useChains();
const { chains, isLoading } = useChains();
const [fromChainId, toChainId] = useWatch({
name: [SwapFormKey.FromChain, SwapFormKey.ToChain],
});
Expand All @@ -44,7 +45,7 @@ export const ChainSelect = ({ formType }: SwapFormTypeProps) => {
</MenuItem>
));

return (
return !isLoading ? (
<>
<FormControl
fullWidth
Expand Down Expand Up @@ -73,5 +74,12 @@ export const ChainSelect = ({ formType }: SwapFormTypeProps) => {
</Select>
</FormControl>
</>
) : (
<Skeleton
variant="rectangular"
width="100%"
height={45}
sx={{ borderRadius: '8px' }}
/>
);
};
4 changes: 2 additions & 2 deletions packages/widget/src/hooks/useChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useWidgetConfig } from '../providers/WidgetProvider';

export const useChains = () => {
const { enabledChains } = useWidgetConfig();
const { data, isLoading } = useQuery(['chains'], async () => {
const { data, ...other } = useQuery(['chains'], async () => {
const possibilities = await LiFi.getPossibilities({ include: ['chains'] });
return possibilities?.chains?.filter((chain) =>
enabledChains.includes(chain.id),
Expand All @@ -23,5 +23,5 @@ export const useChains = () => {
[data],
);

return { chains: data, isLoading, getChainById };
return { chains: data, getChainById, ...other };
};

0 comments on commit af62515

Please sign in to comment.