import React, { useCallback, useMemo } from 'react'; import cn from 'classnames'; import { Grid, Text } from 'indigo-react'; import * as azimuth from 'azimuth-js'; import { useNetwork } from 'store/network'; import { usePointCursor } from 'store/pointCursor'; import { usePointCache } from 'store/pointCache'; import { useStarReleaseCache } from 'store/starRelease'; import * as need from 'lib/need'; import { useLocalRouter } from 'lib/LocalRouter'; import useCurrentPointName from 'lib/useCurrentPointName'; import useEthereumTransaction from 'lib/useEthereumTransaction'; import { GAS_LIMITS } from 'lib/constants'; import ViewHeader from 'components/ViewHeader'; import NoticeBox from 'components/NoticeBox'; import InlineEthereumTransaction from 'components/InlineEthereumTransaction'; import { AddressInput } from 'form/Inputs'; import { composeValidator, buildAddressValidator } from 'form/validators'; import BridgeForm from 'form/BridgeForm'; import FormError from 'form/FormError'; function useTransfer() { const { contracts } = useNetwork(); const { pointCursor } = usePointCursor(); const { syncDetails } = usePointCache(); const _contracts = need.contracts(contracts); const _point = need.point(pointCursor); return useEthereumTransaction( useCallback( address => azimuth.ecliptic.setTransferProxy(_contracts, _point, address), [_contracts, _point] ), useCallback(() => syncDetails(_point), [_point, syncDetails]), GAS_LIMITS.SET_PROXY ); } export default function AdminTransfer() { const { pop } = useLocalRouter(); const name = useCurrentPointName(); const { pointCursor } = usePointCursor(); const { starReleaseDetails } = useStarReleaseCache(); const { construct, unconstruct, completed, inputsLocked, bind, } = useTransfer(); const needLockupWarning = useMemo(() => { const point = need.point(pointCursor); const az = azimuth.azimuth; return ( az.getPointSize(point) === az.PointSize.Galaxy && starReleaseDetails.map(a => a.kind).getOrElse('none') !== 'none' ); }, [pointCursor, starReleaseDetails]); const validate = useMemo( () => composeValidator({ address: buildAddressValidator() }), [] ); const onValues = useCallback( ({ valid, values }) => { if (valid) { construct(values.address); } else { unconstruct(); } }, [construct, unconstruct] ); return ( Transfer Point {({ handleSubmit, values }) => ( <> {!completed && ( Transfer {name} to a new owner. )} {!completed && needLockupWarning && ( You have stars in lockup. These will not transfer with the{' '} galaxy. If you wish, you must transfer the lockup separately. )} {completed && ( <> Started transferring {name} to{' '} {values.address} Until they accept the transfer, you still own{' '} {name} )} {!completed && ( )} pop()} /> )} ); }