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

Preimage loading status indicator #8774

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/page-preimages/src/Preimages/Preimage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Preimage ({ className, value }: Props): React.ReactElement<Props> {
{info
? (
<>
{info.status && (<div>{info.status?.type}{info.count !== 0 && <>&nbsp;/&nbsp;{formatNumber(info.count)}</>}</div>)}
{info.status && (<div>{info.status?.type}{!!info.count && <>&nbsp;/&nbsp;{formatNumber(info.count)}</>}</div>)}
<Free value={info} />
</>
)
Expand Down
17 changes: 13 additions & 4 deletions packages/page-referenda/src/Referenda/Submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ function Submit ({ className = '', isMember, members, palletReferenda, tracks }:
imageLenDefault: preimage.proposalLength,
isImageLenValid: prev.isImageLenValid
}));

preimage && !preimage.isCompleted && setImageLen({
imageLen: BN_ZERO,
imageLenDefault: BN_ZERO,
isImageLenValid: false
});
}, [preimage]);

const trackInfo = useMemo(
Expand Down Expand Up @@ -180,12 +186,14 @@ function Submit ({ className = '', isMember, members, palletReferenda, tracks }:
[]
);

const isLoadingPreimage = isImageHashValid && (!preimage || !preimage.isCompleted || preimage.proposalHash !== imageHash);

return (
<>
{trackOpts && isSubmitOpen && (
<Modal
className={className}
header={t<string>('Submit proposal')}
header={t<string>('Create referendum')}
onClose={toggleSubmit}
size='large'
>
Expand Down Expand Up @@ -251,8 +259,9 @@ function Submit ({ className = '', isMember, members, palletReferenda, tracks }:
/>
<InputNumber
defaultValue={imageLenDefault}
isDisabled={!!preimage?.proposalLength && !preimage?.proposalLength.isZero() && isImageHashValid && isImageLenValid}
isDisabled={!isLoadingPreimage && !!preimage?.proposalLength && !preimage?.proposalLength.isZero() && isImageHashValid && isImageLenValid}
isError={!isImageLenValid}
isLoading={isLoadingPreimage}
key='inputLength'
label={t<string>('preimage length')}
onChange={_onChangeImageLen}
Expand Down Expand Up @@ -306,7 +315,7 @@ function Submit ({ className = '', isMember, members, palletReferenda, tracks }:
accountId={accountId}
icon='plus'
isDisabled={!selectedOrigin || !isImageHashValid || !isImageLenValid || !accountId || isInvalidAt || !preimage?.proposalHash}
label={t<string>('Submit proposal')}
label={t<string>('Create referendum')}
onStart={toggleSubmit}
params={[
selectedOrigin,
Expand All @@ -327,7 +336,7 @@ function Submit ({ className = '', isMember, members, palletReferenda, tracks }:
<Button
icon='plus'
isDisabled={!isMember || !trackOpts}
label={t<string>('Submit proposal')}
label={t<string>('Create referendum')}
onClick={toggleSubmit}
/>
</>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/src/Modal/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function Actions ({ children, className = '' }: ActionsProps) {
}

export default React.memo(styled(Actions)`
background-color: var(--bg-input);
border-radius: 0 0 4px 4px;
position: relative;

.ui--Button-Group {
margin: 1rem 1rem;
Expand Down
42 changes: 23 additions & 19 deletions packages/react-components/src/Modal/Base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ function Base (props: ModalProps): React.ReactElement<ModalProps> {
>
<DisableGlobalScroll />
<div
className='ui--Modal__overlay'
className='ui--Modal__overlay-bg'
onClick={onClose}
/>
<div className='ui--Modal__body'>
<Header
header={header}
onClose={onClose}
/>
{children}
<div className='ui--Modal__overlay-body'>
<div className='ui--Modal__body'>
<Header
header={header}
onClose={onClose}
/>
{children}
</div>
</div>
</div>,
document.body
Expand All @@ -68,7 +70,7 @@ export default React.memo(styled(Base)`
z-index: 1000;
overflow-y: auto;

.ui--Modal__overlay {
.ui--Modal__overlay-bg {
position: fixed;
top: 0;
left: 0;
Expand All @@ -77,24 +79,26 @@ export default React.memo(styled(Base)`
background: rgba(96, 96, 96, 0.5);
}

.ui--Modal__body {
margin-top: 30px;
background: var(--bg-page);
border-radius: 4px;
box-shadow: none;

.ui--Modal__overlay-body {
align-items: center;
color: var(--color-text);
display: flex;
flex-direction: column;
font: var(--font-sans);
left: 0;
padding: 2rem 0;
position: absolute;
right: 0;
top: 0;
left: 50%;
transform: translate(-50%, 0);
}

.ui--Modal__body {
background: var(--bg-page);
border-radius: 4px;
display: flex;
flex-direction: column;
max-width: 900px;
width: calc(100% - 16px);

color: var(--color-text);
font: var(--font-sans);
}

&.smallSize .ui--Modal__body {
Expand Down
6 changes: 6 additions & 0 deletions packages/react-components/src/Modal/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function Header ({ className = '', header, onClose }: HeaderProps) {
<h1>{header}</h1>
)}
<Button
className='closeModal'
dataTestId='close-modal'
icon='times'
onClick={onClose}
Expand All @@ -27,4 +28,9 @@ export default React.memo(styled(Header)`
display: flex;
justify-content: space-between;
padding: 0.75rem 1.5rem 0;

.closeModal {
right: 0;
top: 0;
}
`);
6 changes: 3 additions & 3 deletions packages/react-components/src/VoteValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ function VoteValue ({ accountId, autoFocus, label, noDefault, onChange }: Props)
[accountId]
);

const isDisabled = accountId !== selectedId;
const isLoading = accountId !== selectedId;

return (
<InputBalance
autoFocus={autoFocus}
defaultValue={
isDisabled
isLoading
? undefined
: defaultValue
}
isDisabled={isDisabled}
isLoading={isLoading}
isZeroable
label={label || t<string>('vote value')}
labelExtra={
Expand Down
3 changes: 2 additions & 1 deletion packages/react-hooks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ export interface PreimageDeposit {
}

export interface PreimageStatus {
count: number;
count?: number;
deposit?: PreimageDeposit;
isCompleted: boolean;
isHashParam: boolean;
proposalHash: HexString;
proposalLength?: BN;
registry: Registry;
Expand Down
Loading