1import cn from 'classnames';
2import { Box, Text } from '@tlon/indigo-react';
3import { AddressButton } from 'components/AddressButton';
4import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
5import BridgeForm from 'form/BridgeForm';
6import { convertToNumber } from 'form/formatters';
7import FormError from 'form/FormError';
8import { AddressInput, NumberInput } from 'form/Inputs';
9import { buildNumberValidator, composeValidator } from 'form/validators';
10import { Grid, Flex } from 'indigo-react';
11import { pluralize } from 'lib/pluralize';
12import { useCallback, useEffect, useMemo } from 'react';
13import { useStarReleaseCache } from 'store/starRelease';
14import { useWithdrawStars } from './useWithdrawStars';
16interface WithdrawFormProps {
17 afterSubmit: VoidFunction;
20export const WithdrawForm = ({ afterSubmit }: WithdrawFormProps) => {
28 } = useWithdrawStars();
31 syncStarReleaseDetails,
33 }: any = useStarReleaseCache();
36 syncStarReleaseDetails();
37 }, [syncStarReleaseDetails]);
39 const onValues = useCallback(
40 ({ valid, values }) => {
42 construct(values.address, convertToNumber(values.numStars));
47 [construct, unconstruct]
50 const canWithdraw = starReleaseDetails.map((b: any) => b.available);
51 const total = starReleaseDetails.map((b: any) => b.total);
53 const validate = useMemo(
57 numStars: buildNumberValidator(0, canWithdraw.getOrElse(0) + 1),
59 (values, errors) => (inputsLocked ? false : errors)
61 [canWithdraw, inputsLocked]
64 const initialValues = {};
69 initialValues={initialValues}
72 afterSubmit={afterSubmit}>
73 {({ values, form }: any) => (
78 className={cn('info-row', {
79 available: canWithdraw.value > 0,
81 <Text>{`${canWithdraw.value} of ${total.value} available`}</Text>
83 <Box className="info-row">
84 <Text>{`${total.value -
85 canWithdraw.value} are in lockup`}</Text>
93 disabled={inputsLocked}
95 <Grid.Item full className="f5" cols={[1, 13]} as={Flex} col>
100 disabled={inputsLocked}
103 <AddressButton inputName="address">
111 <Grid.Item full as={FormError} />
114 <Grid.Item full className="pv4">
115 {values.numStars}{' '}
116 {pluralize(values.numStars, 'star has', 'stars have')} been
124 as={InlineEthereumTransaction}
126 label="Withdraw Stars"
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