Skip to content

Commit

Permalink
storage, wallet, and tron fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nsjames committed Oct 31, 2019
1 parent ead0ce4 commit 466937f
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 280 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
LOCAL_TESTING=http://localhost:8081/
#LOCAL_TESTING=

WEB_HOST=https://embed.get-scatter.com/
WEB_HOST_SIMPLE_MODE=https://bridge.get-scatter.com/
Expand Down
61 changes: 15 additions & 46 deletions electron/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const NotificationService = require('./services/notifier');
const HighLevelSockets = require('./services/sockets');
const prompt = require('./services/prompt');

const embedder = require('./services/embedder');
const ecc = require('eosjs-ecc');

const Embedder = require('embedder');
const files = require('./services/files');


Expand Down Expand Up @@ -103,52 +105,20 @@ const createScatterInstance = async () => {
loadingWindow.focus();
});

let hasEmbed = false;

const updateLocalFiles = async (regenerate = false) => {
if(!await embedder.cacheEmbedFiles(loadingWindow, regenerate)){
hasEmbed = await prompt.accepted(
'There was an issue getting the latest Embed version.',
'Would you like to keep using your locally cached version of Scatter Embed which has already been verified previously?'
);
} else hasEmbed = true;
return true;
}

if(await embedder.versionAvailable()){
// User doesn't have a local version,
// so they must grab the version.
if(!await embedder.hasLocalVersion()){
hasEmbed = await embedder.cacheEmbedFiles(loadingWindow);
}

// User has a local version, so they can choose to
// update their local version to the next one.
else {
if(await prompt.accepted(
'An updated Scatter Embed is available.',
'There is an updated version of Scatter Embed available. Do you want to use it?'
)) await updateLocalFiles();
else hasEmbed = true;
}
} else {
// Checking if the user's local file hashes match the ones on the server.
if(await embedder.checkCachedHashes(loadingWindow)) hasEmbed = true;

// If they don't then we will notify the user and allow them to
// either continue using their local files, or re-pull the version from
// the web.
else {
if(!await prompt.accepted(
'Some of your local files had mismatched hashes.',
`It looks like some of the files you have locally don't match the hashes of the current embed version, but your version says it's up to date.
Do you want to continue using your local version instead of trying to re-pull the current embed?`
)) hasEmbed = true;
else await updateLocalFiles(true);
}
}
Embedder.init(
process.env.LOCAL_TESTING ? process.env.LOCAL_TESTING : process.env.WEB_HOST,
process.env.PROOF_KEYS.split(','),
files,
ecc.sha256,
dialog.showErrorBox,
prompt.accepted,
(hashed, signed) => ecc.recoverHash(signed, hashed),
hashstat => loadingWindow.webContents.send('hashstat', hashstat),
process.env.LOCAL_TESTING,
);

if(!hasEmbed) return process.exit(0);
if(!await Embedder.check()) return process.exit(0);

files.toggleAllowInternals(false);

Expand Down Expand Up @@ -214,7 +184,6 @@ app.on('will-finish-launching', () => {

global.appShared = {
ApiWatcher:null,
embedder:require('./services/embedder')
};


Expand Down
229 changes: 0 additions & 229 deletions electron/services/embedder.js

This file was deleted.

7 changes: 7 additions & 0 deletions electron/services/getHost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const {getSimpleMode} = require('./storage');
// getHost
module.exports = () => {
if(process.env.LOCAL_TESTING) return process.env.LOCAL_TESTING;
return getSimpleMode() ? process.env.WEB_HOST_SIMPLE_MODE : process.env.WEB_HOST;

};
2 changes: 1 addition & 1 deletion electron/services/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const safeSetScatter = async (scatter, resolver) => {
};


const getSimpleMode = () => scatterStorage().get('simple_mode');
const getSimpleMode = () => scatterStorage().get('simple_mode') || false;
const setSimpleMode = isSimpleMode => scatterStorage().set('simple_mode', isSimpleMode);

const getScatter = () => scatterStorage().get('scatter');
Expand Down
1 change: 1 addition & 0 deletions electron/services/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const plugins = {
eth:new (require('@walletpack/ethereum').default)()
}

plugins.trx.init();

let seed, salt, scatter, storage;

Expand Down
4 changes: 1 addition & 3 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,9 @@

<script>
const path = require('path');
const storage = require('../electron/services/storage');
const getHost = require('../electron/services/getHost');
const {remote, ipcRenderer} = window.require('electron');

// TODO: Simple mode
console.log('uitype', storage.getSimpleMode());

const isPopOut = location.hash.replace("#/", '') === 'popout';

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"test": "npm run testfile \"test/**/*.spec.js\" --timeout 1000000"
},
"dependencies": {
"embedder":"git+https://[email protected]/GetScatter/Scatter-Embedder.git#master",
"@ledgerhq/hw-app-eth": "^4.68.4",
"@ledgerhq/hw-transport-node-hid": "^4.55.0",
"@walletpack/bitcoin": "1.0.29",
Expand Down
14 changes: 14 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
const { ipcRenderer, remote } = require('electron');
const wallet = remote.getGlobal('wallet');
const getHost = require('./electron/services/getHost');

console.log('getHost', getHost());

const loadStyles = (tries = 0) => {
if(tries >= 20) return console.error('Could not load styles!');
if(typeof window.loadStyles === 'function'){
window.loadStyles(getHost());
}
else setTimeout(() => loadStyles(tries++), 100);
};
loadStyles();

if(!window.wallet) window.wallet = {};

Expand All @@ -10,3 +22,5 @@ ipcRenderer.on('console', (event, data) => console.log('Console from client: ',

window.wallet = Object.assign(window.wallet, wallet);
window.wallet.windowId = remote.getCurrentWindow().id;


Loading

0 comments on commit 466937f

Please sign in to comment.