1import React, { useCallback, useMemo } from 'react';
2import { AccessoryIcon, useForm } from 'indigo-react';
3import { identity } from 'lodash';
5import { DEFAULT_HD_PATH } from 'lib/wallet';
15 validateMaximumPatpByteLength,
16 validateEthereumAddress,
17 validateNotNullAddress,
19} from 'lib/validators';
20import { prependSig, convertToNumber } from 'lib/transformers';
22import InputSigil from 'components/InputSigil';
24const PLACEHOLDER_POINT = '~sampel-ponnym';
25const PLACEHOLDER_HD_PATH = DEFAULT_HD_PATH;
26const PLACEHOLDER_MNEMONIC =
27 'example crew supreme gesture quantum web media hazard theory mercy wing kitten';
28const PLACEHOLDER_TICKET = '~sampel-ticlyt-migfun-falmel';
29const PLACEHOLDER_ADDRESS = '0x12345abcdeDB11D175F123F6891AA64F01c24F7d';
30const PLACEHOLDER_PRIVATE_KEY =
31 '0x12345abcdee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
33// pulls out the first input from a useForm() call
34function useFirstOf({ inputs, setValue, ...rest }, mapper = identity) {
35 // ask the mapper function for any values to overwrite
40 // memoize the setValue callback for manually setting the value
41 // in response to some imperative event
42 const _setValue = useCallback(value => setValue(input.name, value), [
47 // provide the first input as the first element
48 // _and_ as the second element to facilitate destructuring
49 // and then provide the pass/error/setValue/etc properties at the end
60export function usePassphraseInput(props) {
66 placeholder: 'Passphrase',
73export function useHexInput({ length, ...rest }) {
77 type: 'text', // or password
79 placeholder: PLACEHOLDER_PRIVATE_KEY,
83 validateLength(length + 2),
94const kMnemonicValidators = [validateMnemonic, validateNotEmpty];
95export function useMnemonicInput(props) {
101 placeholder: PLACEHOLDER_MNEMONIC,
102 validators: kMnemonicValidators,
109export function useHdPathInput(props) {
115 placeholder: PLACEHOLDER_HD_PATH,
122const kTicketValidators = [validateTicket, validateNotEmpty];
123//TODO needs to be fancier, displaying sig and dashes instead of •ing all
124const kTicketTransformers = [prependSig];
125export function useTicketInput({ validators = [], deriving = false, ...rest }) {
131 placeholder: PLACEHOLDER_TICKET,
132 validators: useMemo(() => [...validators, ...kTicketValidators], [
135 transformers: kTicketTransformers,
140 ({ error, pass }) => ({
142 <AccessoryIcon.Failure />
144 <AccessoryIcon.Pending />
146 <AccessoryIcon.Success />
152const kPointTransformers = [prependSig];
153export function usePointInput({ size = 4, validators = [], ...rest }) {
154 const _validators = useMemo(
158 validateMaximumPatpByteLength(size),
169 placeholder: PLACEHOLDER_POINT,
170 validators: _validators,
171 transformers: kPointTransformers,
176 ({ error, pass, focused, value }) => ({
191export function useGalaxyInput(props) {
192 return usePointInput({
193 label: 'Galaxy Name',
199export function useCheckboxInput({ initialValue, ...rest }) {
210export function useSelectInput({ initialValue, options, ...rest }) {
218 options.map(option => option.value),
225 initialValue: initialValue || options[0].value,
232const kAddressValidators = [
233 validateEthereumAddress,
234 validateNotNullAddress,
237export function useAddressInput({ ...rest }) {
242 label: 'Ethereum Address',
243 placeholder: PLACEHOLDER_ADDRESS,
245 validators: kAddressValidators,
253const kNumberTransformers = [convertToNumber];
254const kNumberValidators = [validateGreaterThan(0)];
255export function useNumberInput({ ...rest }) {
262 transformers: kNumberTransformers,
263 validators: kNumberValidators,
270const kEmailValidators = [validateEmail, validateNotEmpty];
271export const buildEmailInputConfig = extra => ({
274 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