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 validateNotNullAddress,
19} from 'lib/validators';
20import { prependSig } from 'lib/transformers';
22import InputSigil from 'components/InputSigil';
24const EXAMPLE_PRIVATE_KEY =
25 '0xa44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
27// pulls out the first input from a useForm() call
28function useFirstOf({ inputs, setValue, ...rest }, mapper = identity) {
29 // ask the mapper function for any values to overwrite
34 // memoize the setValue callback for manually setting the value
35 // in response to some imperative event
36 const _setValue = useCallback(value => setValue(input.name, value), [
41 // provide the first input as the first element
42 // _and_ as the second element to facilitate destructuring
43 // and then provide the pass/error/setValue/etc properties at the end
54export function usePassphraseInput(props) {
60 placeholder: 'Passphrase',
67export function useHexInput({ length, ...rest }) {
71 type: 'text', // or password
73 placeholder: EXAMPLE_PRIVATE_KEY,
77 validateLength(length + 2),
88const kExampleMnemonic = bip39.generateMnemonic();
89const kMnemonicValidators = [validateMnemonic, validateNotEmpty];
90export function useMnemonicInput(props) {
96 placeholder: `e.g. ${kExampleMnemonic}`,
97 validators: kMnemonicValidators,
104export function useHdPathInput(props) {
110 placeholder: `e.g. ${DEFAULT_HD_PATH}`,
117const kTicketValidators = [validateTicket, validateNotEmpty];
118//TODO needs to be fancier, displaying sig and dashes instead of •ing all
119const kTicketTransformers = [prependSig];
120export function useTicketInput({ validators = [], deriving = false, ...rest }) {
126 placeholder: 'e.g. ~ragtyd-modwen-bostec-hinsep',
127 validators: useMemo(() => [...validators, ...kTicketValidators], [
130 transformers: kTicketTransformers,
135 ({ error, pass }) => ({
137 <AccessoryIcon.Failure />
139 <AccessoryIcon.Pending />
141 <AccessoryIcon.Success />
147const kPointValidators = [
149 validateMaximumPatpByteLength(4),
152const kPointTransformers = [prependSig];
153export function usePointInput(rest) {
154 const [lastValidPoint, setLastValidPoint] = useState('');
160 placeholder: 'e.g. ~zod',
161 validators: kPointValidators,
162 transformers: kPointTransformers,
164 onValue: setLastValidPoint,
168 ({ error, pass, focused }) => ({
169 accessory: lastValidPoint ? (
171 patp={lastValidPoint}
183export function useCheckboxInput({ initialValue, ...rest }) {
194export function useSelectInput({ initialValue, options, ...rest }) {
202 options.map(option => option.value),
209 initialValue: initialValue || options[0].value,
216const kAddressValidators = [
217 validateEthereumAddress,
218 validateNotNullAddress,
221export function useAddressInput({ ...rest }) {
226 label: 'Ethereum Address',
227 placeholder: 'e.g. 0x6DEfFb0caFDB11D175F123F6891AA64F01c24F7d',
229 validators: kAddressValidators,
237const kEmailValidators = [validateEmail, validateNotEmpty];
238export const buildEmailInputConfig = extra => ({
241 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