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 MiniBackButton from 'components/MiniBackButton';
24import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
25import { GAS_LIMITS } from 'lib/constants';
27const proxyFromDetails = (details, contracts, proxyType) => {
29 case PROXY_TYPE.MANAGEMENT:
30 return details.managementProxy;
31 case PROXY_TYPE.SPAWN:
32 return details.spawnProxy;
33 case PROXY_TYPE.TRANSFER:
34 return details.transferProxy;
35 case PROXY_TYPE.VOTING:
36 if (eqAddr(details.votingProxy, contracts.delegatedSending.address)) {
37 return `${details.votingProxy} (invites contract)`;
39 return details.votingProxy;
42 throw new Error(`Unknown proxyType: ${proxyType}`);
46function useSetProxy(proxyType) {
47 const { contracts } = useNetwork();
48 const { pointCursor } = usePointCursor();
49 const { syncDetails } = usePointCache();
51 const _contracts = need.contracts(contracts);
52 const _point = need.point(pointCursor);
54 const { construct, ...rest } = useEthereumTransaction(
57 const txArgs = [_contracts, _point, address];
60 case PROXY_TYPE.MANAGEMENT:
61 return azimuth.ecliptic.setManagementProxy(...txArgs);
62 case PROXY_TYPE.SPAWN:
63 return azimuth.ecliptic.setSpawnProxy(...txArgs);
64 case PROXY_TYPE.TRANSFER:
65 return azimuth.ecliptic.setTransferProxy(...txArgs);
66 case PROXY_TYPE.VOTING:
67 return azimuth.ecliptic.setVotingProxy(...txArgs);
69 throw new Error(`Unknown proxyType ${proxyType}`);
72 [_contracts, _point, proxyType]
74 useCallback(() => syncDetails(_point), [_point, syncDetails]),
79 const unset = useCallback(() => {
80 construct(ETH_ZERO_ADDR);
90export default function AdminSetProxy() {
91 const { data, pop } = useLocalRouter();
92 const { getDetails } = usePointCache();
93 const { pointCursor } = usePointCursor();
94 const { contracts } = useNetwork();
96 const _point = need.point(pointCursor);
97 const _details = need.details(getDetails(_point));
98 const _contracts = need.contracts(contracts);
100 const properProxyType = capitalize(proxyTypeToHuman(data.proxyType));
109 } = useSetProxy(data.proxyType);
111 const [unsetInput, { data: isUnsetting }] = useCheckboxInput({
114 inverseLabel: 'Specify',
116 disabled: inputsLocked,
120 { pass: validAddress, data: address },
121 { reset: resetAddress },
122 ] = useAddressInput({
124 label: `New ${properProxyType} Address`,
125 disabled: inputsLocked || isUnsetting,
132 } else if (validAddress) {
147 const proxyAddress = proxyFromDetails(_details, _contracts, data.proxyType);
148 const isProxySet = !isZeroAddress(proxyAddress);
150 const proxyAddressLabel = `${
151 completed ? 'New' : 'Current'
152 } ${properProxyType} Address`;
156 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
158 <Grid.Item full as={ViewHeader}>
159 {properProxyType} Address
162 <Grid.Item full as={Text} className="mb4 f5">
163 {proxyTypeToHumanDescription(data.proxyType)}
169 className={cn('f6 mb1', {
175 <Grid.Item full as={Flex} row justify="between" align="center">
179 className={cn('mono', {
180 black: !completed && isProxySet,
181 gray4: !completed && !isProxySet,
184 {isProxySet ? proxyAddress : 'Unset'}
186 {!completed && isProxySet && (
187 <Flex.Item as={ToggleInput} {...unsetInput} />
192 <Grid.Item full className="mb4" />
194 <Grid.Item full as={Input} {...addressInput} className="mv4" />
199 as={InlineEthereumTransaction}
201 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