|
|
@ -1,19 +1,23 @@ |
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react' |
|
|
|
import React, { PureComponent } from 'react' |
|
|
|
import { connect } from 'react-redux' |
|
|
|
import styled from 'styled-components' |
|
|
|
import { ipcRenderer } from 'electron' |
|
|
|
|
|
|
|
import type { MapStateToProps } from 'react-redux' |
|
|
|
import type { Device } from 'types/common' |
|
|
|
|
|
|
|
import { getCurrentDevice } from 'reducers/devices' |
|
|
|
import { sendEvent } from 'renderer/events' |
|
|
|
|
|
|
|
import Box from 'components/base/Box' |
|
|
|
import QRCode from 'components/base/QRCode' |
|
|
|
import Icon from 'components/base/Icon' |
|
|
|
import Button from 'components/base/Button' |
|
|
|
import CopyToClipboard from 'components/base/CopyToClipboard' |
|
|
|
import Text from 'components/base/Text' |
|
|
|
import Icon from 'components/base/Icon' |
|
|
|
import Print from 'components/base/Print' |
|
|
|
|
|
|
|
type Props = { |
|
|
|
amount?: string, |
|
|
|
address: string, |
|
|
|
} |
|
|
|
import QRCode from 'components/base/QRCode' |
|
|
|
import Text from 'components/base/Text' |
|
|
|
|
|
|
|
export const AddressBox = styled(Box).attrs({ |
|
|
|
bg: 'cream', |
|
|
@ -22,7 +26,7 @@ export const AddressBox = styled(Box).attrs({ |
|
|
|
border-radius: 3px; |
|
|
|
border: 1px solid ${p => p.theme.colors.mouse}; |
|
|
|
cursor: text; |
|
|
|
text-alignitems: center; |
|
|
|
text-align: center; |
|
|
|
user-select: text; |
|
|
|
word-break: break-all; |
|
|
|
` |
|
|
@ -35,7 +39,7 @@ const Action = styled(Box).attrs({ |
|
|
|
fontSize: 0, |
|
|
|
})` |
|
|
|
font-weight: bold; |
|
|
|
text-alignitems: center; |
|
|
|
text-align: center; |
|
|
|
cursor: pointer; |
|
|
|
text-transform: uppercase; |
|
|
|
|
|
|
@ -44,44 +48,130 @@ const Action = styled(Box).attrs({ |
|
|
|
} |
|
|
|
` |
|
|
|
|
|
|
|
const ReceiveBox = ({ amount, address }: Props) => ( |
|
|
|
<Box flow={3}> |
|
|
|
<Box alignItems="center"> |
|
|
|
<QRCode size={150} data={`bitcoin:${address}${amount ? `?amount=${amount}` : ''}`} /> |
|
|
|
</Box> |
|
|
|
<Box alignItems="center" flow={2}> |
|
|
|
<Text fontSize={1}>{'Current address'}</Text> |
|
|
|
<AddressBox>{address}</AddressBox> |
|
|
|
</Box> |
|
|
|
<Box horizontal> |
|
|
|
<CopyToClipboard |
|
|
|
data={address} |
|
|
|
render={copy => ( |
|
|
|
<Action onClick={copy}> |
|
|
|
<Icon name="clone" /> |
|
|
|
<span>{'Copy'}</span> |
|
|
|
</Action> |
|
|
|
)} |
|
|
|
/> |
|
|
|
<Print |
|
|
|
data={{ address, amount }} |
|
|
|
render={(print, isLoading) => ( |
|
|
|
<Action onClick={print}> |
|
|
|
<Icon name="print" /> |
|
|
|
<span>{isLoading ? '...' : 'Print'}</span> |
|
|
|
const mapStateToProps: MapStateToProps<*, *, *> = state => ({ |
|
|
|
currentDevice: getCurrentDevice(state), |
|
|
|
}) |
|
|
|
|
|
|
|
type Props = { |
|
|
|
currentDevice: Device | null, |
|
|
|
address: string, |
|
|
|
amount?: string, |
|
|
|
path: string, |
|
|
|
} |
|
|
|
|
|
|
|
type State = { |
|
|
|
isVerified: null | boolean, |
|
|
|
isDisplay: boolean, |
|
|
|
} |
|
|
|
|
|
|
|
const defaultState = { |
|
|
|
isVerified: null, |
|
|
|
isDisplay: false, |
|
|
|
} |
|
|
|
|
|
|
|
class ReceiveBox extends PureComponent<Props, State> { |
|
|
|
static defaultProps = { |
|
|
|
amount: undefined, |
|
|
|
} |
|
|
|
|
|
|
|
state = { |
|
|
|
...defaultState, |
|
|
|
} |
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
ipcRenderer.on('msg', this.handleMsgEvent) |
|
|
|
} |
|
|
|
|
|
|
|
componentWillUnmount() { |
|
|
|
ipcRenderer.removeListener('msg', this.handleMsgEvent) |
|
|
|
this.setState({ |
|
|
|
...defaultState, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
handleMsgEvent = (e, { type }) => { |
|
|
|
if (type === 'wallet.verifyAddress.success') { |
|
|
|
this.setState({ |
|
|
|
isVerified: true, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
if (type === 'wallet.verifyAddress.fail') { |
|
|
|
this.setState({ |
|
|
|
isVerified: false, |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
handleVerifyAddress = () => { |
|
|
|
const { currentDevice, path } = this.props |
|
|
|
|
|
|
|
if (currentDevice !== null) { |
|
|
|
sendEvent('usb', 'wallet.verifyAddress', { |
|
|
|
pathDevice: currentDevice.path, |
|
|
|
path, |
|
|
|
}) |
|
|
|
|
|
|
|
this.setState({ |
|
|
|
isDisplay: true, |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
render() { |
|
|
|
const { amount, address } = this.props |
|
|
|
const { isVerified, isDisplay } = this.state |
|
|
|
|
|
|
|
if (!isDisplay) { |
|
|
|
return ( |
|
|
|
<Box grow alignItems="center" justifyContent="center"> |
|
|
|
<Button onClick={this.handleVerifyAddress}>Display address on device</Button> |
|
|
|
</Box> |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
return ( |
|
|
|
<Box flow={3}> |
|
|
|
<Box> |
|
|
|
isVerified:{' '} |
|
|
|
{isVerified === null |
|
|
|
? 'not yet...' |
|
|
|
: isVerified === true ? 'ok!' : '/!\\ contact support'} |
|
|
|
</Box> |
|
|
|
<Box alignItems="center"> |
|
|
|
<QRCode size={150} data={`bitcoin:${address}${amount ? `?amount=${amount}` : ''}`} /> |
|
|
|
</Box> |
|
|
|
<Box alignItems="center" flow={2}> |
|
|
|
<Text fontSize={1}>{'Current address'}</Text> |
|
|
|
<AddressBox>{address}</AddressBox> |
|
|
|
</Box> |
|
|
|
<Box horizontal> |
|
|
|
<CopyToClipboard |
|
|
|
data={address} |
|
|
|
render={copy => ( |
|
|
|
<Action onClick={copy}> |
|
|
|
<Icon name="clone" /> |
|
|
|
<span>{'Copy'}</span> |
|
|
|
</Action> |
|
|
|
)} |
|
|
|
/> |
|
|
|
<Print |
|
|
|
data={{ address, amount }} |
|
|
|
render={(print, isLoading) => ( |
|
|
|
<Action onClick={print}> |
|
|
|
<Icon name="print" /> |
|
|
|
<span>{isLoading ? '...' : 'Print'}</span> |
|
|
|
</Action> |
|
|
|
)} |
|
|
|
/> |
|
|
|
<Action> |
|
|
|
<Icon name="share-square" /> |
|
|
|
<span>{'Share'}</span> |
|
|
|
</Action> |
|
|
|
)} |
|
|
|
/> |
|
|
|
<Action> |
|
|
|
<Icon name="share-square" /> |
|
|
|
<span>{'Share'}</span> |
|
|
|
</Action> |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|
) |
|
|
|
|
|
|
|
ReceiveBox.defaultProps = { |
|
|
|
amount: undefined, |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export default ReceiveBox |
|
|
|
export default connect(mapStateToProps, null)(ReceiveBox) |
|
|
|