diff --git a/app/package.json b/app/package.json index f04598a..864e606 100644 --- a/app/package.json +++ b/app/package.json @@ -30,8 +30,12 @@ "uuid": "3.3.2", "web3": "1.0.0-beta.50" }, + "devDependencies": { + "libp2p-websocket-star-rendezvous": "0.3.0" + }, "scripts": { "start": "react-scripts start", + "rendezvous": "rendezvous --port=9090 --host=127.0.0.1", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/app/src/assets/images/ethereum_logo.svg b/app/src/assets/images/ethereum_logo.svg new file mode 100644 index 0000000..7038c6a --- /dev/null +++ b/app/src/assets/images/ethereum_logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/src/assets/images/ipfs_logo.png b/app/src/assets/images/ipfs_logo.png deleted file mode 100644 index 2aa68e8..0000000 Binary files a/app/src/assets/images/ipfs_logo.png and /dev/null differ diff --git a/app/src/assets/images/ipfs_logo.svg b/app/src/assets/images/ipfs_logo.svg new file mode 100644 index 0000000..8d6a879 --- /dev/null +++ b/app/src/assets/images/ipfs_logo.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/components/ProfileInformation.js b/app/src/components/ProfileInformation.js index 512696f..6efae66 100644 --- a/app/src/components/ProfileInformation.js +++ b/app/src/components/ProfileInformation.js @@ -15,6 +15,12 @@ const callsInfo = [ }, { contract: 'Forum', method: 'getOrbitDBId' + }, { + contract: 'Forum', + method: 'getOrbitTopicsDB' + }, { + contract: 'Forum', + method: 'getOrbitPostsDB' }]; class ProfileInformation extends Component { @@ -27,7 +33,9 @@ class ProfileInformation extends Component { this.state = { pageStatus: 'initialized', dateOfRegister: '', - orbitDBId: '' + orbitDBId: '', + topicsDBId: '', + postsDBId: '' }; } @@ -40,7 +48,7 @@ class ProfileInformation extends Component { } getBlockchainData() { - const { pageStatus, dateOfRegister, orbitDBId } = this.state; + const { pageStatus, dateOfRegister, orbitDBId, topicsDBId, postsDBId } = this.state; const { drizzleStatus, address, contracts } = this.props; if (pageStatus === 'initialized' @@ -87,11 +95,29 @@ class ProfileInformation extends Component { }); } } + + if (topicsDBId === '') { + const transaction = contracts[callsInfo[2].contract][callsInfo[2].method][this.dataKey[2]]; + if (transaction) { + this.setState({ + topicsDBId: transaction.value + }); + } + } + + if (postsDBId === '') { + const transaction = contracts[callsInfo[3].contract][callsInfo[3].method][this.dataKey[3]]; + if (transaction) { + this.setState({ + postsDBId: transaction.value + }); + } + } } } render() { - const { orbitDBId, dateOfRegister } = this.state; + const { orbitDBId, topicsDBId, postsDBId, dateOfRegister } = this.state; const { avatarUrl, username, address, numberOfTopics, numberOfPosts, self } = this.props; return ( @@ -118,6 +144,14 @@ class ProfileInformation extends Component { OrbitDB: {orbitDBId} + + TopicsDB: + {topicsDBId} + + + PostsDB: + {postsDBId} + Number of topics created: {numberOfTopics} diff --git a/app/src/components/Topic.js b/app/src/components/Topic.js index e4fdc5c..3d5625c 100644 --- a/app/src/components/Topic.js +++ b/app/src/components/Topic.js @@ -113,11 +113,12 @@ function getTopicSubject(state, props){ if(orbitData && orbitData.subject) return orbitData.subject; } - const db = orbit.replicatedDatabases.find(db => db.fullAddress === `/orbitdb/${topicData.value[0]}/topics`); - if(db && db.ready && db.store){ - const localOrbitData = db.store.get(topicID); - if (localOrbitData){ - return localOrbitData.subject; + else{ + const db = orbit.peerDatabases.find(db => db.fullAddress === `/orbitdb/${topicData.value[0]}/topics`); + if(db && db.store){ + const localOrbitData = db.store.get(topicID); + if (localOrbitData) + return localOrbitData.subject; } } } diff --git a/app/src/containers/LoadingContainer.js b/app/src/containers/LoadingContainer.js index b36fe63..5983628 100644 --- a/app/src/containers/LoadingContainer.js +++ b/app/src/containers/LoadingContainer.js @@ -1,6 +1,7 @@ import React, { Children, Component } from 'react'; import { connect } from 'react-redux'; -import ipfs_logo from '../assets/images/ipfs_logo.png'; +import ethereum_logo from '../assets/images/ethereum_logo.svg'; +import ipfs_logo from '../assets/images/ipfs_logo.svg'; //TODO: Add OrbitDB Loading thingy class LoadingContainer extends Component { @@ -15,7 +16,7 @@ class LoadingContainer extends Component {
-

🦊

+ ethereum_logo

This browser has no connection to the Ethereum network.

Please make sure that: @@ -36,7 +37,7 @@ class LoadingContainer extends Component {

-

🦊

+ ethereum_logo

We can't find any Ethereum accounts!.

@@ -49,7 +50,7 @@ class LoadingContainer extends Component {
-

âš™

+ ethereum_logo

Initializing contracts...

If this takes too long please make sure they are deployed to the network and you are connected to the correct one. diff --git a/app/src/helpers/EpochTimeConverter.js b/app/src/helpers/EpochTimeConverter.js index 87c4508..a3a338d 100644 --- a/app/src/helpers/EpochTimeConverter.js +++ b/app/src/helpers/EpochTimeConverter.js @@ -1,8 +1,8 @@ const epochTimeConverter = (timestamp) => { const timestampDate = new Date(0); timestampDate.setUTCSeconds(timestamp); - return (`${timestampDate.getMonth() + 1} ${ - timestampDate.getDate()}, ${ + return (`${timestampDate.getDate()}/${ + timestampDate.getMonth() + 1}/${ timestampDate.getFullYear()}, ${ timestampDate.getHours()}:${ timestampDate.getMinutes()}:${ diff --git a/app/src/redux/actions/orbitActions.js b/app/src/redux/actions/orbitActions.js index 20f9a01..16ed151 100644 --- a/app/src/redux/actions/orbitActions.js +++ b/app/src/redux/actions/orbitActions.js @@ -3,8 +3,7 @@ const DATABASES_CREATED = 'DATABASES_CREATED'; const DATABASES_LOADED = 'DATABASES_LOADED'; const DATABASES_NOT_READY = 'DATABASES_NOT_READY'; const ADD_PEER_DATABASE = 'ADD_PEER_DATABASE'; -const OPENING_PEER_DATABASE = 'OPENING_PEER_DATABASE'; -const PEER_DATABASE_LOADED = 'PEER_DATABASE_LOADED'; +const PEER_DATABASE_ADDED = 'PEER_DATABASE_ADDED'; const UPDATE_PEERS = 'UPDATE_PEERS'; function updateDatabases(type, orbitdb, topicsDB, postsDB) { @@ -30,8 +29,7 @@ export { DATABASES_CREATED, IPFS_INITIALIZED, UPDATE_PEERS, ADD_PEER_DATABASE, - OPENING_PEER_DATABASE, - PEER_DATABASE_LOADED, + PEER_DATABASE_ADDED, addPeerDatabase, updateDatabases }; diff --git a/app/src/redux/reducers/orbitReducer.js b/app/src/redux/reducers/orbitReducer.js index 7495a99..fc82d3f 100644 --- a/app/src/redux/reducers/orbitReducer.js +++ b/app/src/redux/reducers/orbitReducer.js @@ -1,8 +1,8 @@ import { DATABASES_CREATED, DATABASES_LOADED, - DATABASES_NOT_READY, OPENING_PEER_DATABASE, - IPFS_INITIALIZED, UPDATE_PEERS, PEER_DATABASE_LOADED + DATABASES_NOT_READY, + IPFS_INITIALIZED, UPDATE_PEERS, PEER_DATABASE_ADDED } from '../actions/orbitActions'; const initialState = { @@ -13,7 +13,7 @@ const initialState = { topicsDB: null, postsDB: null, pubsubPeers: {topicsDBPeers:[], postsDBPeers:[]}, - replicatedDatabases: [], + peerDatabases: [], id: null }; @@ -52,22 +52,14 @@ const orbitReducer = (state = initialState, action) => { postsDB: null, id: null }; - case OPENING_PEER_DATABASE: - if(state.replicatedDatabases.find(db => db.fullAddress === action.fullAddress)) + case PEER_DATABASE_ADDED: + if(state.peerDatabases.find(db => db.fullAddress === action.fullAddress)) return state; + console.debug(`Added peer database ${action.fullAddress}`); return { ...state, - replicatedDatabases:[...state.replicatedDatabases, - {fullAddress: action.fullAddress, ready: false, store: null}] - }; - case PEER_DATABASE_LOADED: - return { - ...state, - replicatedDatabases: [...state.replicatedDatabases.map((db) => { - if (db.fullAddress !== action.fullAddress) - return db; // This isn't the item we care about - keep it as-is - return { ...db, ready: true, store: action.store} // Otherwise return an updated value - })] + peerDatabases:[...state.peerDatabases, + {fullAddress: action.fullAddress, store: action.store}] }; case UPDATE_PEERS: return { diff --git a/app/src/redux/sagas/orbitSaga.js b/app/src/redux/sagas/orbitSaga.js index 34c8d60..80514be 100644 --- a/app/src/redux/sagas/orbitSaga.js +++ b/app/src/redux/sagas/orbitSaga.js @@ -4,7 +4,7 @@ import { forumContract, getCurrentAccount } from './drizzleUtilsSaga'; import { loadDatabases, orbitSagaOpen } from '../../utils/orbitUtils'; import { DRIZZLE_UTILS_SAGA_INITIALIZED } from '../actions/drizzleUtilsActions'; import { - ADD_PEER_DATABASE, PEER_DATABASE_LOADED, + ADD_PEER_DATABASE, PEER_DATABASE_ADDED, DATABASES_NOT_READY, IPFS_INITIALIZED, OPENING_PEER_DATABASE, UPDATE_PEERS @@ -65,12 +65,9 @@ function* addPeerDatabase(action) { if(peerOrbitAddresses.size>size){ const { orbitdb } = yield select(state => state.orbit); if(orbitdb){ - yield put.resolve({ - type: OPENING_PEER_DATABASE, fullAddress - }); const store = yield call(orbitSagaOpen, orbitdb, fullAddress); yield put({ - type: PEER_DATABASE_LOADED, fullAddress, store: store + type: PEER_DATABASE_ADDED, fullAddress, store: store }); } } diff --git a/app/src/utils/orbitUtils.js b/app/src/utils/orbitUtils.js index 88ecdbd..390cbf7 100644 --- a/app/src/utils/orbitUtils.js +++ b/app/src/utils/orbitUtils.js @@ -16,14 +16,12 @@ function initIPFS() { ipfs.id(function (error, identity) { if (error) console.error(`IPFS id() error: ${error}`); - console.debug(`IPFS initialized with id: ${identity.id}`); + console.debug(`IPFS initialized with id ${identity.id}`); }) }); } async function createDatabases() { - console.debug("Deleting local storage..."); // Else we are in danger of reusing an existing orbit - localStorage.clear(); // Perhaps not needed at all when orbit ids are used in Orbit 0.20.x+ console.debug('Creating databases...'); const ipfs = getIPFS(); const orbitdb = new OrbitDB(ipfs);