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 kMnemonicValidators = [validateMnemonic, validateNotEmpty];
61export function useMnemonicInput(props) {
67 placeholder: PLACEHOLDER_MNEMONIC,
68 validators: kMnemonicValidators,
75export function useHdPathInput(props) {
81 placeholder: PLACEHOLDER_HD_PATH,
88const kTicketValidators = [validateTicket, validateNotEmpty];
89//TODO needs to be fancier, displaying sig and dashes instead of •ing all
90const kTicketTransformers = [prependSig];
91export function useTicketInput({ validators = [], deriving = false, ...rest }) {
97 placeholder: PLACEHOLDER_TICKET,
98 validators: useMemo(() => [...validators, ...kTicketValidators], [
101 transformers: kTicketTransformers,
106 ({ error, pass }) => ({
108 <AccessoryIcon.Failure />
110 <AccessoryIcon.Pending />
112 <AccessoryIcon.Success />
118const kPointTransformers = [prependSig];
119export function usePointInput({ size = 4, validators = [], ...rest }) {
120 const _validators = useMemo(
124 validateMaximumPatpByteLength(size),
135 placeholder: PLACEHOLDER_POINT,
136 validators: _validators,
137 transformers: kPointTransformers,
142 ({ error, pass, focused, value }) => ({
157export function useGalaxyInput(props) {
158 return usePointInput({
159 label: 'Galaxy Name',
165export function useCheckboxInput({ initialValue, ...rest }) {
176export function useSelectInput({ initialValue, options, ...rest }) {
183 validateOneOf(options.map(option => option.value)),
189 initialValue: initialValue || options[0].value,
196const kAddressValidators = [
197 validateEthereumAddress,
198 validateNotNullAddress,
201export function useAddressInput({ ...rest }) {
206 label: 'Ethereum Address',
207 placeholder: PLACEHOLDER_ADDRESS,
209 validators: kAddressValidators,
217const kNumberTransformers = [convertToNumber];
218const kNumberValidators = [validateGreaterThan(0)];
219export function useNumberInput({ ...rest }) {
226 transformers: kNumberTransformers,
227 validators: kNumberValidators,
234const kEmailValidators = [validateEmail, validateNotEmpty];
235export const buildEmailInputConfig = extra => ({
238 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