-
Notifications
You must be signed in to change notification settings - Fork 25
/
Inputs.js
198 lines (183 loc) · 4.07 KB
/
Inputs.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import React from 'react';
import { Input, AccessoryIcon } from 'indigo-react';
import { useField } from 'react-final-form';
import {
convertToNumber,
buildFormatter,
downcase,
ensurePatFormat,
stripHexPrefix,
ensureHexPrefix,
} from 'form/formatters';
import { DEFAULT_HD_PATH } from 'lib/wallet';
import InputSigil from 'components/InputSigil';
const PLACEHOLDER_POINT = '~sampel-ponnym';
const PLACEHOLDER_HD_PATH = DEFAULT_HD_PATH;
const PLACEHOLDER_MNEMONIC =
'example crew supreme gesture quantum web media hazard theory mercy wing kitten';
const PLACEHOLDER_TICKET = '~sampel-ticlyt-migfun-falmel';
const PLACEHOLDER_ADDRESS = '0x';
const PLACEHOLDER_HEX = '0x';
const PLACEHOLDER_PRIVATE_KEY =
'a44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
const PLACEHOLDER_EMAIL = 'email@example.com';
const formatPat = buildFormatter([downcase, ensurePatFormat]);
export function TicketInput({ name, ...rest }) {
const {
meta: { valid, error, validating, touched, active },
} = useField(name, {
subscription: {
valid: true,
error: true,
validating: true,
touched: true,
active: true,
},
});
return (
<Input
type="text"
name={name}
obscure={value => value.replace(/[^~-]+/g, '••••••')}
placeholder={PLACEHOLDER_TICKET}
autoCapitalize="none"
autoCorrect="off"
accessory={
touched && !active && error ? (
<AccessoryIcon.Failure />
) : validating ? (
<AccessoryIcon.Pending />
) : valid ? (
<AccessoryIcon.Success />
) : null
}
config={{ parse: formatPat }}
mono
{...rest}
/>
);
}
export function MnemonicInput({ ...rest }) {
return (
<Input
type="textarea"
placeholder={PLACEHOLDER_MNEMONIC}
autoCapitalize="none"
autoComplete="off"
mono
{...rest}
/>
);
}
export function HdPathInput({ ...rest }) {
return (
<Input
type="text"
placeholder={PLACEHOLDER_HD_PATH}
autoCapitalize="none"
autoComplete="off"
autoCorrect="off"
{...rest}
/>
);
}
export function PassphraseInput({ ...rest }) {
return (
<Input
type="password"
placeholder="Passphrase"
autoCapitalize="none"
autoCorrect="off"
{...rest}
/>
);
}
export function PointInput({ name, size = 4, ...rest }) {
const {
input: { value },
meta: { active, valid, error },
} = useField(name, {
subscription: { value: true, active: true, valid: true, error: true },
});
return (
<Input
type="text"
label="Urbit ID"
name={name}
placeholder={PLACEHOLDER_POINT}
autoCapitalize="none"
autoComplete="off"
autoCorrect="off"
accessory={
value ? (
<InputSigil
patp={value}
size={44}
valid={valid}
error={error}
active={active}
/>
) : null
}
config={{ parse: formatPat }}
mono
{...rest}
/>
);
}
export function HexInput({ ...rest }) {
return (
<Input
type="text"
placeholder={PLACEHOLDER_HEX}
autoCapitalize="none"
autoComplete="off"
autoCorrect="off"
mono
config={{ parse: ensureHexPrefix }}
{...rest}
/>
);
}
export function PrivateKeyInput({ ...rest }) {
return (
<HexInput
type="password"
placeholder={PLACEHOLDER_PRIVATE_KEY}
config={{ parse: stripHexPrefix }}
{...rest}
/>
);
}
export function AddressInput({ ...rest }) {
return (
<Input
type="text"
placeholder={PLACEHOLDER_ADDRESS}
autoCapitalize="none"
autoCorrect="off"
mono
{...rest}
/>
);
}
export function NumberInput({ ...rest }) {
return (
<Input
type="number"
label="Number"
config={{ format: convertToNumber }}
{...rest}
/>
);
}
export function EmailInput({ ...rest }) {
return (
<Input
type="email"
placeholder={PLACEHOLDER_EMAIL}
autoCapitalize="none"
{...rest}
/>
);
}