This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Merged
Embeddable ParityBar #4222
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// Copyright 2015, 2016 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity. | ||
|
||
// Parity is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Parity 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 General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import 'babel-polyfill'; | ||
import 'whatwg-fetch'; | ||
|
||
import es6Promise from 'es6-promise'; | ||
es6Promise.polyfill(); | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { AppContainer } from 'react-hot-loader'; | ||
|
||
import injectTapEventPlugin from 'react-tap-event-plugin'; | ||
|
||
import SecureApi from '~/secureApi'; | ||
import ContractInstances from '~/contracts'; | ||
|
||
import { initStore } from '~/redux'; | ||
import ContextProvider from '~/ui/ContextProvider'; | ||
import muiTheme from '~/ui/Theme'; | ||
|
||
import { patchApi } from '~/util/tx'; | ||
import { setApi } from '~/redux/providers/apiActions'; | ||
|
||
import '~/environment'; | ||
|
||
import '../assets/fonts/Roboto/font.css'; | ||
import '../assets/fonts/RobotoMono/font.css'; | ||
|
||
injectTapEventPlugin(); | ||
|
||
import ParityBar from '~/views/ParityBar'; | ||
|
||
// Test transport (std transport should be provided as global object) | ||
class FakeTransport { | ||
constructor () { | ||
console.warn('Secure Transport not provided. Falling back to FakeTransport'); | ||
} | ||
|
||
execute (method, ...params) { | ||
console.log('Calling', method, params); | ||
return Promise.reject('not connected'); | ||
} | ||
|
||
on () { | ||
} | ||
} | ||
|
||
class FrameSecureApi extends SecureApi { | ||
constructor (transport) { | ||
super('', null, () => { | ||
return transport; | ||
}); | ||
} | ||
|
||
connect () { | ||
// Do nothing - this API does not need connecting | ||
this.emit('connecting'); | ||
// Fire connected event with some delay. | ||
setTimeout(() => { | ||
this.emit('connected'); | ||
}); | ||
} | ||
|
||
needsToken () { | ||
return false; | ||
} | ||
|
||
isConnecting () { | ||
return false; | ||
} | ||
|
||
isConnected () { | ||
return true; | ||
} | ||
} | ||
|
||
const api = new FrameSecureApi(window.secureTransport || new FakeTransport()); | ||
|
||
patchApi(api); | ||
ContractInstances.create(api); | ||
|
||
const store = initStore(api, null, true); | ||
|
||
store.dispatch({ type: 'initAll', api }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newline. |
||
store.dispatch(setApi(api)); | ||
|
||
window.secureApi = api; | ||
|
||
const app = ( | ||
<ParityBar dapp externalLink={ 'http://127.0.0.1:8180' } /> | ||
); | ||
const container = document.querySelector('#container'); | ||
|
||
ReactDOM.render( | ||
<AppContainer> | ||
<ContextProvider | ||
api={ api } | ||
muiTheme={ muiTheme } | ||
store={ store } | ||
> | ||
{ app } | ||
</ContextProvider> | ||
</AppContainer>, | ||
container | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,24 +25,27 @@ import CertificationsMiddleware from './providers/certifications/middleware'; | |
import ChainMiddleware from './providers/chainMiddleware'; | ||
import RegistryMiddleware from './providers/registry/middleware'; | ||
|
||
export default function (api, browserHistory) { | ||
export default function (api, browserHistory, forEmbed = false) { | ||
const errors = new ErrorsMiddleware(); | ||
const signer = new SignerMiddleware(api); | ||
const settings = new SettingsMiddleware(); | ||
const status = statusMiddleware(); | ||
const certifications = new CertificationsMiddleware(); | ||
const routeMiddleware = routerMiddleware(browserHistory); | ||
const chain = new ChainMiddleware(); | ||
const registry = new RegistryMiddleware(api); | ||
|
||
const middleware = [ | ||
settings.toMiddleware(), | ||
signer.toMiddleware(), | ||
errors.toMiddleware(), | ||
certifications.toMiddleware(), | ||
chain.toMiddleware(), | ||
registry | ||
chain.toMiddleware() | ||
]; | ||
|
||
if (!forEmbed) { | ||
const certifications = new CertificationsMiddleware().toMiddleware(); | ||
const registry = new RegistryMiddleware(api); | ||
|
||
middleware.push(certifications, registry); | ||
} | ||
|
||
const status = statusMiddleware(); | ||
const routeMiddleware = browserHistory ? routerMiddleware(browserHistory) : []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newline after. |
||
|
||
return middleware.concat(status, routeMiddleware, thunk); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,12 @@ | |
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import { uniq } from 'lodash'; | ||
import store from 'store'; | ||
|
||
import Api from './api'; | ||
import { LOG_KEYS, getLogger } from '~/config'; | ||
|
||
const log = getLogger(LOG_KEYS.Signer); | ||
const sysuiToken = window.localStorage.getItem('sysuiToken'); | ||
|
||
export default class SecureApi extends Api { | ||
_isConnecting = false; | ||
|
@@ -31,13 +31,18 @@ export default class SecureApi extends Api { | |
_dappsPort = 8080; | ||
_signerPort = 8180; | ||
|
||
constructor (url, nextToken) { | ||
const transport = new Api.Transport.Ws(url, sysuiToken, false); | ||
static getTransport (url, sysuiToken) { | ||
return new Api.Transport.Ws(url, sysuiToken, false); | ||
} | ||
|
||
constructor (url, nextToken, getTransport = SecureApi.getTransport) { | ||
const sysuiToken = store.get('sysuiToken'); | ||
const transport = getTransport(url, sysuiToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newline after. |
||
|
||
super(transport); | ||
|
||
this._url = url; | ||
|
||
// Try tokens from localstorage, from hash and 'initial' | ||
// Try tokens from localStorage, from hash and 'initial' | ||
this._tokens = uniq([sysuiToken, nextToken, 'initial']) | ||
.filter((token) => token) | ||
.map((token) => ({ value: token, tried: false })); | ||
|
@@ -308,7 +313,7 @@ export default class SecureApi extends Api { | |
} | ||
|
||
_saveToken (token) { | ||
window.localStorage.setItem('sysuiToken', token); | ||
store.set('sysuiToken', token); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newline after var declaration. ()Not trapped yet)