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",
"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",

2
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

4
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 ));
}
}

16
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) {

12
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}`));

Loading…
Cancel
Save