Add hash to judgement call (#8173)

* Add hash to judgement call

* Use built-in toHex on hash output

* Adjust
This commit is contained in:
Jaco 2022-09-27 18:15:45 +03:00 committed by GitHub
parent ee284ec7a5
commit 21b511ddb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,10 +1,14 @@
// Copyright 2017-2022 @polkadot/react-query authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Option } from '@polkadot/types';
import type { PalletIdentityRegistration } from '@polkadot/types/lookup';
import type { HexString } from '@polkadot/util/types';
import React, { useEffect, useState } from 'react';
import { Dropdown, Input, InputAddress, Modal, TxButton } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { Dropdown, Input, InputAddress, MarkError, Modal, Spinner, TxButton } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
import { useTranslation } from '../translate';
@ -23,9 +27,17 @@ const JUDGEMENT_ENUM = [
{ text: 'Low quality', value: 5 }
];
const OPT_ID = {
transform: (optId: Option<PalletIdentityRegistration>): HexString | null =>
optId.isSome
? optId.unwrap().info.hash.toHex()
: null
};
function RegistrarJudgement ({ address, registrars, toggleJudgement }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api } = useApi();
const identityHash = useCall(api.query.identity.identityOf, [address], OPT_ID);
const [addresses] = useState(() => registrars.map(({ address }) => address));
const [judgementAccountId, setJudgementAccountId] = useState<string | null>(null);
const [judgementEnum, setJudgementEnum] = useState(2); // Reasonable
@ -66,15 +78,31 @@ function RegistrarJudgement ({ address, registrars, toggleJudgement }: Props): R
options={JUDGEMENT_ENUM}
value={judgementEnum}
/>
{identityHash
? (
<Input
defaultValue={identityHash}
isDisabled
label={t<string>('identity hash')}
/>
)
: identityHash === null
? <MarkError content={t<string>('No identity associated with account')} />
: <Spinner noLabel />
}
</Modal.Content>
<Modal.Actions>
<TxButton
accountId={judgementAccountId}
icon='check'
isDisabled={registrarIndex === -1}
isDisabled={!identityHash || registrarIndex === -1}
label={t<string>('Judge')}
onStart={toggleJudgement}
params={[registrarIndex, address, judgementEnum]}
params={
api.tx.identity.provideJudgement.meta.args.length === 4
? [registrarIndex, address, judgementEnum, identityHash]
: [registrarIndex, address, judgementEnum]
}
tx={api.tx.identity.provideJudgement}
/>
</Modal.Actions>