From 6318500e403e545ba84529293d00c8a143baeb4a Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 12 May 2020 18:45:58 +0200 Subject: [PATCH] Allow sudo.sudoUncheckedWeight submission (#2724) --- packages/page-sudo/src/Sudo.tsx | 64 ++++++++++++++++++++++++++++----- packages/page-sudo/src/types.ts | 1 + 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/packages/page-sudo/src/Sudo.tsx b/packages/page-sudo/src/Sudo.tsx index be925b1c1a..4f9a4bab67 100644 --- a/packages/page-sudo/src/Sudo.tsx +++ b/packages/page-sudo/src/Sudo.tsx @@ -5,16 +5,22 @@ 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 { +const ZERO = new BN(0); + +function Propose ({ className, isMine, sudoKey }: Props): React.ReactElement { const { t } = useTranslation(); - const { apiDefaultTxSudo } = useApi(); + const { api, apiDefaultTxSudo } = useApi(); + const [withWeight, toggleWithWeight] = useToggle(); const [method, setMethod] = useState | null>(null); + const [weight, setWeight] = useState(ZERO); const _onChangeExtrinsic = useCallback( (method: SubmittableExtrinsic<'promise'> | null = null) => @@ -22,23 +28,58 @@ function Propose ({ isMine, sudoKey }: Props): React.ReactElement { [] ); + const _onChangeWeight = useCallback( + (weight: BN = ZERO) => setWeight(weight), + [] + ); + return isMine ? ( -
+

+ {withWeight && ( + + )} + {api.tx.sudo.sudoUncheckedWeight && ( + + )}
@@ -53,4 +94,9 @@ function Propose ({ isMine, sudoKey }: Props): React.ReactElement { ); } -export default React.memo(Propose); +export default React.memo(styled(Propose)` + .sudoToggle { + width: 100%; + text-align: right; + } +`); diff --git a/packages/page-sudo/src/types.ts b/packages/page-sudo/src/types.ts index 971ae7c612..420658dd9d 100644 --- a/packages/page-sudo/src/types.ts +++ b/packages/page-sudo/src/types.ts @@ -4,6 +4,7 @@ export interface ComponentProps { allAccounts: string[]; + className?: string; isMine: boolean; sudoKey?: string; }