@@ -1,11 +1,14 @@
1−import React, { useCallback, useMemo } from 'react';
1+import React, { useCallback, useMemo, useState } from 'react';
2import cn from 'classnames';
2import cn from 'classnames';
3−import { Grid, Text, Flex } from 'indigo-react';
3+import { Grid, Text, Flex, Button } from 'indigo-react';
4import * as azimuth from 'azimuth-js';
4import * as azimuth from 'azimuth-js';
6+import './SetProxy.scss';
6import { useNetwork } from 'store/network';
8import { useNetwork } from 'store/network';
7import { usePointCache } from 'store/pointCache';
9import { usePointCache } from 'store/pointCache';
8import { usePointCursor } from 'store/pointCursor';
10import { usePointCursor } from 'store/pointCursor';
11+import { useRollerStore } from 'store/roller';
11 PROXY_TYPE,
14 PROXY_TYPE,
@@ -17,6 +20,7 @@ import { useLocalRouter } from 'lib/LocalRouter';
17import { eqAddr, isZeroAddress } from 'lib/utils/address';
20import { eqAddr, isZeroAddress } from 'lib/utils/address';
18import { capitalize } from 'lib/capitalize';
21import { capitalize } from 'lib/capitalize';
19import useEthereumTransaction from 'lib/useEthereumTransaction';
22import useEthereumTransaction from 'lib/useEthereumTransaction';
23+import useRoller from 'lib/useRoller';
21import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
25import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
22import { ETH_ZERO_ADDR, GAS_LIMITS } from 'lib/constants';
26import { ETH_ZERO_ADDR, GAS_LIMITS } from 'lib/constants';
@@ -29,6 +33,15 @@ import {
29import BridgeForm from 'form/BridgeForm';
33import BridgeForm from 'form/BridgeForm';
30import FormError from 'form/FormError';
34import FormError from 'form/FormError';
36+const getL2ProxyName = proxy =>
37+ proxy === PROXY_TYPE.MANAGEMENT
39+ : proxy === PROXY_TYPE.SPAWN
41+ : proxy === PROXY_TYPE.TRANSFER
32const proxyFromDetails = (details, contracts, proxyType) => {
45const proxyFromDetails = (details, contracts, proxyType) => {
33 switch (proxyType) {
46 switch (proxyType) {
34 case PROXY_TYPE.MANAGEMENT:
47 case PROXY_TYPE.MANAGEMENT:
@@ -97,6 +110,9 @@ export default function SetProxy() {
97 const { getDetails } = usePointCache();
110 const { getDetails } = usePointCache();
98 const { pointCursor } = usePointCursor();
111 const { pointCursor } = usePointCursor();
99 const { contracts } = useNetwork();
112 const { contracts } = useNetwork();
113+ const { currentL2 } = useRollerStore();
114+ const { setProxyAddress, getPendingTransactions } = useRoller();
115+ const [newAddress, setNewAddress] = useState('');
101 const _point = need.point(pointCursor);
117 const _point = need.point(pointCursor);
102 const _details = need.details(getDetails(_point));
118 const _details = need.details(getDetails(_point));
@@ -113,7 +129,30 @@ export default function SetProxy() {
114 } = useSetProxy(data.proxyType);
130 } = useSetProxy(data.proxyType);
132+ const setProxy = useCallback(async () => {
133+ // setLoading(true);
134+ console.log(newAddress);
135+ if (newAddress === '') return;
137+ await setProxyAddress(getL2ProxyName(data.proxyType), newAddress);
138+ getPendingTransactions(_point);
143+ // setLoading(false);
147+ getPendingTransactions,
116 const validateForm = useCallback((values, errors) => {
154 const validateForm = useCallback((values, errors) => {
155+ console.log('hola');
117 if (!values.unset && errors.address) {
156 if (!values.unset && errors.address) {
118 return errors;
157 return errors;
@@ -133,18 +172,21 @@ export default function SetProxy() {
134 const onValues = useCallback(
173 const onValues = useCallback(
135 ({ valid, values, form }) => {
174 ({ valid, values, form }) => {
175+ console.log('currentL2', currentL2);
136 if (valid) {
176 if (valid) {
137 if (values.unset) {
177 if (values.unset) {
139 form.change('address', '');
179 form.change('address', '');
141 construct(values.address);
182 construct(values.address);
183+ setNewAddress(values.address);
144 unconstruct();
186 unconstruct();
147− [construct, unconstruct, unset]
189+ [construct, unconstruct, unset, setNewAddress, currentL2]
150 const initialValues = useMemo(() => ({ unset: false }), []);
192 const initialValues = useMemo(() => ({ unset: false }), []);
@@ -213,12 +255,25 @@ export default function SetProxy() {
214 <Grid.Item full as={FormError} />
256 <Grid.Item full as={FormError} />
216− <Grid.Item
259+ <Grid.Item
262+ className="set-proxy"
265+ disabled={values.unset}
267+ {'Sign Transaction'}
218− as={InlineEthereumTransaction}
272+ as={InlineEthereumTransaction}
219− {...bind}
273+ {...bind}
220− onReturn={() => pop()}
274+ onReturn={() => pop()}
224 </BridgeForm>
279 </BridgeForm>