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

Refactoring of the Dapp Registry #4589

Merged
merged 45 commits into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3a7708b
Add React Hot Loader to DappReg dapp
ngotchac Feb 13, 2017
6936397
Updated colours
ngotchac Feb 13, 2017
cd9c6ff
Merge branch 'master' into ng-dappreg-enhancements
ngotchac Feb 16, 2017
4b5adc0
Add DappCards
ngotchac Feb 16, 2017
7b30b70
Dapp Modal with manifest displayed
ngotchac Feb 16, 2017
6e2fe5c
Add input to the Dapp Modal
ngotchac Feb 16, 2017
64a0c17
WIP // Editing a Dapp
ngotchac Feb 16, 2017
d52c8b8
Clean-Up
ngotchac Feb 17, 2017
b635dfd
Linting
ngotchac Feb 17, 2017
33a49c5
Merge branch 'master' into ng-dappreg-enhancements
ngotchac Feb 17, 2017
2d52ed5
CleanUp and separate dapp from dappS
ngotchac Feb 17, 2017
a4f5353
Semi-working updates
ngotchac Feb 17, 2017
47b8531
Working Editing of a Dapp
ngotchac Feb 17, 2017
05336d9
OCD
ngotchac Feb 17, 2017
4b92e75
Merge branch 'master' into ng-dappreg-enhancements
ngotchac Feb 28, 2017
ca776f8
Linting
ngotchac Feb 28, 2017
d58a9cd
Add a Dapp -- WIP
ngotchac Mar 1, 2017
1b36579
Merge branch 'master' into ng-dappreg-enhancements
ngotchac Mar 1, 2017
13f9dcb
Merge branch 'master' into ng-dappreg-enhancements
ngotchac Mar 7, 2017
e8eda38
Register a new Dapp
ngotchac Mar 7, 2017
e9855e6
Merge branch 'master' into ng-dappreg-enhancements
ngotchac Mar 8, 2017
abb9612
Merge branch 'master' into ng-dappreg-enhancements
ngotchac Mar 8, 2017
41f3033
WIP Dapps
ngotchac Mar 8, 2017
1729fb6
Working update / delete / register
ngotchac Mar 8, 2017
eb47d1e
Better promises
ngotchac Mar 8, 2017
d68b89d
Working updates for DappReg
ngotchac Mar 8, 2017
27c6a54
Merge branch 'master' into ng-dappreg-enhancements
ngotchac Mar 8, 2017
fff580d
Fully functional again !
ngotchac Mar 8, 2017
16f086f
Generic Card Component
ngotchac Mar 8, 2017
23a9b34
Dashed Register Card
ngotchac Mar 8, 2017
2c8a45d
Cleanups
ngotchac Mar 8, 2017
caf4e2c
Cleanups
ngotchac Mar 9, 2017
bc8d695
Add Actions to Modal
ngotchac Mar 9, 2017
dbf3e53
Clean-Up
ngotchac Mar 9, 2017
f86bc7f
Better Close Icon
ngotchac Mar 9, 2017
3705c71
Merge branch 'master' into ng-dappreg-enhancements
ngotchac Mar 9, 2017
94a7545
Single place for Registry version // Fetch meta-data from Registry
ngotchac Mar 9, 2017
fb6a2dc
Fixing test
ngotchac Mar 9, 2017
953740d
Fix saving changes in dapp reg
ngotchac Mar 9, 2017
b9caa71
Merge branch 'master' into ng-dappreg-enhancements
ngotchac Mar 10, 2017
cfee45d
Merge branch 'master' into ng-dappreg-enhancements
ngotchac Mar 10, 2017
659126d
PR Grumbles - Part I
ngotchac Mar 10, 2017
77075fc
PR Grumble - Part I
ngotchac Mar 10, 2017
9dcf34c
PR Grumble - Part II
ngotchac Mar 10, 2017
14a1ca4
DappReg Contract owner can delete dapps
ngotchac Mar 10, 2017
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
12 changes: 12 additions & 0 deletions js/assets/images/dapps/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions js/assets/images/dapps/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 51 additions & 4 deletions js/src/contracts/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@

import * as abis from './abi';

const REGISTRY_V1_HASHES = [
'0x34f7c51bbb1b1902fbdabfdf04811100f5c9f998f26dd535d2f6f977492c748e', // ropsten
'0x64c3ee34851517a9faecd995c102b339f03e564ad6772dc43a26f993238b20ec' // homestead
];

export default class Registry {
_registryContract = null;

constructor (api) {
this._api = api;

Expand All @@ -43,11 +50,10 @@ export default class Registry {

this._fetching = true;

return this._api.parity
.registryAddress()
.then((address) => {
return this.fetchContract()
.then((contract) => {
this._fetching = false;
this._instance = this._api.newContract(abis.registry, address).instance;
this._instance = contract.instance;

this._queue.forEach((queued) => {
queued.resolve(this._instance);
Expand Down Expand Up @@ -89,6 +95,47 @@ export default class Registry {
.then((contract) => contract.instance);
}

fetchContract () {
if (this._registryContract) {
return Promise.resolve(this._registryContract);
}

return this._api.parity
.registryAddress()
.then((address) => Promise.all([ address, this._api.eth.getCode(address) ]))
.then(([ address, code ]) => {
const codeHash = this._api.util.sha3(code);
const version = REGISTRY_V1_HASHES.includes(codeHash)
? 1
: 2;
const abi = version === 1
? abis.registry
: abis.registry2;
const contract = this._api.newContract(abi, address);

// Add support for previous `set` and `get` methods
if (!contract.instance.get && contract.instance.getData) {
contract.instance.get = contract.instance.getData;
}

if (contract.instance.get && !contract.instance.getData) {
contract.instance.getData = contract.instance.get;
}

if (!contract.instance.set && contract.instance.setData) {
contract.instance.set = contract.instance.setData;
}

if (contract.instance.set && !contract.instance.setData) {
contract.instance.setData = contract.instance.set;
}

console.log(`registry at ${address}, code ${codeHash}, version ${version}`);
this._registryContract = contract;
return this._registryContract;
});
}

_createGetParams (_name, key) {
const name = _name.toLowerCase();
const sha3 = this._api.util.sha3.text(name);
Expand Down
3 changes: 3 additions & 0 deletions js/src/contracts/registry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ function create () {
}
};
api = {
eth: {
getCode: sinon.stub().resolves('0x123456')
},
parity: {
registryAddress: sinon.stub().resolves('testRegistryAddress')
},
Expand Down
18 changes: 17 additions & 1 deletion js/src/dapps/dappreg.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import injectTapEventPlugin from 'react-tap-event-plugin';
import { AppContainer } from 'react-hot-loader';

injectTapEventPlugin();

Expand All @@ -27,6 +28,21 @@ import '../../assets/fonts/RobotoMono/font.css';
import './style.css';

ReactDOM.render(
<Application />,
<AppContainer>
<Application />
</AppContainer>,
document.querySelector('#container')
);

if (module.hot) {
module.hot.accept('./dappreg/Application/index.js', () => {
require('./dappreg/Application/index.js');

ReactDOM.render(
<AppContainer>
<Application />
</AppContainer>,
document.querySelector('#container')
);
});
}
17 changes: 9 additions & 8 deletions js/src/dapps/dappreg/Application/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/

@import '../_colors.css';

.body {
color: #333;
background: #eee;
padding: 4.5em 0;
color: $text-color;
background: $background-color;
padding: 3em 0 6em;
text-align: center;
}

.apps {
background: #fff;
background: white;
border-radius: 0.5em;
margin: 0 auto;
max-width: 980px;
Expand All @@ -39,9 +41,8 @@
}

.header {
background: #44e;
border-radius: 0 0 0.25em 0.25em;
color: #fff;
background: $blue;
color: white;
left: 0;
padding: 1em;
position: fixed;
Expand All @@ -54,5 +55,5 @@
text-align: center;
padding-top: 5em;
font-size: 2em;
color: #999;
color: $loading-color;
}
33 changes: 19 additions & 14 deletions js/src/dapps/dappreg/Application/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ import { observer } from 'mobx-react';

import DappsStore from '../dappsStore';

import ButtonBar from '../ButtonBar';
import Dapp from '../Dapp';
import ModalDelete from '../ModalDelete';
import ModalRegister from '../ModalRegister';
import ModalUpdate from '../ModalUpdate';
import SelectDapp from '../SelectDapp';
import Dapps from '../Dapps';
import Transactions from '../Transactions';
import Warning from '../Warning';
import styles from './application.css';

@observer
export default class Application extends Component {
dappsStore = DappsStore.instance();
dappsStore = DappsStore.get();

render () {
if (this.dappsStore.isLoading) {
Expand All @@ -41,23 +37,32 @@ export default class Application extends Component {
);
}

const { ownDapps, otherDapps } = this.dappsStore;

return (
<div className={ styles.body }>
<div className={ styles.header }>
DAPP REGISTRY, a global view of distributed applications available on the network. Putting the puzzle together.
</div>
<div className={ styles.apps }>
<SelectDapp />
<ButtonBar />
<Dapp />

<div>
<Dapps
dapps={ ownDapps }
own
title='My Dapps'
/>
<Dapps
dapps={ otherDapps }
title='Other Dapps'
/>
</div>

<div className={ styles.footer }>
{ this.dappsStore.count } applications registered, { this.dappsStore.ownedCount } owned by user
</div>

<Transactions />
<Warning />
<ModalDelete />
<ModalRegister />
<ModalUpdate />
</div>
);
}
Expand Down
17 changes: 13 additions & 4 deletions js/src/dapps/dappreg/Button/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/

@import '../_colors.css';
@import '../_utils.css';

.button {
background: #44e;
composes: bezier-transform;

background: $blue;
border: none;
border-radius: 0.25em;
color: #fff;
color: white;
cursor: pointer;
font-size: 1em;
margin: 1em 0.375em;
Expand All @@ -29,10 +34,14 @@
&[disabled] {
opacity: 0.5;
cursor: default;
background: #aaa;
background: $disabled-bg;
}

&[data-warning="true"] {
background: #e44;
background: $warning-bg;
}

&:focus {
transform: scale(1.05);
}
}
12 changes: 7 additions & 5 deletions js/src/dapps/dappreg/Button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,29 @@ export default class Button extends Component {
disabled: PropTypes.bool,
label: PropTypes.string.isRequired,
warning: PropTypes.bool,
onClick: PropTypes.func.isRequired
onClick: PropTypes.func
}

render () {
const { className, disabled, label, warning } = this.props;
const classes = `${styles.button} ${className}`;
const classes = [ styles.button, className ];

return (
<button
className={ classes }
className={ classes.join(' ') }
data-warning={ warning }
disabled={ disabled }
onClick={ this.onClick }
onClick={ this.handleClick }
>
{ label }
</button>
);
}

onClick = (event) => {
handleClick = (event) => {
if (this.props.disabled) {
event.preventDefault();
event.stopPropagation();
return;
}

Expand Down
Loading