Skip to content

Commit

Permalink
update embark & fix primitive ui
Browse files Browse the repository at this point in the history
  • Loading branch information
3esmit committed Nov 9, 2020
1 parent 648ff9f commit 9451a8d
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 31 deletions.
12 changes: 7 additions & 5 deletions app/TopicDemocracy.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import EmbarkJS from 'Embark/EmbarkJS';
import Delegation from 'Embark/contracts/Delegation';
import EmbarkJS from '../embarkArtifacts/embarkjs';
import Delegation from '../embarkArtifacts/contracts/Delegation';
import { HashRouter, Route, Redirect, Link } from "react-router-dom";

import './TopicDemocracy.css';
Expand Down Expand Up @@ -34,7 +34,8 @@ class TopicDemocracy extends React.Component {

this.state = {
error: null,
defaultAccount: null
defaultAccount: null,
deployedAddress: null
};
}

Expand All @@ -43,14 +44,15 @@ class TopicDemocracy extends React.Component {
if (err) {
return this.setState({ error: err.message || err });
}
console.log(web3.eth.defaultAccount)
this.setState({ defaultAccount: web3.eth.defaultAccount, blockchainEnabled: true })
});

}

render() {
const { classes } = this.props;
const { blockchainEnabled, defaultAccount } = this.state;
const { blockchainEnabled, defaultAccount, deployedAddress } = this.state;
if (!blockchainEnabled) {
return (
<div>Waiting for blockchain.</div>
Expand All @@ -74,7 +76,7 @@ class TopicDemocracy extends React.Component {
</AppBar>
<main className={classes.layout}>
<Route exact path="/" render={({ match }) => (
<DelegationFactoryUI account={defaultAccount} />
<DelegationFactoryUI account={defaultAccount} onDeploy={(deployedAddress) => {this.setState({deployedAddress})} } />
)} />
<Route path="/:address" render={({ match }) => (
<DelegationUI account={defaultAccount} Delegation={new EmbarkJS.Blockchain.Contract({ abi: Delegation._jsonInterface, address: match.params.address }) } />
Expand Down
2 changes: 1 addition & 1 deletion app/actions/accounts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ERC20Token from 'Embark/contracts/ERC20Token';
import ERC20Token from '../../embarkArtifacts/contracts/ERC20Token';
import { actions as accountActions } from '../reducers/accounts'

const { receiveAccounts } = accountActions
Expand Down
21 changes: 13 additions & 8 deletions app/components/DelegationFactoryUI.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Redirect } from "react-router-dom";
import { withStyles } from '@material-ui/core/styles';
import DelegationFactory from 'Embark/contracts/DelegationFactory';
import DelegationFactory from '../../embarkArtifacts/contracts/DelegationFactory';
import EthAddress from './EthAddress';
import { FormLabel, Paper, Grid } from '@material-ui/core';
import TransactionSendButton from './TransactionSendButton';
Expand Down Expand Up @@ -30,30 +31,34 @@ class DelegationFactoryUI extends React.Component {
constructor(props) {
super(props);
this.state = {
parent: null,
controller: props.account,
defaultDelegate: null
parent: "0x0000000000000000000000000000000000000000",
defaultDelegate: "0x0000000000000000000000000000000000000000",
deployedAddress: null
};
}

render() {
const { classes, account } = this.props;
const { parent, controller, defaultDelegate } = this.state;
const { parent, controller, defaultDelegate, deployedAddress} = this.state;
if(deployedAddress) {
return (<Redirect to={'/'+deployedAddress} />)
}
console.log(parent, controller, defaultDelegate);
return (
<Paper className={classes.paper}>
<Grid container spacing={16}>
<Grid item>
<FormLabel component="legend">Controller</FormLabel>
<EthAddress defaultValue={account} control={true} onChange={(controller) => this.setState({controller})} />
<EthAddress allowZero={true} defaultValue={account} value={controller} control={true} onChange={(e) => this.setState({controller: e.target.value })} />
</Grid>
<Grid item>
<FormLabel component="legend">Default Delegate</FormLabel>
<EthAddress control={true} onChange={(defaultDelegate) => this.setState({defaultDelegate})} />
<EthAddress allowZero={true} control={true} value={defaultDelegate} onChange={(e) => this.setState({defaultDelegate: e.target.value })} />
</Grid>
<Grid item>
<FormLabel component="legend">Parent Delegation</FormLabel>
<EthAddress control={true} onChange={(parent) => this.setState({parent})} />
<EthAddress allowZero={true} control={true} value={parent} onChange={(e) => this.setState({parent: e.target.value })} />
</Grid>
<Grid item>
<TransactionSendButton
Expand All @@ -67,7 +72,7 @@ class DelegationFactoryUI extends React.Component {
account={account}
text="Deploy Delegation"
onSend={(txHash) => {console.log("txHash",txHash)}}
onResult={(result) => {console.log("result",result.events)}}
onResult={(result) => {this.setState({deployedAddress: result.events.InstanceCreated.returnValues.instance})}}
onReceipt={(receipt) => {console.log("receipt",receipt)}}
onError={(error) => {console.log("error",error)}}
/>
Expand Down
11 changes: 6 additions & 5 deletions app/components/DelegationUI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DelegationUI extends React.Component {

editDelegationOf(delegate) {
const editDelegation = this.state.editDelegation;
if(!delegateChain.includes(delegate)){
if(!editDelegation.includes(delegate)){
editDelegation.push(delegate);
this.setState({editDelegation});
this.props.Delegation.methods.delegatedTo(delegate).call().then((delegatedTo) => {
Expand All @@ -77,7 +77,7 @@ class DelegationUI extends React.Component {
<div className={className} >
<div>
<p>Delegation:</p>
<EthAddress value={Delegation.options.address} />
<EthAddress value={Delegation.address} />
</div>
<div>
<small>Delegate Chain:</small>
Expand All @@ -91,7 +91,8 @@ class DelegationUI extends React.Component {
</div>
<div>
<p>Delegate Set</p>
<EthAddress defaultValue={editDelegate} control={true} onChange={(editDelegate) => {
<EthAddress defaultValue={editDelegate} control={true} onChange={(e) => {
let editDelegate = e.target.value;
this.setState({editDelegate});
if(editDelegate != delegateChain[0]) {
this.setState({editDelegation : []});
Expand All @@ -102,8 +103,8 @@ class DelegationUI extends React.Component {
{editDelegation.length > 0 &&
<Breadcrumbs arial-label="Breadcrumb" maxItems={5}>
{
editDelegation.map((value) => {
return <EthAddress value={value} />
editDelegation.map((value, i) => {
return <EthAddress key={i} value={value} />
})
}
</Breadcrumbs>
Expand Down
4 changes: 4 additions & 0 deletions app/components/EthAddress.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import EmbarkJS from '../../embarkArtifacts/embarkjs';
import React from 'react';
import PropTypes from 'prop-types';
import Blockies from 'react-blockies';
Expand Down Expand Up @@ -86,6 +87,9 @@ class EthAddress extends React.Component {


setValue(value){
if(!value) {
value = ""
}
value = value.trim();
const validAddress = /^(0x)?[0-9a-f]{40}$/i.test(value);
const acceptedOutput = validAddress && (this.props.allowZero || value != nullAddress);
Expand Down
4 changes: 2 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<html>
<head>
<title>Status Network - Test Demo</title>
<title>µTopic Democracy</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<div id="app">
</div>
<script src="js/dapp.js"></script>
<script src="js/dapp.js" charset="UTF-8"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions app/models/DelegationModel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EmbarkJS from './embarkArtifacts/EmbarkJS';
import Delegation from './embarkArtifacts/contracts/Delegation';
import DelegationFactory from './embarkArtifacts/contracts/DelegationFactory';
import EmbarkJS from '../../embarkArtifacts/embarkjs';
import Delegation from '../../embarkArtifacts/contracts/Delegation';
import DelegationFactory from '../../embarkArtifacts/contracts/DelegationFactory';

class DelegationModel {

Expand Down
2 changes: 0 additions & 2 deletions app/store/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import web3 from "Embark/web3"
import EmbarkJS from 'Embark/EmbarkJS'
import store from './configureStore'
import { fetchAndDispatchAccountsWithBalances } from '../actions/accounts'

Expand Down
2 changes: 1 addition & 1 deletion config/communication.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
default: {
enabled: true,
enabled: false,
provider: "whisper",
available_providers: ["whisper"],
},
Expand Down
9 changes: 8 additions & 1 deletion config/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ module.exports = {

}
},

development:{
dappConnection: [
"$EMBARK",
"$WEB3",
"ws://localhost:8546",
"http://localhost:8545"
]
},
testnet: {
contracts: {
MiniMeTokenFactory: {
Expand Down
3 changes: 1 addition & 2 deletions config/storage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
default: {
enabled: true,
enabled: false,
ipfs_bin: "ipfs",
available_providers: ["ipfs"],
upload: {
Expand All @@ -18,7 +18,6 @@ module.exports = {
]
},
development: {
enabled: true,
upload: {
provider: "ipfs",
host: "localhost",
Expand Down
2 changes: 1 addition & 1 deletion contracts/democracy/Democracy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "./delegation/DelegationFactory.sol";
import "./proposal/ProposalFactory.sol";

/**
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
*/
contract Democracy {

Expand Down

0 comments on commit 9451a8d

Please sign in to comment.