// 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 . import React, { Component, PropTypes } from 'react'; import ReactDOM from 'react-dom'; import { Link } from 'react-router'; import { connect } from 'react-redux'; import { throttle } from 'lodash'; import store from 'store'; import { CancelIcon, FingerprintIcon } from '~/ui/Icons'; import { Badge, Button, ContainerTitle, ParityBackground } from '~/ui'; import { Embedded as Signer } from '../Signer'; import DappsStore from '~/views/Dapps/dappsStore'; import imagesEthcoreBlock from '!url-loader!../../../assets/images/parity-logo-white-no-text.svg'; import styles from './parityBar.css'; const LS_STORE_KEY = '_parity::parityBar'; const DEFAULT_POSITION = { right: '1em', bottom: 0 }; class ParityBar extends Component { app = null; measures = null; moving = false; static contextTypes = { api: PropTypes.object.isRequired }; static propTypes = { dapp: PropTypes.bool, externalLink: PropTypes.string, pending: PropTypes.array }; state = { moving: false, opened: false, position: DEFAULT_POSITION }; constructor (props) { super(props); this.debouncedMouseMove = throttle( this._onMouseMove, 40, { leading: true, trailing: true } ); } componentWillMount () { const { api } = this.context; // Hook to the dapp loaded event to position the // Parity Bar accordingly DappsStore.get(api).on('loaded', (app) => { this.app = app; this.loadPosition(); }); } componentWillReceiveProps (nextProps) { const count = this.props.pending.length; const newCount = nextProps.pending.length; if (count === newCount) { return; } if (count < newCount) { this.setOpened(true); } else if (newCount === 0 && count === 1) { this.setOpened(false); } } setOpened (opened) { this.setState({ opened }); if (!this.bar) { return; } // Fire up custom even to support having parity bar iframed. const event = new CustomEvent('parity.bar.visibility', { bubbles: true, detail: { opened } }); this.bar.dispatchEvent(event); } onRef = (element) => { this.bar = element; } render () { const { moving, opened, position } = this.state; const content = opened ? this.renderExpanded() : this.renderBar(); const containerClassNames = opened ? [ styles.overlay ] : [ styles.bar ]; if (!opened && moving) { containerClassNames.push(styles.moving); } const parityBgClassName = opened ? styles.expanded : styles.corner; const parityBgClassNames = [ parityBgClassName, styles.parityBg ]; if (moving) { parityBgClassNames.push(styles.moving); } const parityBgStyle = { ...position }; // Open the Signer at one of the four corners // of the screen if (opened) { // Set at top or bottom of the screen if (position.top !== undefined) { parityBgStyle.top = 0; } else { parityBgStyle.bottom = 0; } // Set at left or right of the screen if (position.left !== undefined) { parityBgStyle.left = '1em'; } else { parityBgStyle.right = '1em'; } } return (
{ content }
); } renderBar () { const { dapp } = this.props; if (!dapp) { return null; } const parityIcon = ( ); const parityButton = (