aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/shift-list-item.js
blob: b87bf959e14ba1ce5c41ccc94b88d9934a3232d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
const inherits = require('util').inherits
const Component = require('react').Component
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
const connect = require('react-redux').connect
const vreme = new (require('vreme'))()
const explorerLink = require('etherscan-link').createExplorerLink
const actions = require('../actions')
const addressSummary = require('../util').addressSummary

const CopyButton = require('./copyButton')
const EthBalance = require('./eth-balance')
const Tooltip = require('./tooltip')


ShiftListItem.contextTypes = {
  t: PropTypes.func,
}

module.exports = connect(mapStateToProps)(ShiftListItem)


function mapStateToProps (state) {
  return {
    selectedAddress: state.metamask.selectedAddress,
    conversionRate: state.metamask.conversionRate,
    currentCurrency: state.metamask.currentCurrency,
  }
}

inherits(ShiftListItem, Component)

function ShiftListItem () {
  Component.call(this)
}

ShiftListItem.prototype.render = function () {
  return h('div.transaction-list-item.tx-list-clickable', {
    style: {
      paddingTop: '20px',
      paddingBottom: '20px',
      justifyContent: 'space-around',
      alignItems: 'center',
      flexDirection: 'row',
    },
  }, [
    h('div', {
      style: {
        width: '0px',
        position: 'relative',
        bottom: '19px',
      },
    }, [
      h('img', {
        src: 'https://info.shapeshift.io/sites/default/files/logo.png',
        style: {
          height: '35px',
          width: '132px',
          position: 'absolute',
          clip: 'rect(0px,23px,34px,0px)',
        },
      }),
    ]),

    this.renderInfo(),
    this.renderUtilComponents(),
  ])
}

function formatDate (date) {
  return vreme.format(new Date(date), 'March 16 2014 14:30')
}

ShiftListItem.prototype.renderUtilComponents = function () {
  var props = this.props
  const { conversionRate, currentCurrency } = props

  switch (props.response.status) {
    case 'no_deposits':
      return h('.flex-row', [
        h(CopyButton, {
          value: this.props.depositAddress,
        }),
        h(Tooltip, {
          title: this.context.t('qrCode'),
        }, [
          h('i.fa.fa-qrcode.pointer.pop-hover', {
            onClick: () => props.dispatch(actions.reshowQrCode(props.depositAddress, props.depositType)),
            style: {
              margin: '5px',
              marginLeft: '23px',
              marginRight: '12px',
              fontSize: '20px',
              color: '#F7861C',
            },
          }),
        ]),
      ])
    case 'received':
      return h('.flex-row')

    case 'complete':
      return h('.flex-row', [
        h(CopyButton, {
          value: this.props.response.transaction,
        }),
        h(EthBalance, {
          value: `${props.response.outgoingCoin}`,
          conversionRate,
          currentCurrency,
          width: '55px',
          shorten: true,
          needsParse: false,
          incoming: true,
          style: {
            fontSize: '15px',
            color: '#01888C',
          },
        }),
      ])

    case 'failed':
      return ''
    default:
      return ''
  }
}

ShiftListItem.prototype.renderInfo = function () {
  var props = this.props
  switch (props.response.status) {
    case 'no_deposits':
      return h('.flex-column', {
        style: {
          width: '200px',
          overflow: 'hidden',
        },
      }, [
        h('div', {
          style: {
            fontSize: 'x-small',
            color: '#ABA9AA',
            width: '100%',
          },
        }, this.context.t('toETHviaShapeShift', [props.depositType])),
        h('div', this.context.t('noDeposits')),
        h('div', {
          style: {
            fontSize: 'x-small',
            color: '#ABA9AA',
            width: '100%',
          },
        }, formatDate(props.time)),
      ])
    case 'received':
      return h('.flex-column', {
        style: {
          width: '200px',
          overflow: 'hidden',
        },
      }, [
        h('div', {
          style: {
            fontSize: 'x-small',
            color: '#ABA9AA',
            width: '100%',
          },
        }, this.context.t('toETHviaShapeShift', [props.depositType])),
        h('div', this.context.t('conversionProgress')),
        h('div', {
          style: {
            fontSize: 'x-small',
            color: '#ABA9AA',
            width: '100%',
          },
        }, formatDate(props.time)),
      ])
    case 'complete':
      var url = explorerLink(props.response.transaction, parseInt('1'))

      return h('.flex-column.pointer', {
        style: {
          width: '200px',
          overflow: 'hidden',
        },
        onClick: () => global.platform.openWindow({ url }),
      }, [
        h('div', {
          style: {
            fontSize: 'x-small',
            color: '#ABA9AA',
            width: '100%',
          },
        }, this.context.t('fromShapeShift')),
        h('div', formatDate(props.time)),
        h('div', {
          style: {
            fontSize: 'x-small',
            color: '#ABA9AA',
            width: '100%',
          },
        }, addressSummary(props.response.transaction)),
      ])

    case 'failed':
      return h('span.error', '(' + this.context.t('failed') + ')')
    default:
      return ''
  }
}