/
depositPage.js
97 lines (83 loc) · 3.46 KB
/
depositPage.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import BigNumber from 'bignumber.js'
import { push } from 'connected-react-router'
import {
getTokenDomain,
getAccountBalancesDomain,
getTokenPairsDomain,
getAccountDomain,
getDepositDomain,
} from '../domains'
import * as actionCreators from '../actions/depositPage'
import { amountPrecision } from '../../config/tokens'
export default function depositPageSelector(state: State) {
const accountDomain = getAccountDomain(state)
const userAddress = accountDomain.address()
const authenticated = accountDomain.authenticated()
const tokensBalance = getAccountBalancesDomain(state).balances()
const tokenPairs = getTokenPairsDomain(state).getPairs()
let tokens = getTokenDomain(state).tokens()
tokens = tokens
.filter(token => token.verified)
.map((token, index) => {
const pairs = tokenPairs.filter(pair => pair.includes(token.symbol))
return {...token, ...tokensBalance[token.symbol], rank: index + 1, pairs}
})
let depositHistory = JSON.parse(JSON.stringify(getDepositDomain(state).getData()))
depositHistory = depositHistory.map(deposit => {
const token = tokens.find(token => token.symbol === deposit.coin)
const decimals = token ? token.decimals : amountPrecision
deposit.amount = BigNumber(deposit.amount).dividedBy(10**decimals).toFixed(8)
deposit.scanUrl = token.explorerUrl
deposit.tokenConfirmations = token.confirmations
return deposit
})
const total = getDepositDomain(state).getTotal()
return {
tokens,
userAddress,
depositHistory,
authenticated,
total,
}
}
export const getBridgeTokenConfig = (): ThunkAction => {
return async (dispatch, getState, { api }) => {
const { swapCoin } = await api.getBridgeTokenConfig()
dispatch(actionCreators.updateBridgeTokenConfig(swapCoin))
}
}
export const getBridgeDepositAddress = (payload): ThunkAction => {
return async (dispatch, getState, { api }) => {
const { address, coin } = await api.getBridgeDepositAddress(payload)
dispatch(actionCreators.updateBridgeDepositAddress({ depositAddress: address, coin }))
}
}
export const getBridgeDepositHistory = (address: string, page, limit): ThunkAction => {
return async (dispatch, getState, { api }) => {
const result = await api.getBridgeDepositHistory(address, page, limit)
const data = result.Data.map(item => {
return {
coin: item.InTx.CoinType,
amount: item.InTx.Amount,
status: item.InTx.Status.toUpperCase() === 'DEPOSITED' ? 'COMPLETED' : 'PROCESSING',
txHash: item.InTx.Hash,
confirmations: item.InTx.Confirmations,
date: item.CreatedAt,
depositAddress: item.InTx.To,
}
})
dispatch(actionCreators.updateRecentHistory({ data, total: result.Total }))
}
}
export const updateCurrentPair = (pairName: string): ThunkAction => {
return async (dispatch, getState) => {
const state = getState()
const tokenPairsDomain = getTokenPairsDomain(state)
const pairs = tokenPairsDomain.getPairsByCode()
const pair = pairs[pairName]
if (!pair) return
const param = pairName.replace('/', '-')
dispatch(actionCreators.updateCurrentPair(pair))
dispatch(push(`/trade/${param}`))
}
}