import React, { Component } from 'react' import PropTypes from 'prop-types' import classnames from 'classnames' import {qrcode} from 'qrcode-npm' import {connect} from 'react-redux' import {shapeShiftSubview, pairUpdate, buyWithShapeShift} from '../../../../ui/app/actions' import {isValidAddress} from '../../../../ui/app/util' export class ShapeShiftForm extends Component { static propTypes = { selectedAddress: PropTypes.string.isRequired, btnClass: PropTypes.string.isRequired, tokenExchangeRates: PropTypes.object.isRequired, coinOptions: PropTypes.object.isRequired, shapeShiftSubview: PropTypes.func.isRequired, pairUpdate: PropTypes.func.isRequired, buyWithShapeShift: PropTypes.func.isRequired, }; state = { depositCoin: 'btc', refundAddress: '', showQrCode: false, depositAddress: '', errorMessage: '', isLoading: false, }; componentWillMount () { this.props.shapeShiftSubview() } onCoinChange = e => { const coin = e.target.value this.setState({ depositCoin: coin, errorMessage: '', }) this.props.pairUpdate(coin) } onBuyWithShapeShift = () => { this.setState({ isLoading: true, showQrCode: true, }) const { buyWithShapeShift, selectedAddress: withdrawal, } = this.props const { refundAddress: returnAddress, depositCoin, } = this.state const pair = `${depositCoin}_eth` const data = { withdrawal, pair, returnAddress, // Public api key 'apiKey': '803d1f5df2ed1b1476e4b9e6bcd089e34d8874595dda6a23b67d93c56ea9cc2445e98a6748b219b2b6ad654d9f075f1f1db139abfa93158c04e825db122c14b6', } if (isValidAddress(withdrawal)) { buyWithShapeShift(data) .then(d => this.setState({ showQrCode: true, depositAddress: d.deposit, isLoading: false, })) .catch(() => this.setState({ showQrCode: false, errorMessage: 'Invalid Request', isLoading: false, })) } } renderMetadata (label, value) { return (