Show all accounts on Topbar (#7498)

* Show all accounts in the top bar

* Update to latest js-shared

* Add comments

* Update refs and remove dapp-dapp-accounts
This commit is contained in:
Amaury Martiny 2018-01-08 16:21:52 +01:00 committed by Jaco Greeff
parent a553485bbd
commit c6b0db61e7
5 changed files with 113 additions and 59 deletions

112
js/package-lock.json generated
View File

@ -44,10 +44,6 @@
"version": "github:paritytech/dapp-console#7dc791af2943ddc949ec501726dc36161279eac1", "version": "github:paritytech/dapp-console#7dc791af2943ddc949ec501726dc36161279eac1",
"dev": true "dev": true
}, },
"@parity/dapp-dapp-accounts": {
"version": "github:paritytech/dapp-dapp-accounts#47384068f07331f0a843a6f609bd048955dac041",
"dev": true
},
"@parity/dapp-dapp-methods": { "@parity/dapp-dapp-methods": {
"version": "github:js-dist-paritytech/dapp-dapp-methods#b4dce52a09303fddf55172bb0d2e6bb83f12e196", "version": "github:js-dist-paritytech/dapp-dapp-methods#b4dce52a09303fddf55172bb0d2e6bb83f12e196",
"dev": true, "dev": true,
@ -132,7 +128,7 @@
} }
}, },
"@parity/dapp-dapp-visible": { "@parity/dapp-dapp-visible": {
"version": "github:js-dist-paritytech/dapp-dapp-visible#2621fc479b52948cbce2d468fcb7b4da51039fc9", "version": "github:js-dist-paritytech/dapp-dapp-visible#19f0b7d3de7bcc9859ac5d8059e866e1f5804366",
"dev": true, "dev": true,
"requires": { "requires": {
"@parity/api": "2.1.14", "@parity/api": "2.1.14",
@ -365,9 +361,9 @@
"version": "github:paritytech/plugin-signer-qr#c16423de5b8a8f68ebd5f1e78e084fa959329a9f" "version": "github:paritytech/plugin-signer-qr#c16423de5b8a8f68ebd5f1e78e084fa959329a9f"
}, },
"@parity/shared": { "@parity/shared": {
"version": "2.2.20", "version": "2.2.21",
"resolved": "https://registry.npmjs.org/@parity/shared/-/shared-2.2.20.tgz", "resolved": "https://registry.npmjs.org/@parity/shared/-/shared-2.2.21.tgz",
"integrity": "sha512-qOD+3TtZ9cbRSugl12VKmsjJKUfejG208Lugzfrs1irrkB3S7jHhYAYa+tkMrHafQX9MbsfpmkDT6jToh5iOIg==", "integrity": "sha512-8Xuuv/SpS+lviX3xRVvh3UUMcWYrQPQvn+KkSiKofuHlVL/IlhEnLyflk5j5FgGviXwaqBxmOllTSTPQBna4Gw==",
"requires": { "requires": {
"@parity/ledger": "2.1.2", "@parity/ledger": "2.1.2",
"eventemitter3": "2.0.3", "eventemitter3": "2.0.3",
@ -419,6 +415,37 @@
"loose-envify": "1.3.1", "loose-envify": "1.3.1",
"symbol-observable": "1.1.0" "symbol-observable": "1.1.0"
} }
},
"solc": {
"version": "github:ngotchac/solc-js#04eb38cc3003fba8cb3656653a7941ed36408818",
"requires": {
"memorystream": "0.3.1",
"require-from-string": "1.2.1",
"yargs": "4.8.1"
},
"dependencies": {
"yargs": {
"version": "4.8.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-4.8.1.tgz",
"integrity": "sha1-wMQpJMpKqmsObaFznfshZDn53cA=",
"requires": {
"cliui": "3.2.0",
"decamelize": "1.2.0",
"get-caller-file": "1.0.2",
"lodash.assign": "4.2.0",
"os-locale": "1.4.0",
"read-pkg-up": "1.0.1",
"require-directory": "2.1.1",
"require-main-filename": "1.0.1",
"set-blocking": "2.0.0",
"string-width": "1.0.2",
"which-module": "1.0.0",
"window-size": "0.2.0",
"y18n": "3.2.1",
"yargs-parser": "2.4.1"
}
}
}
} }
} }
}, },
@ -430,7 +457,7 @@
"@parity/api": "2.1.14", "@parity/api": "2.1.14",
"@parity/etherscan": "2.1.3", "@parity/etherscan": "2.1.3",
"@parity/mobx": "1.0.4", "@parity/mobx": "1.0.4",
"@parity/shared": "2.2.20", "@parity/shared": "2.2.21",
"babel-runtime": "6.26.0", "babel-runtime": "6.26.0",
"bignumber.js": "4.1.0", "bignumber.js": "4.1.0",
"brace": "0.11.0", "brace": "0.11.0",
@ -2610,7 +2637,7 @@
}, },
"capture-stack-trace": { "capture-stack-trace": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/capture-stack-trace/-/capture-stack-trace-1.0.0.tgz", "resolved": "http://registry.npmjs.org/capture-stack-trace/-/capture-stack-trace-1.0.0.tgz",
"integrity": "sha1-Sm+gc5nCa7pH8LJJa00PtAjFVQ0=", "integrity": "sha1-Sm+gc5nCa7pH8LJJa00PtAjFVQ0=",
"dev": true "dev": true
}, },
@ -3491,7 +3518,7 @@
}, },
"create-error-class": { "create-error-class": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/create-error-class/-/create-error-class-3.0.2.tgz", "resolved": "http://registry.npmjs.org/create-error-class/-/create-error-class-3.0.2.tgz",
"integrity": "sha1-Br56vvlHo/FKMP1hBnHUAbyot7Y=", "integrity": "sha1-Br56vvlHo/FKMP1hBnHUAbyot7Y=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -4343,9 +4370,9 @@
} }
}, },
"doctrine": { "doctrine": {
"version": "2.0.2", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.0.2.tgz", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz",
"integrity": "sha512-y0tm5Pq6ywp3qSTZ1vPgVdAnbDEoeoc5wlOHXoY1c4Wug/a7JvqHIl7BTvwodaHmejWkK/9dSb3sCYfyo/om8A==", "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==",
"dev": true, "dev": true,
"requires": { "requires": {
"esutils": "2.0.2" "esutils": "2.0.2"
@ -5301,9 +5328,9 @@
} }
}, },
"eslint-import-resolver-node": { "eslint-import-resolver-node": {
"version": "0.3.1", "version": "0.3.2",
"resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.1.tgz", "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz",
"integrity": "sha512-yUtXS15gIcij68NmXmP9Ni77AQuCN0itXbCc/jWd8C6/yKZaSNXicpC8cgvjnxVdmfsosIXrjpzFq7GcDryb6A==", "integrity": "sha512-sfmTqJfPSizWu4aymbPr4Iidp5yKm8yDkHp+Ir3YiTHiiDfxh69mOUsmiqW6RZ9zRXFaF64GtYmN7e+8GHBv6Q==",
"dev": true, "dev": true,
"requires": { "requires": {
"debug": "2.6.9", "debug": "2.6.9",
@ -5363,7 +5390,7 @@
"contains-path": "0.1.0", "contains-path": "0.1.0",
"debug": "2.6.9", "debug": "2.6.9",
"doctrine": "1.5.0", "doctrine": "1.5.0",
"eslint-import-resolver-node": "0.3.1", "eslint-import-resolver-node": "0.3.2",
"eslint-module-utils": "2.1.1", "eslint-module-utils": "2.1.1",
"has": "1.0.1", "has": "1.0.1",
"lodash.cond": "4.5.2", "lodash.cond": "4.5.2",
@ -8225,9 +8252,9 @@
"dev": true "dev": true
}, },
"is-ci": { "is-ci": {
"version": "1.0.10", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.0.10.tgz", "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.1.0.tgz",
"integrity": "sha1-9zkzayYyNlBhqdSCcM1WrjNpMY4=", "integrity": "sha512-c7TnwxLePuqIlxHgr7xtxzycJPegNHFuIrBkwbf8hc58//+Op1CqFkyS+xnIMkwn9UsJIwc174BIjkyBmSpjKg==",
"dev": true, "dev": true,
"requires": { "requires": {
"ci-info": "1.1.2" "ci-info": "1.1.2"
@ -8729,7 +8756,7 @@
"callsites": "2.0.0", "callsites": "2.0.0",
"chalk": "1.1.3", "chalk": "1.1.3",
"graceful-fs": "4.1.11", "graceful-fs": "4.1.11",
"is-ci": "1.0.10", "is-ci": "1.1.0",
"istanbul-api": "1.2.1", "istanbul-api": "1.2.1",
"istanbul-lib-coverage": "1.1.1", "istanbul-lib-coverage": "1.1.1",
"istanbul-lib-instrument": "1.9.1", "istanbul-lib-instrument": "1.9.1",
@ -13423,7 +13450,7 @@
"concat-stream": "1.6.0", "concat-stream": "1.6.0",
"cross-spawn": "5.1.0", "cross-spawn": "5.1.0",
"debug": "3.1.0", "debug": "3.1.0",
"doctrine": "2.0.2", "doctrine": "2.1.0",
"eslint-scope": "3.7.1", "eslint-scope": "3.7.1",
"espree": "3.5.2", "espree": "3.5.2",
"esquery": "1.0.0", "esquery": "1.0.0",
@ -13490,7 +13517,7 @@
"integrity": "sha512-tvjU9u3VqmW2vVuYnE8Qptq+6ji4JltjOjJ9u7VAOxVYkUkyBZWRvNYKbDv5fN+L6wiA+4we9+qQahZ0m63XEA==", "integrity": "sha512-tvjU9u3VqmW2vVuYnE8Qptq+6ji4JltjOjJ9u7VAOxVYkUkyBZWRvNYKbDv5fN+L6wiA+4we9+qQahZ0m63XEA==",
"dev": true, "dev": true,
"requires": { "requires": {
"doctrine": "2.0.2", "doctrine": "2.1.0",
"has": "1.0.1", "has": "1.0.1",
"jsx-ast-utils": "2.0.1", "jsx-ast-utils": "2.0.1",
"prop-types": "15.5.10" "prop-types": "15.5.10"
@ -13683,7 +13710,7 @@
"dev": true, "dev": true,
"requires": { "requires": {
"loader-utils": "1.1.0", "loader-utils": "1.1.0",
"postcss": "6.0.14", "postcss": "6.0.16",
"postcss-load-config": "1.2.0", "postcss-load-config": "1.2.0",
"schema-utils": "0.3.0" "schema-utils": "0.3.0"
}, },
@ -13697,6 +13724,17 @@
"ansi-styles": "3.2.0", "ansi-styles": "3.2.0",
"escape-string-regexp": "1.0.5", "escape-string-regexp": "1.0.5",
"supports-color": "4.5.0" "supports-color": "4.5.0"
},
"dependencies": {
"supports-color": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz",
"integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=",
"dev": true,
"requires": {
"has-flag": "2.0.0"
}
}
} }
}, },
"has-flag": { "has-flag": {
@ -13706,14 +13744,14 @@
"dev": true "dev": true
}, },
"postcss": { "postcss": {
"version": "6.0.14", "version": "6.0.16",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-6.0.14.tgz", "resolved": "https://registry.npmjs.org/postcss/-/postcss-6.0.16.tgz",
"integrity": "sha512-NJ1z0f+1offCgadPhz+DvGm5Mkci+mmV5BqD13S992o0Xk9eElxUfPPF+t2ksH5R/17gz4xVK8KWocUQ5o3Rog==", "integrity": "sha512-m758RWPmSjFH/2MyyG3UOW1fgYbR9rtdzz5UNJnlm7OLtu4B2h9C6gi+bE4qFKghsBRFfZT8NzoQBs6JhLotoA==",
"dev": true, "dev": true,
"requires": { "requires": {
"chalk": "2.3.0", "chalk": "2.3.0",
"source-map": "0.6.1", "source-map": "0.6.1",
"supports-color": "4.5.0" "supports-color": "5.1.0"
} }
}, },
"source-map": { "source-map": {
@ -13723,9 +13761,9 @@
"dev": true "dev": true
}, },
"supports-color": { "supports-color": {
"version": "4.5.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.1.0.tgz",
"integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", "integrity": "sha512-Ry0AwkoKjDpVKK4sV4h6o3UJmNRbjYm2uXhwfj3J56lMVdvnUNqzQVRztOOMGQ++w1K/TjNDFvpJk0F/LoeBCQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"has-flag": "2.0.0" "has-flag": "2.0.0"
@ -14202,7 +14240,7 @@
}, },
"read-all-stream": { "read-all-stream": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/read-all-stream/-/read-all-stream-3.1.0.tgz", "resolved": "http://registry.npmjs.org/read-all-stream/-/read-all-stream-3.1.0.tgz",
"integrity": "sha1-NcPhd/IHjveJ7kv6+kNzB06u9Po=", "integrity": "sha1-NcPhd/IHjveJ7kv6+kNzB06u9Po=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -16093,7 +16131,7 @@
"requires": { "requires": {
"del": "2.2.2", "del": "2.2.2",
"sw-precache": "5.2.0", "sw-precache": "5.2.0",
"uglify-js": "3.2.2" "uglify-js": "3.3.5"
}, },
"dependencies": { "dependencies": {
"source-map": { "source-map": {
@ -16103,9 +16141,9 @@
"dev": true "dev": true
}, },
"uglify-js": { "uglify-js": {
"version": "3.2.2", "version": "3.3.5",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.2.2.tgz", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.3.5.tgz",
"integrity": "sha512-++1NO/zZIEdWf6cDIGceSJQPX31SqIpbVAHwFG5+240MtZqPG/NIPoinj8zlXQtAfMBqEt1Jyv2FiLP3n9gVhQ==", "integrity": "sha512-ZebM2kgBL/UI9rKeAbsS2J0UPPv7SBy5hJNZml/YxB1zC6JK8IztcPs+cxilE4pu0li6vadVSFqiO7xFTKuSrg==",
"dev": true, "dev": true,
"requires": { "requires": {
"commander": "2.12.2", "commander": "2.12.2",

View File

@ -45,7 +45,6 @@
}, },
"devDependencies": { "devDependencies": {
"@parity/dapp-console": "paritytech/dapp-console", "@parity/dapp-console": "paritytech/dapp-console",
"@parity/dapp-dapp-accounts": "paritytech/dapp-dapp-accounts",
"@parity/dapp-dapp-methods": "js-dist-paritytech/dapp-dapp-methods", "@parity/dapp-dapp-methods": "js-dist-paritytech/dapp-dapp-methods",
"@parity/dapp-dapp-visible": "js-dist-paritytech/dapp-dapp-visible", "@parity/dapp-dapp-visible": "js-dist-paritytech/dapp-dapp-visible",
"@parity/dapp-dappreg": "paritytech/dapp-dappreg", "@parity/dapp-dappreg": "paritytech/dapp-dappreg",
@ -147,7 +146,7 @@
"@parity/plugin-signer-default": "paritytech/plugin-signer-default", "@parity/plugin-signer-default": "paritytech/plugin-signer-default",
"@parity/plugin-signer-hardware": "paritytech/plugin-signer-hardware", "@parity/plugin-signer-hardware": "paritytech/plugin-signer-hardware",
"@parity/plugin-signer-qr": "paritytech/plugin-signer-qr", "@parity/plugin-signer-qr": "paritytech/plugin-signer-qr",
"@parity/shared": "2.2.20", "@parity/shared": "2.2.21",
"@parity/ui": "3.0.22", "@parity/ui": "3.0.22",
"keythereum": "1.0.2", "keythereum": "1.0.2",
"lodash.flatten": "4.4.0", "lodash.flatten": "4.4.0",

View File

@ -14,15 +14,17 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import { action, observable, transaction } from 'mobx'; import { action, computed, observable, transaction } from 'mobx';
let instance; let instance;
export default class AccountStore { export default class AccountStore {
@observable accounts = []; @observable allAccounts = [];
@observable defaultAccount = null; @observable defaultAccount = null;
@observable isLoading = false; @observable isLoading = false;
whitelist = []; // Whitelist of account addresses visible by dapps, i.e. parity_getNewDappsAddresses
constructor (api) { constructor (api) {
this._api = api; this._api = api;
@ -31,13 +33,27 @@ export default class AccountStore {
.then(() => this.loadAccounts()); .then(() => this.loadAccounts());
} }
/**
* Accounts that are whitelisted to be shown to dapps
*/
@computed get accounts () {
return this.allAccounts.filter(account => this.whitelist.includes(account.address));
}
/**
* For backwards compatibility
*/
@action setAccounts = (accounts) => { @action setAccounts = (accounts) => {
this.accounts = accounts; return this.setAllAccounts(accounts);
}
@action setAllAccounts = (allAccounts) => {
this.allAccounts = allAccounts;
} }
@action setDefaultAccount = (defaultAccount) => { @action setDefaultAccount = (defaultAccount) => {
transaction(() => { transaction(() => {
this.accounts = this.accounts.map((account) => { this.allAccounts = this.allAccounts.map((account) => {
account.checked = account.address === defaultAccount; account.checked = account.address === defaultAccount;
return account; return account;
@ -70,6 +86,8 @@ export default class AccountStore {
this._api.parity.allAccountsInfo() this._api.parity.allAccountsInfo()
]) ])
.then(([whitelist, allAccounts]) => { .then(([whitelist, allAccounts]) => {
this.whitelist = whitelist;
transaction(() => { transaction(() => {
const accounts = Object const accounts = Object
.keys(allAccounts) .keys(allAccounts)
@ -77,9 +95,8 @@ export default class AccountStore {
const account = allAccounts[address]; const account = allAccounts[address];
const isAccount = account.uuid; const isAccount = account.uuid;
const isExternal = account.meta && (account.meta.external || account.meta.hardware); const isExternal = account.meta && (account.meta.external || account.meta.hardware);
const isWhitelisted = !whitelist || whitelist.includes(address);
return (isAccount || isExternal) && isWhitelisted; return (isAccount || isExternal);
}) })
.map((address) => { .map((address) => {
return { return {
@ -90,7 +107,7 @@ export default class AccountStore {
}); });
this.setLoading(false); this.setLoading(false);
this.setAccounts(accounts); this.setAllAccounts(accounts);
}); });
}) })
.catch((error) => { .catch((error) => {
@ -119,7 +136,7 @@ export default class AccountStore {
} }
}); });
return Promise.all([ promiseDefaultAccount, promiseEthAccounts, promiseAccountsInfo ]); return Promise.all([promiseDefaultAccount, promiseEthAccounts, promiseAccountsInfo]);
} }
static get (api) { static get (api) {

View File

@ -42,10 +42,10 @@ describe('ParityBar/AccountStore', () => {
}); });
describe('@action', () => { describe('@action', () => {
describe('setAccounts', () => { describe('setAllAccounts', () => {
it('sets the accounts', () => { it('sets the accounts', () => {
store.setAccounts('testing'); store.setAllAccounts('testing');
expect(store.accounts).to.equal('testing'); expect(store.allAccounts).to.equal('testing');
}); });
}); });
@ -67,13 +67,13 @@ describe('ParityBar/AccountStore', () => {
describe('operations', () => { describe('operations', () => {
describe('loadAccounts', () => { describe('loadAccounts', () => {
beforeEach(() => { beforeEach(() => {
sinon.spy(store, 'setAccounts'); sinon.spy(store, 'setAllAccounts');
return store.loadAccounts(); return store.loadAccounts();
}); });
afterEach(() => { afterEach(() => {
store.setAccounts.restore(); store.setAllAccounts.restore();
}); });
it('calls into parity_getNewDappsAddresses', () => { it('calls into parity_getNewDappsAddresses', () => {
@ -85,7 +85,7 @@ describe('ParityBar/AccountStore', () => {
}); });
it('sets the accounts', () => { it('sets the accounts', () => {
expect(store.setAccounts).to.have.been.called; expect(store.setAllAccounts).to.have.been.called;
}); });
}); });

View File

@ -50,10 +50,10 @@ class DefaultAccount extends Component {
} }
render () { render () {
const { accounts, defaultAccount: defaultAddress } = this.props.accountStore; const { allAccounts, defaultAccount: defaultAddress } = this.props.accountStore;
const defaultAccount = accounts.find(({ address }) => address === defaultAddress); const defaultAccount = allAccounts.find(({ address }) => address === defaultAddress);
if (!accounts || !defaultAccount) { return null; } if (!allAccounts || !defaultAccount) { return null; }
return ( return (
<Popup <Popup
@ -68,15 +68,15 @@ class DefaultAccount extends Component {
} }
content={ content={
<div> <div>
<List relaxed='very' selection className={ [styles.list, styles.isDefault, accounts.length > 1 && styles.hasOtherAccounts].join(' ') }> <List relaxed='very' selection className={ [styles.list, styles.isDefault, allAccounts.length > 1 && styles.hasOtherAccounts].join(' ') }>
<AccountItem <AccountItem
isDefault isDefault
account={ defaultAccount } account={ defaultAccount }
/> />
</List> </List>
{accounts.length > 1 && {allAccounts.length > 1 &&
<List relaxed='very' selection className={ styles.list } divided> <List relaxed='very' selection className={ styles.list } divided>
{accounts {allAccounts
.filter(({ address }) => address !== defaultAddress) .filter(({ address }) => address !== defaultAddress)
.map(account => ( .map(account => (
<AccountItem <AccountItem