Browse Source

Orbit tiny improvements

develop
Ezerous 6 years ago
parent
commit
e0ad21453d
  1. 1
      app/package.json
  2. 2
      app/src/CustomPropTypes.js
  3. 4
      app/src/redux/sagas/orbitSaga.js
  4. 16
      app/src/utils/EthereumIdentityProvider.js
  5. 12
      app/src/utils/orbitUtils.js

1
app/package.json

@ -13,7 +13,6 @@
"ipfs": "0.35.0", "ipfs": "0.35.0",
"lodash.isequal": "4.5.0", "lodash.isequal": "4.5.0",
"orbit-db": "0.21.0-rc.1", "orbit-db": "0.21.0-rc.1",
"orbit-db-keystore": "0.2.1",
"orbit-db-identity-provider": "0.1.0", "orbit-db-identity-provider": "0.1.0",
"prop-types": "15.7.2", "prop-types": "15.7.2",
"react": "16.8.6", "react": "16.8.6",

2
app/src/CustomPropTypes.js

@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
//TODO: Move this file //TODO: Move this file
const GetTopicResult = PropTypes.PropTypes.shape({ const GetTopicResult = PropTypes.PropTypes.shape({
userAddress: PropTypes.string.isRequired, userAddress: PropTypes.string.isRequired,
fullOrbitAddress: PropTypes.string.isRequired,
userName: PropTypes.string.isRequired, userName: PropTypes.string.isRequired,
timestamp: PropTypes.number.isRequired, timestamp: PropTypes.number.isRequired,
numberOfReplies: PropTypes.number.isRequired numberOfReplies: PropTypes.number.isRequired
@ -11,7 +10,6 @@ const GetTopicResult = PropTypes.PropTypes.shape({
const GetPostResult = PropTypes.PropTypes.shape({ const GetPostResult = PropTypes.PropTypes.shape({
userAddress: PropTypes.string.isRequired, userAddress: PropTypes.string.isRequired,
fullOrbitAddress: PropTypes.string.isRequired,
userName: PropTypes.string.isRequired, userName: PropTypes.string.isRequired,
timestamp: PropTypes.number.isRequired, timestamp: PropTypes.number.isRequired,
topicID: PropTypes.string.isRequired topicID: PropTypes.string.isRequired

4
app/src/redux/sagas/orbitSaga.js

@ -31,11 +31,11 @@ function* getOrbitDBInfo() {
address: account address: account
}); });
if (callResult) { if (callResult) {
yield call(loadDatabases); yield call(loadDatabases, account);
} else { } else {
const orbit = yield select(state => state.orbit); const orbit = yield select(state => state.orbit);
if(!orbit.ready){ 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 )); yield put(updateDatabases(DATABASES_CREATED, orbitdb, topicsDB, postsDB ));
} }
} }

16
app/src/utils/EthereumIdentityProvider.js

@ -1,22 +1,16 @@
import { web3 } from '../redux/sagas/web3UtilsSaga'; import { web3 } from '../redux/sagas/web3UtilsSaga';
class EthereumIdentityProvider { class EthereumIdentityProvider {
constructor () { constructor (options = {}) { // Orbit's Identity Id (equals user's Ethereum address)
this.web3 = web3; 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 this.id; }
async getId () {
return (await this.web3.eth.getAccounts())[0];
}
// Returns a signature of pubkeysignature
async signIdentity (data) { async signIdentity (data) {
const address = await this.getId(); return await web3.eth.personal.sign(data, this.id,""); //Password not required for MetaMask
return await this.web3.eth.personal.sign(data,address,""); //Password not required for MetaMask
} }
static async verifyIdentity (identity) { static async verifyIdentity (identity) {

12
app/src/utils/orbitUtils.js

@ -22,16 +22,16 @@ function initIPFS() {
}); });
} }
async function createDatabases() { async function createDatabases(identityId) {
console.debug('Creating databases...'); console.debug('Creating databases...');
const databases = await createDBs(); const databases = await createDBs(identityId);
console.debug('Databases created successfully.'); console.debug('Databases created successfully.');
return databases; return databases;
} }
async function loadDatabases() { async function loadDatabases(identityId) {
console.debug('Loading databases...'); 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 topicsDB.load().catch((error) => console.error(`TopicsDB loading error: ${error}`));
await postsDB.load().catch((error) => console.error(`PostsDB 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; return store;
} }
async function createDBs(){ async function createDBs(identityId){
const ipfs = getIPFS(); 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 orbitdb = await OrbitDB.createInstance(ipfs, {identity});
const topicsDB = await orbitdb.keyvalue('topics') const topicsDB = await orbitdb.keyvalue('topics')
.catch((error) => console.error(`TopicsDB init error: ${error}`)); .catch((error) => console.error(`TopicsDB init error: ${error}`));

Loading…
Cancel
Save