@bufinance/web3-signin 0.1.2 → 0.1.4
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": "@bufinance/web3-signin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Headless cross-app Web3 wallet sign-in for BUFI: EIP-6963 wallet discovery + Supabase signInWithWeb3 (EIP-4361) + Turnstile captcha. Shared by desk-v1 and defi-web-app. Source of truth lives here; both apps consume it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -21,6 +21,7 @@ export interface WalletDropdownClassNames {
|
|
|
21
21
|
tabActive?: string;
|
|
22
22
|
accountRow?: string;
|
|
23
23
|
balanceRow?: string;
|
|
24
|
+
signOut?: string;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export interface WalletDropdownProps {
|
|
@@ -32,6 +33,19 @@ export interface WalletDropdownProps {
|
|
|
32
33
|
scope?: WalletScope | "all";
|
|
33
34
|
/** Currency formatter for the USD total; defaults to en-US $. */
|
|
34
35
|
formatUsd?: (n: number) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Custom trigger (pill) renderer. When provided, replaces the built-in
|
|
38
|
+
* text-only pill so a host can render its own rich trigger (icon, animated
|
|
39
|
+
* total, chevron) while the shell still owns open-state, the auth gate, and
|
|
40
|
+
* click-outside. The host renders its own button and calls `toggle` on click.
|
|
41
|
+
* Omit for the default pill (desk).
|
|
42
|
+
*/
|
|
43
|
+
trigger?: (state: {
|
|
44
|
+
open: boolean;
|
|
45
|
+
total: number;
|
|
46
|
+
toggle: () => void;
|
|
47
|
+
formatUsd: (n: number) => string;
|
|
48
|
+
}) => ReactNode;
|
|
35
49
|
/** Extra content inside the open panel — desk injects gateway/hinkal/multisig;
|
|
36
50
|
* defi-web injects its full per-chain balance body (net toggle, ghost, APY). */
|
|
37
51
|
children?: ReactNode;
|
|
@@ -45,6 +59,14 @@ export interface WalletDropdownProps {
|
|
|
45
59
|
/** Shown when authed but no accounts yet (provisioning). */
|
|
46
60
|
emptyState?: ReactNode;
|
|
47
61
|
onSelectAccount?: (account: WalletAccount) => void;
|
|
62
|
+
/**
|
|
63
|
+
* When provided, a "Log out" button renders at the BOTTOM of the open panel
|
|
64
|
+
* (below children). Both apps wire their own session sign-out — desk via
|
|
65
|
+
* Supabase, defi-web via the BUFI session — so the control lives in one place.
|
|
66
|
+
*/
|
|
67
|
+
onSignOut?: () => void;
|
|
68
|
+
/** Label for the sign-out button (default "Log out"). */
|
|
69
|
+
signOutLabel?: string;
|
|
48
70
|
classNames?: WalletDropdownClassNames;
|
|
49
71
|
}
|
|
50
72
|
|
|
@@ -61,10 +83,13 @@ export function WalletDropdown(props: WalletDropdownProps): ReactNode {
|
|
|
61
83
|
accounts,
|
|
62
84
|
scope = "all",
|
|
63
85
|
formatUsd = defaultFormatUsd,
|
|
86
|
+
trigger,
|
|
64
87
|
children,
|
|
65
88
|
renderBalances = true,
|
|
66
89
|
emptyState,
|
|
67
90
|
onSelectAccount,
|
|
91
|
+
onSignOut,
|
|
92
|
+
signOutLabel = "Log out",
|
|
68
93
|
classNames = {},
|
|
69
94
|
} = props;
|
|
70
95
|
|
|
@@ -103,17 +128,23 @@ export function WalletDropdown(props: WalletDropdownProps): ReactNode {
|
|
|
103
128
|
const active = visible.find((a) => a.id === activeId) ?? visible[0];
|
|
104
129
|
const pillTotal = active ? totalUsd(active.balances) : 0;
|
|
105
130
|
|
|
131
|
+
const toggle = (): void => setOpen((v) => !v);
|
|
132
|
+
|
|
106
133
|
return (
|
|
107
134
|
<div ref={rootRef} className={classNames.root} data-bufi-wallet>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
135
|
+
{trigger ? (
|
|
136
|
+
trigger({ open, total: pillTotal, toggle, formatUsd })
|
|
137
|
+
) : (
|
|
138
|
+
<button
|
|
139
|
+
type="button"
|
|
140
|
+
aria-label="Open Stablecoin FX Wallet"
|
|
141
|
+
aria-expanded={open}
|
|
142
|
+
className={classNames.pill ?? "acct-mini"}
|
|
143
|
+
onClick={toggle}
|
|
144
|
+
>
|
|
145
|
+
{formatUsd(pillTotal)}
|
|
146
|
+
</button>
|
|
147
|
+
)}
|
|
117
148
|
|
|
118
149
|
{open && (
|
|
119
150
|
<div role="menu" className={classNames.panel} data-bufi-wallet-panel>
|
|
@@ -168,6 +199,18 @@ export function WalletDropdown(props: WalletDropdownProps): ReactNode {
|
|
|
168
199
|
{children}
|
|
169
200
|
</>
|
|
170
201
|
)}
|
|
202
|
+
|
|
203
|
+
{/* Sign out — always the last thing in the panel. */}
|
|
204
|
+
{onSignOut && (
|
|
205
|
+
<button
|
|
206
|
+
type="button"
|
|
207
|
+
className={classNames.signOut}
|
|
208
|
+
onClick={onSignOut}
|
|
209
|
+
data-bufi-signout
|
|
210
|
+
>
|
|
211
|
+
{signOutLabel}
|
|
212
|
+
</button>
|
|
213
|
+
)}
|
|
171
214
|
</div>
|
|
172
215
|
)}
|
|
173
216
|
</div>
|