1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 18:41:38 +01:00
metamask-extension/ui/app/components/shift-list-item.js

203 lines
4.8 KiB
JavaScript
Raw Normal View History

2016-08-18 19:40:35 +02:00
const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')
const connect = require('react-redux').connect
const vreme = new (require('vreme'))
const explorerLink = require('../../lib/explorer-link')
const extension = require('../../../app/scripts/lib/extension')
const actions = require('../actions')
const addressSummary = require('../util').addressSummary
const CopyButton = require('./copyButton')
const EtherBalance = require('./eth-balance')
2016-08-19 00:20:26 +02:00
const Tooltip = require('./tooltip')
2016-08-18 19:40:35 +02:00
module.exports = connect(mapStateToProps)(ShiftListItem)
function mapStateToProps (state) {
return {}
}
inherits(ShiftListItem, Component)
2016-08-19 00:20:26 +02:00
2016-08-18 19:40:35 +02:00
function ShiftListItem () {
Component.call(this)
}
ShiftListItem.prototype.render = function () {
2016-08-18 19:40:35 +02:00
return (
2016-08-19 00:20:26 +02:00
h('.transaction-list-item.flex-row', {
style: {
2016-08-18 19:40:35 +02:00
paddingTop: '20px',
paddingBottom: '20px',
justifyContent: 'space-around',
alignItems: 'center',
},
}, [
h('div', {
style: {
2016-08-19 00:20:26 +02:00
width: '0px',
2016-08-18 19:40:35 +02:00
position: 'relative',
bottom: '19px',
},
}, [
h('img', {
2016-08-19 00:20:26 +02:00
src: 'https://info.shapeshift.io/sites/default/files/logo.png',
2016-08-18 19:40:35 +02:00
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
switch (props.response.status) {
case 'no_deposits':
return h('.flex-row', [
2016-08-19 00:20:26 +02:00
h(CopyButton, {
value: this.props.depositAddress,
2016-08-18 19:40:35 +02:00
}),
2016-08-19 00:20:26 +02:00
h(Tooltip, {
title: 'QR Code',
}, [
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',
},
}),
]),
2016-08-18 19:40:35 +02:00
])
case 'received':
return h('.flex-row')
case 'complete':
return h('.flex-row', [
2016-08-19 00:20:26 +02:00
h(CopyButton, {
value: this.props.response.transaction,
}),
h(EtherBalance, {
value: `${props.response.outgoingCoin}`,
width: '55px',
shorten: true,
needsParse: false,
incoming: true,
2016-08-19 00:20:26 +02:00
style: {
fontSize: '15px',
color: '#01888C',
2016-08-19 00:20:26 +02:00
},
}),
2016-08-18 19:40:35 +02:00
])
case 'failed':
return ''
default:
return ''
}
}
ShiftListItem.prototype.renderInfo = function () {
var props = this.props
switch (props.response.status) {
case 'no_deposits':
2016-08-19 00:20:26 +02:00
return h('.flex-column', {
style: {
width: '200px',
overflow: 'hidden',
},
}, [
2016-08-18 19:40:35 +02:00
h('div', {
2016-08-19 00:20:26 +02:00
style: {
fontSize: 'x-small',
color: '#ABA9AA',
width: '100%',
},
}, `${props.depositType} to ETH via ShapeShift`),
h('div', 'No deposits received'),
2016-08-18 19:40:35 +02:00
h('div', {
style: {
fontSize: 'x-small',
color: '#ABA9AA',
width: '100%',
},
}, formatDate(props.time)),
])
case 'received':
2016-08-19 00:20:26 +02:00
return h('.flex-column', {
style: {
width: '200px',
overflow: 'hidden',
},
}, [
2016-08-18 19:40:35 +02:00
h('div', {
2016-08-19 00:20:26 +02:00
style: {
fontSize: 'x-small',
color: '#ABA9AA',
width: '100%',
},
}, `${props.depositType} to ETH via ShapeShift`),
h('div', 'Conversion in progress'),
2016-08-18 19:40:35 +02:00
h('div', {
style: {
fontSize: 'x-small',
color: '#ABA9AA',
width: '100%',
},
}, formatDate(props.time)),
])
case 'complete':
2016-08-19 00:20:26 +02:00
var url = explorerLink(props.response.transaction, parseInt('1'))
2016-08-18 19:40:35 +02:00
return h('.flex-column.pointer', {
2016-08-19 00:20:26 +02:00
style: {
width: '200px',
overflow: 'hidden',
},
onClick: () => extension.tabs.create({
url,
}),
2016-08-18 19:40:35 +02:00
}, [
h('div', {
2016-08-19 00:20:26 +02:00
style: {
fontSize: 'x-small',
color: '#ABA9AA',
width: '100%',
},
}, 'From ShapeShift'),
h('div', formatDate(props.time)),
2016-08-18 19:40:35 +02:00
h('div', {
style: {
fontSize: 'x-small',
color: '#ABA9AA',
width: '100%',
},
}, addressSummary(props.response.transaction)),
])
case 'failed':
2016-08-19 00:20:26 +02:00
return h('span.error', '(Failed)')
2016-08-18 19:40:35 +02:00
default:
return ''
}
}