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 = [
144 validatePatpByteLength(8), // tickets are 8 bytes of patp
147//TODO needs to be fancier, displaying sig and dashes instead of •ing all
148const kTicketTransformers = [prependSig];
149export function useTicketInput({ validators = [], deriving = false, ...rest }) {
155 placeholder: 'e.g. ~ragtyd-modwen-bostec-hinsep',
156 validators: useMemo(() => [...validators, ...kTicketValidators], [
159 transformers: kTicketTransformers,
164 ({ error, pass }) => ({
166 <AccessoryIcon.Failure />
168 <AccessoryIcon.Pending />
170 <AccessoryIcon.Success />
176const kPointValidators = [
178 validateMaximumPatpByteLength(4),
181const kPointTransformers = [prependSig];
182export function usePointInput(rest) {
183 const [lastValidPoint, setLastValidPoint] = useState('');
189 placeholder: 'e.g. ~zod',
190 validators: kPointValidators,
191 transformers: kPointTransformers,
193 onValue: setLastValidPoint,
197 ({ error, pass, focused }) => ({
198 accessory: lastValidPoint ? (
200 patp={lastValidPoint}
212export function useCheckboxInput({ initialValue, ...rest }) {
223export function useSelectInput({ initialValue, options, ...rest }) {
231 options.map(option => option.value),
238 initialValue: initialValue || options[0].value,
245const kEmailValidators = [validateEmail, validateNotEmpty];
246export const buildEmailInputConfig = extra => ({
249 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