From e0ad21453dddffb4709971aeede8973e7cb5f536 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 18 May 2019 14:34:03 +0300 Subject: [PATCH] Orbit tiny improvements --- app/package.json | 1 - app/src/CustomPropTypes.js | 2 -- app/src/redux/sagas/orbitSaga.js | 4 ++-- app/src/utils/EthereumIdentityProvider.js | 16 +++++----------- app/src/utils/orbitUtils.js | 12 ++++++------ 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/app/package.json b/app/package.json index fa888c5..fe30cc7 100644 --- a/app/package.json +++ b/app/package.json @@ -13,7 +13,6 @@ "ipfs": "0.35.0", "lodash.isequal": "4.5.0", "orbit-db": "0.21.0-rc.1", - "orbit-db-keystore": "0.2.1", "orbit-db-identity-provider": "0.1.0", "prop-types": "15.7.2", "react": "16.8.6", diff --git a/app/src/CustomPropTypes.js b/app/src/CustomPropTypes.js index cd6baf8..eb92eae 100644 --- a/app/src/CustomPropTypes.js +++ b/app/src/CustomPropTypes.js @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'; //TODO: Move this file const GetTopicResult = PropTypes.PropTypes.shape({ userAddress: PropTypes.string.isRequired, - fullOrbitAddress: PropTypes.string.isRequired, userName: PropTypes.string.isRequired, timestamp: PropTypes.number.isRequired, numberOfReplies: PropTypes.number.isRequired @@ -11,7 +10,6 @@ const GetTopicResult = PropTypes.PropTypes.shape({ const GetPostResult = PropTypes.PropTypes.shape({ userAddress: PropTypes.string.isRequired, - fullOrbitAddress: PropTypes.string.isRequired, userName: PropTypes.string.isRequired, timestamp: PropTypes.number.isRequired, topicID: PropTypes.string.isRequired diff --git a/app/src/redux/sagas/orbitSaga.js b/app/src/redux/sagas/orbitSaga.js index b6ec73b..d0d2853 100644 --- a/app/src/redux/sagas/orbitSaga.js +++ b/app/src/redux/sagas/orbitSaga.js @@ -31,11 +31,11 @@ function* getOrbitDBInfo() { address: account }); if (callResult) { - yield call(loadDatabases); + yield call(loadDatabases, account); } else { const orbit = yield select(state => state.orbit); if(!orbit.ready){ - const { orbitdb, topicsDB, postsDB } = yield call(createDatabases); + const { orbitdb, topicsDB, postsDB } = yield call(createDatabases, account); yield put(updateDatabases(DATABASES_CREATED, orbitdb, topicsDB, postsDB )); } } diff --git a/app/src/utils/EthereumIdentityProvider.js b/app/src/utils/EthereumIdentityProvider.js index 734628f..0ba707b 100644 --- a/app/src/utils/EthereumIdentityProvider.js +++ b/app/src/utils/EthereumIdentityProvider.js @@ -1,22 +1,16 @@ import { web3 } from '../redux/sagas/web3UtilsSaga'; class EthereumIdentityProvider { - constructor () { - this.web3 = web3; + constructor (options = {}) { // Orbit's Identity Id (equals user's Ethereum address) + this.id = options.id; // web3.eth.getAccounts())[0] } - // Returns the type of the identity provider - static get type () { return 'ethereum' } + static get type () { return 'ethereum'; } - // Returns the signer's id - async getId () { - return (await this.web3.eth.getAccounts())[0]; - } + async getId () { return this.id; } - // Returns a signature of pubkeysignature async signIdentity (data) { - const address = await this.getId(); - return await this.web3.eth.personal.sign(data,address,""); //Password not required for MetaMask + return await web3.eth.personal.sign(data, this.id,""); //Password not required for MetaMask } static async verifyIdentity (identity) { diff --git a/app/src/utils/orbitUtils.js b/app/src/utils/orbitUtils.js index b5105eb..4adfc23 100644 --- a/app/src/utils/orbitUtils.js +++ b/app/src/utils/orbitUtils.js @@ -22,16 +22,16 @@ function initIPFS() { }); } -async function createDatabases() { +async function createDatabases(identityId) { console.debug('Creating databases...'); - const databases = await createDBs(); + const databases = await createDBs(identityId); console.debug('Databases created successfully.'); return databases; } -async function loadDatabases() { +async function loadDatabases(identityId) { console.debug('Loading databases...'); - const { orbitdb, topicsDB, postsDB } = await createDBs(); + const { orbitdb, topicsDB, postsDB } = await createDBs(identityId); await topicsDB.load().catch((error) => console.error(`TopicsDB loading error: ${error}`)); await postsDB.load().catch((error) => console.error(`PostsDB loading error: ${error}`)); @@ -87,9 +87,9 @@ async function orbitSagaOpen(orbitdb, address) { return store; } -async function createDBs(){ +async function createDBs(identityId){ const ipfs = getIPFS(); - const identity = await Identities.createIdentity({type: 'ethereum'}); + const identity = await Identities.createIdentity({id: identityId, type: 'ethereum'}); const orbitdb = await OrbitDB.createInstance(ipfs, {identity}); const topicsDB = await orbitdb.keyvalue('topics') .catch((error) => console.error(`TopicsDB init error: ${error}`));