1import * as need from 'lib/need';
2import CopiableAddress from 'components/copiable/CopiableAddress';
3import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
4import NoticeBox from 'components/NoticeBox';
5import BridgeForm from 'form/BridgeForm';
6import FormError from 'form/FormError';
7import { AddressInput } from 'form/Inputs';
8import { composeValidator } from 'form/validators';
9import { Grid, Flex } from 'indigo-react';
10import { useCallback, useEffect, useMemo } from 'react';
11import { useHistory } from 'store/history';
12import { useNetwork } from 'store/network';
13import { useStarReleaseCache } from 'store/starRelease';
14import { useWallet } from 'store/wallet';
15import { eqAddr, isZeroAddress } from 'lib/utils/address';
16import { useTransferLockup } from './useTransferLockup';
17import { isValidAddress } from '@ethereumjs/util';
18import { getLockupKind } from 'lib/starRelease';
20interface TransferFormProps {
21 afterSubmit: VoidFunction;
24export const TransferForm = ({ afterSubmit }: TransferFormProps) => {
25 const { wallet }: any = useWallet();
26 const { contracts }: any = useNetwork();
27 const { pop }: any = useHistory();
28 const address = need.addressFromWallet(wallet);
31 syncStarReleaseDetails,
33 }: any = useStarReleaseCache();
36 syncStarReleaseDetails();
37 }, [syncStarReleaseDetails]);
39 const kind = useMemo(() => {
40 return starReleaseDetails.map((a: any) => a.kind).getOrElse('') ===
44 }, [starReleaseDetails]);
46 const approvedFor = useMemo(() => {
48 if (kind === 'conditional') {
49 approved = starReleaseDetails.map(
50 (a: any) => a.conditional.approvedTransferTo
53 approved = starReleaseDetails.map(
54 (a: any) => a.linear.approvedTransferTo
57 approved = approved.getOrElse('0x0');
58 if (isZeroAddress(approved) || eqAddr(approved, address)) {
63 }, [starReleaseDetails, kind, address]);
71 } = useTransferLockup(kind);
73 const onValues = useCallback(
74 async ({ valid, values }) => {
81 [construct, unconstruct]
84 const validate = useMemo(
87 to: async (to: string) => {
88 if (!isValidAddress(to)) {
89 return 'This is not a valid Ethereum address.';
91 const theirs = await getLockupKind(need.contracts(contracts), to);
92 if (theirs === kind || theirs === 'both') {
93 return `Target address already owns a ${kind} lockup.`;
102 <BridgeForm onValues={onValues} validate={validate}>
103 {({ values }: any) => (
107 <Grid.Item full className="f5">
108 Allow the specified address to take over your {kind} lockup.
110 After they accept the transfer, you will no longer be able to{' '}
111 withdraw from this lockup.
114 <Grid.Item full as={NoticeBox}>
115 Transfer currently approved for{' '}
116 <CopiableAddress>{approvedFor}</CopiableAddress>
119 <Grid.Item full className="f5" cols={[1, 13]} as={Flex} col>
123 label="Approve transfer to"
124 disabled={inputsLocked}
130 <Grid.Item full as={FormError} />
133 <Grid.Item full className="pv4">
134 <CopiableAddress>{values.to}</CopiableAddress> is now allowed{' '}
135 to take ownership of this lockup. They can do so by visiting:
137 <Grid.Item full as="code" className="f5 mb4 mono wrap">
138 https://bridge.urbit.org/?kind=takeLockup&lock={kind}
146 as={InlineEthereumTransaction}
148 label="Approve Transfer"
149 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