// Copyright 2017-2021 @polkadot/app-js authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { SubmittableExtrinsic } from '@polkadot/api/types'; import BN from 'bn.js'; import React, { useCallback, useState } from 'react'; import styled from 'styled-components'; import { Button, Extrinsic, Icon, InputNumber, Toggle, TxButton } from '@polkadot/react-components'; import { useApi, useToggle } from '@polkadot/react-hooks'; import { BN_ZERO } from '@polkadot/util'; import { useTranslation } from './translate'; interface Props { className?: string; isMine: boolean; sudoKey?: string; } function Sudo ({ className, isMine, sudoKey }: Props): React.ReactElement { const { t } = useTranslation(); const { api, apiDefaultTxSudo } = useApi(); const [withWeight, toggleWithWeight] = useToggle(); const [method, setMethod] = useState | null>(null); const [weight, setWeight] = useState(BN_ZERO); const _onChangeExtrinsic = useCallback( (method: SubmittableExtrinsic<'promise'> | null = null) => setMethod(() => method), [] ); const _onChangeWeight = useCallback( (weight: BN = BN_ZERO) => setWeight(weight), [] ); return isMine ? (
('submit the following change')} onChange={_onChangeExtrinsic} /> {api.tx.sudo.sudoUncheckedWeight && ( ('The unchecked weight as specified for the sudoUncheckedWeight call.')} isDisabled={!withWeight} isError={weight.eq(BN_ZERO)} isZeroable={false} label={t('unchecked weight for this call')} onChange={_onChangeWeight} value={weight} > ('with weight override')} onChange={toggleWithWeight} value={withWeight} /> )} ('Submit Sudo Unchecked') : t('Submit Sudo') } params={ withWeight ? [method, weight] : [method] } tx={ withWeight ? api.tx.sudo.sudoUncheckedWeight : api.tx.sudo.sudo } />
) : (
{t('You do not have access to the current sudo key')}
); } export default React.memo(styled(Sudo)` .sudoToggle { width: 100%; text-align: right; } `);