-
Notifications
You must be signed in to change notification settings - Fork 504
/
selectors.ts
executable file
·96 lines (91 loc) · 3.44 KB
/
selectors.ts
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
import { createDeepEqualSelector } from '../../utils'
import {
curry,
filter,
keys,
lensProp,
mapObjIndexed,
path,
prop,
propOr,
set,
toUpper
} from 'ramda'
import { FiatTypeEnum } from 'blockchain-wallet-v4/src/types'
import { getInvitations } from '../settings/selectors'
import { getSBPaymentMethods } from 'data/components/simpleBuy/selectors'
import { RootState } from 'data/rootReducer'
import { SupportedCoinType } from './types'
// general
export const getOptions = (state: RootState) => state.walletOptionsPath
export const getDomains = state => getOptions(state).map(prop('domains'))
export const getWebOptions = state =>
getOptions(state).map(path(['platforms', 'web']))
export const getWalletHelperUrl = state =>
getDomains(state).map(prop('walletHelper'))
export const getAppEnv = state =>
getWebOptions(state).map(path(['application', 'environment']))
export const getAnalyticsSiteId = state =>
getWebOptions(state).map(path(['application', 'analyticsSiteId']))
export const getAnnouncements = state =>
getWebOptions(state).map(path(['application', 'announcements']))
export const getAdsBlacklist = state =>
getWebOptions(state).map(path(['ads', 'blacklist']))
export const getAdsUrl = state => getWebOptions(state).map(path(['ads', 'url']))
// coins
export const getSupportedCoins = createDeepEqualSelector(
[getInvitations, getWebOptions, getSBPaymentMethods],
(invitationsR, webOptionsR, sbPaymentMethods) => {
const addInvited = (obj, coin) => {
// @ts-ignore
const invited = invitationsR.map(propOr(true, coin)).getOrElse(false)
return set(lensProp('invited'), invited, obj)
}
const addMethod = (obj, coin) => {
const methods = sbPaymentMethods.getOrElse({
currency: 'USD',
methods: []
})
const method =
coin in FiatTypeEnum
? methods.methods.find(method => method.currency === coin)
: true
return set(lensProp('method'), method, obj)
}
return webOptionsR
.map(prop('coins'))
.map(mapObjIndexed(addInvited))
.map(mapObjIndexed(addMethod))
}
)
export const getSyncToExchangeList = state =>
getSupportedCoins(state)
.map(filter((value: SupportedCoinType) => value.availability.syncToPit))
.map(keys)
export const getBtcNetwork = state =>
getSupportedCoins(state).map(path(['BTC', 'config', 'network']))
export const getEthTxFuse = state =>
getSupportedCoins(state).map(path(['ETH', 'lastTxFuse']))
export const getXlmSendTimeOutSeconds = state =>
getSupportedCoins(state).map(path(['XLM', 'config', 'sendTimeOutSeconds']))
export const getXlmExchangeAddresses = state =>
getSupportedCoins(state).map(path(['XLM', 'exchangeAddresses']))
export const getStxCampaign = state =>
getWebOptions(state).map(path(['coins', 'STX', 'campaign']))
export const getCoinAvailability = curry((state, coin) =>
getSupportedCoins(state).map(path([toUpper(coin), 'availability']))
)
export const getErc20CoinList = state =>
getSupportedCoins(state).map(x =>
keys(filter((c: SupportedCoinType) => !!c.contractAddress, x))
)
export const getCoinModel = (state, coin) =>
getSupportedCoins(state).map(x => prop(toUpper(coin), x))
export const getCoinIcons = (state, coin) =>
// @ts-ignore
getCoinModel(state, coin).map(path(['icons']))
// domains
export const getVeriffDomain = state => getDomains(state).map(prop('veriff'))
// partners
export const getSiftKey = state =>
getWebOptions(state).map(path(['sift', 'apiKey']))