on master help sign in
wip
e86b440Liam Fitzgerald
src/Bridge.js+1−1
@@ -20,7 +20,7 @@ import WithErrorBoundary from 'components/WithErrorBoundary';
20import GlobalErrorBoundary from 'components/GlobalErrorBoundary';
20import GlobalErrorBoundary from 'components/GlobalErrorBoundary';
21
21
22const INITIAL_NETWORK_TYPE = isDevelopment
22const INITIAL_NETWORK_TYPE = isDevelopment
23− ? NETWORK_TYPES.LOCAL
23+ ? NETWORK_TYPES.ROPSTEN
24 : NETWORK_TYPES.MAINNET;
24 : NETWORK_TYPES.MAINNET;
25
25
26// NB(shrugs): modify these variables to change the default local state.
26// 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';
2import { Grid, ErrorText } from 'indigo-react';
2import { Grid, ErrorText } from 'indigo-react';
3
3
4import cn from 'classnames';
4import cn from 'classnames';
5
5
6+import { useHosting } from 'store/hosting';
7+
6import BridgeForm from 'form/BridgeForm';
8import BridgeForm from 'form/BridgeForm';
7
9
8import { GenerateButton, ForwardButton } from './Buttons';
10import { GenerateButton, ForwardButton } from './Buttons';
9
11
10import 'style/hosted-ship.scss';
12import 'style/hosted-ship.scss';
13+import useKeyfileGenerator from 'lib/useKeyfileGenerator';
11
14
12export default function HostedShip({
15export default function HostedShip({
13 // useHostedShip
16 // useHostedShip
14− ship,
15
17
16 // additional from parent
18 // additional from parent
17 className,
19 className,
18}) {
20}) {
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+
19 const renderStatus = () => {
29 const renderStatus = () => {
20 if (ship.missing || ship.booting) {
30 if (ship.missing || ship.booting) {
21 return (
31 return (
@@ -26,7 +36,7 @@ export default function HostedShip({
26 success
36 success
27 disabled={ship.booting}
37 disabled={ship.booting}
28 loading={ship.booting}
38 loading={ship.booting}
29− onClick={ship.create}>
39+ onClick={createShip}>
30 Boot Urbit OS
40 Boot Urbit OS
31 </Grid.Item>
41 </Grid.Item>
32 );
42 );
@@ -64,7 +74,7 @@ export default function HostedShip({
64 success
74 success
65 disabled={ship.querying}
75 disabled={ship.querying}
66 loading={ship.querying}
76 loading={ship.querying}
67− onClick={ship.getStatus}>
77+ onClick={syncStatus}>
68 Query
78 Query
69 </Grid.Item>
79 </Grid.Item>
70 );
80 );
src/lib/SolarisClient.js+1−1
@@ -95,7 +95,7 @@ export default class SolarisClient {
95 return await fetch(this.postShipsUrl(), {
95 return await fetch(this.postShipsUrl(), {
96 method: 'POST',
96 method: 'POST',
97 cache: 'no-cache',
97 cache: 'no-cache',
98− body: JSON.stringify(data),
98+ body: JSON.stringify({...data, debug: true}),
99 headers: {
99 headers: {
100 'Accept': 'application/json',
100 'Accept': 'application/json',
101 'Content-Type': 'application/json',
101 'Content-Type': 'application/json',
src/lib/useKeyfileGenerator.js+1
@@ -128,6 +128,7 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
128 download,
128 download,
129 filename,
129 filename,
130 notice,
130 notice,
131+ keyfile,
131 code,
132 code,
132 };
133 };
133
134
src/store/hosting.js+1−1
@@ -5,7 +5,7 @@ import useHostingStore from './lib/useHostingStore';
5export const HostingContext = createContext(null);
5export const HostingContext = createContext(null);
6
6
7export function HostingProvider({ children }) {
7export function HostingProvider({ children }) {
8− const store = useHostingStore('https://localhost:3030');
8+ const store = useHostingStore('http://localhost:8080');
9 return (
9 return (
10 <HostingContext.Provider value={store}>{children}</HostingContext.Provider>
10 <HostingContext.Provider value={store}>{children}</HostingContext.Provider>
11 );
11 );
src/store/lib/useHostingStore.js+33−20
@@ -4,6 +4,7 @@ import * as ob from 'urbit-ob';
4
4
5import SolarisClient from 'lib/SolarisClient';
5import SolarisClient from 'lib/SolarisClient';
6import { usePointCursor } from 'store/pointCursor';
6import { usePointCursor } from 'store/pointCursor';
7+import useKeyfileGenerator from 'lib/useKeyfileGenerator';
7const STATE = {
8const STATE = {
8 // container states
9 // container states
9 UNKNOWN: 'UNKNOWN',
10 UNKNOWN: 'UNKNOWN',
@@ -18,6 +19,12 @@ const STATE = {
18 CONNECTED: 'CONNECTED',
19 CONNECTED: 'CONNECTED',
19};
20};
20
21
22+const mockFetch = status => ({
23+ ok: true,
24+
25+ json: () => Promise.resolve({ status }),
26+});
27+
21function useHostingStore(url) {
28function useHostingStore(url) {
22 const client = new SolarisClient(url);
29 const client = new SolarisClient(url);
23
30
@@ -117,16 +124,19 @@ function useHostingStore(url) {
117 // source.onmessage = console.log;
124 // source.onmessage = console.log;
118
125
119 source.addEventListener('sys', event => {
126 source.addEventListener('sys', event => {
127+ console.log(event);
120 setSysEvents(previous => [...previous, JSON.parse(event.data)]);
128 setSysEvents(previous => [...previous, JSON.parse(event.data)]);
121 });
129 });
122
130
123 source.addEventListener('new', event => {
131 source.addEventListener('new', event => {
132+ console.log(event);
124 if (event.data !== '') {
133 if (event.data !== '') {
125 setNewEvents(previous => [...previous, event.data]);
134 setNewEvents(previous => [...previous, event.data]);
126 }
135 }
127 });
136 });
128
137
129 source.addEventListener('run', event => {
138 source.addEventListener('run', event => {
139+ console.log(event);
130 if (event.data !== '') {
140 if (event.data !== '') {
131 setRunEvents(previous => [...previous, event.data]);
141 setRunEvents(previous => [...previous, event.data]);
132 }
142 }
@@ -136,30 +146,33 @@ function useHostingStore(url) {
136 }
146 }
137 }, [setError, resetEvents, client, pointCursor, setState]);
147 }, [setError, resetEvents, client, pointCursor, setState]);
138
148
139− const create = useCallback(async () => {
149+ const create = useCallback(
150+ async keyfile => {
140− try {
151+ try {
141− if (Nothing.hasInstance(pointCursor)) {
152+ if (Nothing.hasInstance(pointCursor)) {
142− return;
153+ return;
143− }
154+ }
144− const patp = ob.patp(pointCursor.value);
155+ const patp = ob.patp(pointCursor.value);
145− setError(undefined);
156+ setError(undefined);
146
157
147− setState(STATE.BOOTING);
158+ setState(STATE.BOOTING);
148
159
149− const response = await client.postShips({
160+ const response = await client.postShips({
150− patp,
161+ patp,
151− key: '123',
162+ key: keyfile,
152− });
163+ });
153
164
154− if (!response.ok) {
165+ if (!response.ok) {
155− setError(response.statusText);
166+ setError(response.statusText);
156− } else {
167+ } else {
157− getEvents();
168+ getEvents();
169+ }
170+ } catch (error) {
171+ setError(error);
158 }
172 }
159− } catch (error) {
173+ },
160− setError(error);
161− }
162− }, [pointCursor, setError, setState, client, getEvents]);
174+ [pointCursor, setError, setState, client, getEvents]
175+ );
163
176
164 return {
177 return {
165 error,
178 error,