@oxyhq/services 22.0.0 → 22.1.0
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/lib/commonjs/index.js +12 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/ui/components/OxyAccountDialog.js +27 -529
- package/lib/commonjs/ui/components/OxyAccountDialog.js.map +1 -1
- package/lib/commonjs/ui/components/OxyAuthChooser.js +881 -0
- package/lib/commonjs/ui/components/OxyAuthChooser.js.map +1 -0
- package/lib/commonjs/ui/components/oxyAuthChooserStyles.js +158 -0
- package/lib/commonjs/ui/components/oxyAuthChooserStyles.js.map +1 -0
- package/lib/commonjs/ui/context/OxyContext.js +28 -3
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/context/useOxyAccountGraph.js +6 -2
- package/lib/commonjs/ui/context/useOxyAccountGraph.js.map +1 -1
- package/lib/commonjs/ui/hooks/useSwitchableAccounts.js +2 -1
- package/lib/commonjs/ui/hooks/useSwitchableAccounts.js.map +1 -1
- package/lib/commonjs/ui/utils/commonsStoreLinks.js +42 -0
- package/lib/commonjs/ui/utils/commonsStoreLinks.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/ui/components/OxyAccountDialog.js +29 -533
- package/lib/module/ui/components/OxyAccountDialog.js.map +1 -1
- package/lib/module/ui/components/OxyAuthChooser.js +878 -0
- package/lib/module/ui/components/OxyAuthChooser.js.map +1 -0
- package/lib/module/ui/components/oxyAuthChooserStyles.js +155 -0
- package/lib/module/ui/components/oxyAuthChooserStyles.js.map +1 -0
- package/lib/module/ui/context/OxyContext.js +28 -3
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/context/useOxyAccountGraph.js +6 -2
- package/lib/module/ui/context/useOxyAccountGraph.js.map +1 -1
- package/lib/module/ui/hooks/useSwitchableAccounts.js +2 -1
- package/lib/module/ui/hooks/useSwitchableAccounts.js.map +1 -1
- package/lib/module/ui/utils/commonsStoreLinks.js +37 -0
- package/lib/module/ui/utils/commonsStoreLinks.js.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +2 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/OxyAccountDialog.d.ts +10 -20
- package/lib/typescript/commonjs/ui/components/OxyAccountDialog.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/OxyAuthChooser.d.ts +60 -0
- package/lib/typescript/commonjs/ui/components/OxyAuthChooser.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/oxyAuthChooserStyles.d.ts +148 -0
- package/lib/typescript/commonjs/ui/components/oxyAuthChooserStyles.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/context/useOxyAccountGraph.d.ts +1 -0
- package/lib/typescript/commonjs/ui/context/useOxyAccountGraph.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useSwitchableAccounts.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/utils/commonsStoreLinks.d.ts +24 -0
- package/lib/typescript/commonjs/ui/utils/commonsStoreLinks.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +2 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/OxyAccountDialog.d.ts +10 -20
- package/lib/typescript/module/ui/components/OxyAccountDialog.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/OxyAuthChooser.d.ts +60 -0
- package/lib/typescript/module/ui/components/OxyAuthChooser.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/oxyAuthChooserStyles.d.ts +148 -0
- package/lib/typescript/module/ui/components/oxyAuthChooserStyles.d.ts.map +1 -0
- package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/module/ui/context/useOxyAccountGraph.d.ts +1 -0
- package/lib/typescript/module/ui/context/useOxyAccountGraph.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useSwitchableAccounts.d.ts.map +1 -1
- package/lib/typescript/module/ui/utils/commonsStoreLinks.d.ts +24 -0
- package/lib/typescript/module/ui/utils/commonsStoreLinks.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +7 -0
- package/src/ui/components/OxyAccountDialog.tsx +33 -557
- package/src/ui/components/OxyAuthChooser.tsx +883 -0
- package/src/ui/components/oxyAuthChooserStyles.ts +152 -0
- package/src/ui/context/OxyContext.tsx +31 -3
- package/src/ui/context/useOxyAccountGraph.ts +4 -2
- package/src/ui/hooks/useSwitchableAccounts.ts +1 -0
- package/src/ui/utils/commonsStoreLinks.ts +38 -0
|
@@ -3,24 +3,13 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* OxyAccountDialog — the ONE unified account dialog for `@oxyhq/services`.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* (the uniform switch), the active row is flagged, and a "+ Add account" row
|
|
14
|
-
* opens the sign-in entry. This is what `ProfileButton` opens.
|
|
15
|
-
* - `add` / `signin` — the sign-in entry: primary "Sign in with Oxy" (device
|
|
16
|
-
* flow), "Scan a QR", and a secondary "Use a password" hand-off that opens
|
|
17
|
-
* auth.oxy.so (password + 2FA are NOT in the SDK).
|
|
18
|
-
* - `qr` — the cross-device QR handoff + its waiting state.
|
|
19
|
-
*
|
|
20
|
-
* Per-account color re-theming uses Bloom's `APP_COLOR_PRESETS` + `BloomColorScope`
|
|
21
|
-
* (same visual language auth.oxy.so uses). Base theming is `useTheme()` + a
|
|
22
|
-
* `StyleSheet`, so the dialog renders correctly in EVERY consumer — including apps
|
|
23
|
-
* that do not use NativeWind (e.g. the accounts app).
|
|
6
|
+
* Bloom `<Dialog>` chrome (header, back button, placement, scroll body) around
|
|
7
|
+
* the headless chooser logic, which lives in `OxyAuthChooser` — the account
|
|
8
|
+
* switcher, sign-in, sign-up, and QR views are ALL there, extracted so the
|
|
9
|
+
* same chooser can be mounted bare by a future host with no Dialog chrome
|
|
10
|
+
* (e.g. an auth.oxy.so hub page driving the cross-origin passkey popup, b2).
|
|
11
|
+
* This file owns ONLY the chrome: the title/subtitle per view, the back
|
|
12
|
+
* button, and the Bloom `<Dialog>` surface itself.
|
|
24
13
|
*
|
|
25
14
|
* The surface is Bloom's `<Dialog>` (`@oxyhq/bloom/dialog`) with a responsive
|
|
26
15
|
* `placement` — a bottom sheet on narrow viewports, a centered card on wide ones.
|
|
@@ -36,50 +25,22 @@
|
|
|
36
25
|
* Backdrop / swipe-to-dismiss is disabled (`dismissOnBackdrop={false}`) on purpose:
|
|
37
26
|
* Bloom's controlled `bottom` placement does not fire `onClose` on a gesture or
|
|
38
27
|
* backdrop dismissal, so allowing it would desync `isAccountDialogOpen` from the
|
|
39
|
-
* sheet and block reopening. The header close button (and
|
|
40
|
-
* drive `closeAccountDialog`, which flips `open` and runs the exit
|
|
28
|
+
* sheet and block reopening. The header close button (and `OxyAuthChooser`'s
|
|
29
|
+
* `onComplete`) drive `closeAccountDialog`, which flips `open` and runs the exit
|
|
30
|
+
* animation.
|
|
41
31
|
*/
|
|
42
32
|
|
|
43
|
-
import { useCallback,
|
|
33
|
+
import { useCallback, useSyncExternalStore } from 'react';
|
|
44
34
|
import { Pressable, ScrollView, StyleSheet, View } from 'react-native';
|
|
45
35
|
import { MaterialCommunityIcons } from '@expo/vector-icons';
|
|
46
|
-
import QRCode from 'react-native-qrcode-svg';
|
|
47
|
-
import { Avatar } from '@oxyhq/bloom/avatar';
|
|
48
|
-
import { Button } from '@oxyhq/bloom/button';
|
|
49
36
|
import { Dialog } from '@oxyhq/bloom/dialog';
|
|
50
37
|
import { Text } from '@oxyhq/bloom/typography';
|
|
51
|
-
import { useTheme
|
|
52
|
-
import { isOxyRpOrigin } from '@oxyhq/core';
|
|
53
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
38
|
+
import { useTheme } from '@oxyhq/bloom/theme';
|
|
54
39
|
import { useOxy } from "../context/OxyContext.js";
|
|
55
40
|
import { useI18n } from "../hooks/useI18n.js";
|
|
56
|
-
import
|
|
41
|
+
import OxyAuthChooser from "./OxyAuthChooser.js";
|
|
57
42
|
import { LogoIcon } from "./logo/LogoIcon.js";
|
|
58
|
-
|
|
59
|
-
/** Diameter of a row avatar. */
|
|
60
43
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
61
|
-
const ROW_AVATAR_SIZE = 40;
|
|
62
|
-
/** High-contrast QR colors — intentionally fixed (NOT themed) for scan reliability. */
|
|
63
|
-
const QR_PLATE_BG = '#FFFFFF';
|
|
64
|
-
const QR_FOREGROUND = '#000000';
|
|
65
|
-
const QR_SIZE = 196;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Resolve an account's stored color (a named Bloom preset, e.g. `'purple'`) to
|
|
69
|
-
* a concrete brand hex for the row accent. Falls back to the theme primary when
|
|
70
|
-
* the account has no color or the value is not a recognized preset, so the accent
|
|
71
|
-
* renders in EVERY consumer regardless of NativeWind availability.
|
|
72
|
-
*/
|
|
73
|
-
function resolveAccentHex(color, fallback) {
|
|
74
|
-
const preset = toPreset(color);
|
|
75
|
-
return preset ? APP_COLOR_PRESETS[preset].hex : fallback;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Narrow a stored color string to a known `AppColorName`, or `undefined`. */
|
|
79
|
-
function toPreset(color) {
|
|
80
|
-
if (!color) return undefined;
|
|
81
|
-
return APP_COLOR_NAMES.includes(color) ? color : undefined;
|
|
82
|
-
}
|
|
83
44
|
/**
|
|
84
45
|
* The unified account dialog. Mounted once by `OxyProvider`; opened imperatively
|
|
85
46
|
* via `useOxy().openAccountDialog(view?)` or imperative `openAccountDialog('signin')`.
|
|
@@ -88,93 +49,26 @@ const OxyAccountDialog = () => {
|
|
|
88
49
|
const {
|
|
89
50
|
accountDialogController: controller,
|
|
90
51
|
isAccountDialogOpen,
|
|
91
|
-
closeAccountDialog
|
|
92
|
-
showBottomSheet,
|
|
93
|
-
logoutAll,
|
|
94
|
-
refreshAccounts,
|
|
95
|
-
signInWithPasskey
|
|
52
|
+
closeAccountDialog
|
|
96
53
|
} = useOxy();
|
|
97
54
|
const theme = useTheme();
|
|
98
55
|
const {
|
|
99
56
|
t
|
|
100
57
|
} = useI18n();
|
|
101
|
-
const queryClient = useQueryClient();
|
|
102
58
|
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
// for arbitrary web origins is a later phase). This is environment-static.
|
|
107
|
-
const passkeyAvailable = useMemo(() => isWebBrowser() && isOxyRpOrigin(), []);
|
|
108
|
-
const [passkeyPending, setPasskeyPending] = useState(false);
|
|
109
|
-
const [passkeyError, setPasskeyError] = useState(null);
|
|
110
|
-
const handleSignInWithPasskey = useCallback(async () => {
|
|
111
|
-
if (passkeyPending) return;
|
|
112
|
-
setPasskeyPending(true);
|
|
113
|
-
setPasskeyError(null);
|
|
114
|
-
try {
|
|
115
|
-
await signInWithPasskey();
|
|
116
|
-
closeAccountDialog();
|
|
117
|
-
} catch (error) {
|
|
118
|
-
// A cancelled/failed ceremony keeps the dialog open so the user can retry
|
|
119
|
-
// or fall back to another method — surface a concise message, never swallow.
|
|
120
|
-
setPasskeyError(error instanceof Error && error.message ? error.message : 'Passkey sign-in failed.');
|
|
121
|
-
} finally {
|
|
122
|
-
setPasskeyPending(false);
|
|
123
|
-
}
|
|
124
|
-
}, [passkeyPending, signInWithPasskey, closeAccountDialog]);
|
|
125
|
-
|
|
126
|
-
// Bind the headless controller. `getSnapshot` returns a stable reference
|
|
127
|
-
// between changes, so it is `useSyncExternalStore`-safe. Guard the no-provider
|
|
128
|
-
// loading state (`controller` is `null`) with an inert store.
|
|
59
|
+
// A lightweight, header-only binding to the same controller `OxyAuthChooser`
|
|
60
|
+
// binds independently — cheap, and the established pattern here (
|
|
61
|
+
// `useSwitchableAccounts` also binds to this controller on its own).
|
|
129
62
|
const subscribe = useCallback(listener => controller ? controller.subscribe(listener) : () => undefined, [controller]);
|
|
130
63
|
const getSnapshot = useCallback(() => controller ? controller.getSnapshot() : EMPTY_SNAPSHOT, [controller]);
|
|
131
64
|
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
132
|
-
const [switching, setSwitching] = useState(false);
|
|
133
|
-
const handleSwitch = useCallback(async accountId => {
|
|
134
|
-
if (!controller || switching) return;
|
|
135
|
-
if (accountId === snapshot.activeAccountId) {
|
|
136
|
-
closeAccountDialog();
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
setSwitching(true);
|
|
140
|
-
try {
|
|
141
|
-
await controller.switchTo(accountId);
|
|
142
|
-
// A switch succeeds unless the controller recorded an error. On success
|
|
143
|
-
// reload the app's account graph and drop cached account-scoped data so
|
|
144
|
-
// the new active identity re-fetches — the same side effects the
|
|
145
|
-
// context's own `switchToAccount` performs.
|
|
146
|
-
if (!controller.getSnapshot().error) {
|
|
147
|
-
void refreshAccounts();
|
|
148
|
-
queryClient.invalidateQueries();
|
|
149
|
-
closeAccountDialog();
|
|
150
|
-
}
|
|
151
|
-
} finally {
|
|
152
|
-
setSwitching(false);
|
|
153
|
-
}
|
|
154
|
-
}, [controller, switching, snapshot.activeAccountId, closeAccountDialog, refreshAccounts, queryClient]);
|
|
155
|
-
const handleManage = useCallback(() => {
|
|
156
|
-
closeAccountDialog();
|
|
157
|
-
showBottomSheet?.('ManageAccount');
|
|
158
|
-
}, [closeAccountDialog, showBottomSheet]);
|
|
159
|
-
const handleSignOutAll = useCallback(() => {
|
|
160
|
-
closeAccountDialog();
|
|
161
|
-
void logoutAll();
|
|
162
|
-
}, [closeAccountDialog, logoutAll]);
|
|
163
|
-
const handlers = useMemo(() => ({
|
|
164
|
-
onSwitch: accountId => {
|
|
165
|
-
void handleSwitch(accountId);
|
|
166
|
-
},
|
|
167
|
-
onAdd: () => controller?.add(),
|
|
168
|
-
onManage: handleManage,
|
|
169
|
-
onClose: closeAccountDialog
|
|
170
|
-
}), [handleSwitch, controller, handleManage, closeAccountDialog]);
|
|
171
65
|
if (!controller) {
|
|
172
66
|
return null;
|
|
173
67
|
}
|
|
174
68
|
const {
|
|
175
69
|
view
|
|
176
70
|
} = snapshot;
|
|
177
|
-
const showBack = view === 'qr' || view === 'add' && snapshot.accounts.length > 0;
|
|
71
|
+
const showBack = view === 'qr' || view === 'signup' || view === 'add' && snapshot.accounts.length > 0;
|
|
178
72
|
return /*#__PURE__*/_jsxs(Dialog, {
|
|
179
73
|
open: isAccountDialogOpen,
|
|
180
74
|
onClose: closeAccountDialog,
|
|
@@ -196,26 +90,8 @@ const OxyAccountDialog = () => {
|
|
|
196
90
|
style: styles.body,
|
|
197
91
|
contentContainerStyle: styles.bodyContent,
|
|
198
92
|
showsVerticalScrollIndicator: false,
|
|
199
|
-
children:
|
|
200
|
-
|
|
201
|
-
theme: theme,
|
|
202
|
-
t: t,
|
|
203
|
-
handlers: handlers
|
|
204
|
-
}) : view === 'qr' ? /*#__PURE__*/_jsx(QrView, {
|
|
205
|
-
snapshot: snapshot,
|
|
206
|
-
theme: theme,
|
|
207
|
-
t: t,
|
|
208
|
-
onRetry: () => void controller.showQr()
|
|
209
|
-
}) : /*#__PURE__*/_jsx(SignInView, {
|
|
210
|
-
snapshot: snapshot,
|
|
211
|
-
theme: theme,
|
|
212
|
-
t: t,
|
|
213
|
-
handlers: handlers,
|
|
214
|
-
onSignInWithOxy: () => void controller.signInWithOxy(),
|
|
215
|
-
onScanQr: () => void controller.showQr(),
|
|
216
|
-
onSignInWithPasskey: passkeyAvailable ? () => void handleSignInWithPasskey() : undefined,
|
|
217
|
-
passkeyPending: passkeyPending,
|
|
218
|
-
passkeyError: passkeyError
|
|
93
|
+
children: /*#__PURE__*/_jsx(OxyAuthChooser, {
|
|
94
|
+
onComplete: closeAccountDialog
|
|
219
95
|
})
|
|
220
96
|
})]
|
|
221
97
|
});
|
|
@@ -287,280 +163,6 @@ const DialogHeader = ({
|
|
|
287
163
|
});
|
|
288
164
|
};
|
|
289
165
|
|
|
290
|
-
// ---------------------------------------------------------------------------
|
|
291
|
-
// Accounts view
|
|
292
|
-
// ---------------------------------------------------------------------------
|
|
293
|
-
|
|
294
|
-
const AccountsView = ({
|
|
295
|
-
snapshot,
|
|
296
|
-
theme,
|
|
297
|
-
t,
|
|
298
|
-
handlers
|
|
299
|
-
}) => {
|
|
300
|
-
if (snapshot.loading && snapshot.accounts.length === 0) {
|
|
301
|
-
return /*#__PURE__*/_jsxs(View, {
|
|
302
|
-
style: styles.centeredBlock,
|
|
303
|
-
children: [/*#__PURE__*/_jsx(MaterialCommunityIcons, {
|
|
304
|
-
name: "loading",
|
|
305
|
-
size: 24,
|
|
306
|
-
color: theme.colors.textSecondary
|
|
307
|
-
}), /*#__PURE__*/_jsx(Text, {
|
|
308
|
-
style: [styles.mutedText, {
|
|
309
|
-
color: theme.colors.textSecondary
|
|
310
|
-
}],
|
|
311
|
-
children: t('accountSwitcher.loading') || 'Loading accounts…'
|
|
312
|
-
})]
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
return /*#__PURE__*/_jsxs(View, {
|
|
316
|
-
style: styles.rows,
|
|
317
|
-
children: [snapshot.accounts.map(account => /*#__PURE__*/_jsx(AccountRow, {
|
|
318
|
-
account: account,
|
|
319
|
-
theme: theme,
|
|
320
|
-
switching: snapshot.switchingAccountId === account.accountId,
|
|
321
|
-
disabled: snapshot.switchingAccountId !== null,
|
|
322
|
-
onPress: () => handlers.onSwitch(account.accountId)
|
|
323
|
-
}, account.accountId)), /*#__PURE__*/_jsxs(Pressable, {
|
|
324
|
-
style: [styles.addRow, {
|
|
325
|
-
borderColor: theme.colors.border
|
|
326
|
-
}],
|
|
327
|
-
onPress: handlers.onAdd,
|
|
328
|
-
accessibilityRole: "button",
|
|
329
|
-
accessibilityLabel: t('signin.addAccountTitle') || 'Add another account',
|
|
330
|
-
children: [/*#__PURE__*/_jsx(View, {
|
|
331
|
-
style: [styles.addBadge, {
|
|
332
|
-
borderColor: theme.colors.border
|
|
333
|
-
}],
|
|
334
|
-
children: /*#__PURE__*/_jsx(MaterialCommunityIcons, {
|
|
335
|
-
name: "plus",
|
|
336
|
-
size: 20,
|
|
337
|
-
color: theme.colors.textSecondary
|
|
338
|
-
})
|
|
339
|
-
}), /*#__PURE__*/_jsx(Text, {
|
|
340
|
-
style: [styles.rowName, {
|
|
341
|
-
color: theme.colors.textSecondary
|
|
342
|
-
}],
|
|
343
|
-
children: t('signin.addAccountTitle') || 'Add another account'
|
|
344
|
-
})]
|
|
345
|
-
}), /*#__PURE__*/_jsx(View, {
|
|
346
|
-
style: styles.footerLinks,
|
|
347
|
-
children: /*#__PURE__*/_jsx(Pressable, {
|
|
348
|
-
onPress: handlers.onManage,
|
|
349
|
-
accessibilityRole: "button",
|
|
350
|
-
children: /*#__PURE__*/_jsx(Text, {
|
|
351
|
-
style: [styles.linkText, {
|
|
352
|
-
color: theme.colors.primary
|
|
353
|
-
}],
|
|
354
|
-
children: t('accountMenu.manage') || 'Manage accounts'
|
|
355
|
-
})
|
|
356
|
-
})
|
|
357
|
-
})]
|
|
358
|
-
});
|
|
359
|
-
};
|
|
360
|
-
const AccountRow = ({
|
|
361
|
-
account,
|
|
362
|
-
theme,
|
|
363
|
-
switching,
|
|
364
|
-
disabled,
|
|
365
|
-
onPress
|
|
366
|
-
}) => {
|
|
367
|
-
const accent = resolveAccentHex(account.color, theme.colors.primary);
|
|
368
|
-
const rowStyle = [styles.accountRow, {
|
|
369
|
-
borderColor: account.isCurrent ? accent : theme.colors.border,
|
|
370
|
-
backgroundColor: theme.colors.card
|
|
371
|
-
}, disabled && !switching ? styles.rowDisabled : null];
|
|
372
|
-
return /*#__PURE__*/_jsx(BloomColorScope, {
|
|
373
|
-
colorPreset: toPreset(account.color),
|
|
374
|
-
asChild: true,
|
|
375
|
-
children: /*#__PURE__*/_jsxs(Pressable, {
|
|
376
|
-
style: rowStyle,
|
|
377
|
-
onPress: onPress,
|
|
378
|
-
disabled: disabled,
|
|
379
|
-
accessibilityRole: "button",
|
|
380
|
-
accessibilityState: {
|
|
381
|
-
selected: account.isCurrent,
|
|
382
|
-
disabled
|
|
383
|
-
},
|
|
384
|
-
accessibilityLabel: account.displayName,
|
|
385
|
-
children: [/*#__PURE__*/_jsx(View, {
|
|
386
|
-
style: [styles.avatarRing, {
|
|
387
|
-
borderColor: account.isCurrent ? accent : 'transparent'
|
|
388
|
-
}],
|
|
389
|
-
children: /*#__PURE__*/_jsx(Avatar, {
|
|
390
|
-
source: account.avatarUrl ?? undefined,
|
|
391
|
-
variant: "thumb",
|
|
392
|
-
name: account.displayName,
|
|
393
|
-
size: ROW_AVATAR_SIZE
|
|
394
|
-
})
|
|
395
|
-
}), /*#__PURE__*/_jsxs(View, {
|
|
396
|
-
style: styles.rowMeta,
|
|
397
|
-
children: [/*#__PURE__*/_jsx(Text, {
|
|
398
|
-
style: [styles.rowName, {
|
|
399
|
-
color: theme.colors.text
|
|
400
|
-
}],
|
|
401
|
-
numberOfLines: 1,
|
|
402
|
-
children: account.displayName
|
|
403
|
-
}), account.email ? /*#__PURE__*/_jsx(Text, {
|
|
404
|
-
style: [styles.rowHandle, {
|
|
405
|
-
color: theme.colors.textSecondary
|
|
406
|
-
}],
|
|
407
|
-
numberOfLines: 1,
|
|
408
|
-
children: account.email
|
|
409
|
-
}) : null]
|
|
410
|
-
}), switching ? /*#__PURE__*/_jsx(MaterialCommunityIcons, {
|
|
411
|
-
name: "loading",
|
|
412
|
-
size: 20,
|
|
413
|
-
color: accent
|
|
414
|
-
}) : account.isCurrent ? /*#__PURE__*/_jsx(MaterialCommunityIcons, {
|
|
415
|
-
name: "check-circle",
|
|
416
|
-
size: 20,
|
|
417
|
-
color: accent
|
|
418
|
-
}) : /*#__PURE__*/_jsx(MaterialCommunityIcons, {
|
|
419
|
-
name: "chevron-right",
|
|
420
|
-
size: 20,
|
|
421
|
-
color: theme.colors.textSecondary
|
|
422
|
-
})]
|
|
423
|
-
})
|
|
424
|
-
});
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
// ---------------------------------------------------------------------------
|
|
428
|
-
// Sign-in view (add / signin)
|
|
429
|
-
// ---------------------------------------------------------------------------
|
|
430
|
-
|
|
431
|
-
const SignInView = ({
|
|
432
|
-
snapshot,
|
|
433
|
-
theme,
|
|
434
|
-
t,
|
|
435
|
-
handlers,
|
|
436
|
-
onSignInWithOxy,
|
|
437
|
-
onScanQr,
|
|
438
|
-
onSignInWithPasskey,
|
|
439
|
-
passkeyPending,
|
|
440
|
-
passkeyError
|
|
441
|
-
}) => /*#__PURE__*/_jsxs(View, {
|
|
442
|
-
style: styles.signInBlock,
|
|
443
|
-
children: [snapshot.accounts.length > 0 ? /*#__PURE__*/_jsxs(View, {
|
|
444
|
-
style: styles.rows,
|
|
445
|
-
children: [snapshot.accounts.map(account => /*#__PURE__*/_jsx(AccountRow, {
|
|
446
|
-
account: account,
|
|
447
|
-
theme: theme,
|
|
448
|
-
switching: snapshot.switchingAccountId === account.accountId,
|
|
449
|
-
disabled: snapshot.switchingAccountId !== null,
|
|
450
|
-
onPress: () => handlers.onSwitch(account.accountId)
|
|
451
|
-
}, account.accountId)), /*#__PURE__*/_jsx(Dividerish, {
|
|
452
|
-
theme: theme,
|
|
453
|
-
label: t('signin.or') || 'or'
|
|
454
|
-
})]
|
|
455
|
-
}) : null, /*#__PURE__*/_jsx(Button, {
|
|
456
|
-
variant: "primary",
|
|
457
|
-
onPress: onSignInWithOxy,
|
|
458
|
-
style: styles.primaryButton,
|
|
459
|
-
children: "Sign in with Oxy"
|
|
460
|
-
}), onSignInWithPasskey ? /*#__PURE__*/_jsx(Button, {
|
|
461
|
-
variant: "secondary",
|
|
462
|
-
onPress: onSignInWithPasskey,
|
|
463
|
-
disabled: passkeyPending,
|
|
464
|
-
style: styles.secondaryButton,
|
|
465
|
-
testID: "passkey-signin-button",
|
|
466
|
-
children: passkeyPending ? t('accountSwitcher.passkeySigningIn') || 'Signing in…' : t('accountSwitcher.signInWithPasskey') || 'Sign in with a passkey'
|
|
467
|
-
}) : null, passkeyError ? /*#__PURE__*/_jsx(Text, {
|
|
468
|
-
style: [styles.errorText, {
|
|
469
|
-
color: theme.colors.error
|
|
470
|
-
}],
|
|
471
|
-
children: passkeyError
|
|
472
|
-
}) : null, /*#__PURE__*/_jsx(Button, {
|
|
473
|
-
variant: "secondary",
|
|
474
|
-
onPress: onScanQr,
|
|
475
|
-
style: styles.secondaryButton,
|
|
476
|
-
children: t('accountSwitcher.scanQr') || 'Scan a QR from another device'
|
|
477
|
-
})]
|
|
478
|
-
});
|
|
479
|
-
const Dividerish = ({
|
|
480
|
-
theme,
|
|
481
|
-
label
|
|
482
|
-
}) => /*#__PURE__*/_jsxs(View, {
|
|
483
|
-
style: styles.dividerRow,
|
|
484
|
-
children: [/*#__PURE__*/_jsx(View, {
|
|
485
|
-
style: [styles.dividerLine, {
|
|
486
|
-
backgroundColor: theme.colors.border
|
|
487
|
-
}]
|
|
488
|
-
}), /*#__PURE__*/_jsx(Text, {
|
|
489
|
-
style: [styles.dividerText, {
|
|
490
|
-
color: theme.colors.textSecondary
|
|
491
|
-
}],
|
|
492
|
-
children: label
|
|
493
|
-
}), /*#__PURE__*/_jsx(View, {
|
|
494
|
-
style: [styles.dividerLine, {
|
|
495
|
-
backgroundColor: theme.colors.border
|
|
496
|
-
}]
|
|
497
|
-
})]
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
// ---------------------------------------------------------------------------
|
|
501
|
-
// QR view
|
|
502
|
-
// ---------------------------------------------------------------------------
|
|
503
|
-
|
|
504
|
-
const QrView = ({
|
|
505
|
-
snapshot,
|
|
506
|
-
theme,
|
|
507
|
-
t,
|
|
508
|
-
onRetry
|
|
509
|
-
}) => {
|
|
510
|
-
const {
|
|
511
|
-
signIn
|
|
512
|
-
} = snapshot;
|
|
513
|
-
if (signIn.phase === 'error') {
|
|
514
|
-
return /*#__PURE__*/_jsxs(View, {
|
|
515
|
-
style: styles.centeredBlock,
|
|
516
|
-
children: [/*#__PURE__*/_jsx(Text, {
|
|
517
|
-
style: [styles.errorText, {
|
|
518
|
-
color: theme.colors.error
|
|
519
|
-
}],
|
|
520
|
-
children: signIn.error || 'Sign-in failed. Please try again.'
|
|
521
|
-
}), /*#__PURE__*/_jsx(Button, {
|
|
522
|
-
variant: "secondary",
|
|
523
|
-
onPress: onRetry,
|
|
524
|
-
style: styles.secondaryButton,
|
|
525
|
-
children: t('common.actions.tryAgain') || 'Try again'
|
|
526
|
-
})]
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
if (signIn.phase === 'starting' || signIn.phase === 'authorized' || !signIn.qrPayload) {
|
|
530
|
-
const label = signIn.phase === 'authorized' ? t('signin.status.signingIn') || 'Signing in…' : t('accountSwitcher.loading') || 'Preparing sign-in…';
|
|
531
|
-
return /*#__PURE__*/_jsxs(View, {
|
|
532
|
-
style: styles.centeredBlock,
|
|
533
|
-
children: [/*#__PURE__*/_jsx(MaterialCommunityIcons, {
|
|
534
|
-
name: "loading",
|
|
535
|
-
size: 26,
|
|
536
|
-
color: theme.colors.primary
|
|
537
|
-
}), /*#__PURE__*/_jsx(Text, {
|
|
538
|
-
style: [styles.mutedText, {
|
|
539
|
-
color: theme.colors.textSecondary
|
|
540
|
-
}],
|
|
541
|
-
children: label
|
|
542
|
-
})]
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
return /*#__PURE__*/_jsxs(View, {
|
|
546
|
-
style: styles.centeredBlock,
|
|
547
|
-
children: [/*#__PURE__*/_jsx(View, {
|
|
548
|
-
style: styles.qrPlate,
|
|
549
|
-
children: /*#__PURE__*/_jsx(QRCode, {
|
|
550
|
-
value: signIn.qrPayload,
|
|
551
|
-
size: QR_SIZE,
|
|
552
|
-
backgroundColor: QR_PLATE_BG,
|
|
553
|
-
color: QR_FOREGROUND
|
|
554
|
-
})
|
|
555
|
-
}), /*#__PURE__*/_jsx(Text, {
|
|
556
|
-
style: [styles.mutedText, {
|
|
557
|
-
color: theme.colors.textSecondary
|
|
558
|
-
}],
|
|
559
|
-
children: t('accountSwitcher.scanWithOxy') || 'Scan with any Oxy app and approve.'
|
|
560
|
-
})]
|
|
561
|
-
});
|
|
562
|
-
};
|
|
563
|
-
|
|
564
166
|
// ---------------------------------------------------------------------------
|
|
565
167
|
// Copy + helpers
|
|
566
168
|
// ---------------------------------------------------------------------------
|
|
@@ -574,8 +176,13 @@ function headerCopy(view, accountCount, t) {
|
|
|
574
176
|
};
|
|
575
177
|
case 'qr':
|
|
576
178
|
return {
|
|
577
|
-
title: t('accountSwitcher.scanTitle') || '
|
|
578
|
-
subtitle: t('accountSwitcher.scanSubtitle') || '
|
|
179
|
+
title: t('accountSwitcher.scanTitle') || 'Sign in with Oxy',
|
|
180
|
+
subtitle: t('accountSwitcher.scanSubtitle') || 'Scan with Commons on your phone.'
|
|
181
|
+
};
|
|
182
|
+
case 'signup':
|
|
183
|
+
return {
|
|
184
|
+
title: t('signup.title') || 'Create your account',
|
|
185
|
+
subtitle: t('signup.subtitle') || 'One identity for the whole ecosystem.'
|
|
579
186
|
};
|
|
580
187
|
default:
|
|
581
188
|
return accountCount > 0 ? {
|
|
@@ -587,12 +194,6 @@ function headerCopy(view, accountCount, t) {
|
|
|
587
194
|
};
|
|
588
195
|
}
|
|
589
196
|
}
|
|
590
|
-
|
|
591
|
-
/** Current document URL on web; `undefined` where `location` is absent. */
|
|
592
|
-
function currentHref() {
|
|
593
|
-
const location = globalThis.location;
|
|
594
|
-
return typeof location?.href === 'string' ? location.href : undefined;
|
|
595
|
-
}
|
|
596
197
|
const EMPTY_SNAPSHOT = {
|
|
597
198
|
view: 'accounts',
|
|
598
199
|
accounts: [],
|
|
@@ -606,7 +207,8 @@ const EMPTY_SNAPSHOT = {
|
|
|
606
207
|
qrPayload: null,
|
|
607
208
|
expiresAt: null,
|
|
608
209
|
error: null
|
|
609
|
-
}
|
|
210
|
+
},
|
|
211
|
+
commonsAvailability: 'unknown'
|
|
610
212
|
};
|
|
611
213
|
const styles = StyleSheet.create({
|
|
612
214
|
header: {
|
|
@@ -646,112 +248,6 @@ const styles = StyleSheet.create({
|
|
|
646
248
|
bodyContent: {
|
|
647
249
|
paddingTop: 4,
|
|
648
250
|
paddingBottom: 4
|
|
649
|
-
},
|
|
650
|
-
rows: {
|
|
651
|
-
width: '100%',
|
|
652
|
-
gap: 8
|
|
653
|
-
},
|
|
654
|
-
accountRow: {
|
|
655
|
-
flexDirection: 'row',
|
|
656
|
-
alignItems: 'center',
|
|
657
|
-
gap: 12,
|
|
658
|
-
borderWidth: StyleSheet.hairlineWidth,
|
|
659
|
-
borderRadius: 16,
|
|
660
|
-
paddingVertical: 10,
|
|
661
|
-
paddingHorizontal: 12
|
|
662
|
-
},
|
|
663
|
-
rowDisabled: {
|
|
664
|
-
opacity: 0.6
|
|
665
|
-
},
|
|
666
|
-
avatarRing: {
|
|
667
|
-
borderRadius: 9999,
|
|
668
|
-
borderWidth: 2,
|
|
669
|
-
padding: 1
|
|
670
|
-
},
|
|
671
|
-
rowMeta: {
|
|
672
|
-
flex: 1,
|
|
673
|
-
minWidth: 0
|
|
674
|
-
},
|
|
675
|
-
rowName: {
|
|
676
|
-
fontSize: 15,
|
|
677
|
-
fontWeight: '600'
|
|
678
|
-
},
|
|
679
|
-
rowHandle: {
|
|
680
|
-
fontSize: 12.5,
|
|
681
|
-
marginTop: 1
|
|
682
|
-
},
|
|
683
|
-
addRow: {
|
|
684
|
-
flexDirection: 'row',
|
|
685
|
-
alignItems: 'center',
|
|
686
|
-
gap: 12,
|
|
687
|
-
borderWidth: StyleSheet.hairlineWidth,
|
|
688
|
-
borderStyle: 'dashed',
|
|
689
|
-
borderRadius: 16,
|
|
690
|
-
paddingVertical: 10,
|
|
691
|
-
paddingHorizontal: 12,
|
|
692
|
-
marginTop: 8
|
|
693
|
-
},
|
|
694
|
-
addBadge: {
|
|
695
|
-
width: ROW_AVATAR_SIZE,
|
|
696
|
-
height: ROW_AVATAR_SIZE,
|
|
697
|
-
borderRadius: 9999,
|
|
698
|
-
borderWidth: StyleSheet.hairlineWidth,
|
|
699
|
-
alignItems: 'center',
|
|
700
|
-
justifyContent: 'center'
|
|
701
|
-
},
|
|
702
|
-
footerLinks: {
|
|
703
|
-
alignItems: 'center',
|
|
704
|
-
marginTop: 16
|
|
705
|
-
},
|
|
706
|
-
linkText: {
|
|
707
|
-
fontSize: 14,
|
|
708
|
-
fontWeight: '600'
|
|
709
|
-
},
|
|
710
|
-
signInBlock: {
|
|
711
|
-
width: '100%'
|
|
712
|
-
},
|
|
713
|
-
primaryButton: {
|
|
714
|
-
width: '100%',
|
|
715
|
-
borderRadius: 14,
|
|
716
|
-
marginTop: 8
|
|
717
|
-
},
|
|
718
|
-
secondaryButton: {
|
|
719
|
-
width: '100%',
|
|
720
|
-
borderRadius: 14,
|
|
721
|
-
marginTop: 10
|
|
722
|
-
},
|
|
723
|
-
dividerRow: {
|
|
724
|
-
flexDirection: 'row',
|
|
725
|
-
alignItems: 'center',
|
|
726
|
-
width: '100%',
|
|
727
|
-
marginVertical: 14
|
|
728
|
-
},
|
|
729
|
-
dividerLine: {
|
|
730
|
-
flex: 1,
|
|
731
|
-
height: StyleSheet.hairlineWidth
|
|
732
|
-
},
|
|
733
|
-
dividerText: {
|
|
734
|
-
marginHorizontal: 12,
|
|
735
|
-
fontSize: 13
|
|
736
|
-
},
|
|
737
|
-
centeredBlock: {
|
|
738
|
-
alignItems: 'center',
|
|
739
|
-
justifyContent: 'center',
|
|
740
|
-
gap: 12,
|
|
741
|
-
paddingVertical: 24
|
|
742
|
-
},
|
|
743
|
-
mutedText: {
|
|
744
|
-
fontSize: 14,
|
|
745
|
-
textAlign: 'center'
|
|
746
|
-
},
|
|
747
|
-
errorText: {
|
|
748
|
-
fontSize: 14,
|
|
749
|
-
textAlign: 'center'
|
|
750
|
-
},
|
|
751
|
-
qrPlate: {
|
|
752
|
-
padding: 16,
|
|
753
|
-
borderRadius: 16,
|
|
754
|
-
backgroundColor: QR_PLATE_BG
|
|
755
251
|
}
|
|
756
252
|
});
|
|
757
253
|
export default OxyAccountDialog;
|