@@ -3,6 +3,15 @@ import * as wg from 'lib/walletgen';
3import * as need from 'lib/need';
3import * as need from 'lib/need';
4import * as azimuth from 'azimuth-js';
4import * as azimuth from 'azimuth-js';
5import * as ob from 'urbit-ob';
5import * as ob from 'urbit-ob';
6+import { Just } from 'folktale/maybe';
7+import { randomHex } from 'web3-utils';
10+ attemptNetworkSeedDerivation,
12+ CRYPTO_SUITE_VERSION,
14+import { addHexPrefix } from 'lib/utils/address';
@@ -33,6 +42,97 @@ import { usePointCache } from 'store/pointCache';
33import { getOutgoingPoints, maybeGetResult } from 'views/Points';
42import { getOutgoingPoints, maybeGetResult } from 'views/Points';
34import { isPlanet } from './utils/point';
43import { isPlanet } from './utils/point';
54+ ship: _point, //ship that is spawning the planet
59+ address: _wallet.address,
60+ ship: planet, // ship to spawn
63+ const hash = await api.hashTransaction(nonce, from, 'spawn', data);
64+ const sSig = signTransactionHash(hash, _wallet.privateKey);
65+ return api.spawn(sSig, from, _wallet.address, data);
68+const configureKeys = async (
76+ authMnemonic: string,
81+ ship: _point, //ship that is spawning the planet
85+ const networkSeed = await attemptNetworkSeedDerivation({
95+ const seed = Just.hasInstance(networkSeed)
99+ const pair = deriveNetworkKeys(seed);
102+ encrypt: addHexPrefix(pair.crypt.public),
103+ auth: addHexPrefix(pair.auth.public),
104+ cryptoSuite: String(CRYPTO_SUITE_VERSION),
108+ const hash = await api.hashTransaction(nonce, from, 'configureKeys', data);
109+ const sig = signTransactionHash(hash, _wallet.privateKey);
110+ return api.configureKeys(sig, from, _wallet.address, data);
113+const transferPoint = async (
122+ ship: _point, //ship that is spawning the planet
131+ const hash = await api.hashTransaction(nonce, from, 'transferPoint', data);
132+ const sig = signTransactionHash(hash, _wallet.privateKey);
133+ return api.transferPoint(sig, from, _wallet.address, data);
36const hasPoint = (point: number) => (invite: Invite) => invite.planet === point;
136const hasPoint = (point: number) => (invite: Invite) => invite.planet === point;
38const getProxyAndNonce = (
138const getProxyAndNonce = (
@@ -55,7 +155,7 @@ const getProxyAndNonce = (
55 : { proxy: undefined, nonce: undefined };
155 : { proxy: undefined, nonce: undefined };
57export default function useRoller() {
157export default function useRoller() {
58− const { wallet, authToken }: any = useWallet();
158+ const { wallet, authToken, authMnemonic, urbitWallet }: any = useWallet();
59 const { pointCursor }: any = usePointCursor();
159 const { pointCursor }: any = usePointCursor();
60 const { web3, contracts }: any = useNetwork();
160 const { web3, contracts }: any = useNetwork();
61 const allPoints: any = usePointCache();
161 const allPoints: any = usePointCache();
@@ -119,7 +219,8 @@ export default function useRoller() {
119 const _web3 = web3.getOrElse(null);
219 const _web3 = web3.getOrElse(null);
120 const _wallet = wallet.getOrElse(null);
220 const _wallet = wallet.getOrElse(null);
121 const _authToken = authToken.getOrElse(null);
221 const _authToken = authToken.getOrElse(null);
222+ const _details = getDetails(_point);
122− if (!_contracts || !_web3 || !_wallet || !_authToken) {
223+ if (!_contracts || !_web3 || !_wallet || !_authToken || !_details) {
123 // not using need because we want a custom error
224 // not using need because we want a custom error
124 throw new Error('Internal Error: Missing Contracts/Web3/Wallet');
225 throw new Error('Internal Error: Missing Contracts/Web3/Wallet');
@@ -137,31 +238,45 @@ export default function useRoller() {
138 for (let i = 0; i < numInvites && planets[i]; i++) {
239 for (let i = 0; i < numInvites && planets[i]; i++) {
139 const planet = planets[i];
240 const planet = planets[i];
241+ const nonceInc = i * 3;
141 const { ticket, owner } = await wg.generateTemporaryDeterministicWallet(
243 const { ticket, owner } = await wg.generateTemporaryDeterministicWallet(
143 _authToken
245 _authToken
146− const from = {
248+ const spawnRequest = await spawn(
147− ship: _point, //ship that is spawning the planet
249+ api,
152− address: owner.keys.address, // the new owner of the star (invite wallet)
153− ship: planet, // ship to spawn
254+ planet
156− const txHash = await api.hashTransaction(
163− const signature = signTransactionHash(txHash, _wallet.privateKey);
257+ const configureKeysRequest = await configureKeys(
164− requests.push(api.spawn(signature, from, _wallet.address, data));
258+ api,
270+ const transferPointRequest = await transferPoint(
279+ requests.push(spawnRequest, configureKeysRequest, transferPointRequest);
165 tickets.push({
280 tickets.push({
@@ -170,13 +285,13 @@ export default function useRoller() {
172 const hashes = await Promise.all(requests);
287 const hashes = await Promise.all(requests);
173− const pendingInvites = hashes.map(
289+ const pendingInvites = tickets.map((ticket, ind) => ({
174− (hash, i): Invite => ({
290+ ...ticket,
175− hash,
291+ hash: hashes[ind * 3 + 2],
177− status: 'pending',
292+ status: 'pending',
180 setPendingInvites(_point, pendingInvites);
295 setPendingInvites(_point, pendingInvites);
@@ -188,6 +303,9 @@ export default function useRoller() {
188 // walletHdPath,
303 // walletHdPath,
189 // walletType,
304 // walletType,
@@ -240,9 +358,14 @@ export default function useRoller() {
240 const completed = !pendingTransactions.find(
358 const completed = !pendingTransactions.find(
241 p => `~${p?.rawTx?.tx?.tx?.data?.ship}` === ob.patp(invite.planet)
359 p => `~${p?.rawTx?.tx?.tx?.data?.ship}` === ob.patp(invite.planet)
243− if (completed) {
363+ completed &&
364+ !availableInvites.find(({ ship }) => invite.ship === ship)
244 availableInvites.push({ ...invite, status: 'available' });
366 availableInvites.push({ ...invite, status: 'available' });
246 return !completed;
369 return !completed;