1import React, { useCallback, useEffect, useState } from 'react';
2import cn from 'classnames';
3import { Grid, Text, Input, Flex, LinkButton } 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 } from 'lib/wallet';
18import capitalize from 'lib/capitalize';
19import { useAddressInput } 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, 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 return details.votingProxy;
38 throw new Error(`Unknown proxyType: ${proxyType}`);
42function useSetProxy(proxyType, address) {
43 const { contracts } = useNetwork();
44 const { pointCursor } = usePointCursor();
45 const { syncOwnedPoint } = usePointCache();
47 const _contracts = need.contracts(contracts);
48 const _point = need.point(pointCursor);
50 const [isUnsetting, setUnsetting] = useState(false);
52 const buildUnsignedTx = useCallback(
54 const txArgs = [_contracts, _point, address];
57 case PROXY_TYPE.MANAGEMENT:
58 return azimuth.ecliptic.setManagementProxy(...txArgs);
59 case PROXY_TYPE.SPAWN:
60 return azimuth.ecliptic.setSpawnProxy(...txArgs);
61 case PROXY_TYPE.TRANSFER:
62 return azimuth.ecliptic.setTransferProxy(...txArgs);
63 case PROXY_TYPE.VOTING:
64 return azimuth.ecliptic.setVotingProxy(...txArgs);
66 throw new Error(`Unknown proxyType ${proxyType}`);
69 [_contracts, _point, proxyType]
75 construct: _construct,
86 } = useEthereumTransaction(GAS_LIMITS.SET_PROXY);
88 // sync point details after success
91 syncOwnedPoint(_point);
93 }, [_point, confirmed, syncOwnedPoint]);
95 // construct the unsigned transaction when we have a valid address
96 const construct = useCallback(
97 address => _construct(buildUnsignedTx(address)),
98 [_construct, buildUnsignedTx]
102 const unset = useCallback(() => {
104 _construct(buildUnsignedTx(ETH_ZERO_ADDR));
105 }, [_construct, buildUnsignedTx]);
111 inputsLocked: inputsLocked || isUnsetting,
116export default function AdminSetProxy() {
117 const { data, pop } = useLocalRouter();
118 const { getDetails } = usePointCache();
119 const { pointCursor } = usePointCursor();
120 const point = need.point(pointCursor);
121 const details = need.details(getDetails(point));
123 const properProxyType = capitalize(proxyTypeToHuman(data.proxyType));
125 const { construct, unset, inputsLocked, bind } = useSetProxy(data.proxyType);
126 const [addressInput, { pass, data: address }] = useAddressInput({
128 label: `New ${properProxyType} Address`,
129 disabled: inputsLocked,
136 }, [pass, address, construct]);
138 const proxyAddress = proxyFromDetails(details, data.proxyType);
139 const isProxySet = !eqAddr(ETH_ZERO_ADDR, proxyAddress);
143 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
144 <Grid.Item full as={ViewHeader}>
145 {properProxyType} Address
147 <Grid.Item full as={Text} className="mb4">
148 {proxyTypeToHumanDescription(data.proxyType)}
150 <Grid.Item full as={Text} className="f6 mb1">
151 Current {properProxyType} Address
153 <Grid.Item full as={Flex} row justify="between" align="center">
158 'mono black': isProxySet,
161 {isProxySet ? proxyAddress : 'Unset'}
164 <Flex.Item as={LinkButton} onClick={unset} disabled={inputsLocked}>
170 <Grid.Item full as={Input} {...addressInput} className="mv4" />
172 <Grid.Item full as={InlineEthereumTransaction} {...bind} />
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