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} from 'lib/validators';
20import { prependSig } from 'lib/transformers';
22const EXAMPLE_PRIVATE_KEY =
23 '0xa44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
25// const RequiredInput = advancedInput({
26// WrappedComponent: Input,
27// validators: [validateNotEmpty],
30// const NetworkKeyInput = advancedInput({
31// WrappedComponent: Input,
32// validators: [validateNotEmpty, validateNetworkKey],
35// const NetworkSeedInput = advancedInput({
36// WrappedComponent: Input,
37// validators: [validateNotEmpty, validateNetworkSeed],
40// const AddressInput = advancedInput({
41// WrappedComponent: Input,
42// validators: [validateEthereumAddress, validateNotEmpty],
45// const GalaxyInput = advancedInput({
46// WrappedComponent: Input,
47// validators: [validateGalaxy, validateNotEmpty],
48// transformers: [prependSig],
51// pulls out the first input from a useForm() call
52function useFirstOf({ inputs, setValue, ...rest }, mapper = identity) {
53 // ask the mapper function for any values to overwrite
58 // memoize the setValue callback for manually setting the value
59 // in response to some imperative event
60 const _setValue = useCallback(value => setValue(input.name, value), [
65 // provide the first input as the first element
66 // _and_ as the second element to facilitate destructuring
67 // and then provide the pass/error/setValue/etc properties at the end
78export function usePassphraseInput(props) {
84 placeholder: 'Passphrase',
91export function useHexInput({ length, ...rest }) {
95 type: 'text', // or password
97 placeholder: EXAMPLE_PRIVATE_KEY,
101 validateLength(length + 2),
112const kExampleMnemonic = bip39.generateMnemonic();
113const kMnemonicValidators = [validateMnemonic, validateNotEmpty];
114export function useMnemonicInput(props) {
120 placeholder: `e.g. ${kExampleMnemonic}`,
121 validators: kMnemonicValidators,
128export function useHdPathInput(props) {
134 placeholder: `e.g. ${DEFAULT_HD_PATH}`,
141const kTicketValidators = [validateTicket, validateNotEmpty];
142const kTicketTransformers = [prependSig];
143//TODO needs to be fancier, displaying sig and dashes instead of •ing all
144export function useTicketInput({ validators = [], deriving = false, ...rest }) {
150 placeholder: '~ragtyd-modwen-bostec-hinsep',
151 validators: useMemo(() => [...validators, ...kTicketValidators], [
154 transformers: kTicketTransformers,
159 ({ error, pass }) => ({
161 <AccessoryIcon.Failure />
163 <AccessoryIcon.Pending />
165 <AccessoryIcon.Success />
171const kPointValidators = [
173 validateMaximumPatpByteLength(4),
176const kPointTransformers = [prependSig];
177export function usePointInput(rest) {
178 const [lastValidPoint, setLastValidPoint] = useState('');
184 placeholder: 'e.g. ~zod',
185 validators: kPointValidators,
186 transformers: kPointTransformers,
188 onValue: setLastValidPoint,
192 ({ error, pass, focused }) => ({
193 accessory: lastValidPoint ? (
195 patp={lastValidPoint}
207export function useCheckboxInput({ initialValue, ...rest }) {
218export function useSelectInput({ initialValue, options, ...rest }) {
226 options.map(option => option.value),
233 initialValue: initialValue || options[0].value,
240const kEmailValidators = [validateEmail, validateNotEmpty];
241export const buildEmailInputConfig = extra => ({
244 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