-
Notifications
You must be signed in to change notification settings - Fork 312
/
Claim.jsx
61 lines (52 loc) · 1.57 KB
/
Claim.jsx
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
// @flow
import React, { Component } from 'react'
import Button from '../../components/Button'
import Tooltip from '../../components/Tooltip'
import { formatGAS } from '../../core/formatters'
import { toBigNumber } from '../../core/math'
import ClaimIcon from '../../assets/icons/claim.svg'
type Props = {
className: ?string,
doGasClaim: Function,
disableClaimButton: boolean,
claimAmount: string,
isWatchOnly: boolean,
}
export default class Claim extends Component<Props> {
intervalId: ?number
render() {
const { className } = this.props
const disabled = this.isDisabled()
return (
<div>
<Tooltip title={this.getTooltip()} disabled={!disabled}>
<Button
id="claim"
className={className}
disabled={disabled}
primary
renderIcon={ClaimIcon}
onClick={this.handleClaim}
>
Claim {this.getFormattedAmount()} GAS
</Button>
</Tooltip>
</div>
)
}
handleClaim = () => {
this.props.doGasClaim()
}
isDisabled = () => {
const { claimAmount, disableClaimButton, isWatchOnly } = this.props
return disableClaimButton || toBigNumber(claimAmount).eq(0) || isWatchOnly
}
getFormattedAmount = () => formatGAS(this.props.claimAmount)
getTooltip = () => {
const { claimAmount, isWatchOnly } = this.props
if (isWatchOnly) return 'You cannot claim GAS in watch mode.'
return toBigNumber(claimAmount).eq(0)
? 'Address must hold NEO in order to claim GAS'
: 'You can claim GAS once every 5 minutes'
}
}