1import React, { useCallback, useMemo } from 'react';
2import cn from 'classnames';
3import { Grid, Text } from 'indigo-react';
4import * as azimuth from 'azimuth-js';
5import { memoize } from 'lodash';
7import { useNetwork } from 'store/network';
8import { useWallet } from 'store/wallet';
9import { useHistory } from 'store/history';
11import * as need from 'lib/need';
12import useEthereumTransaction from 'lib/useEthereumTransaction';
13import { GAS_LIMITS } from 'lib/constants';
14import { useLocalRouter } from 'lib/LocalRouter';
15import { useFlowCommand } from 'lib/flowCommand';
16import { isValidAddress, eqAddr } from 'lib/utils/address';
18import ViewHeader from 'components/ViewHeader';
19import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
20import View from 'components/View';
22import BridgeForm from 'form/BridgeForm';
23import { AddressInput } from 'form/Inputs';
24import { composeValidator } from 'form/validators';
26function useAcceptLockup() {
27 const { contracts } = useNetwork();
28 const { push, names } = useHistory();
30 const flow = useFlowCommand();
32 const _contracts = need.contracts(contracts);
34 const transaction = useEthereumTransaction(
37 if (flow.lock === 'conditional') {
38 return azimuth.conditionalSR.transferCommitment(_contracts, from);
40 return azimuth.linearSR.transferBatch(_contracts, from);
45 useCallback(() => push(names.STAR_RELEASE), [push, names]),
46 GAS_LIMITS.TRANSFER_LOCKUP
54export default function AcceptLockup() {
55 const { pop } = useLocalRouter();
56 const { contracts } = useNetwork();
57 const { wallet } = useWallet();
58 const flow = useFlowCommand();
60 const _contracts = need.contracts(contracts);
61 const _address = need.addressFromWallet(wallet);
69 } = useAcceptLockup();
71 const initialValues = useMemo(() => {
72 if (!flow.from) return {};
73 return { from: flow.from };
76 const getApproved = useMemo(() => {
77 return memoize(async from => {
78 console.log('------ looking up');
79 const lok = await (flow.lock === 'conditional'
80 ? azimuth.conditionalSR.getCommitment(_contracts, from)
81 : azimuth.linearSR.getBatch(_contracts, from));
82 return lok.approvedTransferTo;
84 }, [flow, _contracts]);
86 const validate = useMemo(
90 if (!isValidAddress(from)) {
91 return 'This is not a valid Ethereum address.';
93 const approved = await getApproved(from);
94 if (!eqAddr(_address, approved)) {
95 return 'Not permitted to take lockup from this address.';
99 [_address, getApproved]
102 const onValues = useCallback(
103 ({ valid, values, form }) => {
105 construct(values.from);
110 [construct, unconstruct]
114 <View pop={pop} inset>
116 <Grid.Item full as={ViewHeader}>
123 className={cn('f5 wrap', {
127 ? `You have accepted the star lockup.`
128 : `Accept the incoming transfer of a star lockup.`}
133 initialValues={initialValues}
140 label="Previous owner of the star lockup"
141 disabled={inputsLocked}
149 as={InlineEthereumTransaction}
151 onReturn={() => pop()}
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