on master help sign in
rebase on roller

- resolve imports merge conflict - rename useRoller#acceptInvite - remove unused SegmentedProgressBar

commita5fcdb15049c8346e8361612c0f4007f6e6acdf7 authortomholford <tomholford@users.noreply.github.com> dateSun 19 Sep 2021, 21:50 (5 years ago) parentdaad500
3 files changed+49−54
src/lib/useRoller.ts+38−44 src/views/Activate/ActivateSteps.tsx+1−3 src/views/Activate/MasterKeyTransfer.tsx+10−7
src/lib/useRoller.ts+38−44
@@ -1,17 +1,33 @@
11import { useCallback, useEffect, useMemo, useState } from 'react';
2−import * as wg from 'lib/walletgen';
3−import * as need from 'lib/need';
42import * as azimuth from 'azimuth-js';
3+import * as need from 'lib/need';
54import * as ob from 'urbit-ob';
5+import * as wg from 'lib/walletgen';
6+
7+import { addHexPrefix } from 'lib/utils/address';
8+import { convertToInt } from './convertToInt';
9+import { ensureHexPrefix } from 'form/formatters';
10+import { getOutgoingPoints, maybeGetResult } from 'views/Points';
11+import { getTimeToNextBatch } from './utils/roller';
12+import { Invite } from 'types/Invite';
13+import { isDevelopment, isRopsten } from './flags';
14+import { isPlanet } from './utils/point';
615import { Just } from 'folktale/maybe';
716import { randomHex } from 'web3-utils';
17+import { ROLLER_HOSTS } from './constants';
18+import { signTransactionHash } from './authToken';
19+import { useNetwork } from 'store/network';
20+import { usePointCache } from 'store/pointCache';
21+import { usePointCursor } from 'store/pointCursor';
22+import { useRollerStore } from 'store/roller';
23+import { useWallet } from 'store/wallet';
824
925import {
1026 attemptNetworkSeedDerivation,
1127 deriveNetworkKeys,
1228 CRYPTO_SUITE_VERSION,
29+ deriveNetworkSeedFromUrbitWallet,
1330} from 'lib/keys';
14−import { addHexPrefix } from 'lib/utils/address';
1531
1632import {
1733 Config,
@@ -26,30 +42,11 @@ import {
2642 Hash,
2743} from '@urbit/roller-api';
2844
29−import { isDevelopment, isRopsten } from './flags';
30−import { ROLLER_HOSTS } from './constants';
31−import { useRollerStore } from 'store/roller';
32−import { getTimeToNextBatch } from './utils/roller';
33−import { useWallet } from 'store/wallet';
34−import { usePointCursor } from 'store/pointCursor';
35−import { useNetwork } from 'store/network';
36−import { signTransactionHash } from './authToken';
37−import { Invite } from 'lib/types/Invite';
3845import {
3946 getStoredInvites,
4047 setPendingInvites,
4148 setStoredInvites,
4249} from 'store/storage/roller';
43−import { usePointCache } from 'store/pointCache';
44−import { getOutgoingPoints, maybeGetResult } from 'views/Points';
45−import { isPlanet } from './utils/point';
46−import {
47− CRYPTO_SUITE_VERSION,
48− deriveNetworkKeys,
49− deriveNetworkSeedFromUrbitWallet,
50−} from './keys';
51−import { convertToInt } from './convertToInt';
52−import { ensureHexPrefix } from 'form/formatters';
5350
5451const spawn = async (
5552 api: any,
@@ -216,7 +213,7 @@ export default function useRoller() {
216213 .catch(err => {
217214 // TODO: more elegant error handling
218215 console.warn(
219− '[fetchConfig:failed] is roller running on localhost?\n',
216+ '[fetchConfig:failed] check the roller connection?\n',
220217 err
221218 );
222219 });
@@ -483,33 +480,38 @@ export default function useRoller() {
483480
484481 // }
485482
486− interface TransferPointParams {
483+ interface AcceptInviteParams {
487484 point: Ship;
488485 to: EthAddress;
489− ownerAddress: EthAddress;
490486 fromWallet: any; // TODO: wallet type
491487 toWallet: any; // TODO: wallet type
492488 }
493489
494− const transferPoint = async ({
490+ const acceptInvite = async ({
495491 point,
496492 to,
497− ownerAddress,
498493 fromWallet,
499494 toWallet,
500− }: TransferPointParams) => {
501− const patp = ob.patp(point);
495+ }: AcceptInviteParams) => {
502496 const azimuthPoint = await api.getPoint(point);
497+ const spawnerPatp = ob.patp(azimuthPoint?.network?.sponsor?.who);
498+ console.log('azimuthPoint', azimuthPoint);
499+ const ownerAddress = azimuthPoint?.ownership?.owner?.address!;
503500
504501 const { nonce } = getProxyAndNonce(azimuthPoint, ownerAddress);
505502 if (nonce === undefined) {
506503 throw new Error('Nonce unavailable');
507504 }
508505
509− // update networking keys
506+ // 1. Update networking keys
510507 // TODO: extract this to a useRoller#configureKeys function?
511508 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
512509 const nextRevision = networkRevision + 1;
510+ const fromOwnerProxy: From = {
511+ ship: spawnerPatp,
512+ proxy: 'own',
513+ };
514+
513515 const seed = await deriveNetworkSeedFromUrbitWallet(toWallet, nextRevision);
514516 const keys = deriveNetworkKeys(seed.value);
515517 const keysData = {
@@ -518,14 +520,10 @@ export default function useRoller() {
518520 cryptoSuite: CRYPTO_SUITE_VERSION.toString(),
519521 encrypt: ensureHexPrefix(keys.crypt.public),
520522 };
521− const keysFrom: From = {
522− ship: patp,
523− proxy: 'own',
524− };
525523
526524 const keysHash: Hash = await api.hashTransaction(
527525 nonce,
528− keysFrom,
526+ fromOwnerProxy,
529527 'configureKeys',
530528 keysData
531529 );
@@ -533,21 +531,16 @@ export default function useRoller() {
533531 const keysSigningKey = fromWallet.privateKey;
534532 await api.configureKeys(
535533 signTransactionHash(keysHash, Buffer.from(keysSigningKey, 'hex')),
536− keysFrom,
534+ fromOwnerProxy,
537535 ownerAddress,
538536 keysData
539537 );
540538
541− // transfer point
542− const transferFrom: From = {
543− ship: patp,
544− proxy: 'transfer',
545− };
546−
539+ // 2. Transfer point
547540 const transferData = { address: ownerAddress, reset: false };
548541 const transferHash: Hash = await api.hashTransaction(
549542 nonce + 1,
550− transferFrom,
543+ fromOwnerProxy,
551544 'transferPoint',
552545 transferData
553546 );
@@ -555,7 +548,7 @@ export default function useRoller() {
555548 const transferSigningKey = toWallet.ownership.keys.private;
556549 const transferTxHash = await api.transferPoint(
557550 signTransactionHash(transferHash, Buffer.from(transferSigningKey, 'hex')),
558− transferFrom,
551+ fromOwnerProxy,
559552 to,
560553 transferData
561554 );
@@ -591,6 +584,7 @@ export default function useRoller() {
591584
592585 return {
593586 api,
587+ acceptInvite,
594588 config,
595589 getPoints,
596590 getInvites,
src/views/Activate/ActivateSteps.tsx+1−3
@@ -1,4 +1,4 @@
1−import { Box, SegmentedProgressBar } from '@tlon/indigo-react';
1+import { Box } from '@tlon/indigo-react';
22import withFadeable from './withFadeable';
33
44type ActivateStepsProps = {
@@ -41,8 +41,6 @@ export const ActivateSteps = ({
4141 flexWrap={'nowrap'}
4242 width={'100%'}
4343 className={className}>
44− {/* TODO: Ask Jimmy: */}
45− {/* <SegmentedProgressBar current={currentStep} segments={totalSteps} /> */}
4644 {renderSteps()}
4745 </Box>
4846 );
src/views/Activate/MasterKeyTransfer.tsx+10−7
@@ -14,7 +14,7 @@ import DangerBox from './DangerBox';
1414import View from 'components/View';
1515
1616const MasterKeyTransfer = () => {
17− const { api, transferPoint } = useRoller();
17+ const { acceptInvite } = useRoller();
1818 const {
1919 derivedPatp,
2020 derivedPoint,
@@ -27,11 +27,9 @@ const MasterKeyTransfer = () => {
2727 setError(undefined);
2828
2929 try {
30− const l2point = await api.getPoint(derivedPoint.value);
31− await transferPoint({
30+ await acceptInvite({
3231 point: derivedPoint.value,
3332 to: derivedWallet.value.ownership.address,
34− ownerAddress: l2point.ownership?.owner?.address!,
3533 toWallet: derivedWallet.value,
3634 fromWallet: inviteWallet.value,
3735 });
@@ -39,7 +37,12 @@ const MasterKeyTransfer = () => {
3937 console.error(error);
4038 setError(error);
4139 }
42− }, [api, derivedPoint.value, derivedWallet, inviteWallet, transferPoint]);
40+ }, [
41+ derivedPoint.value,
42+ derivedWallet.value,
43+ inviteWallet.value,
44+ acceptInvite,
45+ ]);
4346
4447 useFadeIn();
4548
@@ -89,14 +92,14 @@ const MasterKeyTransfer = () => {
8992 flexDirection={'column'}
9093 flexWrap={'nowrap'}
9194 justifyContent={'space-between'}>
92− {/* {error && <DangerBox>{error.toString()}</DangerBox>} */}
95+ {error && <DangerBox>{error.toString()}</DangerBox>}
9396 <ActivateButton
9497 onClick={() =>
9598 window.open(
9699 'https://github.com/urbit/port/releases/latest/download/Port.dmg'
97100 )
98101 }
99− // disabled={error}
102+ disabled={error}
100103 success={true}>
101104 Download the Client for Mac
102105 </ActivateButton>