Fixing UI issues after UI server refactor (#5710)
* Self-sufficient secureApi. * Updating embed. * Linting issues.
This commit is contained in:
parent
e89d49d958
commit
8a364bbfaa
@ -96,4 +96,8 @@ export default class Http extends JsonRpcBase {
|
|||||||
.then(nextTimeout)
|
.then(nextTimeout)
|
||||||
.catch(nextTimeout);
|
.catch(nextTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set url (url) {
|
||||||
|
this._url = url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,6 +249,10 @@ export default class Ws extends JsonRpcBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set url (url) {
|
||||||
|
this._url = url;
|
||||||
|
}
|
||||||
|
|
||||||
get token () {
|
get token () {
|
||||||
return this._token;
|
return this._token;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ class FakeTransport {
|
|||||||
|
|
||||||
class FrameSecureApi extends SecureApi {
|
class FrameSecureApi extends SecureApi {
|
||||||
constructor (transport) {
|
constructor (transport) {
|
||||||
super('', null, () => {
|
super(transport.uiUrl, null, () => {
|
||||||
return transport;
|
return transport;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -91,7 +91,11 @@ class FrameSecureApi extends SecureApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const api = new FrameSecureApi(window.secureTransport || new FakeTransport());
|
const transport = window.secureTransport || new FakeTransport();
|
||||||
|
const uiUrl = transport.uiUrl || 'http://127.0.0.1:8180';
|
||||||
|
|
||||||
|
transport.uiUrl = uiUrl.replace('http://', '').replace('https://', '');
|
||||||
|
const api = new FrameSecureApi(transport);
|
||||||
|
|
||||||
patchApi(api);
|
patchApi(api);
|
||||||
ContractInstances.create(api);
|
ContractInstances.create(api);
|
||||||
@ -104,7 +108,7 @@ store.dispatch(setApi(api));
|
|||||||
window.secureApi = api;
|
window.secureApi = api;
|
||||||
|
|
||||||
const app = (
|
const app = (
|
||||||
<ParityBar dapp externalLink={ 'http://127.0.0.1:8180' } />
|
<ParityBar dapp externalLink={ uiUrl } />
|
||||||
);
|
);
|
||||||
const container = document.querySelector('#container');
|
const container = document.querySelector('#container');
|
||||||
|
|
||||||
|
@ -53,7 +53,6 @@ if (process.env.NODE_ENV === 'development') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AUTH_HASH = '#/auth?';
|
const AUTH_HASH = '#/auth?';
|
||||||
const parityUrl = process.env.PARITY_URL || '127.0.0.1:8546';
|
|
||||||
|
|
||||||
let token = null;
|
let token = null;
|
||||||
|
|
||||||
@ -61,7 +60,8 @@ if (window.location.hash && window.location.hash.indexOf(AUTH_HASH) === 0) {
|
|||||||
token = qs.parse(window.location.hash.substr(AUTH_HASH.length)).token;
|
token = qs.parse(window.location.hash.substr(AUTH_HASH.length)).token;
|
||||||
}
|
}
|
||||||
|
|
||||||
const api = new SecureApi(parityUrl, token);
|
const uiUrl = window.location.host;
|
||||||
|
const api = new SecureApi(uiUrl, token);
|
||||||
|
|
||||||
patchApi(api);
|
patchApi(api);
|
||||||
loadSender(api);
|
loadSender(api);
|
||||||
|
@ -26,14 +26,22 @@ export default class SecureApi extends Api {
|
|||||||
_isConnecting = false;
|
_isConnecting = false;
|
||||||
_needsToken = false;
|
_needsToken = false;
|
||||||
_tokens = [];
|
_tokens = [];
|
||||||
|
_uiApi = null;
|
||||||
|
|
||||||
_dappsUrl = null;
|
_dappsUrl = null;
|
||||||
_wsUrl = null;
|
_wsUrl = null;
|
||||||
|
_url = null;
|
||||||
|
|
||||||
static getTransport (url, sysuiToken, protocol) {
|
static getTransport (url, sysuiToken, protocol) {
|
||||||
|
const transportUrl = SecureApi.transportUrl(url, protocol);
|
||||||
|
|
||||||
|
return new Api.Transport.Ws(transportUrl, sysuiToken, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static transportUrl (url, protocol) {
|
||||||
const proto = protocol() === 'https:' ? 'wss:' : 'ws:';
|
const proto = protocol() === 'https:' ? 'wss:' : 'ws:';
|
||||||
|
|
||||||
return new Api.Transport.Ws(`${proto}//${url}`, sysuiToken, false);
|
return `${proto}//${url}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a protocol with `:` at the end.
|
// Returns a protocol with `:` at the end.
|
||||||
@ -41,14 +49,16 @@ export default class SecureApi extends Api {
|
|||||||
return window.location.protocol;
|
return window.location.protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor (url, nextToken, getTransport = SecureApi.getTransport, protocol = SecureApi.protocol) {
|
constructor (uiUrl, nextToken, getTransport = SecureApi.getTransport, protocol = SecureApi.protocol) {
|
||||||
const sysuiToken = store.get('sysuiToken');
|
const sysuiToken = store.get('sysuiToken');
|
||||||
const transport = getTransport(url, sysuiToken, protocol);
|
const transport = getTransport(uiUrl, sysuiToken, protocol);
|
||||||
|
|
||||||
super(transport);
|
super(transport);
|
||||||
|
|
||||||
this._wsUrl = url;
|
|
||||||
this.protocol = protocol;
|
this.protocol = protocol;
|
||||||
|
this._url = uiUrl;
|
||||||
|
this._uiApi = new Api(new Api.Transport.Http(`${this.protocol()}//${this._url}/rpc`, 0), false);
|
||||||
|
this._wsUrl = uiUrl;
|
||||||
// Try tokens from localStorage, from hash and 'initial'
|
// Try tokens from localStorage, from hash and 'initial'
|
||||||
this._tokens = uniq([sysuiToken, nextToken, 'initial'])
|
this._tokens = uniq([sysuiToken, nextToken, 'initial'])
|
||||||
.filter((token) => token)
|
.filter((token) => token)
|
||||||
@ -116,26 +126,6 @@ export default class SecureApi extends Api {
|
|||||||
return this._transport.token;
|
return this._transport.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure the current API with the given values
|
|
||||||
* (`signerPort`, `dappsInterface`, `dappsPort`, ...)
|
|
||||||
*/
|
|
||||||
configure (configuration) {
|
|
||||||
const { dappsInterface, dappsPort, signerPort, wsPort } = configuration;
|
|
||||||
|
|
||||||
if (dappsInterface) {
|
|
||||||
this._dappsUrl = `${dappsInterface}:${this._dappsAddress.port}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dappsPort) {
|
|
||||||
this._dappsUrl = `${this.hostname}:${dappsPort}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (signerPort || wsPort) {
|
|
||||||
this._wsUrl = `${this.hostname}:${signerPort || wsPort}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
connect () {
|
connect () {
|
||||||
if (this._isConnecting) {
|
if (this._isConnecting) {
|
||||||
return;
|
return;
|
||||||
@ -189,7 +179,7 @@ export default class SecureApi extends Api {
|
|||||||
* otherwise (HEAD request to the Node)
|
* otherwise (HEAD request to the Node)
|
||||||
*/
|
*/
|
||||||
isNodeUp () {
|
isNodeUp () {
|
||||||
return fetch(`${this.protocol()}//${this._wsUrl}`, { method: 'HEAD', mode: 'no-cors' })
|
return fetch(`${this.protocol()}//${this._url}/api/ping`, { method: 'HEAD' })
|
||||||
.then(
|
.then(
|
||||||
(r) => r.status === 200,
|
(r) => r.status === 200,
|
||||||
() => false
|
() => false
|
||||||
@ -240,7 +230,6 @@ export default class SecureApi extends Api {
|
|||||||
// If correct and valid token, wait until the Node is ready
|
// If correct and valid token, wait until the Node is ready
|
||||||
// and resolve as connected
|
// and resolve as connected
|
||||||
return this._waitUntilNodeReady()
|
return this._waitUntilNodeReady()
|
||||||
.then(() => this._fetchSettings())
|
|
||||||
.then(() => true);
|
.then(() => true);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@ -259,11 +248,16 @@ export default class SecureApi extends Api {
|
|||||||
// Sanitize the token first
|
// Sanitize the token first
|
||||||
const token = this._sanitiseToken(_token);
|
const token = this._sanitiseToken(_token);
|
||||||
|
|
||||||
// Update the token in the transport layer
|
const connectPromise = this._fetchSettings()
|
||||||
this.transport.updateToken(token, false);
|
.then(() => {
|
||||||
log.debug('connecting with token', token);
|
// Update the URL and token in the transport layer
|
||||||
|
this.transport.url = SecureApi.transportUrl(this._wsUrl, this.protocol);
|
||||||
|
this.transport.updateToken(token, false);
|
||||||
|
|
||||||
const connectPromise = this.transport.connect()
|
log.debug('connecting with token', token);
|
||||||
|
|
||||||
|
return this.transport.connect();
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
log.debug('connected with', token);
|
log.debug('connected with', token);
|
||||||
|
|
||||||
@ -318,12 +312,12 @@ export default class SecureApi extends Api {
|
|||||||
_fetchSettings () {
|
_fetchSettings () {
|
||||||
return Promise
|
return Promise
|
||||||
.all([
|
.all([
|
||||||
this.parity.dappsUrl(),
|
this._uiApi.parity.dappsUrl(),
|
||||||
this.parity.wsUrl()
|
this._uiApi.parity.wsUrl()
|
||||||
])
|
])
|
||||||
.then(([dappsUrl, wsUrl]) => {
|
.then(([dappsUrl, wsUrl]) => {
|
||||||
this._dappsUrl = dappsUrl;
|
this._dappsUrl = dappsUrl;
|
||||||
this._wsUrl = dappsUrl;
|
this._wsUrl = wsUrl;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -762,10 +762,6 @@ impl Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn ui_hosts(&self) -> Option<Vec<String>> {
|
fn ui_hosts(&self) -> Option<Vec<String>> {
|
||||||
if self.args.flag_ui_no_validation {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.hosts(&self.args.flag_ui_hosts, &self.ui_interface())
|
self.hosts(&self.args.flag_ui_hosts, &self.ui_interface())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -774,6 +770,10 @@ impl Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn ws_hosts(&self) -> Option<Vec<String>> {
|
fn ws_hosts(&self) -> Option<Vec<String>> {
|
||||||
|
if self.args.flag_ui_no_validation {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
self.hosts(&self.args.flag_ws_hosts, &self.ws_interface())
|
self.hosts(&self.args.flag_ws_hosts, &self.ws_interface())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1486,13 +1486,15 @@ mod tests {
|
|||||||
port: 8180,
|
port: 8180,
|
||||||
hosts: Some(vec![]),
|
hosts: Some(vec![]),
|
||||||
});
|
});
|
||||||
|
assert!(conf0.ws_config().unwrap().hosts.is_some());
|
||||||
assert_eq!(conf1.directories().signer, "signer".to_owned());
|
assert_eq!(conf1.directories().signer, "signer".to_owned());
|
||||||
assert_eq!(conf1.ui_config(), UiConfiguration {
|
assert_eq!(conf1.ui_config(), UiConfiguration {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
interface: "127.0.0.1".into(),
|
interface: "127.0.0.1".into(),
|
||||||
port: 8180,
|
port: 8180,
|
||||||
hosts: None,
|
hosts: Some(vec![]),
|
||||||
});
|
});
|
||||||
|
assert_eq!(conf1.ws_config().unwrap().hosts, None);
|
||||||
assert_eq!(conf2.directories().signer, "signer".to_owned());
|
assert_eq!(conf2.directories().signer, "signer".to_owned());
|
||||||
assert_eq!(conf2.ui_config(), UiConfiguration {
|
assert_eq!(conf2.ui_config(), UiConfiguration {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
@ -1500,6 +1502,7 @@ mod tests {
|
|||||||
port: 3123,
|
port: 3123,
|
||||||
hosts: Some(vec![]),
|
hosts: Some(vec![]),
|
||||||
});
|
});
|
||||||
|
assert!(conf2.ws_config().unwrap().hosts.is_some());
|
||||||
assert_eq!(conf3.directories().signer, "signer".to_owned());
|
assert_eq!(conf3.directories().signer, "signer".to_owned());
|
||||||
assert_eq!(conf3.ui_config(), UiConfiguration {
|
assert_eq!(conf3.ui_config(), UiConfiguration {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
@ -1507,6 +1510,7 @@ mod tests {
|
|||||||
port: 8180,
|
port: 8180,
|
||||||
hosts: Some(vec![]),
|
hosts: Some(vec![]),
|
||||||
});
|
});
|
||||||
|
assert!(conf3.ws_config().unwrap().hosts.is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user