1import React, { useCallback, useState, useMemo } from 'react';
2import { AccessoryIcon, useForm } from 'indigo-react';
3import { identity } from 'lodash';
4import * as bip39 from 'bip39';
6import { DEFAULT_HD_PATH } from 'lib/wallet';
16 validateMaximumPatpByteLength,
17} from 'lib/validators';
18import { prependSig } from 'lib/transformers';
20import InputSigil from 'components/InputSigil';
22const EXAMPLE_PRIVATE_KEY =
23 '0xa44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
25// pulls out the first input from a useForm() call
26function useFirstOf({ inputs, setValue, ...rest }, mapper = identity) {
27 // ask the mapper function for any values to overwrite
32 // memoize the setValue callback for manually setting the value
33 // in response to some imperative event
34 const _setValue = useCallback(value => setValue(input.name, value), [
39 // provide the first input as the first element
40 // _and_ as the second element to facilitate destructuring
41 // and then provide the pass/error/setValue/etc properties at the end
52export function usePassphraseInput(props) {
58 placeholder: 'Passphrase',
65export function useHexInput({ length, ...rest }) {
69 type: 'text', // or password
71 placeholder: EXAMPLE_PRIVATE_KEY,
75 validateLength(length + 2),
86const kExampleMnemonic = bip39.generateMnemonic();
87const kMnemonicValidators = [validateMnemonic, validateNotEmpty];
88export function useMnemonicInput(props) {
94 placeholder: `e.g. ${kExampleMnemonic}`,
95 validators: kMnemonicValidators,
102export function useHdPathInput(props) {
108 placeholder: `e.g. ${DEFAULT_HD_PATH}`,
115const kTicketValidators = [validateTicket, validateNotEmpty];
116//TODO needs to be fancier, displaying sig and dashes instead of •ing all
117const kTicketTransformers = [prependSig];
118export function useTicketInput({ validators = [], deriving = false, ...rest }) {
124 placeholder: 'e.g. ~ragtyd-modwen-bostec-hinsep',
125 validators: useMemo(() => [...validators, ...kTicketValidators], [
128 transformers: kTicketTransformers,
133 ({ error, pass }) => ({
135 <AccessoryIcon.Failure />
137 <AccessoryIcon.Pending />
139 <AccessoryIcon.Success />
145const kPointValidators = [
147 validateMaximumPatpByteLength(4),
150const kPointTransformers = [prependSig];
151export function usePointInput(rest) {
152 const [lastValidPoint, setLastValidPoint] = useState('');
158 placeholder: 'e.g. ~zod',
159 validators: kPointValidators,
160 transformers: kPointTransformers,
162 onValue: setLastValidPoint,
166 ({ error, pass, focused }) => ({
167 accessory: lastValidPoint ? (
169 patp={lastValidPoint}
181export function useCheckboxInput({ initialValue, ...rest }) {
192export function useSelectInput({ initialValue, options, ...rest }) {
200 options.map(option => option.value),
207 initialValue: initialValue || options[0].value,
214const kEmailValidators = [validateEmail, validateNotEmpty];
215export const buildEmailInputConfig = extra => ({
218 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