@dxos/react-client 2.19.7-dev.42eb65c2 → 2.19.8-dev.1dd2f6c4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "2.19.7-dev.42eb65c2",
3
+ "version": "2.19.8-dev.1dd2f6c4",
4
4
  "description": "React client API",
5
5
  "keywords": [],
6
6
  "license": "AGPL-3.0",
@@ -8,24 +8,24 @@
8
8
  "main": "dist/src/index.js",
9
9
  "types": "dist/src/index.d.ts",
10
10
  "dependencies": {
11
- "@dxos/async": "2.19.7-dev.42eb65c2",
12
- "@dxos/bot-factory-client": "2.19.7-dev.42eb65c2",
13
- "@dxos/client": "2.19.7-dev.42eb65c2",
14
- "@dxos/config": "2.19.7-dev.42eb65c2",
15
- "@dxos/credentials": "2.19.7-dev.42eb65c2",
16
- "@dxos/crypto": "2.19.7-dev.42eb65c2",
17
- "@dxos/debug": "2.19.7-dev.42eb65c2",
18
- "@dxos/echo-db": "2.19.7-dev.42eb65c2",
19
- "@dxos/util": "2.19.7-dev.42eb65c2",
11
+ "@dxos/async": "2.19.8-dev.1dd2f6c4",
12
+ "@dxos/bot-factory-client": "2.19.8-dev.1dd2f6c4",
13
+ "@dxos/client": "2.19.8-dev.1dd2f6c4",
14
+ "@dxos/config": "2.19.8-dev.1dd2f6c4",
15
+ "@dxos/credentials": "2.19.8-dev.1dd2f6c4",
16
+ "@dxos/crypto": "2.19.8-dev.1dd2f6c4",
17
+ "@dxos/debug": "2.19.8-dev.1dd2f6c4",
18
+ "@dxos/echo-db": "2.19.8-dev.1dd2f6c4",
19
+ "@dxos/util": "2.19.8-dev.1dd2f6c4",
20
20
  "assert": "^2.0.0",
21
21
  "debug": "^4.3.3",
22
22
  "react-display-name": "^0.2.5",
23
23
  "use-subscription": "^1.4.1"
24
24
  },
25
25
  "devDependencies": {
26
- "@dxos/esbuild-plugins": "2.19.7-dev.42eb65c2",
27
- "@dxos/esbuild-server": "~1.7.1",
28
- "@dxos/toolchain-node-library": "2.19.6",
26
+ "@dxos/esbuild-plugins": "2.19.8-dev.1dd2f6c4",
27
+ "@dxos/esbuild-server": "~1.7.2",
28
+ "@dxos/toolchain-node-library": "2.19.7",
29
29
  "@mui/material": "^5.0.1",
30
30
  "@testing-library/react": "^11.0.4",
31
31
  "@testing-library/react-hooks": "5.1.2",
@@ -6,7 +6,7 @@ import { useState } from 'react';
6
6
 
7
7
  import { trigger } from '@dxos/async';
8
8
 
9
- export const useSecretProvider = <T extends any> (): [() => Promise<T>, (value: T) => void] => {
9
+ export const useSecretProvider = <T> (): [() => Promise<T>, (value: T) => void] => {
10
10
  const [[provider, resolver]] = useState(() => trigger<T>());
11
11
 
12
12
  return [provider, resolver];
@@ -8,7 +8,7 @@ import {
8
8
  Box, Button, Divider, Paper, TextField, Toolbar
9
9
  } from '@mui/material';
10
10
 
11
- import { encodeInvitation, decodeInvitation } from '@dxos/client';
11
+ import { decodeInvitation, encodeInvitation, Invitation } from '@dxos/client';
12
12
  import { PublicKey } from '@dxos/crypto';
13
13
  import { InvitationDescriptorType } from '@dxos/echo-db';
14
14
 
@@ -18,9 +18,7 @@ import {
18
18
  useClient,
19
19
  useContacts,
20
20
  useParties,
21
- useProfile,
22
- useSecretGenerator,
23
- useSecretProvider
21
+ useProfile
24
22
  } from '../src';
25
23
  import {
26
24
  ClientPanel,
@@ -42,31 +40,47 @@ const PartyInvitationContainer = () => {
42
40
  const client = useClient();
43
41
  const [partyKey, setPartyKey] = useState<PublicKey>();
44
42
  const [invitationCode, setInvitationCode] = useState<string>();
45
- const [secretProvider, pin, resetPin] = useSecretGenerator();
46
43
  const [contact, setContact] = useState<string>();
47
44
  const [contacts] = useContacts();
45
+ const [pin, setPin] = useState('');
46
+
47
+ const resetInvitations = () => {
48
+ setInvitationCode('');
49
+ setPin('');
50
+ };
48
51
 
49
52
  const handleCreateParty = () => {
50
53
  setImmediate(async () => {
51
54
  const party = await client.echo.createParty();
52
55
  setPartyKey(party.key);
53
- setInvitationCode('');
54
- resetPin();
56
+ resetInvitations();
55
57
  });
56
58
  };
57
59
 
60
+ // const handleCreateInvitation = async () => {
61
+ // const invitation = await client.createHaloInvitation({
62
+ // onFinish: () => { // TODO(burdon): Normalize callbacks (error, etc.)
63
+ // setInvitation(undefined);
64
+ // setPin('');
65
+ // },
66
+ // onPinGenerated: setPin
67
+ // });
68
+
69
+ // setInvitation(invitation);
70
+ // };
71
+
58
72
  const handleCreateInvitation = () => {
59
73
  setImmediate(async () => {
60
- const invitation = (contact)
61
- ? await client.echo.createOfflineInvitation(partyKey!, PublicKey.fromHex(contact!))
62
- : await client.echo.createInvitation(partyKey!, { secretProvider }, {
63
- onFinish: () => { // TODO(burdon): Normalize callbacks (error, etc.)
64
- setInvitationCode(undefined);
65
- resetPin();
66
- }
67
- });
68
-
69
- setInvitationCode(encodeInvitation(invitation));
74
+ resetInvitations();
75
+ if (contact) {
76
+ const invitation = await client.echo.createOfflineInvitation(partyKey!, PublicKey.fromHex(contact!));
77
+ setInvitationCode(encodeInvitation(invitation));
78
+ } else {
79
+ const invitation = await client.echo.createInvitation(partyKey!);
80
+ invitation.connected.on(() => setPin(invitation.secret.toString()));
81
+ invitation.finshed.on(() => resetInvitations());
82
+ setInvitationCode(encodeInvitation(invitation.descriptor));
83
+ }
70
84
  });
71
85
  };
72
86
 
@@ -124,31 +138,39 @@ const PartyInvitationContainer = () => {
124
138
  );
125
139
  };
126
140
 
141
+ interface Status {
142
+ error?: any,
143
+ party?: string,
144
+ invitation?: Invitation
145
+ }
146
+
127
147
  /**
128
148
  * Processes party invitations.
129
149
  */
130
150
  const PartyJoinContainer = () => {
131
151
  const client = useClient();
132
- const [status, setStatus] = useState({});
133
- const [secretProvider, secretResolver] = useSecretProvider<Buffer>();
152
+ const [status, setStatus] = useState<Status>({});
134
153
 
135
154
  const handleSubmit = async (invitationCode: string) => {
136
155
  setStatus({});
137
156
 
138
157
  try {
139
158
  const invitation = decodeInvitation(invitationCode);
140
- const offline = invitation.type === InvitationDescriptorType.OFFLINE_KEY;
141
- const party = await client.echo.joinParty(invitation, offline ? undefined : secretProvider);
142
- await party.open();
143
-
144
- setStatus({ party: party.key.toHex() });
159
+ if (invitation.type === InvitationDescriptorType.OFFLINE_KEY) {
160
+ const party = await client.echo.joinParty(invitation);
161
+ await party.open();
162
+ setStatus({ party: party.key.toHex() });
163
+ } else {
164
+ const redeemingInvitation = client.echo.acceptInvitation(invitation);
165
+ setStatus({ invitation: redeemingInvitation });
166
+ }
145
167
  } catch (error: any) {
146
168
  setStatus({ error });
147
169
  }
148
170
  };
149
171
 
150
- const handleAuthenticate = (pin: string) => {
151
- secretResolver(Buffer.from(pin));
172
+ const handleAuthenticate = async (pin: string) => {
173
+ await status.invitation?.authenticate(Buffer.from(pin));
152
174
  };
153
175
 
154
176
  return (
package/tsconfig.json CHANGED
@@ -21,6 +21,9 @@
21
21
  {
22
22
  "path": "../../common/async"
23
23
  },
24
+ {
25
+ "path": "../../bot/bot-factory-client"
26
+ },
24
27
  {
25
28
  "path": "../client"
26
29
  },