@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/.rush/temp/package-deps_build.json +3 -3
- package/.rush/temp/package-deps_build:test.json +5 -5
- package/.rush/temp/shrinkwrap-deps.json +2 -2
- package/dist/src/hooks/invitations/useSecretProvider.d.ts +1 -1
- package/dist/src/hooks/invitations/useSecretProvider.d.ts.map +1 -1
- package/dist/src/hooks/invitations/useSecretProvider.js.map +1 -1
- package/dist/stories/party-invitations.stories.d.ts +0 -1
- package/dist/stories/party-invitations.stories.d.ts.map +1 -1
- package/dist/stories/party-invitations.stories.js +39 -19
- package/dist/stories/party-invitations.stories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -13
- package/src/hooks/invitations/useSecretProvider.ts +1 -1
- package/stories/party-invitations.stories.tsx +48 -26
- package/tsconfig.json +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-client",
|
|
3
|
-
"version": "2.19.
|
|
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.
|
|
12
|
-
"@dxos/bot-factory-client": "2.19.
|
|
13
|
-
"@dxos/client": "2.19.
|
|
14
|
-
"@dxos/config": "2.19.
|
|
15
|
-
"@dxos/credentials": "2.19.
|
|
16
|
-
"@dxos/crypto": "2.19.
|
|
17
|
-
"@dxos/debug": "2.19.
|
|
18
|
-
"@dxos/echo-db": "2.19.
|
|
19
|
-
"@dxos/util": "2.19.
|
|
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.
|
|
27
|
-
"@dxos/esbuild-server": "~1.7.
|
|
28
|
-
"@dxos/toolchain-node-library": "2.19.
|
|
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
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
172
|
+
const handleAuthenticate = async (pin: string) => {
|
|
173
|
+
await status.invitation?.authenticate(Buffer.from(pin));
|
|
152
174
|
};
|
|
153
175
|
|
|
154
176
|
return (
|