1import React, { useCallback, 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,
20} from 'lib/validators';
21import { prependSig, convertToNumber } from 'lib/transformers';
23import InputSigil from 'components/InputSigil';
25const EXAMPLE_PRIVATE_KEY =
26 '0xa44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
28// pulls out the first input from a useForm() call
29function useFirstOf({ inputs, setValue, ...rest }, mapper = identity) {
30 // ask the mapper function for any values to overwrite
35 // memoize the setValue callback for manually setting the value
36 // in response to some imperative event
37 const _setValue = useCallback(value => setValue(input.name, value), [
42 // provide the first input as the first element
43 // _and_ as the second element to facilitate destructuring
44 // and then provide the pass/error/setValue/etc properties at the end
55export function usePassphraseInput(props) {
61 placeholder: 'Passphrase',
68export function useHexInput({ length, ...rest }) {
72 type: 'text', // or password
74 placeholder: `e.g. ${EXAMPLE_PRIVATE_KEY}`,
78 validateLength(length + 2),
89const kExampleMnemonic = bip39.generateMnemonic();
90const kMnemonicValidators = [validateMnemonic, validateNotEmpty];
91export function useMnemonicInput(props) {
97 placeholder: `e.g. ${kExampleMnemonic}`,
98 validators: kMnemonicValidators,
105export function useHdPathInput(props) {
111 placeholder: `e.g. ${DEFAULT_HD_PATH}`,
118const kTicketValidators = [validateTicket, validateNotEmpty];
119//TODO needs to be fancier, displaying sig and dashes instead of •ing all
120const kTicketTransformers = [prependSig];
121export function useTicketInput({ validators = [], deriving = false, ...rest }) {
127 placeholder: 'e.g. ~ragtyd-modwen-bostec-hinsep',
128 validators: useMemo(() => [...validators, ...kTicketValidators], [
131 transformers: kTicketTransformers,
136 ({ error, pass }) => ({
138 <AccessoryIcon.Failure />
140 <AccessoryIcon.Pending />
142 <AccessoryIcon.Success />
148const kPointValidators = [
150 validateMaximumPatpByteLength(4),
153const kPointTransformers = [prependSig];
154export function usePointInput(rest) {
160 placeholder: 'e.g. ~zod',
161 validators: kPointValidators,
162 transformers: kPointTransformers,
167 ({ error, pass, focused, data }) => ({
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 = [
216 validateEthereumAddress,
217 validateNotNullAddress,
220export function useAddressInput({ ...rest }) {
225 label: 'Ethereum Address',
226 placeholder: 'e.g. 0x6DEfFb0caFDB11D175F123F6891AA64F01c24F7d',
228 validators: kAddressValidators,
236const kNumberTransformers = [convertToNumber];
237const kNumberValidators = [validateGreaterThan(0)];
238export function useNumberInput({ ...rest }) {
245 transformers: kNumberTransformers,
246 validators: kNumberValidators,
253const kEmailValidators = [validateEmail, validateNotEmpty];
254export const buildEmailInputConfig = extra => ({
257 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