1import React, { useCallback, useState, useMemo } from 'react';
2import { AccessoryIcon, useForm } from 'indigo-react';
3import { identity } from 'lodash';
4import * as bip39 from 'bip39';
6import InputSigil from 'components/InputSigil';
8import { DEFAULT_HD_PATH } from 'lib/wallet';
18} from 'lib/validators';
19import { prependSig } from 'lib/transformers';
21const EXAMPLE_PRIVATE_KEY =
22 '0xa44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
24// const RequiredInput = advancedInput({
25// WrappedComponent: Input,
26// validators: [validateNotEmpty],
29// const NetworkKeyInput = advancedInput({
30// WrappedComponent: Input,
31// validators: [validateNotEmpty, validateNetworkKey],
34// const NetworkSeedInput = advancedInput({
35// WrappedComponent: Input,
36// validators: [validateNotEmpty, validateNetworkSeed],
39// const AddressInput = advancedInput({
40// WrappedComponent: Input,
41// validators: [validateEthereumAddress, validateNotEmpty],
44// const GalaxyInput = advancedInput({
45// WrappedComponent: Input,
46// validators: [validateGalaxy, validateNotEmpty],
47// transformers: [prependSig],
50// pulls out the first input from a useForm() call
51function useFirstOf({ inputs, setValue, ...rest }, mapper = identity) {
52 // ask the mapper function for any values to overwrite
57 // memoize the setValue callback for manually setting the value
58 // in response to some imperative event
59 const _setValue = useCallback(value => setValue(input.name, value), [
64 // provide the first input as the first element
65 // _and_ as the second element to facilitate destructuring
66 // and then provide the pass/error/setValue/etc properties at the end
77export function usePassphraseInput(props) {
83 placeholder: 'Passphrase',
90export function useHexInput({ length, ...rest }) {
94 type: 'text', // or password
96 placeholder: EXAMPLE_PRIVATE_KEY,
100 validateLength(length + 2),
111const kExampleMnemonic = bip39.generateMnemonic();
112const kMnemonicValidators = [validateMnemonic, validateNotEmpty];
113export function useMnemonicInput(props) {
119 placeholder: `e.g. ${kExampleMnemonic}`,
120 validators: kMnemonicValidators,
127export function useHdPathInput(props) {
133 placeholder: `e.g. ${DEFAULT_HD_PATH}`,
140const kTicketValidators = [validateTicket, validateNotEmpty];
141const kTicketTransformers = [prependSig];
142//TODO needs to be fancier, displaying sig and dashes instead of •ing all
143export function useTicketInput({ validators = [], deriving = false, ...rest }) {
149 placeholder: '~ragtyd-modwen-bostec-hinsep',
150 validators: useMemo(() => [...validators, ...kTicketValidators], [
153 transformers: kTicketTransformers,
158 ({ error, pass }) => ({
160 <AccessoryIcon.Failure />
162 <AccessoryIcon.Pending />
164 <AccessoryIcon.Success />
170const kPointValidators = [validatePoint, validateNotEmpty];
171const kPointTransformers = [prependSig];
172export function usePointInput(rest) {
173 const [lastValidPoint, setLastValidPoint] = useState('');
179 placeholder: 'e.g. ~zod',
180 validators: kPointValidators,
181 transformers: kPointTransformers,
183 onValue: setLastValidPoint,
187 ({ error, pass, focused }) => ({
188 accessory: lastValidPoint ? (
190 patp={lastValidPoint}
202export function useCheckboxInput({ initialValue, ...rest }) {
213export function useSelectInput({ initialValue, options, ...rest }) {
221 options.map(option => option.value),
228 initialValue: initialValue || options[0].value,
235const kEmailValidators = [validateEmail, validateNotEmpty];
236export const buildEmailInputConfig = extra => ({
239 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