@@ -0,0 +1,212 @@
1+import React, { useState, useCallback, useMemo, useEffect } from 'react';
2+
3+import { useNetwork } from 'store/network';
4+import { useWallet } from 'store/wallet';
5+import { useHistory } from 'store/history';
6+import { usePointCursor } from 'store/pointCursor';
7+
8+import * as need from 'lib/need';
9+import useLifecycle from 'lib/useLifecycle';
10+import useBlockWindowClose from 'lib/useBlockWindowClose';
11+import { reticketPointBetweenWallets } from 'lib/reticket';
12+
13+import { Anchor, Box, Text } from '@tlon/indigo-react';
14+import { useActivateFlow } from './ActivateFlow';
15+import ActivateView from './ActivateView';
16+import { POINT_DOMINIONS } from 'lib/constants';
17+import { From } from '@urbit/roller-api';
18+import useRoller from 'lib/useRoller';
19+import { FadeableActivateHeader as ActivateHeader } from './ActivateHeader';
20+import { FadeableActivateButton as ActivateButton } from './ActivateButton';
21+import useFadeIn from './useFadeIn';
22+import PointPresenter from './PointPresenter';
23+
24+const MasterKeyTransfer = ({ className, resetActivateRouter }) => {
25+ const { replaceWith, names } = useHistory();
26+ const { setUrbitWallet } = useWallet();
27+ const { setPointCursor } = usePointCursor();
28+ const { web3, contracts, networkType } = useNetwork();
29+ const { api, transferPoint } = useRoller();
30+ const {
31+ derivedPatp,
32+ derivedPoint,
33+ derivedPointDominion,
34+ derivedWallet,
35+ inviteWallet,
36+ reset: resetActivateFlow,
37+ } = useActivateFlow();
38+ const [generalError, setGeneralError] = useState();
39+ const [progress, setProcesss] = useState(0);
40+ const [needFunds, setNeedFunds] = useState();
41+
42+ // const [transferTxHash, setTransferTxHash] = useState<string | null>(null);
43+
44+ const _inviteWallet = need.wallet(inviteWallet);
45+ const _wallet = need.wallet(derivedWallet);
46+ const _point = need.point(derivedPoint);
47+ const _web3 = need.web3(web3);
48+ const _contracts = need.contracts(contracts);
49+
50+ const goToLogin = useCallback(
51+ () => replaceWith([{ key: names.LOGIN }, { key: names.POINT }]),
52+ [replaceWith, names]
53+ );
54+
55+ const goToRestart = useCallback(() => {
56+ // NOTE: because we're already on the ACTIVATE view in the history,
57+ // react (intelligently) doesn't trigger a re-render and that means the
58+ // current state of the two nested routers (activate & passport) stick
59+ // around unless we manually clear them.
60+ // we only need to clear activate because that will unmount the passport
61+ // router (which will be set to initialRoutes when mounted again)
62+
63+ // 2) reset local router
64+ resetActivateRouter();
65+ // 3) clear the state
66+ resetActivateFlow();
67+ }, [resetActivateRouter, resetActivateFlow]);
68+
69+ const claimL2Point = useCallback(async () => {
70+ console.log('claiming l2 point:');
71+ const transferFrom: From = {
72+ ship: derivedPatp.value,
73+ proxy: 'transfer',
74+ };
75+
76+ const l2point = await api.getPoint(derivedPoint.value);
77+ const fromAddress = l2point.ownership?.owner?.address!;
78+ const txHash = await transferPoint({
79+ point: derivedPoint.value,
80+ from: transferFrom,
81+ to: _inviteWallet.address,
82+ fromAddress: fromAddress,
83+ signingKey: derivedWallet.value.ownership.keys.private,
84+ });
85+
86+ // setTransferTxHash(txHash);
87+ }, [
88+ _inviteWallet.address,
89+ api,
90+ derivedPatp.value,
91+ derivedPoint.value,
92+ derivedWallet.value,
93+ transferPoint,
94+ ]);
95+
96+ // const claimL1Point = useCallback(async () => {
97+ // await reticketPointBetweenWallets({
98+ // fromWallet: _inviteWallet,
99+ // toWallet: _wallet,
100+ // point: _point,
101+ // web3: _web3,
102+ // contracts: _contracts,
103+ // networkType,
104+ // onUpdate: handleUpdate,
105+ // transferEth: true,
106+ // //NOTE not passing wc function, we always have invite ticket wallet
107+ // });
108+ // }, [_contracts, _inviteWallet, _point, _wallet, _web3, networkType]);
109+
110+ const claimPoint = useCallback(async () => {
111+ setGeneralError(false);
112+
113+ try {
114+ // If L2
115+ if (derivedPointDominion.value === POINT_DOMINIONS.L2) {
116+ await claimL2Point();
117+ } else {
118+ // await claimL1Point();
119+ console.log('do nothing for now');
120+ }
121+
122+ // If L1
123+
124+ // set the global wallet
125+ // setUrbitWallet(derivedWallet);
126+ // setPointCursor(derivedPoint);
127+
128+ // and redirect to login
129+ // await timeout(3000);
130+ // goToLogin();
131+ } catch (error) {
132+ console.error(error);
133+ // some generic error
134+ setGeneralError(error);
135+ }
136+ }, [derivedPointDominion, claimL2Point]);
137+
138+ // useBlockWindowClose();
139+ useFadeIn();
140+
141+ useLifecycle(() => {
142+ claimPoint();
143+ });
144+
145+ const header = useMemo(() => {
146+ return (
147+ <ActivateHeader
148+ content={
149+ <>
150+ Congratulations{' '}
151+ <Text fontFamily="Source Code Pro" fontSize={3} fontWeight={600}>
152+ {derivedPatp.value}
153+ </Text>{' '}
154+ is now yours
155+ </>
156+ }
157+ />
158+ );
159+ }, [derivedPatp.value]);
160+
161+ const footer = useMemo(() => {
162+ return (
163+ <Box
164+ display={'flex'}
165+ flexDirection={'column'}
166+ flexWrap={'nowrap'}
167+ justifyContent={'space-between'}>
168+ <ActivateButton
169+ onClick={() =>
170+ window.open(
171+ 'https://github.com/urbit/port/releases/latest/download/Port.dmg'
172+ )
173+ }
174+ success={true}>
175+ Download the Client for Mac
176+ </ActivateButton>
177+ <Anchor
178+ href="https://urbit.org/getting-started/cli"
179+ marginTop={'20px'}
180+ marginBottom={'10px'}
181+ underline={false}
182+ fontFamily={'Inter'}
183+ fontSize={'14px'}
184+ fontWeight={'500'}
185+ lineHeight={'16px'}
186+ textAlign={'center'}>
187+ or setup via command line
188+ </Anchor>
189+ </Box>
190+ );
191+ }, []);
192+
193+ return (
194+ <ActivateView header={header} footer={footer}>
195+ <Box
196+ alignItems={'center'}
197+ display={'flex'}
198+ flexDirection={'column'}
199+ flexWrap={'nowrap'}
200+ height={'100%'}
201+ justifyContent={'center'}>
202+ <PointPresenter
203+ patp={derivedPatp.value}
204+ showLabel={false}
205+ success={true}
206+ />
207+ </Box>
208+ </ActivateView>
209+ );
210+};
211+
212+export default MasterKeyTransfer;