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 validateMaximumPatpByteLength,
19 validatePatpByteLength,
20} from 'lib/validators';
21import { prependSig } from 'lib/transformers';
23const EXAMPLE_PRIVATE_KEY =
24 '0xa44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
26// const RequiredInput = advancedInput({
27// WrappedComponent: Input,
28// validators: [validateNotEmpty],
31// const NetworkKeyInput = advancedInput({
32// WrappedComponent: Input,
33// validators: [validateNotEmpty, validateNetworkKey],
36// const NetworkSeedInput = advancedInput({
37// WrappedComponent: Input,
38// validators: [validateNotEmpty, validateNetworkSeed],
41// const AddressInput = advancedInput({
42// WrappedComponent: Input,
43// validators: [validateEthereumAddress, validateNotEmpty],
46// const GalaxyInput = advancedInput({
47// WrappedComponent: Input,
48// validators: [validateGalaxy, validateNotEmpty],
49// transformers: [prependSig],
52// pulls out the first input from a useForm() call
53function useFirstOf({ inputs, setValue, ...rest }, mapper = identity) {
54 // ask the mapper function for any values to overwrite
59 // memoize the setValue callback for manually setting the value
60 // in response to some imperative event
61 const _setValue = useCallback(value => setValue(input.name, value), [
66 // provide the first input as the first element
67 // _and_ as the second element to facilitate destructuring
68 // and then provide the pass/error/setValue/etc properties at the end
79export function usePassphraseInput(props) {
85 placeholder: 'Passphrase',
92export function useHexInput({ length, ...rest }) {
96 type: 'text', // or password
98 placeholder: EXAMPLE_PRIVATE_KEY,
102 validateLength(length + 2),
113const kExampleMnemonic = bip39.generateMnemonic();
114const kMnemonicValidators = [validateMnemonic, validateNotEmpty];
115export function useMnemonicInput(props) {
121 placeholder: `e.g. ${kExampleMnemonic}`,
122 validators: kMnemonicValidators,
129export function useHdPathInput(props) {
135 placeholder: `e.g. ${DEFAULT_HD_PATH}`,
142const kTicketValidators = [validateTicket, validateNotEmpty];
143//TODO needs to be fancier, displaying sig and dashes instead of •ing all
144const kTicketTransformers = [prependSig];
145export function useTicketInput({ validators = [], deriving = false, ...rest }) {
151 placeholder: 'e.g. ~ragtyd-modwen-bostec-hinsep',
152 validators: useMemo(() => [...validators, ...kTicketValidators], [
155 transformers: kTicketTransformers,
160 ({ error, pass }) => ({
162 <AccessoryIcon.Failure />
164 <AccessoryIcon.Pending />
166 <AccessoryIcon.Success />
172const kPointValidators = [
174 validateMaximumPatpByteLength(4),
177const kPointTransformers = [prependSig];
178export function usePointInput(rest) {
179 const [lastValidPoint, setLastValidPoint] = useState('');
185 placeholder: 'e.g. ~zod',
186 validators: kPointValidators,
187 transformers: kPointTransformers,
189 onValue: setLastValidPoint,
193 ({ error, pass, focused }) => ({
194 accessory: lastValidPoint ? (
196 patp={lastValidPoint}
208export function useCheckboxInput({ initialValue, ...rest }) {
219export function useSelectInput({ initialValue, options, ...rest }) {
227 options.map(option => option.value),
234 initialValue: initialValue || options[0].value,
241const kEmailValidators = [validateEmail, validateNotEmpty];
242export const buildEmailInputConfig = extra => ({
245 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