-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy pathprop-types.js
More file actions
287 lines (248 loc) · 8.07 KB
/
prop-types.js
File metadata and controls
287 lines (248 loc) · 8.07 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import PropTypes from 'prop-types'
import Aragon from '@aragon/wrapper'
import {
APPS_STATUS_ERROR,
APPS_STATUS_READY,
APPS_STATUS_LOADING,
APPS_STATUS_UNLOADED,
DAO_STATUS_ERROR,
DAO_STATUS_READY,
DAO_STATUS_LOADING,
DAO_STATUS_UNLOADED,
ACTIVITY_STATUS_CONFIRMED,
ACTIVITY_STATUS_FAILED,
ACTIVITY_STATUS_PENDING,
ACTIVITY_STATUS_TIMED_OUT,
TRANSACTION_STATUS_ERROR,
TRANSACTION_STATUS_PENDING,
TRANSACTION_STATUS_SUCCESS,
TRANSACTION_STATUS_UPCOMING,
} from './symbols'
import { isAddress } from './util/web3'
const validatorCreator = nonRequiredFunction => {
const validator = nonRequiredFunction
validator.isRequired = (props, propName, componentName) => {
const value = props[propName]
if (value === null || value === undefined || value === '') {
return new Error(
`Property ${propName} is required on ${componentName}, but ${value} was given.`
)
}
return nonRequiredFunction(props, propName, componentName)
}
return validator
}
const ethereumAddressValidator = (props, propName, componentName) => {
const value = props[propName]
if (value === null || value === undefined || value === '') {
return null
}
if (!isAddress(value)) {
const valueType = typeof value
let nonAddress = null
if (valueType !== 'object') {
nonAddress = value.toString()
}
return new Error(
`Invalid prop ${propName} supplied to ${componentName}. The provided value is not a valid ethereum address.${nonAddress &&
` You provided "${nonAddress}"`}`
)
}
}
export const EthereumAddressType = validatorCreator(ethereumAddressValidator)
export const ActivityStatusType = PropTypes.oneOf([
ACTIVITY_STATUS_CONFIRMED,
ACTIVITY_STATUS_FAILED,
ACTIVITY_STATUS_PENDING,
ACTIVITY_STATUS_TIMED_OUT,
])
export const AppType = PropTypes.shape({
appId: PropTypes.string.isRequired,
baseUrl: PropTypes.string.isRequired,
codeAddress: EthereumAddressType.isRequired,
hasWebApp: PropTypes.bool.isRequired,
proxyAddress: EthereumAddressType.isRequired,
src: PropTypes.string.isRequired,
tags: PropTypes.arrayOf(PropTypes.string).isRequired,
// This content may not be available if the app's content couldn't be fetched
abi: PropTypes.array,
appName: PropTypes.string,
apmRegistry: PropTypes.string,
content: PropTypes.shape({
location: PropTypes.string.isRequired,
provider: PropTypes.string.isRequired,
}),
description: PropTypes.string,
functions: PropTypes.array,
icons: PropTypes.arrayOf(
PropTypes.shape({
src: PropTypes.string.isRequired,
})
),
name: PropTypes.string,
roles: PropTypes.array,
status: PropTypes.string,
version: PropTypes.string,
// This content is only available if the app is an aragonOS internal app
isAragonOsInternalApp: PropTypes.bool,
// This content is not available if the app is the Kernel
isForwarder: PropTypes.bool,
kernelAddress: EthereumAddressType,
})
export const AppsListType = PropTypes.arrayOf(AppType)
export const AppInstanceType = PropTypes.shape({
// Note that app instances also include embedded applications, like Home, that do not have
// associated on-chain information
codeAddress: EthereumAddressType,
identifier: PropTypes.string,
instanceId: PropTypes.oneOfType([EthereumAddressType, PropTypes.string])
.isRequired,
proxyAddress: EthereumAddressType,
})
export const AppInstanceGroupType = PropTypes.shape({
app: PropTypes.object.isRequired,
appId: PropTypes.string.isRequired,
instances: PropTypes.arrayOf(AppInstanceType).isRequired,
// This content may not be available if the app's content couldn't be fetched
hasWebApp: PropTypes.bool,
name: PropTypes.string,
repoName: PropTypes.string,
})
export const AppsStatusType = PropTypes.oneOf([
APPS_STATUS_ERROR,
APPS_STATUS_READY,
APPS_STATUS_LOADING,
APPS_STATUS_UNLOADED,
])
export const AragonType = PropTypes.instanceOf(Aragon)
export const DaoAddressType = PropTypes.shape({
address: EthereumAddressType,
domain: PropTypes.string,
})
export const DaoItemType = PropTypes.shape({
name: PropTypes.string,
address: EthereumAddressType,
})
export const DaoStatusType = PropTypes.oneOf([
DAO_STATUS_ERROR,
DAO_STATUS_READY,
DAO_STATUS_LOADING,
DAO_STATUS_UNLOADED,
])
export const FavoriteDaoType = PropTypes.shape({
name: PropTypes.string,
address: EthereumAddressType,
favorited: PropTypes.bool,
})
export const RenderFnType = PropTypes.oneOfType([
PropTypes.func,
PropTypes.oneOf([false]),
])
export const RepoContentType = PropTypes.shape({
name: PropTypes.string,
changelog_url: PropTypes.string,
description: PropTypes.string,
details_url: PropTypes.string,
icons: PropTypes.arrayOf(
PropTypes.shape({
src: PropTypes.string.isRequired,
sizes: PropTypes.string.isRequired,
})
),
screenshots: PropTypes.arrayOf(
PropTypes.shape({
src: PropTypes.string.isRequired,
})
),
})
export const RepoVersionType = PropTypes.shape({
content: RepoContentType.isRequired,
version: PropTypes.string.isRequired,
})
export const RepoType = PropTypes.shape({
appId: PropTypes.string.isRequired,
currentVersion: RepoVersionType,
latestVersion: RepoVersionType.isRequired,
repoAddress: EthereumAddressType.isRequired,
versions: PropTypes.arrayOf(
PropTypes.shape({
contentURI: PropTypes.string.isRequired,
contractAddress: PropTypes.string.isRequired,
timestamp: PropTypes.number,
version: PropTypes.string.isRequired,
versionId: PropTypes.string.isRequired,
})
).isRequired,
})
export const ReposListType = PropTypes.arrayOf(RepoType)
// https://github.com/react-spring/react-spring/blob/31200a79843ce85200b2a7692e8f14788e60f9e9/types/renderprops-universal.d.ts#L133
export const ReactSpringStateType = PropTypes.oneOf([
'enter',
'update',
'leave',
])
// see ethereum-providers/
export const EthereumProviderType = PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
image: PropTypes.string.isRequired,
strings: PropTypes.object.isRequired,
})
// see templates/
const OrgTemplateAppType = PropTypes.shape({
appName: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
})
export const OrgTemplateType = PropTypes.shape({
apps: PropTypes.arrayOf(OrgTemplateAppType.isRequired),
caseStudyUrl: PropTypes.string,
description: PropTypes.string.isRequired,
disabled: PropTypes.bool,
header: PropTypes.string.isRequired,
icon: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
longDesc: PropTypes.string,
name: PropTypes.string.isRequired,
optionalApps: PropTypes.arrayOf(OrgTemplateAppType.isRequired),
prepareTransactions: PropTypes.func,
registry: PropTypes.string,
screens: PropTypes.arrayOf(
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.func]))
),
sourceCodeUrl: PropTypes.string,
userGuideUrl: PropTypes.string,
})
// The status of a single transaction (only used to deploy an org for now).
// The “upcoming” status is used to indicate that the transaction is waiting
// for another one to be mined before being processed.
export const TransactionStatusType = PropTypes.oneOf([
TRANSACTION_STATUS_ERROR,
TRANSACTION_STATUS_PENDING,
TRANSACTION_STATUS_SUCCESS,
TRANSACTION_STATUS_UPCOMING,
])
// See src/wallet.js
export const WalletType = PropTypes.shape({
account: PropTypes.string,
balance: PropTypes.object.isRequired,
chainId: PropTypes.number.isRequired,
enable: PropTypes.bool.isRequired,
connected: PropTypes.bool.isRequired,
isContract: PropTypes.bool.isRequired,
networkType: PropTypes.string.isRequired,
providerInfo: PropTypes.object.isRequired,
web3: PropTypes.object.isRequired,
})
export const AragonUiAppearanceType = PropTypes.oneOf(['dark', 'light'])
export const AragonUiThemeType = PropTypes.oneOf([
PropTypes.string,
PropTypes.shape({
_name: PropTypes.string.isRequired,
_appearance: AragonUiAppearanceType.isRequired,
}),
])
export const ClientThemeType = PropTypes.shape({
theme: AragonUiThemeType,
appearance: AragonUiAppearanceType.isRequired,
})