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 validateEthereumAddress,
18} from 'lib/validators';
19import { prependSig } from 'lib/transformers';
21import InputSigil from 'components/InputSigil';
23const EXAMPLE_PRIVATE_KEY =
24 '0xa44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
26// pulls out the first input from a useForm() call
27function useFirstOf({ inputs, setValue, ...rest }, mapper = identity) {
28 // ask the mapper function for any values to overwrite
33 // memoize the setValue callback for manually setting the value
34 // in response to some imperative event
35 const _setValue = useCallback(value => setValue(input.name, value), [
40 // provide the first input as the first element
41 // _and_ as the second element to facilitate destructuring
42 // and then provide the pass/error/setValue/etc properties at the end
53export function usePassphraseInput(props) {
59 placeholder: 'Passphrase',
66export function useHexInput({ length, ...rest }) {
70 type: 'text', // or password
72 placeholder: EXAMPLE_PRIVATE_KEY,
76 validateLength(length + 2),
87const kExampleMnemonic = bip39.generateMnemonic();
88const kMnemonicValidators = [validateMnemonic, validateNotEmpty];
89export function useMnemonicInput(props) {
95 placeholder: `e.g. ${kExampleMnemonic}`,
96 validators: kMnemonicValidators,
103export function useHdPathInput(props) {
109 placeholder: `e.g. ${DEFAULT_HD_PATH}`,
116const kTicketValidators = [validateTicket, validateNotEmpty];
117//TODO needs to be fancier, displaying sig and dashes instead of •ing all
118const kTicketTransformers = [prependSig];
119export function useTicketInput({ validators = [], deriving = false, ...rest }) {
125 placeholder: 'e.g. ~ragtyd-modwen-bostec-hinsep',
126 validators: useMemo(() => [...validators, ...kTicketValidators], [
129 transformers: kTicketTransformers,
134 ({ error, pass }) => ({
136 <AccessoryIcon.Failure />
138 <AccessoryIcon.Pending />
140 <AccessoryIcon.Success />
146const kPointValidators = [
148 validateMaximumPatpByteLength(4),
151const kPointTransformers = [prependSig];
152export function usePointInput(rest) {
153 const [lastValidPoint, setLastValidPoint] = useState('');
159 placeholder: 'e.g. ~zod',
160 validators: kPointValidators,
161 transformers: kPointTransformers,
163 onValue: setLastValidPoint,
167 ({ error, pass, focused }) => ({
168 accessory: lastValidPoint ? (
170 patp={lastValidPoint}
182export function useCheckboxInput({ initialValue, ...rest }) {
193export function useSelectInput({ initialValue, options, ...rest }) {
201 options.map(option => option.value),
208 initialValue: initialValue || options[0].value,
215const kAddressValidators = [validateEthereumAddress, validateNotEmpty];
216export function useAddressInput({ ...rest }) {
221 label: 'Ethereum Address',
222 placeholder: 'e.g. 0x6DEfFb0caFDB11D175F123F6891AA64F01c24F7d',
224 validators: kAddressValidators,
232const kEmailValidators = [validateEmail, validateNotEmpty];
233export const buildEmailInputConfig = extra => ({
236 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