1import React, { useCallback, useEffect } from 'react';
2import cn from 'classnames';
3import { Grid, Text, Input, Flex, ToggleInput } from 'indigo-react';
4import * as azimuth from 'azimuth-js';
6import { useNetwork } from 'store/network';
7import { usePointCache } from 'store/pointCache';
8import { usePointCursor } from 'store/pointCursor';
13 proxyTypeToHumanDescription,
15import * as need from 'lib/need';
16import { useLocalRouter } from 'lib/LocalRouter';
17import { ETH_ZERO_ADDR, eqAddr, isZeroAddress } from 'lib/wallet';
18import capitalize from 'lib/capitalize';
19import { useAddressInput, useCheckboxInput } from 'lib/useInputs';
20import useEthereumTransaction from 'lib/useEthereumTransaction';
22import ViewHeader from 'components/ViewHeader';
23import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
24import { GAS_LIMITS } from 'lib/constants';
26const proxyFromDetails = (details, contracts, proxyType) => {
28 case PROXY_TYPE.MANAGEMENT:
29 return details.managementProxy;
30 case PROXY_TYPE.SPAWN:
31 return details.spawnProxy;
32 case PROXY_TYPE.TRANSFER:
33 return details.transferProxy;
34 case PROXY_TYPE.VOTING:
35 if (eqAddr(details.votingProxy, contracts.delegatedSending.address)) {
36 return `${details.votingProxy} (invites contract)`;
38 return details.votingProxy;
41 throw new Error(`Unknown proxyType: ${proxyType}`);
45function useSetProxy(proxyType) {
46 const { contracts } = useNetwork();
47 const { pointCursor } = usePointCursor();
48 const { syncDetails } = usePointCache();
50 const _contracts = need.contracts(contracts);
51 const _point = need.point(pointCursor);
53 const { construct, ...rest } = useEthereumTransaction(
56 const txArgs = [_contracts, _point, address];
59 case PROXY_TYPE.MANAGEMENT:
60 return azimuth.ecliptic.setManagementProxy(...txArgs);
61 case PROXY_TYPE.SPAWN:
62 return azimuth.ecliptic.setSpawnProxy(...txArgs);
63 case PROXY_TYPE.TRANSFER:
64 return azimuth.ecliptic.setTransferProxy(...txArgs);
65 case PROXY_TYPE.VOTING:
66 return azimuth.ecliptic.setVotingProxy(...txArgs);
68 throw new Error(`Unknown proxyType ${proxyType}`);
71 [_contracts, _point, proxyType]
73 useCallback(() => syncDetails(_point), [_point, syncDetails]),
78 const unset = useCallback(() => {
79 construct(ETH_ZERO_ADDR);
89export default function AdminSetProxy() {
90 const { data, pop } = useLocalRouter();
91 const { getDetails } = usePointCache();
92 const { pointCursor } = usePointCursor();
93 const { contracts } = useNetwork();
95 const _point = need.point(pointCursor);
96 const _details = need.details(getDetails(_point));
97 const _contracts = need.contracts(contracts);
99 const properProxyType = capitalize(proxyTypeToHuman(data.proxyType));
108 } = useSetProxy(data.proxyType);
110 const [unsetInput, { data: isUnsetting }] = useCheckboxInput({
113 inverseLabel: 'Specify',
115 disabled: inputsLocked,
119 { pass: validAddress, data: address },
120 { reset: resetAddress },
121 ] = useAddressInput({
123 label: `New ${properProxyType} Address`,
124 disabled: inputsLocked || isUnsetting,
131 } else if (validAddress) {
146 const proxyAddress = proxyFromDetails(_details, _contracts, data.proxyType);
147 const isProxySet = !isZeroAddress(proxyAddress);
149 const proxyAddressLabel = `${
150 completed ? 'New' : 'Current'
151 } ${properProxyType} Address`;
155 <Grid.Item full as={ViewHeader}>
156 {properProxyType} Address
159 <Grid.Item full as={Text} className="mb4 f5">
160 {proxyTypeToHumanDescription(data.proxyType)}
166 className={cn('f6 mb1', {
172 <Grid.Item full as={Flex} row justify="between" align="center">
176 className={cn('mono', {
177 black: !completed && isProxySet,
178 gray4: !completed && !isProxySet,
181 {isProxySet ? proxyAddress : 'Unset'}
183 {!completed && isProxySet && (
184 <Flex.Item as={ToggleInput} {...unsetInput} />
189 <Grid.Item full className="mb4" />
191 <Grid.Item full as={Input} {...addressInput} className="mv4" />
196 as={InlineEthereumTransaction}
198 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