Skip to content

Commit

Permalink
Allow sudo.sudoUncheckedWeight submission (#2724)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr authored May 12, 2020
1 parent cd09733 commit 6318500
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
64 changes: 55 additions & 9 deletions packages/page-sudo/src/Sudo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,81 @@
import { SubmittableExtrinsic } from '@polkadot/api/types';
import { ComponentProps as Props } from './types';

import BN from 'bn.js';
import React, { useCallback, useState } from 'react';
import { Button, Icon, Extrinsic, TxButton } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import styled from 'styled-components';
import { Button, Icon, Extrinsic, Toggle, TxButton, InputNumber } from '@polkadot/react-components';
import { useApi, useToggle } from '@polkadot/react-hooks';

import { useTranslation } from './translate';

function Propose ({ isMine, sudoKey }: Props): React.ReactElement<Props> {
const ZERO = new BN(0);

function Propose ({ className, isMine, sudoKey }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { apiDefaultTxSudo } = useApi();
const { api, apiDefaultTxSudo } = useApi();
const [withWeight, toggleWithWeight] = useToggle();
const [method, setMethod] = useState<SubmittableExtrinsic<'promise'> | null>(null);
const [weight, setWeight] = useState<BN>(ZERO);

const _onChangeExtrinsic = useCallback(
(method: SubmittableExtrinsic<'promise'> | null = null) =>
setMethod(() => method),
[]
);

const _onChangeWeight = useCallback(
(weight: BN = ZERO) => setWeight(weight),
[]
);

return isMine
? (
<section>
<section className={className}>
<Extrinsic
defaultValue={apiDefaultTxSudo}
label={t('submit the following change')}
onChange={_onChangeExtrinsic}
/>
<br />
{withWeight && (
<InputNumber
help={t('The unchecked weight as specified for the sudoUncheckedWeight call.')}
isError={weight.eq(ZERO)}
isZeroable={false}
label={t('unchecked weight for this call')}
onChange={_onChangeWeight}
value={weight}
/>
)}
{api.tx.sudo.sudoUncheckedWeight && (
<Toggle
className='sudoToggle'
label={
withWeight
? t('sudo with unchecked weight parameter')
: t('sudo without unchecked weight parameter')
}
onChange={toggleWithWeight}
value={withWeight}
/>
)}
<Button.Group>
<TxButton
accountId={sudoKey}
icon='sign-in'
isDisabled={!method}
isDisabled={!method || (withWeight ? weight.eq(ZERO) : false)}
label={t('Submit Sudo')}
params={[method]}
tx='sudo.sudo'
params={
withWeight
? [method, weight]
: [method]
}
tx={
withWeight
? 'sudo.sudoUncheckedWeight'
: 'sudo.sudo'
}
/>
</Button.Group>
</section>
Expand All @@ -53,4 +94,9 @@ function Propose ({ isMine, sudoKey }: Props): React.ReactElement<Props> {
);
}

export default React.memo(Propose);
export default React.memo(styled(Propose)`
.sudoToggle {
width: 100%;
text-align: right;
}
`);
1 change: 1 addition & 0 deletions packages/page-sudo/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

export interface ComponentProps {
allAccounts: string[];
className?: string;
isMine: boolean;
sudoKey?: string;
}

0 comments on commit 6318500

Please sign in to comment.