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

Parachain Management #100

Merged
merged 33 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
245432a
WIP: reserve & register modals
TopETH May 9, 2024
e75e92b
Merge branch 'master' into parachain-management
TopETH May 9, 2024
2697abd
reservation cost
TopETH May 9, 2024
59fcf70
refactor formatBalance
TopETH May 9, 2024
fe16621
more refactoring for balances
TopETH May 9, 2024
a0d6de0
reservation modal working
TopETH May 9, 2024
773b2cc
fix build
TopETH May 10, 2024
41d93a0
fix styles
TopETH May 10, 2024
56c7f46
show table
TopETH May 10, 2024
805bbd7
default token name and decimals
cuteolaf May 13, 2024
3aa59ba
reservation working, state
TopETH May 14, 2024
9ecfb9d
Update src/pages/paras/index.tsx
Szegoo May 14, 2024
2ad1a47
Update src/pages/paras/index.tsx
Szegoo May 14, 2024
35b21e4
buy coretime
TopETH May 14, 2024
2dbee8e
parachains soon active
TopETH May 14, 2024
391b3a5
no action required for 'soon active'
TopETH May 14, 2024
9ea137b
registration modal
cuteolaf May 14, 2024
5e16da4
merge remote branch
cuteolaf May 14, 2024
17df1ce
revert the revert :)
Szegoo May 14, 2024
19c1f31
fix
cuteolaf May 14, 2024
adb9f72
Merge branch 'parachain-management' of github.com:regionx-labs/corehu…
cuteolaf May 14, 2024
509058f
fix
Szegoo May 14, 2024
89a6a90
fix duplicated
TopETH May 14, 2024
cface09
fix
TopETH May 14, 2024
b6a815d
Merge branch 'master' into parachain-management
TopETH May 15, 2024
d48f7cc
fix format balance
TopETH May 15, 2024
e654c75
lease holding and system paras
Szegoo May 15, 2024
b98915b
lint fix
Szegoo May 15, 2024
743912a
fix build
Szegoo May 15, 2024
c3c195e
rename parathread to 'ondemand parachain'
TopETH May 15, 2024
80f9416
pass para id to the renewal page
TopETH May 15, 2024
ce774af
Update src/pages/paras/index.tsx
Szegoo May 15, 2024
bb18b7b
Update src/pages/paras/index.tsx
Szegoo May 15, 2024
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"react": "^18.2.0",
"react-countdown-circle-timer": "^3.2.1",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"sass": "^1.48.0",
"sharp": "^0.32.6"
},
Expand Down
20 changes: 15 additions & 5 deletions src/components/Elements/Balance/index.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
import { Box, Typography, useTheme } from '@mui/material';

import { formatBalance } from '@/utils/functions';
import { getBalanceString } from '@/utils/functions';

import { useAccounts } from '@/contexts/account';
import { useCoretimeApi, useRelayApi } from '@/contexts/apis';

import styles from './index.module.scss';

interface BalanceProps {
coretimeBalance: number;
relayBalance: number;
symbol: string;
}

const Balance = ({ relayBalance, coretimeBalance, symbol }: BalanceProps) => {
const Balance = ({ relayBalance, coretimeBalance }: BalanceProps) => {
const theme = useTheme();
const {
state: { activeAccount },
} = useAccounts();
const {
state: { decimals: relayDecimals, symbol: relaySymbol },
} = useRelayApi();
const {
state: { decimals: coretimeDecimals, symbol: coretimeSymbol },
} = useCoretimeApi();

const items = [
{
label: 'Relay Chain',
value: relayBalance,
symbol: relaySymbol,
decimals: relayDecimals,
},
{
label: 'Coretime Chain',
value: coretimeBalance,
symbol: coretimeSymbol,
decimals: coretimeDecimals,
},
];

return activeAccount ? (
<Box className={styles.container}>
{items.map(({ label, value }, index) => (
{items.map(({ label, value, symbol, decimals }, index) => (
<Box key={index} className={styles.balanceItem}>
<Typography sx={{ color: theme.palette.text.primary }}>
{label}
Expand All @@ -43,7 +53,7 @@ const Balance = ({ relayBalance, coretimeBalance, symbol }: BalanceProps) => {
}}
className={styles.balanceWrapper}
>
{`${formatBalance(value.toString(), false)} ${symbol}`}
{getBalanceString(value.toString(), decimals, symbol)}
</Box>
</Box>
))}
Expand Down
52 changes: 52 additions & 0 deletions src/components/Elements/InputFile/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.container {
display: flex;
flex-direction: column;
justify-content: center;
flex: 1 0 0;
width: 15rem;
height: 7.5rem;
position: relative;
background-color: #f6f7fa;
color: #000;
border: 1px solid #888;
border-radius: 0.5rem;
cursor: pointer;
user-select: none;
}

.upload {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 0.5rem;
flex-grow: 1;
}

.fileName,
.fileSize {
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
}

.fileSize {
font-size: 0.75rem;
}

.fileName {
margin: 0.25rem 0.5rem;
}

.hasFile {
display: flex;
flex-direction: column;
padding: 1.25rem 1rem;
}

.closeIcon {
position: absolute;
top: 4px;
right: 4px;
padding: 0;
}
123 changes: 123 additions & 0 deletions src/components/Elements/InputFile/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import CloseIcon from '@mui/icons-material/Close';
import { IconButton } from '@mui/material';
import { hexToU8a, isHex, u8aToString } from '@polkadot/util';
import React, { createRef, useCallback, useState } from 'react';
import type { DropzoneRef } from 'react-dropzone';
import { useDropzone } from 'react-dropzone';

import styles from './index.module.scss';

export interface InputFilePropsBase {
className?: string;
clearContent?: boolean;
isDisabled?: boolean;
isError?: boolean;
isFull?: boolean;
icon: React.ReactNode;
label: string;
}

export interface InputFileProps extends InputFilePropsBase {
accept?: string[];
onChange?: (_contents: Uint8Array) => void;
onCancel?: () => void;
}

interface FileState {
name: string;
size: number;
}

const BYTE_STR_0 = '0'.charCodeAt(0);
const BYTE_STR_X = 'x'.charCodeAt(0);
const STR_NL = '\n';
const NOOP = (): void => undefined;

function convertResult(result: ArrayBuffer): Uint8Array {
const data = new Uint8Array(result);

// this converts the input (if detected as hex), via the hex conversion route
if (data[0] === BYTE_STR_0 && data[1] === BYTE_STR_X) {
let hex = u8aToString(data);

while (hex.endsWith(STR_NL)) {
hex = hex.substring(0, hex.length - 1);
}

if (isHex(hex)) {
return hexToU8a(hex);
}
}

return data;
}

function InputFile({
accept,
isDisabled,
icon,
label,
onChange,
onCancel,
}: InputFileProps): React.ReactElement<InputFileProps> {
const dropRef = createRef<DropzoneRef>();
const [file, setFile] = useState<FileState | undefined>();

const onDrop = useCallback(
(files: File[]): void => {
files.forEach((file): void => {
const reader = new FileReader();

reader.onabort = NOOP;
reader.onerror = NOOP;

reader.onload = ({ target }: ProgressEvent<FileReader>): void => {
if (target?.result) {
const name = file.name;
const data = convertResult(target.result as ArrayBuffer);

onChange && onChange(data);
dropRef &&
setFile({
name,
size: data.length,
});
}
};

reader.readAsArrayBuffer(file);
});
},
[dropRef, onChange]
);

const { getInputProps, getRootProps } = useDropzone({
accept: accept?.reduce((all, mime) => ({ ...all, [mime]: [] }), {}),
disabled: isDisabled,
onDrop,
});

return (
<div className={styles.container}>
{!file ? (
<div className={styles.upload} {...getRootProps()}>
{icon}
{label}
<input {...getInputProps()} />
</div>
) : (
<div className={styles.hasFile}>
<IconButton className={styles.closeIcon} onClick={onCancel}>
<CloseIcon />
</IconButton>
<div className={styles.fileName}>{file.name}</div>
<div
className={styles.fileSize}
>{`(${file.size.toLocaleString()} bytes)`}</div>
</div>
)}
</div>
);
}

export default React.memo(InputFile);
18 changes: 10 additions & 8 deletions src/components/Elements/ListingCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import TimeAgo from 'javascript-time-ago';
import en from 'javascript-time-ago/locale/en';
import React, { useCallback, useEffect, useState } from 'react';

import { formatBalance, timesliceToTimestamp } from '@/utils/functions';
import { getBalanceString, timesliceToTimestamp } from '@/utils/functions';

import { useRelayApi } from '@/contexts/apis';
import { ApiState } from '@/contexts/apis/types';
Expand Down Expand Up @@ -86,7 +86,7 @@ const ListingCardInner = ({
const [endTimestamp, setEndTimestamp] = useState(0);

const {
state: { api, apiState, symbol },
state: { api, apiState, symbol, decimals },
} = useRelayApi();
const { timeslicePeriod } = useCommon();

Expand Down Expand Up @@ -196,10 +196,11 @@ const ListingCardInner = ({
>
<Typography fontSize={'1rem'}>Price/timeslice:</Typography>
<Typography variant='h2'>
{`${formatBalance(
{getBalanceString(
listing.timeslicePrice.toString(),
true
)} ${symbol}`}
decimals,
symbol
)}
</Typography>
</Box>
<Box
Expand All @@ -209,10 +210,11 @@ const ListingCardInner = ({
>
<Typography fontSize={'1rem'}>Total:</Typography>
<Typography variant='h2'>
{`${formatBalance(
{getBalanceString(
listing.currentPrice.toString(),
true
)} ${symbol}`}
decimals,
symbol
)}
</Typography>
</Box>
</Box>
Expand Down
15 changes: 9 additions & 6 deletions src/components/Elements/MarketFilters/PriceFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { Box, Slider, Typography } from '@mui/material';
import { useState } from 'react';

import { formatBalance } from '@/utils/functions';
import { planckBnToUnit } from '@/utils/functions';

import { FilterProps } from '.';

const PriceFilter = ({ listings, filters, updateFilters }: FilterProps) => {
const PriceFilter = ({
listings,
filters,
updateFilters,
decimals,
}: FilterProps) => {
const maxValue = (): number => {
if (listings.length < 1) return 0;
const sortedListings = new Array(...listings);
sortedListings.sort((a, b) => b.currentPrice.cmp(a.currentPrice));
return Number(
formatBalance(sortedListings[0].currentPrice.toString(), true)
);
return planckBnToUnit(sortedListings[0].currentPrice.toString(), decimals);
};

const [priceLimit, setPriceLimit] = useState(maxValue());
Expand All @@ -22,7 +25,7 @@ const PriceFilter = ({ listings, filters, updateFilters }: FilterProps) => {
updateFilters({
...filters,
priceFilter: (listing) =>
Number(formatBalance(listing.currentPrice.toString(), true)) <=
planckBnToUnit(listing.currentPrice.toString(), decimals) <=
(newValue as number),
});
};
Expand Down
8 changes: 7 additions & 1 deletion src/components/Elements/MarketFilters/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box, Typography } from '@mui/material';
import { useState } from 'react';

import { Listing } from '@/models';
import { Listing, REGIONX_DECIMALS } from '@/models';

import CoreOccupancyFilter from './coreOccupancyFilter';
import DurationFilter from './DurationFilter';
Expand All @@ -19,6 +19,7 @@ export interface FilterProps {
filters: Filters;
listings: Array<Listing>;
updateFilters: (_filters: Filters) => void;
decimals: number;
}

type Filters = {
Expand Down Expand Up @@ -65,27 +66,31 @@ export const MarketFilters = ({ listings, setFilteredListings }: Props) => {
<CoreOccupancyFilter
listings={listings}
filters={filters}
decimals={REGIONX_DECIMALS}
updateFilters={updateFilters}
/>
</Box>
<Box marginRight={'1em'} marginTop={'.5em'}>
<DurationFilter
listings={listings}
filters={filters}
decimals={REGIONX_DECIMALS}
updateFilters={updateFilters}
/>
</Box>
<Box marginRight={'1em'} marginTop={'.5em'}>
<RegionStartFilter
listings={listings}
filters={filters}
decimals={REGIONX_DECIMALS}
updateFilters={updateFilters}
/>
</Box>
<Box marginRight={'1em'} marginTop={'.5em'}>
<RegionEndFilter
listings={listings}
filters={filters}
decimals={REGIONX_DECIMALS}
updateFilters={updateFilters}
/>
</Box>
Expand All @@ -106,6 +111,7 @@ export const MarketFilters = ({ listings, setFilteredListings }: Props) => {
<PriceFilter
listings={listings}
filters={filters}
decimals={REGIONX_DECIMALS}
updateFilters={updateFilters}
/>
</Box>
Expand Down
Loading
Loading