1import React, { useCallback, useMemo } from 'react';
2import { AccessoryIcon, useForm } from 'indigo-react';
3import { identity } from 'lodash';
5import { DEFAULT_HD_PATH } from 'lib/wallet';
15 validateMaximumPatpByteLength,
16 validateEthereumAddress,
17 validateNotNullAddress,
19} from 'lib/validators';
20import { prependSig, convertToNumber } from 'lib/transformers';
22import InputSigil from 'components/InputSigil';
24const PLACEHOLDER_POINT = '~sampel-ponnym';
25const PLACEHOLDER_HD_PATH = DEFAULT_HD_PATH;
26const PLACEHOLDER_MNEMONIC =
27 'example crew supreme gesture quantum web media hazard theory mercy wing kitten';
28const PLACEHOLDER_TICKET = '~sampel-ticlyt-migfun-falmel';
29const PLACEHOLDER_ADDRESS = '0x12345abcdeDB11D175F123F6891AA64F01c24F7d';
30const PLACEHOLDER_PRIVATE_KEY =
31 '0x12345abcdee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
33// pulls out the first input from a useForm() call
34function useFirstOf({ inputs, setValue, ...rest }, mapper = identity) {
35 // ask the mapper function for any values to overwrite
40 // memoize the setValue callback for manually setting the value
41 // in response to some imperative event
42 const _setValue = useCallback(value => setValue(input.name, value), [
47 // provide the first input as the first element
48 // _and_ as the second element to facilitate destructuring
49 // and then provide the pass/error/setValue/etc properties at the end
60const kPointTransformers = [prependSig];
61export function usePointInput({ size = 4, validators = [], ...rest }) {
62 const _validators = useMemo(
66 validateMaximumPatpByteLength(size),
77 placeholder: PLACEHOLDER_POINT,
78 validators: _validators,
79 transformers: kPointTransformers,
84 ({ error, pass, focused, value }) => ({
99export function useGalaxyInput(props) {
100 return usePointInput({
101 label: 'Galaxy Name',
107const kAddressValidators = [
108 validateEthereumAddress,
109 validateNotNullAddress,
112export function useAddressInput({ ...rest }) {
117 label: 'Ethereum Address',
118 placeholder: PLACEHOLDER_ADDRESS,
120 validators: kAddressValidators,
128const kNumberTransformers = [convertToNumber];
129const kNumberValidators = [validateGreaterThan(0)];
130export function useNumberInput({ ...rest }) {
137 transformers: kNumberTransformers,
138 validators: kNumberValidators,
145const kEmailValidators = [validateEmail, validateNotEmpty];
146export const buildEmailInputConfig = extra => ({
149 validators: kEmailValidators,
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