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

Commit 6d0dfa6

Browse files
jacograrkpar
authored andcommitted
Backport #6710 & #6714 (#6715)
* [ci skip] js-precompiled 20171011-183908 * Fix estimate gas if from is not provided. (#6714) * Display vouched overlay on dapps (#6710) * Remove .only * Add vouch overlays to dapps * Cleanup address * Only run where we have a contentHash * GitLab kickstart
1 parent d30c715 commit 6d0dfa6

File tree

11 files changed

+204
-8
lines changed

11 files changed

+204
-8
lines changed

js/scripts/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// test script 10
1+
// test script 11

js/src/contracts/abi/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ export signaturereg from './signaturereg.json';
2929
export smsverification from './sms-verification.json';
3030
export tokenreg from './tokenreg.json';
3131
export foundationWallet from './foundation-multisig-wallet.json';
32+
export vouchfor from './vouchfor.json';

js/src/contracts/abi/vouchfor.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"constant":true,"inputs":[],"name":"certifier","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_what","type":"bytes32"}],"name":"vouch","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_what","type":"bytes32"},{"name":"_index","type":"uint256"}],"name":"vouched","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_what","type":"bytes32"},{"name":"_index","type":"uint256"}],"name":"unvouch","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"},{"name":"","type":"uint256"}],"name":"vouchers","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_certifier","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"who","type":"address"},{"indexed":false,"name":"what","type":"bytes32"}],"name":"Vouched","type":"event"}]

js/src/ui/DappCard/dappCard.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import React, { Component, PropTypes } from 'react';
1919
import Container, { Title as ContainerTitle } from '~/ui/Container';
2020
import DappIcon from '~/ui/DappIcon';
2121
import Tags from '~/ui/Tags';
22+
import DappVouchFor from '../DappVouchFor';
2223

2324
import styles from './dappCard.css';
2425

@@ -61,6 +62,7 @@ export default class DappCard extends Component {
6162
app={ app }
6263
className={ styles.image }
6364
/>
65+
<DappVouchFor app={ app } />
6466
<Tags
6567
className={ styles.tags }
6668
tags={
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* Copyright 2015-2017 Parity Technologies (UK) Ltd.
2+
/* This file is part of Parity.
3+
/*
4+
/* Parity is free software: you can redistribute it and/or modify
5+
/* it under the terms of the GNU General Public License as published by
6+
/* the Free Software Foundation, either version 3 of the License, or
7+
/* (at your option) any later version.
8+
/*
9+
/* Parity is distributed in the hope that it will be useful,
10+
/* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
/* GNU General Public License for more details.
13+
/*
14+
/* You should have received a copy of the GNU General Public License
15+
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
.tag {
19+
color: inherit;
20+
position: absolute;
21+
top: 1em;
22+
right: 1em;
23+
24+
.image {
25+
position: absolute;
26+
right: 0;
27+
top: 0;
28+
width: 32px;
29+
height: 32px;
30+
}
31+
32+
.bubble {
33+
background: red;
34+
border-radius: 0.25em;
35+
color: white;
36+
font-size: 0.75em;
37+
padding: 0.1em 0.5em;
38+
position: absolute;
39+
right: 0;
40+
top: 0;
41+
z-index: 100;
42+
}
43+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
2+
// This file is part of Parity.
3+
4+
// Parity is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Parity is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import React, { Component, PropTypes } from 'react';
18+
import { observer } from 'mobx-react';
19+
20+
import IdentityIcon from '../IdentityIcon';
21+
22+
import Store from './store';
23+
import styles from './dappVouchFor.css';
24+
25+
@observer
26+
export default class DappVouchFor extends Component {
27+
static contextTypes = {
28+
api: PropTypes.object.isRequired
29+
};
30+
31+
static propTypes = {
32+
app: PropTypes.object.isRequired
33+
};
34+
35+
store = new Store(this.context.api, this.props.app);
36+
37+
render () {
38+
const count = this.store.vouchers.length;
39+
40+
if (!count) {
41+
return null;
42+
}
43+
44+
return (
45+
<div className={ styles.tag }>
46+
<IdentityIcon
47+
address={ this.store.vouchers[0] }
48+
className={ styles.image }
49+
alt={ `${count} identities vouch for this dapp` }
50+
/>
51+
<div className={ styles.bubble }>
52+
{ count }
53+
</div>
54+
</div>
55+
);
56+
}
57+
}

js/src/ui/DappVouchFor/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
2+
// This file is part of Parity.
3+
4+
// Parity is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Parity is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
16+
17+
export default from './dappVouchFor';

js/src/ui/DappVouchFor/store.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
2+
// This file is part of Parity.
3+
4+
// Parity is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Parity is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import { action, observable } from 'mobx';
18+
import { uniq } from 'lodash';
19+
20+
import Contracts from '~/contracts';
21+
import { vouchfor as vouchForAbi } from '~/contracts/abi';
22+
23+
export default class Store {
24+
@observable vouchers = [];
25+
26+
constructor (api, app) {
27+
this._api = api;
28+
29+
const { contentHash } = app;
30+
31+
if (contentHash) {
32+
this.lookupVouchers(contentHash);
33+
}
34+
}
35+
36+
lookupVouchers (contentHash) {
37+
Contracts
38+
.get().registry
39+
.lookupAddress('vouchfor')
40+
.then((address) => {
41+
if (!address || /^0x0*$/.test(address)) {
42+
return;
43+
}
44+
45+
return this._api.newContract(vouchForAbi, address);
46+
})
47+
.then(async (contract) => {
48+
if (!contract) {
49+
return;
50+
}
51+
52+
let lastItem = false;
53+
54+
for (let index = 0; !lastItem; index++) {
55+
const voucher = await contract.instance.vouched.call({}, [`0x${contentHash}`, index]);
56+
57+
if (/^0x0*$/.test(voucher)) {
58+
lastItem = true;
59+
} else {
60+
this.addVoucher(voucher);
61+
}
62+
}
63+
})
64+
.catch((error) => {
65+
console.error('vouchFor', error);
66+
67+
return;
68+
});
69+
}
70+
71+
@action addVoucher = (voucher) => {
72+
this.vouchers = uniq([].concat(this.vouchers.peek(), [voucher]));
73+
}
74+
}

js/src/ui/IdentityIcon/identityIcon.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class IdentityIcon extends Component {
3030

3131
static propTypes = {
3232
address: PropTypes.string,
33+
alt: PropTypes.string,
3334
button: PropTypes.bool,
3435
center: PropTypes.bool,
3536
className: PropTypes.string,
@@ -84,7 +85,7 @@ class IdentityIcon extends Component {
8485
}
8586

8687
render () {
87-
const { address, button, className, center, disabled, inline, padded, tiny } = this.props;
88+
const { address, alt, button, className, center, disabled, inline, padded, tiny } = this.props;
8889
const { iconsrc } = this.state;
8990
const classes = [
9091
styles.icon,
@@ -135,6 +136,7 @@ class IdentityIcon extends Component {
135136

136137
return (
137138
<img
139+
alt={ alt || address }
138140
className={ classes }
139141
data-address-img
140142
height={ size }

js/src/util/tx.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ export function getTxOptions (api, func, _options, values = []) {
8181
options.to = options.to || func.contract.address;
8282
}
8383

84-
if (!address) {
85-
return Promise.resolve({ func, options, values });
86-
}
84+
const promise = (!address)
85+
? Promise.resolve(false)
86+
: WalletsUtils.isWallet(api, address);
8787

88-
return WalletsUtils
89-
.isWallet(api, address)
88+
return promise
9089
.then((isWallet) => {
9190
if (!isWallet) {
9291
return { func, options, values };

js/src/views/Signer/components/SignRequest/signRequest.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('views/Signer/components/SignRequest', () => {
9999
expect(isMarkdown(encodedMd)).to.be.true;
100100
});
101101

102-
it('returns false for randow data', () => {
102+
it('returns false for random data', () => {
103103
expect(isMarkdown('0x1234')).to.be.false;
104104
});
105105
});

0 commit comments

Comments
 (0)