1import React from 'react';
2import { Input, AccessoryIcon } from 'indigo-react';
3import { useField } from 'react-final-form';
4import { some } from 'lodash';
12 validateMaximumPatpByteLength,
16 validateEthereumAddress,
17} from 'lib/validators';
18import { compose } from 'lib/lib';
19import { prependSig } from 'lib/transformers';
20import { DEFAULT_HD_PATH } from 'lib/wallet';
21import InputSigil from 'components/InputSigil';
23const PLACEHOLDER_POINT = '~sampel-ponnym';
24const PLACEHOLDER_HD_PATH = DEFAULT_HD_PATH;
25const PLACEHOLDER_MNEMONIC =
26 'example crew supreme gesture quantum web media hazard theory mercy wing kitten';
27const PLACEHOLDER_TICKET = '~sampel-ticlyt-migfun-falmel';
28const PLACEHOLDER_ADDRESS = '0x12345abcdeDB11D175F123F6891AA64F01c24F7d';
29const PLACEHOLDER_PRIVATE_KEY =
30 '0x12345abcdee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
32const buildValidator = (
40 )(value).error || (await fn(value))
44export const hasErrors = obj => some(obj, v => v !== undefined);
46export const buildTicketValidator = (validators = []) =>
47 buildValidator([...validators, validateTicket, validateNotEmpty]);
48export const buildMnemonicValidator = () =>
49 buildValidator([validateMnemonic, validateNotEmpty]);
50export const buildCheckboxValidator = mustBe =>
52 validateOneOf(mustBe !== undefined ? [mustBe] : [true, false]),
54export const buildPassphraseValidator = () => buildValidator([]);
55// TODO: validate hdpath format
56export const buildHdPathValidator = () => buildValidator([validateNotEmpty]);
57export const buildPointValidator = (size = 4) =>
60 validateMaximumPatpByteLength(size),
63export const buildSelectValidator = options =>
64 buildValidator([validateOneOf(options.map(option => option.value))]);
65export const buildHexValidator = length =>
67 validateHexLength(length),
71export const buildUploadValidator = () => buildValidator([validateNotEmpty]);
72export const buildAddressValidator = () =>
74 validateEthereumAddress,
75 validateHexLength(40),
80// the default form validator just returns field-level validations
81const kDefaultFormValidator = (values, errors) => errors;
82export const composeValidator = (
84 formValidator = kDefaultFormValidator
86 const names = Object.keys(fieldValidators);
88 const fieldLevelValidators = names.map(name => value =>
89 fieldValidators[name](value)
92 const fieldLevelValidator = async values => {
93 const errors = await Promise.all(
94 names.map((name, i) => fieldLevelValidators[i](values[name]))
106 return async values => {
107 const errors = await fieldLevelValidator(values);
108 return await formValidator(values, errors);
112export function TicketInput({ name, ...rest }) {
114 meta: { valid, error, validating, touched, active },
129 placeholder={PLACEHOLDER_TICKET}
131 touched && !active && error ? (
132 <AccessoryIcon.Failure />
134 <AccessoryIcon.Pending />
136 <AccessoryIcon.Success />
139 config={{ format: prependSig }}
146export function MnemonicInput({ ...rest }) {
148 <Input type="textarea" placeholder={PLACEHOLDER_MNEMONIC} mono {...rest} />
152export function HdPathInput({ ...rest }) {
156 placeholder={PLACEHOLDER_HD_PATH}
163export function PassphraseInput({ ...rest }) {
167 placeholder="Passphrase"
174export function PointInput({ name, size = 4, ...rest }) {
177 meta: { active, valid, error },
179 subscription: { value: true, active: true, valid: true, error: true },
187 placeholder={PLACEHOLDER_POINT}
200 config={{ format: prependSig }}
207export function HexInput({ ...rest }) {
211 placeholder={PLACEHOLDER_PRIVATE_KEY}
219export function AddressInput({ ...rest }) {
223 placeholder={PLACEHOLDER_ADDRESS}
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