hd-wallet-ui 2.0.29 → 2.0.30

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/README.md CHANGED
@@ -8,10 +8,10 @@ and signed approval requests.
8
8
  ## Install
9
9
 
10
10
  ```sh
11
- npm install hd-wallet-ui@2.0.29
11
+ npm install hd-wallet-ui@2.0.30
12
12
  ```
13
13
 
14
- `hd-wallet-wasm` 2.0.29 is the package's only runtime dependency.
14
+ `hd-wallet-wasm` 2.0.30 is the package's only runtime dependency.
15
15
 
16
16
  ## Published surfaces
17
17
 
@@ -0,0 +1,99 @@
1
+ export interface AccountViewBond {
2
+ value?: string;
3
+ label?: string;
4
+ }
5
+
6
+ export interface AccountViewWallet {
7
+ id: string;
8
+ name?: string;
9
+ }
10
+
11
+ export interface AccountViewChip {
12
+ label: string;
13
+ tone?: string;
14
+ title?: string;
15
+ }
16
+
17
+ export interface AccountViewAction {
18
+ label: string;
19
+ onClick: () => unknown;
20
+ title?: string;
21
+ variant?: string;
22
+ }
23
+
24
+ export interface AccountViewTab {
25
+ id: string;
26
+ label?: string;
27
+ render?: (panel: HTMLElement) => void;
28
+ }
29
+
30
+ export interface AccountViewField {
31
+ id: string;
32
+ label?: string;
33
+ value?: string;
34
+ readOnly?: boolean;
35
+ multiline?: boolean;
36
+ placeholder?: string;
37
+ note?: string;
38
+ title?: string;
39
+ }
40
+
41
+ export interface AccountViewStatus {
42
+ text?: string;
43
+ tone?: 'busy' | 'error' | 'ok' | string;
44
+ }
45
+
46
+ export interface AccountViewIdentity {
47
+ fields?: AccountViewField[];
48
+ photoUrl?: string;
49
+ photoStatus?: AccountViewStatus;
50
+ saveStatus?: AccountViewStatus;
51
+ onSave?: (values: Record<string, string>) => unknown;
52
+ onPhoto?: (blob: Blob) => unknown;
53
+ onPhotoRemove?: () => unknown;
54
+ }
55
+
56
+ export interface AccountViewOptions {
57
+ document?: Document;
58
+ title?: string;
59
+ bond?: AccountViewBond;
60
+ wallets?: AccountViewWallet[];
61
+ activeWalletId?: string;
62
+ onWalletChange?: (walletId: string) => void;
63
+ chips?: AccountViewChip[];
64
+ actions?: AccountViewAction[];
65
+ tabs?: AccountViewTab[];
66
+ activeTabId?: string;
67
+ onTabChange?: (tabId: string) => void;
68
+ identity?: AccountViewIdentity;
69
+ onClose?: () => void;
70
+ }
71
+
72
+ export interface AccountViewUpdate {
73
+ title?: string;
74
+ bond?: AccountViewBond;
75
+ chips?: AccountViewChip[];
76
+ actions?: AccountViewAction[];
77
+ wallets?: AccountViewWallet[];
78
+ activeWalletId?: string;
79
+ identity?: AccountViewIdentity;
80
+ activeTabId?: string;
81
+ }
82
+
83
+ export interface AccountView {
84
+ element: HTMLElement;
85
+ panel(id: string): HTMLElement | null;
86
+ getActiveTab(): string | null;
87
+ setActiveTab(id: string): void;
88
+ update(next?: AccountViewUpdate): void;
89
+ destroy(): void;
90
+ }
91
+
92
+ export declare const DEFAULT_ACCOUNT_TABS: ReadonlyArray<{ id: string; label: string }>;
93
+
94
+ export declare function createAccountView(options?: AccountViewOptions): AccountView;
95
+
96
+ export declare function mountAccountView(
97
+ container: Element,
98
+ options?: AccountViewOptions,
99
+ ): AccountView;
@@ -0,0 +1,252 @@
1
+ const $ = Object.freeze([
2
+ Object.freeze({ id: "identity", label: "Identity" }),
3
+ Object.freeze({ id: "trust", label: "Trust Map" }),
4
+ Object.freeze({ id: "messaging", label: "Messaging" }),
5
+ Object.freeze({ id: "wallet", label: "Wallet" }),
6
+ Object.freeze({ id: "manage", label: "Manage" })
7
+ ]), z = Object.freeze(["image/png", "image/jpeg", "image/webp"]);
8
+ function o(t, i, f, p) {
9
+ const h = t.createElement(i);
10
+ return f && (h.className = f), p != null && p !== "" && (h.textContent = String(p)), h;
11
+ }
12
+ function g(t, i, f, p) {
13
+ const h = o(t, "button", i, f);
14
+ return h.type = "button", p && (h.title = p), h;
15
+ }
16
+ function m(t) {
17
+ return t == null ? "" : String(t);
18
+ }
19
+ function V(t) {
20
+ if (t?.document) return t.document;
21
+ if (typeof document < "u") return document;
22
+ throw new Error("createAccountView requires a document");
23
+ }
24
+ function q(t = {}) {
25
+ const i = V(t), f = (Array.isArray(t.tabs) && t.tabs.length ? t.tabs : $).filter((e) => e && typeof e.id == "string" && e.id !== "");
26
+ if (!f.length) throw new Error("createAccountView requires at least one tab");
27
+ const p = o(i, "div", "wallet-account-view modal-glass modal-wide");
28
+ p.setAttribute("data-wallet-account-view", "");
29
+ const h = o(i, "div", "modal-header account-modal-header"), j = o(i, "div", "account-header-info"), y = o(i, "div", "account-wallet-row"), l = o(i, "select", "glass-input compact account-wallet-select");
30
+ l.setAttribute("aria-label", "Select wallet"), y.append(l);
31
+ const B = o(i, "div", "account-wallet-summary"), v = o(i, "div", "account-wallet-balance-line"), w = o(i, "div", "ph-portfolio-value");
32
+ w.id = "wallet-bond-value";
33
+ const L = o(i, "div", "ph-portfolio-label");
34
+ v.append(w, L), B.append(v);
35
+ const A = o(i, "div", "account-header-title"), C = o(i, "span", "account-header-name"), I = o(i, "span", "account-header-chips");
36
+ A.append(C, I), j.append(y, B, A);
37
+ const d = o(i, "div", "account-header-actions"), S = g(i, "modal-close account-modal-close", "×", "Close");
38
+ S.setAttribute("aria-label", "Close"), d.append(S), h.append(j, d);
39
+ const P = o(i, "div", "modal-tabs");
40
+ P.setAttribute("role", "tablist");
41
+ const k = o(i, "div", "modal-body"), b = /* @__PURE__ */ new Map(), O = /* @__PURE__ */ new Map();
42
+ for (const e of f) {
43
+ const a = g(i, "modal-tab", m(e.label ?? e.id));
44
+ a.dataset.modalTab = `${e.id}-tab-content`, a.setAttribute("role", "tab");
45
+ const c = o(i, "div", "modal-tab-content");
46
+ c.id = `${e.id}-tab-content`, c.setAttribute("role", "tabpanel"), O.set(e.id, a), b.set(e.id, c), P.append(a), k.append(c);
47
+ }
48
+ p.append(h, P, k);
49
+ let T = null;
50
+ function E(e) {
51
+ if (b.has(e)) {
52
+ T = e;
53
+ for (const [a, c] of O) {
54
+ const s = a === e;
55
+ c.classList.toggle("active", s), c.setAttribute("aria-selected", s ? "true" : "false"), b.get(a).classList.toggle("active", s);
56
+ }
57
+ typeof t.onTabChange == "function" && t.onTabChange(e);
58
+ }
59
+ }
60
+ for (const [e, a] of O)
61
+ a.addEventListener("click", () => E(e));
62
+ const U = b.get("identity"), R = D(i, t.identity ?? {}, U);
63
+ for (const e of f)
64
+ typeof e.render == "function" && e.render(b.get(e.id));
65
+ S.addEventListener("click", () => {
66
+ typeof t.onClose == "function" && t.onClose();
67
+ }), l.addEventListener("change", () => {
68
+ typeof t.onWalletChange == "function" && t.onWalletChange(l.value);
69
+ });
70
+ function u(e) {
71
+ for (const a of [...d.querySelectorAll(".account-header-action")]) a.remove();
72
+ for (const a of Array.isArray(e) ? e : []) {
73
+ if (!a || typeof a.label != "string") continue;
74
+ const c = g(
75
+ i,
76
+ `glass-btn small account-header-action${a.variant ? ` ${a.variant}` : ""}`,
77
+ a.label,
78
+ a.title
79
+ );
80
+ c.addEventListener("click", () => {
81
+ typeof a.onClick == "function" && a.onClick();
82
+ }), d.insertBefore(c, S);
83
+ }
84
+ }
85
+ function M(e) {
86
+ I.replaceChildren();
87
+ for (const a of Array.isArray(e) ? e : []) {
88
+ if (!a || typeof a.label != "string") continue;
89
+ const c = o(i, "span", `account-chip${a.tone ? ` chip-${a.tone}` : ""}`, a.label);
90
+ a.title && (c.title = a.title), I.append(c);
91
+ }
92
+ }
93
+ function n(e, a) {
94
+ l.replaceChildren();
95
+ const c = Array.isArray(e) ? e : [];
96
+ for (const s of c) {
97
+ if (!s || typeof s.id != "string") continue;
98
+ const W = o(i, "option", "", m(s.name ?? s.id));
99
+ W.value = s.id, l.append(W);
100
+ }
101
+ l.hidden = c.length === 0, typeof a == "string" && c.some((s) => s?.id === a) && (l.value = a);
102
+ }
103
+ function r(e = {}) {
104
+ "title" in e && (C.textContent = m(e.title)), "bond" in e && (w.textContent = m(e.bond?.value ?? ""), L.textContent = m(e.bond?.label ?? "Bond")), "chips" in e && M(e.chips), "actions" in e && u(e.actions), ("wallets" in e || "activeWalletId" in e) && n(e.wallets ?? t.wallets, e.activeWalletId ?? t.activeWalletId), "identity" in e && R.update(e.identity ?? {}), "activeTabId" in e && E(e.activeTabId);
105
+ }
106
+ return r({
107
+ title: t.title ?? "",
108
+ bond: t.bond ?? {},
109
+ chips: t.chips,
110
+ actions: t.actions,
111
+ wallets: t.wallets,
112
+ activeWalletId: t.activeWalletId
113
+ }), E(
114
+ typeof t.activeTabId == "string" && b.has(t.activeTabId) ? t.activeTabId : f[0].id
115
+ ), {
116
+ element: p,
117
+ panel: (e) => b.get(e) ?? null,
118
+ getActiveTab: () => T,
119
+ setActiveTab: E,
120
+ update: r,
121
+ destroy() {
122
+ R.destroy(), p.remove();
123
+ }
124
+ };
125
+ }
126
+ function N(t, i = {}) {
127
+ if (!t || typeof t.append != "function")
128
+ throw new Error("mountAccountView requires a container element");
129
+ const f = q({ document: t.ownerDocument, ...i });
130
+ return t.append(f.element), f;
131
+ }
132
+ function D(t, i, f) {
133
+ const p = o(t, "div", "identity-card"), h = o(t, "div", "identity-card-photo"), j = o(t, "div", "photo-preview"), y = o(t, "img", "photo-image");
134
+ y.alt = "", y.hidden = !0;
135
+ const l = o(t, "video", "photo-camera");
136
+ l.autoplay = !0, l.playsInline = !0, l.hidden = !0;
137
+ const B = o(t, "div", "photo-actions"), v = o(t, "input", "photo-file-input");
138
+ v.type = "file", v.accept = z.join(","), v.hidden = !0;
139
+ const w = g(t, "glass-btn small", "Upload"), L = g(t, "glass-btn small", "Use Camera"), A = g(t, "glass-btn small primary", "Capture"), C = g(t, "glass-btn small", "Cancel"), I = g(t, "glass-btn small", "Remove");
140
+ A.hidden = !0, C.hidden = !0, B.append(w, L, A, C, I, v), j.append(y, l);
141
+ const d = o(t, "p", "photo-status");
142
+ h.append(j, B, d);
143
+ const S = o(t, "div", "identity-fields"), P = o(t, "div", "identity-save-row"), k = g(t, "glass-btn primary", "Save"), b = o(t, "span", "identity-save-status");
144
+ P.append(k, b), p.append(h, S, P), f && f.append(p);
145
+ const O = /* @__PURE__ */ new Map();
146
+ let T = null;
147
+ function E() {
148
+ if (T) {
149
+ for (const n of T.getTracks()) n.stop();
150
+ T = null;
151
+ }
152
+ l.hidden = !0, "srcObject" in l && (l.srcObject = null), A.hidden = !0, C.hidden = !0, L.hidden = !1, w.hidden = !1;
153
+ }
154
+ function U(n) {
155
+ S.replaceChildren(), O.clear();
156
+ let r = !1;
157
+ for (const e of Array.isArray(n) ? n : []) {
158
+ if (!e || typeof e.id != "string") continue;
159
+ const a = o(t, "div", "identity-field"), c = o(t, "label", "identity-field-label", m(e.label ?? e.id));
160
+ if (a.append(c), e.readOnly) {
161
+ const s = o(t, "div", "identity-field-value", m(e.value));
162
+ e.title && (s.title = e.title), a.append(s);
163
+ } else {
164
+ r = !0;
165
+ const s = o(t, e.multiline ? "textarea" : "input", "glass-input identity-field-input");
166
+ e.multiline || (s.type = "text"), s.value = m(e.value), e.placeholder && (s.placeholder = e.placeholder);
167
+ const W = `identity-field-${e.id}`;
168
+ s.id = W, c.setAttribute("for", W), O.set(e.id, s), a.append(s);
169
+ }
170
+ e.note && a.append(o(t, "p", "identity-field-note", m(e.note))), S.append(a);
171
+ }
172
+ P.hidden = !r;
173
+ }
174
+ function R(n) {
175
+ const r = m(n);
176
+ y.hidden = r === "", r ? y.src = r : y.removeAttribute("src"), I.hidden = r === "";
177
+ }
178
+ function u(n, r, e) {
179
+ n.textContent = m(r), n.className = n.className.split(" ").filter((a) => !a.startsWith("status-")).join(" "), e && n.classList.add(`status-${e}`);
180
+ }
181
+ async function M(n) {
182
+ if (typeof i.onPhoto == "function") {
183
+ u(d, "Pinning…", "busy");
184
+ try {
185
+ await i.onPhoto(n), u(d, "", null);
186
+ } catch (r) {
187
+ u(d, r?.message || "The photo could not be stored.", "error");
188
+ }
189
+ }
190
+ }
191
+ return w.addEventListener("click", () => v.click()), v.addEventListener("change", () => {
192
+ const n = v.files && v.files[0];
193
+ v.value = "", n && M(n);
194
+ }), L.addEventListener("click", async () => {
195
+ const n = t.defaultView?.navigator?.mediaDevices;
196
+ if (!n || typeof n.getUserMedia != "function") {
197
+ u(d, "This browser has no camera available.", "error");
198
+ return;
199
+ }
200
+ try {
201
+ T = await n.getUserMedia({ video: !0 });
202
+ } catch {
203
+ u(d, "Camera access was refused.", "error");
204
+ return;
205
+ }
206
+ "srcObject" in l && (l.srcObject = T), l.hidden = !1, A.hidden = !1, C.hidden = !1, L.hidden = !0, w.hidden = !0, u(d, "", null);
207
+ }), C.addEventListener("click", E), A.addEventListener("click", async () => {
208
+ const n = t.createElement("canvas");
209
+ n.width = l.videoWidth || 512, n.height = l.videoHeight || 512;
210
+ const r = typeof n.getContext == "function" ? n.getContext("2d") : null;
211
+ if (!r) {
212
+ u(d, "This browser cannot capture from the camera.", "error");
213
+ return;
214
+ }
215
+ r.drawImage(l, 0, 0, n.width, n.height), E();
216
+ const e = await new Promise((a) => {
217
+ typeof n.toBlob == "function" ? n.toBlob(a, "image/png") : a(null);
218
+ });
219
+ e ? await M(e) : u(d, "The capture produced no image.", "error");
220
+ }), I.addEventListener("click", async () => {
221
+ if (typeof i.onPhotoRemove == "function") {
222
+ u(d, "Removing…", "busy");
223
+ try {
224
+ await i.onPhotoRemove(), u(d, "", null);
225
+ } catch (n) {
226
+ u(d, n?.message || "The photo could not be removed.", "error");
227
+ }
228
+ }
229
+ }), k.addEventListener("click", async () => {
230
+ if (typeof i.onSave != "function") return;
231
+ const n = {};
232
+ for (const [r, e] of O) n[r] = e.value;
233
+ k.disabled = !0, u(b, "Saving…", "busy");
234
+ try {
235
+ await i.onSave(n), u(b, "Saved", "ok");
236
+ } catch (r) {
237
+ u(b, r?.message || "The change could not be saved.", "error");
238
+ } finally {
239
+ k.disabled = !1;
240
+ }
241
+ }), U(i.fields), R(i.photoUrl), {
242
+ update(n = {}) {
243
+ "fields" in n && U(n.fields), "photoUrl" in n && R(n.photoUrl), "photoStatus" in n && u(d, n.photoStatus?.text, n.photoStatus?.tone), "saveStatus" in n && u(b, n.saveStatus?.text, n.saveStatus?.tone), typeof n.onSave == "function" && (i.onSave = n.onSave), typeof n.onPhoto == "function" && (i.onPhoto = n.onPhoto), typeof n.onPhotoRemove == "function" && (i.onPhotoRemove = n.onPhotoRemove);
244
+ },
245
+ destroy: E
246
+ };
247
+ }
248
+ export {
249
+ $ as DEFAULT_ACCOUNT_TABS,
250
+ q as createAccountView,
251
+ N as mountAccountView
252
+ };
@@ -1,8 +1,10 @@
1
1
  import type {
2
2
  SdnWalletClient,
3
+ SpaceAwarePublishWalletClient,
3
4
  WalletClientErrorMessages,
4
5
  } from './types.js';
5
6
 
6
7
  export declare const WALLET_CLIENT_ERRORS: WalletClientErrorMessages;
7
8
 
8
9
  export declare function createSdnWalletClient(): SdnWalletClient;
10
+ export declare function createSpaceAwarePublishWalletClient(): SpaceAwarePublishWalletClient;