@@ -1,17 +1,33 @@
1import { useCallback, useEffect, useMemo, useState } from 'react';
1import { useCallback, useEffect, useMemo, useState } from 'react';
2−import * as wg from 'lib/walletgen';
3−import * as need from 'lib/need';
4import * as azimuth from 'azimuth-js';
2import * as azimuth from 'azimuth-js';
3+import * as need from 'lib/need';
5import * as ob from 'urbit-ob';
4import * as ob from 'urbit-ob';
5+import * as wg from 'lib/walletgen';
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';
6import { Just } from 'folktale/maybe';
15import { Just } from 'folktale/maybe';
7import { randomHex } from 'web3-utils';
16import { 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';
10 attemptNetworkSeedDerivation,
26 attemptNetworkSeedDerivation,
11 deriveNetworkKeys,
27 deriveNetworkKeys,
12 CRYPTO_SUITE_VERSION,
28 CRYPTO_SUITE_VERSION,
29+ deriveNetworkSeedFromUrbitWallet,
13} from 'lib/keys';
30} from 'lib/keys';
14−import { addHexPrefix } from 'lib/utils/address';
@@ -26,30 +42,11 @@ import {
27} from '@urbit/roller-api';
43} from '@urbit/roller-api';
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';
39 getStoredInvites,
46 getStoredInvites,
40 setPendingInvites,
47 setPendingInvites,
41 setStoredInvites,
48 setStoredInvites,
42} from 'store/storage/roller';
49} from 'store/storage/roller';
43−import { usePointCache } from 'store/pointCache';
44−import { getOutgoingPoints, maybeGetResult } from 'views/Points';
45−import { isPlanet } from './utils/point';
47− CRYPTO_SUITE_VERSION,
49− deriveNetworkSeedFromUrbitWallet,
51−import { convertToInt } from './convertToInt';
52−import { ensureHexPrefix } from 'form/formatters';
54const spawn = async (
51const spawn = async (
@@ -216,7 +213,7 @@ export default function useRoller() {
216 .catch(err => {
213 .catch(err => {
217 // TODO: more elegant error handling
214 // TODO: more elegant error handling
218 console.warn(
215 console.warn(
219− '[fetchConfig:failed] is roller running on localhost?\n',
216+ '[fetchConfig:failed] check the roller connection?\n',
@@ -483,33 +480,38 @@ export default function useRoller() {
486− interface TransferPointParams {
483+ interface AcceptInviteParams {
487 point: Ship;
484 point: Ship;
488 to: EthAddress;
485 to: EthAddress;
489− ownerAddress: EthAddress;
490 fromWallet: any; // TODO: wallet type
486 fromWallet: any; // TODO: wallet type
491 toWallet: any; // TODO: wallet type
487 toWallet: any; // TODO: wallet type
494− const transferPoint = async ({
490+ const acceptInvite = async ({
498 fromWallet,
493 fromWallet,
499 toWallet,
494 toWallet,
500− }: TransferPointParams) => {
495+ }: AcceptInviteParams) => {
501− const patp = ob.patp(point);
502 const azimuthPoint = await api.getPoint(point);
496 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!;
504 const { nonce } = getProxyAndNonce(azimuthPoint, ownerAddress);
501 const { nonce } = getProxyAndNonce(azimuthPoint, ownerAddress);
505 if (nonce === undefined) {
502 if (nonce === undefined) {
506 throw new Error('Nonce unavailable');
503 throw new Error('Nonce unavailable');
509− // update networking keys
506+ // 1. Update networking keys
510 // TODO: extract this to a useRoller#configureKeys function?
507 // TODO: extract this to a useRoller#configureKeys function?
511 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
508 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
512 const nextRevision = networkRevision + 1;
509 const nextRevision = networkRevision + 1;
510+ const fromOwnerProxy: From = {
513 const seed = await deriveNetworkSeedFromUrbitWallet(toWallet, nextRevision);
515 const seed = await deriveNetworkSeedFromUrbitWallet(toWallet, nextRevision);
514 const keys = deriveNetworkKeys(seed.value);
516 const keys = deriveNetworkKeys(seed.value);
515 const keysData = {
517 const keysData = {
@@ -518,14 +520,10 @@ export default function useRoller() {
518 cryptoSuite: CRYPTO_SUITE_VERSION.toString(),
520 cryptoSuite: CRYPTO_SUITE_VERSION.toString(),
519 encrypt: ensureHexPrefix(keys.crypt.public),
521 encrypt: ensureHexPrefix(keys.crypt.public),
521− const keysFrom: From = {
526 const keysHash: Hash = await api.hashTransaction(
524 const keysHash: Hash = await api.hashTransaction(
528− keysFrom,
526+ fromOwnerProxy,
529 'configureKeys',
527 'configureKeys',
@@ -533,21 +531,16 @@ export default function useRoller() {
533 const keysSigningKey = fromWallet.privateKey;
531 const keysSigningKey = fromWallet.privateKey;
534 await api.configureKeys(
532 await api.configureKeys(
535 signTransactionHash(keysHash, Buffer.from(keysSigningKey, 'hex')),
533 signTransactionHash(keysHash, Buffer.from(keysSigningKey, 'hex')),
536− keysFrom,
534+ fromOwnerProxy,
537 ownerAddress,
535 ownerAddress,
541− // transfer point
539+ // 2. Transfer point
542− const transferFrom: From = {
547 const transferData = { address: ownerAddress, reset: false };
540 const transferData = { address: ownerAddress, reset: false };
548 const transferHash: Hash = await api.hashTransaction(
541 const transferHash: Hash = await api.hashTransaction(
549 nonce + 1,
542 nonce + 1,
550− transferFrom,
543+ fromOwnerProxy,
551 'transferPoint',
544 'transferPoint',
552 transferData
545 transferData
@@ -555,7 +548,7 @@ export default function useRoller() {
555 const transferSigningKey = toWallet.ownership.keys.private;
548 const transferSigningKey = toWallet.ownership.keys.private;
556 const transferTxHash = await api.transferPoint(
549 const transferTxHash = await api.transferPoint(
557 signTransactionHash(transferHash, Buffer.from(transferSigningKey, 'hex')),
550 signTransactionHash(transferHash, Buffer.from(transferSigningKey, 'hex')),
558− transferFrom,
551+ fromOwnerProxy,
560 transferData
553 transferData
@@ -591,6 +584,7 @@ export default function useRoller() {
595 getPoints,
589 getPoints,
596 getInvites,
590 getInvites,