Allow submission of unsigned (inherent) (#557)

* Allow submission of unsigned (inherent)

* Remove stray log

* Update text to refelect unigned

* Cleanup stray import
This commit is contained in:
Jaco Greeff 2019-01-03 18:17:26 +01:00 committed by GitHub
parent 92a0f05d92
commit 47ca853ff8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 28 deletions

View File

@ -62,10 +62,18 @@ class Selection extends React.PureComponent<Props, State> {
value={accountId}
/>
<Button.Group>
<Button
isDisabled={!isValid}
onClick={this.onQueueInherent}
text={t('submit.label', {
defaultValue: 'Submit Inherent'
})}
/>
<Button.Or />
<Button
isDisabled={!isValid}
isPrimary
onClick={this.onQueue}
onClick={this.onQueueExtrinsic}
text={t('submit.label', {
defaultValue: 'Submit Transaction'
})}
@ -111,7 +119,7 @@ class Selection extends React.PureComponent<Props, State> {
this.nextState({ accountId, accountNonce: new BN(0) } as State);
}
private onQueue = (): void => {
private onQueue (isUnsigned: boolean): void {
const { queueExtrinsic } = this.props;
const { accountNonce, method, isValid, accountId } = this.state;
@ -120,11 +128,20 @@ class Selection extends React.PureComponent<Props, State> {
}
queueExtrinsic({
accountId,
accountNonce,
extrinsic: new Extrinsic({ method }),
accountId
isUnsigned
});
}
private onQueueExtrinsic = (): void => {
this.onQueue(false);
}
private onQueueInherent = (): void => {
this.onQueue(true);
}
}
export default translate(Selection);

View File

@ -144,11 +144,12 @@ export default class Queue extends React.Component<Props, State> {
return id;
}
queueExtrinsic = ({ accountId, accountNonce, extrinsic }: PartialQueueTx$Extrinsic): number => {
queueExtrinsic = ({ accountId, accountNonce, extrinsic, isUnsigned }: PartialQueueTx$Extrinsic): number => {
return this.queueAdd({
accountId,
accountNonce: accountNonce || new BN(0),
extrinsic
extrinsic,
isUnsigned
});
}

View File

@ -26,6 +26,7 @@ export type QueueTx = AccountInfo & {
error?: Error,
extrinsic?: Extrinsic,
id: number,
isUnsigned?: boolean,
result?: any,
rpc: RpcMethod,
values?: Array<any>,
@ -58,7 +59,8 @@ export type PartialAccountInfo = {
};
export type PartialQueueTx$Extrinsic = PartialAccountInfo & {
extrinsic: Extrinsic
extrinsic: Extrinsic,
isUnsigned?: boolean
};
export type PartialQueueTx$Rpc = PartialAccountInfo & {

View File

@ -5,7 +5,6 @@
import { I18nProps } from '@polkadot/ui-app/types';
import { QueueTx } from '@polkadot/ui-app/Status/types';
import BN from 'bn.js';
import React from 'react';
import { Trans } from 'react-i18next';
import { Method } from '@polkadot/types';
@ -20,13 +19,28 @@ type Props = I18nProps & {
class Transaction extends React.PureComponent<Props> {
render () {
const { children, t, value: { accountId, accountNonce = new BN(0), extrinsic } } = this.props;
const { children, t, value: { accountId, accountNonce, extrinsic, isUnsigned } } = this.props;
if (!extrinsic) {
return null;
}
const { method, section } = Method.findFunction(extrinsic.callIndex);
const header = isUnsigned
? (
<Trans i18nKey='decoded.short-unsigned'>You are about to submit an (unsigned) inherent transaction calling <span className='code'>{section}.{method}</span></Trans>
)
: (
<Trans i18nKey='decoded.short-signed'>You are about to sign a message from <span className='code'>{accountId}</span> calling <span className='code'>{section}.{method}</span> with an index of <span className='code'>{accountNonce.toString()}</span></Trans>
);
const icon = isUnsigned
? undefined
: (
<IdentityIcon
className='icon'
value={accountId}
/>
);
return [
<Modal.Header key='header'>
@ -37,17 +51,10 @@ class Transaction extends React.PureComponent<Props> {
<Modal.Content className='ui--signer-Signer-Content' key='content'>
<div className='ui--signer-Signer-Decoded'>
<div className='expanded'>
<p>
<Trans i18nKey='decoded.short'>
You are about to sign a message from <span className='code'>{accountId}</span> calling <span className='code'>{section}.{method}</span> with an index of <span className='code'>{accountNonce.toString()}</span>
</Trans>
</p>
<p>{header}</p>
<Call value={extrinsic} />
</div>
<IdentityIcon
className='icon'
value={accountId}
/>
{icon}
</div>
{children}
</Modal.Content>

View File

@ -99,6 +99,11 @@ class Signer extends React.PureComponent<Props, State> {
private renderButtons () {
const { t } = this.props;
const { currentItem } = this.state;
if (!currentItem) {
return null;
}
return (
<Modal.Actions>
@ -118,9 +123,13 @@ class Signer extends React.PureComponent<Props, State> {
onClick={this.onSend}
tabIndex={2}
text={
t('extrinsic.signedSend', {
defaultValue: 'Sign and Submit'
})
currentItem.isUnsigned
? t('extrinsic.unsignedSend', {
defaultValue: 'Submit (no signature)'
})
: t('extrinsic.signedSend', {
defaultValue: 'Sign and Submit'
})
}
/>
</Button.Group>
@ -146,7 +155,7 @@ class Signer extends React.PureComponent<Props, State> {
const { t } = this.props;
const { currentItem, password, unlockError } = this.state;
if (!currentItem) {
if (!currentItem || currentItem.isUnsigned) {
return null;
}
@ -244,16 +253,18 @@ class Signer extends React.PureComponent<Props, State> {
queueSetTxStatus(id, status, result, error);
}
private sendExtrinsic = async ({ extrinsic, id, accountNonce, accountId }: QueueTx, password?: string): Promise<void> => {
private sendExtrinsic = async ({ accountNonce, accountId, extrinsic, id, isUnsigned }: QueueTx, password?: string): Promise<void> => {
if (!extrinsic || !accountId) {
return;
}
const unlockError = this.unlockAccount(accountId, password);
if (!isUnsigned) {
const unlockError = this.unlockAccount(accountId, password);
if (unlockError) {
this.setState({ unlockError });
return;
if (unlockError) {
this.setState({ unlockError });
return;
}
}
const { apiObservable, queueSetTxStatus } = this.props;
@ -262,9 +273,13 @@ class Signer extends React.PureComponent<Props, State> {
const pair = keyring.getPair(accountId);
console.log(`sendExtrinsic: from=${pair.address()}, nonce=${accountNonce}, hash=${apiObservable.genesisHash.toHex()}`);
if (!isUnsigned) {
console.log(`sendExtrinsic: from=${pair.address()}, nonce=${accountNonce}, blockHash=${apiObservable.genesisHash.toHex()}`);
extrinsic.sign(pair, accountNonce, apiObservable.genesisHash);
extrinsic.sign(pair, accountNonce, apiObservable.genesisHash);
} else {
console.log(`sendInherent: from=${pair.address()}, nonce=${accountNonce}`);
}
await this.submitExtrinsic(extrinsic, id);
}