1import React, { useCallback, useMemo } from 'react';
2import { AccessoryIcon, useForm } from 'indigo-react';
3import { identity } from 'lodash';
4import * as bip39 from 'bip39';
6import { DEFAULT_HD_PATH } from 'lib/wallet';
16 validateMaximumPatpByteLength,
17 validateEthereumAddress,
18 validateNotNullAddress,
20} from 'lib/validators';
21import { prependSig, convertToNumber } from 'lib/transformers';
23import InputSigil from 'components/InputSigil';
25const EXAMPLE_PRIVATE_KEY =
26 '0xa44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
28// pulls out the first input from a useForm() call
29function useFirstOf({ inputs, setValue, ...rest }, mapper = identity) {
30 // ask the mapper function for any values to overwrite
35 // memoize the setValue callback for manually setting the value
36 // in response to some imperative event
37 const _setValue = useCallback(value => setValue(input.name, value), [
42 // provide the first input as the first element
43 // _and_ as the second element to facilitate destructuring
44 // and then provide the pass/error/setValue/etc properties at the end
55export function usePassphraseInput(props) {
61 placeholder: 'Passphrase',
68export function useHexInput({ length, ...rest }) {
72 type: 'text', // or password
74 placeholder: `e.g. ${EXAMPLE_PRIVATE_KEY}`,
78 validateLength(length + 2),
89const kExampleMnemonic = bip39.generateMnemonic();
90const kMnemonicValidators = [validateMnemonic, validateNotEmpty];
91export function useMnemonicInput(props) {
97 placeholder: `e.g. ${kExampleMnemonic}`,
98 validators: kMnemonicValidators,
105export function useHdPathInput(props) {
111 placeholder: `e.g. ${DEFAULT_HD_PATH}`,
118const kTicketValidators = [validateTicket, validateNotEmpty];
119//TODO needs to be fancier, displaying sig and dashes instead of •ing all
120const kTicketTransformers = [prependSig];
121export function useTicketInput({ validators = [], deriving = false, ...rest }) {
127 placeholder: 'e.g. ~ragtyd-modwen-bostec-hinsep',
128 validators: useMemo(() => [...validators, ...kTicketValidators], [
131 transformers: kTicketTransformers,
136 ({ error, pass }) => ({
138 <AccessoryIcon.Failure />
140 <AccessoryIcon.Pending />
142 <AccessoryIcon.Success />
148const kPointTransformers = [prependSig];
149export function usePointInput({ size = 4, validators = [], ...rest }) {
150 const _validators = useMemo(
154 validateMaximumPatpByteLength(size),
165 placeholder: 'e.g. ~zod',
166 validators: _validators,
167 transformers: kPointTransformers,
172 ({ error, pass, focused, value }) => ({
187export function useGalaxyInput(props) {
188 return usePointInput({
189 label: 'Galaxy Name',
195export function useCheckboxInput({ initialValue, ...rest }) {
206export function useSelectInput({ initialValue, options, ...rest }) {
214 options.map(option => option.value),
221 initialValue: initialValue || options[0].value,
228const kAddressValidators = [
229 validateEthereumAddress,
230 validateNotNullAddress,
233export function useAddressInput({ ...rest }) {
238 label: 'Ethereum Address',
239 placeholder: 'e.g. 0x6DEfFb0caFDB11D175F123F6891AA64F01c24F7d',
241 validators: kAddressValidators,
249const kNumberTransformers = [convertToNumber];
250const kNumberValidators = [validateGreaterThan(0)];
251export function useNumberInput({ ...rest }) {
258 transformers: kNumberTransformers,
259 validators: kNumberValidators,
266const kEmailValidators = [validateEmail, validateNotEmpty];
267export const buildEmailInputConfig = extra => ({
270 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