-
Notifications
You must be signed in to change notification settings - Fork 504
/
index.tsx
94 lines (77 loc) · 2.77 KB
/
index.tsx
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
import { bindActionCreators, Dispatch } from 'redux'
import { connect, ConnectedProps } from 'react-redux'
import { includes } from 'ramda'
import React, { PureComponent } from 'react'
import { actions } from 'data'
import { CoinType, FiatType, RemoteDataType } from 'core/types'
import { InterestStepMetadata } from 'data/types'
import DataError from 'components/DataError'
import { getData } from './selectors'
import AccountSummary from './template.success'
import Currencies from 'core/exchange/currencies'
import Loading from './template.loading'
import Unsupported from './template.unsupported'
class AccountSummaryContainer extends PureComponent<Props> {
state = {}
componentDidMount () {
this.handleFetchInterestLimits()
}
handleDepositClick = () => {
const { coin } = this.props
this.props.interestActions.showInterestModal('DEPOSIT', coin)
}
handleFetchInterestLimits = () => {
const { coin } = this.props
const { walletCurrency } = this.props.data.getOrElse({
walletCurrency: 'GBP' as FiatType
} as SuccessStateType)
this.props.interestActions.fetchInterestLimits(coin, walletCurrency)
}
handleRefresh = () => {
const { coin } = this.props
this.props.interestActions.showInterestModal('ACCOUNT_SUMMARY', coin)
}
render () {
const { data } = this.props
const unsupportedCurrencies = [Currencies.TWD.code, Currencies.CLP.code]
return data.cata({
Success: val =>
includes(val.walletCurrency, unsupportedCurrencies) ? (
<Unsupported {...val} {...this.props} />
) : (
<AccountSummary
{...val}
{...this.props}
handleDepositClick={this.handleDepositClick}
/>
),
Failure: () => <DataError onClick={this.handleRefresh} />,
Loading: () => <Loading />,
NotAsked: () => <Loading />
})
}
}
const mapStateToProps = (state): LinkStatePropsType => ({
data: getData(state)
})
const mapDispatchToProps = (dispatch: Dispatch): LinkDispatchPropsType => ({
interestActions: bindActionCreators(actions.components.interest, dispatch),
simpleBuyActions: bindActionCreators(actions.components.simpleBuy, dispatch)
})
const connector = connect(mapStateToProps, mapDispatchToProps)
export type OwnProps = {
coin: CoinType
handleClose: () => void
handleSBClick: (string) => void
stepMetadata: InterestStepMetadata
}
export type LinkDispatchPropsType = {
interestActions: typeof actions.components.interest
simpleBuyActions: typeof actions.components.simpleBuy
}
export type SuccessStateType = ReturnType<typeof getData>['data']
type LinkStatePropsType = {
data: RemoteDataType<string | Error, SuccessStateType>
}
type Props = OwnProps & ConnectedProps<typeof connector>
export default connector(AccountSummaryContainer)