Skip to content

Commit

Permalink
Merge pull request #322 from SuperblocksHQ/feature-ipfs-sync
Browse files Browse the repository at this point in the history
Feature ipfs sync
  • Loading branch information
javier-tarazaga authored Jan 14, 2019
2 parents 183bf08 + 4fd2fde commit 5333dc0
Show file tree
Hide file tree
Showing 89 changed files with 4,234 additions and 682 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"ethereumjs-util": "^5.1.5",
"ethereumjs-vm": "~2.3.3",
"file-saver": "^2.0.0-rc.4",
"ipfs-api": "^26.1.2",
"jszip": "^3.1.5",
"jszip-utils": "^0.0.2",
"less": "^3.8.1",
Expand All @@ -113,6 +114,7 @@
"react-splitter-layout": "^3.0.1",
"react-switch": "^3.0.4",
"react-tippy": "^1.2.3",
"react-toastify": "^4.5.2",
"redux": "^4.0.0",
"redux-observable": "^1.0.0",
"redux-persist": "^5.10.0",
Expand Down
4 changes: 3 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export * from './app.actions';
export * from './panes.actions';
export * from './projects.actions';
export * from './project.actions';
export * from './explorer.actions';
export * from './sidePanels.actions';
export * from './settings.actions';
export * from './ipfs.actions';
export * from './toast.actions';
123 changes: 123 additions & 0 deletions src/actions/ipfs.actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright 2018 Superblocks AB
//
// This file is part of Superblocks Lab.
//
// Superblocks Lab is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3 of the License.
//
// Superblocks Lab is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Superblocks Lab. If not, see <http://www.gnu.org/licenses/>.

export const ipfsActions = {
UPLOAD_TO_IPFS: 'UPLOAD_TO_IPFS',
uploadToIPFS(uploadSettings) {
return {
type: ipfsActions.UPLOAD_TO_IPFS,
data: { uploadSettings }
};
},
UPLOAD_TO_IPFS_SUCCESS: 'UPLOAD_TO_IPFS_SUCCESS',
uploadToIPFSSuccess({ timestamp, shareURL }) {
return {
type: ipfsActions.UPLOAD_TO_IPFS_SUCCESS,
data: { timestamp, shareURL }
}
},
UPLOAD_TO_IPFS_FAIL: 'UPLOAD_TO_IPFS_FAIL',
uploadToIPFSFail(error) {
return {
type: ipfsActions.UPLOAD_TO_IPFS_FAIL,
data: error
}
},
RESTORE_IPFS_STATE_SUCCESS: 'RESTORE_IPFS_STATE_SUCCESS',
restoreIPFSStateSuccess({ timestamp, shareURL }) {
return {
type: ipfsActions.RESTORE_IPFS_STATE_SUCCESS,
data: { timestamp, shareURL }
}
},
RESTORE_IPFS_STATE_FAIL: 'RESTORE_IPFS_STATE_FAIL',
restoreIPFSStateFail() {
return {
type: ipfsActions.RESTORE_IPFS_STATE_FAIL,
}
},
SHOW_UPLOAD_SETTINGS: 'SHOW_UPLOAD_SETTINGS',
showUploadSettings() {
return {
type: ipfsActions.SHOW_UPLOAD_SETTINGS,
}
},
HIDE_UPLOAD_SETTINGS: 'HIDE_UPLOAD_SETTINGS',
hideUploadSettings() {
return {
type: ipfsActions.HIDE_UPLOAD_SETTINGS,
}
},
UPLOAD_SETTINGS_CHANGED: 'UPLOAD_SETTINGS_CHANGED',
uploadSettingsChanged(uploadSettings) {
return {
type: ipfsActions.UPLOAD_SETTINGS_CHANGED,
data: uploadSettings
}
},
HIDE_UPLOAD_DIALOG: 'HIDE_UPLOAD_DIALOG',
hideUploadDialog() {
return {
type: ipfsActions.HIDE_UPLOAD_DIALOG,
}
},
FORK_PROJECT: 'FORK_PROJECT',
forkProject() {
return {
type: ipfsActions.FORK_PROJECT,
}
},
FORK_PROJECT_SUCCESS: 'FORK_PROJECT_SUCCESS',
forkProjectSuccess() {
return {
type: ipfsActions.FORK_PROJECT_SUCCESS,
}
},
FORK_PROJECT_FAIL: 'FORK_PROJECT_FAIL',
forkProjectFail(error) {
return {
type: ipfsActions.FORK_PROJECT_FAIL,
data: error
}
},
IMPORT_PROJECT_FROM_IPFS: 'IMPORT_PROJECT_FROM_IPFS',
importProjectFromIpfs(hash) {
return {
type: ipfsActions.IMPORT_PROJECT_FROM_IPFS,
data: hash
}
},
IMPORT_PROJECT_FROM_IPFS_SUCCESS: 'IMPORT_PROJECT_FROM_IPFS_SUCCESS',
importProjectFromIpfsSuccess() {
return {
type: ipfsActions.IMPORT_PROJECT_FROM_IPFS_SUCCESS,
}
},
IMPORT_PROJECT_FROM_IPFS_FAIL: 'IMPORT_PROJECT_FROM_IPFS_FAIL',
importProjectFromIpfsFail(error) {
return {
type: ipfsActions.IMPORT_PROJECT_FROM_IPFS_FAIL,
data: error
}
},
UPDATE_IPFS_ACTION_BUTTONS: 'UPDATE_IPFS_ACTION_BUTTONS',
updateIpfsActionButtons({ showUploadButton, showForkButton }) {
return {
type: ipfsActions.UPDATE_IPFS_ACTION_BUTTONS,
data: { showUploadButton, showForkButton }
}
}
}
48 changes: 48 additions & 0 deletions src/actions/project.actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2018 Superblocks AB
//
// This file is part of Superblocks Lab.
//
// Superblocks Lab is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3 of the License.
//
// Superblocks Lab is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Superblocks Lab. If not, see <http://www.gnu.org/licenses/>.

export const projectActions = {
SELECT_PROJECT: 'SELECT_PROJECT',
selectProject(project) {
return {
type: projectActions.SELECT_PROJECT,
data: project
};
},
UPDATE_PROJECT_SETTINGS: 'UPDATE_PROJECT_SETTINGS',
updateProjectSettings(projectSettings) {
return {
type: projectActions.UPDATE_PROJECT_SETTINGS,
data: projectSettings
};
},
UPDATE_PROJECT_SETTINGS_SUCCESS: 'UPDATE_PROJECT_SETTINGS_SUCCESS',
updateProjectSettingsSuccess(newProjectSettings) {
return {
type: projectActions.UPDATE_PROJECT_SETTINGS_SUCCESS,
data: newProjectSettings,
};
},
UPDATE_PROJECT_SETTINGS_FAIL: 'UPDATE_PROJECT_SETTINGS_FAIL',
updateProjectSettingsFail(error) {
return {
type: projectActions.UPDATE_PROJECT_SETTINGS_FAIL,
error: error
};
}
}


6 changes: 0 additions & 6 deletions src/actions/projects.actions.js

This file was deleted.

25 changes: 25 additions & 0 deletions src/actions/toast.actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2018 Superblocks AB
//
// This file is part of Superblocks Lab.
//
// Superblocks Lab is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3 of the License.
//
// Superblocks Lab is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Superblocks Lab. If not, see <http://www.gnu.org/licenses/>.

export const toastActions = {
TOAST_DISMISSED: 'TOAST_DISMISSED',
toastDismissed(id) {
return {
type: toastActions.TOAST_DISMISSED,
data: id
};
}
}
20 changes: 20 additions & 0 deletions src/actions/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2018 Superblocks AB
//
// This file is part of Superblocks Lab.
//
// Superblocks Lab is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3 of the License.
//
// Superblocks Lab is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Superblocks Lab. If not, see <http://www.gnu.org/licenses/>.

export const closeAllPanels = () => ({ type: 'CLOSE_ALL_PANELS' });
export const toggleTransactionsHistoryPanel = () => ({ type: 'TOGGLE_TRANSACTIONS_HISTORY_PANEL' });
export const openTransactionsHistoryPanel = () => ({ type: 'OPEN_TRANSACTIONS_HISTORY_PANEL' });
export const closeTransactionsHistoryPanel = () => ({ type: 'CLOSE_TRANSACTIONS_HISTORY_PANEL' });
1 change: 1 addition & 0 deletions src/assets/static/img/icon-information.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions src/assets/static/img/img-ipfs-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 21 additions & 13 deletions src/components/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
import React, { Component } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';

import Backend from '../projecteditor/control/backend';
import Modal from '../modal';
import ProjectEditor from '../projecteditor';
import { Wallet } from '../projecteditor/wallet';
import Solc from '../solc';
import EVM from '../evm';
import Networks from '../../networks';
import { previewService } from '../../services';
import { previewService, ipfsService } from '../../services';
import AnalyticsDialog from '../analyticsDialog';
import OnlyIf from '../onlyIf';
import ToastContainer from "../toasts/toastcontainer";

export default class App extends Component {

Expand All @@ -39,16 +39,14 @@ export default class App extends Component {
constructor(props) {
super(props);
this.idCounter = 0;
this.isImportedProject = false;
this.backend = new Backend();

this.session = {
start_time: Date.now(),
};

// Used to communicate between components, events is probably a better way of doing this.
this.router = {
register: this.register,
};

this.router = this.props.router;
this.router.register('app', this);

this.functions = {
Expand Down Expand Up @@ -94,8 +92,7 @@ export default class App extends Component {
}

_convertProjects = cb => {
const backend = new Backend();
backend.convertProjects(status => {
this.backend.convertProjects(status => {
if (status == 1) {
const modalData = {
title: 'Projects converted',
Expand Down Expand Up @@ -137,10 +134,6 @@ export default class App extends Component {
this.forceUpdate();
};

register = (name, obj) => {
this.router[name] = obj;
};

_init = () => {
let { appVersion } = this.props;
const modalData = {
Expand All @@ -162,19 +155,31 @@ export default class App extends Component {
this.functions.EVM = new EVM({ id: this.generateId() });

previewService.init(this.functions.wallet);
ipfsService.init(this.backend);

const fn = () => {
if (this.functions.compiler && this.functions.EVM) {
console.log('Superblocks Lab ' + appVersion + ' Ready.');

this.functions.modal.close();

this._checkIpfsOnUrl();
} else {
setTimeout(fn, 500);
}
};
fn();
};

_checkIpfsOnUrl = () => {
const a = document.location.href.match("^.*/ipfs/(.+)$");
if (a) {
// TODO: pop modal about importing being processed.
this.isImportedProject = true;
this.props.importProjectFromIpfs(a[1]);
}
};

session_start_time = () => {
return this.session.start_time;
};
Expand Down Expand Up @@ -261,10 +266,12 @@ export default class App extends Component {
router={this.router}
functions={this.functions}
knownWalletSeed={this.knownWalletSeed}
isImportedProject={this.isImportedProject}
/>
<OnlyIf test={showTrackingAnalyticsDialog}>
<AnalyticsDialog />
</OnlyIf>
<ToastContainer />
</OnlyIf>
</div>
</div>
Expand All @@ -277,6 +284,7 @@ export default class App extends Component {
}

App.propTypes = {
router: PropTypes.object.isRequired,
appVersion: PropTypes.string.isRequired,
notifyAppStart: PropTypes.func.isRequired
}
Loading

0 comments on commit 5333dc0

Please sign in to comment.