From 6fe361b382a0b7551ccb8fcb09c740936f47bff1 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 20 Nov 2017 12:05:03 +0100 Subject: [PATCH 1/8] Allow localUrl in manifest --- dapps/src/apps/app.rs | 4 ++++ dapps/src/endpoint.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/dapps/src/apps/app.rs b/dapps/src/apps/app.rs index 1d2c9dca6..e22a9e855 100644 --- a/dapps/src/apps/app.rs +++ b/dapps/src/apps/app.rs @@ -26,6 +26,8 @@ pub struct App { pub author: String, #[serde(rename="iconUrl")] pub icon_url: String, + #[serde(rename="localUrl")] + pub local_url: String; } impl App { @@ -38,6 +40,7 @@ impl App { version: info.version.to_owned(), author: info.author.to_owned(), icon_url: info.icon_url.to_owned(), + local_url: info.local_url.to_owned(), } } } @@ -50,6 +53,7 @@ impl Into for App { version: self.version, author: self.author, icon_url: self.icon_url, + local_url: self.local_url, } } } diff --git a/dapps/src/endpoint.rs b/dapps/src/endpoint.rs index 2dbcf209f..3a0b23a04 100644 --- a/dapps/src/endpoint.rs +++ b/dapps/src/endpoint.rs @@ -44,6 +44,7 @@ pub struct EndpointInfo { pub version: String, pub author: String, pub icon_url: String, + pub local_url: String, } pub type Endpoints = BTreeMap>; From d8e86cfe0a63e5b2fa00697a6530b58bd87b33ec Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 20 Nov 2017 13:37:23 +0100 Subject: [PATCH 2/8] Add to all icon_url places --- dapps/js-glue/src/lib.rs.in | 1 + dapps/src/apps/app.rs | 2 +- dapps/src/apps/fetcher/mod.rs | 1 + dapps/src/apps/fs.rs | 1 + dapps/src/page/builtin.rs | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dapps/js-glue/src/lib.rs.in b/dapps/js-glue/src/lib.rs.in index 99a253013..460c6498b 100644 --- a/dapps/js-glue/src/lib.rs.in +++ b/dapps/js-glue/src/lib.rs.in @@ -38,6 +38,7 @@ pub struct Info { pub author: &'static str, pub description: &'static str, pub icon_url: &'static str, + pub local_url: &'static str, } pub trait WebApp : Default + Send + Sync { diff --git a/dapps/src/apps/app.rs b/dapps/src/apps/app.rs index e22a9e855..9ced2438d 100644 --- a/dapps/src/apps/app.rs +++ b/dapps/src/apps/app.rs @@ -27,7 +27,7 @@ pub struct App { #[serde(rename="iconUrl")] pub icon_url: String, #[serde(rename="localUrl")] - pub local_url: String; + pub local_url: String, } impl App { diff --git a/dapps/src/apps/fetcher/mod.rs b/dapps/src/apps/fetcher/mod.rs index effcc19cd..e66c44eb6 100644 --- a/dapps/src/apps/fetcher/mod.rs +++ b/dapps/src/apps/fetcher/mod.rs @@ -306,6 +306,7 @@ mod tests { version: "".into(), author: "".into(), icon_url: "".into(), + local_url: "".into(), }, Default::default(), None); // when diff --git a/dapps/src/apps/fs.rs b/dapps/src/apps/fs.rs index 8be2dcf58..888e32bbf 100644 --- a/dapps/src/apps/fs.rs +++ b/dapps/src/apps/fs.rs @@ -56,6 +56,7 @@ fn read_manifest(name: &str, mut path: PathBuf) -> EndpointInfo { version: "0.0.0".into(), author: "?".into(), icon_url: "icon.png".into(), + local_url: "".into(), } }) } diff --git a/dapps/src/page/builtin.rs b/dapps/src/page/builtin.rs index f1ea50d42..b8c013cb3 100644 --- a/dapps/src/page/builtin.rs +++ b/dapps/src/page/builtin.rs @@ -132,6 +132,7 @@ impl From for EndpointInfo { description: info.description.into(), author: info.author.into(), icon_url: info.icon_url.into(), + local_url: info.local_url.into(), version: info.version.into(), } } From ac722e9e50876aeacbc2311ac3ce766f69ffa755 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 20 Nov 2017 13:37:52 +0100 Subject: [PATCH 3/8] Add appId as needed to local dapps --- js/src/Dapp/dapp.js | 5 ++++- js/src/inject.js | 24 +++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/js/src/Dapp/dapp.js b/js/src/Dapp/dapp.js index 038df7da3..b1b62572a 100644 --- a/js/src/Dapp/dapp.js +++ b/js/src/Dapp/dapp.js @@ -110,7 +110,10 @@ export default class Dapp extends Component { switch (app.type) { case 'local': - src = `${dappsUrl}/${app.id}/`; + console.log('app', app); + src = app.localUrl + ? `${app.localUrl}?appId=${app.id}` + : `${dappsUrl}/${app.id}/`; break; case 'network': diff --git a/js/src/inject.js b/js/src/inject.js index 7610a5ba7..8ffca9008 100644 --- a/js/src/inject.js +++ b/js/src/inject.js @@ -20,11 +20,29 @@ import Web3 from 'web3'; import web3extensions from './web3.extensions'; function initProvider () { - const parts = window.location.pathname.split('/'); - let appId = parts[1]; + const path = window.location.pathname.split('/'); + const qs = ((query) => { + if (!query) { + return {}; + } + + return query.split('&').reduce((result, combined) => { + const [name, value] = combined.split('=', 2); + + result[name] = !name + ? '' + : decodeURIComponent(value.replace(/\+/g, ' ')); + + return result; + }, {}); + })(window.location.search.substr(1)); + + let appId = path[1] || qs.appId; + + console.log('appId', appId, path, qs); if (appId === 'dapps') { - appId = parts[2]; + appId = path[2]; } else if (!Api.util.isHex(appId)) { appId = Api.util.sha3(appId); } From 73dcde65aa8ae23c29ddbe6b56af5af3abb38fea Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 20 Nov 2017 15:11:12 +0100 Subject: [PATCH 4/8] localUrl only from manifest --- dapps/js-glue/src/lib.rs.in | 1 - dapps/src/apps/app.rs | 2 +- dapps/src/apps/fs.rs | 2 +- dapps/src/endpoint.rs | 2 +- dapps/src/page/builtin.rs | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/dapps/js-glue/src/lib.rs.in b/dapps/js-glue/src/lib.rs.in index 460c6498b..99a253013 100644 --- a/dapps/js-glue/src/lib.rs.in +++ b/dapps/js-glue/src/lib.rs.in @@ -38,7 +38,6 @@ pub struct Info { pub author: &'static str, pub description: &'static str, pub icon_url: &'static str, - pub local_url: &'static str, } pub trait WebApp : Default + Send + Sync { diff --git a/dapps/src/apps/app.rs b/dapps/src/apps/app.rs index 9ced2438d..3b674aa15 100644 --- a/dapps/src/apps/app.rs +++ b/dapps/src/apps/app.rs @@ -27,7 +27,7 @@ pub struct App { #[serde(rename="iconUrl")] pub icon_url: String, #[serde(rename="localUrl")] - pub local_url: String, + pub local_url: Option, } impl App { diff --git a/dapps/src/apps/fs.rs b/dapps/src/apps/fs.rs index 888e32bbf..c581c2a8a 100644 --- a/dapps/src/apps/fs.rs +++ b/dapps/src/apps/fs.rs @@ -56,7 +56,7 @@ fn read_manifest(name: &str, mut path: PathBuf) -> EndpointInfo { version: "0.0.0".into(), author: "?".into(), icon_url: "icon.png".into(), - local_url: "".into(), + local_url: None, } }) } diff --git a/dapps/src/endpoint.rs b/dapps/src/endpoint.rs index 3a0b23a04..5491b76de 100644 --- a/dapps/src/endpoint.rs +++ b/dapps/src/endpoint.rs @@ -44,7 +44,7 @@ pub struct EndpointInfo { pub version: String, pub author: String, pub icon_url: String, - pub local_url: String, + pub local_url: Option, } pub type Endpoints = BTreeMap>; diff --git a/dapps/src/page/builtin.rs b/dapps/src/page/builtin.rs index b8c013cb3..0e93b1c68 100644 --- a/dapps/src/page/builtin.rs +++ b/dapps/src/page/builtin.rs @@ -132,7 +132,7 @@ impl From for EndpointInfo { description: info.description.into(), author: info.author.into(), icon_url: info.icon_url.into(), - local_url: info.local_url.into(), + local_url: None, version: info.version.into(), } } From e67b05e632964ef47fd108bfbcb5d3f7a6a9a8d8 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 21 Nov 2017 12:31:34 +0100 Subject: [PATCH 5/8] Use query-string for search parsing --- js/package-lock.json | 35 ++++++++++++++++++++++++++++++++--- js/package.json | 1 + js/src/inject.js | 19 +++---------------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/js/package-lock.json b/js/package-lock.json index cde7c67f8..f8613fe83 100644 --- a/js/package-lock.json +++ b/js/package-lock.json @@ -3147,6 +3147,11 @@ "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" }, + "decode-uri-component": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", + "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=" + }, "deep-eql": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", @@ -5942,6 +5947,17 @@ "loose-envify": "1.3.1", "query-string": "4.3.4", "warning": "3.0.0" + }, + "dependencies": { + "query-string": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-4.3.4.tgz", + "integrity": "sha1-u7aTucqRXCMlFbIosaArYJBD2+s=", + "requires": { + "object-assign": "4.1.1", + "strict-uri-encode": "1.1.0" + } + } } }, "hmac-drbg": { @@ -8261,6 +8277,18 @@ "prepend-http": "1.0.4", "query-string": "4.3.4", "sort-keys": "1.1.2" + }, + "dependencies": { + "query-string": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-4.3.4.tgz", + "integrity": "sha1-u7aTucqRXCMlFbIosaArYJBD2+s=", + "dev": true, + "requires": { + "object-assign": "4.1.1", + "strict-uri-encode": "1.1.0" + } + } } }, "npm-run-path": { @@ -9907,10 +9935,11 @@ "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" }, "query-string": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/query-string/-/query-string-4.3.4.tgz", - "integrity": "sha1-u7aTucqRXCMlFbIosaArYJBD2+s=", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-5.0.1.tgz", + "integrity": "sha512-aM+MkQClojlNiKkO09tiN2Fv8jM/L7GWIjG2liWeKljlOdOPNWr+bW3KQ+w5V/uKprpezC7fAsAMsJtJ+2rLKA==", "requires": { + "decode-uri-component": "0.2.0", "object-assign": "4.1.1", "strict-uri-encode": "1.1.0" } diff --git a/js/package.json b/js/package.json index 873720452..bbb992495 100644 --- a/js/package.json +++ b/js/package.json @@ -158,6 +158,7 @@ "lodash.uniq": "4.5.0", "material-ui": "0.16.5", "prop-types": "15.5.10", + "query-string": "5.0.1", "react": "15.6.1", "react-dom": "15.6.1", "react-intl": "2.1.5", diff --git a/js/src/inject.js b/js/src/inject.js index 8ffca9008..49982c8b2 100644 --- a/js/src/inject.js +++ b/js/src/inject.js @@ -15,29 +15,16 @@ // along with Parity. If not, see . import Api from '@parity/api'; +import qs from 'query-string'; import Web3 from 'web3'; import web3extensions from './web3.extensions'; function initProvider () { const path = window.location.pathname.split('/'); - const qs = ((query) => { - if (!query) { - return {}; - } + const query = qs.parse(window.location.search); - return query.split('&').reduce((result, combined) => { - const [name, value] = combined.split('=', 2); - - result[name] = !name - ? '' - : decodeURIComponent(value.replace(/\+/g, ' ')); - - return result; - }, {}); - })(window.location.search.substr(1)); - - let appId = path[1] || qs.appId; + let appId = path[1] || query.appId; console.log('appId', appId, path, qs); From 17df58b767b2874b6066e3e6ecfbba0551d69fef Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 21 Nov 2017 15:02:54 +0100 Subject: [PATCH 6/8] Add localUrl to serialization --- parity/dapps.rs | 1 + rpc/src/v1/types/dapps.rs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/parity/dapps.rs b/parity/dapps.rs index c15b16337..ebd8937eb 100644 --- a/parity/dapps.rs +++ b/parity/dapps.rs @@ -297,6 +297,7 @@ mod server { version: app.version, author: app.author, icon_url: app.icon_url, + local_url: app.local_url, }) .collect() } diff --git a/rpc/src/v1/types/dapps.rs b/rpc/src/v1/types/dapps.rs index fb4a868f0..907a6c2cc 100644 --- a/rpc/src/v1/types/dapps.rs +++ b/rpc/src/v1/types/dapps.rs @@ -31,6 +31,9 @@ pub struct LocalDapp { /// Dapp icon #[serde(rename="iconUrl")] pub icon_url: String, + /// Local development Url + #[serde(rename="localUrl")] + pub local_url: Option, } #[cfg(test)] @@ -40,7 +43,7 @@ mod tests { #[test] fn dapp_serialization() { - let s = r#"{"id":"skeleton","name":"Skeleton","description":"A skeleton dapp","version":"0.1","author":"Parity Technologies Ltd","iconUrl":"title.png"}"#; + let s = r#"{"id":"skeleton","name":"Skeleton","description":"A skeleton dapp","version":"0.1","author":"Parity Technologies Ltd","iconUrl":"title.png","localUrl":"http://localhost:5000"}"#; let dapp = LocalDapp { id: "skeleton".into(), @@ -49,6 +52,7 @@ mod tests { version: "0.1".into(), author: "Parity Technologies Ltd".into(), icon_url: "title.png".into(), + local_url: "http://localhost:5000".into(), }; let serialized = serde_json::to_string(&dapp).unwrap(); From 20f8943eb31e24fe33d396343e4a2d31333847de Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 21 Nov 2017 15:04:47 +0100 Subject: [PATCH 7/8] Cleanup debug info --- js/src/inject.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/js/src/inject.js b/js/src/inject.js index 49982c8b2..7bde1233d 100644 --- a/js/src/inject.js +++ b/js/src/inject.js @@ -26,8 +26,6 @@ function initProvider () { let appId = path[1] || query.appId; - console.log('appId', appId, path, qs); - if (appId === 'dapps') { appId = path[2]; } else if (!Api.util.isHex(appId)) { From e7543f656a44a4b86e13d2815739fc5ce5a3296c Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 21 Nov 2017 15:17:05 +0100 Subject: [PATCH 8/8] Remove debug log --- js/src/Dapp/dapp.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/src/Dapp/dapp.js b/js/src/Dapp/dapp.js index b1b62572a..6c5b8f74a 100644 --- a/js/src/Dapp/dapp.js +++ b/js/src/Dapp/dapp.js @@ -110,7 +110,6 @@ export default class Dapp extends Component { switch (app.type) { case 'local': - console.log('app', app); src = app.localUrl ? `${app.localUrl}?appId=${app.id}` : `${dappsUrl}/${app.id}/`;