Skip to content

Commit

Permalink
fix libs structure; add working systemjs plugins; use better dapp-bro…
Browse files Browse the repository at this point in the history
…wser structure

- [CORE-635]
  • Loading branch information
Tobias Winkler committed Feb 26, 2020
1 parent fa6a297 commit 759d03c
Show file tree
Hide file tree
Showing 15 changed files with 640 additions and 90 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ temp/
hooks/
platforms/
!platforms/android/build.gradle
plugins/
plugins/android.json
plugins/ios.json
www/
$RECYCLE.BIN/

Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"dependencies": {
"@evan.network/api-blockchain-core": "^2.3.0",
"console.table": "^0.9.1",
"copy-webpack-plugin": "^5.1.1",
"css-loader": "^3.4.2",
"del": "^2.2.2",
"express": "^4.16.2",
"gulp": "^4.0.0",
"gulp-minify": "^3.1.0",
"inquirer": "^5.1.0",
"ipfs-api": "^26.1.2",
"minimist": "^1.2.0",
"node-sass": "^4.13.1",
"request": "^2.83.0",
"sass-loader": "^8.0.2",
Expand All @@ -20,15 +20,19 @@
},
"description": "evan dapp root project for loading sub dapps, that can also be compiled as a mobile application",
"devDependencies": {
"terser-webpack-plugin": "^2.3.5",
"copy-webpack-plugin": "^5.1.1",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^3.1.2",
"ts-loader": "^6.2.1",
"typescript": "^3.8.2",
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"webpack-cli": "^3.3.11",
"webpack-node-externals": "^1.7.2"
},
"homepage": "https://evannetwork.github.io/",
"keywords": [
Expand All @@ -39,7 +43,7 @@
"SASS"
],
"license": "AGPL-3.0-only",
"main": "dist/app.js",
"main": "dist/dapp-browser.js",
"name": "@evan.network/ui-dapp-browser",
"repository": {
"type": "git",
Expand All @@ -48,11 +52,9 @@
"scripts": {
"build": "npx webpack --mode=production",
"build-dev": "npx webpack --mode=development",
"watch": "npx webpack --mode=development --watch",
"deploy": "gulp --gulpfile gulp/deployment.js deploy --config",
"doc": "gulp --gulpfile gulp/documentation.js",
"postinstall": "npm rebuild node-sass",
"serve": "gulp --cwd . --gulpfile gulp/serve.js serve && npm run watch"
"serve": "gulp --cwd . --gulpfile gulp/serve.js serve && npm run watch",
"watch": "npx webpack --mode=development --watch"
},
"types": "runtime/build/main.d.ts",
"version": "2.17.0"
Expand Down
11 changes: 6 additions & 5 deletions src/app/ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
import config from './config';
import { ipfsCatPromise } from './ipfs';
import { devLog } from './utils';
import bs58Bundle from '../libs/bs58.bundle';
import sha3Bundle from '../libs/js-sha3.min';
import BufferPolyFill from '../libs/buffer.polyfill';

import * as stuff from '../libs/bs58.bundle';

console.log(stuff)
const bs58: any = {};
const keccak256: any = {};
const Buffer = (BufferPolyFill as any).Buffer;
const bs58 = (bs58Bundle as any);
const keccak256 = (sha3Bundle as any).keccak256;

// const bs58 = (window as any).bs58;
let ensCache: any = { };
Expand Down
58 changes: 58 additions & 0 deletions src/app/start.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright (C) 2018-present evan GmbH.
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License, version 3,
as published by the Free Software Foundation.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see http://www.gnu.org/licenses/ or
write to the Free Software Foundation, Inc., 51 Franklin Street,
Fifth Floor, Boston, MA, 02110-1301 USA, or download the license from
the following URL: https://evan.network/license/
*/

import * as loading from './loading';
import * as routing from './routing';
import * as utils from './utils';
import System from '../systemjs/index';

/**
* Starts the whole dapp-browser.
*
* @param {boolean} enableRouting dapp-browser watch for url changes and automatically starts
* dapps with ens addresses that were passed to the location
* hash
*/
export default async function(): Promise<void> {
delete (window as any).System;
delete (window as any).SystemJS;

// add page load performance tracking
(window as any).evanloadTime = Date.now();

// check if we are running in dev mode, load dev mode available modules
await Promise.all([
utils.setUpDevMode(System),
utils.getBrowserName(),
utils.getIsPrivateMode(),
]);

try {
routing.initialize();
await utils.onDeviceReady();

// update build number to enable ens cache
if ((window as any).dappBrowserBuild) {
window.localStorage['evan-dapp-browser-build'] = (window as any).dappBrowserBuild || '';
}
} catch (ex) {
console.error(ex);
utils.showError();
}
}
72 changes: 9 additions & 63 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,76 +23,22 @@ import * as loading from './app/loading';
import * as routing from './app/routing';
import * as utils from './app/utils';
import config from './app/config';

import './index.scss';

// import libs
import System from './systemjs/index';
import start from './app/start';

import './index.scss';

/**
* is inserted when the application was bundled, used to prevent window usage
*/
let evanGlobals: any = { };

/**
* add page load performance tracking
*/
(window as any).evanloadTime = Date.now();

/**************************************************************************************************/
const getDomainName = utils.getDomainName;
let web3;

// prefill bcc for systemjs plugin usage
evanGlobals.ipfsCatPromise = ipfs.ipfsCatPromise;
evanGlobals.restIpfs = ipfs.restIpfs;
evanGlobals.System = System;
evanGlobals.queryParams = routing.getQueryParameters();

/**
* Starts the whole dapp-browser.
*
* @param {boolean} enableRouting dapp-browser watch for url changes and automatically starts
* dapps with ens addresses that were passed to the location
* hash
*/
async function startEvan(): Promise<void> {
// check if we are running in dev mode, load dev mode available modules
await Promise.all([
utils.setUpDevMode(System),
utils.getBrowserName(),
utils.getIsPrivateMode(),
]);

// set initial loadin step
loading.raiseProgress(5);

// load smart-contracts and blockchain-core minimal setup for accessing ens from ipfs
try {
routing.initialize();
await utils.onDeviceReady();

// update build number to enable ens cache
if ((window as any).dappBrowserBuild) {
window.localStorage['evan-dapp-browser-build'] = (window as any).dappBrowserBuild || '';
}
} catch (ex) {
console.error(ex);
utils.showError();
}
}

startEvan();

export {
const DAppBrowser = {
config,
dapp,
evanGlobals,
getDomainName,
getDomainName: utils.getDomainName,
ipfs,
loading,
routing,
start,
System,
utils,
}
};

System.amdDefine('@evan.network/ui-dapp-browser', DAppBrowser);
export default DAppBrowser;
2 changes: 1 addition & 1 deletion src/libs/bs58.bundle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(f){debugger;if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.bs58 = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.bs58 = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict'

exports.byteLength = byteLength
Expand Down
7 changes: 7 additions & 0 deletions src/static/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,12 @@
</div>
</div>
</div>
<script>
System
.import('@evan.network/ui-dapp-browser')
.then((dappBrowser) => {
dappBrowser.start();
});
</script>
</body>
</html>
Loading

0 comments on commit 759d03c

Please sign in to comment.