diff --git a/packages/app-transfer/src/Transfer.tsx b/packages/app-transfer/src/Transfer.tsx index f723477686..0406adfb82 100644 --- a/packages/app-transfer/src/Transfer.tsx +++ b/packages/app-transfer/src/Transfer.tsx @@ -67,6 +67,7 @@ class Transfer extends React.PureComponent { diff --git a/packages/ui-signer/src/Checks/index.tsx b/packages/ui-signer/src/Checks/index.tsx index ab01b407ac..d1ef755e4a 100644 --- a/packages/ui-signer/src/Checks/index.tsx +++ b/packages/ui-signer/src/Checks/index.tsx @@ -36,6 +36,7 @@ type Props = I18nProps & { balances_votingBalance?: DerivedBalances, accountId?: string | null, extrinsic?: Extrinsic | null, + isSendable: boolean, onChange?: (hasAvailble: boolean) => void, system_accountNonce?: BN }; @@ -117,7 +118,7 @@ class FeeDisplay extends React.PureComponent { } render () { - const { accountId, className, t } = this.props; + const { accountId, className, isSendable, t } = this.props; const { allFees, allTotal, allWarn, hasAvailable, isRemovable, isReserved, overLimit } = this.state; if (!accountId) { @@ -138,6 +139,11 @@ class FeeDisplay extends React.PureComponent { className={[className, feeClass, 'padded'].join(' ')} key='txinfo' > + { + isSendable + ? undefined + :
{t('The selected account does not exist on your keyring')}
+ } { hasAvailable ? undefined diff --git a/packages/ui-signer/src/Modal.spec.js b/packages/ui-signer/src/Modal.spec.js deleted file mode 100644 index 1c9e565800..0000000000 --- a/packages/ui-signer/src/Modal.spec.js +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2017-2019 @polkadot/ui-app authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import React from 'react'; - -import { shallow } from '../../../test/enzyme'; -import { Signer } from './Modal'; - -const mockT = (key, options) => (key); - -describe('Signer', () => { - let expectedNextCurrentItemState, fixtureCurrentItemState, fixtureQueueProp, unlockComponent, wrapper; - - beforeEach(() => { - fixtureCurrentItemState = { - rpc: { - isSigned: true - }, - id: 'test1', - publicKey: new Uint8Array([1]), - status: 'sending' - }; - - fixtureQueueProp = [{ - rpc: { - isSigned: true - }, - id: 'test2', - publicKey: new Uint8Array([2]), - status: 'queued' - }]; - - expectedNextCurrentItemState = fixtureQueueProp[0]; - - wrapper = shallow( - , {} - ); - }); - - it('creates the element', () => { - return new Promise((resolve) => { - wrapper.setState({ - currentItem: fixtureCurrentItemState, - password: '123', - unlockError: null - }, () => { - wrapper.setProps({ - queue: fixtureQueueProp - }, resolve); - }); - }).then(() => { - wrapper.update(); - expect(wrapper).toHaveLength(1); - }); - }); - - // Reference: https://github.com/airbnb/enzyme/issues/1794 - it('renders Unlock component with empty password', () => { - return new Promise((resolve) => { - wrapper.setState({ - currentItem: fixtureCurrentItemState, - password: '123', - unlockError: null - }, () => { - wrapper.setProps({ - queue: fixtureQueueProp - }, resolve); - }); - }).then(() => { - wrapper.update(); - expect(wrapper.state('currentItem')).toEqual(expectedNextCurrentItemState); - expect(wrapper.find('.ui--signer-Signer')).toHaveLength(1); - unlockComponent = wrapper.find('.ui--signer-Signer').children().at(0).childAt(0); - expect(unlockComponent.props().password).toEqual(''); - }); - }); -}); diff --git a/packages/ui-signer/src/Modal.tsx b/packages/ui-signer/src/Modal.tsx index 830807ad94..89d96ffd96 100644 --- a/packages/ui-signer/src/Modal.tsx +++ b/packages/ui-signer/src/Modal.tsx @@ -8,13 +8,15 @@ import { ApiProps } from '@polkadot/ui-api/types'; import { I18nProps, BareProps } from '@polkadot/ui-app/types'; import { RpcMethod } from '@polkadot/jsonrpc/types'; import { KeyringPair } from '@polkadot/keyring/types'; +import { SubjectInfo } from '@polkadot/ui-keyring/observable/types'; import { SignatureOptions } from '@polkadot/types/ExtrinsicSignature'; import { QueueTx, QueueTx$MessageSetStatus, QueueTx$Result, QueueTx$Status, SignerCallback } from '@polkadot/ui-app/Status/types'; import React from 'react'; import { Button, Modal } from '@polkadot/ui-app/index'; import keyring from '@polkadot/ui-keyring'; -import { withApi, withMulti } from '@polkadot/ui-api/index'; +import { withApi, withMulti, withObservable } from '@polkadot/ui-api/index'; +import accountObservable from '@polkadot/ui-keyring/observable/accounts'; import { assert } from '@polkadot/util'; import { format } from '@polkadot/util/logger'; @@ -27,7 +29,9 @@ type BaseProps = BareProps & { queueSetTxStatus: QueueTx$MessageSetStatus }; -type Props = I18nProps & ApiProps & BaseProps; +type Props = I18nProps & ApiProps & BaseProps & { + allAccounts?: SubjectInfo +}; type UnlockI18n = { key: string, @@ -36,17 +40,19 @@ type UnlockI18n = { type State = { currentItem?: QueueTx, + isSendable: boolean, password: string, unlockError: UnlockI18n | null }; class Signer extends React.PureComponent { state: State = { + isSendable: false, password: '', unlockError: null }; - static getDerivedStateFromProps ({ queue }: Props, { currentItem, password, unlockError }: State): State { + static getDerivedStateFromProps ({ allAccounts, queue }: Props, { currentItem, password, unlockError }: State): State { const nextItem = queue.find(({ status }) => status === 'queued' ); @@ -60,8 +66,21 @@ class Signer extends React.PureComponent { ) ); + let isSendable = !!nextItem && !!nextItem.isUnsigned; + + if (!isSendable && nextItem && nextItem.accountId && allAccounts) { + try { + const pair = keyring.getPair(nextItem.accountId); + + isSendable = !!pair && !!allAccounts[nextItem.accountId]; + } catch (error) { + // swallow + } + } + return { currentItem: nextItem, + isSendable, password: isSame ? password : '', unlockError: isSame ? unlockError : null }; @@ -96,7 +115,7 @@ class Signer extends React.PureComponent { private renderButtons () { const { t } = this.props; - const { currentItem } = this.state; + const { currentItem, isSendable } = this.state; if (!currentItem) { return null; @@ -114,6 +133,7 @@ class Signer extends React.PureComponent {