@@ -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,