From 582d6a3722138cb046ba94d223498552320154fa Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sat, 2 Nov 2019 17:57:11 +0100 Subject: [PATCH] Toggle for tip (#1831) --- packages/react-signer/src/Modal.tsx | 43 +++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/packages/react-signer/src/Modal.tsx b/packages/react-signer/src/Modal.tsx index b1bd65bea8..259703139f 100644 --- a/packages/react-signer/src/Modal.tsx +++ b/packages/react-signer/src/Modal.tsx @@ -17,7 +17,7 @@ import React from 'react'; import { SubmittableResult } from '@polkadot/api'; import { web3FromSource } from '@polkadot/extension-dapp'; import { createType } from '@polkadot/types'; -import { Button, InputBalance, Modal } from '@polkadot/react-components'; +import { Button, InputBalance, Modal, Toggle } from '@polkadot/react-components'; import { withApi, withMulti, withObservable } from '@polkadot/react-api'; import keyring from '@polkadot/ui-keyring'; import { assert, isFunction } from '@polkadot/util'; @@ -50,6 +50,7 @@ interface State { qrPayload: Uint8Array; qrResolve?: (result: SignerResult) => void; qrReject?: (error: Error) => void; + showTip: boolean; tip?: BN; unlockError?: string | null; } @@ -99,6 +100,7 @@ class Signer extends React.PureComponent { password: '', qrAddress: '', qrPayload: new Uint8Array(), + showTip: false, unlockError: null }; @@ -271,22 +273,39 @@ class Signer extends React.PureComponent { private renderTip (): React.ReactNode { const { t } = this.props; - const { currentItem, isSendable, isV2 } = this.state; + const { currentItem, isSendable, isV2, showTip } = this.state; if (!isV2 || !isSendable || !currentItem || currentItem.isUnsigned) { return null; } return ( - + <> + + {showTip && ( + + )} + ); } + private onShowTip = (showTip: boolean): void => { + this.setState({ showTip }); + } + private renderUnlock (): React.ReactNode { const { currentItem, isSendable, password, unlockError } = this.state; @@ -445,7 +464,7 @@ class Signer extends React.PureComponent { } private async sendExtrinsic (queueTx: QueueTx, password?: string): Promise { - const { isV2, tip } = this.state; + const { isV2, showTip, tip } = this.state; const { accountId, extrinsic, payload, isUnsigned } = queueTx; @@ -464,7 +483,7 @@ class Signer extends React.PureComponent { return makeExtrinsicSignature( { ...payload, - ...((isV2 && tip && !payload.tip) ? { tip: tip.toString() } : {}) + ...((isV2 && showTip && tip && !payload.tip) ? { tip: tip.toString() } : {}) }, queueTx, keyring.getPair(accountId as string) @@ -508,7 +527,7 @@ class Signer extends React.PureComponent { private async makeExtrinsicCall (extrinsic: SubmittableExtrinsic, { id, txFailedCb, txSuccessCb, txStartCb, txUpdateCb }: QueueTx, extrinsicCall: (...params: any[]) => any, pair?: KeyringPair): Promise { const { api, queueSetTxStatus } = this.props; - const { isV2, tip } = this.state; + const { isV2, showTip, tip } = this.state; console.log('makeExtrinsicCall: extrinsic ::', extrinsic.toHex()); @@ -539,7 +558,7 @@ class Signer extends React.PureComponent { } } - if (isV2 && tip) { + if (showTip && isV2 && tip) { params.push({ tip } as Partial); }