Default to multisig approval first, call last (#2708)

* Default to multisig approval first, call last

* Reset multiCall to default between (update helper text)
This commit is contained in:
Jaco Greeff 2020-05-08 13:09:33 +02:00 committed by GitHub
parent b4b1c62987
commit 36f82cd4b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,7 +48,7 @@ interface State {
isRenderError: boolean;
isSendable: boolean;
isSubmit: boolean;
multiApproval: boolean;
multiCall: boolean;
nonce?: BN;
password: string;
qrAddress: string;
@ -123,7 +123,7 @@ const initialState: State = {
isRenderError: false,
isSendable: false,
isSubmit: true,
multiApproval: false,
multiCall: false,
nonce: undefined,
password: '',
qrAddress: '',
@ -136,8 +136,8 @@ const initialState: State = {
class Signer extends React.PureComponent<Props, State> {
public state: State = initialState;
public static getDerivedStateFromProps ({ allAccounts, queue }: Props, { currentItem, password, unlockError }: State): Partial<State> {
const nextItem = queue.find(({ status }): boolean => ['queued', 'qr'].includes(status));
public static getDerivedStateFromProps ({ allAccounts, queue }: Props, { currentItem, multiCall, password, unlockError }: State): Partial<State> {
const nextItem = queue.find(({ status }) => ['queued', 'qr'].includes(status));
const isSame =
!!nextItem &&
!!currentItem &&
@ -159,8 +159,10 @@ class Signer extends React.PureComponent<Props, State> {
return {
currentItem: nextItem,
isSendable,
password: isSame ? password : '',
unlockError: isSame ? unlockError : null
...(isSame
? { multiCall, password, unlockError }
: { multiCall: false, password: '', unlockError: null }
)
};
}
@ -299,7 +301,7 @@ class Signer extends React.PureComponent<Props, State> {
private renderSignatory (): React.ReactNode {
const { t } = this.props;
const { currentItem, multiApproval } = this.state;
const { currentItem, multiCall } = this.state;
const { isMultisig, who } = currentItem
? extractExternal(currentItem.accountId)
: { isMultisig: false, who: [] };
@ -309,30 +311,39 @@ class Signer extends React.PureComponent<Props, State> {
}
return (
<Modal.Columns>
<Modal.Column>
<InputAddress
filter={who}
help={t('The multisig signatory for this transaction.')}
label={t('signatory')}
onChange={this.onChangeSignatory}
type='account'
/>
<Toggle
className='tipToggle'
label={
multiApproval
? t('Multisig approval with hash (not message with call)')
: t('Multisig message with call (not approval with hash)')
}
onChange={this.onToggleMultiApproval}
value={multiApproval}
/>
</Modal.Column>
<Modal.Column>
<p>{t('The signatory is one of the allowed accounts on the multisig. The transaction could either be the call or an approval for the hash of a call.')}</p>
</Modal.Column>
</Modal.Columns>
<>
<Modal.Columns>
<Modal.Column>
<InputAddress
filter={who}
help={t('The multisig signatory for this transaction.')}
label={t('signatory')}
onChange={this.onChangeSignatory}
type='account'
/>
</Modal.Column>
<Modal.Column>
<p>{t('The signatory is one of the allowed accounts on the multisig, making a recorded approval for the transaction.')}</p>
</Modal.Column>
</Modal.Columns>
<Modal.Columns>
<Modal.Column>
<Toggle
className='tipToggle'
label={
multiCall
? t('Multisig message with call (for final approval)')
: t('Multisig approval with hash (non-final approval)')
}
onChange={this.onToggleMultiCall}
value={multiCall}
/>
</Modal.Column>
<Modal.Column>
<p>{t('This could either be an approval for the hash or with full call details. The call as last approval triggers execution.')}</p>
</Modal.Column>
</Modal.Columns>
</>
);
}
@ -447,8 +458,8 @@ class Signer extends React.PureComponent<Props, State> {
this.setState({ showTip });
};
private onToggleMultiApproval = (multiApproval: boolean): void => {
this.setState({ multiApproval });
private onToggleMultiCall = (multiCall: boolean): void => {
this.setState({ multiCall });
}
private onToggleSign = (isSubmit: boolean): void => {
@ -650,7 +661,7 @@ class Signer extends React.PureComponent<Props, State> {
private async sendExtrinsic (queueTx: QueueTx, password?: string): Promise<void> {
const { api, queueSetTxStatus } = this.props;
const { isSubmit, multiApproval, showTip, signatory, tip } = this.state;
const { isSubmit, multiCall, showTip, signatory, tip } = this.state;
const { accountId, extrinsic, id, isUnsigned, payload } = queueTx;
if (!isUnsigned) {
@ -700,9 +711,9 @@ class Signer extends React.PureComponent<Props, State> {
}
pair = keyring.getPair(signatory as string);
tx = multiApproval
? api.tx.utility.approveAsMulti(basePair.meta.threshold, others, timepoint, submittable.method.hash)
: api.tx.utility.asMulti(basePair.meta.threshold, others, timepoint, submittable.method);
tx = multiCall
? api.tx.utility.asMulti(basePair.meta.threshold, others, timepoint, submittable.method)
: api.tx.utility.approveAsMulti(basePair.meta.threshold, others, timepoint, submittable.method.hash);
}
console.log('sendExtrinsic::', JSON.stringify(tx.method.toHuman()));