1import React from 'react';
2import { Input, AccessoryIcon } from 'indigo-react';
3import { useField } from 'react-final-form';
4import { some } from 'lodash';
12 validateMaximumPatpByteLength,
16} from 'lib/validators';
17import { compose } from 'lib/lib';
18import { prependSig } from 'lib/transformers';
19import { DEFAULT_HD_PATH } from 'lib/wallet';
20import InputSigil from 'components/InputSigil';
22const PLACEHOLDER_POINT = '~sampel-ponnym';
23const PLACEHOLDER_HD_PATH = DEFAULT_HD_PATH;
24const PLACEHOLDER_MNEMONIC =
25 'example crew supreme gesture quantum web media hazard theory mercy wing kitten';
26const PLACEHOLDER_TICKET = '~sampel-ticlyt-migfun-falmel';
27const PLACEHOLDER_ADDRESS = '0x12345abcdeDB11D175F123F6891AA64F01c24F7d';
28const PLACEHOLDER_PRIVATE_KEY =
29 '0x12345abcdee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
31const buildValidator = (
39 )(value).error || (await fn(value))
43export const hasErrors = obj => some(obj, v => v !== undefined);
45export const buildTicketValidator = (validators = []) =>
46 buildValidator([...validators, validateTicket, validateNotEmpty]);
47export const buildMnemonicValidator = () =>
48 buildValidator([validateMnemonic, validateNotEmpty]);
49export const buildCheckboxValidator = () =>
50 buildValidator([validateOneOf([true, false])]);
51export const buildPassphraseValidator = () => buildValidator([]);
52// TODO: validate hdpath format
53export const buildHdPathValidator = () => buildValidator([validateNotEmpty]);
54export const buildPointValidator = (size = 4) =>
57 validateMaximumPatpByteLength(size),
60export const buildSelectValidator = options =>
61 buildValidator([validateOneOf(options.map(option => option.value))]);
62export const buildHexValidator = length =>
64 validateHexLength(length),
68export const buildUploadValidator = () => buildValidator([validateNotEmpty]);
70// the default form validator just returns field-level validations
71const kDefaultFormValidator = (values, errors) => errors;
72export const composeValidator = (
74 formValidator = kDefaultFormValidator
76 const names = Object.keys(fieldValidators);
78 const fieldLevelValidators = names.map(name => value =>
79 fieldValidators[name](value)
82 const fieldLevelValidator = async values => {
83 const errors = await Promise.all(
84 names.map((name, i) => fieldLevelValidators[i](values[name]))
96 return async values => {
97 console.log('validating...');
98 const errors = await fieldLevelValidator(values);
99 return await formValidator(values, errors);
103export function TicketInput({ name, ...rest }) {
105 meta: { valid, error, validating, touched, active },
120 placeholder={PLACEHOLDER_TICKET}
122 touched && !active && error ? (
123 <AccessoryIcon.Failure />
125 <AccessoryIcon.Pending />
127 <AccessoryIcon.Success />
130 config={{ format: prependSig }}
137export function MnemonicInput({ ...rest }) {
139 <Input type="textarea" placeholder={PLACEHOLDER_MNEMONIC} mono {...rest} />
143export function HdPathInput({ ...rest }) {
147 placeholder={PLACEHOLDER_HD_PATH}
154export function PassphraseInput({ ...rest }) {
158 placeholder="Passphrase"
165export function PointInput({ name, size = 4, ...rest }) {
168 meta: { active, valid, error },
170 subscription: { value: true, active: true, valid: true, error: true },
178 placeholder={PLACEHOLDER_POINT}
191 config={{ format: prependSig }}
198export function PrivateKeyInput({ ...rest }) {
202 placeholder={PLACEHOLDER_PRIVATE_KEY}
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list