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';
17} from 'lib/validators';
18import { prependSig } from 'lib/transformers';
20const EXAMPLE_PRIVATE_KEY =
21 '0xa44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
23// const RequiredInput = advancedInput({
24// WrappedComponent: Input,
25// validators: [validateNotEmpty],
28// const NetworkKeyInput = advancedInput({
29// WrappedComponent: Input,
30// validators: [validateNotEmpty, validateNetworkKey],
33// const NetworkSeedInput = advancedInput({
34// WrappedComponent: Input,
35// validators: [validateNotEmpty, validateNetworkSeed],
38// const AddressInput = advancedInput({
39// WrappedComponent: Input,
40// validators: [validateEthereumAddress, validateNotEmpty],
43// const GalaxyInput = advancedInput({
44// WrappedComponent: Input,
45// validators: [validateGalaxy, validateNotEmpty],
46// transformers: [prependSig],
49// pulls out the first input from a useForm() call
50function useFirstOf({ inputs, setValue, ...rest }, mapper = identity) {
51 // ask the mapper function for any values to overwrite
56 // memoize the setValue callback for manually setting the value
57 // in response to some imperative event
58 const _setValue = useCallback(value => setValue(input.name, value), [
63 // provide the first input as the first element
64 // _and_ as the second element to facilitate destructuring
65 // and then provide the pass/error/setValue/etc properties at the end
76export function usePassphraseInput(props) {
82 placeholder: 'Passphrase',
89export function useHexInput({ length, ...rest }) {
93 type: 'text', // or password
95 placeholder: EXAMPLE_PRIVATE_KEY,
99 validateLength(length + 2),
110const kExampleMnemonic = bip39.generateMnemonic();
111const kMnemonicValidators = [validateMnemonic, validateNotEmpty];
112export function useMnemonicInput(props) {
118 placeholder: `e.g. ${kExampleMnemonic}`,
119 validators: kMnemonicValidators,
126export function useHdPathInput(props) {
132 placeholder: `e.g. ${DEFAULT_HD_PATH}`,
139const kTicketValidators = [validateTicket, validateNotEmpty];
140const kTicketTransformers = [prependSig];
141//TODO needs to be fancier, displaying sig and dashes instead of •ing all
142export function useTicketInput({ validators = [], deriving = false, ...rest }) {
148 placeholder: '~ragtyd-modwen-bostec-hinsep',
149 validators: useMemo(() => [...validators, ...kTicketValidators], [
152 transformers: kTicketTransformers,
157 ({ error, pass }) => ({
159 <AccessoryIcon.Failure />
161 <AccessoryIcon.Pending />
163 <AccessoryIcon.Success />
169const kPointValidators = [validatePoint, validateNotEmpty];
170const kPointTransformers = [prependSig];
171export function usePointInput(rest) {
172 const [lastValidPoint, setLastValidPoint] = useState('');
178 placeholder: 'e.g. ~zod',
179 validators: kPointValidators,
180 transformers: kPointTransformers,
182 onValue: setLastValidPoint,
186 ({ error, pass, focused }) => ({
187 accessory: lastValidPoint ? (
189 patp={lastValidPoint}
201export function useCheckboxInput({ initialValue, ...rest }) {
212const kEmailValidators = [validateEmail, validateNotEmpty];
213export const buildEmailInputConfig = extra => ({
216 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