on master help sign in
wip
commite86b440a6366f0ac0f8b2c94e1e733f32c2b0201 authorLiam Fitzgerald <liam@urizen.co> dateWed 12 Feb 2020, 12:47 (7 years ago) parent66bd0fa
6 files changed+51−27
src/Bridge.js+1−1 src/components/HostedShip.js+14−4 src/lib/SolarisClient.js+1−1 src/lib/useKeyfileGenerator.js+1 src/store/hosting.js+1−1 src/store/lib/useHostingStore.js+33−20
src/Bridge.js+1−1
@@ -20,7 +20,7 @@ import WithErrorBoundary from 'components/WithErrorBoundary';
2020import GlobalErrorBoundary from 'components/GlobalErrorBoundary';
2121
2222const INITIAL_NETWORK_TYPE = isDevelopment
23− ? NETWORK_TYPES.LOCAL
23+ ? NETWORK_TYPES.ROPSTEN
2424 : NETWORK_TYPES.MAINNET;
2525
2626// NB(shrugs): modify these variables to change the default local state.
src/components/HostedShip.js+14−4
@@ -1,21 +1,31 @@
1−import React from 'react';
1+import React, { useEffect, useCallback } from 'react';
22import { Grid, ErrorText } from 'indigo-react';
33
44import cn from 'classnames';
55
6+import { useHosting } from 'store/hosting';
7+
68import BridgeForm from 'form/BridgeForm';
79
810import { GenerateButton, ForwardButton } from './Buttons';
911
1012import 'style/hosted-ship.scss';
13+import useKeyfileGenerator from 'lib/useKeyfileGenerator';
1114
1215export default function HostedShip({
1316 // useHostedShip
14− ship,
1517
1618 // additional from parent
1719 className,
1820}) {
21+ const ship = useHosting();
22+ const { syncStatus } = ship;
23+ console.log(ship);
24+
25+ const { keyfile } = useKeyfileGenerator();
26+
27+ const createShip = useCallback(() => ship.create(keyfile), [ship, keyfile]);
28+
1929 const renderStatus = () => {
2030 if (ship.missing || ship.booting) {
2131 return (
@@ -26,7 +36,7 @@ export default function HostedShip({
2636 success
2737 disabled={ship.booting}
2838 loading={ship.booting}
29− onClick={ship.create}>
39+ onClick={createShip}>
3040 Boot Urbit OS
3141 </Grid.Item>
3242 );
@@ -64,7 +74,7 @@ export default function HostedShip({
6474 success
6575 disabled={ship.querying}
6676 loading={ship.querying}
67− onClick={ship.getStatus}>
77+ onClick={syncStatus}>
6878 Query
6979 </Grid.Item>
7080 );
src/lib/SolarisClient.js+1−1
@@ -95,7 +95,7 @@ export default class SolarisClient {
9595 return await fetch(this.postShipsUrl(), {
9696 method: 'POST',
9797 cache: 'no-cache',
98− body: JSON.stringify(data),
98+ body: JSON.stringify({...data, debug: true}),
9999 headers: {
100100 'Accept': 'application/json',
101101 'Content-Type': 'application/json',
src/lib/useKeyfileGenerator.js+1
@@ -128,6 +128,7 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
128128 download,
129129 filename,
130130 notice,
131+ keyfile,
131132 code,
132133 };
133134
src/store/hosting.js+1−1
@@ -5,7 +5,7 @@ import useHostingStore from './lib/useHostingStore';
55export const HostingContext = createContext(null);
66
77export function HostingProvider({ children }) {
8− const store = useHostingStore('https://localhost:3030');
8+ const store = useHostingStore('http://localhost:8080');
99 return (
1010 <HostingContext.Provider value={store}>{children}</HostingContext.Provider>
1111 );
src/store/lib/useHostingStore.js+33−20
@@ -4,6 +4,7 @@ import * as ob from 'urbit-ob';
44
55import SolarisClient from 'lib/SolarisClient';
66import { usePointCursor } from 'store/pointCursor';
7+import useKeyfileGenerator from 'lib/useKeyfileGenerator';
78const STATE = {
89 // container states
910 UNKNOWN: 'UNKNOWN',
@@ -18,6 +19,12 @@ const STATE = {
1819 CONNECTED: 'CONNECTED',
1920};
2021
22+const mockFetch = status => ({
23+ ok: true,
24+
25+ json: () => Promise.resolve({ status }),
26+});
27+
2128function useHostingStore(url) {
2229 const client = new SolarisClient(url);
2330
@@ -117,16 +124,19 @@ function useHostingStore(url) {
117124 // source.onmessage = console.log;
118125
119126 source.addEventListener('sys', event => {
127+ console.log(event);
120128 setSysEvents(previous => [...previous, JSON.parse(event.data)]);
121129 });
122130
123131 source.addEventListener('new', event => {
132+ console.log(event);
124133 if (event.data !== '') {
125134 setNewEvents(previous => [...previous, event.data]);
126135 }
127136 });
128137
129138 source.addEventListener('run', event => {
139+ console.log(event);
130140 if (event.data !== '') {
131141 setRunEvents(previous => [...previous, event.data]);
132142 }
@@ -136,30 +146,33 @@ function useHostingStore(url) {
136146 }
137147 }, [setError, resetEvents, client, pointCursor, setState]);
138148
139− const create = useCallback(async () => {
140− try {
141− if (Nothing.hasInstance(pointCursor)) {
142− return;
143− }
144− const patp = ob.patp(pointCursor.value);
145− setError(undefined);
149+ const create = useCallback(
150+ async keyfile => {
151+ try {
152+ if (Nothing.hasInstance(pointCursor)) {
153+ return;
154+ }
155+ const patp = ob.patp(pointCursor.value);
156+ setError(undefined);
146157
147− setState(STATE.BOOTING);
158+ setState(STATE.BOOTING);
148159
149− const response = await client.postShips({
150− patp,
151− key: '123',
152− });
160+ const response = await client.postShips({
161+ patp,
162+ key: keyfile,
163+ });
153164
154− if (!response.ok) {
155− setError(response.statusText);
156− } else {
157− getEvents();
165+ if (!response.ok) {
166+ setError(response.statusText);
167+ } else {
168+ getEvents();
169+ }
170+ } catch (error) {
171+ setError(error);
158172 }
159− } catch (error) {
160− setError(error);
161− }
162− }, [pointCursor, setError, setState, client, getEvents]);
173+ },
174+ [pointCursor, setError, setState, client, getEvents]
175+ );
163176
164177 return {
165178 error,