Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into am-fix-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 authored May 16, 2018
2 parents 3469dcf + 29339a2 commit 5d32232
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,28 @@ import qs from 'query-string';

console.log('This inject.js has been injected by the shell.');

function initProvider () {
const match = window.location.pathname.match(/(0x)?[a-f0-9]{64}|v1/i); // Find the appId
const query = qs.parse(window.location.search);
function getAppId () {
// Dapps built into the shell; URL: file://path-to-shell/.build/dapps/0x0587.../index.html
// Dapps installed from the registry and served by Parity; URL: http://127.0.0.1:8545/ff19...
const [hash] = window.location.pathname.match(/(0x)?[a-f0-9]{64}/i) || [];

if (hash) { return hash; }

// Dapps served in development mode on a dedicated port; URL: http://localhost:3001/?appId=dapp-name
const fromQuery = qs.parse(window.location.search).appId;

if (fromQuery) { return fromQuery; }

// Dapps built locally and served by Parity; URL: http://127.0.0.1:8545/dapp-name
const [, fromParity] = window.location.pathname.match(/^\/?([^/]+)\/?$/) || [];

let appId = match ? match[0] : query.appId;
if (fromParity) { return fromParity; }

console.error('Could not find appId');
}

function initProvider () {
const appId = getAppId();

const ethereum = isElectron()
? new Api.Provider.Ipc(appId)
Expand Down

0 comments on commit 5d32232

Please sign in to comment.