Fix dapp account selection (#3399)

* Fix GHH accounts (filter non accounts)

* SignatureReg handle undefined ABI names gracefully

* SignatureReg fix accounts (filter non accounts)

* TokenReg fix accounts (filter non accounts)

* Registry fix accounts (filter non accounts)
This commit is contained in:
Jaco Greeff 2016-11-12 22:24:55 +01:00 committed by Gav Wood
parent e5486f5d58
commit 6b33899239
5 changed files with 43 additions and 48 deletions

View File

@ -28,26 +28,26 @@ export function attachInterface () {
return Promise return Promise
.all([ .all([
registry.getAddress.call({}, [api.util.sha3('githubhint'), 'A']), registry.getAddress.call({}, [api.util.sha3('githubhint'), 'A']),
api.eth.accounts(),
api.parity.accounts() api.parity.accounts()
]); ]);
}) })
.then(([address, addresses, accountsInfo]) => { .then(([address, accountsInfo]) => {
accountsInfo = accountsInfo || {};
console.log(`githubhint was found at ${address}`); console.log(`githubhint was found at ${address}`);
const contract = api.newContract(abis.githubhint, address); const contract = api.newContract(abis.githubhint, address);
const accounts = addresses.reduce((obj, address) => { const accounts = Object
const info = accountsInfo[address] || {}; .keys(accountsInfo)
.filter((address) => accountsInfo[address].uuid)
.reduce((obj, address) => {
const account = accountsInfo[address];
return Object.assign(obj, { return Object.assign(obj, {
[address]: { [address]: {
address, address,
name: info.name, name: account.name
uuid: info.uuid }
} });
}); }, {});
}, {});
const fromAddress = Object.keys(accounts)[0]; const fromAddress = Object.keys(accounts)[0];
return { return {

View File

@ -19,18 +19,16 @@ import { api } from '../parity';
export const set = (addresses) => ({ type: 'addresses set', addresses }); export const set = (addresses) => ({ type: 'addresses set', addresses });
export const fetch = () => (dispatch) => { export const fetch = () => (dispatch) => {
return Promise return api.parity
.all([ .accounts()
api.eth.accounts(), .then((accountsInfo) => {
api.parity.accounts() const addresses = Object
]) .keys(accountsInfo)
.then(([ accounts, data ]) => { .filter((address) => accountsInfo[address] && !accountsInfo[address].meta.deleted)
data = data || {};
const addresses = Object.keys(data)
.filter((address) => data[address] && !data[address].meta.deleted)
.map((address) => ({ .map((address) => ({
...data[address], address, ...accountsInfo[address],
isAccount: accounts.includes(address) address,
isAccount: !!accountsInfo[address].uuid
})); }));
dispatch(set(addresses)); dispatch(set(addresses));
}) })

View File

@ -146,7 +146,7 @@ export default class Import extends Component {
} }
sortFunctions = (a, b) => { sortFunctions = (a, b) => {
return a.name.localeCompare(b.name); return (a.name || '').localeCompare(b.name || '');
} }
countFunctions () { countFunctions () {

View File

@ -49,26 +49,26 @@ export function attachInterface (callback) {
return Promise return Promise
.all([ .all([
registry.getAddress.call({}, [api.util.sha3('signaturereg'), 'A']), registry.getAddress.call({}, [api.util.sha3('signaturereg'), 'A']),
api.eth.accounts(),
api.parity.accounts() api.parity.accounts()
]); ]);
}) })
.then(([address, addresses, accountsInfo]) => { .then(([address, accountsInfo]) => {
accountsInfo = accountsInfo || {};
console.log(`signaturereg was found at ${address}`); console.log(`signaturereg was found at ${address}`);
const contract = api.newContract(abis.signaturereg, address); const contract = api.newContract(abis.signaturereg, address);
const accounts = addresses.reduce((obj, address) => { const accounts = Object
const info = accountsInfo[address] || {}; .keys(accountsInfo)
.filter((address) => accountsInfo[address].uuid)
.reduce((obj, address) => {
const info = accountsInfo[address] || {};
return Object.assign(obj, { return Object.assign(obj, {
[address]: { [address]: {
address, address,
name: info.name || 'Unnamed', name: info.name || 'Unnamed'
uuid: info.uuid }
} });
}); }, {});
}, {});
const fromAddress = Object.keys(accounts)[0]; const fromAddress = Object.keys(accounts)[0];
return { return {

View File

@ -35,16 +35,13 @@ export const setSelectedAccount = (address) => ({
}); });
export const loadAccounts = () => (dispatch) => { export const loadAccounts = () => (dispatch) => {
Promise api.parity
.all([ .accounts()
api.eth.accounts(), .then((accountsInfo) => {
api.parity.accounts() const accountsList = Object
]) .keys(accountsInfo)
.then(([ accounts, accountsInfo ]) => { .filter((address) => accountsInfo[address].uuid)
accountsInfo = accountsInfo || {}; .map((address) => ({
const accountsList = accounts
.map(address => ({
...accountsInfo[address], ...accountsInfo[address],
address address
})); }));