-
Notifications
You must be signed in to change notification settings - Fork 504
/
index.tsx
77 lines (67 loc) · 1.94 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
import { actions } from 'data'
import { bindActionCreators, Dispatch } from 'redux'
import { BorrowMinMaxType } from 'data/types'
import { connect, ConnectedProps } from 'react-redux'
import { getData } from './selectors'
import {
LoanTransactionsType,
LoanType,
OfferType,
PaymentValue,
RatesType,
RemoteDataType,
SupportedCoinsType
} from 'core/types'
import { RootState } from 'data/rootReducer'
import DataError from 'components/DataError'
import Loading from './template.loading'
import React, { PureComponent } from 'react'
import Success from './template.success'
class RepayLoan extends PureComponent<Props> {
state = {}
componentDidMount () {
this.props.borrowActions.initializeRepayLoan('PAX')
}
handleRefresh = () => {
this.props.borrowActions.initializeRepayLoan('PAX')
}
handleSubmit = () => {
this.props.borrowActions.repayLoan()
}
render () {
return this.props.data.cata({
Success: val => (
<Success {...val} {...this.props} onSubmit={this.handleSubmit} />
),
Failure: e => (
<DataError message={{ message: e }} onClick={this.handleRefresh} />
),
Loading: () => <Loading />,
NotAsked: () => <Loading />
})
}
}
const mapStateToProps = (state: RootState): LinkStatePropsType => ({
data: getData(state)
})
const mapDispatchToProps = (dispatch: Dispatch) => ({
borrowActions: bindActionCreators(actions.components.borrow, dispatch)
})
const connector = connect(mapStateToProps, mapDispatchToProps)
type OwnProps = {
handleClose: () => void
loan: LoanType
offer: OfferType
}
export type SuccessStateType = {
limits: BorrowMinMaxType
loanTransactions: Array<LoanTransactionsType>
payment: PaymentValue
rates: RatesType
supportedCoins: SupportedCoinsType
}
type LinkStatePropsType = {
data: RemoteDataType<string | Error, SuccessStateType>
}
export type Props = OwnProps & ConnectedProps<typeof connector>
export default connector(RepayLoan)