@goodwidget/ai-credits-widget 0.1.5 → 0.1.6

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/index.cjs CHANGED
@@ -32,6 +32,7 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  AiCreditsWidget: () => AiCreditsWidget,
34
34
  CELO_GOODID_ADDRESS: () => CELO_GOODID_ADDRESS,
35
+ DEEP_LINK_MANUAL_FALLBACK_HINT: () => DEEP_LINK_MANUAL_FALLBACK_HINT,
35
36
  DEFAULT_BASE_RPC_URL: () => DEFAULT_BASE_RPC_URL,
36
37
  DEFAULT_CELO_RPC_URL: () => DEFAULT_CELO_RPC_URL,
37
38
  DEFAULT_DISCOUNT_CONFIG: () => DEFAULT_DISCOUNT_CONFIG,
@@ -39,9 +40,18 @@ __export(src_exports, {
39
40
  UnavailableAiCreditsBackendClient: () => UnavailableAiCreditsBackendClient,
40
41
  aiCreditsIntegration: () => aiCreditsIntegration,
41
42
  buildAccountView: () => buildAccountView,
43
+ clearDeepLinkArtifacts: () => clearDeepLinkArtifacts,
44
+ clearStoredDeepLinkParams: () => clearStoredDeepLinkParams,
42
45
  createBackendClient: () => createBackendClient,
43
46
  createChainClient: () => createChainClient,
47
+ deepLinkManualFallbackMessage: () => deepLinkManualFallbackMessage,
44
48
  enrichAccountView: () => enrichAccountView,
49
+ isValidBuyerAddress: () => isValidBuyerAddress,
50
+ isValidOperatorSignature: () => isValidOperatorSignature,
51
+ parseDeepLinkParams: () => parseDeepLinkParams,
52
+ readStoredDeepLinkParams: () => readStoredDeepLinkParams,
53
+ resolveDeepLinkParams: () => resolveDeepLinkParams,
54
+ storeDeepLinkParams: () => storeDeepLinkParams,
45
55
  totalCreditUsdFromProfile: () => totalCreditUsdFromProfile,
46
56
  totalCreditUsdFromStatus: () => totalCreditUsdFromStatus,
47
57
  usdToCredits: () => usdToCredits,
@@ -69,6 +79,119 @@ var aiCreditsIntegration = {
69
79
  events: ["pay-success", "pay-error"]
70
80
  };
71
81
 
82
+ // src/deepLinkParams.ts
83
+ var BUYER_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
84
+ var OPERATOR_SIGNATURE_RE = /^0x[0-9a-fA-F]{128}([0-9a-fA-F]{2})?$/;
85
+ var DEEP_LINK_STORAGE_KEY = "goodwidget.ai-credits.deepLink";
86
+ var DEEP_LINK_MANUAL_FALLBACK_HINT = "Generate or import a signer key manually to continue.";
87
+ function isValidBuyerAddress(value) {
88
+ return BUYER_ADDRESS_RE.test(value.trim());
89
+ }
90
+ function isValidOperatorSignature(value) {
91
+ return OPERATOR_SIGNATURE_RE.test(value.trim());
92
+ }
93
+ function deepLinkManualFallbackMessage(reason) {
94
+ return `${reason} ${DEEP_LINK_MANUAL_FALLBACK_HINT}`;
95
+ }
96
+ function canUseLocalStorage() {
97
+ return typeof window !== "undefined" && typeof window.localStorage !== "undefined";
98
+ }
99
+ function readStoredDeepLinkParams() {
100
+ if (!canUseLocalStorage()) return null;
101
+ try {
102
+ const raw = window.localStorage.getItem(DEEP_LINK_STORAGE_KEY);
103
+ if (!raw) return null;
104
+ const parsed = JSON.parse(raw);
105
+ const buyerAddress = typeof parsed.buyerAddress === "string" ? parsed.buyerAddress.trim() : "";
106
+ const operatorSignature = typeof parsed.operatorSignature === "string" ? parsed.operatorSignature.trim() : "";
107
+ if (!isValidBuyerAddress(buyerAddress) || !isValidOperatorSignature(operatorSignature)) {
108
+ clearStoredDeepLinkParams();
109
+ return null;
110
+ }
111
+ return { buyerAddress, operatorSignature };
112
+ } catch {
113
+ clearStoredDeepLinkParams();
114
+ return null;
115
+ }
116
+ }
117
+ function storeDeepLinkParams(value) {
118
+ if (!canUseLocalStorage()) return;
119
+ try {
120
+ window.localStorage.setItem(
121
+ DEEP_LINK_STORAGE_KEY,
122
+ JSON.stringify({
123
+ buyerAddress: value.buyerAddress.trim(),
124
+ operatorSignature: value.operatorSignature.trim()
125
+ })
126
+ );
127
+ } catch {
128
+ return;
129
+ }
130
+ }
131
+ function clearStoredDeepLinkParams() {
132
+ if (!canUseLocalStorage()) return;
133
+ try {
134
+ window.localStorage.removeItem(DEEP_LINK_STORAGE_KEY);
135
+ } catch {
136
+ return;
137
+ }
138
+ }
139
+ function parseDeepLinkParams(search = typeof window !== "undefined" ? window.location.search : "") {
140
+ const params = typeof search === "string" ? new URLSearchParams(search) : search;
141
+ const buyerAddress = params.get("buyerAddress")?.trim() ?? "";
142
+ const operatorSignature = params.get("operatorSignature")?.trim() ?? "";
143
+ const hasBuyer = buyerAddress.length > 0;
144
+ const hasSignature = operatorSignature.length > 0;
145
+ if (!hasBuyer && !hasSignature) return { status: "absent" };
146
+ if (hasBuyer && !hasSignature) return { status: "partial", present: "buyerAddress" };
147
+ if (!hasBuyer && hasSignature) return { status: "partial", present: "operatorSignature" };
148
+ if (!isValidBuyerAddress(buyerAddress)) {
149
+ return { status: "invalid", reason: "Deep-link buyerAddress is invalid" };
150
+ }
151
+ if (!isValidOperatorSignature(operatorSignature)) {
152
+ return {
153
+ status: "invalid",
154
+ reason: "Deep-link operatorSignature is invalid"
155
+ };
156
+ }
157
+ return {
158
+ status: "complete",
159
+ source: "url",
160
+ value: {
161
+ buyerAddress,
162
+ operatorSignature
163
+ }
164
+ };
165
+ }
166
+ function resolveDeepLinkParams(search = typeof window !== "undefined" ? window.location.search : "") {
167
+ const fromUrl = parseDeepLinkParams(search);
168
+ if (fromUrl.status === "complete") {
169
+ storeDeepLinkParams(fromUrl.value);
170
+ return fromUrl;
171
+ }
172
+ if (fromUrl.status === "partial" || fromUrl.status === "invalid") {
173
+ return fromUrl;
174
+ }
175
+ const stored = readStoredDeepLinkParams();
176
+ if (!stored) return { status: "absent" };
177
+ return { status: "complete", source: "storage", value: stored };
178
+ }
179
+ function stripDeepLinkParamsFromUrl() {
180
+ if (typeof window === "undefined") return;
181
+ const url = new URL(window.location.href);
182
+ if (!url.searchParams.has("buyerAddress") && !url.searchParams.has("operatorSignature")) {
183
+ return;
184
+ }
185
+ url.searchParams.delete("buyerAddress");
186
+ url.searchParams.delete("operatorSignature");
187
+ const next = `${url.pathname}${url.search}${url.hash}`;
188
+ window.history.replaceState(window.history.state, "", next);
189
+ }
190
+ function clearDeepLinkArtifacts() {
191
+ clearStoredDeepLinkParams();
192
+ stripDeepLinkParamsFromUrl();
193
+ }
194
+
72
195
  // src/quoteMath.ts
73
196
  var import_viem = require("viem");
74
197
  var CREDITS_PER_USD = 1e4;
@@ -236,13 +359,17 @@ function clampHistoryLimit(limit) {
236
359
  if (limit === void 0) return DEFAULT_HISTORY_LIMIT;
237
360
  return Math.min(Math.max(1, Math.floor(limit)), MAX_HISTORY_LIMIT);
238
361
  }
239
- function resolveBuyerAddress(entries) {
362
+ function collectBuyerAddressesFromEntries(entries) {
363
+ const seen = /* @__PURE__ */ new Set();
364
+ const result = [];
240
365
  for (const entry of entries) {
241
- if (entry.buyerAddress && (0, import_viem2.isAddress)(entry.buyerAddress)) {
242
- return normalizeAddress(entry.buyerAddress);
243
- }
366
+ if (!entry.buyerAddress || !(0, import_viem2.isAddress)(entry.buyerAddress)) continue;
367
+ const key = normalizeAddress(entry.buyerAddress);
368
+ if (seen.has(key)) continue;
369
+ seen.add(key);
370
+ result.push(key);
244
371
  }
245
- return null;
372
+ return result;
246
373
  }
247
374
  function defaultOperatorStatus(payer) {
248
375
  const account = normalizeAddress(payer);
@@ -480,13 +607,11 @@ async function waitForOperatorConsent(chain, ref) {
480
607
  }
481
608
  async function buildAccountView(payer, backend, chain, options = {}) {
482
609
  const normalizedPayer = normalizeAddress(payer);
483
- const [credit, outstanding, history] = await Promise.all([
610
+ const [credit, outstanding] = await Promise.all([
484
611
  backend.getAccountCredit(payer),
485
- backend.getOutstanding(payer),
486
- backend.getCreditHistory(payer, { limit: MAX_HISTORY_LIMIT, offset: 0 })
612
+ backend.getOutstanding(payer)
487
613
  ]);
488
- const sessionBuyer = options.buyerAddress && (0, import_viem2.isAddress)(options.buyerAddress) ? normalizeAddress(options.buyerAddress) : null;
489
- const buyer = sessionBuyer ?? resolveBuyerAddress(history.items);
614
+ const buyer = options.buyerAddress && (0, import_viem2.isAddress)(options.buyerAddress) ? normalizeAddress(options.buyerAddress) : null;
490
615
  const [operator, withdrawableUsd] = buyer ? await Promise.all([
491
616
  chain.getBuyerOperatorStatus({ payer: normalizedPayer, buyer }),
492
617
  chain.getWithdrawableUsd(buyer)
@@ -831,40 +956,262 @@ async function signRequestClose(params) {
831
956
  }
832
957
 
833
958
  // src/payerSession.ts
834
- var payerWalletSessions = /* @__PURE__ */ new Map();
959
+ var STORAGE_KEY_PREFIX = "goodwidget.ai-credits.payerSession.";
835
960
  function payerSessionKey(address) {
836
961
  return address.toLowerCase();
837
962
  }
963
+ function normalizeBuyerAddress(address) {
964
+ return address.toLowerCase();
965
+ }
966
+ function canUseLocalStorage2() {
967
+ return typeof window !== "undefined" && typeof window.localStorage !== "undefined";
968
+ }
969
+ function formatBuyerAddress(address) {
970
+ const key = normalizeBuyerAddress(address);
971
+ return key.startsWith("0x") ? `0x${key.slice(2)}` : key;
972
+ }
973
+ function emptySession() {
974
+ return {
975
+ buyerKeys: {},
976
+ knownBuyers: [],
977
+ activeBuyerAddress: null,
978
+ derivedBuyerAddress: null
979
+ };
980
+ }
981
+ function isBuyerKeyEntry(value) {
982
+ if (!value || typeof value !== "object") return false;
983
+ const entry = value;
984
+ return (entry.privateKey === void 0 || typeof entry.privateKey === "string") && (entry.operatorSignature === void 0 || typeof entry.operatorSignature === "string") && (entry.operatorConsented === void 0 || typeof entry.operatorConsented === "boolean");
985
+ }
986
+ function migrateLegacySession(raw) {
987
+ const session = emptySession();
988
+ const known = /* @__PURE__ */ new Set();
989
+ const trackKnown = (address) => {
990
+ if (!address) return;
991
+ known.add(normalizeBuyerAddress(address));
992
+ };
993
+ if (typeof raw.buyerPubKey === "string" && raw.buyerPubKey) {
994
+ const address = normalizeBuyerAddress(raw.buyerPubKey);
995
+ session.activeBuyerAddress = address;
996
+ session.derivedBuyerAddress = address;
997
+ trackKnown(address);
998
+ if (typeof raw.buyerPrvKey === "string" && raw.buyerPrvKey) {
999
+ session.buyerKeys[address] = { privateKey: raw.buyerPrvKey };
1000
+ }
1001
+ }
1002
+ if (Array.isArray(raw.buyers)) {
1003
+ for (const item of raw.buyers) {
1004
+ if (typeof item === "string" && item) {
1005
+ trackKnown(item);
1006
+ continue;
1007
+ }
1008
+ if (!item || typeof item !== "object") continue;
1009
+ const buyer = item;
1010
+ if (typeof buyer.address !== "string" || !buyer.address) continue;
1011
+ const address = normalizeBuyerAddress(buyer.address);
1012
+ trackKnown(address);
1013
+ const entry = {};
1014
+ if (typeof buyer.privateKey === "string" && buyer.privateKey) {
1015
+ entry.privateKey = buyer.privateKey;
1016
+ }
1017
+ if (typeof buyer.operatorSignature === "string" && buyer.operatorSignature) {
1018
+ entry.operatorSignature = buyer.operatorSignature;
1019
+ }
1020
+ if (typeof buyer.operatorConsented === "boolean") {
1021
+ entry.operatorConsented = buyer.operatorConsented;
1022
+ }
1023
+ if (entry.privateKey || entry.operatorSignature || entry.operatorConsented !== void 0) {
1024
+ session.buyerKeys[address] = {
1025
+ ...session.buyerKeys[address],
1026
+ ...entry
1027
+ };
1028
+ }
1029
+ if (buyer.type === "derived" && entry.privateKey) {
1030
+ session.derivedBuyerAddress = address;
1031
+ }
1032
+ }
1033
+ }
1034
+ if (Array.isArray(raw.knownBuyers)) {
1035
+ for (const item of raw.knownBuyers) {
1036
+ if (typeof item === "string" && item) trackKnown(item);
1037
+ }
1038
+ }
1039
+ if (typeof raw.activeBuyerAddress === "string" && raw.activeBuyerAddress) {
1040
+ session.activeBuyerAddress = normalizeBuyerAddress(raw.activeBuyerAddress);
1041
+ trackKnown(session.activeBuyerAddress);
1042
+ }
1043
+ if (typeof raw.derivedBuyerAddress === "string" && raw.derivedBuyerAddress) {
1044
+ session.derivedBuyerAddress = normalizeBuyerAddress(raw.derivedBuyerAddress);
1045
+ trackKnown(session.derivedBuyerAddress);
1046
+ }
1047
+ if (typeof raw.operatorSignature === "string" && raw.operatorSignature && session.activeBuyerAddress) {
1048
+ const active = session.activeBuyerAddress;
1049
+ session.buyerKeys[active] = {
1050
+ ...session.buyerKeys[active],
1051
+ operatorSignature: raw.operatorSignature
1052
+ };
1053
+ }
1054
+ if (raw.buyerKeys && typeof raw.buyerKeys === "object") {
1055
+ for (const [address, entry] of Object.entries(raw.buyerKeys)) {
1056
+ if (!isBuyerKeyEntry(entry)) continue;
1057
+ const key = normalizeBuyerAddress(address);
1058
+ trackKnown(key);
1059
+ session.buyerKeys[key] = {
1060
+ ...session.buyerKeys[key],
1061
+ ...entry
1062
+ };
1063
+ }
1064
+ }
1065
+ if (typeof raw.operatorConsented === "boolean" && raw.operatorConsented && session.activeBuyerAddress) {
1066
+ const active = session.activeBuyerAddress;
1067
+ session.buyerKeys[active] = {
1068
+ ...session.buyerKeys[active],
1069
+ operatorConsented: true
1070
+ };
1071
+ }
1072
+ session.knownBuyers = [...known].map((key) => formatBuyerAddress(key));
1073
+ return session;
1074
+ }
1075
+ function parseStoredSession(raw) {
1076
+ try {
1077
+ const parsed = JSON.parse(raw);
1078
+ return migrateLegacySession(parsed);
1079
+ } catch {
1080
+ return null;
1081
+ }
1082
+ }
1083
+ function persistSession(address, session) {
1084
+ if (!canUseLocalStorage2()) return;
1085
+ try {
1086
+ window.localStorage.setItem(
1087
+ `${STORAGE_KEY_PREFIX}${payerSessionKey(address)}`,
1088
+ JSON.stringify(session)
1089
+ );
1090
+ } catch {
1091
+ return;
1092
+ }
1093
+ }
838
1094
  function readPayerSession(address) {
839
- if (!address) return null;
840
- return payerWalletSessions.get(payerSessionKey(address)) ?? null;
1095
+ if (!address || !canUseLocalStorage2()) return null;
1096
+ try {
1097
+ const raw = window.localStorage.getItem(
1098
+ `${STORAGE_KEY_PREFIX}${payerSessionKey(address)}`
1099
+ );
1100
+ if (!raw) return null;
1101
+ return parseStoredSession(raw);
1102
+ } catch {
1103
+ return null;
1104
+ }
1105
+ }
1106
+ function getBuyerKeyEntry(payer, buyerAddress) {
1107
+ const session = readPayerSession(payer);
1108
+ if (!session) return null;
1109
+ return session.buyerKeys[normalizeBuyerAddress(buyerAddress)] ?? null;
841
1110
  }
842
- function patchPayerSession(address, patch) {
843
- const existing = readPayerSession(address);
844
- payerWalletSessions.set(payerSessionKey(address), {
845
- operatorConsented: false,
1111
+ function setBuyerOperatorConsented(payer, buyerAddress, operatorConsented) {
1112
+ upsertBuyerKey(payer, buyerAddress, { operatorConsented }, { setActive: false });
1113
+ }
1114
+ function upsertBuyerKey(payer, buyerAddress, entry, options) {
1115
+ const existing = readPayerSession(payer) ?? emptySession();
1116
+ const key = normalizeBuyerAddress(buyerAddress);
1117
+ const previous = existing.buyerKeys[key] ?? {};
1118
+ const knownBuyers = mergeBuyerAddressList(existing.knownBuyers, key);
1119
+ const next = {
846
1120
  ...existing,
847
- ...patch
848
- });
1121
+ knownBuyers,
1122
+ buyerKeys: {
1123
+ ...existing.buyerKeys,
1124
+ [key]: {
1125
+ privateKey: entry.privateKey ?? previous.privateKey,
1126
+ operatorSignature: entry.operatorSignature ?? previous.operatorSignature,
1127
+ operatorConsented: entry.operatorConsented !== void 0 ? entry.operatorConsented : previous.operatorConsented
1128
+ }
1129
+ },
1130
+ activeBuyerAddress: options?.setActive === false ? existing.activeBuyerAddress : key,
1131
+ derivedBuyerAddress: options?.setDerived ? key : existing.derivedBuyerAddress
1132
+ };
1133
+ persistSession(payer, next);
1134
+ return next;
1135
+ }
1136
+ function setActiveBuyerAddress(payer, buyerAddress) {
1137
+ const existing = readPayerSession(payer) ?? emptySession();
1138
+ const normalized = buyerAddress ? normalizeBuyerAddress(buyerAddress) : null;
1139
+ const next = {
1140
+ ...existing,
1141
+ knownBuyers: normalized ? mergeBuyerAddressList(existing.knownBuyers, normalized) : existing.knownBuyers,
1142
+ activeBuyerAddress: normalized
1143
+ };
1144
+ persistSession(payer, next);
1145
+ return next;
1146
+ }
1147
+ function mergeBuyerAddressList(existingBuyers, ...extras) {
1148
+ const seen = /* @__PURE__ */ new Set();
1149
+ const result = [];
1150
+ for (const address of [...existingBuyers, ...extras]) {
1151
+ if (!address) continue;
1152
+ const key = normalizeBuyerAddress(address);
1153
+ if (seen.has(key)) continue;
1154
+ seen.add(key);
1155
+ result.push(formatBuyerAddress(key));
1156
+ }
1157
+ return result;
1158
+ }
1159
+ function listKnownBuyerAddresses(payer) {
1160
+ const session = readPayerSession(payer);
1161
+ if (!session) return [];
1162
+ return mergeBuyerAddressList(
1163
+ session.knownBuyers,
1164
+ ...Object.keys(session.buyerKeys),
1165
+ session.activeBuyerAddress,
1166
+ session.derivedBuyerAddress
1167
+ );
1168
+ }
1169
+ function rememberBuyerAddresses(payer, addresses) {
1170
+ const existing = readPayerSession(payer) ?? emptySession();
1171
+ const knownBuyers = mergeBuyerAddressList(existing.knownBuyers, ...addresses);
1172
+ if (knownBuyers.length === existing.knownBuyers.length && knownBuyers.every(
1173
+ (address, index) => address.toLowerCase() === existing.knownBuyers[index]?.toLowerCase()
1174
+ )) {
1175
+ return listKnownBuyerAddresses(payer);
1176
+ }
1177
+ persistSession(payer, { ...existing, knownBuyers });
1178
+ return listKnownBuyerAddresses(payer);
1179
+ }
1180
+ function buildBuyerStateFields(payer, buyers, selectedAddress) {
1181
+ const session = readPayerSession(payer);
1182
+ const entry = selectedAddress ? getBuyerKeyEntry(payer, selectedAddress) : null;
1183
+ return {
1184
+ buyers,
1185
+ buyerPubKey: selectedAddress,
1186
+ buyerPrvKey: entry?.privateKey ?? null,
1187
+ operatorSignature: entry?.operatorSignature ?? null,
1188
+ operatorConsented: Boolean(entry?.operatorConsented),
1189
+ derivedBuyerAddress: session?.derivedBuyerAddress ?? null
1190
+ };
849
1191
  }
850
1192
  function patchPayerSessionFields(address) {
851
1193
  const session = readPayerSession(address);
852
1194
  if (!session) {
853
1195
  return {
1196
+ buyerPubKey: null,
854
1197
  buyerPrvKey: null,
855
- operatorConsented: false
1198
+ operatorSignature: null,
1199
+ operatorConsented: false,
1200
+ activeBuyerAddress: null,
1201
+ derivedBuyerAddress: null
856
1202
  };
857
1203
  }
1204
+ const active = session.activeBuyerAddress;
1205
+ const entry = active ? session.buyerKeys[normalizeBuyerAddress(active)] : void 0;
858
1206
  return {
859
- buyerPubKey: session.buyerPubKey,
860
- buyerPrvKey: session.buyerPrvKey ?? null,
861
- operatorConsented: session.operatorConsented
1207
+ buyerPubKey: active,
1208
+ buyerPrvKey: entry?.privateKey ?? null,
1209
+ operatorSignature: entry?.operatorSignature ?? null,
1210
+ operatorConsented: Boolean(entry?.operatorConsented),
1211
+ activeBuyerAddress: active,
1212
+ derivedBuyerAddress: session.derivedBuyerAddress
862
1213
  };
863
1214
  }
864
- function addressesMatch(a, b) {
865
- if (!a || !b) return false;
866
- return payerSessionKey(a) === payerSessionKey(b);
867
- }
868
1215
 
869
1216
  // src/celoPayment.ts
870
1217
  var import_viem5 = require("viem");
@@ -1144,7 +1491,7 @@ function getPayDisabledMessage(params) {
1144
1491
  if (params.validation.streamBelowMin && params.minStreamUsd) {
1145
1492
  return `Monthly stream must be at least ${formatMinUsdDisplay(params.minStreamUsd)}.`;
1146
1493
  }
1147
- if (params.status !== "quote_ready") {
1494
+ if (params.status !== "quote_ready" && params.status !== "payment_failed") {
1148
1495
  return "Enter a deposit or change the monthly stream amount to continue.";
1149
1496
  }
1150
1497
  return "Adjust the amounts to continue.";
@@ -1280,8 +1627,11 @@ var INITIAL_STATE = {
1280
1627
  isGoodIdVerified: false,
1281
1628
  buyerPubKey: null,
1282
1629
  buyerPrvKey: null,
1630
+ operatorSignature: null,
1283
1631
  operatorConsented: false,
1632
+ operatorConsentPending: false,
1284
1633
  operatorAddress: null,
1634
+ currentOperator: null,
1285
1635
  minDepositUsd: null,
1286
1636
  minStreamUsd: null,
1287
1637
  totalGdDepositedG: null,
@@ -1290,7 +1640,9 @@ var INITIAL_STATE = {
1290
1640
  depositBonusPercent: DEFAULT_DISCOUNT_CONFIG.depositBonusPercent,
1291
1641
  streamBonusPercent: DEFAULT_DISCOUNT_CONFIG.streamBonusPercent,
1292
1642
  error: null,
1293
- activeTab: "buy"
1643
+ activeTab: "setup",
1644
+ buyers: [],
1645
+ derivedBuyerAddress: null
1294
1646
  };
1295
1647
  var WALLET_LOADING_STATE = {
1296
1648
  gBalance: null,
@@ -1302,17 +1654,59 @@ var WALLET_LOADING_STATE = {
1302
1654
  totalGdDepositedG: null,
1303
1655
  monthlyStreamG: null,
1304
1656
  withdrawableUsd: null,
1305
- operatorAddress: null
1657
+ operatorAddress: null,
1658
+ currentOperator: null
1306
1659
  };
1660
+ var BUYER_HISTORY_LOOKUP_LIMIT = 100;
1661
+ function resolveLocalBuyers(payer, preferredBuyer, ...extras) {
1662
+ const buyers = rememberBuyerAddresses(payer, [
1663
+ preferredBuyer,
1664
+ ...listKnownBuyerAddresses(payer),
1665
+ ...extras
1666
+ ]);
1667
+ return { buyers, selected: selectPreferredBuyer(buyers, preferredBuyer) };
1668
+ }
1669
+ async function discoverBuyersFromHistory(payer, backend, ...extras) {
1670
+ let historyBuyers = [];
1671
+ try {
1672
+ const history = await backend.getCreditHistory(payer, {
1673
+ limit: BUYER_HISTORY_LOOKUP_LIMIT,
1674
+ offset: 0
1675
+ });
1676
+ historyBuyers = collectBuyerAddressesFromEntries(history.items);
1677
+ } catch {
1678
+ historyBuyers = [];
1679
+ }
1680
+ return rememberBuyerAddresses(payer, [...historyBuyers, ...extras]);
1681
+ }
1682
+ function selectPreferredBuyer(buyers, preferredBuyer) {
1683
+ if (preferredBuyer && buyers.some((item) => item.toLowerCase() === preferredBuyer.toLowerCase())) {
1684
+ return preferredBuyer;
1685
+ }
1686
+ return buyers[0] ?? preferredBuyer ?? null;
1687
+ }
1307
1688
  function isNonBuyTab(tab) {
1308
- return tab === "manage" || tab === "history";
1689
+ return tab === "setup" || tab === "manage" || tab === "history";
1690
+ }
1691
+ function needsWalletConnection(state) {
1692
+ return !state.address || state.status === "disconnected" || state.status === "connecting";
1693
+ }
1694
+ function resolveDefaultActiveTab(payerAddress, totalCreditUsd) {
1695
+ if (hasCreditBalance(totalCreditUsd)) return "manage";
1696
+ if (payerAddress && listKnownBuyerAddresses(payerAddress).length > 0) return "buy";
1697
+ return "setup";
1309
1698
  }
1310
1699
  function resolveActiveTab(prev, overrides) {
1311
1700
  if (overrides.activeTab !== void 0) return overrides.activeTab;
1701
+ const payerAddress = overrides.address !== void 0 ? overrides.address : prev.address;
1702
+ const totalCreditUsd = overrides.totalCreditUsd !== void 0 ? overrides.totalCreditUsd : prev.totalCreditUsd;
1312
1703
  if (overrides.totalCreditUsd !== void 0 && overrides.totalCreditUsd !== null) {
1313
- return hasCreditBalance(overrides.totalCreditUsd) ? "manage" : "buy";
1704
+ return resolveDefaultActiveTab(payerAddress, overrides.totalCreditUsd);
1314
1705
  }
1315
- return prev.activeTab ?? "buy";
1706
+ if (overrides.address !== void 0 && overrides.address !== prev.address) {
1707
+ return resolveDefaultActiveTab(payerAddress, totalCreditUsd);
1708
+ }
1709
+ return prev.activeTab ?? resolveDefaultActiveTab(payerAddress, totalCreditUsd);
1316
1710
  }
1317
1711
  function hasCreditBalance(totalCreditUsd) {
1318
1712
  return totalCreditUsd !== null && BigInt(totalCreditUsd) > 0n;
@@ -1370,7 +1764,7 @@ function mergeStatePreservingNonBuyTab(prev, overrides) {
1370
1764
  }
1371
1765
  const activeTab = isNonBuyTab(nextTab) ? nextTab : prev.activeTab;
1372
1766
  const status = deriveStatus({
1373
- isConnected: true,
1767
+ isConnected: !needsWalletConnection(prev),
1374
1768
  chainId: overrides.chainId ?? prev.chainId,
1375
1769
  gBalance: overrides.gBalance ?? prev.gBalance,
1376
1770
  buyerPubKey: overrides.buyerPubKey ?? prev.buyerPubKey,
@@ -1394,31 +1788,15 @@ function viewToStatePatch(view, enriched, prev, options) {
1394
1788
  isGoodIdVerified: enriched.goodIdVerified,
1395
1789
  operatorConsented: operatorAccepted,
1396
1790
  operatorAddress: view.operator.operatorAddress ?? null,
1791
+ currentOperator: view.operator.currentOperator ?? null,
1397
1792
  withdrawableUsd: view.withdrawableUsd,
1398
1793
  totalGdDepositedG: enriched.totalGdDepositedG,
1399
- monthlyStreamG: enriched.monthlyStreamG,
1400
- ...view.buyer ? { buyerPubKey: view.buyer } : {}
1401
- };
1402
- }
1403
- function mergeSessionFields(prev, sessionPatch, accountPatch, accountSwitched) {
1404
- const buyerPubKey = sessionPatch.buyerPubKey ?? accountPatch.buyerPubKey ?? (accountSwitched ? null : prev.buyerPubKey);
1405
- const buyerPrvKey = sessionPatch.buyerPrvKey ?? (accountSwitched ? null : prev.buyerPrvKey);
1406
- const operatorConsented = accountSwitched ? sessionPatch.operatorConsented ?? accountPatch.operatorConsented ?? false : accountPatch.operatorConsented ?? sessionPatch.operatorConsented ?? prev.operatorConsented;
1407
- return {
1408
- buyerPubKey,
1409
- buyerPrvKey,
1410
- operatorConsented
1794
+ monthlyStreamG: enriched.monthlyStreamG
1411
1795
  };
1412
1796
  }
1413
- function syncOperatorConsentSession(address, operatorConsented) {
1414
- if (operatorConsented === void 0) return;
1415
- patchPayerSession(address, { operatorConsented });
1416
- }
1417
- function syncBuyerPubKeySession(address, buyerPubKey) {
1418
- if (!buyerPubKey) return;
1419
- const existing = readPayerSession(address);
1420
- if (existing?.buyerPubKey) return;
1421
- patchPayerSession(address, { buyerPubKey });
1797
+ function activateBuyerSelection(payer, buyers, selectedAddress) {
1798
+ setActiveBuyerAddress(payer, selectedAddress);
1799
+ return buildBuyerStateFields(payer, buyers, selectedAddress);
1422
1800
  }
1423
1801
  function useAiCreditsAdapter({
1424
1802
  environment = "production",
@@ -1442,6 +1820,9 @@ function useAiCreditsAdapter({
1442
1820
  const providerRef = (0, import_react.useRef)(null);
1443
1821
  providerRef.current = provider;
1444
1822
  const goodIdVerifyPendingRef = (0, import_react.useRef)(false);
1823
+ const pendingDeepLinkRef = (0, import_react.useRef)(null);
1824
+ const deepLinkParseDoneRef = (0, import_react.useRef)(false);
1825
+ const deepLinkApplyInFlightRef = (0, import_react.useRef)(false);
1445
1826
  const celoVault = vaultAddress ?? CELO_GD_ANTSEED_VAULT_FALLBACK;
1446
1827
  const backendClient = (0, import_react.useMemo)(
1447
1828
  () => backendClientOverride ?? createBackendClient(backendUrl),
@@ -1459,7 +1840,11 @@ function useAiCreditsAdapter({
1459
1840
  );
1460
1841
  (0, import_react.useEffect)(() => {
1461
1842
  if (!isConnected || !address) {
1462
- setState((prev) => prev.status === "connecting" ? prev : { ...INITIAL_STATE });
1843
+ setState((prev) => {
1844
+ if (prev.status === "connecting") return prev;
1845
+ if (!prev.address && prev.status === "disconnected" && prev.error === null) return prev;
1846
+ return { ...INITIAL_STATE };
1847
+ });
1463
1848
  return;
1464
1849
  }
1465
1850
  if (configurationError) {
@@ -1478,14 +1863,17 @@ function useAiCreditsAdapter({
1478
1863
  if (prev.status === "payment_pending" || prev.status === "payment_confirmed" || prev.status === "payment_failed") {
1479
1864
  return prev;
1480
1865
  }
1481
- const accountSwitched = !addressesMatch(prev.address, address);
1482
- const buyerFields = mergeSessionFields(prev, sessionPatch, {}, accountSwitched);
1483
1866
  return withDerivedStatus(
1484
1867
  prev,
1485
1868
  {
1486
1869
  address,
1487
1870
  chainId,
1488
- ...buyerFields,
1871
+ buyerPubKey: sessionPatch.buyerPubKey,
1872
+ buyerPrvKey: sessionPatch.buyerPrvKey,
1873
+ operatorSignature: sessionPatch.operatorSignature,
1874
+ operatorConsented: sessionPatch.operatorConsented,
1875
+ derivedBuyerAddress: sessionPatch.derivedBuyerAddress,
1876
+ buyers: prev.buyers,
1489
1877
  ...WALLET_LOADING_STATE,
1490
1878
  error: null,
1491
1879
  status: "connecting"
@@ -1508,8 +1896,11 @@ function useAiCreditsAdapter({
1508
1896
  functionName: "decimals"
1509
1897
  })
1510
1898
  ]);
1511
- const accountPromise = buildAccountView(address, backendClient, chainClient, {
1512
- buyerAddress: sessionPatch.buyerPubKey ?? null
1899
+ const pendingDeepLink = pendingDeepLinkRef.current;
1900
+ const sessionBuyer = patchPayerSessionFields(address).buyerPubKey;
1901
+ const preferredBuyer = pendingDeepLink?.buyerAddress ?? sessionBuyer ?? null;
1902
+ const accountPromise = pendingDeepLink || deepLinkApplyInFlightRef.current ? Promise.resolve(null) : buildAccountView(address, backendClient, chainClient, {
1903
+ buyerAddress: preferredBuyer
1513
1904
  }).then(async (view) => ({
1514
1905
  view,
1515
1906
  enriched: await enrichAccountView(view, chainClient)
@@ -1520,13 +1911,25 @@ function useAiCreditsAdapter({
1520
1911
  }) : fetchVaultPaymentMinimums(publicClient, celoVault, address).catch(() => null);
1521
1912
  const gdUsdPerTokenPromise = chainClient.fetchGdUsdPerToken().catch(() => null);
1522
1913
  const discountConfigPromise = backendClient.getDiscountConfig().catch(() => null);
1914
+ const buyersPromise = pendingDeepLink ? Promise.resolve(
1915
+ rememberBuyerAddresses(address, [
1916
+ preferredBuyer,
1917
+ ...listKnownBuyerAddresses(address)
1918
+ ])
1919
+ ) : discoverBuyersFromHistory(
1920
+ address,
1921
+ backendClient,
1922
+ preferredBuyer,
1923
+ ...listKnownBuyerAddresses(address)
1924
+ );
1523
1925
  try {
1524
- const [[rawBalance, decimals], account, minimums, gdUsdPerToken, discountConfig] = await Promise.all([
1926
+ const [[rawBalance, decimals], account, minimums, gdUsdPerToken, discountConfig, buyers] = await Promise.all([
1525
1927
  balancePromise,
1526
1928
  accountPromise,
1527
1929
  minimumsPromise,
1528
1930
  gdUsdPerTokenPromise,
1529
- discountConfigPromise
1931
+ discountConfigPromise,
1932
+ buyersPromise
1530
1933
  ]);
1531
1934
  if (cancelled) return;
1532
1935
  const patch = {
@@ -1539,41 +1942,54 @@ function useAiCreditsAdapter({
1539
1942
  depositBonusPercent: discountConfig?.depositBonusPercent ?? DEFAULT_DISCOUNT_CONFIG.depositBonusPercent,
1540
1943
  streamBonusPercent: discountConfig?.streamBonusPercent ?? DEFAULT_DISCOUNT_CONFIG.streamBonusPercent
1541
1944
  };
1542
- setState((prev) => {
1543
- const accountSwitched = !addressesMatch(prev.address, address);
1544
- const accountPatch = account ? viewToStatePatch(account.view, account.enriched, prev, {
1545
- balanceMode: "always"
1546
- }) : {};
1547
- const buyerFields = mergeSessionFields(prev, sessionPatch, accountPatch, accountSwitched);
1548
- if (address && accountPatch.operatorConsented !== void 0) {
1549
- syncOperatorConsentSession(address, accountPatch.operatorConsented);
1550
- }
1551
- if (address && account?.view.buyer) {
1552
- syncBuyerPubKeySession(address, account.view.buyer);
1553
- }
1554
- return withDerivedStatus(
1945
+ if (pendingDeepLink || deepLinkApplyInFlightRef.current) {
1946
+ setState(
1947
+ (prev) => withDerivedStatus(
1948
+ prev,
1949
+ {
1950
+ ...patch,
1951
+ buyers: mergeBuyerAddressList(prev.buyers, ...buyers)
1952
+ },
1953
+ true
1954
+ )
1955
+ );
1956
+ return;
1957
+ }
1958
+ const selectedBuyer = selectPreferredBuyer(buyers, preferredBuyer);
1959
+ const accountPatch = account ? viewToStatePatch(account.view, account.enriched, INITIAL_STATE, {
1960
+ balanceMode: "always"
1961
+ }) : {};
1962
+ if (selectedBuyer && accountPatch.operatorConsented !== void 0) {
1963
+ setBuyerOperatorConsented(address, selectedBuyer, accountPatch.operatorConsented);
1964
+ }
1965
+ const buyerFields = activateBuyerSelection(address, buyers, selectedBuyer);
1966
+ setState(
1967
+ (prev) => withDerivedStatus(
1555
1968
  prev,
1556
1969
  {
1557
1970
  ...patch,
1558
1971
  ...accountPatch,
1559
1972
  ...buyerFields,
1560
- ...account ? {} : { activeTab: "buy" }
1973
+ operatorConsented: accountPatch.operatorConsented ?? buyerFields.operatorConsented
1561
1974
  },
1562
1975
  true
1563
- );
1564
- });
1976
+ )
1977
+ );
1565
1978
  } catch {
1566
1979
  if (cancelled) return;
1567
1980
  setState((prev) => {
1568
- const accountSwitched = !addressesMatch(prev.address, address);
1569
- const buyerFields = mergeSessionFields(prev, sessionPatch, {}, accountSwitched);
1570
1981
  return withDerivedStatus(
1571
1982
  prev,
1572
1983
  {
1573
1984
  address,
1574
1985
  chainId,
1575
1986
  gBalance: "0",
1576
- ...buyerFields,
1987
+ buyers: [],
1988
+ derivedBuyerAddress: null,
1989
+ buyerPubKey: null,
1990
+ buyerPrvKey: null,
1991
+ operatorSignature: null,
1992
+ operatorConsented: false,
1577
1993
  status: chainId !== null && chainId !== CELO_CHAIN_ID2 ? "unsupported_chain" : "purchase_setup"
1578
1994
  },
1579
1995
  true
@@ -1612,14 +2028,32 @@ function useAiCreditsAdapter({
1612
2028
  setState(
1613
2029
  (prev) => withDerivedStatus(
1614
2030
  prev,
1615
- { error: "Connect your wallet before generating a buyer key" },
2031
+ { error: "Connect your wallet before generating a signer key" },
1616
2032
  true
1617
2033
  )
1618
2034
  );
1619
2035
  return;
1620
2036
  }
2037
+ const payerAddress = address;
2038
+ const session = readPayerSession(payerAddress);
2039
+ const derivedAddress = session?.derivedBuyerAddress ?? null;
2040
+ const existingKey = derivedAddress ? getBuyerKeyEntry(payerAddress, derivedAddress) : null;
2041
+ if (derivedAddress && existingKey?.privateKey) {
2042
+ const buyers = mergeBuyerAddressList(
2043
+ listKnownBuyerAddresses(payerAddress),
2044
+ derivedAddress
2045
+ );
2046
+ const buyerFields = activateBuyerSelection(payerAddress, buyers, derivedAddress);
2047
+ setState(
2048
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2049
+ ...buyerFields,
2050
+ error: null,
2051
+ ...!isNonBuyTab(prev.activeTab) ? { status: "purchase_setup" } : {}
2052
+ })
2053
+ );
2054
+ return;
2055
+ }
1621
2056
  try {
1622
- const payerAddress = address;
1623
2057
  const message = buildBuyerKeyMessage(payerAddress);
1624
2058
  const walletClient = (0, import_viem8.createWalletClient)({
1625
2059
  account: payerAddress,
@@ -1631,15 +2065,21 @@ function useAiCreditsAdapter({
1631
2065
  message
1632
2066
  });
1633
2067
  const privateKey = deriveBuyerPrivateKeyFromSignature(signature);
1634
- const account = (0, import_accounts4.privateKeyToAccount)(privateKey);
1635
- patchPayerSession(payerAddress, {
1636
- buyerPubKey: account.address,
1637
- buyerPrvKey: privateKey
1638
- });
2068
+ const buyerAccount = (0, import_accounts4.privateKeyToAccount)(privateKey);
2069
+ upsertBuyerKey(
2070
+ payerAddress,
2071
+ buyerAccount.address,
2072
+ { privateKey },
2073
+ { setActive: true, setDerived: true }
2074
+ );
2075
+ const buyers = mergeBuyerAddressList(
2076
+ listKnownBuyerAddresses(payerAddress),
2077
+ buyerAccount.address
2078
+ );
2079
+ const buyerFields = buildBuyerStateFields(payerAddress, buyers, buyerAccount.address);
1639
2080
  setState(
1640
2081
  (prev) => mergeStatePreservingNonBuyTab(prev, {
1641
- buyerPubKey: account.address,
1642
- buyerPrvKey: privateKey,
2082
+ ...buyerFields,
1643
2083
  error: null,
1644
2084
  ...!isNonBuyTab(prev.activeTab) ? { status: "purchase_setup" } : {}
1645
2085
  })
@@ -1656,64 +2096,332 @@ function useAiCreditsAdapter({
1656
2096
  );
1657
2097
  }
1658
2098
  }, [address]);
1659
- const handleSignOperatorConsent = (0, import_react.useCallback)(async () => {
1660
- const currentState = state;
1661
- if (!currentState.address || !currentState.buyerPubKey || !currentState.buyerPrvKey) {
2099
+ const handleSelectBuyer = (0, import_react.useCallback)(
2100
+ async (buyerAddress) => {
2101
+ if (!address) return;
2102
+ const known = listKnownBuyerAddresses(address);
2103
+ if (!known.some((item) => item.toLowerCase() === buyerAddress.toLowerCase())) {
2104
+ return;
2105
+ }
2106
+ const buyers = mergeBuyerAddressList(known, buyerAddress);
2107
+ const buyerFields = activateBuyerSelection(address, buyers, buyerAddress);
1662
2108
  setState(
1663
- (prev) => withDerivedStatus(
1664
- prev,
1665
- { error: "Generate a buyer key before signing operator consent" },
1666
- true
1667
- )
2109
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2110
+ ...buyerFields,
2111
+ operatorAddress: null,
2112
+ currentOperator: null,
2113
+ totalCreditUsd: null,
2114
+ withdrawableUsd: null,
2115
+ totalGdDepositedG: null,
2116
+ monthlyStreamG: null,
2117
+ operatorConsentPending: false,
2118
+ error: null
2119
+ })
1668
2120
  );
1669
- return;
1670
- }
1671
- const ref = { payer: currentState.address, buyer: currentState.buyerPubKey };
1672
- const onNonBuyTab = isNonBuyTab(currentState.activeTab);
1673
- try {
1674
- const operatorStatus = await chainClient.getBuyerOperatorStatus(ref);
1675
- if (!operatorStatus.enabled) {
1676
- throw new Error("Operator consent is not available");
2121
+ try {
2122
+ const view = await buildAccountView(address, backendClient, chainClient, {
2123
+ buyerAddress
2124
+ });
2125
+ const enriched = await enrichAccountView(view, chainClient);
2126
+ const accountPatch = viewToStatePatch(view, enriched, INITIAL_STATE, {
2127
+ balanceMode: "always"
2128
+ });
2129
+ if (accountPatch.operatorConsented !== void 0) {
2130
+ setBuyerOperatorConsented(address, buyerAddress, accountPatch.operatorConsented);
2131
+ }
2132
+ const nextBuyerFields = buildBuyerStateFields(address, buyers, buyerAddress);
2133
+ setState(
2134
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2135
+ ...accountPatch,
2136
+ ...nextBuyerFields,
2137
+ operatorConsented: accountPatch.operatorConsented ?? nextBuyerFields.operatorConsented,
2138
+ error: null
2139
+ })
2140
+ );
2141
+ } catch (err) {
2142
+ setState(
2143
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2144
+ error: err instanceof Error ? err.message : "Could not load buyer account"
2145
+ })
2146
+ );
1677
2147
  }
1678
- if (operatorStatus.operatorAccepted) {
1679
- patchPayerSession(currentState.address, { operatorConsented: true });
2148
+ },
2149
+ [address, backendClient, chainClient]
2150
+ );
2151
+ const handleDiscoverBuyers = (0, import_react.useCallback)(
2152
+ (addresses) => {
2153
+ if (!address || addresses.length === 0) return;
2154
+ const buyers = rememberBuyerAddresses(address, addresses);
2155
+ setState((prev) => {
2156
+ const sameLength = buyers.length === prev.buyers.length;
2157
+ const unchanged = sameLength && buyers.every(
2158
+ (item, index) => item.toLowerCase() === prev.buyers[index]?.toLowerCase()
2159
+ );
2160
+ if (unchanged) return prev;
2161
+ return { ...prev, buyers };
2162
+ });
2163
+ },
2164
+ [address]
2165
+ );
2166
+ const handleImportBuyerFromPrivateKey = (0, import_react.useCallback)(
2167
+ async (rawPrivateKey) => {
2168
+ if (!address) {
2169
+ setState(
2170
+ (prev) => withDerivedStatus(prev, { error: "Connect your wallet before importing a signer key" }, true)
2171
+ );
2172
+ return null;
2173
+ }
2174
+ const trimmed = rawPrivateKey.trim();
2175
+ const normalized = trimmed.startsWith("0x") ? trimmed : `0x${trimmed}`;
2176
+ if (!/^0x[0-9a-fA-F]{64}$/.test(normalized)) {
2177
+ setState(
2178
+ (prev) => withDerivedStatus(
2179
+ prev,
2180
+ { error: "Invalid private key format \u2014 expected 0x followed by 64 hex characters" },
2181
+ true
2182
+ )
2183
+ );
2184
+ return null;
2185
+ }
2186
+ try {
2187
+ const privateKey = normalized;
2188
+ const buyerAccount = (0, import_accounts4.privateKeyToAccount)(privateKey);
2189
+ upsertBuyerKey(address, buyerAccount.address, { privateKey }, { setActive: true });
2190
+ const buyers = mergeBuyerAddressList(
2191
+ listKnownBuyerAddresses(address),
2192
+ buyerAccount.address
2193
+ );
2194
+ const buyerFields = buildBuyerStateFields(address, buyers, buyerAccount.address);
1680
2195
  setState(
1681
2196
  (prev) => mergeStatePreservingNonBuyTab(prev, {
1682
- operatorConsented: true,
2197
+ ...buyerFields,
2198
+ operatorAddress: null,
2199
+ currentOperator: null,
2200
+ totalCreditUsd: null,
2201
+ withdrawableUsd: null,
2202
+ totalGdDepositedG: null,
2203
+ monthlyStreamG: null,
1683
2204
  error: null,
1684
- ...!onNonBuyTab ? { status: "purchase_setup" } : {}
2205
+ ...!isNonBuyTab(prev.activeTab) ? { status: "purchase_setup" } : {}
1685
2206
  })
1686
2207
  );
2208
+ try {
2209
+ const view = await buildAccountView(address, backendClient, chainClient, {
2210
+ buyerAddress: buyerAccount.address
2211
+ });
2212
+ const enriched = await enrichAccountView(view, chainClient);
2213
+ const accountPatch = viewToStatePatch(view, enriched, INITIAL_STATE, {
2214
+ balanceMode: "always"
2215
+ });
2216
+ if (accountPatch.operatorConsented !== void 0) {
2217
+ setBuyerOperatorConsented(
2218
+ address,
2219
+ buyerAccount.address,
2220
+ accountPatch.operatorConsented
2221
+ );
2222
+ }
2223
+ const nextBuyerFields = buildBuyerStateFields(
2224
+ address,
2225
+ buyers,
2226
+ buyerAccount.address
2227
+ );
2228
+ setState(
2229
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2230
+ ...accountPatch,
2231
+ ...nextBuyerFields,
2232
+ operatorConsented: accountPatch.operatorConsented ?? nextBuyerFields.operatorConsented,
2233
+ error: null
2234
+ })
2235
+ );
2236
+ } catch {
2237
+ return buyerAccount.address;
2238
+ }
2239
+ return buyerAccount.address;
2240
+ } catch {
2241
+ setState(
2242
+ (prev) => withDerivedStatus(prev, { error: "Could not derive an account from the provided private key" }, true)
2243
+ );
2244
+ return null;
2245
+ }
2246
+ },
2247
+ [address, backendClient, chainClient]
2248
+ );
2249
+ const resolveBuyerList = (0, import_react.useCallback)(
2250
+ (payer, preferredBuyer) => resolveLocalBuyers(payer, preferredBuyer),
2251
+ []
2252
+ );
2253
+ const handleApplyDeepLinkBuyer = (0, import_react.useCallback)(
2254
+ async (buyerAddress, operatorSignature) => {
2255
+ if (!address) {
1687
2256
  return;
1688
2257
  }
1689
- const payload = await chainClient.buildOperatorConsentPayload(ref, operatorStatus);
1690
- if (!payload.enabled || !payload.typedData) {
1691
- throw new Error("Operator consent is not available");
2258
+ const trimmedAddress = buyerAddress.trim();
2259
+ const trimmedSignature = operatorSignature.trim();
2260
+ if (!isValidBuyerAddress(trimmedAddress)) {
2261
+ setState(
2262
+ (prev) => withDerivedStatus(
2263
+ prev,
2264
+ {
2265
+ error: deepLinkManualFallbackMessage("Deep-link buyerAddress is invalid."),
2266
+ activeTab: "buy",
2267
+ status: "purchase_setup"
2268
+ },
2269
+ true
2270
+ )
2271
+ );
2272
+ return;
1692
2273
  }
1693
- const buyerSig = await signOperatorConsentFromTypedData(
1694
- currentState.buyerPrvKey,
1695
- payload.typedData
1696
- );
1697
- await backendClient.submitOperatorConsent(ref.buyer, {
1698
- nonce: operatorStatus.consentNonce,
1699
- signature: buyerSig
2274
+ if (!isValidOperatorSignature(trimmedSignature)) {
2275
+ setState(
2276
+ (prev) => withDerivedStatus(
2277
+ prev,
2278
+ {
2279
+ error: deepLinkManualFallbackMessage("Deep-link operatorSignature is invalid."),
2280
+ activeTab: "buy",
2281
+ status: "purchase_setup"
2282
+ },
2283
+ true
2284
+ )
2285
+ );
2286
+ return;
2287
+ }
2288
+ storeDeepLinkParams({
2289
+ buyerAddress: trimmedAddress,
2290
+ operatorSignature: trimmedSignature
1700
2291
  });
1701
- await waitForOperatorConsent(chainClient, ref);
1702
- patchPayerSession(currentState.address, { operatorConsented: true });
2292
+ upsertBuyerKey(
2293
+ address,
2294
+ trimmedAddress,
2295
+ { operatorSignature: trimmedSignature },
2296
+ { setActive: true }
2297
+ );
2298
+ const buyers = mergeBuyerAddressList(listKnownBuyerAddresses(address), trimmedAddress);
2299
+ const buyerFields = buildBuyerStateFields(address, buyers, trimmedAddress);
1703
2300
  setState(
1704
2301
  (prev) => mergeStatePreservingNonBuyTab(prev, {
1705
- operatorConsented: true,
2302
+ ...buyerFields,
2303
+ operatorAddress: null,
2304
+ currentOperator: null,
2305
+ totalCreditUsd: null,
2306
+ withdrawableUsd: null,
2307
+ totalGdDepositedG: null,
2308
+ monthlyStreamG: null,
2309
+ activeTab: "buy",
2310
+ operatorConsentPending: false,
2311
+ error: null
2312
+ })
2313
+ );
2314
+ },
2315
+ [address]
2316
+ );
2317
+ const handleSignOperatorConsent = (0, import_react.useCallback)(async () => {
2318
+ const currentState = state;
2319
+ if (!currentState.address || !currentState.buyerPubKey) {
2320
+ setState(
2321
+ (prev) => withDerivedStatus(
2322
+ prev,
2323
+ { error: "Select a buyer before authorizing your wallet" },
2324
+ true
2325
+ )
2326
+ );
2327
+ return;
2328
+ }
2329
+ const keyEntry = getBuyerKeyEntry(currentState.address, currentState.buyerPubKey);
2330
+ const storedOperatorSignature = currentState.operatorSignature ?? keyEntry?.operatorSignature ?? null;
2331
+ if (!currentState.buyerPrvKey && !storedOperatorSignature) {
2332
+ setState(
2333
+ (prev) => withDerivedStatus(
2334
+ prev,
2335
+ { error: "Generate a signer key before authorizing your wallet" },
2336
+ true
2337
+ )
2338
+ );
2339
+ return;
2340
+ }
2341
+ if (currentState.operatorConsentPending) return;
2342
+ const ref = { payer: currentState.address, buyer: currentState.buyerPubKey };
2343
+ const onNonBuyTab = isNonBuyTab(currentState.activeTab);
2344
+ setState((prev) => ({
2345
+ ...prev,
2346
+ operatorConsentPending: true,
2347
+ error: null
2348
+ }));
2349
+ try {
2350
+ const operatorStatus = await chainClient.getBuyerOperatorStatus(ref);
2351
+ if (!operatorStatus.enabled) {
2352
+ throw new Error("Operator consent is not available");
2353
+ }
2354
+ const hasDifferentOperator = operatorStatus.currentOperator !== "0x0000000000000000000000000000000000000000" && !operatorStatus.operatorAccepted;
2355
+ if (hasDifferentOperator) {
2356
+ throw new Error(
2357
+ "This signer key is already controlled by another operator. Import a different signer key or generate a new one."
2358
+ );
2359
+ }
2360
+ if (operatorStatus.operatorAccepted) {
2361
+ setBuyerOperatorConsented(currentState.address, currentState.buyerPubKey, true);
2362
+ const buyerList2 = resolveBuyerList(currentState.address, currentState.buyerPubKey);
2363
+ const buyerFields2 = buildBuyerStateFields(
2364
+ currentState.address,
2365
+ buyerList2.buyers,
2366
+ buyerList2.selected
2367
+ );
2368
+ setState(
2369
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2370
+ ...buyerFields2,
2371
+ operatorConsented: true,
2372
+ operatorConsentPending: false,
2373
+ error: null,
2374
+ ...!onNonBuyTab ? { status: "purchase_setup" } : {}
2375
+ })
2376
+ );
2377
+ clearDeepLinkArtifacts();
2378
+ return;
2379
+ }
2380
+ let buyerSig;
2381
+ if (currentState.buyerPrvKey) {
2382
+ const payload = await chainClient.buildOperatorConsentPayload(ref, operatorStatus);
2383
+ if (!payload.enabled || !payload.typedData) {
2384
+ throw new Error("Operator consent is not available");
2385
+ }
2386
+ buyerSig = await signOperatorConsentFromTypedData(
2387
+ currentState.buyerPrvKey,
2388
+ payload.typedData
2389
+ );
2390
+ } else if (storedOperatorSignature) {
2391
+ buyerSig = storedOperatorSignature;
2392
+ } else {
2393
+ throw new Error("Generate a signer key before authorizing your wallet");
2394
+ }
2395
+ await backendClient.submitOperatorConsent(ref.buyer, {
2396
+ nonce: operatorStatus.consentNonce,
2397
+ signature: buyerSig
2398
+ });
2399
+ await waitForOperatorConsent(chainClient, ref);
2400
+ setBuyerOperatorConsented(currentState.address, currentState.buyerPubKey, true);
2401
+ const buyerList = resolveBuyerList(currentState.address, currentState.buyerPubKey);
2402
+ const buyerFields = buildBuyerStateFields(
2403
+ currentState.address,
2404
+ buyerList.buyers,
2405
+ buyerList.selected
2406
+ );
2407
+ setState(
2408
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2409
+ ...buyerFields,
2410
+ operatorConsented: true,
2411
+ operatorConsentPending: false,
1706
2412
  error: null,
1707
2413
  ...!onNonBuyTab ? { status: "purchase_setup" } : {}
1708
2414
  })
1709
2415
  );
2416
+ clearDeepLinkArtifacts();
1710
2417
  } catch (err) {
1711
2418
  setState((prev) => ({
1712
2419
  ...prev,
2420
+ operatorConsentPending: false,
1713
2421
  error: err instanceof Error ? err.message : "Operator consent signature rejected"
1714
2422
  }));
1715
2423
  }
1716
- }, [state, backendClient, chainClient]);
2424
+ }, [state, backendClient, chainClient, resolveBuyerList]);
1717
2425
  const handleSyncOperatorConsentFromChain = (0, import_react.useCallback)(async () => {
1718
2426
  const currentState = state;
1719
2427
  if (!currentState.address || !currentState.buyerPubKey || currentState.operatorConsented) {
@@ -1723,7 +2431,7 @@ function useAiCreditsAdapter({
1723
2431
  const ref = { payer: currentState.address, buyer: currentState.buyerPubKey };
1724
2432
  const operatorStatus = await chainClient.getBuyerOperatorStatus(ref);
1725
2433
  if (!operatorStatus.operatorAccepted) return;
1726
- patchPayerSession(currentState.address, { operatorConsented: true });
2434
+ setBuyerOperatorConsented(currentState.address, currentState.buyerPubKey, true);
1727
2435
  const onNonBuyTab = isNonBuyTab(currentState.activeTab);
1728
2436
  setState(
1729
2437
  (prev) => mergeStatePreservingNonBuyTab(prev, {
@@ -1755,7 +2463,7 @@ function useAiCreditsAdapter({
1755
2463
  async (quote) => {
1756
2464
  const currentState = state;
1757
2465
  if (!currentState.address || !currentState.buyerPubKey || !providerRef.current) {
1758
- throw new Error("Connect your wallet and generate a buyer key before paying");
2466
+ throw new Error("Connect your wallet and generate a signer key before paying");
1759
2467
  }
1760
2468
  const hasDeposit = Number.parseFloat(quote.depositAmountG) > 0;
1761
2469
  const streamChanged = isStreamAmountChanged(quote.streamAmountG, currentState.monthlyStreamG);
@@ -1861,8 +2569,15 @@ function useAiCreditsAdapter({
1861
2569
  previousBalance: balanceBefore
1862
2570
  });
1863
2571
  const creditUsdMicro = (BigInt(totalCreditUsd) - BigInt(balanceBefore || "0")).toString();
2572
+ const buyerList = resolveBuyerList(currentState.address, currentState.buyerPubKey);
2573
+ const buyerFields = buildBuyerStateFields(
2574
+ currentState.address,
2575
+ buyerList.buyers,
2576
+ buyerList.selected
2577
+ );
1864
2578
  setState(
1865
2579
  (prev) => withDerivedStatus(prev, {
2580
+ ...buyerFields,
1866
2581
  totalCreditUsd,
1867
2582
  error: null,
1868
2583
  activeTab: "manage"
@@ -1897,6 +2612,7 @@ function useAiCreditsAdapter({
1897
2612
  celoVault,
1898
2613
  onPaySuccess,
1899
2614
  onPayError,
2615
+ resolveBuyerList,
1900
2616
  prepareSettlement,
1901
2617
  skipVaultPaymentValidation
1902
2618
  ]
@@ -1906,36 +2622,38 @@ function useAiCreditsAdapter({
1906
2622
  const currentState = state;
1907
2623
  if (!currentState.address) return;
1908
2624
  try {
1909
- const sessionBuyer = currentState.buyerPubKey ?? patchPayerSessionFields(currentState.address).buyerPubKey ?? null;
2625
+ const preferredBuyer = currentState.buyerPubKey;
2626
+ const buyerList = resolveBuyerList(currentState.address, preferredBuyer);
1910
2627
  const [view, discountConfig] = await Promise.all([
1911
2628
  buildAccountView(currentState.address, backendClient, chainClient, {
1912
- buyerAddress: sessionBuyer
2629
+ buyerAddress: preferredBuyer
1913
2630
  }),
1914
2631
  backendClient.getDiscountConfig().catch(() => null)
1915
2632
  ]);
1916
2633
  const enriched = await enrichAccountView(view, chainClient);
1917
- setState((prev) => {
1918
- const accountPatch = viewToStatePatch(view, enriched, prev, {
1919
- balanceMode: "always"
1920
- });
1921
- const sessionFields = mergeSessionFields(
1922
- prev,
1923
- patchPayerSessionFields(currentState.address),
1924
- accountPatch,
1925
- false
2634
+ const accountPatch = viewToStatePatch(view, enriched, INITIAL_STATE, {
2635
+ balanceMode: "always"
2636
+ });
2637
+ if (preferredBuyer && accountPatch.operatorConsented !== void 0 && currentState.address) {
2638
+ setBuyerOperatorConsented(
2639
+ currentState.address,
2640
+ preferredBuyer,
2641
+ accountPatch.operatorConsented
1926
2642
  );
1927
- if (accountPatch.operatorConsented !== void 0 && currentState.address) {
1928
- syncOperatorConsentSession(currentState.address, accountPatch.operatorConsented);
1929
- }
1930
- if (currentState.address && view.buyer) {
1931
- syncBuyerPubKeySession(currentState.address, view.buyer);
1932
- }
2643
+ }
2644
+ const buyerFields = buildBuyerStateFields(
2645
+ currentState.address,
2646
+ buyerList.buyers,
2647
+ buyerList.selected
2648
+ );
2649
+ setState((prev) => {
1933
2650
  const statusSeed = options?.afterGoodIdVerify && prev.status === "payment_failed" ? "quote_ready" : prev.status === "backend_unavailable" ? "purchase_setup" : prev.status;
1934
2651
  return withDerivedStatus(
1935
2652
  { ...prev, status: statusSeed },
1936
2653
  {
1937
2654
  ...accountPatch,
1938
- ...sessionFields,
2655
+ ...buyerFields,
2656
+ operatorConsented: accountPatch.operatorConsented ?? buyerFields.operatorConsented,
1939
2657
  activeTab: prev.activeTab,
1940
2658
  error: null,
1941
2659
  depositBonusPercent: discountConfig?.depositBonusPercent ?? prev.depositBonusPercent,
@@ -1953,7 +2671,7 @@ function useAiCreditsAdapter({
1953
2671
  );
1954
2672
  }
1955
2673
  },
1956
- [state, backendClient, chainClient]
2674
+ [state, backendClient, chainClient, resolveBuyerList]
1957
2675
  );
1958
2676
  const handleVerifyGoodId = (0, import_react.useCallback)(async () => {
1959
2677
  const currentState = state;
@@ -2024,7 +2742,7 @@ function useAiCreditsAdapter({
2024
2742
  if (!currentState.buyerPrvKey) {
2025
2743
  setState((prev) => ({
2026
2744
  ...prev,
2027
- error: "Sign with your payer wallet in Buyer & Operator below to generate the buyer private key before closing a channel"
2745
+ error: "Sign with your payer wallet in Signer Key below to generate the buyer private key before closing a channel"
2028
2746
  }));
2029
2747
  return;
2030
2748
  }
@@ -2061,7 +2779,7 @@ function useAiCreditsAdapter({
2061
2779
  if (!currentState.buyerPrvKey) {
2062
2780
  setState((prev) => ({
2063
2781
  ...prev,
2064
- error: "Sign with your payer wallet in Buyer & Operator below to generate the buyer private key before withdrawing funds"
2782
+ error: "Sign with your payer wallet in Signer Key below to generate the buyer private key before withdrawing funds"
2065
2783
  }));
2066
2784
  return;
2067
2785
  }
@@ -2127,22 +2845,76 @@ function useAiCreditsAdapter({
2127
2845
  await handleRefresh();
2128
2846
  }, [configurationError, handleRefresh]);
2129
2847
  const handleSetActiveTab = (0, import_react.useCallback)((tab) => {
2130
- if (tab === "buy") {
2848
+ setState((prev) => {
2849
+ if (needsWalletConnection(prev)) {
2850
+ if (tab === "setup") {
2851
+ return mergeStatePreservingNonBuyTab(prev, { activeTab: "setup", error: null });
2852
+ }
2853
+ return prev;
2854
+ }
2855
+ if (tab === "buy") {
2856
+ return withDerivedStatus(prev, { activeTab: "buy", status: "purchase_setup", error: null }, true);
2857
+ }
2858
+ return mergeStatePreservingNonBuyTab(prev, { activeTab: tab, error: null });
2859
+ });
2860
+ }, []);
2861
+ const handleStartPurchase = (0, import_react.useCallback)(() => {
2862
+ handleSetActiveTab("buy");
2863
+ }, [handleSetActiveTab]);
2864
+ (0, import_react.useEffect)(() => {
2865
+ if (typeof window === "undefined" || deepLinkParseDoneRef.current) return;
2866
+ deepLinkParseDoneRef.current = true;
2867
+ const parsed = resolveDeepLinkParams(window.location.search);
2868
+ if (parsed.status === "absent") return;
2869
+ if (parsed.status === "partial") {
2870
+ const missing = parsed.present === "buyerAddress" ? "operatorSignature" : "buyerAddress";
2871
+ setState(
2872
+ (prev) => withDerivedStatus(
2873
+ prev,
2874
+ {
2875
+ error: deepLinkManualFallbackMessage(`Deep link is missing ${missing}.`),
2876
+ activeTab: "buy",
2877
+ status: "purchase_setup"
2878
+ },
2879
+ false
2880
+ )
2881
+ );
2882
+ return;
2883
+ }
2884
+ if (parsed.status === "invalid") {
2131
2885
  setState(
2132
- (prev) => withDerivedStatus(prev, { activeTab: "buy", status: "purchase_setup", error: null }, true)
2886
+ (prev) => withDerivedStatus(
2887
+ prev,
2888
+ {
2889
+ error: deepLinkManualFallbackMessage(`${parsed.reason}.`),
2890
+ activeTab: "buy",
2891
+ status: "purchase_setup"
2892
+ },
2893
+ false
2894
+ )
2133
2895
  );
2134
2896
  return;
2135
2897
  }
2136
- setState((prev) => mergeStatePreservingNonBuyTab(prev, { activeTab: tab, error: null }));
2898
+ pendingDeepLinkRef.current = parsed.value;
2137
2899
  }, []);
2138
- const handleStartPurchase = (0, import_react.useCallback)(() => {
2139
- handleSetActiveTab("buy");
2140
- }, [handleSetActiveTab]);
2900
+ (0, import_react.useEffect)(() => {
2901
+ const pending = pendingDeepLinkRef.current;
2902
+ if (!address || !pending || deepLinkApplyInFlightRef.current) return;
2903
+ deepLinkApplyInFlightRef.current = true;
2904
+ void handleApplyDeepLinkBuyer(pending.buyerAddress, pending.operatorSignature).finally(() => {
2905
+ deepLinkApplyInFlightRef.current = false;
2906
+ pendingDeepLinkRef.current = null;
2907
+ });
2908
+ }, [address, handleApplyDeepLinkBuyer]);
2141
2909
  const actions = (0, import_react.useMemo)(
2142
2910
  () => ({
2143
2911
  connect: handleConnect,
2144
2912
  switchChain: handleSwitchChain,
2145
2913
  generateBuyerKey: handleGenerateBuyerKey,
2914
+ selectBuyer: handleSelectBuyer,
2915
+ discoverBuyers: handleDiscoverBuyers,
2916
+ importBuyerFromPrivateKey: handleImportBuyerFromPrivateKey,
2917
+ applyDeepLinkBuyer: handleApplyDeepLinkBuyer,
2146
2918
  signOperatorConsent: handleSignOperatorConsent,
2147
2919
  syncOperatorConsentFromChain: handleSyncOperatorConsentFromChain,
2148
2920
  buildQuote: handleBuildQuote,
@@ -2159,6 +2931,10 @@ function useAiCreditsAdapter({
2159
2931
  handleConnect,
2160
2932
  handleSwitchChain,
2161
2933
  handleGenerateBuyerKey,
2934
+ handleSelectBuyer,
2935
+ handleDiscoverBuyers,
2936
+ handleImportBuyerFromPrivateKey,
2937
+ handleApplyDeepLinkBuyer,
2162
2938
  handleSignOperatorConsent,
2163
2939
  handleSyncOperatorConsentFromChain,
2164
2940
  handleBuildQuote,
@@ -2176,14 +2952,16 @@ function useAiCreditsAdapter({
2176
2952
  }
2177
2953
 
2178
2954
  // src/AiCreditsWidget.tsx
2179
- var import_react14 = __toESM(require("react"), 1);
2955
+ var import_react17 = __toESM(require("react"), 1);
2180
2956
  var import_core2 = require("@goodwidget/core");
2181
- var import_ui16 = require("@goodwidget/ui");
2957
+ var import_ui21 = require("@goodwidget/ui");
2182
2958
 
2183
2959
  // src/useAiCreditsHistory.ts
2184
2960
  var import_react2 = require("react");
2185
2961
  var HISTORY_PAGE_SIZE = 10;
2186
2962
  var HISTORY_LOOKBACK_DAYS = 90;
2963
+ var BUYER_FILTER_FILL_MAX_PAGES = 8;
2964
+ var BUYER_FILTER_ALL = "all";
2187
2965
  var HISTORY_SOURCE_OPTIONS = [
2188
2966
  { id: "deposit", label: "Deposit", defaultChecked: true },
2189
2967
  { id: "streamUpdate", label: "Stream update", defaultChecked: true },
@@ -2219,11 +2997,23 @@ function toIsoEndOfDay(dateValue) {
2219
2997
  if (Number.isNaN(parsed)) return void 0;
2220
2998
  return new Date(parsed).toISOString();
2221
2999
  }
3000
+ function matchesBuyerFilter(entry, filter) {
3001
+ if (filter === BUYER_FILTER_ALL) return true;
3002
+ return entry.buyerAddress?.toLowerCase() === filter.toLowerCase();
3003
+ }
2222
3004
  function useAiCreditsHistory(options) {
2223
- const { address, backendUrl, environment = "production", backendClient } = options;
3005
+ const {
3006
+ address,
3007
+ backendUrl,
3008
+ defaultBuyerFilter = BUYER_FILTER_ALL,
3009
+ environment = "production",
3010
+ backendClient,
3011
+ onBuyersDiscovered
3012
+ } = options;
2224
3013
  const defaultRange = (0, import_react2.useMemo)(() => getLast90DaysRange(), []);
2225
3014
  const [selectedSources, setSelectedSources] = (0, import_react2.useState)(createDefaultSelectedSources);
2226
3015
  const [statusFilter, setStatusFilter] = (0, import_react2.useState)("all");
3016
+ const [buyerAddressFilter, setBuyerAddressFilter] = (0, import_react2.useState)(defaultBuyerFilter);
2227
3017
  const [fromDate, setFromDate] = (0, import_react2.useState)(defaultRange.from);
2228
3018
  const [toDate, setToDate] = (0, import_react2.useState)(defaultRange.to);
2229
3019
  const [entries, setEntries] = (0, import_react2.useState)([]);
@@ -2232,6 +3022,9 @@ function useAiCreditsHistory(options) {
2232
3022
  const [loading, setLoading] = (0, import_react2.useState)(false);
2233
3023
  const [loadingMore, setLoadingMore] = (0, import_react2.useState)(false);
2234
3024
  const [error, setError] = (0, import_react2.useState)(null);
3025
+ (0, import_react2.useEffect)(() => {
3026
+ setBuyerAddressFilter(defaultBuyerFilter);
3027
+ }, [defaultBuyerFilter]);
2235
3028
  const activeSources = (0, import_react2.useMemo)(
2236
3029
  () => HISTORY_SOURCE_OPTIONS.map((option) => option.id).filter((id) => selectedSources[id]),
2237
3030
  [selectedSources]
@@ -2239,12 +3032,12 @@ function useAiCreditsHistory(options) {
2239
3032
  const loadHistory = (0, import_react2.useCallback)(
2240
3033
  async (nextOffset, append) => {
2241
3034
  if (!address) {
2242
- setEntries([]);
2243
- setOffset(0);
2244
- setHasMore(false);
2245
- setError(null);
2246
- setLoading(false);
2247
- setLoadingMore(false);
3035
+ setEntries((prev) => prev.length === 0 ? prev : []);
3036
+ setOffset((prev) => prev === 0 ? prev : 0);
3037
+ setHasMore((prev) => prev ? false : prev);
3038
+ setError((prev) => prev === null ? prev : null);
3039
+ setLoading((prev) => prev ? false : prev);
3040
+ setLoadingMore((prev) => prev ? false : prev);
2248
3041
  return;
2249
3042
  }
2250
3043
  if (activeSources.length === 0) {
@@ -2262,19 +3055,38 @@ function useAiCreditsHistory(options) {
2262
3055
  const client = backendClient ?? createBackendClient(backendUrl);
2263
3056
  const apiSource = activeSources.length === 1 ? activeSources[0] : void 0;
2264
3057
  const fundingStatus = statusFilter === "all" ? void 0 : statusFilter;
3058
+ const filterByBuyer = buyerAddressFilter !== BUYER_FILTER_ALL;
2265
3059
  try {
2266
- const response = await client.getCreditHistory(address, {
2267
- limit: HISTORY_PAGE_SIZE,
2268
- offset: nextOffset,
2269
- source: apiSource,
2270
- fundingStatus,
2271
- from: toIsoStartOfDay(fromDate),
2272
- to: toIsoEndOfDay(toDate)
2273
- });
2274
- const pageItems = activeSources.length === 1 ? response.items : response.items.filter((entry) => selectedSources[entry.source]);
2275
- setEntries((prev) => append ? [...prev, ...pageItems] : pageItems);
2276
- setOffset(nextOffset);
2277
- setHasMore(response.hasMore);
3060
+ const collected = [];
3061
+ let cursor = nextOffset;
3062
+ let apiHasMore = true;
3063
+ let pages = 0;
3064
+ while (pages < BUYER_FILTER_FILL_MAX_PAGES && collected.length < HISTORY_PAGE_SIZE && apiHasMore) {
3065
+ const response = await client.getCreditHistory(address, {
3066
+ limit: HISTORY_PAGE_SIZE,
3067
+ offset: cursor,
3068
+ source: apiSource,
3069
+ fundingStatus,
3070
+ from: toIsoStartOfDay(fromDate),
3071
+ to: toIsoEndOfDay(toDate)
3072
+ });
3073
+ const sourceFiltered = activeSources.length === 1 ? response.items : response.items.filter((entry) => selectedSources[entry.source]);
3074
+ const discoveredBuyers = sourceFiltered.map((entry) => entry.buyerAddress).filter((value) => Boolean(value));
3075
+ if (discoveredBuyers.length > 0) {
3076
+ onBuyersDiscovered?.(discoveredBuyers);
3077
+ }
3078
+ const buyerFiltered = sourceFiltered.filter(
3079
+ (entry) => matchesBuyerFilter(entry, buyerAddressFilter)
3080
+ );
3081
+ collected.push(...buyerFiltered);
3082
+ apiHasMore = response.hasMore;
3083
+ cursor = response.offset + response.limit;
3084
+ pages += 1;
3085
+ if (!filterByBuyer) break;
3086
+ }
3087
+ setEntries((prev) => append ? [...prev, ...collected] : collected);
3088
+ setOffset(cursor);
3089
+ setHasMore(apiHasMore);
2278
3090
  } catch (err) {
2279
3091
  if (!append) setEntries([]);
2280
3092
  setHasMore(false);
@@ -2291,9 +3103,11 @@ function useAiCreditsHistory(options) {
2291
3103
  backendClient,
2292
3104
  activeSources,
2293
3105
  statusFilter,
3106
+ buyerAddressFilter,
2294
3107
  fromDate,
2295
3108
  toDate,
2296
- selectedSources
3109
+ selectedSources,
3110
+ onBuyersDiscovered
2297
3111
  ]
2298
3112
  );
2299
3113
  (0, import_react2.useEffect)(() => {
@@ -2311,12 +3125,13 @@ function useAiCreditsHistory(options) {
2311
3125
  await loadHistory(0, false);
2312
3126
  }, [loadHistory]);
2313
3127
  const loadMore = (0, import_react2.useCallback)(async () => {
2314
- await loadHistory(offset + HISTORY_PAGE_SIZE, true);
3128
+ await loadHistory(offset, true);
2315
3129
  }, [loadHistory, offset]);
2316
3130
  return {
2317
3131
  state: {
2318
3132
  selectedSources,
2319
3133
  statusFilter,
3134
+ buyerAddressFilter,
2320
3135
  fromDate,
2321
3136
  toDate,
2322
3137
  entries,
@@ -2330,6 +3145,7 @@ function useAiCreditsHistory(options) {
2330
3145
  actions: {
2331
3146
  setSourceChecked,
2332
3147
  setStatusFilter,
3148
+ setBuyerAddressFilter,
2333
3149
  setFromDate,
2334
3150
  setToDate,
2335
3151
  reload,
@@ -2428,8 +3244,8 @@ function BuyerKeyPanel({
2428
3244
  }
2429
3245
  const Shell = embedded ? import_ui4.YStack : import_ui4.Card;
2430
3246
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Shell, { gap: "$3", children: [
2431
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Heading, { level: 5, children: "Buyer Key" }),
2432
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Text, { children: "Sign a message with your payer wallet to derive a deterministic AntSeed buyer key. Save the private key \u2014 you will need it to authenticate from your developer tools." }),
3247
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Heading, { level: 5, children: "Signer Key" }),
3248
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Text, { children: "Sign a message with your payer wallet to derive a dedicated AntSeed signer key. Save the private key \u2014 you will need it to authenticate from your developer tools." }),
2433
3249
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_ui4.YStack, { gap: "$3", children: [
2434
3250
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2435
3251
  import_ui4.Button,
@@ -2465,6 +3281,7 @@ function BuyerKeyPanel({
2465
3281
  }
2466
3282
  ),
2467
3283
  buyerPrvKey && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3284
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AiCreditsStatusNotice, { borderColor: "$warning", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Text, { color: "$warning", fontSize: "$2", children: "Back up any existing AntSeed signer key before importing this one. Importing replaces the signer used by your AntSeed account." }) }),
2468
3285
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_ui4.XStack, { justifyContent: "space-between", alignItems: "center", children: [
2469
3286
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Text, { variant: "label", secondary: true, children: "Private Key \u2014 save this securely" }),
2470
3287
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -2509,7 +3326,8 @@ function BuyerKeyPanel({
2509
3326
  )
2510
3327
  ]
2511
3328
  }
2512
- )
3329
+ ),
3330
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Text, { fontSize: "$2", secondary: true, children: "In AntSeed, open Settings \u2192 Signer key and import this private key. The public address above is the signer identity used for AI credits." })
2513
3331
  ] }),
2514
3332
  buyerPrvKey && !buyerPubKeySaved && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Button, { size: "sm", ...compactButtonProps, onPress: onConfirm, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.ButtonText, { children: "I've Saved My Private Key" }) }),
2515
3333
  buyerPubKeySaved && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_ui4.XStack, { gap: "$2", alignItems: "center", children: [
@@ -2522,22 +3340,23 @@ function BuyerKeyPanel({
2522
3340
  }
2523
3341
 
2524
3342
  // src/components/buy/OperatorConsentStep.tsx
2525
- var import_react5 = require("react");
2526
3343
  var import_ui5 = require("@goodwidget/ui");
2527
3344
  var import_jsx_runtime3 = require("react/jsx-runtime");
2528
3345
  function OperatorConsentStep({
2529
3346
  buyerPubKey,
2530
3347
  buyerPrvKey,
3348
+ operatorSignature = null,
2531
3349
  operatorConsented,
3350
+ operatorConsentPending = false,
2532
3351
  onSign,
2533
3352
  embedded = false
2534
3353
  }) {
2535
- const [isSigning, setIsSigning] = (0, import_react5.useState)(false);
2536
- const canSign = Boolean(buyerPubKey && buyerPrvKey);
3354
+ const canSign = Boolean(buyerPubKey && (buyerPrvKey || operatorSignature));
3355
+ const isBusy = operatorConsentPending;
2537
3356
  const Shell = embedded ? import_ui5.YStack : import_ui5.Card;
2538
3357
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Shell, { gap: "$3", ...!embedded ? { backgroundColor: "$backgroundHover" } : {}, children: [
2539
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Heading, { level: 5, children: "Authorize AntSeed Operator" }),
2540
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Text, { fontSize: "$2", lineHeight: "$3", children: "Your buyer key signs an EIP-712 SetOperator message. The backend submits it to AntseedDeposits so the funding vault can act as your operator. No gas is required from you." }),
3358
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Heading, { level: 5, children: "Authorize Wallet" }),
3359
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Text, { fontSize: "$2", lineHeight: "$3", children: "GoodDollar needs this one-time authorization to fund and manage your AI credits on Base after you pay with G$ on Celo. It lets the GoodDollar operator move funds in your separate AI credits account, but never gives access to your payer wallet or G$. Granting this permission means trusting GoodDollar with that scoped Base role; you can revoke it later through the account controls." }),
2541
3360
  buyerPubKey && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui5.Text, { fontSize: "$2", lineHeight: "$2", children: [
2542
3361
  "Buyer address:",
2543
3362
  " ",
@@ -2545,38 +3364,35 @@ function OperatorConsentStep({
2545
3364
  ] }),
2546
3365
  operatorConsented ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui5.XStack, { gap: "$2", alignItems: "center", children: [
2547
3366
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Icon, { name: "check", size: "sm", color: "success" }),
2548
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Text, { color: "$success", children: "Operator consent accepted \u2014 ready to pay" })
3367
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Text, { color: "$success", children: "Wallet authorized \u2014 ready to pay" })
2549
3368
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2550
3369
  import_ui5.Button,
2551
3370
  {
2552
3371
  size: "sm",
2553
3372
  ...compactButtonProps,
2554
3373
  onPress: () => {
2555
- setIsSigning(true);
2556
- void onSign().finally(() => {
2557
- setIsSigning(false);
2558
- });
3374
+ void onSign();
2559
3375
  },
2560
- disabled: !canSign || isSigning,
2561
- children: isSigning ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui5.XStack, { gap: "$2", alignItems: "center", children: [
2562
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.ButtonText, { children: "Signing\u2026" }),
3376
+ disabled: !canSign || isBusy,
3377
+ children: isBusy ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui5.XStack, { gap: "$2", alignItems: "center", children: [
3378
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.ButtonText, { children: "Submitting\u2026" }),
2563
3379
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Spinner, { size: "sm" })
2564
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.ButtonText, { children: "Sign Operator Consent" })
3380
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.ButtonText, { children: "Authorize Wallet" })
2565
3381
  }
2566
3382
  )
2567
3383
  ] });
2568
3384
  }
2569
3385
 
2570
3386
  // src/components/buy/AmountPicker.tsx
2571
- var import_react7 = require("react");
3387
+ var import_react6 = require("react");
2572
3388
  var import_ui7 = require("@goodwidget/ui");
2573
3389
 
2574
3390
  // src/components/shared/tooltips.tsx
2575
- var import_react6 = require("react");
3391
+ var import_react5 = require("react");
2576
3392
  var import_ui6 = require("@goodwidget/ui");
2577
3393
  var import_jsx_runtime4 = require("react/jsx-runtime");
2578
3394
  function InfoTooltip({ message }) {
2579
- const [open, setOpen] = (0, import_react6.useState)(false);
3395
+ const [open, setOpen] = (0, import_react5.useState)(false);
2580
3396
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2581
3397
  import_ui6.XStack,
2582
3398
  {
@@ -2621,7 +3437,7 @@ function HoverTooltip({
2621
3437
  children,
2622
3438
  fullWidth = false
2623
3439
  }) {
2624
- const [open, setOpen] = (0, import_react6.useState)(false);
3440
+ const [open, setOpen] = (0, import_react5.useState)(false);
2625
3441
  if (!message) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children });
2626
3442
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2627
3443
  import_ui6.XStack,
@@ -2705,17 +3521,17 @@ function AmountPicker({
2705
3521
  onVerifyGoodId,
2706
3522
  embedded = false
2707
3523
  }) {
2708
- const streamSeed = (0, import_react7.useMemo)(() => resolveInitialStreamAmount(monthlyStreamG), [monthlyStreamG]);
2709
- const [depositAmount, setDepositAmount] = (0, import_react7.useState)(DEFAULT_DEPOSIT_AMOUNT);
2710
- const [streamAmount, setStreamAmount] = (0, import_react7.useState)(streamSeed);
2711
- const [quote, setQuote] = (0, import_react7.useState)(null);
2712
- const [quotePending, setQuotePending] = (0, import_react7.useState)(false);
2713
- const [isVerifyingGoodId, setIsVerifyingGoodId] = (0, import_react7.useState)(false);
3524
+ const streamSeed = (0, import_react6.useMemo)(() => resolveInitialStreamAmount(monthlyStreamG), [monthlyStreamG]);
3525
+ const [depositAmount, setDepositAmount] = (0, import_react6.useState)(DEFAULT_DEPOSIT_AMOUNT);
3526
+ const [streamAmount, setStreamAmount] = (0, import_react6.useState)(streamSeed);
3527
+ const [quote, setQuote] = (0, import_react6.useState)(null);
3528
+ const [quotePending, setQuotePending] = (0, import_react6.useState)(false);
3529
+ const [isVerifyingGoodId, setIsVerifyingGoodId] = (0, import_react6.useState)(false);
2714
3530
  const isStreamUpdateFlow = parseGAmount(streamSeed) > 0;
2715
- (0, import_react7.useEffect)(() => {
3531
+ (0, import_react6.useEffect)(() => {
2716
3532
  setStreamAmount(streamSeed);
2717
3533
  }, [streamSeed]);
2718
- (0, import_react7.useEffect)(() => {
3534
+ (0, import_react6.useEffect)(() => {
2719
3535
  let cancelled = false;
2720
3536
  setQuotePending(true);
2721
3537
  void buildQuote(depositAmount, streamAmount).then((nextQuote) => {
@@ -2733,7 +3549,7 @@ function AmountPicker({
2733
3549
  const streamG = parseGAmount(streamAmount);
2734
3550
  const depositBonusLabel = isGoodIdVerified ? `+${depositBonusPercent}% bonus` : `Verify for +${depositBonusPercent}%`;
2735
3551
  const streamBonusLabel = isGoodIdVerified ? `+${streamBonusPercent}% bonus` : `Verify for +${streamBonusPercent}%`;
2736
- const paymentValidation = (0, import_react7.useMemo)(
3552
+ const paymentValidation = (0, import_react6.useMemo)(
2737
3553
  () => getPaymentAmountValidation({
2738
3554
  depositAmount,
2739
3555
  streamAmount,
@@ -2747,7 +3563,8 @@ function AmountPicker({
2747
3563
  [depositAmount, streamAmount, monthlyStreamG, minDepositUsd, minStreamUsd, quote, gdUsdPerToken, gBalance]
2748
3564
  );
2749
3565
  const minsLoaded = minStreamUsd !== null;
2750
- const canPay = status === "quote_ready" && minsLoaded && paymentValidation.hasPaymentAction && paymentValidation.vaultMinimumsMet && !paymentValidation.overBalance && !quotePending && quote !== null;
3566
+ const canRetryAfterFailure = status === "quote_ready" || status === "payment_failed";
3567
+ const canPay = canRetryAfterFailure && minsLoaded && paymentValidation.hasPaymentAction && paymentValidation.vaultMinimumsMet && !paymentValidation.overBalance && !quotePending && quote !== null;
2751
3568
  const payDisabledMessage = getPayDisabledMessage({
2752
3569
  canPay,
2753
3570
  minsLoaded,
@@ -2890,126 +3707,20 @@ function AmountPicker({
2890
3707
  ] });
2891
3708
  }
2892
3709
 
2893
- // src/components/buy/BuyCreditsFaq.tsx
2894
- var import_react8 = require("react");
2895
- var import_ui8 = require("@goodwidget/ui");
2896
- var import_jsx_runtime6 = require("react/jsx-runtime");
2897
- var FAQ_ITEMS = [
2898
- {
2899
- id: "what-are-credits",
2900
- question: "What are AI credits?",
2901
- answer: "AI credits pay for AntSeed-compatible coding tools. GoodDollar only supports purchasing AntSeed AI credits. You buy them with G$ on Celo; AI credits (USD) settle on Base and appear in your Manage tab balance."
2902
- },
2903
- {
2904
- id: "how-to-buy",
2905
- question: "How do I buy credits?",
2906
- answer: "Complete the Buy Credits steps: generate a buyer key, sign operator consent, then enter a one-time G$ deposit and/or a monthly G$ stream and confirm one Celo transaction (approve, deposit, and stream changes are batched when needed)."
2907
- },
2908
- {
2909
- id: "deposit-vs-stream",
2910
- question: "What is a one-time deposit vs a monthly stream?",
2911
- answer: "A one-time deposit converts G$ into credits right away. A monthly stream sets a G$/month flow rate on Celo; credits are added in real time as G$ streams in, not as a single monthly lump."
2912
- },
2913
- {
2914
- id: "minimums",
2915
- question: "What are the minimum amounts?",
2916
- answer: "Your first one-time deposit must be at least US$1.00. If you set a monthly stream, it must be at least US$1.00/month. After your first deposit, there is no minimum for additional one-time deposits.\n\nTo open a new channel to a new provider, you need more than 1 USDC in available credits."
2917
- },
2918
- {
2919
- id: "goodid-bonus",
2920
- question: "How do GoodID bonuses work?",
2921
- answer: "With a verified GoodID you receive bonus credits on one-time deposits and monthly streams. The current bonus rates are shown in the Buy Credits form. Without GoodID verification, bonuses do not apply."
2922
- },
2923
- {
2924
- id: "buyer-key",
2925
- question: "What is the buyer key?",
2926
- answer: "Your payer wallet pays G$ on Celo. The buyer key is a separate key derived from a payer signature; it manages your AI credits on Base. Save the buyer private key from this session for AI API setup and Manage actions like withdraw."
2927
- },
2928
- {
2929
- id: "operator-consent",
2930
- question: "Why do I authorize the Gooddollar operator?",
2931
- answer: "Payer is the wallet that pays G$ on Celo. Buyer is a separate key derived from a payer signature; it owns your AI credit account on Base.\n\nOperator consent is a one-time sign-off so the GoodDollar operator can act as your operator on Base. After you pay G$ on Celo, the operator can fund your credits and handle Base-side actions \u2014 including moving credit funds \u2014 without you paying Base gas. It cannot access your payer wallet or G$ on Celo. Because the operator can act on your Base credit account, you are trusting GoodDollar with that role. You can also withdraw unused principal yourself with your buyer private key."
2932
- },
2933
- {
2934
- id: "when-credits-arrive",
2935
- question: "When do credits arrive?",
2936
- answer: "After your Celo payment confirms, credits are funded on Base. Funding usually completes within a short time; check the Manage tab for your updated balance."
2937
- },
2938
- {
2939
- id: "withdraw",
2940
- question: "What funds can I withdraw?",
2941
- answer: "You can withdraw unused principal up to the Withdrawable amount shown in Manage. Bonus credits from GoodID are not withdrawable and stay for AI usage only.\n\nWithdrawals are signed with your buyer private key and settled on Base as USD to your payer wallet address \u2014 the same wallet that pays G$ on Celo. Your total credit balance will be higher than the withdrawable amount when bonuses are included."
2942
- },
2943
- {
2944
- id: "api-setup",
2945
- question: "What is API setup?",
2946
- answer: "After you have credits, open Manage \u2192 API Setup and copy the commands into your terminal. ANTSEED_IDENTITY_HEX is your buyer private key. it links your purchases to the credit balance your AI tools should use."
2947
- },
2948
- {
2949
- id: "support",
2950
- question: "Who do I contact for support?",
2951
- answer: "GoodDollar only supports purchasing AntSeed AI credits through this widget. For post-purchase issues \u2014 including credit usage, channels, providers, or AntSeed tooling \u2014 contact the AntSeed support team on Telegram: https://t.me/antseed"
2952
- }
2953
- ];
2954
- function FaqItem({
2955
- question,
2956
- answer,
2957
- expanded,
2958
- onToggle
2959
- }) {
2960
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.YStack, { gap: "$1", children: [
2961
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2962
- import_ui8.XStack,
2963
- {
2964
- justifyContent: "space-between",
2965
- alignItems: "center",
2966
- gap: "$2",
2967
- onPress: onToggle,
2968
- cursor: "pointer",
2969
- children: [
2970
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$2", fontWeight: "600", flex: 1, children: question }),
2971
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Icon, { name: expanded ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
2972
- ]
2973
- }
2974
- ),
2975
- expanded && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.YStack, { gap: "$2", children: answer.split("\n\n").map((paragraph, index) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$2", secondary: true, lineHeight: "$3", children: paragraph }, index)) })
2976
- ] });
2977
- }
2978
- function BuyCreditsFaq() {
2979
- const [expandedId, setExpandedId] = (0, import_react8.useState)(null);
2980
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.Card, { gap: "$3", children: [
2981
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Heading, { level: 6, children: "FAQ" }),
2982
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.YStack, { gap: "$3", children: FAQ_ITEMS.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.YStack, { gap: "$3", children: [
2983
- index > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Separator, {}),
2984
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2985
- FaqItem,
2986
- {
2987
- question: item.question,
2988
- answer: item.answer,
2989
- expanded: expandedId === item.id,
2990
- onToggle: () => {
2991
- setExpandedId((current) => current === item.id ? null : item.id);
2992
- }
2993
- }
2994
- )
2995
- ] }, item.id)) })
2996
- ] });
2997
- }
2998
-
2999
3710
  // src/components/manage/CreditsManagementCard.tsx
3000
- var import_react9 = require("react");
3001
- var import_ui9 = require("@goodwidget/ui");
3711
+ var import_react7 = require("react");
3712
+ var import_ui8 = require("@goodwidget/ui");
3002
3713
 
3003
3714
  // src/components/shared/constants.ts
3004
- var BUYER_KEY_REQUIRED_CLOSE_TOOLTIP = "Sign with your payer wallet in Buyer & Operator below to generate the buyer private key before closing a channel.";
3005
- var BUYER_KEY_REQUIRED_WITHDRAW_TOOLTIP = "Sign with your payer wallet in Buyer & Operator below to generate the buyer private key before withdrawing funds.";
3715
+ var BUYER_KEY_REQUIRED_CLOSE_TOOLTIP = "Sign with your payer wallet in Signer Key below to generate the buyer private key before closing a channel.";
3716
+ var BUYER_KEY_REQUIRED_WITHDRAW_TOOLTIP = "Sign with your payer wallet in Signer Key below to generate the buyer private key before withdrawing funds.";
3006
3717
  var WITHDRAW_TOOLTIP = "Withdraws principal to your payer wallet (not bonus). Requires the buyer private key from this session.";
3007
3718
 
3008
3719
  // src/components/manage/CreditsManagementCard.tsx
3009
- var import_jsx_runtime7 = require("react/jsx-runtime");
3720
+ var import_jsx_runtime6 = require("react/jsx-runtime");
3010
3721
  function StatCell({ label, children }) {
3011
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
3012
- import_ui9.YStack,
3722
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
3723
+ import_ui8.YStack,
3013
3724
  {
3014
3725
  flex: 1,
3015
3726
  minWidth: "45%",
@@ -3021,8 +3732,8 @@ function StatCell({ label, children }) {
3021
3732
  minWidth: "28%"
3022
3733
  },
3023
3734
  children: [
3024
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", secondary: true, children: label }),
3025
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.YStack, { justifyContent: "center", children })
3735
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$1", secondary: true, children: label }),
3736
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.YStack, { justifyContent: "center", children })
3026
3737
  ]
3027
3738
  }
3028
3739
  );
@@ -3031,7 +3742,7 @@ function StatValueText({
3031
3742
  children,
3032
3743
  color
3033
3744
  }) {
3034
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$2", fontWeight: "700", color, children });
3745
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$2", fontWeight: "700", color, children });
3035
3746
  }
3036
3747
  function formatCompactAmount(amount) {
3037
3748
  const value = Number.parseFloat(amount);
@@ -3050,16 +3761,16 @@ function formatExactGAmount(amount) {
3050
3761
  }).format(value)} G$`;
3051
3762
  }
3052
3763
  function CompactGStatValue({ amount }) {
3053
- const [open, setOpen] = (0, import_react9.useState)(false);
3764
+ const [open, setOpen] = (0, import_react7.useState)(false);
3054
3765
  const value = Number.parseFloat(amount);
3055
3766
  const compact = formatCompactAmount(amount);
3056
3767
  const exact = formatExactGAmount(amount);
3057
3768
  const needsExact = Number.isFinite(value) && value >= 1e3;
3058
3769
  if (!needsExact) {
3059
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValueText, { children: compact });
3770
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StatValueText, { children: compact });
3060
3771
  }
3061
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
3062
- import_ui9.XStack,
3772
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
3773
+ import_ui8.XStack,
3063
3774
  {
3064
3775
  position: "relative",
3065
3776
  cursor: "help",
@@ -3072,9 +3783,9 @@ function CompactGStatValue({ amount }) {
3072
3783
  onBlur: () => setOpen(false),
3073
3784
  onPress: () => setOpen((prev) => !prev),
3074
3785
  children: [
3075
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValueText, { children: compact }),
3076
- open && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3077
- import_ui9.YStack,
3786
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StatValueText, { children: compact }),
3787
+ open && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3788
+ import_ui8.YStack,
3078
3789
  {
3079
3790
  position: "absolute",
3080
3791
  bottom: "100%",
@@ -3087,7 +3798,7 @@ function CompactGStatValue({ amount }) {
3087
3798
  padding: "$2",
3088
3799
  zIndex: 100,
3089
3800
  pointerEvents: "none",
3090
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", lineHeight: "$2", color: "$color", whiteSpace: "nowrap", children: exact })
3801
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$1", lineHeight: "$2", color: "$color", whiteSpace: "nowrap", children: exact })
3091
3802
  }
3092
3803
  )
3093
3804
  ]
@@ -3103,10 +3814,10 @@ function formatUsdAmount(usdMicro) {
3103
3814
  }).format(value);
3104
3815
  }
3105
3816
  function CreditsManagementCard({ state, actions }) {
3106
- const [isClosing, setIsClosing] = (0, import_react9.useState)(false);
3107
- const [isWithdrawing, setIsWithdrawing] = (0, import_react9.useState)(false);
3108
- const [channelId, setChannelId] = (0, import_react9.useState)("");
3109
- const [withdrawAmount, setWithdrawAmount] = (0, import_react9.useState)("");
3817
+ const [isClosing, setIsClosing] = (0, import_react7.useState)(false);
3818
+ const [isWithdrawing, setIsWithdrawing] = (0, import_react7.useState)(false);
3819
+ const [channelId, setChannelId] = (0, import_react7.useState)("");
3820
+ const [withdrawAmount, setWithdrawAmount] = (0, import_react7.useState)("");
3110
3821
  const {
3111
3822
  totalCreditUsd,
3112
3823
  totalGdDepositedG,
@@ -3116,7 +3827,7 @@ function CreditsManagementCard({ state, actions }) {
3116
3827
  withdrawableUsd,
3117
3828
  buyerPrvKey
3118
3829
  } = state;
3119
- const monthlyStreamUsdDisplay = (0, import_react9.useMemo)(() => {
3830
+ const monthlyStreamUsdDisplay = (0, import_react7.useMemo)(() => {
3120
3831
  if (!monthlyStreamG || !gdUsdPerToken) return null;
3121
3832
  if (Number.parseFloat(monthlyStreamG) <= 0) return null;
3122
3833
  const quote = { depositAmountG: "0", streamAmountG: monthlyStreamG };
@@ -3132,34 +3843,34 @@ function CreditsManagementCard({ state, actions }) {
3132
3843
  const hasWithdrawableBalance = withdrawableUsd !== null && BigInt(withdrawableUsd) > 0n;
3133
3844
  const canClose = Boolean(buyerPrvKey) && Boolean(channelId.trim()) && !isClosing;
3134
3845
  const canWithdraw = Boolean(buyerPrvKey) && hasWithdrawableBalance && Boolean(withdrawAmount.trim()) && !isWithdrawing;
3135
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Card, { gap: "$3", children: [
3136
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Heading, { level: 6, children: "AI Credits" }),
3137
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.XStack, { gap: "$4", width: "100%", alignItems: "flex-start", flexWrap: "wrap", children: [
3138
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$2", flex: 1, minWidth: 0, children: [
3139
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", secondary: true, children: "Total Credit (US$)" }),
3140
- totalCreditDisplay !== null ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Heading, { level: 5, children: totalCreditDisplay }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Spinner, { size: "sm" })
3846
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.Card, { gap: "$3", children: [
3847
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Heading, { level: 6, children: "AI Credits" }),
3848
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.XStack, { gap: "$4", width: "100%", alignItems: "flex-start", flexWrap: "wrap", children: [
3849
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.YStack, { gap: "$2", flex: 1, minWidth: 0, children: [
3850
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$1", secondary: true, children: "Total Credit (US$)" }),
3851
+ totalCreditDisplay !== null ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Heading, { level: 5, children: totalCreditDisplay }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Spinner, { size: "sm" })
3141
3852
  ] }),
3142
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$2", flex: 1, minWidth: 0, children: [
3143
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", secondary: true, children: "Est. Monthly Credit (US$)" }),
3144
- monthlyStreamUsdDisplay ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Heading, { level: 5, color: "$primary", children: [
3853
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.YStack, { gap: "$2", flex: 1, minWidth: 0, children: [
3854
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$1", secondary: true, children: "Est. Monthly Credit (US$)" }),
3855
+ monthlyStreamUsdDisplay ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.Heading, { level: 5, color: "$primary", children: [
3145
3856
  "~",
3146
3857
  monthlyStreamUsdDisplay
3147
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Heading, { level: 5, children: "\u2014" })
3858
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Heading, { level: 5, children: "\u2014" })
3148
3859
  ] })
3149
3860
  ] }),
3150
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.XStack, { gap: "$2", width: "100%", flexWrap: "wrap", alignItems: "stretch", children: [
3151
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Total Deposited (G$)", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CompactGStatValue, { amount: totalGdDepositedG ?? "0.00" }) }),
3152
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Monthly Stream (G$)", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CompactGStatValue, { amount: monthlyStreamG ?? "0.00" }) }),
3153
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Withdrawable (US$)", children: withdrawableDisplay !== null ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValueText, { children: withdrawableDisplay }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Spinner, { size: "sm" }) })
3861
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.XStack, { gap: "$2", width: "100%", flexWrap: "wrap", alignItems: "stretch", children: [
3862
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StatCell, { label: "Total Deposited (G$)", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CompactGStatValue, { amount: totalGdDepositedG ?? "0.00" }) }),
3863
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StatCell, { label: "Monthly Stream (G$)", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CompactGStatValue, { amount: monthlyStreamG ?? "0.00" }) }),
3864
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StatCell, { label: "Withdrawable (US$)", children: withdrawableDisplay !== null ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StatValueText, { children: withdrawableDisplay }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Spinner, { size: "sm" }) })
3154
3865
  ] }),
3155
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$1", children: [
3156
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.XStack, { gap: "$1", alignItems: "center", children: [
3157
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", variant: "label", children: "Withdraw" }),
3158
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(InfoTooltip, { message: WITHDRAW_TOOLTIP })
3866
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.YStack, { gap: "$1", children: [
3867
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.XStack, { gap: "$1", alignItems: "center", children: [
3868
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$1", variant: "label", children: "Withdraw" }),
3869
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(InfoTooltip, { message: WITHDRAW_TOOLTIP })
3159
3870
  ] }),
3160
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.XStack, { gap: "$2", alignItems: "center", children: [
3161
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.YStack, { flex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3162
- import_ui9.Input,
3871
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.XStack, { gap: "$2", alignItems: "center", children: [
3872
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.YStack, { flex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3873
+ import_ui8.Input,
3163
3874
  {
3164
3875
  size: "sm",
3165
3876
  value: withdrawAmount,
@@ -3167,8 +3878,8 @@ function CreditsManagementCard({ state, actions }) {
3167
3878
  placeholder: hasWithdrawableBalance && withdrawableDisplay ? `Max ${withdrawableDisplay} US$` : "Amount in US$"
3168
3879
  }
3169
3880
  ) }),
3170
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HoverTooltip, { message: !buyerPrvKey ? BUYER_KEY_REQUIRED_WITHDRAW_TOOLTIP : null, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3171
- import_ui9.Button,
3881
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(HoverTooltip, { message: !buyerPrvKey ? BUYER_KEY_REQUIRED_WITHDRAW_TOOLTIP : null, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3882
+ import_ui8.Button,
3172
3883
  {
3173
3884
  variant: "outline",
3174
3885
  size: "sm",
@@ -3183,16 +3894,16 @@ function CreditsManagementCard({ state, actions }) {
3183
3894
  setWithdrawAmount("");
3184
3895
  });
3185
3896
  },
3186
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: isWithdrawing ? "Withdrawing\u2026" : "Withdraw" })
3897
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.ButtonText, { children: isWithdrawing ? "Withdrawing\u2026" : "Withdraw" })
3187
3898
  }
3188
3899
  ) })
3189
3900
  ] })
3190
3901
  ] }),
3191
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$1", children: [
3192
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", variant: "label", children: "Close Channel" }),
3193
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.XStack, { gap: "$2", alignItems: "center", children: [
3194
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.YStack, { flex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3195
- import_ui9.Input,
3902
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.YStack, { gap: "$1", children: [
3903
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$1", variant: "label", children: "Close Channel" }),
3904
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.XStack, { gap: "$2", alignItems: "center", children: [
3905
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.YStack, { flex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3906
+ import_ui8.Input,
3196
3907
  {
3197
3908
  size: "sm",
3198
3909
  value: channelId,
@@ -3200,8 +3911,8 @@ function CreditsManagementCard({ state, actions }) {
3200
3911
  placeholder: "0x\u2026 (64 hex chars)"
3201
3912
  }
3202
3913
  ) }),
3203
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HoverTooltip, { message: !buyerPrvKey ? BUYER_KEY_REQUIRED_CLOSE_TOOLTIP : null, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3204
- import_ui9.Button,
3914
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(HoverTooltip, { message: !buyerPrvKey ? BUYER_KEY_REQUIRED_CLOSE_TOOLTIP : null, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3915
+ import_ui8.Button,
3205
3916
  {
3206
3917
  variant: "outline",
3207
3918
  size: "sm",
@@ -3216,7 +3927,7 @@ function CreditsManagementCard({ state, actions }) {
3216
3927
  setChannelId("");
3217
3928
  });
3218
3929
  },
3219
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: isClosing ? "Closing\u2026" : "Close" })
3930
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.ButtonText, { children: isClosing ? "Closing\u2026" : "Close" })
3220
3931
  }
3221
3932
  ) })
3222
3933
  ] })
@@ -3225,140 +3936,400 @@ function CreditsManagementCard({ state, actions }) {
3225
3936
  }
3226
3937
 
3227
3938
  // src/components/manage/BuyerOperatorCard.tsx
3228
- var import_react10 = require("react");
3229
- var import_ui11 = require("@goodwidget/ui");
3230
-
3231
- // src/components/shared/AddressView.tsx
3939
+ var import_react9 = require("react");
3232
3940
  var import_ui10 = require("@goodwidget/ui");
3233
- var import_jsx_runtime8 = require("react/jsx-runtime");
3234
- function AddressView({ label, address }) {
3235
- const { copied, copy } = useCopyFeedback();
3236
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$1", children: [
3237
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: "$1", secondary: true, children: label }),
3238
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
3239
- import_ui10.XStack,
3240
- {
3241
- backgroundColor: "$backgroundMuted",
3242
- borderRadius: "$2",
3243
- padding: "$2",
3244
- justifyContent: "space-between",
3245
- alignItems: "center",
3246
- children: [
3247
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3248
- import_ui10.Text,
3249
- {
3250
- fontSize: "$2",
3251
- fontFamily: "$mono",
3252
- flex: 1,
3253
- numberOfLines: 1,
3254
- style: monospaceSingleLineStyle,
3255
- children: truncateAddress(address)
3256
- }
3257
- ),
3258
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Button, { size: "sm", variant: "ghost", iconSize: "sm", onPress: () => void copy(address), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Icon, { name: copied ? "check" : "copy", size: "xs", color: copied ? "success" : "text" }) })
3259
- ]
3260
- }
3261
- )
3262
- ] });
3263
- }
3264
3941
 
3265
- // src/components/manage/BuyerOperatorCard.tsx
3266
- var import_jsx_runtime9 = require("react/jsx-runtime");
3267
- function BuyerOperatorCard({ state, actions }) {
3268
- const { address, buyerPubKey, buyerPrvKey, operatorConsented } = state;
3269
- const { copied: copiedPrivate, copy: copyPrivate } = useCopyFeedback();
3270
- const [isPrivateKeyVisible, setIsPrivateKeyVisible] = (0, import_react10.useState)(false);
3271
- const [isGenerating, setIsGenerating] = (0, import_react10.useState)(false);
3272
- const [isSigning, setIsSigning] = (0, import_react10.useState)(false);
3273
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.Card, { gap: "$2", children: [
3274
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Heading, { level: 6, children: "Buyer & Operator" }),
3275
- address && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AddressView, { label: "Payer", address }),
3276
- buyerPubKey && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AddressView, { label: "Buyer", address: buyerPubKey }),
3277
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.XStack, { gap: "$2", alignItems: "stretch", width: "100%", children: [
3278
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3279
- import_ui11.Button,
3942
+ // src/components/setup/SignerKeyPanel.tsx
3943
+ var import_react8 = require("react");
3944
+ var import_ui9 = require("@goodwidget/ui");
3945
+ var import_jsx_runtime7 = require("react/jsx-runtime");
3946
+ var ZERO_OPERATOR = "0x0000000000000000000000000000000000000000";
3947
+ function SignerKeyPanel({
3948
+ state,
3949
+ actions,
3950
+ onProceed,
3951
+ showHeading = true,
3952
+ proceedLabel: proceedLabelOverride,
3953
+ compact = false
3954
+ }) {
3955
+ const [choice, setChoice] = (0, import_react8.useState)(null);
3956
+ const [privateKey, setPrivateKey] = (0, import_react8.useState)("");
3957
+ const [isImporting, setIsImporting] = (0, import_react8.useState)(false);
3958
+ const [keyConfirmed, setKeyConfirmed] = (0, import_react8.useState)(false);
3959
+ const [importedAddress, setImportedAddress] = (0, import_react8.useState)(null);
3960
+ const leaveChoice = () => {
3961
+ setChoice(null);
3962
+ setImportedAddress(null);
3963
+ };
3964
+ const currentOperator = state.currentOperator?.toLowerCase();
3965
+ const expectedOperator = state.operatorAddress?.toLowerCase();
3966
+ const proceedLabel = proceedLabelOverride ?? (state.operatorConsented ? "Done" : "Continue to Authorize Wallet");
3967
+ const hasDifferentOperator = Boolean(currentOperator) && currentOperator !== ZERO_OPERATOR && Boolean(expectedOperator) && currentOperator !== expectedOperator;
3968
+ if (choice === "generate") {
3969
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$3", children: [
3970
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Button, { variant: "text", alignSelf: "flex-start", onPress: leaveChoice, children: [
3971
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Icon, { name: "arrow-left", size: "xs", color: "primary" }),
3972
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: "Back to Generate / Import" })
3973
+ ] }),
3974
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3975
+ BuyerKeyPanel,
3976
+ {
3977
+ embedded: true,
3978
+ buyerPubKey: state.buyerPubKey,
3979
+ buyerPrvKey: state.buyerPrvKey,
3980
+ buyerPubKeySaved: keyConfirmed,
3981
+ onGenerate: actions.generateBuyerKey,
3982
+ onConfirm: () => setKeyConfirmed(true)
3983
+ }
3984
+ ),
3985
+ keyConfirmed && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Button, { size: "sm", ...compactButtonProps, onPress: onProceed, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: proceedLabel }) })
3986
+ ] });
3987
+ }
3988
+ if (choice === "import") {
3989
+ const importedSigner = !isImporting && Boolean(importedAddress) && state.buyerPubKey?.toLowerCase() === importedAddress?.toLowerCase();
3990
+ const importedSignerBlocked = importedSigner && hasDifferentOperator;
3991
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$3", children: [
3992
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Button, { variant: "text", alignSelf: "flex-start", onPress: leaveChoice, children: [
3993
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Icon, { name: "arrow-left", size: "xs", color: "primary" }),
3994
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: "Back to Generate / Import" })
3995
+ ] }),
3996
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Heading, { level: 5, children: "Import Signer Key" }),
3997
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { secondary: true, children: "Paste the private key from AntSeed. It will be checked against the operator configured for this signer before you can continue." }),
3998
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3999
+ import_ui9.Input,
3280
4000
  {
3281
- flex: 1,
3282
- flexBasis: 0,
3283
- minWidth: 0,
3284
4001
  size: "sm",
3285
- ...compactButtonProps,
3286
- onPress: () => {
3287
- setIsGenerating(true);
3288
- void Promise.resolve(actions.generateBuyerKey()).finally(() => setIsGenerating(false));
3289
- },
3290
- disabled: isGenerating,
3291
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.ButtonText, { children: isGenerating ? "Signing\u2026" : "Sign & Generate" })
4002
+ value: privateKey,
4003
+ onChangeText: setPrivateKey,
4004
+ placeholder: "0x\u2026",
4005
+ autoCapitalize: "none"
3292
4006
  }
3293
4007
  ),
3294
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3295
- import_ui11.Button,
4008
+ state.error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { color: "$error", children: state.error }),
4009
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4010
+ import_ui9.Button,
3296
4011
  {
3297
- flex: 1,
3298
- flexBasis: 0,
3299
- minWidth: 0,
3300
4012
  size: "sm",
3301
4013
  ...compactButtonProps,
4014
+ disabled: !privateKey.trim() || isImporting,
3302
4015
  onPress: () => {
3303
- setIsSigning(true);
3304
- void Promise.resolve(actions.signOperatorConsent()).finally(() => setIsSigning(false));
4016
+ setIsImporting(true);
4017
+ setImportedAddress(null);
4018
+ void actions.importBuyerFromPrivateKey(privateKey.trim()).then((buyerAddress) => setImportedAddress(buyerAddress)).catch(() => setImportedAddress(null)).finally(() => setIsImporting(false));
3305
4019
  },
3306
- disabled: operatorConsented || isSigning || !buyerPrvKey,
3307
- children: isSigning ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Spinner, { size: "sm" }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.ButtonText, { children: operatorConsented ? "Consented" : "Sign Consent" })
4020
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: isImporting ? "Checking signer\u2026" : "Import Signer Key" })
3308
4021
  }
3309
- )
3310
- ] }),
3311
- buyerPrvKey && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.YStack, { gap: "$2", children: [
3312
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.XStack, { justifyContent: "space-between", alignItems: "center", children: [
3313
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Text, { fontSize: "$1", secondary: true, children: "Buyer Private Key" }),
3314
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3315
- import_ui11.Button,
3316
- {
3317
- variant: "text",
3318
- size: "sm",
3319
- onPress: () => setIsPrivateKeyVisible((prev) => !prev),
3320
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.ButtonText, { children: isPrivateKeyVisible ? "Hide" : "Reveal" })
3321
- }
3322
- )
3323
- ] }),
3324
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
3325
- import_ui11.XStack,
3326
- {
3327
- backgroundColor: "$backgroundMuted",
3328
- borderRadius: "$2",
3329
- padding: "$2",
3330
- justifyContent: "space-between",
3331
- alignItems: "center",
3332
- children: [
3333
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Text, { fontSize: "$2", style: monospaceSingleLineStyle, flex: 1, numberOfLines: 1, children: isPrivateKeyVisible ? buyerPrvKey : "\u2022".repeat(Math.min(48, buyerPrvKey.length)) }),
3334
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3335
- import_ui11.Button,
3336
- {
3337
- size: "sm",
3338
- variant: "ghost",
3339
- iconSize: "sm",
3340
- onPress: () => void copyPrivate(buyerPrvKey),
3341
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3342
- import_ui11.Icon,
3343
- {
3344
- name: copiedPrivate ? "check" : "copy",
3345
- size: "xs",
3346
- color: copiedPrivate ? "success" : "text"
3347
- }
3348
- )
3349
- }
3350
- )
3351
- ]
3352
- }
3353
- )
4022
+ ),
4023
+ importedSignerBlocked ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$2", children: [
4024
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { color: "$error", fontWeight: "700", children: "Signer key cannot be used" }),
4025
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { secondary: true, children: "The imported signer key already has another operator configured. Paste a different signer key, or go back and generate a new one." })
4026
+ ] }) : importedSigner ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$2", children: [
4027
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { color: "$success", fontWeight: "700", children: "Signer imported" }),
4028
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Text, { secondary: true, children: [
4029
+ truncateAddress(state.buyerPubKey ?? ""),
4030
+ " is now your active signer."
4031
+ ] }),
4032
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { secondary: true, children: state.operatorConsented ? "GoodDollar is already configured as the operator." : currentOperator === ZERO_OPERATOR ? "No operator is configured yet. Continue to authorize GoodDollar." : "The configured operator is being checked." }),
4033
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Button, { size: "sm", ...compactButtonProps, onPress: onProceed, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: proceedLabel }) })
4034
+ ] }) : null
4035
+ ] });
4036
+ }
4037
+ const choices = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
4038
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
4039
+ import_ui9.Button,
4040
+ {
4041
+ flex: compact ? void 0 : 1,
4042
+ alignSelf: compact ? "stretch" : void 0,
4043
+ size: compact ? "sm" : "lg",
4044
+ variant: "outline",
4045
+ ...compactButtonProps,
4046
+ onPress: () => setChoice("generate"),
4047
+ children: [
4048
+ !compact && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Badge, { type: "success", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.BadgeText, { children: "Recommended" }) }),
4049
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: "Generate Signer Key" })
4050
+ ]
4051
+ }
4052
+ ),
4053
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4054
+ import_ui9.Button,
4055
+ {
4056
+ flex: compact ? void 0 : 1,
4057
+ alignSelf: compact ? "stretch" : void 0,
4058
+ size: compact ? "sm" : "lg",
4059
+ variant: "outline",
4060
+ ...compactButtonProps,
4061
+ onPress: () => setChoice("import"),
4062
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: "Import Signer Key" })
4063
+ }
4064
+ )
4065
+ ] });
4066
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$3", children: [
4067
+ showHeading && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Heading, { level: 5, children: "Signer Key" }),
4068
+ !compact && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { secondary: true, children: "A dedicated identity used only to buy and spend AI credits \u2014 separate from your wallet." }),
4069
+ compact ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.YStack, { gap: "$2", children: choices }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.XStack, { gap: "$3", children: choices }),
4070
+ !compact && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$2", secondary: true, children: "Generate is recommended for a fresh signer. Either direction uses the same key once it is set up in AntSeed." })
4071
+ ] });
4072
+ }
4073
+
4074
+ // src/components/manage/BuyerOperatorCard.tsx
4075
+ var import_jsx_runtime8 = require("react/jsx-runtime");
4076
+ function shortAddress(address) {
4077
+ return `${address.slice(0, 6)}\u2026${address.slice(-4)}`;
4078
+ }
4079
+ function DisclosureToggle({
4080
+ open,
4081
+ label,
4082
+ onPress
4083
+ }) {
4084
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4085
+ import_ui10.Button,
4086
+ {
4087
+ variant: "text",
4088
+ size: "sm",
4089
+ alignSelf: "flex-start",
4090
+ gap: "$1.5",
4091
+ ...compactButtonProps,
4092
+ paddingHorizontal: "$0",
4093
+ "aria-expanded": open,
4094
+ onPress,
4095
+ children: [
4096
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Icon, { name: open ? "chevron-up" : "chevron-down", size: "xs", color: "primary" }),
4097
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.ButtonText, { children: label })
4098
+ ]
4099
+ }
4100
+ );
4101
+ }
4102
+ function CopyableValue({ value, display }) {
4103
+ const { copied, copy } = useCopyFeedback();
4104
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4105
+ import_ui10.XStack,
4106
+ {
4107
+ backgroundColor: "$backgroundMuted",
4108
+ borderRadius: "$2",
4109
+ padding: "$2",
4110
+ justifyContent: "space-between",
4111
+ alignItems: "center",
4112
+ gap: "$2",
4113
+ children: [
4114
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: "$2", flex: 1, numberOfLines: 1, style: monospaceSingleLineStyle, children: display ?? value }),
4115
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Button, { size: "sm", variant: "ghost", iconSize: "sm", onPress: () => void copy(value), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Icon, { name: copied ? "check" : "copy", size: "xs", color: copied ? "success" : "text" }) })
4116
+ ]
4117
+ }
4118
+ );
4119
+ }
4120
+ function SignerStatus({
4121
+ consented,
4122
+ size = "$1"
4123
+ }) {
4124
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.XStack, { gap: "$1", alignItems: "center", children: [
4125
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4126
+ import_ui10.Icon,
4127
+ {
4128
+ name: consented ? "check" : "alert-triangle",
4129
+ size: "2xs",
4130
+ color: consented ? "success" : "warning"
4131
+ }
4132
+ ),
4133
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: size, color: consented ? "$success" : "$warning", children: consented ? "Authorized" : "Not authorized" })
4134
+ ] });
4135
+ }
4136
+ function BuyerSelector({
4137
+ buyers,
4138
+ activeBuyerAddress,
4139
+ onSelect
4140
+ }) {
4141
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.YStack, { gap: "$1", children: buyers.map((buyer) => {
4142
+ const isActive = buyer.toLowerCase() === activeBuyerAddress?.toLowerCase();
4143
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4144
+ import_ui10.XStack,
4145
+ {
4146
+ tag: "button",
4147
+ role: "option",
4148
+ "aria-selected": isActive,
4149
+ alignItems: "center",
4150
+ justifyContent: "space-between",
4151
+ gap: "$2",
4152
+ paddingHorizontal: "$2",
4153
+ paddingVertical: "$1.5",
4154
+ borderRadius: "$2",
4155
+ borderWidth: 1,
4156
+ borderColor: isActive ? "$primary" : "$borderColor",
4157
+ backgroundColor: isActive ? "$infoMuted" : "$backgroundDark",
4158
+ cursor: isActive ? "default" : "pointer",
4159
+ hoverStyle: isActive ? {} : { backgroundColor: "$backgroundPress" },
4160
+ onPress: () => {
4161
+ if (!isActive) void onSelect(buyer);
4162
+ },
4163
+ children: [
4164
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4165
+ import_ui10.Text,
4166
+ {
4167
+ fontSize: "$2",
4168
+ fontWeight: isActive ? "700" : "500",
4169
+ color: isActive ? "$primary" : "$color",
4170
+ numberOfLines: 1,
4171
+ flex: 1,
4172
+ style: monospaceSingleLineStyle,
4173
+ children: shortAddress(buyer)
4174
+ }
4175
+ ),
4176
+ isActive ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.XStack, { gap: "$1", alignItems: "center", children: [
4177
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: "$1", color: "$primary", children: "active" }),
4178
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Icon, { name: "check", size: "xs", color: "primary" })
4179
+ ] }) : null
4180
+ ]
4181
+ },
4182
+ buyer
4183
+ );
4184
+ }) });
4185
+ }
4186
+ function BuyerOperatorCard({ state, actions }) {
4187
+ const {
4188
+ buyerPubKey,
4189
+ buyerPrvKey,
4190
+ operatorSignature,
4191
+ operatorConsented,
4192
+ operatorConsentPending,
4193
+ buyers
4194
+ } = state;
4195
+ const [isExpanded, setIsExpanded] = (0, import_react9.useState)(false);
4196
+ const [showSwitcher, setShowSwitcher] = (0, import_react9.useState)(false);
4197
+ const [showReplacePanel, setShowReplacePanel] = (0, import_react9.useState)(false);
4198
+ const [showPrivateKey, setShowPrivateKey] = (0, import_react9.useState)(false);
4199
+ const [panelInstance, setPanelInstance] = (0, import_react9.useState)(0);
4200
+ const buyerCanSign = Boolean(buyerPrvKey || operatorSignature);
4201
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.Card, { gap: "$3", "data-testid": "signer-key-card", children: [
4202
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4203
+ import_ui10.XStack,
4204
+ {
4205
+ tag: "button",
4206
+ "data-testid": "signer-key-toggle",
4207
+ alignItems: "center",
4208
+ justifyContent: "space-between",
4209
+ gap: "$2",
4210
+ width: "100%",
4211
+ backgroundColor: "transparent",
4212
+ borderWidth: 0,
4213
+ paddingHorizontal: "$0",
4214
+ paddingVertical: "$0",
4215
+ cursor: "pointer",
4216
+ "aria-expanded": isExpanded,
4217
+ onPress: () => setIsExpanded((prev) => !prev),
4218
+ children: [
4219
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$1", flex: 1, minWidth: 0, alignItems: "flex-start", children: [
4220
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Heading, { level: 6, children: "Signer Key" }),
4221
+ buyerPubKey ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.XStack, { alignItems: "center", flexWrap: "wrap", children: [
4222
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: "$1", secondary: true, style: monospaceSingleLineStyle, children: `${truncateAddress(buyerPubKey)} \xB7 ` }),
4223
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SignerStatus, { consented: operatorConsented })
4224
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: "$1", secondary: true, children: "No signer key yet" })
4225
+ ] }),
4226
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Icon, { name: isExpanded ? "chevron-up" : "chevron-down", size: "sm", color: "muted" })
4227
+ ]
4228
+ }
4229
+ ),
4230
+ isExpanded && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$4", children: [
4231
+ buyerPubKey && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$2", children: [
4232
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { variant: "label", secondary: true, children: "Active signer" }),
4233
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4234
+ import_ui10.YStack,
4235
+ {
4236
+ backgroundColor: "$backgroundDark",
4237
+ borderRadius: "$2",
4238
+ borderWidth: 1,
4239
+ borderColor: "$borderColor",
4240
+ padding: "$2",
4241
+ gap: "$2",
4242
+ children: [
4243
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CopyableValue, { value: buyerPubKey, display: truncateAddress(buyerPubKey) }),
4244
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SignerStatus, { consented: operatorConsented, size: "$2" }),
4245
+ !operatorConsented && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4246
+ import_ui10.Button,
4247
+ {
4248
+ size: "sm",
4249
+ ...compactButtonProps,
4250
+ disabled: operatorConsentPending || !buyerCanSign,
4251
+ onPress: () => {
4252
+ void Promise.resolve(actions.signOperatorConsent());
4253
+ },
4254
+ children: operatorConsentPending ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Spinner, { size: "sm" }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.ButtonText, { children: "Authorize GoodDollar" })
4255
+ }
4256
+ )
4257
+ ]
4258
+ }
4259
+ )
4260
+ ] }),
4261
+ buyers.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$2", children: [
4262
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4263
+ DisclosureToggle,
4264
+ {
4265
+ open: showSwitcher,
4266
+ label: `Switch signer (${buyers.length})`,
4267
+ onPress: () => setShowSwitcher((prev) => !prev)
4268
+ }
4269
+ ),
4270
+ showSwitcher && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4271
+ BuyerSelector,
4272
+ {
4273
+ buyers,
4274
+ activeBuyerAddress: buyerPubKey,
4275
+ onSelect: actions.selectBuyer
4276
+ }
4277
+ )
4278
+ ] }),
4279
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$2", children: [
4280
+ buyerPubKey ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4281
+ DisclosureToggle,
4282
+ {
4283
+ open: showReplacePanel,
4284
+ label: "Replace signer key",
4285
+ onPress: () => setShowReplacePanel((prev) => !prev)
4286
+ }
4287
+ ) : null,
4288
+ (showReplacePanel || !buyerPubKey) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4289
+ SignerKeyPanel,
4290
+ {
4291
+ state,
4292
+ actions,
4293
+ showHeading: false,
4294
+ compact: Boolean(buyerPubKey),
4295
+ proceedLabel: "Done",
4296
+ onProceed: () => setPanelInstance((prev) => prev + 1)
4297
+ },
4298
+ panelInstance
4299
+ )
4300
+ ] }),
4301
+ buyerPrvKey && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$2", children: [
4302
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.XStack, { justifyContent: "space-between", alignItems: "center", gap: "$2", children: [
4303
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { variant: "label", secondary: true, children: "Private key" }),
4304
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4305
+ import_ui10.Button,
4306
+ {
4307
+ variant: "text",
4308
+ size: "sm",
4309
+ ...compactButtonProps,
4310
+ paddingHorizontal: "$0",
4311
+ onPress: () => setShowPrivateKey((prev) => !prev),
4312
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.ButtonText, { children: showPrivateKey ? "Hide" : "Reveal" })
4313
+ }
4314
+ )
4315
+ ] }),
4316
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4317
+ CopyableValue,
4318
+ {
4319
+ value: buyerPrvKey,
4320
+ display: showPrivateKey ? buyerPrvKey : "\u2022".repeat(Math.min(48, buyerPrvKey.length))
4321
+ }
4322
+ ),
4323
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: "$1", color: "$warning", children: "Treat this like a password \u2014 anyone who has it can spend your credits." })
4324
+ ] })
3354
4325
  ] })
3355
4326
  ] });
3356
4327
  }
3357
4328
 
3358
4329
  // src/components/manage/SetupSnippet.tsx
3359
- var import_react11 = require("react");
3360
- var import_ui12 = require("@goodwidget/ui");
3361
- var import_jsx_runtime10 = require("react/jsx-runtime");
4330
+ var import_react10 = require("react");
4331
+ var import_ui11 = require("@goodwidget/ui");
4332
+ var import_jsx_runtime9 = require("react/jsx-runtime");
3362
4333
  var ANTSEED_API_DOCS_URL = "https://antseed.com/docs/guides/using-the-api";
3363
4334
  var setupSnippetLineStyle = {
3364
4335
  fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",
@@ -3379,21 +4350,21 @@ function buildSetupSnippet() {
3379
4350
  ].join("\n");
3380
4351
  }
3381
4352
  function SetupSnippet() {
3382
- const [expanded, setExpanded] = (0, import_react11.useState)(false);
3383
- const [copied, setCopied] = (0, import_react11.useState)(false);
4353
+ const [expanded, setExpanded] = (0, import_react10.useState)(false);
4354
+ const [copied, setCopied] = (0, import_react10.useState)(false);
3384
4355
  const snippet = buildSetupSnippet();
3385
4356
  const copyText = snippet.replace(/\n\n+/g, "\n").trim();
3386
4357
  const lines = snippet.trim().split("\n");
3387
4358
  async function handleCopy() {
3388
- const copied2 = await (0, import_ui12.copyTextToClipboard)(copyText);
4359
+ const copied2 = await (0, import_ui11.copyTextToClipboard)(copyText);
3389
4360
  if (!copied2) return;
3390
4361
  setCopied(true);
3391
4362
  setTimeout(() => setCopied(false), 2e3);
3392
4363
  }
3393
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.Card, { gap: "$2", children: [
3394
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.XStack, { justifyContent: "space-between", alignItems: "center", children: [
3395
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
3396
- import_ui12.XStack,
4364
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.Card, { gap: "$2", children: [
4365
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.XStack, { justifyContent: "space-between", alignItems: "center", children: [
4366
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
4367
+ import_ui11.XStack,
3397
4368
  {
3398
4369
  flex: 1,
3399
4370
  justifyContent: "space-between",
@@ -3401,29 +4372,29 @@ function SetupSnippet() {
3401
4372
  onPress: () => setExpanded((value) => !value),
3402
4373
  cursor: "pointer",
3403
4374
  children: [
3404
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$3", fontWeight: "600", children: "API Setup" }),
3405
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Icon, { name: expanded ? "chevron-up" : "chevron-right", size: "xs", color: "muted" })
4375
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Text, { fontSize: "$3", fontWeight: "600", children: "API Setup" }),
4376
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Icon, { name: expanded ? "chevron-up" : "chevron-right", size: "xs", color: "muted" })
3406
4377
  ]
3407
4378
  }
3408
4379
  ),
3409
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Button, { size: "sm", variant: "ghost", iconSize: "sm", onPress: handleCopy, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Icon, { name: copied ? "check" : "copy", size: "xs", color: copied ? "success" : "text" }) })
4380
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Button, { size: "sm", variant: "ghost", iconSize: "sm", onPress: handleCopy, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Icon, { name: copied ? "check" : "copy", size: "xs", color: copied ? "success" : "text" }) })
3410
4381
  ] }),
3411
- expanded && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { gap: "$2", children: [
3412
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3413
- import_ui12.YStack,
4382
+ expanded && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.YStack, { gap: "$2", children: [
4383
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4384
+ import_ui11.YStack,
3414
4385
  {
3415
4386
  backgroundColor: "$backgroundMuted",
3416
4387
  borderRadius: "$2",
3417
4388
  padding: "$3",
3418
4389
  width: "100%",
3419
4390
  gap: "$1",
3420
- children: lines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { color: "$text", style: setupSnippetLineStyle, children: line.length > 0 ? line : " " }, index))
4391
+ children: lines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Text, { color: "$text", style: setupSnippetLineStyle, children: line.length > 0 ? line : " " }, index))
3421
4392
  }
3422
4393
  ),
3423
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.Text, { fontSize: "$1", secondary: true, children: [
4394
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.Text, { fontSize: "$1", secondary: true, children: [
3424
4395
  "To connect AI tools to the AntSeed AI provider, see the",
3425
4396
  " ",
3426
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Anchor, { href: ANTSEED_API_DOCS_URL, target: "_blank", children: "AntSeed API guide" }),
4397
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Anchor, { href: ANTSEED_API_DOCS_URL, target: "_blank", children: "AntSeed API guide" }),
3427
4398
  "."
3428
4399
  ] })
3429
4400
  ] })
@@ -3431,9 +4402,9 @@ function SetupSnippet() {
3431
4402
  }
3432
4403
 
3433
4404
  // src/components/history/HistoryTab.tsx
3434
- var import_react12 = require("react");
3435
- var import_ui13 = require("@goodwidget/ui");
3436
- var import_jsx_runtime11 = require("react/jsx-runtime");
4405
+ var import_react11 = require("react");
4406
+ var import_ui12 = require("@goodwidget/ui");
4407
+ var import_jsx_runtime10 = require("react/jsx-runtime");
3437
4408
  var STATUS_OPTIONS = [
3438
4409
  { label: "All", value: "all" },
3439
4410
  { label: "Funded", value: "funded" },
@@ -3505,10 +4476,10 @@ function entryDetailRows(entry) {
3505
4476
  return rows;
3506
4477
  }
3507
4478
  function EntryDetailRow({ label, value }) {
3508
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.XStack, { gap: "$2", alignItems: "flex-start", width: "100%", children: [
3509
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$1", fontWeight: "600", secondary: true, minWidth: 72, flexShrink: 0, children: label }),
3510
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3511
- import_ui13.Text,
4479
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.XStack, { gap: "$2", alignItems: "flex-start", width: "100%", children: [
4480
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$1", fontWeight: "600", secondary: true, minWidth: 72, flexShrink: 0, children: label }),
4481
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4482
+ import_ui12.Text,
3512
4483
  {
3513
4484
  fontSize: "$1",
3514
4485
  flex: 1,
@@ -3628,9 +4599,9 @@ function CreditHistoryEntryRow({
3628
4599
  const amounts = amountLines(entry);
3629
4600
  const detailRows = entryDetailRows(entry);
3630
4601
  const titleColor = entry.fundingStatus === "failed" ? "$error" : "$color";
3631
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Card, { gap: "$2", children: [
3632
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3633
- import_ui13.XStack,
4602
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.Card, { gap: "$2", children: [
4603
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
4604
+ import_ui12.XStack,
3634
4605
  {
3635
4606
  alignItems: "center",
3636
4607
  gap: "$3",
@@ -3638,8 +4609,8 @@ function CreditHistoryEntryRow({
3638
4609
  cursor: "pointer",
3639
4610
  onPress: onToggle,
3640
4611
  children: [
3641
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3642
- import_ui13.YStack,
4612
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4613
+ import_ui12.YStack,
3643
4614
  {
3644
4615
  width: 40,
3645
4616
  height: 40,
@@ -3648,8 +4619,8 @@ function CreditHistoryEntryRow({
3648
4619
  justifyContent: "center",
3649
4620
  backgroundColor: entryIconBackground(entry),
3650
4621
  flexShrink: 0,
3651
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3652
- import_ui13.Icon,
4622
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4623
+ import_ui12.Icon,
3653
4624
  {
3654
4625
  name: entryIconName(entry),
3655
4626
  size: "sm",
@@ -3658,11 +4629,11 @@ function CreditHistoryEntryRow({
3658
4629
  )
3659
4630
  }
3660
4631
  ),
3661
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { flex: 1, gap: "$0.5", minWidth: 0, children: [
3662
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$3", fontWeight: "700", color: titleColor, children: sourceLabel(entry.source) }),
3663
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.XStack, { alignItems: "center", gap: "$1", children: [
3664
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3665
- import_ui13.YStack,
4632
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { flex: 1, gap: "$0.5", minWidth: 0, children: [
4633
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$3", fontWeight: "700", color: titleColor, children: sourceLabel(entry.source) }),
4634
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.XStack, { alignItems: "center", gap: "$1", children: [
4635
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4636
+ import_ui12.YStack,
3666
4637
  {
3667
4638
  width: 6,
3668
4639
  height: 6,
@@ -3670,18 +4641,18 @@ function CreditHistoryEntryRow({
3670
4641
  backgroundColor: accent
3671
4642
  }
3672
4643
  ),
3673
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$1", fontWeight: "600", color: accent, letterSpacing: 0.4, children: statusLabel(entry.fundingStatus) })
4644
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$1", fontWeight: "600", color: accent, letterSpacing: 0.4, children: statusLabel(entry.fundingStatus) })
3674
4645
  ] })
3675
4646
  ] }),
3676
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { alignItems: "flex-end", gap: "$0.5", flexShrink: 0, children: [
3677
- amounts?.primary ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$3", fontWeight: "700", color: amountColor, children: amounts.primary }) : null,
3678
- amounts?.secondary ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", fontWeight: "600", color: amountColor, children: amounts.secondary }) : null,
3679
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$1", secondary: true, children: formatEntryDate(entry.createdAt) })
4647
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { alignItems: "flex-end", gap: "$0.5", flexShrink: 0, children: [
4648
+ amounts?.primary ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$3", fontWeight: "700", color: amountColor, children: amounts.primary }) : null,
4649
+ amounts?.secondary ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$2", fontWeight: "600", color: amountColor, children: amounts.secondary }) : null,
4650
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$1", secondary: true, children: formatEntryDate(entry.createdAt) })
3680
4651
  ] })
3681
4652
  ]
3682
4653
  }
3683
4654
  ),
3684
- expanded && detailRows.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.YStack, { gap: "$1.5", paddingTop: "$1", children: detailRows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(EntryDetailRow, { label: row.label, value: row.value }, row.label)) }) : null
4655
+ expanded && detailRows.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.YStack, { gap: "$1.5", paddingTop: "$1", children: detailRows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(EntryDetailRow, { label: row.label, value: row.value }, row.label)) }) : null
3685
4656
  ] });
3686
4657
  }
3687
4658
  function SourceFilterChip({
@@ -3689,8 +4660,8 @@ function SourceFilterChip({
3689
4660
  selected,
3690
4661
  onPress
3691
4662
  }) {
3692
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3693
- import_ui13.XStack,
4663
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4664
+ import_ui12.XStack,
3694
4665
  {
3695
4666
  tag: "button",
3696
4667
  role: "checkbox",
@@ -3712,8 +4683,8 @@ function SourceFilterChip({
3712
4683
  },
3713
4684
  onPress,
3714
4685
  flexShrink: 0,
3715
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3716
- import_ui13.Text,
4686
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4687
+ import_ui12.Text,
3717
4688
  {
3718
4689
  fontSize: "$2",
3719
4690
  fontWeight: selected ? "700" : "500",
@@ -3729,11 +4700,11 @@ function StatusFilterSelect({
3729
4700
  value,
3730
4701
  onValueChange
3731
4702
  }) {
3732
- const [open, setOpen] = (0, import_react12.useState)(false);
4703
+ const [open, setOpen] = (0, import_react11.useState)(false);
3733
4704
  const selected = STATUS_OPTIONS.find((option) => option.value === value);
3734
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { flex: 1, minWidth: 0, position: "relative", zIndex: open ? 20 : 1, children: [
3735
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3736
- import_ui13.XStack,
4705
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { flex: 1, minWidth: 0, position: "relative", zIndex: open ? 20 : 1, children: [
4706
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
4707
+ import_ui12.XStack,
3737
4708
  {
3738
4709
  tag: "button",
3739
4710
  role: "combobox",
@@ -3749,16 +4720,16 @@ function StatusFilterSelect({
3749
4720
  cursor: "pointer",
3750
4721
  onPress: () => setOpen((current) => !current),
3751
4722
  children: [
3752
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$2", color: "$placeholderColor", numberOfLines: 1, flex: 1, children: [
4723
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.Text, { fontSize: "$2", color: "$placeholderColor", numberOfLines: 1, flex: 1, children: [
3753
4724
  "Status: ",
3754
4725
  selected?.label ?? "All"
3755
4726
  ] }),
3756
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Icon, { name: open ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
4727
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Icon, { name: open ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
3757
4728
  ]
3758
4729
  }
3759
4730
  ),
3760
- open ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3761
- import_ui13.YStack,
4731
+ open ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4732
+ import_ui12.YStack,
3762
4733
  {
3763
4734
  position: "absolute",
3764
4735
  top: "100%",
@@ -3771,8 +4742,93 @@ function StatusFilterSelect({
3771
4742
  backgroundColor: "$backgroundDark",
3772
4743
  overflow: "hidden",
3773
4744
  zIndex: 30,
3774
- children: STATUS_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3775
- import_ui13.XStack,
4745
+ children: STATUS_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4746
+ import_ui12.XStack,
4747
+ {
4748
+ tag: "button",
4749
+ role: "option",
4750
+ paddingHorizontal: "$3",
4751
+ paddingVertical: "$2",
4752
+ cursor: "pointer",
4753
+ backgroundColor: option.value === value ? "$infoMuted" : "transparent",
4754
+ hoverStyle: { backgroundColor: "$backgroundPress" },
4755
+ onPress: () => {
4756
+ onValueChange(option.value);
4757
+ setOpen(false);
4758
+ },
4759
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4760
+ import_ui12.Text,
4761
+ {
4762
+ fontSize: "$2",
4763
+ fontWeight: option.value === value ? "700" : "500",
4764
+ color: option.value === value ? "$primary" : "$color",
4765
+ children: option.label
4766
+ }
4767
+ )
4768
+ },
4769
+ option.value
4770
+ ))
4771
+ }
4772
+ ) : null
4773
+ ] });
4774
+ }
4775
+ function BuyerFilterSelect({
4776
+ value,
4777
+ buyers,
4778
+ onValueChange
4779
+ }) {
4780
+ const [open, setOpen] = (0, import_react11.useState)(false);
4781
+ if (buyers.length === 0) return null;
4782
+ const options = [
4783
+ { value: BUYER_FILTER_ALL, label: "All buyers" },
4784
+ ...buyers.map((b) => ({
4785
+ value: b.address,
4786
+ label: b.label ?? `${b.address.slice(0, 6)}\u2026${b.address.slice(-4)}`
4787
+ }))
4788
+ ];
4789
+ const selected = options.find((o) => o.value === value) ?? options[0];
4790
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { flex: 1, minWidth: 0, position: "relative", zIndex: open ? 25 : 1, children: [
4791
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
4792
+ import_ui12.XStack,
4793
+ {
4794
+ tag: "button",
4795
+ role: "listbox",
4796
+ height: "$7",
4797
+ alignItems: "center",
4798
+ justifyContent: "space-between",
4799
+ gap: "$2",
4800
+ paddingHorizontal: "$3",
4801
+ borderRadius: "$3",
4802
+ borderWidth: 1,
4803
+ borderColor: "$borderColor",
4804
+ backgroundColor: "$backgroundDark",
4805
+ cursor: "pointer",
4806
+ onPress: () => setOpen((current) => !current),
4807
+ children: [
4808
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.Text, { fontSize: "$2", color: "$placeholderColor", numberOfLines: 1, flex: 1, children: [
4809
+ "Buyer: ",
4810
+ selected?.label ?? "All buyers"
4811
+ ] }),
4812
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Icon, { name: open ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
4813
+ ]
4814
+ }
4815
+ ),
4816
+ open ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4817
+ import_ui12.YStack,
4818
+ {
4819
+ position: "absolute",
4820
+ top: "100%",
4821
+ left: 0,
4822
+ right: 0,
4823
+ marginTop: "$1",
4824
+ borderRadius: "$3",
4825
+ borderWidth: 1,
4826
+ borderColor: "$borderColor",
4827
+ backgroundColor: "$backgroundDark",
4828
+ overflow: "hidden",
4829
+ zIndex: 35,
4830
+ children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4831
+ import_ui12.XStack,
3776
4832
  {
3777
4833
  tag: "button",
3778
4834
  role: "option",
@@ -3785,8 +4841,8 @@ function StatusFilterSelect({
3785
4841
  onValueChange(option.value);
3786
4842
  setOpen(false);
3787
4843
  },
3788
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3789
- import_ui13.Text,
4844
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4845
+ import_ui12.Text,
3790
4846
  {
3791
4847
  fontSize: "$2",
3792
4848
  fontWeight: option.value === value ? "700" : "500",
@@ -3801,10 +4857,11 @@ function StatusFilterSelect({
3801
4857
  ) : null
3802
4858
  ] });
3803
4859
  }
3804
- function HistoryTab({ state, actions }) {
4860
+ function HistoryTab({ state, actions, knownBuyers = [] }) {
3805
4861
  const {
3806
4862
  selectedSources,
3807
4863
  statusFilter,
4864
+ buyerAddressFilter,
3808
4865
  fromDate,
3809
4866
  toDate,
3810
4867
  entries,
@@ -3814,26 +4871,26 @@ function HistoryTab({ state, actions }) {
3814
4871
  error,
3815
4872
  activeSources
3816
4873
  } = state;
3817
- const [expandedEntryId, setExpandedEntryId] = (0, import_react12.useState)(null);
3818
- const defaultRange = (0, import_react12.useMemo)(() => getLast90DaysRange(), []);
4874
+ const [expandedEntryId, setExpandedEntryId] = (0, import_react11.useState)(null);
4875
+ const defaultRange = (0, import_react11.useMemo)(() => getLast90DaysRange(), []);
3819
4876
  const isDefaultRange = fromDate === defaultRange.from && toDate === defaultRange.to;
3820
4877
  const rangeSummary = isDefaultRange ? `Last ${HISTORY_LOOKBACK_DAYS} days activity` : `${formatShortDate(fromDate)} \u2013 ${formatShortDate(toDate)}`;
3821
- const accumulatedG = (0, import_react12.useMemo)(
4878
+ const accumulatedG = (0, import_react11.useMemo)(
3822
4879
  () => formatAccumulatedG(sumFilteredGdWei(entries)),
3823
4880
  [entries]
3824
4881
  );
3825
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { gap: "$3", width: "100%", children: [
3826
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Card, { gap: "$3", children: [
3827
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.XStack, { alignItems: "flex-start", justifyContent: "space-between", gap: "$2", width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { flex: 1, gap: "$0.5", minWidth: 0, children: [
3828
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Heading, { level: 4, children: "AI Credit History" }),
3829
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$1", secondary: true, children: rangeSummary })
4882
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { gap: "$3", width: "100%", children: [
4883
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.Card, { gap: "$3", children: [
4884
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.XStack, { alignItems: "flex-start", justifyContent: "space-between", gap: "$2", width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { flex: 1, gap: "$0.5", minWidth: 0, children: [
4885
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Heading, { level: 4, children: "AI Credit History" }),
4886
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$1", secondary: true, children: rangeSummary })
3830
4887
  ] }) }),
3831
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { gap: "$1", children: [
3832
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$1", fontWeight: "600", secondary: true, letterSpacing: 0.6, children: "TOTAL ACCUMULATED" }),
3833
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$7", fontWeight: "700", color: "$color", children: accumulatedG })
4888
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { gap: "$1", children: [
4889
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$1", fontWeight: "600", secondary: true, letterSpacing: 0.6, children: "TOTAL ACCUMULATED" }),
4890
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$7", fontWeight: "700", color: "$color", children: accumulatedG })
3834
4891
  ] })
3835
4892
  ] }),
3836
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.XStack, { gap: "$2", flexWrap: "wrap", width: "100%", children: SOURCE_PILL_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
4893
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.XStack, { gap: "$2", flexWrap: "wrap", width: "100%", children: SOURCE_PILL_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3837
4894
  SourceFilterChip,
3838
4895
  {
3839
4896
  label: option.label,
@@ -3842,16 +4899,26 @@ function HistoryTab({ state, actions }) {
3842
4899
  },
3843
4900
  option.id
3844
4901
  )) }),
3845
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.XStack, { gap: "$2", alignItems: "center", width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3846
- StatusFilterSelect,
3847
- {
3848
- value: statusFilter,
3849
- onValueChange: actions.setStatusFilter
3850
- }
3851
- ) }),
3852
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.XStack, { gap: "$2", width: "100%", children: [
3853
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.YStack, { flex: 1, minWidth: 0, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3854
- import_ui13.Input,
4902
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.XStack, { gap: "$2", alignItems: "center", width: "100%", children: [
4903
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4904
+ StatusFilterSelect,
4905
+ {
4906
+ value: statusFilter,
4907
+ onValueChange: actions.setStatusFilter
4908
+ }
4909
+ ),
4910
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4911
+ BuyerFilterSelect,
4912
+ {
4913
+ value: buyerAddressFilter,
4914
+ buyers: knownBuyers,
4915
+ onValueChange: actions.setBuyerAddressFilter
4916
+ }
4917
+ )
4918
+ ] }),
4919
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.XStack, { gap: "$2", width: "100%", children: [
4920
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.YStack, { flex: 1, minWidth: 0, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4921
+ import_ui12.Input,
3855
4922
  {
3856
4923
  size: "sm",
3857
4924
  type: "date",
@@ -3860,8 +4927,8 @@ function HistoryTab({ state, actions }) {
3860
4927
  onChangeText: actions.setFromDate
3861
4928
  }
3862
4929
  ) }),
3863
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.YStack, { flex: 1, minWidth: 0, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3864
- import_ui13.Input,
4930
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.YStack, { flex: 1, minWidth: 0, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4931
+ import_ui12.Input,
3865
4932
  {
3866
4933
  size: "sm",
3867
4934
  type: "date",
@@ -3871,10 +4938,10 @@ function HistoryTab({ state, actions }) {
3871
4938
  }
3872
4939
  ) })
3873
4940
  ] }),
3874
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.XStack, { alignItems: "center", justifyContent: "space-between", gap: "$2", width: "100%", children: [
3875
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$1", fontWeight: "700", secondary: true, letterSpacing: 0.6, children: "CREDIT HISTORY" }),
3876
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3877
- import_ui13.XStack,
4941
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.XStack, { alignItems: "center", justifyContent: "space-between", gap: "$2", width: "100%", children: [
4942
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$1", fontWeight: "700", secondary: true, letterSpacing: 0.6, children: "CREDIT HISTORY" }),
4943
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4944
+ import_ui12.XStack,
3878
4945
  {
3879
4946
  tag: "button",
3880
4947
  backgroundColor: "transparent",
@@ -3888,17 +4955,17 @@ function HistoryTab({ state, actions }) {
3888
4955
  if (entries.length === 0) return;
3889
4956
  exportEntriesCsv(entries);
3890
4957
  },
3891
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", fontWeight: "600", color: "$primary", children: "Export CSV" })
4958
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$2", fontWeight: "600", color: "$primary", children: "Export CSV" })
3892
4959
  }
3893
4960
  )
3894
4961
  ] }),
3895
- loading ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Card, { gap: "$2", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { alignItems: "center", paddingVertical: "$4", gap: "$2", children: [
3896
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Spinner, { size: "sm" }),
3897
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", secondary: true, children: "Loading credit history\u2026" })
3898
- ] }) }) : error ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Card, { gap: "$2", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { gap: "$2", paddingVertical: "$2", children: [
3899
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { color: "$error", fontSize: "$2", children: error }),
3900
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3901
- import_ui13.Button,
4962
+ loading ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Card, { gap: "$2", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { alignItems: "center", paddingVertical: "$4", gap: "$2", children: [
4963
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Spinner, { size: "sm" }),
4964
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$2", secondary: true, children: "Loading credit history\u2026" })
4965
+ ] }) }) : error ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Card, { gap: "$2", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { gap: "$2", paddingVertical: "$2", children: [
4966
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { color: "$error", fontSize: "$2", children: error }),
4967
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4968
+ import_ui12.Button,
3902
4969
  {
3903
4970
  variant: "outline",
3904
4971
  size: "sm",
@@ -3907,10 +4974,10 @@ function HistoryTab({ state, actions }) {
3907
4974
  onPress: () => {
3908
4975
  void actions.reload();
3909
4976
  },
3910
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.ButtonText, { children: "Retry" })
4977
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.ButtonText, { children: "Retry" })
3911
4978
  }
3912
4979
  )
3913
- ] }) }) : activeSources.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", secondary: true, children: "Select at least one source to view history." }) }) : entries.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", secondary: true, children: "No credit history matches these filters." }) }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.YStack, { gap: "$2", width: "100%", children: entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
4980
+ ] }) }) : activeSources.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$2", secondary: true, children: "Select at least one source to view history." }) }) : entries.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$2", secondary: true, children: "No credit history matches these filters." }) }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.YStack, { gap: "$2", width: "100%", children: entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3914
4981
  CreditHistoryEntryRow,
3915
4982
  {
3916
4983
  entry,
@@ -3919,8 +4986,8 @@ function HistoryTab({ state, actions }) {
3919
4986
  },
3920
4987
  entry.id
3921
4988
  )) }),
3922
- !loading && !error && hasMore && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3923
- import_ui13.Button,
4989
+ !loading && !error && hasMore && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
4990
+ import_ui12.Button,
3924
4991
  {
3925
4992
  variant: "outline",
3926
4993
  size: "sm",
@@ -3931,37 +4998,559 @@ function HistoryTab({ state, actions }) {
3931
4998
  void actions.loadMore();
3932
4999
  },
3933
5000
  children: [
3934
- loadingMore ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Spinner, { size: "sm" }) : null,
3935
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.ButtonText, { children: loadingMore ? "Loading\u2026" : "Load more" })
5001
+ loadingMore ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Spinner, { size: "sm" }) : null,
5002
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.ButtonText, { children: loadingMore ? "Loading\u2026" : "Load more" })
3936
5003
  ]
3937
5004
  }
3938
5005
  )
3939
5006
  ] });
3940
5007
  }
3941
5008
 
3942
- // src/components/flow/purchaseFlowUtils.ts
3943
- function mapStatusToActiveStep(state, buyerPubKeySaved) {
3944
- if (state.operatorConsented) return "pay";
3945
- if (!state.buyerPubKey || !state.buyerPrvKey) return "buyer_key";
3946
- if (!buyerPubKeySaved) return "buyer_key";
3947
- if (!state.operatorConsented) return "consent";
3948
- if (state.status === "purchase_setup" || state.status === "quote_ready" || state.status === "payment_pending" || state.status === "payment_confirmed" || state.status === "payment_failed")
3949
- return "pay";
3950
- return null;
3951
- }
3952
- function getAiCreditsActiveFlowStep(state, buyerPubKeySaved) {
3953
- return mapStatusToActiveStep(state, buyerPubKeySaved);
3954
- }
3955
- function getActiveFlowStepActionLabel(state, step, buyerPubKeySaved) {
3956
- if (!step) return null;
3957
- switch (step) {
3958
- case "buyer_key":
3959
- if (!state.buyerPubKey) return "Sign & Generate Key";
3960
- if (!buyerPubKeySaved) return "Continue Buyer Key";
3961
- return "View Buyer Key";
3962
- case "consent":
3963
- return state.operatorConsented ? "View Operator Consent" : "Sign Operator Consent";
3964
- case "pay":
5009
+ // src/components/setup/SetupGuidanceCard.tsx
5010
+ var import_ui14 = require("@goodwidget/ui");
5011
+
5012
+ // src/components/setup/SetupBonusHighlight.tsx
5013
+ var import_react12 = require("react");
5014
+ var import_ui13 = require("@goodwidget/ui");
5015
+ var import_jsx_runtime11 = require("react/jsx-runtime");
5016
+ function SetupBonusHighlight({
5017
+ depositBonusPercent,
5018
+ streamBonusPercent,
5019
+ isGoodIdVerified
5020
+ }) {
5021
+ const [isExpanded, setIsExpanded] = (0, import_react12.useState)(false);
5022
+ const maxBonusPercent = Math.max(depositBonusPercent, streamBonusPercent);
5023
+ if (maxBonusPercent <= 0) return null;
5024
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Card, { gap: "$2", padding: "$3", backgroundColor: "$backgroundHover", children: [
5025
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
5026
+ import_ui13.XStack,
5027
+ {
5028
+ gap: "$3",
5029
+ alignItems: "center",
5030
+ cursor: "pointer",
5031
+ accessibilityRole: "button",
5032
+ "aria-expanded": isExpanded,
5033
+ onPress: () => setIsExpanded((previous) => !previous),
5034
+ children: [
5035
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
5036
+ import_ui13.YStack,
5037
+ {
5038
+ width: 34,
5039
+ height: 34,
5040
+ borderRadius: "$2",
5041
+ backgroundColor: "$backgroundPress",
5042
+ alignItems: "center",
5043
+ justifyContent: "center",
5044
+ flexShrink: 0,
5045
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Icon, { name: "party-popper", size: "sm", color: "primary" })
5046
+ }
5047
+ ),
5048
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { flex: 1, gap: 2, children: [
5049
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$3", fontWeight: "700", children: [
5050
+ "Up to ",
5051
+ maxBonusPercent,
5052
+ "% more AI credits"
5053
+ ] }),
5054
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$2", lineHeight: "$3", children: [
5055
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$2", fontWeight: "700", color: "$primary", children: [
5056
+ "+",
5057
+ depositBonusPercent,
5058
+ "%"
5059
+ ] }),
5060
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$2", secondary: true, children: [
5061
+ " ",
5062
+ "on deposits,",
5063
+ " "
5064
+ ] }),
5065
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$2", fontWeight: "700", color: "$primary", children: [
5066
+ "+",
5067
+ streamBonusPercent,
5068
+ "%"
5069
+ ] }),
5070
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$2", secondary: true, children: [
5071
+ " ",
5072
+ "on streams \u2014 paid with G$"
5073
+ ] })
5074
+ ] })
5075
+ ] }),
5076
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Icon, { name: isExpanded ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
5077
+ ]
5078
+ }
5079
+ ),
5080
+ isExpanded && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.YStack, { backgroundColor: "$background", borderRadius: "$2", padding: "$3", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", secondary: true, lineHeight: "$3", children: isGoodIdVerified ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
5081
+ "Your wallet is",
5082
+ " ",
5083
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", fontWeight: "700", children: "GoodID verified" }),
5084
+ ", so the bonus is applied automatically to deposits and streams."
5085
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
5086
+ "Bonus applies to",
5087
+ " ",
5088
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", fontWeight: "700", children: "verified GoodDollar wallets" }),
5089
+ " ",
5090
+ "only. Not verified? Claim UBI first via GoodWallet or GoodDapp \u2014 takes a minute, then this kicks in automatically."
5091
+ ] }) }) })
5092
+ ] });
5093
+ }
5094
+
5095
+ // src/components/setup/SetupGuidanceCard.tsx
5096
+ var import_jsx_runtime12 = require("react/jsx-runtime");
5097
+ var ANTSEED_SITE_URL = "https://antseed.com";
5098
+ function SetupGuidanceCard({
5099
+ onHowToUse,
5100
+ onFaq,
5101
+ activeHelpView,
5102
+ depositBonusPercent,
5103
+ streamBonusPercent,
5104
+ isGoodIdVerified
5105
+ }) {
5106
+ return (
5107
+ // Rendered flush on the widget background — no card surface, so it reads as
5108
+ // part of the header rather than a separate panel.
5109
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.YStack, { gap: "$3", paddingHorizontal: "$1", children: [
5110
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Text, { fontSize: "$3", secondary: true, lineHeight: "$4", children: "Buy AI credits with G$ for Claude Code, Codex, chat & other AI tools." }),
5111
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5112
+ SetupBonusHighlight,
5113
+ {
5114
+ depositBonusPercent,
5115
+ streamBonusPercent,
5116
+ isGoodIdVerified
5117
+ }
5118
+ ),
5119
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.YStack, { gap: "$1", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Text, { variant: "label", secondary: true, fontSize: "$1", fontWeight: "700", letterSpacing: 1, children: "WHAT'S INVOLVED:" }) }),
5120
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.YStack, { gap: "$3", children: [
5121
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.XStack, { gap: "$3", alignItems: "flex-start", children: [
5122
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5123
+ import_ui14.YStack,
5124
+ {
5125
+ width: 22,
5126
+ height: 22,
5127
+ borderRadius: "$full",
5128
+ backgroundColor: "$backgroundHover",
5129
+ alignItems: "center",
5130
+ justifyContent: "center",
5131
+ flexShrink: 0,
5132
+ marginTop: 2,
5133
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Text, { fontSize: "$1", fontWeight: "700", color: "$secondary", children: "1" })
5134
+ }
5135
+ ),
5136
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.Text, { fontSize: "$2", flex: 1, lineHeight: "$3", children: [
5137
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.Text, { fontSize: "$2", fontWeight: "700", children: [
5138
+ "Get G$",
5139
+ " "
5140
+ ] }),
5141
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Text, { fontSize: "$2", secondary: true, children: "\u2014 claim UBI via GoodWallet, or buy G$ with your wallet of choice" })
5142
+ ] })
5143
+ ] }),
5144
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.XStack, { gap: "$3", alignItems: "flex-start", children: [
5145
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5146
+ import_ui14.YStack,
5147
+ {
5148
+ width: 22,
5149
+ height: 22,
5150
+ borderRadius: "$full",
5151
+ backgroundColor: "$backgroundHover",
5152
+ alignItems: "center",
5153
+ justifyContent: "center",
5154
+ flexShrink: 0,
5155
+ marginTop: 2,
5156
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Text, { fontSize: "$1", fontWeight: "700", color: "$secondary", children: "2" })
5157
+ }
5158
+ ),
5159
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.Text, { fontSize: "$2", flex: 1, lineHeight: "$3", children: [
5160
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.Text, { fontSize: "$2", fontWeight: "700", children: [
5161
+ "Download Antseed",
5162
+ " "
5163
+ ] }),
5164
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Text, { fontSize: "$2", secondary: true, children: "\u2014 the free desktop app that runs your credits locally" })
5165
+ ] })
5166
+ ] })
5167
+ ] }),
5168
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Separator, {}),
5169
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.XStack, { gap: "$2", flexWrap: "wrap", children: [
5170
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5171
+ import_ui14.Button,
5172
+ {
5173
+ flexGrow: 1,
5174
+ flexBasis: "auto",
5175
+ size: "sm",
5176
+ variant: activeHelpView === "how-to-use" ? "default" : "outline",
5177
+ onPress: onHowToUse,
5178
+ borderRadius: "$3",
5179
+ paddingHorizontal: "$2",
5180
+ minWidth: 0,
5181
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.ButtonText, { numberOfLines: 1, children: "How to use" })
5182
+ }
5183
+ ),
5184
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5185
+ import_ui14.Anchor,
5186
+ {
5187
+ href: ANTSEED_SITE_URL,
5188
+ target: "_blank",
5189
+ style: { flexGrow: 1, flexBasis: "auto", textDecorationLine: "none", minWidth: 0 },
5190
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
5191
+ import_ui14.Button,
5192
+ {
5193
+ size: "sm",
5194
+ variant: "outline",
5195
+ width: "100%",
5196
+ borderRadius: "$3",
5197
+ paddingHorizontal: "$2",
5198
+ gap: "$1",
5199
+ children: [
5200
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.ButtonText, { numberOfLines: 1, children: "Antseed site" }),
5201
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Icon, { name: "external-link", size: "xs", color: "muted" })
5202
+ ]
5203
+ }
5204
+ )
5205
+ }
5206
+ ),
5207
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5208
+ import_ui14.Button,
5209
+ {
5210
+ flexGrow: 1,
5211
+ flexBasis: "auto",
5212
+ size: "sm",
5213
+ variant: activeHelpView === "faq" ? "default" : "outline",
5214
+ onPress: onFaq,
5215
+ borderRadius: "$3",
5216
+ paddingHorizontal: "$2",
5217
+ minWidth: 0,
5218
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.ButtonText, { numberOfLines: 1, children: "FAQs" })
5219
+ }
5220
+ )
5221
+ ] })
5222
+ ] })
5223
+ );
5224
+ }
5225
+
5226
+ // src/components/setup/HowToUseView.tsx
5227
+ var import_ui15 = require("@goodwidget/ui");
5228
+ var import_jsx_runtime13 = require("react/jsx-runtime");
5229
+ var VIDEO_URL = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
5230
+ var WRITTEN_GUIDE_URL = "https://app.notion.com/p/gooddollar/Full-Setup-Walkthrough-Widget-AntSeed-VPR-3c0f258232f08184bee9cd440cc93059";
5231
+ var QUICK_SUMMARY_STEPS = [
5232
+ {
5233
+ index: 1,
5234
+ title: "First, connect your wallet",
5235
+ tabLabel: "Buy",
5236
+ description: "Any wallet holding G$ works. Verified GoodDollar wallets get the bonus automatically."
5237
+ },
5238
+ {
5239
+ index: 2,
5240
+ title: "Then complete the one-time setup",
5241
+ tabLabel: "Buy",
5242
+ description: "Download Antseed, generate your signer key, and authorize your wallet \u2014 three quick taps."
5243
+ },
5244
+ {
5245
+ index: 3,
5246
+ title: "Head to Manage to buy or stream credits",
5247
+ tabLabel: "Manage",
5248
+ description: "Deposit once (+10%) or stream continuously (+20%), then confirm."
5249
+ },
5250
+ {
5251
+ index: 4,
5252
+ title: "Finally, connect Antseed to start using them",
5253
+ tabLabel: "Connect",
5254
+ description: 'Import your signer key \u2014 no separate "start" step, it just works from there.'
5255
+ }
5256
+ ];
5257
+ function HowToUseView({ onBack }) {
5258
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.YStack, { gap: "$4", children: [
5259
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.Button, { variant: "text", alignSelf: "flex-start", onPress: onBack, gap: "$1", children: [
5260
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Icon, { name: "arrow-left", size: "xs", color: "primary" }),
5261
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.ButtonText, { color: "$primary", fontSize: "$2", children: "Back to setup" })
5262
+ ] }),
5263
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$2", secondary: true, lineHeight: "$3", children: "New here? Start with the 3-minute video \u2014 it covers the whole journey, start to finish." }),
5264
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Anchor, { href: VIDEO_URL, target: "_blank", style: { textDecorationLine: "none" }, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
5265
+ import_ui15.Card,
5266
+ {
5267
+ backgroundColor: "$backgroundHover",
5268
+ gap: "$2",
5269
+ paddingVertical: "$4",
5270
+ paddingHorizontal: "$4",
5271
+ hoverStyle: { opacity: 0.9 },
5272
+ children: [
5273
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.XStack, { justifyContent: "flex-end", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Card, { backgroundColor: "$backgroundPress", paddingHorizontal: "$2", paddingVertical: 2, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$1", fontWeight: "700", children: "3:12" }) }) }),
5274
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.XStack, { justifyContent: "center", paddingVertical: "$6", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5275
+ import_ui15.YStack,
5276
+ {
5277
+ width: 56,
5278
+ height: 56,
5279
+ borderRadius: "$full",
5280
+ backgroundColor: "$background",
5281
+ alignItems: "center",
5282
+ justifyContent: "center",
5283
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Icon, { name: "play", size: "md", color: "primary" })
5284
+ }
5285
+ ) }),
5286
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.YStack, { gap: "$1", children: [
5287
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$2", fontWeight: "700", children: "Getting started with AI credits" }),
5288
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$1", secondary: true, children: "Wallet \u2192 buy credits \u2192 connect Antseed" })
5289
+ ] })
5290
+ ]
5291
+ }
5292
+ ) }),
5293
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Anchor, { href: WRITTEN_GUIDE_URL, target: "_blank", style: { textDecorationLine: "none" }, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Card, { backgroundColor: "$backgroundHover", paddingVertical: "$3", paddingHorizontal: "$4", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.XStack, { gap: "$3", alignItems: "center", justifyContent: "space-between", children: [
5294
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.XStack, { gap: "$3", alignItems: "center", flex: 1, children: [
5295
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Icon, { name: "file-text", size: "md", color: "muted" }),
5296
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.YStack, { flex: 1, gap: "$1", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.Text, { fontSize: "$2", lineHeight: "$3", children: [
5297
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.Text, { fontSize: "$2", fontWeight: "700", children: [
5298
+ "Full written guide",
5299
+ " "
5300
+ ] }),
5301
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$2", secondary: true, children: "Step-by-step walkthrough with screenshots, on Notion" })
5302
+ ] }) })
5303
+ ] }),
5304
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Icon, { name: "external-link", size: "xs", color: "muted" })
5305
+ ] }) }) }),
5306
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.YStack, { gap: "$3", children: [
5307
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { variant: "label", secondary: true, fontSize: "$1", fontWeight: "700", letterSpacing: 1, children: "QUICK SUMMARY" }),
5308
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.YStack, { gap: "$4", children: QUICK_SUMMARY_STEPS.map((step) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.XStack, { gap: "$3", alignItems: "flex-start", children: [
5309
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5310
+ import_ui15.YStack,
5311
+ {
5312
+ width: 24,
5313
+ height: 24,
5314
+ borderRadius: "$full",
5315
+ backgroundColor: "$backgroundHover",
5316
+ alignItems: "center",
5317
+ justifyContent: "center",
5318
+ flexShrink: 0,
5319
+ marginTop: 2,
5320
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$1", fontWeight: "700", color: "$secondary", children: step.index })
5321
+ }
5322
+ ),
5323
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.YStack, { flex: 1, gap: "$1", children: [
5324
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.XStack, { gap: "$2", alignItems: "center", flexWrap: "wrap", children: [
5325
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$2", fontWeight: "700", children: step.title }),
5326
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Badge, { size: "sm", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.BadgeText, { children: step.tabLabel }) })
5327
+ ] }),
5328
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$2", secondary: true, lineHeight: "$3", children: step.description })
5329
+ ] })
5330
+ ] }, step.index)) }),
5331
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$1", secondary: true, textAlign: "center", paddingTop: "$1", children: "Your G$ wallet is never exposed \u2014 only the scoped signer key." })
5332
+ ] })
5333
+ ] });
5334
+ }
5335
+
5336
+ // src/components/setup/SetupFaqView.tsx
5337
+ var import_react13 = require("react");
5338
+ var import_ui16 = require("@goodwidget/ui");
5339
+ var import_jsx_runtime14 = require("react/jsx-runtime");
5340
+ var SETUP_FAQ_ITEMS = [
5341
+ {
5342
+ id: "goodwallet-only",
5343
+ question: "I only claim UBI with GoodWallet \u2014 can I still use this?",
5344
+ answer: "Yes. Any wallet that holds G$ on Celo works. Connect your wallet here, generate a signer key, and you can buy credits just like any other G$ holder."
5345
+ },
5346
+ {
5347
+ id: "ubi-savings",
5348
+ question: "Will this ever touch my daily UBI savings?",
5349
+ answer: "No. Only the G$ amount you explicitly deposit or stream is used. Your UBI balance and savings remain untouched unless you choose to spend them."
5350
+ },
5351
+ {
5352
+ id: "deposit-vs-stream",
5353
+ question: "Deposit or stream \u2014 which should I pick?",
5354
+ answer: "A one-time deposit gives you credits immediately (+10% bonus with GoodID). A monthly stream drips G$ over time and earns a higher +20% bonus \u2014 ideal if you use AI tools regularly. You can combine both."
5355
+ },
5356
+ {
5357
+ id: "lost-signer-key",
5358
+ question: "What if I lose my signer key?",
5359
+ answer: 'Re-connect your payer wallet and click "Sign & Generate Key" again \u2014 it derives the same key deterministically. You can also import a backup private key in the Manage tab.'
5360
+ },
5361
+ {
5362
+ id: "no-code",
5363
+ question: "Do I need to know how to code?",
5364
+ answer: "No. The whole flow \u2014 wallet connect, signer key, credit purchase \u2014 is done in this widget. After that, Antseed provides a desktop app that handles the rest without any command-line steps."
5365
+ },
5366
+ {
5367
+ id: "unused-credits",
5368
+ question: "Can I get unused credits back?",
5369
+ answer: "Yes. The Withdrawable amount shown in the Manage tab can be reclaimed to your payer wallet. Bonus credits (from GoodID) are not withdrawable \u2014 they are for AI usage only."
5370
+ },
5371
+ {
5372
+ id: "compatible-tools",
5373
+ question: "Which tools can I actually use my credits with?",
5374
+ answer: "Any tool that supports AntSeed-compatible AI credits, including Claude Code, Codex, and other AI coding assistants. The Antseed desktop app integrates them without extra configuration."
5375
+ },
5376
+ {
5377
+ id: "antseed-safe",
5378
+ question: "Is Antseed safe? Can I check it myself?",
5379
+ answer: "Antseed is an open-source desktop application. Your G$ wallet private key is never shared with it \u2014 only the scoped signer key is exposed. You can audit the source code on the AntSeed GitHub repository."
5380
+ }
5381
+ ];
5382
+ function FaqItem({ question, answer, expanded, onToggle }) {
5383
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$1", children: [
5384
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
5385
+ import_ui16.XStack,
5386
+ {
5387
+ justifyContent: "space-between",
5388
+ alignItems: "center",
5389
+ gap: "$2",
5390
+ onPress: onToggle,
5391
+ cursor: "pointer",
5392
+ children: [
5393
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { fontSize: "$2", fontWeight: "600", flex: 1, children: question }),
5394
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Icon, { name: expanded ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
5395
+ ]
5396
+ }
5397
+ ),
5398
+ expanded && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { fontSize: "$2", secondary: true, lineHeight: "$3", children: answer })
5399
+ ] });
5400
+ }
5401
+ function SetupFaqView({ onBack }) {
5402
+ const [expandedId, setExpandedId] = (0, import_react13.useState)(null);
5403
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$4", children: [
5404
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.Button, { variant: "text", alignSelf: "flex-start", onPress: onBack, gap: "$1", children: [
5405
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Icon, { name: "arrow-left", size: "xs", color: "primary" }),
5406
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.ButtonText, { color: "$primary", fontSize: "$2", children: "Back to setup" })
5407
+ ] }),
5408
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Card, { gap: "$3", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.YStack, { gap: "$3", children: SETUP_FAQ_ITEMS.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$3", children: [
5409
+ index > 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Separator, {}),
5410
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5411
+ FaqItem,
5412
+ {
5413
+ question: item.question,
5414
+ answer: item.answer,
5415
+ expanded: expandedId === item.id,
5416
+ onToggle: () => {
5417
+ setExpandedId((current) => current === item.id ? null : item.id);
5418
+ }
5419
+ }
5420
+ )
5421
+ ] }, item.id)) }) })
5422
+ ] });
5423
+ }
5424
+
5425
+ // src/components/setup/SetupOnboardingFlow.tsx
5426
+ var import_react14 = require("react");
5427
+ var import_ui17 = require("@goodwidget/ui");
5428
+ var import_jsx_runtime15 = require("react/jsx-runtime");
5429
+ var ANTSEED_DOWNLOAD_URL = "https://antseed.com";
5430
+ function SetupOnboardingFlow({ state, actions }) {
5431
+ const [downloadOpened, setDownloadOpened] = (0, import_react14.useState)(false);
5432
+ const [drawerOpen, setDrawerOpen] = (0, import_react14.useState)(false);
5433
+ const [drawerStep, setDrawerStep] = (0, import_react14.useState)(null);
5434
+ const hasSignerKey = Boolean(state.buyerPubKey);
5435
+ const downloadCompleted = downloadOpened || hasSignerKey;
5436
+ const steps = [
5437
+ {
5438
+ id: "download",
5439
+ title: "Download Antseed",
5440
+ description: "The app that runs your credits locally \u2014 required once",
5441
+ status: downloadCompleted ? "completed" : "ready"
5442
+ },
5443
+ {
5444
+ id: "signer",
5445
+ title: "Signer key",
5446
+ description: "Generate or import \u2014 separate from your wallet",
5447
+ status: !downloadCompleted ? "pending" : hasSignerKey ? "completed" : "ready"
5448
+ },
5449
+ {
5450
+ id: "authorize",
5451
+ title: "Authorize Wallet",
5452
+ description: "One-time permission \u2014 scoped to Base credits",
5453
+ status: !hasSignerKey ? "pending" : state.operatorConsented ? "completed" : "ready"
5454
+ }
5455
+ ];
5456
+ const openSignerDrawer = (0, import_react14.useCallback)(() => {
5457
+ setDrawerStep("signer");
5458
+ setDrawerOpen(true);
5459
+ }, []);
5460
+ const handleSignerReady = (0, import_react14.useCallback)(() => {
5461
+ if (state.operatorConsented) {
5462
+ setDrawerOpen(false);
5463
+ setDrawerStep(null);
5464
+ return;
5465
+ }
5466
+ setDrawerStep("authorize");
5467
+ }, [state.operatorConsented]);
5468
+ const handleStepPress = (0, import_react14.useCallback)(
5469
+ (stepId) => {
5470
+ if (stepId === "download") {
5471
+ if (typeof window !== "undefined") {
5472
+ window.open(ANTSEED_DOWNLOAD_URL, "_blank", "noopener,noreferrer");
5473
+ }
5474
+ setDownloadOpened(true);
5475
+ return;
5476
+ }
5477
+ if (stepId === "signer" && downloadCompleted) {
5478
+ openSignerDrawer();
5479
+ }
5480
+ if (stepId === "authorize" && hasSignerKey) {
5481
+ setDrawerStep("authorize");
5482
+ setDrawerOpen(true);
5483
+ }
5484
+ },
5485
+ [downloadCompleted, hasSignerKey, openSignerDrawer]
5486
+ );
5487
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
5488
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5489
+ import_ui17.Stepper,
5490
+ {
5491
+ steps,
5492
+ activeStepId: downloadCompleted ? hasSignerKey ? "authorize" : "signer" : "download",
5493
+ onStepPress: handleStepPress
5494
+ }
5495
+ ),
5496
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5497
+ import_ui17.Drawer,
5498
+ {
5499
+ open: drawerOpen && drawerStep !== null,
5500
+ onClose: () => {
5501
+ setDrawerOpen(false);
5502
+ setDrawerStep(null);
5503
+ },
5504
+ height: "full",
5505
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_ui17.ScrollArea, { width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_ui17.YStack, { gap: "$3", paddingBottom: "$4", width: "100%", children: [
5506
+ drawerStep === "signer" ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SignerKeyPanel, { state, actions, onProceed: handleSignerReady }) : null,
5507
+ drawerStep === "authorize" ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5508
+ OperatorConsentStep,
5509
+ {
5510
+ embedded: true,
5511
+ buyerPubKey: state.buyerPubKey,
5512
+ buyerPrvKey: state.buyerPrvKey ?? null,
5513
+ operatorSignature: state.operatorSignature ?? null,
5514
+ operatorConsented: state.operatorConsented,
5515
+ operatorConsentPending: state.operatorConsentPending,
5516
+ onSign: actions.signOperatorConsent
5517
+ }
5518
+ ) : null
5519
+ ] }) })
5520
+ }
5521
+ )
5522
+ ] });
5523
+ }
5524
+
5525
+ // src/components/flow/purchaseFlowUtils.ts
5526
+ function isSelectedDerivedBuyer(state) {
5527
+ if (!state.buyerPubKey || !state.derivedBuyerAddress) return false;
5528
+ return state.buyerPubKey.toLowerCase() === state.derivedBuyerAddress.toLowerCase();
5529
+ }
5530
+ function mapStatusToActiveStep(state, buyerPubKeySaved) {
5531
+ if (state.operatorConsented) return "pay";
5532
+ if (!state.buyerPubKey) return "buyer_key";
5533
+ if (!state.buyerPrvKey && !state.operatorSignature) return "buyer_key";
5534
+ if (isSelectedDerivedBuyer(state) && state.buyerPrvKey && !buyerPubKeySaved) return "buyer_key";
5535
+ if (!state.operatorConsented) return "consent";
5536
+ if (state.status === "purchase_setup" || state.status === "quote_ready" || state.status === "payment_pending" || state.status === "payment_confirmed" || state.status === "payment_failed")
5537
+ return "pay";
5538
+ return null;
5539
+ }
5540
+ function getAiCreditsActiveFlowStep(state, buyerPubKeySaved) {
5541
+ return mapStatusToActiveStep(state, buyerPubKeySaved);
5542
+ }
5543
+ function getActiveFlowStepActionLabel(state, step, buyerPubKeySaved) {
5544
+ if (!step) return null;
5545
+ switch (step) {
5546
+ case "buyer_key":
5547
+ if (!state.buyerPubKey) return "Sign & Generate Key";
5548
+ if (!buyerPubKeySaved) return "Continue Signer Key";
5549
+ return "View Signer Key";
5550
+ case "consent":
5551
+ if (state.operatorConsentPending) return "Submitting Authorization\u2026";
5552
+ return state.operatorConsented ? "View Authorization" : "Authorize Wallet";
5553
+ case "pay":
3965
5554
  return "Set Amounts & Pay";
3966
5555
  default:
3967
5556
  return null;
@@ -3969,8 +5558,8 @@ function getActiveFlowStepActionLabel(state, step, buyerPubKeySaved) {
3969
5558
  }
3970
5559
 
3971
5560
  // src/components/flow/AiCreditsFlowStepper.tsx
3972
- var import_ui14 = require("@goodwidget/ui");
3973
- var import_jsx_runtime12 = require("react/jsx-runtime");
5561
+ var import_ui18 = require("@goodwidget/ui");
5562
+ var import_jsx_runtime16 = require("react/jsx-runtime");
3974
5563
  var STEP_ORDER = ["buyer_key", "consent", "pay"];
3975
5564
  function AiCreditsFlowStepper({
3976
5565
  state,
@@ -3989,19 +5578,20 @@ function AiCreditsFlowStepper({
3989
5578
  if (step === "pay" && (state.status === "payment_pending" || state.status === "payment_confirmed")) {
3990
5579
  return "active";
3991
5580
  }
5581
+ if (step === "consent" && state.operatorConsentPending) return "active";
3992
5582
  return "ready";
3993
5583
  }
3994
5584
  const steps = [
3995
5585
  {
3996
5586
  id: "buyer_key",
3997
- title: "Buyer Key",
3998
- description: "Generate or provide your AI credits buyer key",
5587
+ title: "Signer Key",
5588
+ description: "Generate or import your AI credits signer key",
3999
5589
  status: getStepStatus("buyer_key")
4000
5590
  },
4001
5591
  {
4002
5592
  id: "consent",
4003
- title: "Operator Consent",
4004
- description: "Sign permission for the AntseedBuyerOperator",
5593
+ title: "Authorize Wallet",
5594
+ description: state.operatorConsentPending ? "Submitting authorization\u2026" : "Authorize GoodDollar to manage your Base credits",
4005
5595
  status: getStepStatus("consent")
4006
5596
  },
4007
5597
  {
@@ -4016,42 +5606,42 @@ function AiCreditsFlowStepper({
4016
5606
  if (!step || step.status === "completed" || step.status === "pending") return;
4017
5607
  onStepPress?.(stepId);
4018
5608
  }
4019
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
4020
- import_ui14.Stepper,
5609
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
5610
+ import_ui18.Stepper,
4021
5611
  {
4022
5612
  steps,
4023
5613
  activeStepId: activeStep,
4024
5614
  onStepPress: onStepPress ? handleStepPress : void 0,
4025
- header: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Heading, { level: 5, secondary: true, children: "Purchase Flow" })
5615
+ header: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_ui18.Heading, { level: 5, secondary: true, children: "Purchase Flow" })
4026
5616
  }
4027
5617
  );
4028
5618
  }
4029
5619
 
4030
5620
  // src/components/flow/AiCreditsPurchaseFlow.tsx
4031
- var import_react13 = require("react");
4032
- var import_ui15 = require("@goodwidget/ui");
4033
- var import_jsx_runtime13 = require("react/jsx-runtime");
5621
+ var import_react15 = require("react");
5622
+ var import_ui19 = require("@goodwidget/ui");
5623
+ var import_jsx_runtime17 = require("react/jsx-runtime");
4034
5624
  function AiCreditsPurchaseFlow({
4035
5625
  state,
4036
5626
  actions,
4037
5627
  isPending,
4038
5628
  onPay
4039
5629
  }) {
4040
- const [buyerPubKeySaved, setBuyerPubKeySaved] = (0, import_react13.useState)(false);
5630
+ const [buyerPubKeySaved, setBuyerPubKeySaved] = (0, import_react15.useState)(false);
4041
5631
  const activeStep = getAiCreditsActiveFlowStep(state, buyerPubKeySaved);
4042
- const [drawerOpen, setDrawerOpen] = (0, import_react13.useState)(false);
4043
- const [drawerStep, setDrawerStep] = (0, import_react13.useState)(activeStep);
4044
- const prevActiveStepRef = (0, import_react13.useRef)(null);
4045
- const goodIdTabPendingRef = (0, import_react13.useRef)(false);
4046
- (0, import_react13.useEffect)(() => {
5632
+ const [drawerOpen, setDrawerOpen] = (0, import_react15.useState)(false);
5633
+ const [drawerStep, setDrawerStep] = (0, import_react15.useState)(null);
5634
+ const prevActiveStepRef = (0, import_react15.useRef)(null);
5635
+ const goodIdTabPendingRef = (0, import_react15.useRef)(false);
5636
+ (0, import_react15.useEffect)(() => {
4047
5637
  setBuyerPubKeySaved(false);
4048
5638
  }, [state.buyerPubKey]);
4049
- (0, import_react13.useEffect)(() => {
5639
+ (0, import_react15.useEffect)(() => {
4050
5640
  if (activeStep !== "consent" || state.operatorConsented) return;
4051
5641
  if (!state.address || !state.buyerPubKey) return;
4052
5642
  void actions.syncOperatorConsentFromChain();
4053
5643
  }, [activeStep, state.operatorConsented, state.address, state.buyerPubKey, actions]);
4054
- (0, import_react13.useEffect)(() => {
5644
+ (0, import_react15.useEffect)(() => {
4055
5645
  if (!activeStep) {
4056
5646
  setDrawerOpen(false);
4057
5647
  setDrawerStep(null);
@@ -4060,14 +5650,12 @@ function AiCreditsPurchaseFlow({
4060
5650
  }
4061
5651
  const previousStep = prevActiveStepRef.current;
4062
5652
  prevActiveStepRef.current = activeStep;
4063
- setDrawerStep(activeStep);
4064
- if (previousStep == null) {
4065
- setDrawerOpen(false);
4066
- } else if (previousStep !== activeStep) {
5653
+ if (previousStep != null && previousStep !== activeStep) {
5654
+ setDrawerStep(activeStep);
4067
5655
  setDrawerOpen(true);
4068
5656
  }
4069
5657
  }, [activeStep]);
4070
- (0, import_react13.useEffect)(() => {
5658
+ (0, import_react15.useEffect)(() => {
4071
5659
  if (typeof window === "undefined") return;
4072
5660
  const onFocus = () => {
4073
5661
  if (!goodIdTabPendingRef.current) return;
@@ -4080,7 +5668,7 @@ function AiCreditsPurchaseFlow({
4080
5668
  window.addEventListener("focus", onFocus);
4081
5669
  return () => window.removeEventListener("focus", onFocus);
4082
5670
  }, [activeStep]);
4083
- const handleVerifyGoodId = (0, import_react13.useCallback)(async () => {
5671
+ const handleVerifyGoodId = (0, import_react15.useCallback)(async () => {
4084
5672
  try {
4085
5673
  const started = await actions.verifyGoodId();
4086
5674
  if (started) {
@@ -4093,7 +5681,7 @@ function AiCreditsPurchaseFlow({
4093
5681
  }
4094
5682
  }
4095
5683
  }, [actions, activeStep]);
4096
- const openDrawer = (0, import_react13.useCallback)(
5684
+ const openDrawer = (0, import_react15.useCallback)(
4097
5685
  (step) => {
4098
5686
  if (step !== activeStep && !(step === "pay" && state.status === "payment_failed")) return;
4099
5687
  setDrawerStep(step);
@@ -4101,7 +5689,7 @@ function AiCreditsPurchaseFlow({
4101
5689
  },
4102
5690
  [activeStep, state.status]
4103
5691
  );
4104
- const handleStepPress = (0, import_react13.useCallback)(
5692
+ const handleStepPress = (0, import_react15.useCallback)(
4105
5693
  (stepId) => {
4106
5694
  openDrawer(stepId);
4107
5695
  },
@@ -4112,7 +5700,7 @@ function AiCreditsPurchaseFlow({
4112
5700
  if (!step) return null;
4113
5701
  switch (step) {
4114
5702
  case "buyer_key":
4115
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5703
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4116
5704
  BuyerKeyPanel,
4117
5705
  {
4118
5706
  embedded: true,
@@ -4124,18 +5712,20 @@ function AiCreditsPurchaseFlow({
4124
5712
  }
4125
5713
  );
4126
5714
  case "consent":
4127
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5715
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4128
5716
  OperatorConsentStep,
4129
5717
  {
4130
5718
  embedded: true,
4131
5719
  buyerPubKey: state.buyerPubKey,
4132
5720
  buyerPrvKey: state.buyerPrvKey ?? null,
5721
+ operatorSignature: state.operatorSignature ?? null,
4133
5722
  operatorConsented: state.operatorConsented,
5723
+ operatorConsentPending: state.operatorConsentPending,
4134
5724
  onSign: actions.signOperatorConsent
4135
5725
  }
4136
5726
  );
4137
5727
  case "pay":
4138
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5728
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4139
5729
  AmountPicker,
4140
5730
  {
4141
5731
  embedded: true,
@@ -4158,8 +5748,8 @@ function AiCreditsPurchaseFlow({
4158
5748
  return null;
4159
5749
  }
4160
5750
  }
4161
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
4162
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5751
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
5752
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4163
5753
  AiCreditsFlowStepper,
4164
5754
  {
4165
5755
  state,
@@ -4167,8 +5757,8 @@ function AiCreditsPurchaseFlow({
4167
5757
  onStepPress: handleStepPress
4168
5758
  }
4169
5759
  ),
4170
- !drawerOpen && actionLabel && activeStep && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4171
- import_ui15.Button,
5760
+ !drawerOpen && actionLabel && activeStep && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
5761
+ import_ui19.Button,
4172
5762
  {
4173
5763
  fullWidth: true,
4174
5764
  size: "sm",
@@ -4176,34 +5766,137 @@ function AiCreditsPurchaseFlow({
4176
5766
  onPress: () => {
4177
5767
  openDrawer(activeStep);
4178
5768
  },
4179
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.ButtonText, { children: actionLabel })
5769
+ children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_ui19.ButtonText, { children: actionLabel })
4180
5770
  }
4181
5771
  ),
4182
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4183
- import_ui15.Drawer,
5772
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
5773
+ import_ui19.Drawer,
4184
5774
  {
4185
5775
  open: drawerOpen && drawerStep !== null,
4186
5776
  onClose: () => {
4187
5777
  setDrawerOpen(false);
4188
5778
  },
4189
5779
  height: "full",
4190
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.ScrollArea, { width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.YStack, { gap: "$3", paddingBottom: "$4", width: "100%", children: renderDrawerContent(drawerStep) }) })
5780
+ children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_ui19.ScrollArea, { width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_ui19.YStack, { gap: "$3", paddingBottom: "$4", width: "100%", children: renderDrawerContent(drawerStep) }) })
4191
5781
  }
4192
5782
  )
4193
5783
  ] });
4194
5784
  }
4195
5785
 
5786
+ // src/components/shared/WalletChip.tsx
5787
+ var import_react16 = require("react");
5788
+ var import_ui20 = require("@goodwidget/ui");
5789
+ var import_jsx_runtime18 = require("react/jsx-runtime");
5790
+ function shortAddress2(address) {
5791
+ return `${address.slice(0, 5)}\u2026${address.slice(-3)}`;
5792
+ }
5793
+ function WalletChip({
5794
+ address,
5795
+ onDisconnect,
5796
+ disconnectLabel = "Disconnect",
5797
+ disconnectIcon = "log-out",
5798
+ disabled = false
5799
+ }) {
5800
+ const [isMenuOpen, setIsMenuOpen] = (0, import_react16.useState)(false);
5801
+ const [disconnectMessage, setDisconnectMessage] = (0, import_react16.useState)(null);
5802
+ (0, import_react16.useEffect)(() => {
5803
+ if (disabled) setIsMenuOpen(false);
5804
+ }, [disabled]);
5805
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_ui20.XStack, { position: "relative", alignItems: "center", opacity: disabled ? 0.5 : 1, children: [
5806
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
5807
+ import_ui20.XStack,
5808
+ {
5809
+ gap: "$1.5",
5810
+ alignItems: "center",
5811
+ paddingHorizontal: "$2",
5812
+ paddingVertical: "$1",
5813
+ borderRadius: "$full",
5814
+ borderWidth: 1,
5815
+ borderColor: "$borderColor",
5816
+ cursor: disabled ? "not-allowed" : "pointer",
5817
+ onPress: () => {
5818
+ if (disabled) return;
5819
+ setDisconnectMessage(null);
5820
+ setIsMenuOpen((open) => !open);
5821
+ },
5822
+ "aria-label": "Wallet options",
5823
+ "aria-disabled": disabled,
5824
+ children: [
5825
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui20.YStack, { width: 6, height: 6, borderRadius: "$full", backgroundColor: "$success" }),
5826
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui20.Text, { fontSize: "$1", numberOfLines: 1, children: address ? shortAddress2(address) : "" }),
5827
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui20.Icon, { name: "chevron-down", size: "2xs", color: "muted" })
5828
+ ]
5829
+ }
5830
+ ),
5831
+ isMenuOpen && !disabled && /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
5832
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
5833
+ import_ui20.XStack,
5834
+ {
5835
+ position: "fixed",
5836
+ top: 0,
5837
+ left: 0,
5838
+ right: 0,
5839
+ bottom: 0,
5840
+ zIndex: 100,
5841
+ onPress: () => setIsMenuOpen(false)
5842
+ }
5843
+ ),
5844
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
5845
+ import_ui20.YStack,
5846
+ {
5847
+ position: "absolute",
5848
+ top: "100%",
5849
+ right: 0,
5850
+ marginTop: "$1",
5851
+ backgroundColor: "$background",
5852
+ borderWidth: 1,
5853
+ borderColor: "$borderColor",
5854
+ borderRadius: "$3",
5855
+ padding: "$1",
5856
+ minWidth: 132,
5857
+ zIndex: 101,
5858
+ children: [
5859
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
5860
+ import_ui20.Button,
5861
+ {
5862
+ size: "sm",
5863
+ variant: "list",
5864
+ height: "$6",
5865
+ paddingHorizontal: "$2",
5866
+ gap: "$1.5",
5867
+ onPress: async () => {
5868
+ if (!onDisconnect) {
5869
+ setDisconnectMessage("Disconnect should be done in your wallet's session");
5870
+ return;
5871
+ }
5872
+ setIsMenuOpen(false);
5873
+ await onDisconnect();
5874
+ },
5875
+ children: [
5876
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui20.Icon, { name: disconnectIcon, size: "xs", color: "muted" }),
5877
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui20.ButtonText, { fontSize: "$2", children: disconnectLabel })
5878
+ ]
5879
+ }
5880
+ ),
5881
+ disconnectMessage && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui20.Text, { variant: "caption", tone: "secondary", padding: "$2", children: disconnectMessage })
5882
+ ]
5883
+ }
5884
+ )
5885
+ ] })
5886
+ ] });
5887
+ }
5888
+
4196
5889
  // src/AiCreditsWidget.tsx
4197
- var import_jsx_runtime14 = require("react/jsx-runtime");
5890
+ var import_jsx_runtime19 = require("react/jsx-runtime");
4198
5891
  var CELO_CHAIN_ID3 = 42220;
4199
- function DisconnectedPanel({
5892
+ function SetupConnectPrompt({
4200
5893
  onConnect,
4201
5894
  connecting
4202
5895
  }) {
4203
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$5", paddingVertical: "$6", alignItems: "center", children: [
4204
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: "Connect your wallet to buy AI credits" }),
4205
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4206
- import_ui16.CircularActionButton,
5896
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { gap: "$5", alignItems: "center", paddingVertical: "$6", width: "100%", children: [
5897
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, center: true, children: "Connect your wallet to get started" }),
5898
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
5899
+ import_ui21.CircularActionButton,
4207
5900
  {
4208
5901
  label: connecting ? "Connecting..." : "Connect Wallet",
4209
5902
  pending: connecting,
@@ -4213,31 +5906,57 @@ function DisconnectedPanel({
4213
5906
  }
4214
5907
  }
4215
5908
  )
4216
- ] }) });
5909
+ ] });
5910
+ }
5911
+ function SetupTabPanel({
5912
+ state,
5913
+ actions,
5914
+ onConnect
5915
+ }) {
5916
+ if (needsWalletConnection(state)) {
5917
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
5918
+ SetupConnectPrompt,
5919
+ {
5920
+ onConnect,
5921
+ connecting: state.status === "connecting"
5922
+ }
5923
+ );
5924
+ }
5925
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { gap: "$4", width: "100%", children: [
5926
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
5927
+ AiCreditsHero,
5928
+ {
5929
+ gBalance: state.gBalance,
5930
+ isGoodIdVerified: state.isGoodIdVerified
5931
+ }
5932
+ ),
5933
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, fontSize: "$2", children: "One-time setup, in order \u2014 each step unlocks the next:" }),
5934
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SetupOnboardingFlow, { state, actions })
5935
+ ] });
4217
5936
  }
4218
5937
  function BuyCreditsPanel({ state, actions, isPending, onPay }) {
4219
5938
  let content;
4220
5939
  if (state.status === "unsupported_chain") {
4221
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(AiCreditsStatusNotice, { children: [
4222
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.XStack, { gap: "$2", alignItems: "center", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$warning", fontWeight: "700", children: "Wrong Network" }) }),
4223
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: "Please switch to the Celo network to continue." }),
4224
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4225
- import_ui16.Button,
5940
+ content = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(AiCreditsStatusNotice, { children: [
5941
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.XStack, { gap: "$2", alignItems: "center", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$warning", fontWeight: "700", children: "Wrong Network" }) }),
5942
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: "Please switch to the Celo network to continue." }),
5943
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
5944
+ import_ui21.Button,
4226
5945
  {
4227
5946
  onPress: () => {
4228
5947
  void actions.switchChain();
4229
5948
  },
4230
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.ButtonText, { children: "Switch to Celo" })
5949
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.ButtonText, { children: "Switch to Celo" })
4231
5950
  }
4232
5951
  )
4233
5952
  ] });
4234
5953
  } else if (state.status === "payment_failed") {
4235
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
4236
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(AiCreditsStatusNotice, { children: [
4237
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$error", fontWeight: "700", children: "Payment Failed" }),
4238
- state.error && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: state.error })
5954
+ content = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
5955
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(AiCreditsStatusNotice, { children: [
5956
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$error", fontWeight: "700", children: "Payment Failed" }),
5957
+ state.error && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: state.error })
4239
5958
  ] }),
4240
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5959
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4241
5960
  AiCreditsPurchaseFlow,
4242
5961
  {
4243
5962
  state,
@@ -4248,57 +5967,61 @@ function BuyCreditsPanel({ state, actions, isPending, onPay }) {
4248
5967
  )
4249
5968
  ] });
4250
5969
  } else if (state.status === "backend_unavailable") {
4251
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(AiCreditsStatusNotice, { children: [
4252
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$warning", fontWeight: "700", children: "Service Unavailable" }),
4253
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: "The AI credits service is temporarily unavailable. Your wallet has not been charged." }),
4254
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4255
- import_ui16.Button,
5970
+ content = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(AiCreditsStatusNotice, { children: [
5971
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$warning", fontWeight: "700", children: "Service Unavailable" }),
5972
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: "The AI credits service is temporarily unavailable. Your wallet has not been charged." }),
5973
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
5974
+ import_ui21.Button,
4256
5975
  {
4257
5976
  onPress: () => {
4258
5977
  void actions.retry();
4259
5978
  },
4260
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.ButtonText, { children: "Retry" })
5979
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.ButtonText, { children: "Retry" })
4261
5980
  }
4262
5981
  )
4263
5982
  ] });
4264
5983
  } else if (state.status === "insufficient_g_balance") {
4265
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
4266
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5984
+ content = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
5985
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4267
5986
  AiCreditsHero,
4268
5987
  {
4269
5988
  gBalance: state.gBalance,
4270
5989
  isGoodIdVerified: state.isGoodIdVerified
4271
5990
  }
4272
5991
  ),
4273
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(AiCreditsStatusNotice, { children: [
4274
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$warning", fontWeight: "700", children: "Insufficient G$ Balance" }),
4275
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: "You need at least 1 G$ to purchase AI credits. Top up your wallet and try again." })
5992
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(AiCreditsStatusNotice, { children: [
5993
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$warning", fontWeight: "700", children: "Insufficient G$ Balance" }),
5994
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: "You need at least 1 G$ to purchase AI credits. Top up your wallet and try again." })
4276
5995
  ] })
4277
5996
  ] });
4278
5997
  } else if (state.status === "payment_pending" || state.status === "payment_confirmed") {
4279
5998
  const message = state.status === "payment_pending" ? "Transaction submitted \u2014 waiting for confirmation\u2026" : "Payment confirmed \u2014 settling credits on Base\u2026";
4280
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
4281
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$4", alignItems: "center", padding: "$4", children: [
4282
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Spinner, { size: "lg" }),
4283
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { center: true, secondary: true, children: message })
5999
+ content = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
6000
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { gap: "$4", alignItems: "center", padding: "$4", children: [
6001
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Spinner, { size: "lg" }),
6002
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { center: true, secondary: true, children: message })
4284
6003
  ] }) }),
4285
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(AiCreditsFlowStepper, { state, buyerPubKeySaved: true })
6004
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(AiCreditsFlowStepper, { state, buyerPubKeySaved: true })
4286
6005
  ] });
4287
6006
  } else {
4288
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
4289
- state.address && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
6007
+ content = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
6008
+ state.error && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(AiCreditsStatusNotice, { children: [
6009
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$error", fontWeight: "700", children: "Deep link unavailable" }),
6010
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: state.error })
6011
+ ] }),
6012
+ state.address && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4290
6013
  AiCreditsHero,
4291
6014
  {
4292
6015
  gBalance: state.gBalance,
4293
6016
  isGoodIdVerified: state.isGoodIdVerified
4294
6017
  }
4295
6018
  ),
4296
- state.error && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(AiCreditsStatusNotice, { children: [
4297
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$error", fontWeight: "700", children: "Request Failed" }),
4298
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: state.error })
6019
+ state.error && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(AiCreditsStatusNotice, { children: [
6020
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$error", fontWeight: "700", children: "Request Failed" }),
6021
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: state.error })
4299
6022
  ] }),
4300
- state.gBalance !== null && Number.parseFloat(state.gBalance) <= 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(AiCreditsStatusNotice, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: "You need G$ before you can buy AI credits." }) }),
4301
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
6023
+ state.gBalance !== null && Number.parseFloat(state.gBalance) <= 0 && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(AiCreditsStatusNotice, { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: "You need G$ before you can buy AI credits." }) }),
6024
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4302
6025
  AiCreditsPurchaseFlow,
4303
6026
  {
4304
6027
  state,
@@ -4309,16 +6032,13 @@ function BuyCreditsPanel({ state, actions, isPending, onPay }) {
4309
6032
  )
4310
6033
  ] });
4311
6034
  }
4312
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$4", children: [
4313
- content,
4314
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(BuyCreditsFaq, {})
4315
- ] });
6035
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.YStack, { gap: "$4", children: content });
4316
6036
  }
4317
6037
  function ManagePanel({
4318
6038
  state,
4319
6039
  actions
4320
6040
  }) {
4321
- const [refreshing, setRefreshing] = import_react14.default.useState(false);
6041
+ const [refreshing, setRefreshing] = import_react17.default.useState(false);
4322
6042
  const handleRefresh = async () => {
4323
6043
  setRefreshing(true);
4324
6044
  try {
@@ -4327,15 +6047,15 @@ function ManagePanel({
4327
6047
  setRefreshing(false);
4328
6048
  }
4329
6049
  };
4330
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$3", width: "100%", children: [
4331
- state.error && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(AiCreditsStatusNotice, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$error", fontSize: "$2", children: state.error }) }),
4332
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(CreditsManagementCard, { state, actions }),
4333
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(BuyerOperatorCard, { state, actions }),
4334
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SetupSnippet, {}),
4335
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$2", width: "100%", alignItems: "center", children: [
4336
- state.error && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$error", fontSize: "$2", textAlign: "center", children: state.error }),
4337
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
4338
- import_ui16.Button,
6050
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { gap: "$3", width: "100%", children: [
6051
+ state.error && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(AiCreditsStatusNotice, { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$error", fontSize: "$2", children: state.error }) }),
6052
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(CreditsManagementCard, { state, actions }),
6053
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(BuyerOperatorCard, { state, actions }),
6054
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SetupSnippet, {}),
6055
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { gap: "$2", width: "100%", alignItems: "center", children: [
6056
+ state.error && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$error", fontSize: "$2", textAlign: "center", children: state.error }),
6057
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
6058
+ import_ui21.Button,
4339
6059
  {
4340
6060
  variant: "outline",
4341
6061
  size: "sm",
@@ -4347,8 +6067,8 @@ function ManagePanel({
4347
6067
  void handleRefresh();
4348
6068
  },
4349
6069
  children: [
4350
- refreshing ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Spinner, { size: "sm" }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Icon, { name: "refresh", size: "sm", color: "muted" }),
4351
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.ButtonText, { children: refreshing ? "Refreshing\u2026" : "Refresh Balance" })
6070
+ refreshing ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Spinner, { size: "sm" }) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Icon, { name: "refresh", size: "sm", color: "muted" }),
6071
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.ButtonText, { children: refreshing ? "Refreshing\u2026" : "Refresh Balance" })
4352
6072
  ]
4353
6073
  }
4354
6074
  )
@@ -4366,7 +6086,9 @@ function AiCreditsInner({
4366
6086
  adapterFactory,
4367
6087
  adapterOptions,
4368
6088
  onPaySuccess,
4369
- onPayError
6089
+ onPayError,
6090
+ showWalletControls = false,
6091
+ hasDisconnectOverride = false
4370
6092
  }) {
4371
6093
  const defaultAdapter = useAiCreditsAdapter({
4372
6094
  environment,
@@ -4383,33 +6105,41 @@ function AiCreditsInner({
4383
6105
  skipVaultPaymentValidation: adapterOptions?.skipVaultPaymentValidation,
4384
6106
  prepareSettlement: adapterOptions?.prepareSettlement
4385
6107
  });
4386
- const activeAdapter = (0, import_react14.useMemo)(
4387
- () => adapterFactory ? adapterFactory({ environment, backendUrl }) : defaultAdapter,
4388
- [adapterFactory, environment, backendUrl, defaultAdapter]
6108
+ const factoryAdapter = (0, import_react17.useMemo)(
6109
+ () => adapterFactory ? adapterFactory({ environment, backendUrl }) : null,
6110
+ [adapterFactory, environment, backendUrl]
4389
6111
  );
6112
+ const activeAdapter = factoryAdapter ?? defaultAdapter;
4390
6113
  const { state, actions } = activeAdapter;
6114
+ const onBuyersDiscoveredRef = import_react17.default.useRef(actions.discoverBuyers);
6115
+ onBuyersDiscoveredRef.current = actions.discoverBuyers;
6116
+ const onBuyersDiscovered = (0, import_react17.useCallback)((addresses) => {
6117
+ onBuyersDiscoveredRef.current(addresses);
6118
+ }, []);
4391
6119
  const history = useAiCreditsHistory({
4392
6120
  address: state.address,
4393
6121
  backendUrl,
6122
+ defaultBuyerFilter: state.buyerPubKey ?? "all",
4394
6123
  environment,
4395
- backendClient: adapterOptions?.backendClient
6124
+ backendClient: adapterOptions?.backendClient,
6125
+ onBuyersDiscovered
4396
6126
  });
4397
- const handlePay = (0, import_react14.useCallback)(
6127
+ const handlePay = (0, import_react17.useCallback)(
4398
6128
  async (quote) => {
4399
- const toastId = (0, import_ui16.createToast)({
6129
+ const toastId = (0, import_ui21.createToast)({
4400
6130
  message: "Submitting Celo transaction\u2026",
4401
6131
  status: "pending",
4402
6132
  duration: 0
4403
6133
  });
4404
6134
  try {
4405
6135
  await actions.pay(quote);
4406
- (0, import_ui16.updateToast)(toastId, {
6136
+ (0, import_ui21.updateToast)(toastId, {
4407
6137
  message: "Credits added successfully!",
4408
6138
  status: "success",
4409
6139
  duration: 4e3
4410
6140
  });
4411
6141
  } catch (err) {
4412
- (0, import_ui16.updateToast)(toastId, {
6142
+ (0, import_ui21.updateToast)(toastId, {
4413
6143
  message: err instanceof Error ? err.message : state.error ?? "Payment failed. Try again.",
4414
6144
  status: "error",
4415
6145
  duration: 4e3
@@ -4418,47 +6148,117 @@ function AiCreditsInner({
4418
6148
  },
4419
6149
  [actions, state.error]
4420
6150
  );
6151
+ const [helpView, setHelpView] = (0, import_react17.useState)(null);
4421
6152
  const isPending = state.status === "payment_pending" || state.status === "payment_confirmed";
4422
- const handleTabChange = (0, import_react14.useCallback)(
6153
+ const handleTabChange = (0, import_react17.useCallback)(
4423
6154
  (tabId) => {
6155
+ if (tabId !== "setup") {
6156
+ setHelpView(null);
6157
+ }
4424
6158
  actions.setActiveTab(tabId);
4425
6159
  },
4426
6160
  [actions]
4427
6161
  );
4428
- const buyPanel = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4429
- BuyCreditsPanel,
4430
- {
4431
- state,
4432
- actions,
4433
- isPending,
4434
- onPay: (quote) => {
4435
- void handlePay(quote);
4436
- }
4437
- }
6162
+ const { disconnect, disconnectLabel, disconnectIcon } = (0, import_core2.useWallet)();
6163
+ const handleDisconnect = (0, import_react17.useCallback)(async () => {
6164
+ await disconnect();
6165
+ setHelpView(null);
6166
+ actions.setActiveTab("setup");
6167
+ }, [actions, disconnect]);
6168
+ const walletRequired = needsWalletConnection(state);
6169
+ const handleHelpViewOpen = (0, import_react17.useCallback)(
6170
+ (view) => {
6171
+ actions.setActiveTab("setup");
6172
+ setHelpView(view);
6173
+ },
6174
+ [actions]
4438
6175
  );
4439
- if (state.status === "disconnected" || state.status === "connecting") {
4440
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.YStack, { gap: "$3", padding: "$3", width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DisconnectedPanel, { onConnect: actions.connect, connecting: state.status === "connecting" }) });
4441
- }
4442
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$3", padding: "$3", width: "100%", children: [
4443
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4444
- import_ui16.WidgetTabs,
6176
+ const handleHelpViewClose = (0, import_react17.useCallback)(() => {
6177
+ setHelpView(null);
6178
+ }, []);
6179
+ const setupPanel = helpView === "how-to-use" ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(HowToUseView, { onBack: handleHelpViewClose }) : helpView === "faq" ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SetupFaqView, { onBack: handleHelpViewClose }) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SetupTabPanel, { state, actions, onConnect: actions.connect });
6180
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { gap: "$3", padding: "$3", width: "100%", children: [
6181
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
6182
+ import_ui21.XStack,
6183
+ {
6184
+ justifyContent: "space-between",
6185
+ alignItems: "center",
6186
+ gap: "$2",
6187
+ paddingHorizontal: "$1",
6188
+ children: [
6189
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Heading, { level: 4, children: "GoodDollar" }),
6190
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.XStack, { gap: "$2", alignItems: "center", flexShrink: 1, minWidth: 0, children: [
6191
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Badge, { type: "info", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.BadgeText, { children: (0, import_ui21.getChainDisplayName)(state.chainId ?? CELO_CHAIN_ID3) }) }),
6192
+ showWalletControls && state.address && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
6193
+ WalletChip,
6194
+ {
6195
+ address: state.address,
6196
+ onDisconnect: hasDisconnectOverride ? handleDisconnect : void 0,
6197
+ disconnectLabel: hasDisconnectOverride ? disconnectLabel : void 0,
6198
+ disconnectIcon: hasDisconnectOverride ? disconnectIcon : void 0
6199
+ }
6200
+ )
6201
+ ] })
6202
+ ]
6203
+ }
6204
+ ),
6205
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
6206
+ SetupGuidanceCard,
6207
+ {
6208
+ activeHelpView: helpView,
6209
+ onHowToUse: () => {
6210
+ handleHelpViewOpen("how-to-use");
6211
+ },
6212
+ onFaq: () => {
6213
+ handleHelpViewOpen("faq");
6214
+ },
6215
+ depositBonusPercent: state.depositBonusPercent,
6216
+ streamBonusPercent: state.streamBonusPercent,
6217
+ isGoodIdVerified: state.isGoodIdVerified
6218
+ }
6219
+ ),
6220
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
6221
+ import_ui21.WidgetTabs,
4445
6222
  {
4446
6223
  tabs: [
6224
+ { id: "setup", label: "Setup" },
4447
6225
  { id: "buy", label: "Buy Credits" },
4448
6226
  { id: "manage", label: "Manage" },
4449
6227
  { id: "history", label: "History" }
4450
6228
  ],
4451
- activeTab: state.activeTab,
6229
+ activeTab: walletRequired ? "setup" : state.activeTab,
4452
6230
  onTabChange: handleTabChange,
4453
- chainId: state.chainId ?? CELO_CHAIN_ID3
6231
+ isTabDisabled: (tabId) => walletRequired && tabId !== "setup",
6232
+ withConnectionStatus: false
4454
6233
  }
4455
6234
  ),
4456
- state.activeTab === "manage" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ManagePanel, { state, actions }) : state.activeTab === "history" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(HistoryTab, { state: history.state, actions: history.actions }) : buyPanel
6235
+ walletRequired || state.activeTab === "setup" ? setupPanel : state.activeTab === "manage" ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ManagePanel, { state, actions }) : state.activeTab === "history" ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
6236
+ HistoryTab,
6237
+ {
6238
+ state: history.state,
6239
+ actions: history.actions,
6240
+ knownBuyers: state.buyers.map((address) => ({ address }))
6241
+ }
6242
+ ) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
6243
+ BuyCreditsPanel,
6244
+ {
6245
+ state,
6246
+ actions,
6247
+ isPending,
6248
+ onPay: (quote) => {
6249
+ void handlePay(quote);
6250
+ }
6251
+ }
6252
+ )
4457
6253
  ] });
4458
6254
  }
4459
6255
  function AiCreditsWidget({
4460
6256
  provider,
4461
6257
  connectOverride,
6258
+ showWalletControls = false,
6259
+ disconnectOverride,
6260
+ disconnectLabel,
6261
+ disconnectIcon,
4462
6262
  environment = "production",
4463
6263
  backendUrl,
4464
6264
  baseRpcUrl,
@@ -4475,16 +6275,19 @@ function AiCreditsWidget({
4475
6275
  adapterOptions,
4476
6276
  testId
4477
6277
  }) {
4478
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
6278
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4479
6279
  import_core2.GoodWidgetProvider,
4480
6280
  {
4481
6281
  provider,
4482
6282
  connectOverride,
6283
+ disconnectOverride,
6284
+ disconnectLabel,
6285
+ disconnectIcon,
4483
6286
  config,
4484
6287
  themeOverrides,
4485
6288
  defaultTheme,
4486
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { backgroundColor: "$background", width: "100%", "data-testid": testId, children: [
4487
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
6289
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { backgroundColor: "$background", width: "100%", "data-testid": testId, children: [
6290
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4488
6291
  AiCreditsInner,
4489
6292
  {
4490
6293
  environment,
@@ -4497,10 +6300,12 @@ function AiCreditsWidget({
4497
6300
  adapterFactory,
4498
6301
  adapterOptions,
4499
6302
  onPaySuccess,
4500
- onPayError
6303
+ onPayError,
6304
+ showWalletControls,
6305
+ hasDisconnectOverride: Boolean(disconnectOverride)
4501
6306
  }
4502
6307
  ),
4503
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.ToastContainer, {})
6308
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.ToastContainer, {})
4504
6309
  ] })
4505
6310
  }
4506
6311
  );
@@ -4509,6 +6314,7 @@ function AiCreditsWidget({
4509
6314
  0 && (module.exports = {
4510
6315
  AiCreditsWidget,
4511
6316
  CELO_GOODID_ADDRESS,
6317
+ DEEP_LINK_MANUAL_FALLBACK_HINT,
4512
6318
  DEFAULT_BASE_RPC_URL,
4513
6319
  DEFAULT_CELO_RPC_URL,
4514
6320
  DEFAULT_DISCOUNT_CONFIG,
@@ -4516,9 +6322,18 @@ function AiCreditsWidget({
4516
6322
  UnavailableAiCreditsBackendClient,
4517
6323
  aiCreditsIntegration,
4518
6324
  buildAccountView,
6325
+ clearDeepLinkArtifacts,
6326
+ clearStoredDeepLinkParams,
4519
6327
  createBackendClient,
4520
6328
  createChainClient,
6329
+ deepLinkManualFallbackMessage,
4521
6330
  enrichAccountView,
6331
+ isValidBuyerAddress,
6332
+ isValidOperatorSignature,
6333
+ parseDeepLinkParams,
6334
+ readStoredDeepLinkParams,
6335
+ resolveDeepLinkParams,
6336
+ storeDeepLinkParams,
4522
6337
  totalCreditUsdFromProfile,
4523
6338
  totalCreditUsdFromStatus,
4524
6339
  usdToCredits,