@hanzo/app 0.2.45 → 0.2.46
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/dist/SettingsPane.js +5 -28
- package/dist/Setup.js +8 -6
- package/dist/pref.d.ts +15 -0
- package/dist/pref.js +96 -0
- package/package.json +1 -1
package/dist/SettingsPane.js
CHANGED
|
@@ -26,6 +26,7 @@ import { showSettings } from './open.js';
|
|
|
26
26
|
import { Look } from './look.js';
|
|
27
27
|
import { ProviderMark } from './ProviderMark.js';
|
|
28
28
|
import { bearer, org, pick } from './lib/session.js';
|
|
29
|
+
import { usePref } from './pref.js';
|
|
29
30
|
import { Experimental } from './experimental.js';
|
|
30
31
|
import { site } from './where.js';
|
|
31
32
|
import { named, ROWS } from './Settings.js';
|
|
@@ -142,40 +143,16 @@ function Account() {
|
|
|
142
143
|
/** Real Web3 Wallet Connect & Payout Address for collecting referral & compute rewards. */
|
|
143
144
|
function WalletPayouts() {
|
|
144
145
|
const { t } = useI18n();
|
|
145
|
-
const [address, setAddress] =
|
|
146
|
-
|
|
147
|
-
return typeof window !== 'undefined' ? (window.localStorage.getItem('hanzo.wallet.address') ?? '') : '';
|
|
148
|
-
}
|
|
149
|
-
catch {
|
|
150
|
-
return '';
|
|
151
|
-
}
|
|
152
|
-
});
|
|
146
|
+
const [address, setAddress] = usePref('rewards_payout_wallet', '');
|
|
147
|
+
const [, setProvider] = usePref('rewards_payout_provider', '');
|
|
153
148
|
const [busy, setBusy] = useState(false);
|
|
154
149
|
const [saved, setSaved] = useState(false);
|
|
155
150
|
const [error, setError] = useState('');
|
|
156
151
|
const persist = async (addr, provider) => {
|
|
157
152
|
const clean = addr.trim();
|
|
153
|
+
// The account holds the address (PATCH /v1/pref), so it is the same on every machine.
|
|
158
154
|
setAddress(clean);
|
|
159
|
-
|
|
160
|
-
if (clean)
|
|
161
|
-
window.localStorage.setItem('hanzo.wallet.address', clean);
|
|
162
|
-
else
|
|
163
|
-
window.localStorage.removeItem('hanzo.wallet.address');
|
|
164
|
-
}
|
|
165
|
-
catch { }
|
|
166
|
-
const tok = bearer();
|
|
167
|
-
if (tok && clean) {
|
|
168
|
-
await fetch(`${api()}/v1/preferences`, {
|
|
169
|
-
method: 'PUT',
|
|
170
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${tok}` },
|
|
171
|
-
body: JSON.stringify({
|
|
172
|
-
preferences: {
|
|
173
|
-
rewards_payout_wallet: clean,
|
|
174
|
-
rewards_payout_provider: provider,
|
|
175
|
-
},
|
|
176
|
-
}),
|
|
177
|
-
}).catch(() => { });
|
|
178
|
-
}
|
|
155
|
+
setProvider(clean ? provider : '');
|
|
179
156
|
setSaved(true);
|
|
180
157
|
setTimeout(() => setSaved(false), 2400);
|
|
181
158
|
};
|
package/dist/Setup.js
CHANGED
|
@@ -24,6 +24,7 @@ import { ProviderMark } from './ProviderMark.js';
|
|
|
24
24
|
import { useBetas } from './Betas.js';
|
|
25
25
|
import { useRooms } from './host.js';
|
|
26
26
|
import { useKept } from './kept.js';
|
|
27
|
+
import { usePref } from './pref.js';
|
|
27
28
|
import { api } from './lib/api.js';
|
|
28
29
|
import { app } from './lib/host.js';
|
|
29
30
|
import { scope } from './lib/session.js';
|
|
@@ -48,11 +49,11 @@ export function Setup({ go } = {}) {
|
|
|
48
49
|
const { isAuthenticated, accessToken } = useIam();
|
|
49
50
|
const { open: opens } = useBetas();
|
|
50
51
|
const pathed = useRooms().path !== null;
|
|
51
|
-
const [later, setLater] =
|
|
52
|
-
const [step, setStep] =
|
|
53
|
-
const [githubDone, setGithubDone] =
|
|
54
|
-
const [slackDone, setSlackDone] =
|
|
55
|
-
const [pluginDone, setPluginDone] =
|
|
52
|
+
const [later, setLater, known] = usePref(LATER_KEY, false);
|
|
53
|
+
const [step, setStep] = usePref(STEP_KEY, 1);
|
|
54
|
+
const [githubDone, setGithubDone] = usePref(GITHUB_KEY, false);
|
|
55
|
+
const [slackDone, setSlackDone] = usePref(SLACK_KEY, false);
|
|
56
|
+
const [pluginDone, setPluginDone] = usePref(PLUGIN_KEY, false);
|
|
56
57
|
const [googleDone, setGoogleDone] = useKept(GOOGLE_KEY, false);
|
|
57
58
|
const [googleAccounts, setGoogleAccounts] = useKept(GOOGLE_ACCOUNTS_KEY, []);
|
|
58
59
|
const [busy, setBusy] = useState(null);
|
|
@@ -198,7 +199,8 @@ export function Setup({ go } = {}) {
|
|
|
198
199
|
const totalDone = (githubDone ? 1 : 0) + (slackDone ? 1 : 0) + (pluginDone ? 1 : 0);
|
|
199
200
|
const allDone = totalDone === 3;
|
|
200
201
|
const activeStep = step === 1 || step === 2 || step === 3 ? step : 1;
|
|
201
|
-
|
|
202
|
+
// Dismissed on another machine is dismissed here: the account answers before the card draws.
|
|
203
|
+
if (!known || (later && !modalOpen))
|
|
202
204
|
return null;
|
|
203
205
|
const openOAuthPopup = (authorizeUrl, provider, label, onDone) => {
|
|
204
206
|
const popup = window.open(authorizeUrl, `hanzo-oauth-${provider}`, 'width=600,height=700');
|
package/dist/pref.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value kept on the signed-in person's account, so it follows them to every
|
|
3
|
+
* machine and every Hanzo surface: GET /v1/pref reads their preference document,
|
|
4
|
+
* PATCH /v1/pref merges one key into it (shallow: a key sent is replaced whole,
|
|
5
|
+
* the rest are left as they are).
|
|
6
|
+
*
|
|
7
|
+
* Signed in, the account is the truth: a key the document holds wins, and a key
|
|
8
|
+
* it does not hold is `initial`, never what this browser kept for whoever used
|
|
9
|
+
* it before. This browser's copy only paints the first frame and stands in while
|
|
10
|
+
* signed out. `ready` is false until the document has answered, so a surface that
|
|
11
|
+
* would flash (a card the person already dismissed) can wait for it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function usePref<T>(key: string, initial: T): [T, (v: T) => void, boolean];
|
|
14
|
+
/** One key written to the account; a signed-out page keeps it in this browser only. */
|
|
15
|
+
export declare function send(patch: Record<string, unknown>): void;
|
package/dist/pref.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { api } from './lib/api.js';
|
|
4
|
+
import { scope } from './lib/session.js';
|
|
5
|
+
/**
|
|
6
|
+
* A value kept on the signed-in person's account, so it follows them to every
|
|
7
|
+
* machine and every Hanzo surface: GET /v1/pref reads their preference document,
|
|
8
|
+
* PATCH /v1/pref merges one key into it (shallow: a key sent is replaced whole,
|
|
9
|
+
* the rest are left as they are).
|
|
10
|
+
*
|
|
11
|
+
* Signed in, the account is the truth: a key the document holds wins, and a key
|
|
12
|
+
* it does not hold is `initial`, never what this browser kept for whoever used
|
|
13
|
+
* it before. This browser's copy only paints the first frame and stands in while
|
|
14
|
+
* signed out. `ready` is false until the document has answered, so a surface that
|
|
15
|
+
* would flash (a card the person already dismissed) can wait for it.
|
|
16
|
+
*/
|
|
17
|
+
export function usePref(key, initial) {
|
|
18
|
+
const signed = Boolean(scope().Authorization);
|
|
19
|
+
const [value, setValue] = useState(() => local(key, initial));
|
|
20
|
+
const [ready, setReady] = useState(!signed);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!signed)
|
|
23
|
+
return;
|
|
24
|
+
let live = true;
|
|
25
|
+
void held().then((doc) => {
|
|
26
|
+
if (!live)
|
|
27
|
+
return;
|
|
28
|
+
if (doc) {
|
|
29
|
+
const next = key in doc ? doc[key] : initial;
|
|
30
|
+
setValue(next);
|
|
31
|
+
keep(key, next);
|
|
32
|
+
}
|
|
33
|
+
setReady(true);
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
live = false;
|
|
37
|
+
};
|
|
38
|
+
// `initial` is a literal at every call site.
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
}, [key, signed]);
|
|
41
|
+
const set = (v) => {
|
|
42
|
+
setValue(v);
|
|
43
|
+
keep(key, v);
|
|
44
|
+
send({ [key]: v });
|
|
45
|
+
};
|
|
46
|
+
return [value, set, ready];
|
|
47
|
+
}
|
|
48
|
+
/** The document, read once per page and per credential, and shared by every key. */
|
|
49
|
+
let read = null;
|
|
50
|
+
function held() {
|
|
51
|
+
const auth = scope();
|
|
52
|
+
if (!auth.Authorization)
|
|
53
|
+
return Promise.resolve(null);
|
|
54
|
+
if (read?.auth !== auth.Authorization) {
|
|
55
|
+
read = {
|
|
56
|
+
auth: auth.Authorization,
|
|
57
|
+
doc: fetch(`${api()}/v1/pref`, { headers: auth })
|
|
58
|
+
.then((r) => (r.ok ? r.json() : null))
|
|
59
|
+
.then((body) => (body && body.prefs && typeof body.prefs === 'object' ? body.prefs : body ? {} : null))
|
|
60
|
+
.catch(() => null),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return read.doc;
|
|
64
|
+
}
|
|
65
|
+
/** One key written to the account; a signed-out page keeps it in this browser only. */
|
|
66
|
+
export function send(patch) {
|
|
67
|
+
const auth = scope();
|
|
68
|
+
if (!auth.Authorization)
|
|
69
|
+
return;
|
|
70
|
+
if (read?.auth === auth.Authorization) {
|
|
71
|
+
const was = read.doc;
|
|
72
|
+
read = { auth: auth.Authorization, doc: was.then((doc) => ({ ...(doc ?? {}), ...patch })) };
|
|
73
|
+
}
|
|
74
|
+
void fetch(`${api()}/v1/pref`, {
|
|
75
|
+
method: 'PATCH',
|
|
76
|
+
headers: { ...auth, 'Content-Type': 'application/json' },
|
|
77
|
+
body: JSON.stringify(patch),
|
|
78
|
+
}).catch(() => { });
|
|
79
|
+
}
|
|
80
|
+
function local(key, initial) {
|
|
81
|
+
try {
|
|
82
|
+
const raw = localStorage.getItem(key);
|
|
83
|
+
return raw === null ? initial : JSON.parse(raw);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return initial;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function keep(key, v) {
|
|
90
|
+
try {
|
|
91
|
+
localStorage.setItem(key, JSON.stringify(v));
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
/* the account still holds it */
|
|
95
|
+
}
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/app",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.46",
|
|
4
4
|
"description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|