-
Notifications
You must be signed in to change notification settings - Fork 504
/
selectors.js
177 lines (158 loc) · 4.64 KB
/
selectors.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import {
any,
compose,
complement,
curry,
equals,
find,
findLast,
hasPath,
lift,
includes,
isNil,
not,
path,
pathOr,
prop,
propEq
} from 'ramda'
import { selectors } from 'data'
import { USER_ACTIVATION_STATES, KYC_STATES, TIERS_STATES } from './model'
export const getUserData = path(['profile', 'userData'])
export const getUserId = compose(
lift(prop('id')),
getUserData
)
export const getWalletAddresses = compose(
lift(prop('walletAddresses')),
getUserData
)
export const getUserActivationState = compose(
lift(prop('state')),
getUserData
)
export const getUserKYCState = compose(
lift(prop('kycState')),
getUserData
)
export const getSunRiverTag = compose(
lift(path(['tags', 'SUNRIVER'])),
getUserData
)
export const getPowerPaxTag = compose(
lift(hasPath(['tags', 'POWER_PAX'])),
getUserData
)
export const getBlockstackTag = compose(
lift(path(['tags', 'BLOCKSTACK'])),
getUserData
)
export const isUserCreated = compose(
lift(equals(USER_ACTIVATION_STATES.CREATED)),
getUserActivationState
)
export const isUserActive = compose(
lift(equals(USER_ACTIVATION_STATES.ACTIVE)),
getUserActivationState
)
export const isUserStateNone = compose(
lift(equals(USER_ACTIVATION_STATES.NONE)),
getUserActivationState
)
export const isUserVerified = compose(
lift(equals(KYC_STATES.VERIFIED)),
getUserKYCState
)
export const getUserCountryCode = compose(
lift(path(['address', 'country'])),
getUserData
)
export const getUserStateCode = compose(
lift(path(['address', 'state'])),
getUserData
)
export const getUserTiers = compose(
lift(prop('tiers')),
getUserData
)
export const getUserLimits = compose(
lift(prop('limits')),
getUserData
)
export const getKycDocResubmissionStatus = compose(
lift(path(['resubmission', 'reason'])),
getUserData
)
export const getTiers = path(['profile', 'userTiers'])
export const getTier = curry((state, tierIndex) =>
lift(find(propEq('index', tierIndex)))(getTiers(state))
)
export const getLastAttemptedTier = compose(
lift(findLast(complement(propEq('state', TIERS_STATES.NONE)))),
getTiers
)
export const isCountrySupported = (countryCode, supportedCountries) =>
any(propEq('code', countryCode), supportedCountries)
export const isInvitedToKyc = state =>
selectors.core.settings.getInvitations(state).map(prop('kyc'))
export const userFlowSupported = isInvitedToKyc
export const isInvitedToPitSidenav = state => {
const pitCountries = selectors.core.walletOptions.getPitCountryList(state)
const userCountry = selectors.core.settings.getCountryCode(state)
const transform = (pitCountries, userCountry) => {
const isCountryWhitelisted =
pitCountries &&
(pitCountries === '*' || includes(userCountry, pitCountries))
return isCountryWhitelisted
}
return lift(transform)(pitCountries, userCountry)
}
export const isInvitedToPitHomeBanner = state => {
const pitCountries = selectors.core.walletOptions.getPitCountryList(state)
const userCountry = selectors.core.settings.getCountryCode(state)
const isInvited = selectors.core.settings
.getInvitations(state)
.map(prop('pitHomeBanner'))
const transform = (pitCountries, userCountry, isInvited) => {
const isCountryWhitelisted =
pitCountries &&
(pitCountries === '*' || includes(userCountry, pitCountries))
return isCountryWhitelisted || isInvited
}
return lift(transform)(pitCountries, userCountry, isInvited)
}
export const getApiToken = path(['profile', 'apiToken'])
export const isAuthenticated = state => getApiToken(state).map(prop('isActive'))
export const getAuthCredentials = state => ({
token: getApiToken(state).getOrElse(''),
email: selectors.core.settings.getEmail(state).getOrElse(''),
guid: selectors.core.wallet.getGuid(state)
})
export const getCampaign = pathOr(null, ['profile', 'campaign'])
export const CLOSE_TO_AMOUNT = 0.8
export const closeToTier1Limit = state =>
lift(
(userData, tiers) =>
path([0, 'state'], tiers) === TIERS_STATES.VERIFIED &&
path([1, 'state'], tiers) === TIERS_STATES.NONE &&
pathOr(0, [0, 'limits', 'annual'], tiers)[0].limits.annual *
CLOSE_TO_AMOUNT <
pathOr(0, ['limits', 'annual'], userData)
)(getUserData(state), getTiers(state))
export const getLinkFromPitAccountStatus = path([
'profile',
'pitOnboarding',
'linkFromPitAccountStatus'
])
export const getLinkToPitAccountStatus = path([
'profile',
'pitOnboarding',
'linkToPitAccountStatus'
])
export const getLinkToPitAccountDeeplink = path([
'profile',
'pitOnboarding',
'linkToPitAccountDeeplink'
])
export const isPitAccountLinked = state =>
lift(user => not(isNil(prop('settings', user))))(getUserData(state))