Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

[beta] Backporting #6676

Merged
merged 4 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions js/src/modals/CreateAccount/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default class Store {
@observable gethAddresses = [];
@observable gethImported = [];
@observable isBusy = false;
@observable isTest = false;
@observable isWindowsPhrase = false;
@observable name = '';
@observable nameError = ERRORS.noName;
Expand Down Expand Up @@ -310,6 +311,10 @@ export default class Store {
this.stage--;
}

@action setIsTest = isTest => {
this.isTest = isTest;
}

createAccount = (vaultStore) => {
if (!this.canCreate) {
return false;
Expand Down
32 changes: 28 additions & 4 deletions js/src/modals/CreateWallet/WalletDetails/walletDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@

import React, { Component, PropTypes } from 'react';
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';

import { Form, TypedInput, Input, AddressSelect, InputAddress } from '~/ui';

import styles from '../createWallet.css';

export default class WalletDetails extends Component {
class WalletDetails extends Component {
static propTypes = {
accounts: PropTypes.object.isRequired,
wallet: PropTypes.object.isRequired,
errors: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
walletType: PropTypes.string.isRequired
walletType: PropTypes.string.isRequired,

knownAddresses: PropTypes.array
};

render () {
Expand Down Expand Up @@ -103,7 +106,10 @@ export default class WalletDetails extends Component {
}

renderMultisigDetails () {
const { accounts, wallet, errors } = this.props;
const { accounts, knownAddresses, wallet, errors } = this.props;
const allowedOwners = knownAddresses
// Exclude sender and already owners of the wallet
.filter((address) => !wallet.owners.includes(address) && address !== wallet.account);

return (
<Form>
Expand Down Expand Up @@ -163,7 +169,7 @@ export default class WalletDetails extends Component {
/>

<TypedInput
accounts={ accounts }
allowedValues={ allowedOwners }
label={
<FormattedMessage
id='createWallet.details.ownersMulti.label'
Expand Down Expand Up @@ -249,3 +255,21 @@ export default class WalletDetails extends Component {
this.props.onChange({ daylimit });
}
}

function mapStateToProps (initState) {
const { accounts, contacts, contracts } = initState.personal;
const knownAddresses = [].concat(
Object.keys(accounts),
Object.keys(contacts),
Object.keys(contracts)
);

return () => ({
knownAddresses
});
}

export default connect(
mapStateToProps,
null
)(WalletDetails);
23 changes: 22 additions & 1 deletion js/src/modals/CreateWallet/WalletDetails/walletDetails.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ import { ACCOUNTS } from '../createWallet.test.js';
let component;
let onChange;

function createRedux () {
return {
dispatch: sinon.stub(),
subscribe: sinon.stub(),
getState: () => {
return {
personal: {
accounts: {},
contacts: {},
contracts: {}
}
};
}
};
}

function render (walletType = 'MULTISIG') {
onChange = sinon.stub();
component = shallow(
Expand All @@ -36,7 +52,12 @@ function render (walletType = 'MULTISIG') {
owners: []
} }
walletType={ walletType }
/>
/>,
{
context: {
store: createRedux()
}
}
);

return component;
Expand Down
3 changes: 2 additions & 1 deletion js/src/modals/CreateWallet/createWalletStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ export default class CreateWalletStore {

const owners = _wallet.owners.filter((owner) => !/^(0x)?0*$/.test(owner));

if (_wallet.required > owners.length) {
// Real number of owners is owners + creator
if (_wallet.required > owners.length + 1) {
requiredValidation.valueError = 'the number of required validators should be lower or equal the number of owners';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export default class ParametersStep extends Component {
};

static propTypes = {
accounts: PropTypes.object.isRequired,
onParamsChange: PropTypes.func.isRequired,

inputs: PropTypes.array,
Expand All @@ -60,7 +59,7 @@ export default class ParametersStep extends Component {
}

renderConstructorInputs () {
const { accounts, params, paramsError } = this.props;
const { params, paramsError } = this.props;
const { inputs } = this.props;

if (!inputs || !inputs.length) {
Expand All @@ -78,7 +77,6 @@ export default class ParametersStep extends Component {
return (
<div key={ index } className={ styles.funcparams }>
<TypedInput
accounts={ accounts }
error={ error }
isEth={ false }
label={ label }
Expand Down
1 change: 0 additions & 1 deletion js/src/modals/DeployContract/deployContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ class DeployContract extends Component {
return (
<ParametersStep
{ ...this.state }
accounts={ accounts }
onParamsChange={ this.onParamsChange }
readOnly={ readOnly }
/>
Expand Down
3 changes: 1 addition & 2 deletions js/src/modals/ExecuteContract/DetailsStep/detailsStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default class DetailsStep extends Component {
}

renderParameters () {
const { accounts, func, values, valuesError, onValueChange } = this.props;
const { func, values, valuesError, onValueChange } = this.props;

if (!func) {
return null;
Expand All @@ -197,7 +197,6 @@ export default class DetailsStep extends Component {
value={ values[index] }
error={ valuesError[index] }
onChange={ onChange }
accounts={ accounts }
param={ input.type }
isEth={ false }
/>
Expand Down
14 changes: 11 additions & 3 deletions js/src/modals/FirstRun/firstRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,23 @@ class FirstRun extends Component {
hasAccounts: PropTypes.bool.isRequired,
newError: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
visible: PropTypes.bool.isRequired
visible: PropTypes.bool.isRequired,
isTest: PropTypes.bool.isRequired
}

createStore = new CreateStore(this.context.api, {}, true, false);
createStore = new CreateStore(this.context.api, {}, this.props.isTest, false);

state = {
stage: 0,
hasAcceptedTnc: false
}

componentWillReceiveProps (nextProps) {
if (nextProps.isTest !== this.props.isTest) {
this.createStore.setIsTest(nextProps.isTest);
}
}

render () {
const { visible } = this.props;
const { stage } = this.state;
Expand Down Expand Up @@ -348,9 +355,10 @@ class FirstRun extends Component {

function mapStateToProps (state) {
const { hasAccounts } = state.personal;
const { isTest } = state.nodeStatus;

return {
hasAccounts
hasAccounts, isTest
};
}

Expand Down
3 changes: 3 additions & 0 deletions js/src/modals/FirstRun/firstRun.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ function createRedux () {
return {
personal: {
hasAccounts: false
},
nodeStatus: {
isTest: false
}
};
}
Expand Down
8 changes: 3 additions & 5 deletions js/src/modals/WalletSettings/walletSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class WalletSettings extends Component {
};

static propTypes = {
accountsInfo: PropTypes.object.isRequired,
wallet: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
senders: PropTypes.object.isRequired
Expand Down Expand Up @@ -74,7 +73,7 @@ class WalletSettings extends Component {
default:
case 'EDIT':
const { errors, fromString, wallet } = this.store;
const { accountsInfo, senders } = this.props;
const { senders } = this.props;

return (
<Form>
Expand Down Expand Up @@ -143,7 +142,6 @@ class WalletSettings extends Component {
}
value={ wallet.owners.slice() }
onChange={ this.store.onOwnersChange }
accounts={ accountsInfo }
param='address[]'
/>

Expand Down Expand Up @@ -443,13 +441,13 @@ class WalletSettings extends Component {
}

function mapStateToProps (initState, initProps) {
const { accountsInfo, accounts } = initState.personal;
const { accounts } = initState.personal;
const { owners } = initProps.wallet;

const senders = pick(accounts, owners);

return () => {
return { accountsInfo, senders };
return { senders };
};
}

Expand Down
13 changes: 13 additions & 0 deletions js/src/ui/Form/AddressSelect/addressSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import { eq } from 'lodash';
import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
import { connect } from 'react-redux';
Expand Down Expand Up @@ -93,6 +94,18 @@ class AddressSelect extends Component {
}

componentWillReceiveProps (nextProps) {
if (!eq(Object.keys(this.props.accounts), Object.keys(nextProps.accounts))) {
return this.setValues(nextProps);
}

if (!eq(Object.keys(this.props.contacts), Object.keys(nextProps.contacts))) {
return this.setValues(nextProps);
}

if (!eq(Object.keys(this.props.contracts), Object.keys(nextProps.contracts))) {
return this.setValues(nextProps);
}

if (this.store.values && this.store.values.length > 0) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion js/src/ui/Form/AddressSelect/addressSelectStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ export default class AddressSelectStore {
const contactsN = Object.keys(contacts).length;

if (accountsN + contractsN + contactsN === 0) {
return;
this.initValues = [];
return this.handleChange();
}

this.initValues = [
Expand Down
5 changes: 4 additions & 1 deletion js/src/ui/Form/Input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import React, { Component, PropTypes } from 'react';
import { TextField } from 'material-ui';
import { noop } from 'lodash';
import keycode from 'keycode';
import localStore from 'store';

import { nodeOrStringProptype } from '~/util/proptypes';
import { toString } from '~/util/messages';
Expand Down Expand Up @@ -223,7 +224,9 @@ export default class Input extends Component {
}

onChange = (event, value) => {
if (!this.props.allowPaste) {
const isDev = localStore.get('allYourBaseAreBelongToUs') || false;

if (!this.props.allowPaste && !isDev) {
if (value.length - this.state.value.length > 8) {
return;
}
Expand Down
27 changes: 23 additions & 4 deletions js/src/ui/Form/InputAddressSelect/inputAddressSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import { pick } from 'lodash';
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';

Expand All @@ -28,6 +29,7 @@ class InputAddressSelect extends Component {
contracts: PropTypes.object.isRequired,

allowCopy: PropTypes.bool,
allowedValues: PropTypes.array,
className: PropTypes.string,
error: nodeOrStringProptype(),
hint: nodeOrStringProptype(),
Expand All @@ -38,16 +40,33 @@ class InputAddressSelect extends Component {
};

render () {
const { accounts, allowCopy, className, contacts, contracts, label, hint, error, value, onChange, readOnly } = this.props;
const { accounts, allowCopy, allowedValues, className, contacts, contracts, label, hint, error, value, onChange, readOnly } = this.props;
// Add the currently selected value to the list
// of allowed values, if any given
const nextAllowedValues = allowedValues
? [].concat(allowedValues, value || [])
: null;

const filteredAccounts = nextAllowedValues
? pick(accounts, nextAllowedValues)
: accounts;

const filteredContacts = nextAllowedValues
? pick(contacts, nextAllowedValues)
: accounts;

const filteredContracts = nextAllowedValues
? pick(contracts, nextAllowedValues)
: accounts;

return (
<AddressSelect
allowCopy={ allowCopy }
allowInput
accounts={ accounts }
accounts={ filteredAccounts }
className={ className }
contacts={ contacts }
contracts={ contracts }
contacts={ filteredContacts }
contracts={ filteredContracts }
error={ error }
hint={ hint }
label={ label }
Expand Down
Loading