@@ -1,6 +1,7 @@
1import React, { useCallback, useEffect, useMemo } from 'react';
1import React, { useCallback, useEffect, useMemo } from 'react';
2import cn from 'classnames';
2import cn from 'classnames';
3import { Grid, Flex } from 'indigo-react';
3import { Grid, Flex } from 'indigo-react';
4+import { Just } from 'folktale/maybe';
5import * as need from 'lib/need';
6import * as need from 'lib/need';
6import useEthereumTransaction from 'lib/useEthereumTransaction';
7import useEthereumTransaction from 'lib/useEthereumTransaction';
@@ -11,6 +12,7 @@ import { usePointCache } from 'store/pointCache';
11import { useStarReleaseCache } from 'store/starRelease';
12import { useStarReleaseCache } from 'store/starRelease';
13import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
14import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
15+import { matchBlinky } from 'components/Blinky';
15import { NumberInput, AddressInput } from 'form/Inputs';
17import { NumberInput, AddressInput } from 'form/Inputs';
16import BridgeForm from 'form/BridgeForm';
18import BridgeForm from 'form/BridgeForm';
@@ -18,6 +20,24 @@ import FormError from 'form/FormError';
18import { composeValidator, buildNumberValidator } from 'form/validators';
20import { composeValidator, buildNumberValidator } from 'form/validators';
19import { convertToNumber } from 'form/formatters';
21import { convertToNumber } from 'form/formatters';
23+function MatchPluralizeStars({ quantity }) {
24+ const _quantity = quantity.getOrElse(0);
25+ console.log(quantity);
31+ green2: _quantity > 0,
32+ red4: Just.hasInstance(quantity) && _quantity === 0,
34+ {matchBlinky(quantity)}
36+ {pluralize(_quantity, ' star ', ' stars ')}
21function AddressIndicator({ isOwn, className }) {
41function AddressIndicator({ isOwn, className }) {
22 return isOwn ? (
42 return isOwn ? (
23 <div className={cn('green2', className)}>✓ Current Address</div>
43 <div className={cn('green2', className)}>✓ Current Address</div>
@@ -31,7 +51,7 @@ function useWithdrawStars() {
32 const { syncStarReleaseDetails, withdraw } = useStarReleaseCache();
52 const { syncStarReleaseDetails, withdraw } = useStarReleaseCache();
33 return useEthereumTransaction(
53 return useEthereumTransaction(
34− useCallback((to, amount) => withdraw(amount, to)),
54+ useCallback((to, amount) => withdraw(amount, to), [withdraw]),
35 useCallback(
55 useCallback(
36 () => Promise.all([syncControlledPoints(), syncStarReleaseDetails()]),
56 () => Promise.all([syncControlledPoints(), syncStarReleaseDetails()]),
37 [syncStarReleaseDetails, syncControlledPoints]
57 [syncStarReleaseDetails, syncControlledPoints]
@@ -39,10 +59,17 @@ function useWithdrawStars() {
42−export default function LockedView({ className }) {
62+export default function Locked({ className, goActive }) {
43 const { wallet } = useWallet();
63 const { wallet } = useWallet();
44 const address = need.addressFromWallet(wallet);
64 const address = need.addressFromWallet(wallet);
45− const { bind, construct, unconstruct, inputsLocked } = useWithdrawStars();
72+ } = useWithdrawStars();
47 const { syncStarReleaseDetails, starReleaseDetails } = useStarReleaseCache();
74 const { syncStarReleaseDetails, starReleaseDetails } = useStarReleaseCache();
@@ -61,79 +88,88 @@ export default function LockedView({ className }) {
61 [construct, unconstruct]
88 [construct, unconstruct]
64− const available = starReleaseDetails
65− .map(b => b.available - b.withdrawn)
91+ const canWithdraw = starReleaseDetails.map(b => b.available - b.withdrawn);
67− const total = starReleaseDetails.map(b => b.total).getOrElse(0);
92+ const total = starReleaseDetails.map(b => b.total);
68− const withdrawn = starReleaseDetails.map(b => b.withdrawn).getOrElse(0);
70 const validate = useMemo(
94 const validate = useMemo(
72− composeValidator({
96+ composeValidator(
73− numStars: buildNumberValidator(0, available + 1),
98+ numStars: buildNumberValidator(0, canWithdraw + 1),
100+ (values, errors) => (inputsLocked ? false : errors)
75− [available]
102+ [canWithdraw, inputsLocked]
78 const initialValues = { address };
105 const initialValues = { address };
81− <Grid gap={6} className={cn('mt4', className)} full>
108+ <Grid gap={completed ? 0 : 6} className={cn('mt4', className)} full>
82 <BridgeForm
109 <BridgeForm
83 initialValues={initialValues}
110 initialValues={initialValues}
84 onValues={onValues}
111 onValues={onValues}
85 validate={validate}>
112 validate={validate}>
86− {({ values, reset }) => (
113+ {({ values, form }) => (
88− <Grid.Item full className="f5">
117+ <Grid.Item full className="f5">
89− You have{' '}
118+ You have <MatchPluralizeStars quantity={canWithdraw} />
92− green2: available > 0,
93− red4: available === 0,
97− {pluralize(available, ' star ', ' stars ')}
98− available to withdraw
119+ available to withdraw
100− You have <span className="green2">{total - withdrawn}</span>
121+ You have
101− {pluralize(available, ' star ', ' stars ')}
122+ <MatchPluralizeStars quantity={total} />
103− </Grid.Item>
124+ </Grid.Item>
131+ disabled={inputsLocked}
133+ <div className="flex-center h-full">
134+ / {matchBlinky(canWithdraw)}
104− <Grid.Item full className="f5" cols={[1, 10]} as={Flex} col>
138+ <Grid.Item full className="f5" cols={[1, 13]} as={Flex} col>
105− <Flex.Item
139+ <Flex.Item
106− name="address"
140+ name="address"
107− as={AddressInput}
141+ as={AddressInput}
108− label="Withdraw To"
142+ label="Withdraw To"
109− disabled={inputsLocked}
143+ disabled={inputsLocked}
111− <Flex.Item
145+ <Flex.Item
112− as={AddressIndicator}
146+ as={AddressIndicator}
113− isOwn={address === values.address}
147+ isOwn={address === values.address}
115− </Grid.Item>
149+ </Grid.Item>
120− style={{ minWidth: '0' }}
124− disabled={inputsLocked}
126− <Grid.Item as={Flex} col cols={[5, 8]}>
127− <Flex.Item className="f6 lh-tall"> </Flex.Item>
128− <Flex.Item className="f3">/ {available}</Flex.Item>
130 <Grid.Item full as={FormError} />
153 <Grid.Item full as={FormError} />
156+ <Grid.Item full className="pv4">
157+ {values.numStars}{' '}
158+ {pluralize(values.numStars, 'star has', 'stars have')} been
131 <Grid.Item
164 <Grid.Item
133 as={InlineEthereumTransaction}
166 as={InlineEthereumTransaction}
134 {...bind}
167 {...bind}
135− onReturn={() => reset()}
136 label="Withdraw Stars"
168 label="Withdraw Stars"