diff --git a/packages/concordia-app/package.json b/packages/concordia-app/package.json
index 65c1b25..0e039b8 100644
--- a/packages/concordia-app/package.json
+++ b/packages/concordia-app/package.json
@@ -9,7 +9,7 @@
"eject": "react-scripts eject",
"postinstall": "patch-package",
"analyze": "source-map-explorer 'build/static/js/*.js'",
- "lint": "yarn run eslint . --format table"
+ "lint": "yarn run eslint --ext js,jsx . --format table"
},
"browserslist": {
"production": [
diff --git a/packages/concordia-app/src/components/App.jsx b/packages/concordia-app/src/components/App.jsx
index 4086e07..88704c8 100644
--- a/packages/concordia-app/src/components/App.jsx
+++ b/packages/concordia-app/src/components/App.jsx
@@ -1,34 +1,33 @@
-import React from 'react'
-import { Provider } from 'react-redux'
-import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
-import LoadingContainer from './LoadingContainer'
-import PropTypes from 'prop-types'
+import React from 'react';
+import { Provider } from 'react-redux';
+import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
+import PropTypes from 'prop-types';
+import LoadingContainer from './LoadingContainer';
// CSS
import '../assets/css/app.css';
import CoreLayoutContainer from './CoreLayoutContainer';
import HomeContainer from './HomeContainer';
-import NotFound from '../components/NotFound';
-
+import NotFound from './NotFound';
const App = ({ store }) => (
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-)
+);
App.propTypes = {
- store: PropTypes.object.isRequired
-}
+ store: PropTypes.object.isRequired,
+};
-export default App
+export default App;
diff --git a/packages/concordia-app/src/components/AppContext.js b/packages/concordia-app/src/components/AppContext.js
deleted file mode 100644
index 5534716..0000000
--- a/packages/concordia-app/src/components/AppContext.js
+++ /dev/null
@@ -1,72 +0,0 @@
-// Modified version of https://github.com/trufflesuite/drizzle/blob/develop/packages/react-plugin/src/DrizzleContext.js
-import React from "react";
-
-const Context = React.createContext();
-
-class Provider extends React.Component {
- state = {
- drizzleState: null,
- drizzleInitialized: false,
- breezeState: null,
- breezeInitialized: false
- };
-
- componentDidMount() {
- const { drizzle, breeze } = this.props;
- // subscribe to changes in the store, keep state up-to-date
- this.unsubscribe = drizzle.store.subscribe(() => {
- const drizzleState = drizzle.store.getState();
- const breezeState = breeze.store.getState();
-
- if (drizzleState.drizzleStatus.initialized) {
- this.setState({
- drizzleState,
- drizzleInitialized: true
- });
- }
- if (breezeState.breezeStatus.initialized) {
- this.setState({
- breezeState: breezeState,
- breezeInitialized: true
- });
- }
- });
-
- this.unsubscribe = breeze.store.subscribe(() => {
- const breezeState = breeze.store.getState();
- if (breezeState.breezeStatus.initialized) {
- this.setState({
- breezeState: breezeState,
- breezeInitialized: true
- });
- }
- });
- }
-
- componentWillUnmount() {
- this.unsubscribe();
- }
-
- render() {
- return (
-
- {this.props.children}
-
- );
- }
-}
-
-export default {
- Context: Context,
- Consumer: Context.Consumer,
- Provider
-};
diff --git a/packages/concordia-app/src/components/AppContext.jsx b/packages/concordia-app/src/components/AppContext.jsx
new file mode 100644
index 0000000..6b8b739
--- /dev/null
+++ b/packages/concordia-app/src/components/AppContext.jsx
@@ -0,0 +1,81 @@
+// Modified version of https://github.com/trufflesuite/drizzle/blob/develop/packages/react-plugin/src/DrizzleContext.js
+import React from 'react';
+
+const Context = React.createContext();
+
+class Provider extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ drizzleState: null,
+ drizzleInitialized: false,
+ breezeState: null,
+ breezeInitialized: false,
+ };
+ }
+
+ componentDidMount() {
+ const { drizzle, breeze } = this.props;
+ // subscribe to changes in the store, keep state up-to-date
+ this.unsubscribe = drizzle.store.subscribe(() => {
+ const drizzleState = drizzle.store.getState();
+ const breezeState = breeze.store.getState();
+
+ if (drizzleState.drizzleStatus.initialized) {
+ this.setState({
+ drizzleState,
+ drizzleInitialized: true,
+ });
+ }
+ if (breezeState.breezeStatus.initialized) {
+ this.setState({
+ breezeState,
+ breezeInitialized: true,
+ });
+ }
+ });
+
+ this.unsubscribe = breeze.store.subscribe(() => {
+ const breezeState = breeze.store.getState();
+ if (breezeState.breezeStatus.initialized) {
+ this.setState({
+ breezeState,
+ breezeInitialized: true,
+ });
+ }
+ });
+ }
+
+ componentWillUnmount() {
+ this.unsubscribe();
+ }
+
+ render() {
+ const {
+ drizzleState, drizzleInitialized, breezeState, breezeInitialized,
+ } = this.state;
+ const { drizzle, breeze, children } = this.props;
+
+ return (
+
+ {children}
+
+ );
+ }
+}
+
+export default {
+ Context,
+ Consumer: Context.Consumer,
+ Provider,
+};
diff --git a/packages/concordia-app/src/components/CoreLayoutContainer.jsx b/packages/concordia-app/src/components/CoreLayoutContainer.jsx
index 4a72130..5da971e 100644
--- a/packages/concordia-app/src/components/CoreLayoutContainer.jsx
+++ b/packages/concordia-app/src/components/CoreLayoutContainer.jsx
@@ -1,19 +1,21 @@
-import React, { Component } from 'react';
+import React from 'react';
import PropTypes from 'prop-types';
import MenuComponent from './MenuComponent';
-export default class CoreLayout extends Component {
- render() {
- return (
-
diff --git a/packages/concordia-app/src/components/SignUpForm.jsx b/packages/concordia-app/src/components/SignUpForm.jsx
index fad79bc..3c9fed3 100644
--- a/packages/concordia-app/src/components/SignUpForm.jsx
+++ b/packages/concordia-app/src/components/SignUpForm.jsx
@@ -1,139 +1,144 @@
import React, { Component } from 'react';
-import { Button, Form, Menu, Message, Modal } from 'semantic-ui-react';
+import {
+ Button, Form, Menu, Message, Modal,
+} from 'semantic-ui-react';
-import AppContext from "./AppContext";
import { connect } from 'react-redux';
+import AppContext from './AppContext';
const contractName = 'Forum';
const checkUsernameTakenMethod = 'isUserNameTaken';
const signUpMethod = 'signUp';
class SignUpForm extends Component {
- constructor(props, context) {
- super(props, context);
-
- // For quick access
- this.contract = this.context.drizzle.contracts[contractName];
-
- this.handleInputChange = this.handleInputChange.bind(this);
- this.handleSubmit = this.handleSubmit.bind(this);
- this.completeAction = this.completeAction.bind(this);
-
- this.checkedUsernames = [];
-
- this.state = {
- usernameInput: '',
- error: false,
- errorHeader: '',
- errorMessage: '',
- signingUp: false,
- };
+ constructor(props, context) {
+ super(props, context);
+
+ // For quick access
+ this.contract = this.context.drizzle.contracts[contractName];
+
+ this.handleInputChange = this.handleInputChange.bind(this);
+ this.handleSubmit = this.handleSubmit.bind(this);
+ this.completeAction = this.completeAction.bind(this);
+
+ this.checkedUsernames = [];
+
+ this.state = {
+ usernameInput: '',
+ error: false,
+ errorHeader: '',
+ errorMessage: '',
+ signingUp: false,
+ };
+ }
+
+ componentDidUpdate() {
+ // TODO
+ }
+
+ handleSubmit() {
+ const { usernameInput, error } = this.state;
+
+ if (usernameInput === '') {
+ this.setState({
+ error: true,
+ errorHeader: 'Data Incomplete',
+ errorMessage: 'You need to provide a username',
+ });
+ } else if (!error) {
+ // TODO
+ // // Makes sure current input username has been checked for availability
+ // if (this.checkedUsernames.some((e) => e.usernameChecked === usernameInput)) {
+ // this.completeAction();
+ // }
+ this.completeAction();
}
-
- handleInputChange(e, { name, value }) {
- this.setState({
- [name]: value,
- error: false,
- });
- if (value !== '') {
- if (this.checkedUsernames.length > 0) {
- if (this.checkedUsernames.some((e) => e.usernameChecked === value)) {
- return;
- }
- }
-
- this.contract.methods[checkUsernameTakenMethod].cacheCall(
- value,
- );
- }
- }
-
- handleSubmit() {
- const { usernameInput, error } = this.state;
-
- if (usernameInput === '') {
- this.setState({
- error: true,
- errorHeader: 'Data Incomplete',
- errorMessage: 'You need to provide a username',
- });
- } else if (!error) {
- // TODO
- // // Makes sure current input username has been checked for availability
- // if (this.checkedUsernames.some((e) => e.usernameChecked === usernameInput)) {
- // this.completeAction();
- // }
- this.completeAction();
+ }
+
+ handleInputChange(e, { name, value }) {
+ this.setState({
+ [name]: value,
+ error: false,
+ });
+ if (value !== '') {
+ if (this.checkedUsernames.length > 0) {
+ if (this.checkedUsernames.some((e) => e.usernameChecked === value)) {
+ return;
}
- }
+ }
- componentDidUpdate() {
- // TODO
+ this.contract.methods[checkUsernameTakenMethod].cacheCall(
+ value,
+ );
}
-
- completeAction() {
- const { usernameInput } = this.state;
- const { user, account } = this.props;
-
- if (user.hasSignedUp) {
- console.log('Signing up..')
- this.contract.methods['signUp'].cacheSend(usernameInput);
- } else {
- this.setState({
- signingUp: true,
- });
- this.contract.methods[signUpMethod].cacheSend(
- ...[usernameInput], { from: account },
- );
- }
- this.setState({
- usernameInput: '',
- });
+ }
+
+ completeAction() {
+ const { usernameInput } = this.state;
+ const { user, account } = this.props;
+
+ if (user.hasSignedUp) {
+ console.log('Signing up..');
+ this.contract.methods.signUp.cacheSend(usernameInput);
+ } else {
+ this.setState({
+ signingUp: true,
+ });
+ this.contract.methods[signUpMethod].cacheSend(
+ ...[usernameInput], { from: account },
+ );
}
-
- render() {
- const {
- error, usernameInput, errorHeader, errorMessage, signingUp,
- } = this.state;
-
- return(
-
this.handleSubmit(e)} trigger={
-
- }>
- Sign Up
-
-
-
-
-
-
- this.handleSubmit(e)}
+ trigger={(
+
+ )}
+ >
+ Sign Up
+
+
+
+
+
-
-
-
-
- )
+
+
+
- }
+
+
+ );
+ }
}
SignUpForm.contextType = AppContext.Context;
const mapStateToProps = (state) => ({
- user: state.user
+ user: state.user,
});
export default connect(mapStateToProps)(SignUpForm);
diff --git a/packages/concordia-app/src/index.js b/packages/concordia-app/src/index.jsx
similarity index 58%
rename from packages/concordia-app/src/index.js
rename to packages/concordia-app/src/index.jsx
index 13071e2..774b9bf 100644
--- a/packages/concordia-app/src/index.js
+++ b/packages/concordia-app/src/index.jsx
@@ -1,11 +1,11 @@
import React from 'react';
import { render } from 'react-dom';
-import App from './components/App'
+import { Drizzle } from '@ezerous/drizzle';
+import { Breeze } from '@ezerous/breeze';
+import App from './components/App';
import store from './redux/store';
-import { Drizzle } from '@ezerous/drizzle'
-import { Breeze } from '@ezerous/breeze'
-import AppContext from "./components/AppContext";
+import AppContext from './components/AppContext';
import drizzleOptions from './options/drizzleOptions';
import * as serviceWorker from './utils/serviceWorker';
@@ -17,13 +17,10 @@ const drizzle = new Drizzle(drizzleOptions, store);
const breeze = new Breeze(breezeOptions, store);
render(
-
-
- ,
- document.getElementById('root')
+
+
+ ,
+ document.getElementById('root'),
);
serviceWorker.unregister(); // See also: http://bit.ly/CRA-PWA
-
-
-
diff --git a/packages/concordia-app/src/options/breezeOptions.js b/packages/concordia-app/src/options/breezeOptions.js
index 45d2431..ca8ab7b 100644
--- a/packages/concordia-app/src/options/breezeOptions.js
+++ b/packages/concordia-app/src/options/breezeOptions.js
@@ -1,45 +1,45 @@
+import { orbitConstants } from '@ezerous/breeze';
import web3Options from './web3Options';
import EthereumIdentityProvider from '../orbit/ΕthereumIdentityProvider';
-import { orbitConstants } from '@ezerous/breeze'
const { web3 } = web3Options;
EthereumIdentityProvider.setWeb3(web3);
const breezeOptions = {
- ipfs: {
- config: {
- Addresses: {
- Swarm: [
- // Use local signaling server (see also rendezvous script in package.json)
- // For more information: https://github.com/libp2p/js-libp2p-webrtc-star
- '/ip4/127.0.0.1/tcp/9090/wss/p2p-webrtc-star'
+ ipfs: {
+ config: {
+ Addresses: {
+ Swarm: [
+ // Use local signaling server (see also rendezvous script in package.json)
+ // For more information: https://github.com/libp2p/js-libp2p-webrtc-star
+ '/ip4/127.0.0.1/tcp/9090/wss/p2p-webrtc-star',
- // Use the following public servers if needed
- // '/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
- // '/dns4/ wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star'
- ]
- },
- },
- preload: {
- enabled: false
- },
- init: {
- emptyRepo: true
- }
+ // Use the following public servers if needed
+ // '/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
+ // '/dns4/ wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star'
+ ],
+ },
},
- orbit: {
- identityProvider: EthereumIdentityProvider,
- databases: [
- {
- name: 'topics',
- type: orbitConstants.ORBIT_TYPE_KEYVALUE
- },
- {
- name: 'posts',
- type: orbitConstants.ORBIT_TYPE_KEYVALUE
- }
- ]
- }
+ preload: {
+ enabled: false,
+ },
+ init: {
+ emptyRepo: true,
+ },
+ },
+ orbit: {
+ identityProvider: EthereumIdentityProvider,
+ databases: [
+ {
+ name: 'topics',
+ type: orbitConstants.ORBIT_TYPE_KEYVALUE,
+ },
+ {
+ name: 'posts',
+ type: orbitConstants.ORBIT_TYPE_KEYVALUE,
+ },
+ ],
+ },
};
export default breezeOptions;
diff --git a/packages/concordia-app/src/options/drizzleOptions.js b/packages/concordia-app/src/options/drizzleOptions.js
index 1e12286..aa563f7 100644
--- a/packages/concordia-app/src/options/drizzleOptions.js
+++ b/packages/concordia-app/src/options/drizzleOptions.js
@@ -3,15 +3,15 @@ import { contracts } from 'concordia-contracts';
import web3Options from './web3Options';
const drizzleOptions = {
- web3: {
- customProvider: web3Options.web3
- },
- contracts,
- events: {
- Forum: ['UserSignedUp', 'UsernameUpdated', 'TopicCreated', 'PostCreated']
- },
- reloadWindowOnNetworkChange: true,
- reloadWindowOnAccountChange: true // We need it to reinitialize breeze and create new Orbit databases
+ web3: {
+ customProvider: web3Options.web3,
+ },
+ contracts,
+ events: {
+ Forum: ['UserSignedUp', 'UsernameUpdated', 'TopicCreated', 'PostCreated'],
+ },
+ reloadWindowOnNetworkChange: true,
+ reloadWindowOnAccountChange: true, // We need it to reinitialize breeze and create new Orbit databases
};
export default drizzleOptions;
diff --git a/packages/concordia-app/src/options/web3Options.js b/packages/concordia-app/src/options/web3Options.js
index 581e31d..13dc9b9 100644
--- a/packages/concordia-app/src/options/web3Options.js
+++ b/packages/concordia-app/src/options/web3Options.js
@@ -8,7 +8,7 @@ const web3 = new Web3(Web3.givenProvider || `ws://${WEB3_URL}:${WEB3_PORT}`);
EthereumIdentityProvider.setWeb3(web3);
const web3Options = {
- web3
+ web3,
};
export default web3Options;
diff --git a/packages/concordia-app/src/orbit/levelUtils.js b/packages/concordia-app/src/orbit/levelUtils.js
index 802a2a5..1a3fd09 100644
--- a/packages/concordia-app/src/orbit/levelUtils.js
+++ b/packages/concordia-app/src/orbit/levelUtils.js
@@ -6,18 +6,18 @@ the app */
const concordiaDB = level('./concordia/identities');
async function storeIdentitySignaturePubKey(key, signaturePubKey) {
- await concordiaDB.put(key, signaturePubKey);
+ await concordiaDB.put(key, signaturePubKey);
}
// If it exists, it returns the identity.signatures.publicKey for the given key (key is the
// concatenation of identity.publicKey + identity.signatures.id
async function getIdentitySignaturePubKey(key) {
- try {
- return await concordiaDB.get(key);
- } catch (err) {
- if (err && err.notFound) return null; // Not found
- throw err;
- }
+ try {
+ return await concordiaDB.get(key);
+ } catch (err) {
+ if (err && err.notFound) return null; // Not found
+ throw err;
+ }
}
export { storeIdentitySignaturePubKey, getIdentitySignaturePubKey };
diff --git a/packages/concordia-app/src/orbit/orbitUtils.js b/packages/concordia-app/src/orbit/orbitUtils.js
index 20da73b..6835fd5 100644
--- a/packages/concordia-app/src/orbit/orbitUtils.js
+++ b/packages/concordia-app/src/orbit/orbitUtils.js
@@ -1,7 +1,11 @@
// https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md#address
-export async function determineDBAddress({orbit, dbName, type, identityId}) {
- const ipfsMultihash = (await orbit.determineAddress(dbName, type, {
- accessController: { write: [identityId] },
- })).root;
- return `/orbitdb/${ipfsMultihash}/${dbName}`;
+async function determineDBAddress({
+ orbit, dbName, type, identityId,
+}) {
+ const ipfsMultihash = (await orbit.determineAddress(dbName, type, {
+ accessController: { write: [identityId] },
+ })).root;
+ return `/orbitdb/${ipfsMultihash}/${dbName}`;
}
+
+export default determineDBAddress;
diff --git a/packages/concordia-app/src/orbit/ΕthereumIdentityProvider.js b/packages/concordia-app/src/orbit/ΕthereumIdentityProvider.js
index 391e152..9c7deab 100644
--- a/packages/concordia-app/src/orbit/ΕthereumIdentityProvider.js
+++ b/packages/concordia-app/src/orbit/ΕthereumIdentityProvider.js
@@ -1,106 +1,108 @@
+/* eslint-disable no-console */
+/* eslint-disable no-return-await */
+import IdentityProvider from 'orbit-db-identity-provider';
import { getIdentitySignaturePubKey, storeIdentitySignaturePubKey } from './levelUtils';
-import IdentityProvider from "orbit-db-identity-provider";
const LOGGING_PREFIX = 'EthereumIdentityProvider: ';
-class EthereumIdentityProvider extends IdentityProvider{
- constructor(options = {}) {
- if(!EthereumIdentityProvider.web3)
- throw new Error(LOGGING_PREFIX + "Couldn't create identity, because web3 wasn't set. " +
- "Please use setWeb3(web3) first!");
+class EthereumIdentityProvider extends IdentityProvider {
+ constructor(options = {}) {
+ if (!EthereumIdentityProvider.web3) {
+ throw new Error(`${LOGGING_PREFIX}Couldn't create identity, because web3 wasn't set. `
+ + 'Please use setWeb3(web3) first!');
+ }
- super(options);
+ super(options);
- // Orbit's Identity Id (user's Ethereum address) - Optional (will be grabbed later if omitted)
- const id = options.id;
- if(id){
- if(EthereumIdentityProvider.web3.utils.isAddress(id))
- this.id = options.id;
- else
- throw new Error(LOGGING_PREFIX + "Couldn't create identity, because an invalid id was supplied.");
- }
+ // Orbit's Identity Id (user's Ethereum address) - Optional (will be grabbed later if omitted)
+ const { id } = options;
+ if (id) {
+ if (EthereumIdentityProvider.web3.utils.isAddress(id)) this.id = options.id;
+ else throw new Error(`${LOGGING_PREFIX}Couldn't create identity, because an invalid id was supplied.`);
}
+ }
- static get type() { return 'ethereum'; }
+ static get type() { return 'ethereum'; }
- async getId() {
- // Id wasn't in the constructor, grab it now
- if(!this.id) {
- const accounts = await EthereumIdentityProvider.web3.eth.getAccounts();
- if(!accounts[0])
- throw new Error(LOGGING_PREFIX + "Couldn't create identity, because no web3 accounts were found (locked Metamask?).");
+ async getId() {
+ // Id wasn't in the constructor, grab it now
+ if (!this.id) {
+ const accounts = await EthereumIdentityProvider.web3.eth.getAccounts();
+ if (!accounts[0]) {
+ throw new Error(`${LOGGING_PREFIX}Couldn't create identity, because no web3 accounts were found (
+ locked Metamask?).`);
+ }
- this.id = accounts[0];
- }
- return this.id;
+ [this.id] = accounts;
}
+ return this.id;
+ }
- async signIdentity(data) {
- if (process.env.NODE_ENV === 'development') { //Don't sign repeatedly while in development
- console.debug(LOGGING_PREFIX + 'Attempting to find stored Orbit identity data...');
- const signaturePubKey = await getIdentitySignaturePubKey(data);
- if (signaturePubKey) {
- const identityInfo = {
- id: this.id,
- pubKeySignId: data,
- signaturePubKey,
- };
- if (await EthereumIdentityProvider.verifyIdentityInfo(identityInfo)) {
- console.debug(LOGGING_PREFIX + 'Found and verified stored Orbit identity data!');
- return signaturePubKey;
- }
- console.debug(LOGGING_PREFIX + "Stored Orbit identity data couldn't be verified.");
- } else
- console.debug(LOGGING_PREFIX + 'No stored Orbit identity data were found.');
+ async signIdentity(data) {
+ if (process.env.NODE_ENV === 'development') { // Don't sign repeatedly while in development
+ console.debug(`${LOGGING_PREFIX}Attempting to find stored Orbit identity data...`);
+ const signaturePubKey = await getIdentitySignaturePubKey(data);
+ if (signaturePubKey) {
+ const identityInfo = {
+ id: this.id,
+ pubKeySignId: data,
+ signaturePubKey,
+ };
+ if (await EthereumIdentityProvider.verifyIdentityInfo(identityInfo)) {
+ console.debug(`${LOGGING_PREFIX}Found and verified stored Orbit identity data!`);
+ return signaturePubKey;
}
- return await this.doSignIdentity(data);
+ console.debug(`${LOGGING_PREFIX}Stored Orbit identity data couldn't be verified.`);
+ } else console.debug(`${LOGGING_PREFIX}No stored Orbit identity data were found.`);
}
+ return await this.doSignIdentity(data);
+ }
- async doSignIdentity(data) {
- try {
- const signaturePubKey = await EthereumIdentityProvider.web3.eth.personal.sign(data, this.id, '');
- if (process.env.NODE_ENV === 'development') {
- storeIdentitySignaturePubKey(data, signaturePubKey)
- .then(() => {
- console.debug(LOGGING_PREFIX + 'Successfully stored current Orbit identity data.');
- })
- .catch(() => {
- console.warn(LOGGING_PREFIX + "Couldn't store current Orbit identity data...");
- });
- }
- return signaturePubKey; // Password not required for MetaMask
- } catch (error) {
- if(error.code && error.code === 4001){
- console.debug(LOGGING_PREFIX + 'User denied message signature.');
- return await this.doSignIdentity(data);
- }
- else{
- console.error(LOGGING_PREFIX + 'Failed to sign data.');
- console.error(error);
- }
- }
- }
+ // eslint-disable-next-line consistent-return
+ async doSignIdentity(data) {
+ try {
+ const signaturePubKey = await EthereumIdentityProvider.web3.eth.personal.sign(data, this.id, '');
+ if (process.env.NODE_ENV === 'development') {
+ storeIdentitySignaturePubKey(data, signaturePubKey)
+ .then(() => {
+ console.debug(`${LOGGING_PREFIX}Successfully stored current Orbit identity data.`);
+ })
+ .catch(() => {
+ console.warn(`${LOGGING_PREFIX}Couldn't store current Orbit identity data...`);
+ });
+ }
+ return signaturePubKey; // Password not required for MetaMask
+ } catch (error) {
+ if (error.code && error.code === 4001) {
+ console.debug(`${LOGGING_PREFIX}User denied message signature.`);
+ return await this.doSignIdentity(data);
+ }
- static async verifyIdentity(identity) {
- // Verify that identity was signed by the ID
- return new Promise(resolve => {
- resolve(EthereumIdentityProvider.web3.eth.accounts.recover(identity.publicKey + identity.signatures.id,
- identity.signatures.publicKey) === identity.id)
- })
+ console.error(`${LOGGING_PREFIX}Failed to sign data.`);
+ console.error(error);
}
+ }
- static async verifyIdentityInfo(identityInfo) {
- // Verify that identity was signed by the ID
- return new Promise(resolve => {
- resolve(EthereumIdentityProvider.web3.eth.accounts.recover(identityInfo.pubKeySignId,
- identityInfo.signaturePubKey) === identityInfo.id)
- })
- }
+ static async verifyIdentity(identity) {
+ // Verify that identity was signed by the ID
+ return new Promise((resolve) => {
+ resolve(EthereumIdentityProvider.web3.eth.accounts.recover(identity.publicKey + identity.signatures.id,
+ identity.signatures.publicKey) === identity.id);
+ });
+ }
- // Initialize by supplying a web3 object
- static setWeb3(web3){
- EthereumIdentityProvider.web3 = web3;
- }
+ static async verifyIdentityInfo(identityInfo) {
+ // Verify that identity was signed by the ID
+ return new Promise((resolve) => {
+ resolve(EthereumIdentityProvider.web3.eth.accounts.recover(identityInfo.pubKeySignId,
+ identityInfo.signaturePubKey) === identityInfo.id);
+ });
+ }
+
+ // Initialize by supplying a web3 object
+ static setWeb3(web3) {
+ EthereumIdentityProvider.web3 = web3;
+ }
}
EthereumIdentityProvider.web3 = {};
diff --git a/packages/concordia-app/src/redux/reducers/userReducer.js b/packages/concordia-app/src/redux/reducers/userReducer.js
index c944f5d..cbe61c6 100644
--- a/packages/concordia-app/src/redux/reducers/userReducer.js
+++ b/packages/concordia-app/src/redux/reducers/userReducer.js
@@ -1,31 +1,31 @@
import { USER_DATA_UPDATED } from '../actions/userActions';
const initialState = {
- username: '',
- address: null,
- hasSignedUp: false,
+ username: '',
+ address: null,
+ hasSignedUp: false,
};
const userReducer = (state = initialState, action) => {
- const { type } = action;
+ const { type } = action;
- if(type === USER_DATA_UPDATED) {
- const { address, username } = action;
- if(username){
- return {
- username: username,
- address: address,
- hasSignedUp: true,
- };
- }
- return {
- username: '',
- address,
- hasSignedUp: false,
- };
+ if (type === USER_DATA_UPDATED) {
+ const { address, username } = action;
+ if (username) {
+ return {
+ username,
+ address,
+ hasSignedUp: true,
+ };
}
+ return {
+ username: '',
+ address,
+ hasSignedUp: false,
+ };
+ }
- return state;
+ return state;
};
export default userReducer;
diff --git a/packages/concordia-app/src/redux/sagas/orbitSaga.js b/packages/concordia-app/src/redux/sagas/orbitSaga.js
index bd0f3c4..12a169b 100644
--- a/packages/concordia-app/src/redux/sagas/orbitSaga.js
+++ b/packages/concordia-app/src/redux/sagas/orbitSaga.js
@@ -1,22 +1,21 @@
-import { put, all, take } from 'redux-saga/effects'
+import { put, all, take } from 'redux-saga/effects';
-import { breezeActions } from '@ezerous/breeze'
-import { drizzleActions } from '@ezerous/drizzle'
+import { breezeActions } from '@ezerous/breeze';
+import { drizzleActions } from '@ezerous/drizzle';
-function * initOrbitDatabases (action) {
- const { account, breeze} = action;
- yield put(breezeActions.orbit.orbitInit(breeze, account)); //same as breeze.initOrbit(account);
+function* initOrbitDatabases(action) {
+ const { account, breeze } = action;
+ yield put(breezeActions.orbit.orbitInit(breeze, account)); // same as breeze.initOrbit(account);
}
-function * orbitSaga () {
- const res = yield all([
- take(drizzleActions.drizzle.DRIZZLE_INITIALIZED),
- take(breezeActions.breeze.BREEZE_INITIALIZED),
- take(drizzleActions.account.ACCOUNTS_FETCHED)
- ]);
+function* orbitSaga() {
+ const res = yield all([
+ take(drizzleActions.drizzle.DRIZZLE_INITIALIZED),
+ take(breezeActions.breeze.BREEZE_INITIALIZED),
+ take(drizzleActions.account.ACCOUNTS_FETCHED),
+ ]);
- yield initOrbitDatabases({breeze:res[1].breeze, account: res[2].accounts[0]});
+ yield initOrbitDatabases({ breeze: res[1].breeze, account: res[2].accounts[0] });
}
-export default orbitSaga
-
+export default orbitSaga;
diff --git a/packages/concordia-app/src/redux/sagas/rootSaga.js b/packages/concordia-app/src/redux/sagas/rootSaga.js
index b6f7917..beead57 100644
--- a/packages/concordia-app/src/redux/sagas/rootSaga.js
+++ b/packages/concordia-app/src/redux/sagas/rootSaga.js
@@ -1,17 +1,17 @@
import { all, fork } from 'redux-saga/effects';
import { drizzleSagas } from '@ezerous/drizzle';
-import { breezeSagas } from '@ezerous/breeze'
-import orbitSaga from './orbitSaga'
-import userSaga from './userSaga'
+import { breezeSagas } from '@ezerous/breeze';
+import orbitSaga from './orbitSaga';
+import userSaga from './userSaga';
export default function* root() {
- const sagas = [
- ...drizzleSagas,
- ...breezeSagas,
- orbitSaga,
- userSaga
- ];
- yield all(
- sagas.map((saga) => fork(saga)),
- );
+ const sagas = [
+ ...drizzleSagas,
+ ...breezeSagas,
+ orbitSaga,
+ userSaga,
+ ];
+ yield all(
+ sagas.map((saga) => fork(saga)),
+ );
}
diff --git a/packages/concordia-app/src/redux/sagas/userSaga.js b/packages/concordia-app/src/redux/sagas/userSaga.js
index 23324b1..6d35de4 100644
--- a/packages/concordia-app/src/redux/sagas/userSaga.js
+++ b/packages/concordia-app/src/redux/sagas/userSaga.js
@@ -1,42 +1,43 @@
-import { all, call, put, take } from 'redux-saga/effects';
+/* eslint-disable no-console */
+import {
+ all, call, put, take,
+} from 'redux-saga/effects';
import { drizzleActions } from '@ezerous/drizzle';
import { USER_DATA_UPDATED, USER_DATA_ERROR } from '../actions/userActions';
-function * fetchUserData ({drizzle, account}) {
- const contract = drizzle.contracts['Forum'];
- const transaction = yield call(contract.methods.hasUserSignedUp, account);
-
- try {
- const dispatchArgs = { address: account };
- const callResult = yield call(transaction.call, { address: account });
-
- // User has signed up, fetch his username
- if (callResult) {
- const txObj2 = yield call(contract.methods.getUsername, account);
- dispatchArgs.username = yield call(txObj2.call, {
- address: account
- });
- }
-
- yield put({
- type: USER_DATA_UPDATED, ...dispatchArgs
- });
-
- } catch (error) {
- console.error(error);
- yield put({ type: USER_DATA_ERROR });
+function* fetchUserData({ drizzle, account }) {
+ const contract = drizzle.contracts.Forum;
+ const transaction = yield call(contract.methods.hasUserSignedUp, account);
+
+ try {
+ const dispatchArgs = { address: account };
+ const callResult = yield call(transaction.call, { address: account });
+
+ // User has signed up, fetch his username
+ if (callResult) {
+ const txObj2 = yield call(contract.methods.getUsername, account);
+ dispatchArgs.username = yield call(txObj2.call, {
+ address: account,
+ });
}
-}
+ yield put({
+ type: USER_DATA_UPDATED, ...dispatchArgs,
+ });
+ } catch (error) {
+ console.error(error);
+ yield put({ type: USER_DATA_ERROR });
+ }
+}
-function * userSaga () {
- const res = yield all([
- take(drizzleActions.drizzle.DRIZZLE_INITIALIZED),
- take(drizzleActions.account.ACCOUNTS_FETCHED)
- ]);
+function* userSaga() {
+ const res = yield all([
+ take(drizzleActions.drizzle.DRIZZLE_INITIALIZED),
+ take(drizzleActions.account.ACCOUNTS_FETCHED),
+ ]);
- yield fetchUserData({drizzle:res[0].drizzle, account: res[1].accounts[0]});
+ yield fetchUserData({ drizzle: res[0].drizzle, account: res[1].accounts[0] });
}
-export default userSaga
+export default userSaga;
diff --git a/packages/concordia-app/src/redux/store.js b/packages/concordia-app/src/redux/store.js
index dfb6f3d..23ff9fc 100644
--- a/packages/concordia-app/src/redux/store.js
+++ b/packages/concordia-app/src/redux/store.js
@@ -1,24 +1,25 @@
import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit';
import { drizzleReducers, drizzleMiddlewares, generateContractsInitialState } from '@ezerous/drizzle';
-import { breezeReducers } from '@ezerous/breeze'
-import userReducer from './reducers/userReducer'
+import { breezeReducers } from '@ezerous/breeze';
import createSagaMiddleware from 'redux-saga';
+import userReducer from './reducers/userReducer';
import rootSaga from './sagas/rootSaga';
import drizzleOptions from '../options/drizzleOptions';
const initialState = {
- contracts: generateContractsInitialState(drizzleOptions),
+ contracts: generateContractsInitialState(drizzleOptions),
};
const sagaMiddleware = createSagaMiddleware();
const store = configureStore({
- reducer: {...drizzleReducers, ...breezeReducers, user: userReducer },
- middleware: getDefaultMiddleware({
- serializableCheck: false, //https://redux.js.org/style-guide/style-guide/#do-not-put-non-serializable-values-in-state-or-actions
- }).concat(drizzleMiddlewares).concat(sagaMiddleware),
- preloadedState: initialState
-})
+ reducer: { ...drizzleReducers, ...breezeReducers, user: userReducer },
+ middleware: getDefaultMiddleware({
+ // https://redux.js.org/style-guide/style-guide/#do-not-put-non-serializable-values-in-state-or-actions
+ serializableCheck: false,
+ }).concat(drizzleMiddlewares).concat(sagaMiddleware),
+ preloadedState: initialState,
+});
sagaMiddleware.run(rootSaga);
export default store;
diff --git a/packages/concordia-app/src/utils/serviceWorker.js b/packages/concordia-app/src/utils/serviceWorker.js
index f8c7e50..07a35b0 100644
--- a/packages/concordia-app/src/utils/serviceWorker.js
+++ b/packages/concordia-app/src/utils/serviceWorker.js
@@ -1,3 +1,6 @@
+/* eslint-disable no-console */
+/* eslint-disable no-use-before-define */
+
// This optional code is used to register a service worker.
// register() is not called by default.
@@ -11,13 +14,13 @@
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
- window.location.hostname === 'localhost' ||
+ window.location.hostname === 'localhost'
// [::1] is the IPv6 localhost address.
- window.location.hostname === '[::1]' ||
+ || window.location.hostname === '[::1]'
// 127.0.0.1/8 is considered localhost for IPv4.
- window.location.hostname.match(
- /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
- )
+ || window.location.hostname.match(
+ /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,
+ ),
);
export function register(config) {
@@ -42,8 +45,8 @@ export function register(config) {
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
- 'This web app is being served cache-first by a service ' +
- 'worker. To learn more, visit https://bit.ly/CRA-PWA'
+ 'This web app is being served cache-first by a service '
+ + 'worker. To learn more, visit https://bit.ly/CRA-PWA',
);
});
} else {
@@ -57,7 +60,8 @@ export function register(config) {
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
- .then(registration => {
+ .then((registration) => {
+ // eslint-disable-next-line no-param-reassign
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
@@ -70,8 +74,8 @@ function registerValidSW(swUrl, config) {
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
- 'New content is available and will be used when all ' +
- 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
+ 'New content is available and will be used when all '
+ + 'tabs for this page are closed. See https://bit.ly/CRA-PWA.',
);
// Execute callback
@@ -93,7 +97,7 @@ function registerValidSW(swUrl, config) {
};
};
})
- .catch(error => {
+ .catch((error) => {
console.error('Error during service worker registration:', error);
});
}
@@ -101,15 +105,15 @@ function registerValidSW(swUrl, config) {
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
- .then(response => {
+ .then((response) => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
- response.status === 404 ||
- (contentType != null && contentType.indexOf('javascript') === -1)
+ response.status === 404
+ || (contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
- navigator.serviceWorker.ready.then(registration => {
+ navigator.serviceWorker.ready.then((registration) => {
registration.unregister().then(() => {
window.location.reload();
});
@@ -121,14 +125,14 @@ function checkValidServiceWorker(swUrl, config) {
})
.catch(() => {
console.log(
- 'No internet connection found. App is running in offline mode.'
+ 'No internet connection found. App is running in offline mode.',
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
- navigator.serviceWorker.ready.then(registration => {
+ navigator.serviceWorker.ready.then((registration) => {
registration.unregister();
});
}
diff --git a/packages/concordia-contracts/index.js b/packages/concordia-contracts/index.js
index 7440d0d..ff79437 100644
--- a/packages/concordia-contracts/index.js
+++ b/packages/concordia-contracts/index.js
@@ -1,13 +1,13 @@
let Forum;
try {
- // eslint-disable-next-line global-require
- Forum = require('./build/Forum.json');
+ // eslint-disable-next-line global-require
+ Forum = require('./build/Forum.json');
} catch (e) {
- // eslint-disable-next-line no-console
- console.error("Could not require contract artifacts. Haven't you run compile yet?");
+ // eslint-disable-next-line no-console
+ console.error("Could not require contract artifacts. Haven't you run compile yet?");
}
module.exports = {
- contracts: [Forum],
+ contracts: [Forum],
};
diff --git a/packages/concordia-contracts/migrations/1_initial_migration.js b/packages/concordia-contracts/migrations/1_initial_migration.js
index 2565467..5dfb83e 100644
--- a/packages/concordia-contracts/migrations/1_initial_migration.js
+++ b/packages/concordia-contracts/migrations/1_initial_migration.js
@@ -2,5 +2,5 @@ const Migrations = artifacts.require('./Migrations.sol');
// eslint-disable-next-line func-names
module.exports = function (deployer) {
- deployer.deploy(Migrations);
+ deployer.deploy(Migrations);
};
diff --git a/packages/concordia-contracts/migrations/2_deploy_contracts.js b/packages/concordia-contracts/migrations/2_deploy_contracts.js
index c94e2cb..ec5722e 100644
--- a/packages/concordia-contracts/migrations/2_deploy_contracts.js
+++ b/packages/concordia-contracts/migrations/2_deploy_contracts.js
@@ -2,5 +2,5 @@ const Forum = artifacts.require('Forum');
// eslint-disable-next-line func-names
module.exports = function (deployer) {
- deployer.deploy(Forum);
+ deployer.deploy(Forum);
};
diff --git a/packages/concordia-contracts/truffle-config.js b/packages/concordia-contracts/truffle-config.js
index ab6d593..3ef72a1 100644
--- a/packages/concordia-contracts/truffle-config.js
+++ b/packages/concordia-contracts/truffle-config.js
@@ -4,24 +4,24 @@ const { GANACHE_HOST } = process.env;
const { GANACHE_PORT } = process.env;
module.exports = {
- // See
- // to customize your Truffle configuration!
- compilers: {
- solc: {
- version: '0.7.1',
- },
+ // See
+ // to customize your Truffle configuration!
+ compilers: {
+ solc: {
+ version: '0.7.1',
},
- contracts_build_directory: path.join(__dirname, 'build/'),
- networks: {
- develop: {
- host: GANACHE_HOST || '127.0.0.1',
- port: GANACHE_PORT || '8545',
- network_id: '*',
- },
- test: {
- host: GANACHE_HOST || '127.0.0.1',
- port: GANACHE_PORT || '8546',
- network_id: '*',
- },
+ },
+ contracts_build_directory: path.join(__dirname, 'build/'),
+ networks: {
+ develop: {
+ host: GANACHE_HOST || '127.0.0.1',
+ port: GANACHE_PORT || '8545',
+ network_id: '*',
},
+ test: {
+ host: GANACHE_HOST || '127.0.0.1',
+ port: GANACHE_PORT || '8546',
+ network_id: '*',
+ },
+ },
};