Display call hash on signer modal (#4885)

This commit is contained in:
Jaco Greeff 2021-03-21 10:42:39 +01:00 committed by GitHub
parent 6a914109f3
commit 555d48a8b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 15 deletions

View File

@ -11,6 +11,7 @@ interface Props {
children?: React.ReactNode;
className?: string;
help?: React.ReactNode;
isDisabled?: boolean;
isError?: boolean;
isFull?: boolean;
isHidden?: boolean;
@ -24,7 +25,7 @@ interface Props {
withLabel?: boolean;
}
function Output ({ children, className = '', help, isError, isFull, isHidden, isMonospace, isSmall, isTrimmed, label, labelExtra, value, withCopy = false, withLabel }: Props): React.ReactElement<Props> {
function Output ({ children, className = '', help, isDisabled, isError, isFull, isHidden, isMonospace, isSmall, isTrimmed, label, labelExtra, value, withCopy = false, withLabel }: Props): React.ReactElement<Props> {
return (
<Labelled
className={className}
@ -36,7 +37,7 @@ function Output ({ children, className = '', help, isError, isFull, isHidden, is
labelExtra={labelExtra}
withLabel={withLabel}
>
<div className={`ui--output${isError ? ' error' : ''}${isMonospace ? ' monospace' : ''}`}>
<div className={`ui--output ui dropdown selection ${isError ? ' error' : ''}${isMonospace ? ' monospace' : ''}${isDisabled ? ' disabled' : ''}`}>
{isTrimmed && value && (value.length > 256)
? `${value.substr(0, 96)}…${value.substr(-96)}`
: value

View File

@ -36,8 +36,15 @@ interface Props {
requestAddress: string;
}
interface InnerTx {
innerHash: string | null;
innerTx: string | null;
}
const NOOP = () => undefined;
const EMPTY_INNER: InnerTx = { innerHash: null, innerTx: null };
let qrId = 0;
function unlockAccount ({ isUnlockCached, signAddress, signPassword }: AddressProxy): string | null {
@ -183,7 +190,7 @@ function TxSigned ({ className, currentItem, requestAddress }: Props): React.Rea
const [senderInfo, setSenderInfo] = useState<AddressProxy>({ isMultiCall: false, isUnlockCached: false, multiRoot: null, proxyRoot: null, signAddress: requestAddress, signPassword: '' });
const [signedOptions, setSignedOptions] = useState<Partial<SignerOptions>>({});
const [signedTx, setSignedTx] = useState<string | null>(null);
const [multiCall, setMultiCall] = useState<string | null>(null);
const [{ innerHash, innerTx }, setCallInfo] = useState<InnerTx>(EMPTY_INNER);
const [tip, setTip] = useState(BN_ZERO);
useEffect((): void => {
@ -193,14 +200,21 @@ function TxSigned ({ className, currentItem, requestAddress }: Props): React.Rea
// when we are sending the hash only, get the wrapped call for display (proxies if required)
useEffect((): void => {
setMultiCall(
currentItem.extrinsic && senderInfo.multiRoot
? (
senderInfo.proxyRoot
? api.tx.proxy.proxy(senderInfo.proxyRoot, null, currentItem.extrinsic)
: currentItem.extrinsic
).method.toHex()
: null
const method = currentItem.extrinsic && (
senderInfo.proxyRoot
? api.tx.proxy.proxy(senderInfo.proxyRoot, null, currentItem.extrinsic)
: currentItem.extrinsic
).method;
setCallInfo(
method
? {
innerHash: method.hash.toHex(),
innerTx: senderInfo.multiRoot
? method.toHex()
: null
}
: EMPTY_INNER
);
}, [api, currentItem, senderInfo]);
@ -367,13 +381,24 @@ function TxSigned ({ className, currentItem, requestAddress }: Props): React.Rea
signedTx={signedTx}
/>
)}
{isSubmit && !senderInfo.isMultiCall && multiCall && (
<Modal.Columns hint={t('The call data that can be supplied to a final call to multi approvals')}>
{isSubmit && !senderInfo.isMultiCall && innerTx && (
<Modal.Columns hint={t('The full call data that can be supplied to a final call to multi approvals')}>
<Output
isFull
isDisabled
isTrimmed
label={t<string>('multisig call data')}
value={multiCall}
value={innerTx}
withCopy
/>
</Modal.Columns>
)}
{isSubmit && innerHash && (
<Modal.Columns hint={t('The call hash as calculated for this transaction')}>
<Output
isDisabled
isTrimmed
label={t<string>('call hash')}
value={innerHash}
withCopy
/>
</Modal.Columns>