From b27c809c641ca5c1572e80a3aeafe34f2f4c79a0 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 27 Dec 2016 16:23:41 +0100 Subject: [PATCH] Visible accounts for dapps (default whitelist) (#3898) * Add APIs for Dapp management * Move AddDapps modal * Add DappsPermissions Modal (basics) * Allow whitelist editing * Add select/unselect tests * Case * Case * Modal render/non-render tests * UI made slightly prettier * Adjust spacing * Allow get/set of null for default whitelist (all) * Allow null = all for selection * Adjust selected background * Address valid comment on formatters location --- js/src/api/format/input.js | 4 + js/src/api/format/output.js | 4 + js/src/api/rpc/parity/parity.js | 37 +++++- js/src/jsonrpc/interfaces/parity.js | 64 ++++++++++ .../AddDapps/addDapps.css} | 0 .../AddDapps/addDapps.js} | 35 +++--- js/src/modals/AddDapps/addDapps.spec.js | 46 +++++++ .../{views/Dapps => modals}/AddDapps/index.js | 2 +- .../DappPermissions/dappPermissions.css | 47 ++++++++ .../modals/DappPermissions/dappPermissions.js | 112 ++++++++++++++++++ .../DappPermissions/dappPermissions.spec.js | 46 +++++++ js/src/modals/DappPermissions/index.js | 17 +++ js/src/modals/DappPermissions/store.js | 94 +++++++++++++++ js/src/modals/DappPermissions/store.spec.js | 100 ++++++++++++++++ js/src/modals/index.js | 4 + js/src/ui/Icons/index.js | 10 +- js/src/views/Dapps/dapps.js | 79 ++++++++---- 17 files changed, 650 insertions(+), 51 deletions(-) rename js/src/{views/Dapps/AddDapps/AddDapps.css => modals/AddDapps/addDapps.css} (100%) rename js/src/{views/Dapps/AddDapps/AddDapps.js => modals/AddDapps/addDapps.js} (94%) create mode 100644 js/src/modals/AddDapps/addDapps.spec.js rename js/src/{views/Dapps => modals}/AddDapps/index.js (95%) create mode 100644 js/src/modals/DappPermissions/dappPermissions.css create mode 100644 js/src/modals/DappPermissions/dappPermissions.js create mode 100644 js/src/modals/DappPermissions/dappPermissions.spec.js create mode 100644 js/src/modals/DappPermissions/index.js create mode 100644 js/src/modals/DappPermissions/store.js create mode 100644 js/src/modals/DappPermissions/store.spec.js diff --git a/js/src/api/format/input.js b/js/src/api/format/input.js index 4307fc912..7a41da109 100644 --- a/js/src/api/format/input.js +++ b/js/src/api/format/input.js @@ -24,6 +24,10 @@ export function inAddress (address) { return inHex(address); } +export function inAddresses (addresses) { + return (addresses || []).map(inAddress); +} + export function inBlockNumber (blockNumber) { if (isString(blockNumber)) { switch (blockNumber) { diff --git a/js/src/api/format/output.js b/js/src/api/format/output.js index 870e28fe3..cf707cbd1 100644 --- a/js/src/api/format/output.js +++ b/js/src/api/format/output.js @@ -42,6 +42,10 @@ export function outAddress (address) { return toChecksumAddress(address); } +export function outAddresses (addresses) { + return (addresses || []).map(outAddress); +} + export function outBlock (block) { if (block) { Object.keys(block).forEach((key) => { diff --git a/js/src/api/rpc/parity/parity.js b/js/src/api/rpc/parity/parity.js index e5ca31d89..174ad3fbf 100644 --- a/js/src/api/rpc/parity/parity.js +++ b/js/src/api/rpc/parity/parity.js @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -import { inAddress, inData, inHex, inNumber16, inOptions } from '../../format/input'; -import { outAccountInfo, outAddress, outChainStatus, outHistogram, outNumber, outPeers, outTransaction } from '../../format/output'; +import { inAddress, inAddresses, inData, inHex, inNumber16, inOptions } from '../../format/input'; +import { outAccountInfo, outAddress, outAddresses, outChainStatus, outHistogram, outNumber, outPeers, outTransaction } from '../../format/output'; export default class Parity { constructor (transport) { @@ -128,6 +128,18 @@ export default class Parity { .execute('parity_generateSecretPhrase'); } + getDappsAddresses (dappId) { + return this._transport + .execute('parity_getDappsAddresses', dappId) + .then(outAddresses); + } + + getNewDappsWhitelist () { + return this._transport + .execute('parity_getNewDappsWhitelist') + .then((addresses) => addresses ? addresses.map(outAddress) : null); + } + hashContent (url) { return this._transport .execute('parity_hashContent', url); @@ -135,8 +147,8 @@ export default class Parity { importGethAccounts (accounts) { return this._transport - .execute('parity_importGethAccounts', (accounts || []).map(inAddress)) - .then((accounts) => (accounts || []).map(outAddress)); + .execute('parity_importGethAccounts', inAddresses) + .then(outAddresses); } killAccount (account, password) { @@ -144,6 +156,11 @@ export default class Parity { .execute('parity_killAccount', inAddress(account), password); } + listRecentDapps () { + return this._transport + .execute('parity_listRecentDapps'); + } + removeAddress (address) { return this._transport .execute('parity_removeAddress', inAddress(address)); @@ -152,7 +169,7 @@ export default class Parity { listGethAccounts () { return this._transport .execute('parity_listGethAccounts') - .then((accounts) => (accounts || []).map(outAddress)); + .then(outAddresses); } localTransactions () { @@ -289,6 +306,11 @@ export default class Parity { .execute('parity_setAuthor', inAddress(address)); } + setDappsAddresses (dappId, addresses) { + return this._transport + .execute('parity_setDappsAddresses', dappId, inAddresses(addresses)); + } + setExtraData (data) { return this._transport .execute('parity_setExtraData', inData(data)); @@ -309,6 +331,11 @@ export default class Parity { .execute('parity_setMode', mode); } + setNewDappsWhitelist (addresses) { + return this._transport + .execute('parity_setNewDappsWhitelist', addresses ? inAddresses(addresses) : null); + } + setTransactionsLimit (quantity) { return this._transport .execute('parity_setTransactionsLimit', inNumber16(quantity)); diff --git a/js/src/jsonrpc/interfaces/parity.js b/js/src/jsonrpc/interfaces/parity.js index 2c0cefaef..1f6caca4a 100644 --- a/js/src/jsonrpc/interfaces/parity.js +++ b/js/src/jsonrpc/interfaces/parity.js @@ -236,6 +236,29 @@ export default { } }, + getDappsAddresses: { + desc: 'Returns the list of accounts available to a specific dapp', + params: [ + { + type: String, + desc: 'Dapp Id' + } + ], + returns: { + type: Array, + desc: 'The list of available accounts' + } + }, + + getNewDappsWhitelist: { + desc: 'Returns the list of accounts available to a new dapps', + params: [], + returns: { + type: Array, + desc: 'The list of available accounts' + } + }, + hashContent: { desc: 'Creates a hash of the file as retrieved', params: [ @@ -282,6 +305,15 @@ export default { } }, + listRecentDapps: { + desc: 'Returns a list of the most recent active dapps', + params: [], + returns: { + type: Array, + desc: 'Array of Dapp Ids' + } + }, + removeAddress: { desc: 'Removes an address from the addressbook', params: [ @@ -586,6 +618,24 @@ export default { } }, + setDappsAddresses: { + desc: 'Sets the available addresses for a dapp', + params: [ + { + type: String, + desc: 'Dapp Id' + }, + { + type: Array, + desc: 'Array of available accounts available to the dapp' + } + ], + returns: { + type: Boolean, + desc: 'True if the call succeeded' + } + }, + setExtraData: { desc: 'Changes extra data for newly mined blocks', params: [ @@ -645,6 +695,20 @@ export default { } }, + setNewDappsWhitelist: { + desc: 'Sets the list of accounts available to new dapps', + params: [ + { + type: Array, + desc: 'List of accounts available by default' + } + ], + returns: { + type: Boolean, + desc: 'True if the call succeeded' + } + }, + setTransactionsLimit: { desc: 'Changes limit for transactions in queue.', params: [ diff --git a/js/src/views/Dapps/AddDapps/AddDapps.css b/js/src/modals/AddDapps/addDapps.css similarity index 100% rename from js/src/views/Dapps/AddDapps/AddDapps.css rename to js/src/modals/AddDapps/addDapps.css diff --git a/js/src/views/Dapps/AddDapps/AddDapps.js b/js/src/modals/AddDapps/addDapps.js similarity index 94% rename from js/src/views/Dapps/AddDapps/AddDapps.js rename to js/src/modals/AddDapps/addDapps.js index cc2b60552..f079c900f 100644 --- a/js/src/views/Dapps/AddDapps/AddDapps.js +++ b/js/src/modals/AddDapps/addDapps.js @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +import { Checkbox } from 'material-ui'; +import { List, ListItem } from 'material-ui/List'; +import { observer } from 'mobx-react'; import React, { Component, PropTypes } from 'react'; import { FormattedMessage } from 'react-intl'; -import { observer } from 'mobx-react'; -import DoneIcon from 'material-ui/svg-icons/action/done'; -import { List, ListItem } from 'material-ui/List'; -import Checkbox from 'material-ui/Checkbox'; import { Modal, Button } from '~/ui'; +import { DoneIcon } from '~/ui/Icons'; -import styles from './AddDapps.css'; +import styles from './addDapps.css'; @observer export default class AddDapps extends Component { @@ -40,25 +40,24 @@ export default class AddDapps extends Component { return ( } + key='done' + label={ + + } + onClick={ store.closeModal } /> + ] } compact title={ } - actions={ [ -