This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
/
ConfirmationCell.js
75 lines (62 loc) · 2.1 KB
/
ConfirmationCell.js
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
// @flow
import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import styled from 'styled-components'
import { createStructuredSelector } from 'reselect'
import type { TokenAccount, Account, Operation } from '@ledgerhq/live-common/lib/types'
import { getMainAccount } from '@ledgerhq/live-common/lib/account'
import { getOperationAmountNumber } from '@ledgerhq/live-common/lib/operation'
import type { T } from 'types/common'
import { confirmationsNbForCurrencySelector, marketIndicatorSelector } from 'reducers/settings'
import { getMarketColor } from 'styles/helpers'
import Box from 'components/base/Box'
import ConfirmationCheck from './ConfirmationCheck'
const mapStateToProps = createStructuredSelector({
confirmationsNb: (state, { account, parentAccount }) =>
confirmationsNbForCurrencySelector(state, {
currency: getMainAccount(account, parentAccount).currency,
}),
marketIndicator: marketIndicatorSelector,
})
const Cell = styled(Box).attrs(() => ({
px: 4,
horizontal: true,
alignItems: 'center',
}))`
width: 44px;
`
type Props = {
account: Account | TokenAccount,
parentAccount?: Account,
confirmationsNb: number,
marketIndicator: string,
t: T,
operation: Operation,
}
class ConfirmationCell extends PureComponent<Props> {
render() {
const { account, parentAccount, confirmationsNb, t, operation, marketIndicator } = this.props
const mainAccount = getMainAccount(account, parentAccount)
const amount = getOperationAmountNumber(operation)
const isNegative = amount.isNegative()
const isConfirmed =
(operation.blockHeight ? mainAccount.blockHeight - operation.blockHeight : 0) >
confirmationsNb
const marketColor = getMarketColor({
marketIndicator,
isNegative,
})
return (
<Cell align="center" justify="flex-start">
<ConfirmationCheck
type={operation.type}
isConfirmed={isConfirmed}
marketColor={marketColor}
hasFailed={operation.hasFailed}
t={t}
/>
</Cell>
)
}
}
export default connect(mapStateToProps)(ConfirmationCell)