1 | import React from 'react'
|
2 |
|
3 | var JsBarcode = require('jsbarcode')
|
4 | var strings = require('./abcui-strings')
|
5 |
|
6 | var context = window.parent.abcContext
|
7 | var vendorName = window.parent.abcuiContext.vendorName
|
8 | var vendorImageUrl = window.parent.abcuiContext.vendorImageUrl
|
9 |
|
10 | var LoginWithAirbitz = React.createClass({
|
11 | getInitialState () {
|
12 | return {
|
13 | barcode: '',
|
14 | initiatingLogin: null,
|
15 | showLogin: false
|
16 | }
|
17 | },
|
18 | cancelRequest () {
|
19 | if (this.state.edgeLoginRequest) {
|
20 | this.state.edgeLoginRequest.cancelRequest()
|
21 | }
|
22 | },
|
23 | render () {
|
24 | this.buttonBouncerUrl = ''
|
25 | if (this.state.edgeLoginRequest) {
|
26 | this.buttonBouncerUrl = 'https://airbitz.co/elf/?address=' + this.state.edgeLoginRequest.id
|
27 | }
|
28 |
|
29 | return (
|
30 | <div className="row">
|
31 | <div className="col-sm-12 text-center">
|
32 | <div className="form-group center-block" style={{'width': '320px'}}>
|
33 | <a className="btn btn-block btn-social btn-facebook" onClick={this.onClick}>
|
34 | <img src="Airbitz-icon-white-transparent.png" style={{'width': '28px', 'padding': '4px'}} />
|
35 | {this.props.register ? strings.scan_barcode_to_register : strings.scan_barcode_to_signin}
|
36 | </a>
|
37 | </div>
|
38 | {this.state.initiatingLogin === null ? (
|
39 | <div className="form-group center-block" style={{'width': '240px'}}>
|
40 | <img id="barcode" style={{'width': '240px'}} />
|
41 | </div>) : (
|
42 | <div className="form-group text-center">
|
43 | Initiating Login for user<br />
|
44 | <b>{this.state.initiatingLogin}</b><br />
|
45 | <span className="glyphicon glyphicon-refresh glyphicon-refresh-animate" />
|
46 | </div>)}
|
47 | <div className="form-group center-block" >
|
48 | <label>OR</label>
|
49 | </div>
|
50 | </div>
|
51 | </div>
|
52 | )
|
53 | },
|
54 | componentDidMount () {
|
55 | var that = this
|
56 | context.requestEdgeLogin({
|
57 | displayName: vendorName,
|
58 | displayImageUrl: vendorImageUrl,
|
59 | onLogin: this.handleEdgeLogin,
|
60 | onProcessLogin: this.handleProcessLogin
|
61 | }, function (error, results) {
|
62 | if (error) {
|
63 |
|
64 | } else if (results) {
|
65 | JsBarcode('#barcode', results.id, {
|
66 | format: 'CODE128A',
|
67 | lineColor: '#333333',
|
68 | width: 6,
|
69 | height: 140,
|
70 | fontSize: 36,
|
71 | displayValue: true
|
72 | })
|
73 | that.setState({edgeLoginRequest: results})
|
74 | }
|
75 | })
|
76 | },
|
77 | handleProcessLogin (username) {
|
78 | this.setState({initiatingLogin: username})
|
79 | },
|
80 | handleEdgeLogin (error, account) {
|
81 | if (error) {
|
82 | console.log('Error on Edge Login')
|
83 | } else {
|
84 | this.props.onLogin(account)
|
85 | }
|
86 | },
|
87 | onClick () {
|
88 | window.open(this.buttonBouncerUrl, '_blank')
|
89 | }
|
90 | })
|
91 |
|
92 | module.exports = LoginWithAirbitz
|