-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: reserve & register modals * reservation cost * refactor formatBalance * more refactoring for balances * reservation modal working * fix build * fix styles * show table * default token name and decimals * reservation working, state * Update src/pages/paras/index.tsx * Update src/pages/paras/index.tsx * buy coretime Co-authored-by: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> * parachains soon active * no action required for 'soon active' * registration modal * revert the revert :) * fix * fix * fix duplicated * fix * fix format balance * lease holding and system paras * lint fix * fix build * rename parathread to 'ondemand parachain' * pass para id to the renewal page * Update src/pages/paras/index.tsx * Update src/pages/paras/index.tsx --------- Co-authored-by: cuteolaf <oliverlim818@gmail.com> Co-authored-by: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Co-authored-by: Sergej <sakacszergej@gmail.com>
- Loading branch information
1 parent
8613251
commit 0caa2fc
Showing
42 changed files
with
1,309 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.