Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor #55

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface AmountInputProps {

// TODO: Fetch dot price and show how much is the currency amount worth.

const AmountInput = ({
export const AmountInput = ({
amount,
currency,
title,
Expand Down Expand Up @@ -60,5 +60,3 @@ const AmountInput = ({
</>
);
};

export default AmountInput;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface BannerProps {
severity: 'info' | 'error' | 'warning' | 'success';
}

const Banner = ({ content, severity }: BannerProps) => {
export const Banner = ({ content, severity }: BannerProps) => {
const [open, setOpen] = useState(true);

const handleClose = () => {
Expand Down Expand Up @@ -36,5 +36,3 @@ const Banner = ({ content, severity }: BannerProps) => {
</Alert>
);
};

export default Banner;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface FeatureCardProps {
href: string;
}

const FeatureCard = ({
export const FeatureCard = ({
title,
buttonText,
image,
Expand Down Expand Up @@ -50,5 +50,3 @@ const FeatureCard = ({
</Card>
);
};

export default FeatureCard;
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Filters = {
regionEndFilter: (_listing: Listing) => boolean;
};

const MarketFilters = ({ listings, setFilteredListings }: Props) => {
export const MarketFilters = ({ listings, setFilteredListings }: Props) => {
const [filters, setFilters] = useState<Filters>({
coreOccupancyFilter: () => true,
durationFilter: () => true,
Expand Down Expand Up @@ -112,5 +112,3 @@ const MarketFilters = ({ listings, setFilteredListings }: Props) => {
</Box>
);
};

export default MarketFilters;
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface ProgressProps {
sections: Section[];
}

const Progress = ({ progress, sections }: ProgressProps) => {
export const Progress = ({ progress, sections }: ProgressProps) => {
return (
<Box position='relative' width='100%' height='20px'>
<BorderLinearProgress variant='determinate' value={progress} />
Expand Down Expand Up @@ -62,5 +62,3 @@ const Progress = ({ progress, sections }: ProgressProps) => {
</Box>
);
};

export default Progress;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface SaleInfoGridProps {
saleEnd: number;
}

const SaleInfoGrid = ({
export const SaleInfoGrid = ({
saleInfo,
currentPhase,
currentPrice,
Expand Down Expand Up @@ -116,5 +116,3 @@ const SaleInfoGrid = ({
</Box>
);
};

export default SaleInfoGrid;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface StatusIndicatorProps {
state: ApiState;
label: string;
}

export const StatusIndicator = ({ state, label }: StatusIndicatorProps) => {
const theme = useTheme();
return (
Expand Down
10 changes: 10 additions & 0 deletions src/components/Elements/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export * from './AmountInput';
export * from './Banner';
export * from './FeatureCard';
export * from './Label';
export * from './ListingCard';
export * from './MarketFilters';
export * from './Progress';
export * from './RegionCard';
export * from './SaleInfo';
export * from './StatusIndicator';
2 changes: 1 addition & 1 deletion src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Divider, Paper, useTheme } from '@mui/material';
import React, { ReactElement } from 'react';

import styles from './index.module.scss';
import Banner from '../elements/Banner';
import { Banner } from '../Elements';
import { Header } from '../Header';
import { Sidebar } from '../Sidebar';

Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/Interlace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useInkathon } from '@scio-labs/use-inkathon';
import { CoreMask } from 'coretime-utils';
import { useEffect, useState } from 'react';

import { RegionCard } from '@/components/elements';
import { RegionCard } from '@/components/Elements';

import { useCoretimeApi } from '@/contexts/apis';
import { useRegions } from '@/contexts/regions';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/Partition/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { useInkathon } from '@scio-labs/use-inkathon';
import { useEffect, useState } from 'react';

import { RegionCard } from '@/components/elements';
import { RegionCard } from '@/components/Elements';

import { useCoretimeApi } from '@/contexts/apis';
import { useCommon } from '@/contexts/common';
Expand Down
9 changes: 4 additions & 5 deletions src/components/Modals/Purchase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { contractTx, useContract, useInkathon } from '@scio-labs/use-inkathon';
import { useState } from 'react';

import { ListingCard } from '@/components/elements/ListingCard';
import { ListingCard } from '@/components/Elements/ListingCard';

import { CONTRACT_MARKET } from '@/contexts/apis/consts';
import { useToast } from '@/contexts/toast';
Expand Down Expand Up @@ -65,10 +65,9 @@ export const PurchaseModal = ({
setWorking(false);
} catch (e: any) {
toastError(
`Failed to purchase region from sale. Error: ${
e.errorMessage === 'Error'
? 'Please check your balance.'
: e.errorMessage
`Failed to purchase region from sale. Error: ${e.errorMessage === 'Error'
? 'Please check your balance.'
: e.errorMessage
}`
);
setWorking(false);
Expand Down
15 changes: 6 additions & 9 deletions src/components/Modals/Sell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import { contractTx, useContract, useInkathon } from '@scio-labs/use-inkathon';
import { Region } from 'coretime-utils';
import { useEffect, useState } from 'react';

import { RegionCard } from '@/components/elements';
import AmountInput from '@/components/elements/AmountInput';
import { RecipientSelector } from '@/components/elements/RecipientSelector';
import { AmountInput, RegionCard } from '@/components/Elements';
import { RecipientSelector } from '@/components/Selectors/RecipientSelector';

import { CONTRACT_MARKET, CONTRACT_XC_REGIONS } from '@/contexts/apis/consts';
import { useRegions } from '@/contexts/regions';
Expand Down Expand Up @@ -86,8 +85,7 @@ export const SellModal = ({
setWorking(false);
} catch (e: any) {
toastError(
`Failed to approve the region. Error: ${
e.errorMessage === 'Error' ? 'Please check your balance.' : e
`Failed to approve the region. Error: ${e.errorMessage === 'Error' ? 'Please check your balance.' : e
}`
);
setWorking(false);
Expand Down Expand Up @@ -128,10 +126,9 @@ export const SellModal = ({
setWorking(false);
} catch (e: any) {
toastError(
`Failed to list the region. Error: ${
e.errorMessage === 'Error'
? 'Please check your balance.'
: e.errorMessage
`Failed to list the region. Error: ${e.errorMessage === 'Error'
? 'Please check your balance.'
: e.errorMessage
}`
);
setWorking(false);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/TaskAssign/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { useInkathon } from '@scio-labs/use-inkathon';
import { useEffect, useState } from 'react';

import { RegionCard } from '@/components/elements';
import { RegionCard } from '@/components/Elements';

import { useCoretimeApi, useRelayApi } from '@/contexts/apis';
import { useRegions } from '@/contexts/regions';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/Transfer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
transferRegionOnCoretimeChain,
} from '@/utils/native/transfer';

import { RegionCard } from '@/components/elements';
import { RegionCard } from '@/components/Elements';

import { useCoretimeApi } from '@/contexts/apis';
import { CONTRACT_XC_REGIONS } from '@/contexts/apis/consts';
Expand Down
9 changes: 4 additions & 5 deletions src/components/Modals/Unlist/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { contractTx, useContract, useInkathon } from '@scio-labs/use-inkathon';
import { Region } from 'coretime-utils';
import { useState } from 'react';

import { RegionCard } from '@/components/elements';
import { RegionCard } from '@/components/Elements';

import { CONTRACT_MARKET } from '@/contexts/apis/consts';
import { useMarket } from '@/contexts/market';
Expand Down Expand Up @@ -72,10 +72,9 @@ export const UnlistModal = ({
setWorking(false);
} catch (e: any) {
toastError(
`Failed to unlist region from sale. Error: ${
e.errorMessage === 'Error'
? 'Please check your balance.'
: e.errorMessage
`Failed to unlist region from sale. Error: ${e.errorMessage === 'Error'
? 'Please check your balance.'
: e.errorMessage
}`
);
setWorking(false);
Expand Down
2 changes: 2 additions & 0 deletions src/components/Modals/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export * from './Interlace';
export * from './Partition';
export * from './Purchase';
export * from './Sell';
export * from './TaskAssign';
export * from './Transfer';
export * from './Unlist';
export * from './WalletConnect';
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,3 @@ export const ChainSelector = ({ chain, setChain }: ChainSelectorProps) => {
</FormControl>
);
};

const page = () => {
return <></>;
};

export default page;
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,3 @@ export const RegionSelector = ({
</FormControl>
);
};

const page = () => {
return <></>;
};

export default page;
3 changes: 3 additions & 0 deletions src/components/Selectors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './ChainSelector';
export * from './RecipientSelector';
export * from './RegionSelector';
7 changes: 3 additions & 4 deletions src/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ApiState } from '@/contexts/apis/types';
import { TransferIcon } from '@/icons';

import styles from './index.module.scss';
import { StatusIndicator } from '../elements';
import { StatusIndicator } from '../Elements';

interface MenuItemProps {
label: string;
Expand All @@ -27,9 +27,8 @@ const MenuItem = ({ label, enabled, route, icon }: MenuItemProps) => {

return (
<Box
className={`${styles.menuItem} ${
isActive ? styles.active : styles.inactive
} ${!enabled ? styles.disabled : ''}`}
className={`${styles.menuItem} ${isActive ? styles.active : styles.inactive
} ${!enabled ? styles.disabled : ''}`}
onClick={() => enabled && route && push(route)}
>
{{
Expand Down
3 changes: 0 additions & 3 deletions src/components/elements/index.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './elements';
export * from './Elements';
export * from './Header';
export * from './Layout';
export * from './Modals';
export * from './Selectors';
export * from './Sidebar';
2 changes: 1 addition & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import '../../styles/global.scss';
import createEmotionCache from '@/utils/createEmotionCache';
import theme from '@/utils/muiTheme';

import { Layout } from '@/components/Layout';
import { Layout } from '@/components';

import {
CoretimeApiContextProvider,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, Grid, Typography, useTheme } from '@mui/material';

import FeatureCard from '@/components/elements/FeatureCard';
import { FeatureCard } from '@/components';

import Chart from '@/assets/chart.png';
import Config from '@/assets/config.png';
Expand Down
4 changes: 1 addition & 3 deletions src/pages/market/marketplace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { useEffect, useState } from 'react';

import theme from '@/utils/muiTheme';

import { ListingCard } from '@/components/elements/ListingCard';
import MarketFilters from '@/components/elements/MarketFilters';
import { PurchaseModal } from '@/components/Modals/Purchase';
import { ListingCard, MarketFilters, PurchaseModal } from '@/components';

import { useMarket } from '@/contexts/market';
import { Listing } from '@/models';
Expand Down
13 changes: 6 additions & 7 deletions src/pages/purchase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {
parseHNString,
} from '@/utils/functions';

import Progress, { Section } from '@/components/elements/Progress';
import SaleInfoGrid from '@/components/elements/SaleInfo';
import { Progress, SaleInfoGrid, Section } from '@/components';

import { useCoretimeApi } from '@/contexts/apis';
import { ApiState } from '@/contexts/apis/types';
Expand Down Expand Up @@ -209,11 +208,11 @@ const Purchase = () => {
</Box>
<Box>
{loading ||
!currentPhase ||
!saleEnd ||
!currentBlockNumber ||
!progress ||
!saleEndTimestamp ? (
!currentPhase ||
!saleEnd ||
!currentBlockNumber ||
!progress ||
!saleEndTimestamp ? (
<>
<Typography variant='h5' align='center'>
Connect your wallet
Expand Down
6 changes: 1 addition & 5 deletions src/pages/transfer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import {
transferRegionOnCoretimeChain,
} from '@/utils/native/transfer';

import { RegionCard } from '@/components';
import { RecipientSelector } from '@/components/elements/RecipientSelector';
import { ChainSelector, RecipientSelector, RegionCard, RegionSelector } from '@/components';

import { useCoretimeApi } from '@/contexts/apis';
import { CONTRACT_XC_REGIONS } from '@/contexts/apis/consts';
Expand All @@ -39,9 +38,6 @@ import { useToast } from '@/contexts/toast';
import XcRegionsMetadata from '@/contracts/xc_regions.json';
import { RegionLocation, RegionMetadata } from '@/models';

import { ChainSelector } from './ChainSelector';
import { RegionSelector } from './RegionSelector';

const Page = () => {
const { activeAccount, activeSigner, api: contractsApi } = useInkathon();
const { contract } = useContract(XcRegionsMetadata, CONTRACT_XC_REGIONS);
Expand Down