on master help sign in
address PR feedback
commit83e8ca44c86e8d5dbab82d7371681d2b1fb2c477 authorLiam Fitzgerald <liam@urizen.co> dateWed 26 Feb 2020, 11:05 (7 years ago) parente86b440
5 files changed+145−85
src/lib/SolarisClient.js+15−16 src/store/hosting.js+1−1 src/store/lib/useHostingStore.js+6 src/views/UrbitOS/Home.js+119−51 src/views/UrbitOS/NetworkingKeys.js+4−17
src/lib/SolarisClient.js+15−16
@@ -10,97 +10,96 @@ export default class SolarisClient {
1010 }
1111
1212 getHealthzUrl() {
13− return (this.endpoint + '/healthz');
13+ return this.endpoint + '/healthz';
1414 }
1515
1616 async getHealthz() {
1717 return await fetch(this.getHealthzUrl(), {
1818 method: 'GET',
1919 headers: {
20− 'Accept': 'application/json',
20+ Accept: 'application/json',
2121 },
2222 });
2323 }
2424
2525 getUrl() {
26− return (this.endpoint + '/');
26+ return this.endpoint + '/';
2727 }
2828
2929 async get() {
3030 return await fetch(this.getUrl(), {
3131 method: 'GET',
3232 headers: {
33− 'Accept': 'application/json',
33+ Accept: 'application/json',
3434 },
3535 });
3636 }
3737
3838 getImagesUrl() {
39− return (this.endpoint + '/images');
39+ return this.endpoint + '/images';
4040 }
4141
4242 async getImages() {
4343 return await fetch(this.getImagesUrl(), {
4444 method: 'GET',
4545 headers: {
46− 'Accept': 'application/json',
46+ Accept: 'application/json',
4747 },
4848 });
4949 }
5050
5151 getShipsUrl() {
52− return (this.endpoint + '/ships');
52+ return this.endpoint + '/ships';
5353 }
5454
5555 async getShips() {
5656 return await fetch(this.getShipsUrl(), {
5757 method: 'GET',
5858 headers: {
59− 'Accept': 'application/json',
59+ Accept: 'application/json',
6060 },
6161 });
6262 }
6363
6464 getShipsByPatpUrl(patp) {
65− return (this.endpoint + '/ships/' + encodeURIComponent(patp) + '');
65+ return this.endpoint + '/ships/' + encodeURIComponent(patp) + '';
6666 }
6767
6868 async getShipsByPatp(patp) {
6969 return await fetch(this.getShipsByPatpUrl(patp), {
7070 method: 'GET',
7171 headers: {
72− 'Accept': 'application/json',
72+ Accept: 'application/json',
7373 },
7474 });
7575 }
7676
7777 getShipsByPatpDetailsUrl(patp) {
78− return (this.endpoint + '/ships/' + encodeURIComponent(patp) + '/details');
78+ return this.endpoint + '/ships/' + encodeURIComponent(patp) + '/details';
7979 }
8080
8181 async getShipsByPatpDetails(patp) {
8282 return await fetch(this.getShipsByPatpDetailsUrl(patp), {
8383 method: 'GET',
8484 headers: {
85− 'Accept': 'application/json',
85+ Accept: 'application/json',
8686 },
8787 });
8888 }
8989
9090 postShipsUrl() {
91− return (this.endpoint + '/ships');
91+ return this.endpoint + '/ships';
9292 }
9393
9494 async postShips(data) {
9595 return await fetch(this.postShipsUrl(), {
9696 method: 'POST',
9797 cache: 'no-cache',
98− body: JSON.stringify({...data, debug: true}),
98+ body: JSON.stringify(data),
9999 headers: {
100− 'Accept': 'application/json',
100+ Accept: 'application/json',
101101 'Content-Type': 'application/json',
102102 },
103103 });
104104 }
105−
106105}
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('http://localhost:8080');
8+ const store = useHostingStore('http://localhost:4000');
99 return (
1010 <HostingContext.Provider value={store}>{children}</HostingContext.Provider>
1111 );
src/store/lib/useHostingStore.js+6
@@ -104,6 +104,10 @@ function useHostingStore(url) {
104104 }
105105 }, [client, pointCursor, resetEvents, setError, setState]);
106106
107+ useEffect(() => {
108+ syncStatus();
109+ }, [pointCursor, syncStatus]);
110+
107111 const getEvents = useCallback(() => {
108112 try {
109113 if (Nothing.hasInstance(pointCursor)) {
@@ -160,6 +164,8 @@ function useHostingStore(url) {
160164 const response = await client.postShips({
161165 patp,
162166 key: keyfile,
167+ debug: true,
168+ fake: false,
163169 });
164170
165171 if (!response.ok) {
src/views/UrbitOS/Home.js+119−51
@@ -1,4 +1,4 @@
1−import React, { useCallback, useState } from 'react';
1+import React, { useCallback, useState, useEffect } from 'react';
22import { Grid, Button, SelectInput } from 'indigo-react';
33import * as ob from 'urbit-ob';
44import { azimuth } from 'azimuth-js';
@@ -14,12 +14,15 @@ import {
1414 OutButton,
1515 ForwardButton,
1616 BootUrbitOSButton,
17+ GenerateButton,
1718} from 'components/Buttons';
1819import CopyButton from 'components/CopyButton';
1920import NetworkingKeys from 'components/NetworkingKeys';
2021
2122import BridgeForm from 'form/BridgeForm';
2223import { useLocalRouter } from 'lib/LocalRouter';
24+import { useHosting } from 'store/hosting';
25+import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
2326
2427export default function UrbitOSHome() {
2528 const { pointCursor } = usePointCursor();
@@ -32,8 +35,6 @@ export default function UrbitOSHome() {
3235
3336 const sponsor = ob.patp(details.sponsor);
3437
35− const { code, notice } = useKeyfileGenerator();
36−
3738 const [showKeys, setShowKeys] = useState(false);
3839
3940 const showSponsor = azimuth.getPointSize(point) !== azimuth.PointSize.Galaxy;
@@ -53,13 +54,7 @@ export default function UrbitOSHome() {
5354 ]);
5455 return (
5556 <>
56− <Grid>
57− <Grid.Item full className="mv7">
58− Urbit OS
59− </Grid.Item>
60− <Grid.Divider />
61− <Grid.Item full as={BootUrbitOSButton} />
62− </Grid>
57+ <Hosting />
6358
6459 <Grid>
6560 <Grid.Item full className="mv7 f5">
@@ -80,15 +75,7 @@ export default function UrbitOSHome() {
8075 <Grid.Divider />
8176 </>
8277 )}
83− <Grid.Item
84− full
85− as={ForwardButton}
86− accessory={code && <CopyButton text={code} />}
87− detail={code || notice}
88− disabled={!code}
89− detailClassName="mono">
90− Login Code
91− </Grid.Item>
78+
9279 <Grid.Divider />
9380 <Grid.Item full as={ForwardButton} onClick={goNetworkingKeys}>
9481 Reset Networking Keys
@@ -109,52 +96,133 @@ export default function UrbitOSHome() {
10996
11097// eslint-disable-next-line
11198function Hosting() {
99+ const bind = useKeyfileGenerator();
100+ const { keyfile, code, notice } = bind;
101+ const ship = { connected: true }; //useHosting();
102+
103+ const { syncStatus } = ship;
104+
105+ const createShip = useCallback(() => ship.create(keyfile), [keyfile, ship]);
106+
112107 const name = useCurrentPointName();
113108 const options = [{ text: 'Tlon', value: 'tlon' }];
114109
115− const props = { name, options };
116− const connected = false;
117−
118− return (
119− <Grid gap={4}>
120− <Grid.Item full className="f5">
121− Urbit OS
122− </Grid.Item>
110+ const props = { name, options, ship };
123111
124− {(connected && <HostingConnected {...props} />) || (
125− <HostingDisconnected {...props} />
126− )}
127− </Grid>
128− );
129−}
112+ const renderMain = useCallback(() => {
113+ if (ship.connected) {
114+ return (
115+ <>
116+ <Grid.Item cols={[1, 9]} as={OutButton} solid success>
117+ Open OS
118+ </Grid.Item>
119+ <Grid.Item cols={[9, 13]} as={Button} className="b-black b1" center>
120+ Disconnect
121+ </Grid.Item>
122+ </>
123+ );
124+ }
125+ if (ship.missing || ship.booting) {
126+ return (
127+ <Grid.Item
128+ full
129+ as={GenerateButton}
130+ solid
131+ success
132+ disabled={ship.booting || !keyfile}
133+ loading={ship.booting}
134+ onClick={createShip}>
135+ Boot Urbit OS
136+ </Grid.Item>
137+ );
138+ }
139+ if (ship.running || ship.connecting) {
140+ return <HostingDisconnected {...props} />;
141+ }
142+ }, [
143+ ship.connected,
144+ ship.missing,
145+ ship.booting,
146+ ship.running,
147+ ship.connecting,
148+ keyfile,
149+ createShip,
150+ props,
151+ ]);
130152
131−function HostingConnected({ name, options }) {
132− return (
133− <BridgeForm initialValues={{ provider: 'tlon' }}>
134− {() => (
153+ const renderDetails = useCallback(() => {
154+ if (ship.connected) {
155+ return (
135156 <>
136157 <Grid.Item full>Status: Connected</Grid.Item>
137158 <Grid.Item cols={[1, 9]} className="gray4">
138159 <span className="mono">{name}</span> is connected to Tlon and has
139160 the IP address 127.0.0.1
140161 </Grid.Item>
141− <Grid.Item cols={[1, 9]} as={OutButton} solid success>
142− Open OS
162+ </>
163+ );
164+ }
165+ if (ship.running || ship.connected) {
166+ return (
167+ <>
168+ <Grid.Item full className="gray4">
169+ <span className="gray3">Status:</span> Disconnected
170+ <br />
171+ <span className="f6">Last connected: 4m ago</span>
143172 </Grid.Item>
144− <Grid.Item cols={[9, 13]} as={Button} className="b-black b1" center>
145− Disconnect
173+
174+ <Grid.Item full as={ForwardButton} solid>
175+ Connect
146176 </Grid.Item>
147− <Grid.Item
148− full
149− as={SelectInput}
150− name="provider"
151− label="Host Provider"
152− options={options}
153− disabled
154− />
155177 </>
156− )}
157− </BridgeForm>
178+ );
179+ }
180+ }, [name, ship]);
181+
182+ return (
183+ <>
184+ <Grid gap={4}>
185+ <Grid.Item full className="f5">
186+ Urbit OS
187+ </Grid.Item>
188+ <BridgeForm initialValues={{ provider: 'tlon' }}>
189+ {() => (
190+ <>
191+ {renderDetails()}
192+ {renderMain()}
193+ <Grid.Item
194+ full
195+ as={SelectInput}
196+ name="provider"
197+ label="Host Provider"
198+ options={options}
199+ disabled
200+ />
201+ </>
202+ )}
203+ </BridgeForm>
204+ </Grid>
205+ <Grid>
206+ <Grid.Item
207+ full
208+ as={DownloadKeyfileButton}
209+ {...bind}
210+ className="mt2"
211+ detail="A keyfile authenticates your Urbit ID to Urbit OS"
212+ />
213+ <Grid.Divider />
214+ <Grid.Item
215+ full
216+ className="mt2"
217+ as={ForwardButton}
218+ accessory={code && <CopyButton text={code} />}
219+ detail={code || notice}
220+ disabled={!code}
221+ detailClassName="mono">
222+ Login Code
223+ </Grid.Item>
224+ </Grid>
225+ </>
158226 );
159227}
160228
src/views/UrbitOS/NetworkingKeys.js+4−17
@@ -197,27 +197,14 @@ export default function UrbitOSNetworkingKeys() {
197197
198198 const usageMessage = 'You need this to authenticate with arvo';
199199
200− const renderTitle = () => {
201− if (completed) {
202− return 'Networking keys are now set.';
203− }
204−
205− if (broadcasting) {
206− return 'Setting Network Keys...';
207− }
208−
209− if (!hasKeys) {
210− return 'Networking keys have not yet been set.';
211− }
212−
213− return 'Networking';
214− };
215−
216200 return (
217201 <>
218202 <Grid>
219203 <Grid.Item full as={ViewHeader}>
220− {renderTitle()}
204+ Set Networking Keys
205+ </Grid.Item>
206+ <Grid.Item className="gray4 f6" full>
207+ Network Keys solidify the handshake between ID and OS
221208 </Grid.Item>
222209 {completed && (
223210 <>