@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.
@@ -1,3 +1,116 @@
1
+ // src/deepLinkParams.ts
2
+ var BUYER_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
3
+ var OPERATOR_SIGNATURE_RE = /^0x[0-9a-fA-F]{128}([0-9a-fA-F]{2})?$/;
4
+ var DEEP_LINK_STORAGE_KEY = "goodwidget.ai-credits.deepLink";
5
+ var DEEP_LINK_MANUAL_FALLBACK_HINT = "Generate or import a signer key manually to continue.";
6
+ function isValidBuyerAddress(value) {
7
+ return BUYER_ADDRESS_RE.test(value.trim());
8
+ }
9
+ function isValidOperatorSignature(value) {
10
+ return OPERATOR_SIGNATURE_RE.test(value.trim());
11
+ }
12
+ function deepLinkManualFallbackMessage(reason) {
13
+ return `${reason} ${DEEP_LINK_MANUAL_FALLBACK_HINT}`;
14
+ }
15
+ function canUseLocalStorage() {
16
+ return typeof window !== "undefined" && typeof window.localStorage !== "undefined";
17
+ }
18
+ function readStoredDeepLinkParams() {
19
+ if (!canUseLocalStorage()) return null;
20
+ try {
21
+ const raw = window.localStorage.getItem(DEEP_LINK_STORAGE_KEY);
22
+ if (!raw) return null;
23
+ const parsed = JSON.parse(raw);
24
+ const buyerAddress = typeof parsed.buyerAddress === "string" ? parsed.buyerAddress.trim() : "";
25
+ const operatorSignature = typeof parsed.operatorSignature === "string" ? parsed.operatorSignature.trim() : "";
26
+ if (!isValidBuyerAddress(buyerAddress) || !isValidOperatorSignature(operatorSignature)) {
27
+ clearStoredDeepLinkParams();
28
+ return null;
29
+ }
30
+ return { buyerAddress, operatorSignature };
31
+ } catch {
32
+ clearStoredDeepLinkParams();
33
+ return null;
34
+ }
35
+ }
36
+ function storeDeepLinkParams(value) {
37
+ if (!canUseLocalStorage()) return;
38
+ try {
39
+ window.localStorage.setItem(
40
+ DEEP_LINK_STORAGE_KEY,
41
+ JSON.stringify({
42
+ buyerAddress: value.buyerAddress.trim(),
43
+ operatorSignature: value.operatorSignature.trim()
44
+ })
45
+ );
46
+ } catch {
47
+ return;
48
+ }
49
+ }
50
+ function clearStoredDeepLinkParams() {
51
+ if (!canUseLocalStorage()) return;
52
+ try {
53
+ window.localStorage.removeItem(DEEP_LINK_STORAGE_KEY);
54
+ } catch {
55
+ return;
56
+ }
57
+ }
58
+ function parseDeepLinkParams(search = typeof window !== "undefined" ? window.location.search : "") {
59
+ const params = typeof search === "string" ? new URLSearchParams(search) : search;
60
+ const buyerAddress = params.get("buyerAddress")?.trim() ?? "";
61
+ const operatorSignature = params.get("operatorSignature")?.trim() ?? "";
62
+ const hasBuyer = buyerAddress.length > 0;
63
+ const hasSignature = operatorSignature.length > 0;
64
+ if (!hasBuyer && !hasSignature) return { status: "absent" };
65
+ if (hasBuyer && !hasSignature) return { status: "partial", present: "buyerAddress" };
66
+ if (!hasBuyer && hasSignature) return { status: "partial", present: "operatorSignature" };
67
+ if (!isValidBuyerAddress(buyerAddress)) {
68
+ return { status: "invalid", reason: "Deep-link buyerAddress is invalid" };
69
+ }
70
+ if (!isValidOperatorSignature(operatorSignature)) {
71
+ return {
72
+ status: "invalid",
73
+ reason: "Deep-link operatorSignature is invalid"
74
+ };
75
+ }
76
+ return {
77
+ status: "complete",
78
+ source: "url",
79
+ value: {
80
+ buyerAddress,
81
+ operatorSignature
82
+ }
83
+ };
84
+ }
85
+ function resolveDeepLinkParams(search = typeof window !== "undefined" ? window.location.search : "") {
86
+ const fromUrl = parseDeepLinkParams(search);
87
+ if (fromUrl.status === "complete") {
88
+ storeDeepLinkParams(fromUrl.value);
89
+ return fromUrl;
90
+ }
91
+ if (fromUrl.status === "partial" || fromUrl.status === "invalid") {
92
+ return fromUrl;
93
+ }
94
+ const stored = readStoredDeepLinkParams();
95
+ if (!stored) return { status: "absent" };
96
+ return { status: "complete", source: "storage", value: stored };
97
+ }
98
+ function stripDeepLinkParamsFromUrl() {
99
+ if (typeof window === "undefined") return;
100
+ const url = new URL(window.location.href);
101
+ if (!url.searchParams.has("buyerAddress") && !url.searchParams.has("operatorSignature")) {
102
+ return;
103
+ }
104
+ url.searchParams.delete("buyerAddress");
105
+ url.searchParams.delete("operatorSignature");
106
+ const next = `${url.pathname}${url.search}${url.hash}`;
107
+ window.history.replaceState(window.history.state, "", next);
108
+ }
109
+ function clearDeepLinkArtifacts() {
110
+ clearStoredDeepLinkParams();
111
+ stripDeepLinkParamsFromUrl();
112
+ }
113
+
1
114
  // src/quoteMath.ts
2
115
  import { parseUnits } from "viem";
3
116
  var CREDITS_PER_USD = 1e4;
@@ -165,13 +278,17 @@ function clampHistoryLimit(limit) {
165
278
  if (limit === void 0) return DEFAULT_HISTORY_LIMIT;
166
279
  return Math.min(Math.max(1, Math.floor(limit)), MAX_HISTORY_LIMIT);
167
280
  }
168
- function resolveBuyerAddress(entries) {
281
+ function collectBuyerAddressesFromEntries(entries) {
282
+ const seen = /* @__PURE__ */ new Set();
283
+ const result = [];
169
284
  for (const entry of entries) {
170
- if (entry.buyerAddress && isAddress(entry.buyerAddress)) {
171
- return normalizeAddress(entry.buyerAddress);
172
- }
285
+ if (!entry.buyerAddress || !isAddress(entry.buyerAddress)) continue;
286
+ const key = normalizeAddress(entry.buyerAddress);
287
+ if (seen.has(key)) continue;
288
+ seen.add(key);
289
+ result.push(key);
173
290
  }
174
- return null;
291
+ return result;
175
292
  }
176
293
  function defaultOperatorStatus(payer) {
177
294
  const account = normalizeAddress(payer);
@@ -409,13 +526,11 @@ async function waitForOperatorConsent(chain, ref) {
409
526
  }
410
527
  async function buildAccountView(payer, backend, chain, options = {}) {
411
528
  const normalizedPayer = normalizeAddress(payer);
412
- const [credit, outstanding, history] = await Promise.all([
529
+ const [credit, outstanding] = await Promise.all([
413
530
  backend.getAccountCredit(payer),
414
- backend.getOutstanding(payer),
415
- backend.getCreditHistory(payer, { limit: MAX_HISTORY_LIMIT, offset: 0 })
531
+ backend.getOutstanding(payer)
416
532
  ]);
417
- const sessionBuyer = options.buyerAddress && isAddress(options.buyerAddress) ? normalizeAddress(options.buyerAddress) : null;
418
- const buyer = sessionBuyer ?? resolveBuyerAddress(history.items);
533
+ const buyer = options.buyerAddress && isAddress(options.buyerAddress) ? normalizeAddress(options.buyerAddress) : null;
419
534
  const [operator, withdrawableUsd] = buyer ? await Promise.all([
420
535
  chain.getBuyerOperatorStatus({ payer: normalizedPayer, buyer }),
421
536
  chain.getWithdrawableUsd(buyer)
@@ -771,40 +886,262 @@ async function signRequestClose(params) {
771
886
  }
772
887
 
773
888
  // src/payerSession.ts
774
- var payerWalletSessions = /* @__PURE__ */ new Map();
889
+ var STORAGE_KEY_PREFIX = "goodwidget.ai-credits.payerSession.";
775
890
  function payerSessionKey(address) {
776
891
  return address.toLowerCase();
777
892
  }
893
+ function normalizeBuyerAddress(address) {
894
+ return address.toLowerCase();
895
+ }
896
+ function canUseLocalStorage2() {
897
+ return typeof window !== "undefined" && typeof window.localStorage !== "undefined";
898
+ }
899
+ function formatBuyerAddress(address) {
900
+ const key = normalizeBuyerAddress(address);
901
+ return key.startsWith("0x") ? `0x${key.slice(2)}` : key;
902
+ }
903
+ function emptySession() {
904
+ return {
905
+ buyerKeys: {},
906
+ knownBuyers: [],
907
+ activeBuyerAddress: null,
908
+ derivedBuyerAddress: null
909
+ };
910
+ }
911
+ function isBuyerKeyEntry(value) {
912
+ if (!value || typeof value !== "object") return false;
913
+ const entry = value;
914
+ 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");
915
+ }
916
+ function migrateLegacySession(raw) {
917
+ const session = emptySession();
918
+ const known = /* @__PURE__ */ new Set();
919
+ const trackKnown = (address) => {
920
+ if (!address) return;
921
+ known.add(normalizeBuyerAddress(address));
922
+ };
923
+ if (typeof raw.buyerPubKey === "string" && raw.buyerPubKey) {
924
+ const address = normalizeBuyerAddress(raw.buyerPubKey);
925
+ session.activeBuyerAddress = address;
926
+ session.derivedBuyerAddress = address;
927
+ trackKnown(address);
928
+ if (typeof raw.buyerPrvKey === "string" && raw.buyerPrvKey) {
929
+ session.buyerKeys[address] = { privateKey: raw.buyerPrvKey };
930
+ }
931
+ }
932
+ if (Array.isArray(raw.buyers)) {
933
+ for (const item of raw.buyers) {
934
+ if (typeof item === "string" && item) {
935
+ trackKnown(item);
936
+ continue;
937
+ }
938
+ if (!item || typeof item !== "object") continue;
939
+ const buyer = item;
940
+ if (typeof buyer.address !== "string" || !buyer.address) continue;
941
+ const address = normalizeBuyerAddress(buyer.address);
942
+ trackKnown(address);
943
+ const entry = {};
944
+ if (typeof buyer.privateKey === "string" && buyer.privateKey) {
945
+ entry.privateKey = buyer.privateKey;
946
+ }
947
+ if (typeof buyer.operatorSignature === "string" && buyer.operatorSignature) {
948
+ entry.operatorSignature = buyer.operatorSignature;
949
+ }
950
+ if (typeof buyer.operatorConsented === "boolean") {
951
+ entry.operatorConsented = buyer.operatorConsented;
952
+ }
953
+ if (entry.privateKey || entry.operatorSignature || entry.operatorConsented !== void 0) {
954
+ session.buyerKeys[address] = {
955
+ ...session.buyerKeys[address],
956
+ ...entry
957
+ };
958
+ }
959
+ if (buyer.type === "derived" && entry.privateKey) {
960
+ session.derivedBuyerAddress = address;
961
+ }
962
+ }
963
+ }
964
+ if (Array.isArray(raw.knownBuyers)) {
965
+ for (const item of raw.knownBuyers) {
966
+ if (typeof item === "string" && item) trackKnown(item);
967
+ }
968
+ }
969
+ if (typeof raw.activeBuyerAddress === "string" && raw.activeBuyerAddress) {
970
+ session.activeBuyerAddress = normalizeBuyerAddress(raw.activeBuyerAddress);
971
+ trackKnown(session.activeBuyerAddress);
972
+ }
973
+ if (typeof raw.derivedBuyerAddress === "string" && raw.derivedBuyerAddress) {
974
+ session.derivedBuyerAddress = normalizeBuyerAddress(raw.derivedBuyerAddress);
975
+ trackKnown(session.derivedBuyerAddress);
976
+ }
977
+ if (typeof raw.operatorSignature === "string" && raw.operatorSignature && session.activeBuyerAddress) {
978
+ const active = session.activeBuyerAddress;
979
+ session.buyerKeys[active] = {
980
+ ...session.buyerKeys[active],
981
+ operatorSignature: raw.operatorSignature
982
+ };
983
+ }
984
+ if (raw.buyerKeys && typeof raw.buyerKeys === "object") {
985
+ for (const [address, entry] of Object.entries(raw.buyerKeys)) {
986
+ if (!isBuyerKeyEntry(entry)) continue;
987
+ const key = normalizeBuyerAddress(address);
988
+ trackKnown(key);
989
+ session.buyerKeys[key] = {
990
+ ...session.buyerKeys[key],
991
+ ...entry
992
+ };
993
+ }
994
+ }
995
+ if (typeof raw.operatorConsented === "boolean" && raw.operatorConsented && session.activeBuyerAddress) {
996
+ const active = session.activeBuyerAddress;
997
+ session.buyerKeys[active] = {
998
+ ...session.buyerKeys[active],
999
+ operatorConsented: true
1000
+ };
1001
+ }
1002
+ session.knownBuyers = [...known].map((key) => formatBuyerAddress(key));
1003
+ return session;
1004
+ }
1005
+ function parseStoredSession(raw) {
1006
+ try {
1007
+ const parsed = JSON.parse(raw);
1008
+ return migrateLegacySession(parsed);
1009
+ } catch {
1010
+ return null;
1011
+ }
1012
+ }
1013
+ function persistSession(address, session) {
1014
+ if (!canUseLocalStorage2()) return;
1015
+ try {
1016
+ window.localStorage.setItem(
1017
+ `${STORAGE_KEY_PREFIX}${payerSessionKey(address)}`,
1018
+ JSON.stringify(session)
1019
+ );
1020
+ } catch {
1021
+ return;
1022
+ }
1023
+ }
778
1024
  function readPayerSession(address) {
779
- if (!address) return null;
780
- return payerWalletSessions.get(payerSessionKey(address)) ?? null;
1025
+ if (!address || !canUseLocalStorage2()) return null;
1026
+ try {
1027
+ const raw = window.localStorage.getItem(
1028
+ `${STORAGE_KEY_PREFIX}${payerSessionKey(address)}`
1029
+ );
1030
+ if (!raw) return null;
1031
+ return parseStoredSession(raw);
1032
+ } catch {
1033
+ return null;
1034
+ }
1035
+ }
1036
+ function getBuyerKeyEntry(payer, buyerAddress) {
1037
+ const session = readPayerSession(payer);
1038
+ if (!session) return null;
1039
+ return session.buyerKeys[normalizeBuyerAddress(buyerAddress)] ?? null;
781
1040
  }
782
- function patchPayerSession(address, patch) {
783
- const existing = readPayerSession(address);
784
- payerWalletSessions.set(payerSessionKey(address), {
785
- operatorConsented: false,
1041
+ function setBuyerOperatorConsented(payer, buyerAddress, operatorConsented) {
1042
+ upsertBuyerKey(payer, buyerAddress, { operatorConsented }, { setActive: false });
1043
+ }
1044
+ function upsertBuyerKey(payer, buyerAddress, entry, options) {
1045
+ const existing = readPayerSession(payer) ?? emptySession();
1046
+ const key = normalizeBuyerAddress(buyerAddress);
1047
+ const previous = existing.buyerKeys[key] ?? {};
1048
+ const knownBuyers = mergeBuyerAddressList(existing.knownBuyers, key);
1049
+ const next = {
786
1050
  ...existing,
787
- ...patch
788
- });
1051
+ knownBuyers,
1052
+ buyerKeys: {
1053
+ ...existing.buyerKeys,
1054
+ [key]: {
1055
+ privateKey: entry.privateKey ?? previous.privateKey,
1056
+ operatorSignature: entry.operatorSignature ?? previous.operatorSignature,
1057
+ operatorConsented: entry.operatorConsented !== void 0 ? entry.operatorConsented : previous.operatorConsented
1058
+ }
1059
+ },
1060
+ activeBuyerAddress: options?.setActive === false ? existing.activeBuyerAddress : key,
1061
+ derivedBuyerAddress: options?.setDerived ? key : existing.derivedBuyerAddress
1062
+ };
1063
+ persistSession(payer, next);
1064
+ return next;
1065
+ }
1066
+ function setActiveBuyerAddress(payer, buyerAddress) {
1067
+ const existing = readPayerSession(payer) ?? emptySession();
1068
+ const normalized = buyerAddress ? normalizeBuyerAddress(buyerAddress) : null;
1069
+ const next = {
1070
+ ...existing,
1071
+ knownBuyers: normalized ? mergeBuyerAddressList(existing.knownBuyers, normalized) : existing.knownBuyers,
1072
+ activeBuyerAddress: normalized
1073
+ };
1074
+ persistSession(payer, next);
1075
+ return next;
1076
+ }
1077
+ function mergeBuyerAddressList(existingBuyers, ...extras) {
1078
+ const seen = /* @__PURE__ */ new Set();
1079
+ const result = [];
1080
+ for (const address of [...existingBuyers, ...extras]) {
1081
+ if (!address) continue;
1082
+ const key = normalizeBuyerAddress(address);
1083
+ if (seen.has(key)) continue;
1084
+ seen.add(key);
1085
+ result.push(formatBuyerAddress(key));
1086
+ }
1087
+ return result;
1088
+ }
1089
+ function listKnownBuyerAddresses(payer) {
1090
+ const session = readPayerSession(payer);
1091
+ if (!session) return [];
1092
+ return mergeBuyerAddressList(
1093
+ session.knownBuyers,
1094
+ ...Object.keys(session.buyerKeys),
1095
+ session.activeBuyerAddress,
1096
+ session.derivedBuyerAddress
1097
+ );
1098
+ }
1099
+ function rememberBuyerAddresses(payer, addresses) {
1100
+ const existing = readPayerSession(payer) ?? emptySession();
1101
+ const knownBuyers = mergeBuyerAddressList(existing.knownBuyers, ...addresses);
1102
+ if (knownBuyers.length === existing.knownBuyers.length && knownBuyers.every(
1103
+ (address, index) => address.toLowerCase() === existing.knownBuyers[index]?.toLowerCase()
1104
+ )) {
1105
+ return listKnownBuyerAddresses(payer);
1106
+ }
1107
+ persistSession(payer, { ...existing, knownBuyers });
1108
+ return listKnownBuyerAddresses(payer);
1109
+ }
1110
+ function buildBuyerStateFields(payer, buyers, selectedAddress) {
1111
+ const session = readPayerSession(payer);
1112
+ const entry = selectedAddress ? getBuyerKeyEntry(payer, selectedAddress) : null;
1113
+ return {
1114
+ buyers,
1115
+ buyerPubKey: selectedAddress,
1116
+ buyerPrvKey: entry?.privateKey ?? null,
1117
+ operatorSignature: entry?.operatorSignature ?? null,
1118
+ operatorConsented: Boolean(entry?.operatorConsented),
1119
+ derivedBuyerAddress: session?.derivedBuyerAddress ?? null
1120
+ };
789
1121
  }
790
1122
  function patchPayerSessionFields(address) {
791
1123
  const session = readPayerSession(address);
792
1124
  if (!session) {
793
1125
  return {
1126
+ buyerPubKey: null,
794
1127
  buyerPrvKey: null,
795
- operatorConsented: false
1128
+ operatorSignature: null,
1129
+ operatorConsented: false,
1130
+ activeBuyerAddress: null,
1131
+ derivedBuyerAddress: null
796
1132
  };
797
1133
  }
1134
+ const active = session.activeBuyerAddress;
1135
+ const entry = active ? session.buyerKeys[normalizeBuyerAddress(active)] : void 0;
798
1136
  return {
799
- buyerPubKey: session.buyerPubKey,
800
- buyerPrvKey: session.buyerPrvKey ?? null,
801
- operatorConsented: session.operatorConsented
1137
+ buyerPubKey: active,
1138
+ buyerPrvKey: entry?.privateKey ?? null,
1139
+ operatorSignature: entry?.operatorSignature ?? null,
1140
+ operatorConsented: Boolean(entry?.operatorConsented),
1141
+ activeBuyerAddress: active,
1142
+ derivedBuyerAddress: session.derivedBuyerAddress
802
1143
  };
803
1144
  }
804
- function addressesMatch(a, b) {
805
- if (!a || !b) return false;
806
- return payerSessionKey(a) === payerSessionKey(b);
807
- }
808
1145
 
809
1146
  // src/celoPayment.ts
810
1147
  import {
@@ -1088,7 +1425,7 @@ function getPayDisabledMessage(params) {
1088
1425
  if (params.validation.streamBelowMin && params.minStreamUsd) {
1089
1426
  return `Monthly stream must be at least ${formatMinUsdDisplay(params.minStreamUsd)}.`;
1090
1427
  }
1091
- if (params.status !== "quote_ready") {
1428
+ if (params.status !== "quote_ready" && params.status !== "payment_failed") {
1092
1429
  return "Enter a deposit or change the monthly stream amount to continue.";
1093
1430
  }
1094
1431
  return "Adjust the amounts to continue.";
@@ -1224,8 +1561,11 @@ var INITIAL_STATE = {
1224
1561
  isGoodIdVerified: false,
1225
1562
  buyerPubKey: null,
1226
1563
  buyerPrvKey: null,
1564
+ operatorSignature: null,
1227
1565
  operatorConsented: false,
1566
+ operatorConsentPending: false,
1228
1567
  operatorAddress: null,
1568
+ currentOperator: null,
1229
1569
  minDepositUsd: null,
1230
1570
  minStreamUsd: null,
1231
1571
  totalGdDepositedG: null,
@@ -1234,7 +1574,9 @@ var INITIAL_STATE = {
1234
1574
  depositBonusPercent: DEFAULT_DISCOUNT_CONFIG.depositBonusPercent,
1235
1575
  streamBonusPercent: DEFAULT_DISCOUNT_CONFIG.streamBonusPercent,
1236
1576
  error: null,
1237
- activeTab: "buy"
1577
+ activeTab: "setup",
1578
+ buyers: [],
1579
+ derivedBuyerAddress: null
1238
1580
  };
1239
1581
  var WALLET_LOADING_STATE = {
1240
1582
  gBalance: null,
@@ -1246,17 +1588,59 @@ var WALLET_LOADING_STATE = {
1246
1588
  totalGdDepositedG: null,
1247
1589
  monthlyStreamG: null,
1248
1590
  withdrawableUsd: null,
1249
- operatorAddress: null
1591
+ operatorAddress: null,
1592
+ currentOperator: null
1250
1593
  };
1594
+ var BUYER_HISTORY_LOOKUP_LIMIT = 100;
1595
+ function resolveLocalBuyers(payer, preferredBuyer, ...extras) {
1596
+ const buyers = rememberBuyerAddresses(payer, [
1597
+ preferredBuyer,
1598
+ ...listKnownBuyerAddresses(payer),
1599
+ ...extras
1600
+ ]);
1601
+ return { buyers, selected: selectPreferredBuyer(buyers, preferredBuyer) };
1602
+ }
1603
+ async function discoverBuyersFromHistory(payer, backend, ...extras) {
1604
+ let historyBuyers = [];
1605
+ try {
1606
+ const history = await backend.getCreditHistory(payer, {
1607
+ limit: BUYER_HISTORY_LOOKUP_LIMIT,
1608
+ offset: 0
1609
+ });
1610
+ historyBuyers = collectBuyerAddressesFromEntries(history.items);
1611
+ } catch {
1612
+ historyBuyers = [];
1613
+ }
1614
+ return rememberBuyerAddresses(payer, [...historyBuyers, ...extras]);
1615
+ }
1616
+ function selectPreferredBuyer(buyers, preferredBuyer) {
1617
+ if (preferredBuyer && buyers.some((item) => item.toLowerCase() === preferredBuyer.toLowerCase())) {
1618
+ return preferredBuyer;
1619
+ }
1620
+ return buyers[0] ?? preferredBuyer ?? null;
1621
+ }
1251
1622
  function isNonBuyTab(tab) {
1252
- return tab === "manage" || tab === "history";
1623
+ return tab === "setup" || tab === "manage" || tab === "history";
1624
+ }
1625
+ function needsWalletConnection(state) {
1626
+ return !state.address || state.status === "disconnected" || state.status === "connecting";
1627
+ }
1628
+ function resolveDefaultActiveTab(payerAddress, totalCreditUsd) {
1629
+ if (hasCreditBalance(totalCreditUsd)) return "manage";
1630
+ if (payerAddress && listKnownBuyerAddresses(payerAddress).length > 0) return "buy";
1631
+ return "setup";
1253
1632
  }
1254
1633
  function resolveActiveTab(prev, overrides) {
1255
1634
  if (overrides.activeTab !== void 0) return overrides.activeTab;
1635
+ const payerAddress = overrides.address !== void 0 ? overrides.address : prev.address;
1636
+ const totalCreditUsd = overrides.totalCreditUsd !== void 0 ? overrides.totalCreditUsd : prev.totalCreditUsd;
1256
1637
  if (overrides.totalCreditUsd !== void 0 && overrides.totalCreditUsd !== null) {
1257
- return hasCreditBalance(overrides.totalCreditUsd) ? "manage" : "buy";
1638
+ return resolveDefaultActiveTab(payerAddress, overrides.totalCreditUsd);
1258
1639
  }
1259
- return prev.activeTab ?? "buy";
1640
+ if (overrides.address !== void 0 && overrides.address !== prev.address) {
1641
+ return resolveDefaultActiveTab(payerAddress, totalCreditUsd);
1642
+ }
1643
+ return prev.activeTab ?? resolveDefaultActiveTab(payerAddress, totalCreditUsd);
1260
1644
  }
1261
1645
  function hasCreditBalance(totalCreditUsd) {
1262
1646
  return totalCreditUsd !== null && BigInt(totalCreditUsd) > 0n;
@@ -1314,7 +1698,7 @@ function mergeStatePreservingNonBuyTab(prev, overrides) {
1314
1698
  }
1315
1699
  const activeTab = isNonBuyTab(nextTab) ? nextTab : prev.activeTab;
1316
1700
  const status = deriveStatus({
1317
- isConnected: true,
1701
+ isConnected: !needsWalletConnection(prev),
1318
1702
  chainId: overrides.chainId ?? prev.chainId,
1319
1703
  gBalance: overrides.gBalance ?? prev.gBalance,
1320
1704
  buyerPubKey: overrides.buyerPubKey ?? prev.buyerPubKey,
@@ -1338,31 +1722,15 @@ function viewToStatePatch(view, enriched, prev, options) {
1338
1722
  isGoodIdVerified: enriched.goodIdVerified,
1339
1723
  operatorConsented: operatorAccepted,
1340
1724
  operatorAddress: view.operator.operatorAddress ?? null,
1725
+ currentOperator: view.operator.currentOperator ?? null,
1341
1726
  withdrawableUsd: view.withdrawableUsd,
1342
1727
  totalGdDepositedG: enriched.totalGdDepositedG,
1343
- monthlyStreamG: enriched.monthlyStreamG,
1344
- ...view.buyer ? { buyerPubKey: view.buyer } : {}
1345
- };
1346
- }
1347
- function mergeSessionFields(prev, sessionPatch, accountPatch, accountSwitched) {
1348
- const buyerPubKey = sessionPatch.buyerPubKey ?? accountPatch.buyerPubKey ?? (accountSwitched ? null : prev.buyerPubKey);
1349
- const buyerPrvKey = sessionPatch.buyerPrvKey ?? (accountSwitched ? null : prev.buyerPrvKey);
1350
- const operatorConsented = accountSwitched ? sessionPatch.operatorConsented ?? accountPatch.operatorConsented ?? false : accountPatch.operatorConsented ?? sessionPatch.operatorConsented ?? prev.operatorConsented;
1351
- return {
1352
- buyerPubKey,
1353
- buyerPrvKey,
1354
- operatorConsented
1728
+ monthlyStreamG: enriched.monthlyStreamG
1355
1729
  };
1356
1730
  }
1357
- function syncOperatorConsentSession(address, operatorConsented) {
1358
- if (operatorConsented === void 0) return;
1359
- patchPayerSession(address, { operatorConsented });
1360
- }
1361
- function syncBuyerPubKeySession(address, buyerPubKey) {
1362
- if (!buyerPubKey) return;
1363
- const existing = readPayerSession(address);
1364
- if (existing?.buyerPubKey) return;
1365
- patchPayerSession(address, { buyerPubKey });
1731
+ function activateBuyerSelection(payer, buyers, selectedAddress) {
1732
+ setActiveBuyerAddress(payer, selectedAddress);
1733
+ return buildBuyerStateFields(payer, buyers, selectedAddress);
1366
1734
  }
1367
1735
  function useAiCreditsAdapter({
1368
1736
  environment = "production",
@@ -1386,6 +1754,9 @@ function useAiCreditsAdapter({
1386
1754
  const providerRef = useRef(null);
1387
1755
  providerRef.current = provider;
1388
1756
  const goodIdVerifyPendingRef = useRef(false);
1757
+ const pendingDeepLinkRef = useRef(null);
1758
+ const deepLinkParseDoneRef = useRef(false);
1759
+ const deepLinkApplyInFlightRef = useRef(false);
1389
1760
  const celoVault = vaultAddress ?? CELO_GD_ANTSEED_VAULT_FALLBACK;
1390
1761
  const backendClient = useMemo(
1391
1762
  () => backendClientOverride ?? createBackendClient(backendUrl),
@@ -1403,7 +1774,11 @@ function useAiCreditsAdapter({
1403
1774
  );
1404
1775
  useEffect(() => {
1405
1776
  if (!isConnected || !address) {
1406
- setState((prev) => prev.status === "connecting" ? prev : { ...INITIAL_STATE });
1777
+ setState((prev) => {
1778
+ if (prev.status === "connecting") return prev;
1779
+ if (!prev.address && prev.status === "disconnected" && prev.error === null) return prev;
1780
+ return { ...INITIAL_STATE };
1781
+ });
1407
1782
  return;
1408
1783
  }
1409
1784
  if (configurationError) {
@@ -1422,14 +1797,17 @@ function useAiCreditsAdapter({
1422
1797
  if (prev.status === "payment_pending" || prev.status === "payment_confirmed" || prev.status === "payment_failed") {
1423
1798
  return prev;
1424
1799
  }
1425
- const accountSwitched = !addressesMatch(prev.address, address);
1426
- const buyerFields = mergeSessionFields(prev, sessionPatch, {}, accountSwitched);
1427
1800
  return withDerivedStatus(
1428
1801
  prev,
1429
1802
  {
1430
1803
  address,
1431
1804
  chainId,
1432
- ...buyerFields,
1805
+ buyerPubKey: sessionPatch.buyerPubKey,
1806
+ buyerPrvKey: sessionPatch.buyerPrvKey,
1807
+ operatorSignature: sessionPatch.operatorSignature,
1808
+ operatorConsented: sessionPatch.operatorConsented,
1809
+ derivedBuyerAddress: sessionPatch.derivedBuyerAddress,
1810
+ buyers: prev.buyers,
1433
1811
  ...WALLET_LOADING_STATE,
1434
1812
  error: null,
1435
1813
  status: "connecting"
@@ -1452,8 +1830,11 @@ function useAiCreditsAdapter({
1452
1830
  functionName: "decimals"
1453
1831
  })
1454
1832
  ]);
1455
- const accountPromise = buildAccountView(address, backendClient, chainClient, {
1456
- buyerAddress: sessionPatch.buyerPubKey ?? null
1833
+ const pendingDeepLink = pendingDeepLinkRef.current;
1834
+ const sessionBuyer = patchPayerSessionFields(address).buyerPubKey;
1835
+ const preferredBuyer = pendingDeepLink?.buyerAddress ?? sessionBuyer ?? null;
1836
+ const accountPromise = pendingDeepLink || deepLinkApplyInFlightRef.current ? Promise.resolve(null) : buildAccountView(address, backendClient, chainClient, {
1837
+ buyerAddress: preferredBuyer
1457
1838
  }).then(async (view) => ({
1458
1839
  view,
1459
1840
  enriched: await enrichAccountView(view, chainClient)
@@ -1464,13 +1845,25 @@ function useAiCreditsAdapter({
1464
1845
  }) : fetchVaultPaymentMinimums(publicClient, celoVault, address).catch(() => null);
1465
1846
  const gdUsdPerTokenPromise = chainClient.fetchGdUsdPerToken().catch(() => null);
1466
1847
  const discountConfigPromise = backendClient.getDiscountConfig().catch(() => null);
1848
+ const buyersPromise = pendingDeepLink ? Promise.resolve(
1849
+ rememberBuyerAddresses(address, [
1850
+ preferredBuyer,
1851
+ ...listKnownBuyerAddresses(address)
1852
+ ])
1853
+ ) : discoverBuyersFromHistory(
1854
+ address,
1855
+ backendClient,
1856
+ preferredBuyer,
1857
+ ...listKnownBuyerAddresses(address)
1858
+ );
1467
1859
  try {
1468
- const [[rawBalance, decimals], account, minimums, gdUsdPerToken, discountConfig] = await Promise.all([
1860
+ const [[rawBalance, decimals], account, minimums, gdUsdPerToken, discountConfig, buyers] = await Promise.all([
1469
1861
  balancePromise,
1470
1862
  accountPromise,
1471
1863
  minimumsPromise,
1472
1864
  gdUsdPerTokenPromise,
1473
- discountConfigPromise
1865
+ discountConfigPromise,
1866
+ buyersPromise
1474
1867
  ]);
1475
1868
  if (cancelled) return;
1476
1869
  const patch = {
@@ -1483,41 +1876,54 @@ function useAiCreditsAdapter({
1483
1876
  depositBonusPercent: discountConfig?.depositBonusPercent ?? DEFAULT_DISCOUNT_CONFIG.depositBonusPercent,
1484
1877
  streamBonusPercent: discountConfig?.streamBonusPercent ?? DEFAULT_DISCOUNT_CONFIG.streamBonusPercent
1485
1878
  };
1486
- setState((prev) => {
1487
- const accountSwitched = !addressesMatch(prev.address, address);
1488
- const accountPatch = account ? viewToStatePatch(account.view, account.enriched, prev, {
1489
- balanceMode: "always"
1490
- }) : {};
1491
- const buyerFields = mergeSessionFields(prev, sessionPatch, accountPatch, accountSwitched);
1492
- if (address && accountPatch.operatorConsented !== void 0) {
1493
- syncOperatorConsentSession(address, accountPatch.operatorConsented);
1494
- }
1495
- if (address && account?.view.buyer) {
1496
- syncBuyerPubKeySession(address, account.view.buyer);
1497
- }
1498
- return withDerivedStatus(
1879
+ if (pendingDeepLink || deepLinkApplyInFlightRef.current) {
1880
+ setState(
1881
+ (prev) => withDerivedStatus(
1882
+ prev,
1883
+ {
1884
+ ...patch,
1885
+ buyers: mergeBuyerAddressList(prev.buyers, ...buyers)
1886
+ },
1887
+ true
1888
+ )
1889
+ );
1890
+ return;
1891
+ }
1892
+ const selectedBuyer = selectPreferredBuyer(buyers, preferredBuyer);
1893
+ const accountPatch = account ? viewToStatePatch(account.view, account.enriched, INITIAL_STATE, {
1894
+ balanceMode: "always"
1895
+ }) : {};
1896
+ if (selectedBuyer && accountPatch.operatorConsented !== void 0) {
1897
+ setBuyerOperatorConsented(address, selectedBuyer, accountPatch.operatorConsented);
1898
+ }
1899
+ const buyerFields = activateBuyerSelection(address, buyers, selectedBuyer);
1900
+ setState(
1901
+ (prev) => withDerivedStatus(
1499
1902
  prev,
1500
1903
  {
1501
1904
  ...patch,
1502
1905
  ...accountPatch,
1503
1906
  ...buyerFields,
1504
- ...account ? {} : { activeTab: "buy" }
1907
+ operatorConsented: accountPatch.operatorConsented ?? buyerFields.operatorConsented
1505
1908
  },
1506
1909
  true
1507
- );
1508
- });
1910
+ )
1911
+ );
1509
1912
  } catch {
1510
1913
  if (cancelled) return;
1511
1914
  setState((prev) => {
1512
- const accountSwitched = !addressesMatch(prev.address, address);
1513
- const buyerFields = mergeSessionFields(prev, sessionPatch, {}, accountSwitched);
1514
1915
  return withDerivedStatus(
1515
1916
  prev,
1516
1917
  {
1517
1918
  address,
1518
1919
  chainId,
1519
1920
  gBalance: "0",
1520
- ...buyerFields,
1921
+ buyers: [],
1922
+ derivedBuyerAddress: null,
1923
+ buyerPubKey: null,
1924
+ buyerPrvKey: null,
1925
+ operatorSignature: null,
1926
+ operatorConsented: false,
1521
1927
  status: chainId !== null && chainId !== CELO_CHAIN_ID2 ? "unsupported_chain" : "purchase_setup"
1522
1928
  },
1523
1929
  true
@@ -1556,14 +1962,32 @@ function useAiCreditsAdapter({
1556
1962
  setState(
1557
1963
  (prev) => withDerivedStatus(
1558
1964
  prev,
1559
- { error: "Connect your wallet before generating a buyer key" },
1965
+ { error: "Connect your wallet before generating a signer key" },
1560
1966
  true
1561
1967
  )
1562
1968
  );
1563
1969
  return;
1564
1970
  }
1971
+ const payerAddress = address;
1972
+ const session = readPayerSession(payerAddress);
1973
+ const derivedAddress = session?.derivedBuyerAddress ?? null;
1974
+ const existingKey = derivedAddress ? getBuyerKeyEntry(payerAddress, derivedAddress) : null;
1975
+ if (derivedAddress && existingKey?.privateKey) {
1976
+ const buyers = mergeBuyerAddressList(
1977
+ listKnownBuyerAddresses(payerAddress),
1978
+ derivedAddress
1979
+ );
1980
+ const buyerFields = activateBuyerSelection(payerAddress, buyers, derivedAddress);
1981
+ setState(
1982
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
1983
+ ...buyerFields,
1984
+ error: null,
1985
+ ...!isNonBuyTab(prev.activeTab) ? { status: "purchase_setup" } : {}
1986
+ })
1987
+ );
1988
+ return;
1989
+ }
1565
1990
  try {
1566
- const payerAddress = address;
1567
1991
  const message = buildBuyerKeyMessage(payerAddress);
1568
1992
  const walletClient = createWalletClient2({
1569
1993
  account: payerAddress,
@@ -1575,15 +1999,21 @@ function useAiCreditsAdapter({
1575
1999
  message
1576
2000
  });
1577
2001
  const privateKey = deriveBuyerPrivateKeyFromSignature(signature);
1578
- const account = privateKeyToAccount4(privateKey);
1579
- patchPayerSession(payerAddress, {
1580
- buyerPubKey: account.address,
1581
- buyerPrvKey: privateKey
1582
- });
2002
+ const buyerAccount = privateKeyToAccount4(privateKey);
2003
+ upsertBuyerKey(
2004
+ payerAddress,
2005
+ buyerAccount.address,
2006
+ { privateKey },
2007
+ { setActive: true, setDerived: true }
2008
+ );
2009
+ const buyers = mergeBuyerAddressList(
2010
+ listKnownBuyerAddresses(payerAddress),
2011
+ buyerAccount.address
2012
+ );
2013
+ const buyerFields = buildBuyerStateFields(payerAddress, buyers, buyerAccount.address);
1583
2014
  setState(
1584
2015
  (prev) => mergeStatePreservingNonBuyTab(prev, {
1585
- buyerPubKey: account.address,
1586
- buyerPrvKey: privateKey,
2016
+ ...buyerFields,
1587
2017
  error: null,
1588
2018
  ...!isNonBuyTab(prev.activeTab) ? { status: "purchase_setup" } : {}
1589
2019
  })
@@ -1600,64 +2030,332 @@ function useAiCreditsAdapter({
1600
2030
  );
1601
2031
  }
1602
2032
  }, [address]);
1603
- const handleSignOperatorConsent = useCallback(async () => {
1604
- const currentState = state;
1605
- if (!currentState.address || !currentState.buyerPubKey || !currentState.buyerPrvKey) {
2033
+ const handleSelectBuyer = useCallback(
2034
+ async (buyerAddress) => {
2035
+ if (!address) return;
2036
+ const known = listKnownBuyerAddresses(address);
2037
+ if (!known.some((item) => item.toLowerCase() === buyerAddress.toLowerCase())) {
2038
+ return;
2039
+ }
2040
+ const buyers = mergeBuyerAddressList(known, buyerAddress);
2041
+ const buyerFields = activateBuyerSelection(address, buyers, buyerAddress);
1606
2042
  setState(
1607
- (prev) => withDerivedStatus(
1608
- prev,
1609
- { error: "Generate a buyer key before signing operator consent" },
1610
- true
1611
- )
2043
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2044
+ ...buyerFields,
2045
+ operatorAddress: null,
2046
+ currentOperator: null,
2047
+ totalCreditUsd: null,
2048
+ withdrawableUsd: null,
2049
+ totalGdDepositedG: null,
2050
+ monthlyStreamG: null,
2051
+ operatorConsentPending: false,
2052
+ error: null
2053
+ })
1612
2054
  );
1613
- return;
1614
- }
1615
- const ref = { payer: currentState.address, buyer: currentState.buyerPubKey };
1616
- const onNonBuyTab = isNonBuyTab(currentState.activeTab);
1617
- try {
1618
- const operatorStatus = await chainClient.getBuyerOperatorStatus(ref);
1619
- if (!operatorStatus.enabled) {
1620
- throw new Error("Operator consent is not available");
2055
+ try {
2056
+ const view = await buildAccountView(address, backendClient, chainClient, {
2057
+ buyerAddress
2058
+ });
2059
+ const enriched = await enrichAccountView(view, chainClient);
2060
+ const accountPatch = viewToStatePatch(view, enriched, INITIAL_STATE, {
2061
+ balanceMode: "always"
2062
+ });
2063
+ if (accountPatch.operatorConsented !== void 0) {
2064
+ setBuyerOperatorConsented(address, buyerAddress, accountPatch.operatorConsented);
2065
+ }
2066
+ const nextBuyerFields = buildBuyerStateFields(address, buyers, buyerAddress);
2067
+ setState(
2068
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2069
+ ...accountPatch,
2070
+ ...nextBuyerFields,
2071
+ operatorConsented: accountPatch.operatorConsented ?? nextBuyerFields.operatorConsented,
2072
+ error: null
2073
+ })
2074
+ );
2075
+ } catch (err) {
2076
+ setState(
2077
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2078
+ error: err instanceof Error ? err.message : "Could not load buyer account"
2079
+ })
2080
+ );
1621
2081
  }
1622
- if (operatorStatus.operatorAccepted) {
1623
- patchPayerSession(currentState.address, { operatorConsented: true });
2082
+ },
2083
+ [address, backendClient, chainClient]
2084
+ );
2085
+ const handleDiscoverBuyers = useCallback(
2086
+ (addresses) => {
2087
+ if (!address || addresses.length === 0) return;
2088
+ const buyers = rememberBuyerAddresses(address, addresses);
2089
+ setState((prev) => {
2090
+ const sameLength = buyers.length === prev.buyers.length;
2091
+ const unchanged = sameLength && buyers.every(
2092
+ (item, index) => item.toLowerCase() === prev.buyers[index]?.toLowerCase()
2093
+ );
2094
+ if (unchanged) return prev;
2095
+ return { ...prev, buyers };
2096
+ });
2097
+ },
2098
+ [address]
2099
+ );
2100
+ const handleImportBuyerFromPrivateKey = useCallback(
2101
+ async (rawPrivateKey) => {
2102
+ if (!address) {
2103
+ setState(
2104
+ (prev) => withDerivedStatus(prev, { error: "Connect your wallet before importing a signer key" }, true)
2105
+ );
2106
+ return null;
2107
+ }
2108
+ const trimmed = rawPrivateKey.trim();
2109
+ const normalized = trimmed.startsWith("0x") ? trimmed : `0x${trimmed}`;
2110
+ if (!/^0x[0-9a-fA-F]{64}$/.test(normalized)) {
2111
+ setState(
2112
+ (prev) => withDerivedStatus(
2113
+ prev,
2114
+ { error: "Invalid private key format \u2014 expected 0x followed by 64 hex characters" },
2115
+ true
2116
+ )
2117
+ );
2118
+ return null;
2119
+ }
2120
+ try {
2121
+ const privateKey = normalized;
2122
+ const buyerAccount = privateKeyToAccount4(privateKey);
2123
+ upsertBuyerKey(address, buyerAccount.address, { privateKey }, { setActive: true });
2124
+ const buyers = mergeBuyerAddressList(
2125
+ listKnownBuyerAddresses(address),
2126
+ buyerAccount.address
2127
+ );
2128
+ const buyerFields = buildBuyerStateFields(address, buyers, buyerAccount.address);
1624
2129
  setState(
1625
2130
  (prev) => mergeStatePreservingNonBuyTab(prev, {
1626
- operatorConsented: true,
2131
+ ...buyerFields,
2132
+ operatorAddress: null,
2133
+ currentOperator: null,
2134
+ totalCreditUsd: null,
2135
+ withdrawableUsd: null,
2136
+ totalGdDepositedG: null,
2137
+ monthlyStreamG: null,
1627
2138
  error: null,
1628
- ...!onNonBuyTab ? { status: "purchase_setup" } : {}
2139
+ ...!isNonBuyTab(prev.activeTab) ? { status: "purchase_setup" } : {}
1629
2140
  })
1630
2141
  );
2142
+ try {
2143
+ const view = await buildAccountView(address, backendClient, chainClient, {
2144
+ buyerAddress: buyerAccount.address
2145
+ });
2146
+ const enriched = await enrichAccountView(view, chainClient);
2147
+ const accountPatch = viewToStatePatch(view, enriched, INITIAL_STATE, {
2148
+ balanceMode: "always"
2149
+ });
2150
+ if (accountPatch.operatorConsented !== void 0) {
2151
+ setBuyerOperatorConsented(
2152
+ address,
2153
+ buyerAccount.address,
2154
+ accountPatch.operatorConsented
2155
+ );
2156
+ }
2157
+ const nextBuyerFields = buildBuyerStateFields(
2158
+ address,
2159
+ buyers,
2160
+ buyerAccount.address
2161
+ );
2162
+ setState(
2163
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2164
+ ...accountPatch,
2165
+ ...nextBuyerFields,
2166
+ operatorConsented: accountPatch.operatorConsented ?? nextBuyerFields.operatorConsented,
2167
+ error: null
2168
+ })
2169
+ );
2170
+ } catch {
2171
+ return buyerAccount.address;
2172
+ }
2173
+ return buyerAccount.address;
2174
+ } catch {
2175
+ setState(
2176
+ (prev) => withDerivedStatus(prev, { error: "Could not derive an account from the provided private key" }, true)
2177
+ );
2178
+ return null;
2179
+ }
2180
+ },
2181
+ [address, backendClient, chainClient]
2182
+ );
2183
+ const resolveBuyerList = useCallback(
2184
+ (payer, preferredBuyer) => resolveLocalBuyers(payer, preferredBuyer),
2185
+ []
2186
+ );
2187
+ const handleApplyDeepLinkBuyer = useCallback(
2188
+ async (buyerAddress, operatorSignature) => {
2189
+ if (!address) {
1631
2190
  return;
1632
2191
  }
1633
- const payload = await chainClient.buildOperatorConsentPayload(ref, operatorStatus);
1634
- if (!payload.enabled || !payload.typedData) {
1635
- throw new Error("Operator consent is not available");
2192
+ const trimmedAddress = buyerAddress.trim();
2193
+ const trimmedSignature = operatorSignature.trim();
2194
+ if (!isValidBuyerAddress(trimmedAddress)) {
2195
+ setState(
2196
+ (prev) => withDerivedStatus(
2197
+ prev,
2198
+ {
2199
+ error: deepLinkManualFallbackMessage("Deep-link buyerAddress is invalid."),
2200
+ activeTab: "buy",
2201
+ status: "purchase_setup"
2202
+ },
2203
+ true
2204
+ )
2205
+ );
2206
+ return;
1636
2207
  }
1637
- const buyerSig = await signOperatorConsentFromTypedData(
1638
- currentState.buyerPrvKey,
1639
- payload.typedData
1640
- );
1641
- await backendClient.submitOperatorConsent(ref.buyer, {
1642
- nonce: operatorStatus.consentNonce,
1643
- signature: buyerSig
2208
+ if (!isValidOperatorSignature(trimmedSignature)) {
2209
+ setState(
2210
+ (prev) => withDerivedStatus(
2211
+ prev,
2212
+ {
2213
+ error: deepLinkManualFallbackMessage("Deep-link operatorSignature is invalid."),
2214
+ activeTab: "buy",
2215
+ status: "purchase_setup"
2216
+ },
2217
+ true
2218
+ )
2219
+ );
2220
+ return;
2221
+ }
2222
+ storeDeepLinkParams({
2223
+ buyerAddress: trimmedAddress,
2224
+ operatorSignature: trimmedSignature
1644
2225
  });
1645
- await waitForOperatorConsent(chainClient, ref);
1646
- patchPayerSession(currentState.address, { operatorConsented: true });
2226
+ upsertBuyerKey(
2227
+ address,
2228
+ trimmedAddress,
2229
+ { operatorSignature: trimmedSignature },
2230
+ { setActive: true }
2231
+ );
2232
+ const buyers = mergeBuyerAddressList(listKnownBuyerAddresses(address), trimmedAddress);
2233
+ const buyerFields = buildBuyerStateFields(address, buyers, trimmedAddress);
1647
2234
  setState(
1648
2235
  (prev) => mergeStatePreservingNonBuyTab(prev, {
1649
- operatorConsented: true,
2236
+ ...buyerFields,
2237
+ operatorAddress: null,
2238
+ currentOperator: null,
2239
+ totalCreditUsd: null,
2240
+ withdrawableUsd: null,
2241
+ totalGdDepositedG: null,
2242
+ monthlyStreamG: null,
2243
+ activeTab: "buy",
2244
+ operatorConsentPending: false,
2245
+ error: null
2246
+ })
2247
+ );
2248
+ },
2249
+ [address]
2250
+ );
2251
+ const handleSignOperatorConsent = useCallback(async () => {
2252
+ const currentState = state;
2253
+ if (!currentState.address || !currentState.buyerPubKey) {
2254
+ setState(
2255
+ (prev) => withDerivedStatus(
2256
+ prev,
2257
+ { error: "Select a buyer before authorizing your wallet" },
2258
+ true
2259
+ )
2260
+ );
2261
+ return;
2262
+ }
2263
+ const keyEntry = getBuyerKeyEntry(currentState.address, currentState.buyerPubKey);
2264
+ const storedOperatorSignature = currentState.operatorSignature ?? keyEntry?.operatorSignature ?? null;
2265
+ if (!currentState.buyerPrvKey && !storedOperatorSignature) {
2266
+ setState(
2267
+ (prev) => withDerivedStatus(
2268
+ prev,
2269
+ { error: "Generate a signer key before authorizing your wallet" },
2270
+ true
2271
+ )
2272
+ );
2273
+ return;
2274
+ }
2275
+ if (currentState.operatorConsentPending) return;
2276
+ const ref = { payer: currentState.address, buyer: currentState.buyerPubKey };
2277
+ const onNonBuyTab = isNonBuyTab(currentState.activeTab);
2278
+ setState((prev) => ({
2279
+ ...prev,
2280
+ operatorConsentPending: true,
2281
+ error: null
2282
+ }));
2283
+ try {
2284
+ const operatorStatus = await chainClient.getBuyerOperatorStatus(ref);
2285
+ if (!operatorStatus.enabled) {
2286
+ throw new Error("Operator consent is not available");
2287
+ }
2288
+ const hasDifferentOperator = operatorStatus.currentOperator !== "0x0000000000000000000000000000000000000000" && !operatorStatus.operatorAccepted;
2289
+ if (hasDifferentOperator) {
2290
+ throw new Error(
2291
+ "This signer key is already controlled by another operator. Import a different signer key or generate a new one."
2292
+ );
2293
+ }
2294
+ if (operatorStatus.operatorAccepted) {
2295
+ setBuyerOperatorConsented(currentState.address, currentState.buyerPubKey, true);
2296
+ const buyerList2 = resolveBuyerList(currentState.address, currentState.buyerPubKey);
2297
+ const buyerFields2 = buildBuyerStateFields(
2298
+ currentState.address,
2299
+ buyerList2.buyers,
2300
+ buyerList2.selected
2301
+ );
2302
+ setState(
2303
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2304
+ ...buyerFields2,
2305
+ operatorConsented: true,
2306
+ operatorConsentPending: false,
2307
+ error: null,
2308
+ ...!onNonBuyTab ? { status: "purchase_setup" } : {}
2309
+ })
2310
+ );
2311
+ clearDeepLinkArtifacts();
2312
+ return;
2313
+ }
2314
+ let buyerSig;
2315
+ if (currentState.buyerPrvKey) {
2316
+ const payload = await chainClient.buildOperatorConsentPayload(ref, operatorStatus);
2317
+ if (!payload.enabled || !payload.typedData) {
2318
+ throw new Error("Operator consent is not available");
2319
+ }
2320
+ buyerSig = await signOperatorConsentFromTypedData(
2321
+ currentState.buyerPrvKey,
2322
+ payload.typedData
2323
+ );
2324
+ } else if (storedOperatorSignature) {
2325
+ buyerSig = storedOperatorSignature;
2326
+ } else {
2327
+ throw new Error("Generate a signer key before authorizing your wallet");
2328
+ }
2329
+ await backendClient.submitOperatorConsent(ref.buyer, {
2330
+ nonce: operatorStatus.consentNonce,
2331
+ signature: buyerSig
2332
+ });
2333
+ await waitForOperatorConsent(chainClient, ref);
2334
+ setBuyerOperatorConsented(currentState.address, currentState.buyerPubKey, true);
2335
+ const buyerList = resolveBuyerList(currentState.address, currentState.buyerPubKey);
2336
+ const buyerFields = buildBuyerStateFields(
2337
+ currentState.address,
2338
+ buyerList.buyers,
2339
+ buyerList.selected
2340
+ );
2341
+ setState(
2342
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2343
+ ...buyerFields,
2344
+ operatorConsented: true,
2345
+ operatorConsentPending: false,
1650
2346
  error: null,
1651
2347
  ...!onNonBuyTab ? { status: "purchase_setup" } : {}
1652
2348
  })
1653
2349
  );
2350
+ clearDeepLinkArtifacts();
1654
2351
  } catch (err) {
1655
2352
  setState((prev) => ({
1656
2353
  ...prev,
2354
+ operatorConsentPending: false,
1657
2355
  error: err instanceof Error ? err.message : "Operator consent signature rejected"
1658
2356
  }));
1659
2357
  }
1660
- }, [state, backendClient, chainClient]);
2358
+ }, [state, backendClient, chainClient, resolveBuyerList]);
1661
2359
  const handleSyncOperatorConsentFromChain = useCallback(async () => {
1662
2360
  const currentState = state;
1663
2361
  if (!currentState.address || !currentState.buyerPubKey || currentState.operatorConsented) {
@@ -1667,7 +2365,7 @@ function useAiCreditsAdapter({
1667
2365
  const ref = { payer: currentState.address, buyer: currentState.buyerPubKey };
1668
2366
  const operatorStatus = await chainClient.getBuyerOperatorStatus(ref);
1669
2367
  if (!operatorStatus.operatorAccepted) return;
1670
- patchPayerSession(currentState.address, { operatorConsented: true });
2368
+ setBuyerOperatorConsented(currentState.address, currentState.buyerPubKey, true);
1671
2369
  const onNonBuyTab = isNonBuyTab(currentState.activeTab);
1672
2370
  setState(
1673
2371
  (prev) => mergeStatePreservingNonBuyTab(prev, {
@@ -1699,7 +2397,7 @@ function useAiCreditsAdapter({
1699
2397
  async (quote) => {
1700
2398
  const currentState = state;
1701
2399
  if (!currentState.address || !currentState.buyerPubKey || !providerRef.current) {
1702
- throw new Error("Connect your wallet and generate a buyer key before paying");
2400
+ throw new Error("Connect your wallet and generate a signer key before paying");
1703
2401
  }
1704
2402
  const hasDeposit = Number.parseFloat(quote.depositAmountG) > 0;
1705
2403
  const streamChanged = isStreamAmountChanged(quote.streamAmountG, currentState.monthlyStreamG);
@@ -1805,8 +2503,15 @@ function useAiCreditsAdapter({
1805
2503
  previousBalance: balanceBefore
1806
2504
  });
1807
2505
  const creditUsdMicro = (BigInt(totalCreditUsd) - BigInt(balanceBefore || "0")).toString();
2506
+ const buyerList = resolveBuyerList(currentState.address, currentState.buyerPubKey);
2507
+ const buyerFields = buildBuyerStateFields(
2508
+ currentState.address,
2509
+ buyerList.buyers,
2510
+ buyerList.selected
2511
+ );
1808
2512
  setState(
1809
2513
  (prev) => withDerivedStatus(prev, {
2514
+ ...buyerFields,
1810
2515
  totalCreditUsd,
1811
2516
  error: null,
1812
2517
  activeTab: "manage"
@@ -1841,6 +2546,7 @@ function useAiCreditsAdapter({
1841
2546
  celoVault,
1842
2547
  onPaySuccess,
1843
2548
  onPayError,
2549
+ resolveBuyerList,
1844
2550
  prepareSettlement,
1845
2551
  skipVaultPaymentValidation
1846
2552
  ]
@@ -1850,36 +2556,38 @@ function useAiCreditsAdapter({
1850
2556
  const currentState = state;
1851
2557
  if (!currentState.address) return;
1852
2558
  try {
1853
- const sessionBuyer = currentState.buyerPubKey ?? patchPayerSessionFields(currentState.address).buyerPubKey ?? null;
2559
+ const preferredBuyer = currentState.buyerPubKey;
2560
+ const buyerList = resolveBuyerList(currentState.address, preferredBuyer);
1854
2561
  const [view, discountConfig] = await Promise.all([
1855
2562
  buildAccountView(currentState.address, backendClient, chainClient, {
1856
- buyerAddress: sessionBuyer
2563
+ buyerAddress: preferredBuyer
1857
2564
  }),
1858
2565
  backendClient.getDiscountConfig().catch(() => null)
1859
2566
  ]);
1860
2567
  const enriched = await enrichAccountView(view, chainClient);
1861
- setState((prev) => {
1862
- const accountPatch = viewToStatePatch(view, enriched, prev, {
1863
- balanceMode: "always"
1864
- });
1865
- const sessionFields = mergeSessionFields(
1866
- prev,
1867
- patchPayerSessionFields(currentState.address),
1868
- accountPatch,
1869
- false
2568
+ const accountPatch = viewToStatePatch(view, enriched, INITIAL_STATE, {
2569
+ balanceMode: "always"
2570
+ });
2571
+ if (preferredBuyer && accountPatch.operatorConsented !== void 0 && currentState.address) {
2572
+ setBuyerOperatorConsented(
2573
+ currentState.address,
2574
+ preferredBuyer,
2575
+ accountPatch.operatorConsented
1870
2576
  );
1871
- if (accountPatch.operatorConsented !== void 0 && currentState.address) {
1872
- syncOperatorConsentSession(currentState.address, accountPatch.operatorConsented);
1873
- }
1874
- if (currentState.address && view.buyer) {
1875
- syncBuyerPubKeySession(currentState.address, view.buyer);
1876
- }
2577
+ }
2578
+ const buyerFields = buildBuyerStateFields(
2579
+ currentState.address,
2580
+ buyerList.buyers,
2581
+ buyerList.selected
2582
+ );
2583
+ setState((prev) => {
1877
2584
  const statusSeed = options?.afterGoodIdVerify && prev.status === "payment_failed" ? "quote_ready" : prev.status === "backend_unavailable" ? "purchase_setup" : prev.status;
1878
2585
  return withDerivedStatus(
1879
2586
  { ...prev, status: statusSeed },
1880
2587
  {
1881
2588
  ...accountPatch,
1882
- ...sessionFields,
2589
+ ...buyerFields,
2590
+ operatorConsented: accountPatch.operatorConsented ?? buyerFields.operatorConsented,
1883
2591
  activeTab: prev.activeTab,
1884
2592
  error: null,
1885
2593
  depositBonusPercent: discountConfig?.depositBonusPercent ?? prev.depositBonusPercent,
@@ -1897,7 +2605,7 @@ function useAiCreditsAdapter({
1897
2605
  );
1898
2606
  }
1899
2607
  },
1900
- [state, backendClient, chainClient]
2608
+ [state, backendClient, chainClient, resolveBuyerList]
1901
2609
  );
1902
2610
  const handleVerifyGoodId = useCallback(async () => {
1903
2611
  const currentState = state;
@@ -1968,7 +2676,7 @@ function useAiCreditsAdapter({
1968
2676
  if (!currentState.buyerPrvKey) {
1969
2677
  setState((prev) => ({
1970
2678
  ...prev,
1971
- error: "Sign with your payer wallet in Buyer & Operator below to generate the buyer private key before closing a channel"
2679
+ error: "Sign with your payer wallet in Signer Key below to generate the buyer private key before closing a channel"
1972
2680
  }));
1973
2681
  return;
1974
2682
  }
@@ -2005,7 +2713,7 @@ function useAiCreditsAdapter({
2005
2713
  if (!currentState.buyerPrvKey) {
2006
2714
  setState((prev) => ({
2007
2715
  ...prev,
2008
- error: "Sign with your payer wallet in Buyer & Operator below to generate the buyer private key before withdrawing funds"
2716
+ error: "Sign with your payer wallet in Signer Key below to generate the buyer private key before withdrawing funds"
2009
2717
  }));
2010
2718
  return;
2011
2719
  }
@@ -2071,22 +2779,76 @@ function useAiCreditsAdapter({
2071
2779
  await handleRefresh();
2072
2780
  }, [configurationError, handleRefresh]);
2073
2781
  const handleSetActiveTab = useCallback((tab) => {
2074
- if (tab === "buy") {
2782
+ setState((prev) => {
2783
+ if (needsWalletConnection(prev)) {
2784
+ if (tab === "setup") {
2785
+ return mergeStatePreservingNonBuyTab(prev, { activeTab: "setup", error: null });
2786
+ }
2787
+ return prev;
2788
+ }
2789
+ if (tab === "buy") {
2790
+ return withDerivedStatus(prev, { activeTab: "buy", status: "purchase_setup", error: null }, true);
2791
+ }
2792
+ return mergeStatePreservingNonBuyTab(prev, { activeTab: tab, error: null });
2793
+ });
2794
+ }, []);
2795
+ const handleStartPurchase = useCallback(() => {
2796
+ handleSetActiveTab("buy");
2797
+ }, [handleSetActiveTab]);
2798
+ useEffect(() => {
2799
+ if (typeof window === "undefined" || deepLinkParseDoneRef.current) return;
2800
+ deepLinkParseDoneRef.current = true;
2801
+ const parsed = resolveDeepLinkParams(window.location.search);
2802
+ if (parsed.status === "absent") return;
2803
+ if (parsed.status === "partial") {
2804
+ const missing = parsed.present === "buyerAddress" ? "operatorSignature" : "buyerAddress";
2805
+ setState(
2806
+ (prev) => withDerivedStatus(
2807
+ prev,
2808
+ {
2809
+ error: deepLinkManualFallbackMessage(`Deep link is missing ${missing}.`),
2810
+ activeTab: "buy",
2811
+ status: "purchase_setup"
2812
+ },
2813
+ false
2814
+ )
2815
+ );
2816
+ return;
2817
+ }
2818
+ if (parsed.status === "invalid") {
2075
2819
  setState(
2076
- (prev) => withDerivedStatus(prev, { activeTab: "buy", status: "purchase_setup", error: null }, true)
2820
+ (prev) => withDerivedStatus(
2821
+ prev,
2822
+ {
2823
+ error: deepLinkManualFallbackMessage(`${parsed.reason}.`),
2824
+ activeTab: "buy",
2825
+ status: "purchase_setup"
2826
+ },
2827
+ false
2828
+ )
2077
2829
  );
2078
2830
  return;
2079
2831
  }
2080
- setState((prev) => mergeStatePreservingNonBuyTab(prev, { activeTab: tab, error: null }));
2832
+ pendingDeepLinkRef.current = parsed.value;
2081
2833
  }, []);
2082
- const handleStartPurchase = useCallback(() => {
2083
- handleSetActiveTab("buy");
2084
- }, [handleSetActiveTab]);
2834
+ useEffect(() => {
2835
+ const pending = pendingDeepLinkRef.current;
2836
+ if (!address || !pending || deepLinkApplyInFlightRef.current) return;
2837
+ deepLinkApplyInFlightRef.current = true;
2838
+ void handleApplyDeepLinkBuyer(pending.buyerAddress, pending.operatorSignature).finally(() => {
2839
+ deepLinkApplyInFlightRef.current = false;
2840
+ pendingDeepLinkRef.current = null;
2841
+ });
2842
+ }, [address, handleApplyDeepLinkBuyer]);
2085
2843
  const actions = useMemo(
2086
2844
  () => ({
2087
2845
  connect: handleConnect,
2088
2846
  switchChain: handleSwitchChain,
2089
2847
  generateBuyerKey: handleGenerateBuyerKey,
2848
+ selectBuyer: handleSelectBuyer,
2849
+ discoverBuyers: handleDiscoverBuyers,
2850
+ importBuyerFromPrivateKey: handleImportBuyerFromPrivateKey,
2851
+ applyDeepLinkBuyer: handleApplyDeepLinkBuyer,
2090
2852
  signOperatorConsent: handleSignOperatorConsent,
2091
2853
  syncOperatorConsentFromChain: handleSyncOperatorConsentFromChain,
2092
2854
  buildQuote: handleBuildQuote,
@@ -2103,6 +2865,10 @@ function useAiCreditsAdapter({
2103
2865
  handleConnect,
2104
2866
  handleSwitchChain,
2105
2867
  handleGenerateBuyerKey,
2868
+ handleSelectBuyer,
2869
+ handleDiscoverBuyers,
2870
+ handleImportBuyerFromPrivateKey,
2871
+ handleApplyDeepLinkBuyer,
2106
2872
  handleSignOperatorConsent,
2107
2873
  handleSyncOperatorConsentFromChain,
2108
2874
  handleBuildQuote,
@@ -2120,19 +2886,23 @@ function useAiCreditsAdapter({
2120
2886
  }
2121
2887
 
2122
2888
  // src/AiCreditsWidget.tsx
2123
- import React11, { useCallback as useCallback4, useMemo as useMemo6 } from "react";
2124
- import { GoodWidgetProvider } from "@goodwidget/core";
2889
+ import React14, { useCallback as useCallback5, useMemo as useMemo6, useState as useState17 } from "react";
2890
+ import { GoodWidgetProvider, useWallet as useWallet2 } from "@goodwidget/core";
2125
2891
  import {
2126
- Button as Button10,
2127
- ButtonText as ButtonText8,
2128
- Card as Card11,
2892
+ Badge as Badge3,
2893
+ BadgeText as BadgeText3,
2894
+ Button as Button14,
2895
+ ButtonText as ButtonText13,
2896
+ Card as Card13,
2129
2897
  CircularActionButton,
2130
- Icon as Icon9,
2131
- Text as Text12,
2898
+ getChainDisplayName,
2899
+ Heading as Heading9,
2900
+ Icon as Icon13,
2901
+ Text as Text16,
2132
2902
  ToastContainer,
2133
2903
  WidgetTabs,
2134
- XStack as XStack13,
2135
- YStack as YStack13,
2904
+ XStack as XStack17,
2905
+ YStack as YStack18,
2136
2906
  Spinner as Spinner7,
2137
2907
  createToast,
2138
2908
  updateToast
@@ -2142,6 +2912,8 @@ import {
2142
2912
  import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
2143
2913
  var HISTORY_PAGE_SIZE = 10;
2144
2914
  var HISTORY_LOOKBACK_DAYS = 90;
2915
+ var BUYER_FILTER_FILL_MAX_PAGES = 8;
2916
+ var BUYER_FILTER_ALL = "all";
2145
2917
  var HISTORY_SOURCE_OPTIONS = [
2146
2918
  { id: "deposit", label: "Deposit", defaultChecked: true },
2147
2919
  { id: "streamUpdate", label: "Stream update", defaultChecked: true },
@@ -2177,11 +2949,23 @@ function toIsoEndOfDay(dateValue) {
2177
2949
  if (Number.isNaN(parsed)) return void 0;
2178
2950
  return new Date(parsed).toISOString();
2179
2951
  }
2952
+ function matchesBuyerFilter(entry, filter) {
2953
+ if (filter === BUYER_FILTER_ALL) return true;
2954
+ return entry.buyerAddress?.toLowerCase() === filter.toLowerCase();
2955
+ }
2180
2956
  function useAiCreditsHistory(options) {
2181
- const { address, backendUrl, environment = "production", backendClient } = options;
2957
+ const {
2958
+ address,
2959
+ backendUrl,
2960
+ defaultBuyerFilter = BUYER_FILTER_ALL,
2961
+ environment = "production",
2962
+ backendClient,
2963
+ onBuyersDiscovered
2964
+ } = options;
2182
2965
  const defaultRange = useMemo2(() => getLast90DaysRange(), []);
2183
2966
  const [selectedSources, setSelectedSources] = useState2(createDefaultSelectedSources);
2184
2967
  const [statusFilter, setStatusFilter] = useState2("all");
2968
+ const [buyerAddressFilter, setBuyerAddressFilter] = useState2(defaultBuyerFilter);
2185
2969
  const [fromDate, setFromDate] = useState2(defaultRange.from);
2186
2970
  const [toDate, setToDate] = useState2(defaultRange.to);
2187
2971
  const [entries, setEntries] = useState2([]);
@@ -2190,6 +2974,9 @@ function useAiCreditsHistory(options) {
2190
2974
  const [loading, setLoading] = useState2(false);
2191
2975
  const [loadingMore, setLoadingMore] = useState2(false);
2192
2976
  const [error, setError] = useState2(null);
2977
+ useEffect2(() => {
2978
+ setBuyerAddressFilter(defaultBuyerFilter);
2979
+ }, [defaultBuyerFilter]);
2193
2980
  const activeSources = useMemo2(
2194
2981
  () => HISTORY_SOURCE_OPTIONS.map((option) => option.id).filter((id) => selectedSources[id]),
2195
2982
  [selectedSources]
@@ -2197,12 +2984,12 @@ function useAiCreditsHistory(options) {
2197
2984
  const loadHistory = useCallback2(
2198
2985
  async (nextOffset, append) => {
2199
2986
  if (!address) {
2200
- setEntries([]);
2201
- setOffset(0);
2202
- setHasMore(false);
2203
- setError(null);
2204
- setLoading(false);
2205
- setLoadingMore(false);
2987
+ setEntries((prev) => prev.length === 0 ? prev : []);
2988
+ setOffset((prev) => prev === 0 ? prev : 0);
2989
+ setHasMore((prev) => prev ? false : prev);
2990
+ setError((prev) => prev === null ? prev : null);
2991
+ setLoading((prev) => prev ? false : prev);
2992
+ setLoadingMore((prev) => prev ? false : prev);
2206
2993
  return;
2207
2994
  }
2208
2995
  if (activeSources.length === 0) {
@@ -2220,19 +3007,38 @@ function useAiCreditsHistory(options) {
2220
3007
  const client = backendClient ?? createBackendClient(backendUrl);
2221
3008
  const apiSource = activeSources.length === 1 ? activeSources[0] : void 0;
2222
3009
  const fundingStatus = statusFilter === "all" ? void 0 : statusFilter;
3010
+ const filterByBuyer = buyerAddressFilter !== BUYER_FILTER_ALL;
2223
3011
  try {
2224
- const response = await client.getCreditHistory(address, {
2225
- limit: HISTORY_PAGE_SIZE,
2226
- offset: nextOffset,
2227
- source: apiSource,
2228
- fundingStatus,
2229
- from: toIsoStartOfDay(fromDate),
2230
- to: toIsoEndOfDay(toDate)
2231
- });
2232
- const pageItems = activeSources.length === 1 ? response.items : response.items.filter((entry) => selectedSources[entry.source]);
2233
- setEntries((prev) => append ? [...prev, ...pageItems] : pageItems);
2234
- setOffset(nextOffset);
2235
- setHasMore(response.hasMore);
3012
+ const collected = [];
3013
+ let cursor = nextOffset;
3014
+ let apiHasMore = true;
3015
+ let pages = 0;
3016
+ while (pages < BUYER_FILTER_FILL_MAX_PAGES && collected.length < HISTORY_PAGE_SIZE && apiHasMore) {
3017
+ const response = await client.getCreditHistory(address, {
3018
+ limit: HISTORY_PAGE_SIZE,
3019
+ offset: cursor,
3020
+ source: apiSource,
3021
+ fundingStatus,
3022
+ from: toIsoStartOfDay(fromDate),
3023
+ to: toIsoEndOfDay(toDate)
3024
+ });
3025
+ const sourceFiltered = activeSources.length === 1 ? response.items : response.items.filter((entry) => selectedSources[entry.source]);
3026
+ const discoveredBuyers = sourceFiltered.map((entry) => entry.buyerAddress).filter((value) => Boolean(value));
3027
+ if (discoveredBuyers.length > 0) {
3028
+ onBuyersDiscovered?.(discoveredBuyers);
3029
+ }
3030
+ const buyerFiltered = sourceFiltered.filter(
3031
+ (entry) => matchesBuyerFilter(entry, buyerAddressFilter)
3032
+ );
3033
+ collected.push(...buyerFiltered);
3034
+ apiHasMore = response.hasMore;
3035
+ cursor = response.offset + response.limit;
3036
+ pages += 1;
3037
+ if (!filterByBuyer) break;
3038
+ }
3039
+ setEntries((prev) => append ? [...prev, ...collected] : collected);
3040
+ setOffset(cursor);
3041
+ setHasMore(apiHasMore);
2236
3042
  } catch (err) {
2237
3043
  if (!append) setEntries([]);
2238
3044
  setHasMore(false);
@@ -2249,9 +3055,11 @@ function useAiCreditsHistory(options) {
2249
3055
  backendClient,
2250
3056
  activeSources,
2251
3057
  statusFilter,
3058
+ buyerAddressFilter,
2252
3059
  fromDate,
2253
3060
  toDate,
2254
- selectedSources
3061
+ selectedSources,
3062
+ onBuyersDiscovered
2255
3063
  ]
2256
3064
  );
2257
3065
  useEffect2(() => {
@@ -2269,12 +3077,13 @@ function useAiCreditsHistory(options) {
2269
3077
  await loadHistory(0, false);
2270
3078
  }, [loadHistory]);
2271
3079
  const loadMore = useCallback2(async () => {
2272
- await loadHistory(offset + HISTORY_PAGE_SIZE, true);
3080
+ await loadHistory(offset, true);
2273
3081
  }, [loadHistory, offset]);
2274
3082
  return {
2275
3083
  state: {
2276
3084
  selectedSources,
2277
3085
  statusFilter,
3086
+ buyerAddressFilter,
2278
3087
  fromDate,
2279
3088
  toDate,
2280
3089
  entries,
@@ -2288,6 +3097,7 @@ function useAiCreditsHistory(options) {
2288
3097
  actions: {
2289
3098
  setSourceChecked,
2290
3099
  setStatusFilter,
3100
+ setBuyerAddressFilter,
2291
3101
  setFromDate,
2292
3102
  setToDate,
2293
3103
  reload,
@@ -2386,8 +3196,8 @@ function BuyerKeyPanel({
2386
3196
  }
2387
3197
  const Shell = embedded ? YStack2 : Card3;
2388
3198
  return /* @__PURE__ */ jsxs2(Shell, { gap: "$3", children: [
2389
- /* @__PURE__ */ jsx2(Heading, { level: 5, children: "Buyer Key" }),
2390
- /* @__PURE__ */ jsx2(Text2, { 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." }),
3199
+ /* @__PURE__ */ jsx2(Heading, { level: 5, children: "Signer Key" }),
3200
+ /* @__PURE__ */ jsx2(Text2, { 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." }),
2391
3201
  /* @__PURE__ */ jsxs2(YStack2, { gap: "$3", children: [
2392
3202
  /* @__PURE__ */ jsx2(
2393
3203
  Button,
@@ -2423,6 +3233,7 @@ function BuyerKeyPanel({
2423
3233
  }
2424
3234
  ),
2425
3235
  buyerPrvKey && /* @__PURE__ */ jsxs2(Fragment, { children: [
3236
+ /* @__PURE__ */ jsx2(AiCreditsStatusNotice, { borderColor: "$warning", children: /* @__PURE__ */ jsx2(Text2, { 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." }) }),
2426
3237
  /* @__PURE__ */ jsxs2(XStack3, { justifyContent: "space-between", alignItems: "center", children: [
2427
3238
  /* @__PURE__ */ jsx2(Text2, { variant: "label", secondary: true, children: "Private Key \u2014 save this securely" }),
2428
3239
  /* @__PURE__ */ jsx2(
@@ -2467,7 +3278,8 @@ function BuyerKeyPanel({
2467
3278
  )
2468
3279
  ]
2469
3280
  }
2470
- )
3281
+ ),
3282
+ /* @__PURE__ */ jsx2(Text2, { 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." })
2471
3283
  ] }),
2472
3284
  buyerPrvKey && !buyerPubKeySaved && /* @__PURE__ */ jsx2(Button, { size: "sm", ...compactButtonProps, onPress: onConfirm, children: /* @__PURE__ */ jsx2(ButtonText, { children: "I've Saved My Private Key" }) }),
2473
3285
  buyerPubKeySaved && /* @__PURE__ */ jsxs2(XStack3, { gap: "$2", alignItems: "center", children: [
@@ -2480,22 +3292,33 @@ function BuyerKeyPanel({
2480
3292
  }
2481
3293
 
2482
3294
  // src/components/buy/OperatorConsentStep.tsx
2483
- import { useState as useState5 } from "react";
2484
- import { Button as Button2, ButtonText as ButtonText2, Card as Card4, Heading as Heading2, Icon as Icon2, Spinner as Spinner2, Text as Text3, XStack as XStack4, YStack as YStack3 } from "@goodwidget/ui";
3295
+ import {
3296
+ Button as Button2,
3297
+ ButtonText as ButtonText2,
3298
+ Card as Card4,
3299
+ Heading as Heading2,
3300
+ Icon as Icon2,
3301
+ Spinner as Spinner2,
3302
+ Text as Text3,
3303
+ XStack as XStack4,
3304
+ YStack as YStack3
3305
+ } from "@goodwidget/ui";
2485
3306
  import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
2486
3307
  function OperatorConsentStep({
2487
3308
  buyerPubKey,
2488
3309
  buyerPrvKey,
3310
+ operatorSignature = null,
2489
3311
  operatorConsented,
3312
+ operatorConsentPending = false,
2490
3313
  onSign,
2491
3314
  embedded = false
2492
3315
  }) {
2493
- const [isSigning, setIsSigning] = useState5(false);
2494
- const canSign = Boolean(buyerPubKey && buyerPrvKey);
3316
+ const canSign = Boolean(buyerPubKey && (buyerPrvKey || operatorSignature));
3317
+ const isBusy = operatorConsentPending;
2495
3318
  const Shell = embedded ? YStack3 : Card4;
2496
3319
  return /* @__PURE__ */ jsxs3(Shell, { gap: "$3", ...!embedded ? { backgroundColor: "$backgroundHover" } : {}, children: [
2497
- /* @__PURE__ */ jsx3(Heading2, { level: 5, children: "Authorize AntSeed Operator" }),
2498
- /* @__PURE__ */ jsx3(Text3, { 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." }),
3320
+ /* @__PURE__ */ jsx3(Heading2, { level: 5, children: "Authorize Wallet" }),
3321
+ /* @__PURE__ */ jsx3(Text3, { 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." }),
2499
3322
  buyerPubKey && /* @__PURE__ */ jsxs3(Text3, { fontSize: "$2", lineHeight: "$2", children: [
2500
3323
  "Buyer address:",
2501
3324
  " ",
@@ -2503,38 +3326,35 @@ function OperatorConsentStep({
2503
3326
  ] }),
2504
3327
  operatorConsented ? /* @__PURE__ */ jsxs3(XStack4, { gap: "$2", alignItems: "center", children: [
2505
3328
  /* @__PURE__ */ jsx3(Icon2, { name: "check", size: "sm", color: "success" }),
2506
- /* @__PURE__ */ jsx3(Text3, { color: "$success", children: "Operator consent accepted \u2014 ready to pay" })
3329
+ /* @__PURE__ */ jsx3(Text3, { color: "$success", children: "Wallet authorized \u2014 ready to pay" })
2507
3330
  ] }) : /* @__PURE__ */ jsx3(
2508
3331
  Button2,
2509
3332
  {
2510
3333
  size: "sm",
2511
3334
  ...compactButtonProps,
2512
3335
  onPress: () => {
2513
- setIsSigning(true);
2514
- void onSign().finally(() => {
2515
- setIsSigning(false);
2516
- });
3336
+ void onSign();
2517
3337
  },
2518
- disabled: !canSign || isSigning,
2519
- children: isSigning ? /* @__PURE__ */ jsxs3(XStack4, { gap: "$2", alignItems: "center", children: [
2520
- /* @__PURE__ */ jsx3(ButtonText2, { children: "Signing\u2026" }),
3338
+ disabled: !canSign || isBusy,
3339
+ children: isBusy ? /* @__PURE__ */ jsxs3(XStack4, { gap: "$2", alignItems: "center", children: [
3340
+ /* @__PURE__ */ jsx3(ButtonText2, { children: "Submitting\u2026" }),
2521
3341
  /* @__PURE__ */ jsx3(Spinner2, { size: "sm" })
2522
- ] }) : /* @__PURE__ */ jsx3(ButtonText2, { children: "Sign Operator Consent" })
3342
+ ] }) : /* @__PURE__ */ jsx3(ButtonText2, { children: "Authorize Wallet" })
2523
3343
  }
2524
3344
  )
2525
3345
  ] });
2526
3346
  }
2527
3347
 
2528
3348
  // src/components/buy/AmountPicker.tsx
2529
- import { useEffect as useEffect3, useMemo as useMemo3, useState as useState7 } from "react";
3349
+ import { useEffect as useEffect3, useMemo as useMemo3, useState as useState6 } from "react";
2530
3350
  import { Button as Button3, ButtonText as ButtonText3, Card as Card5, Heading as Heading3, Input, Separator, Spinner as Spinner3, Text as Text5, TokenAmount as TokenAmount2, XStack as XStack6, YStack as YStack5 } from "@goodwidget/ui";
2531
3351
 
2532
3352
  // src/components/shared/tooltips.tsx
2533
- import { useState as useState6 } from "react";
3353
+ import { useState as useState5 } from "react";
2534
3354
  import { Icon as Icon3, Text as Text4, XStack as XStack5, YStack as YStack4 } from "@goodwidget/ui";
2535
3355
  import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
2536
3356
  function InfoTooltip({ message }) {
2537
- const [open, setOpen] = useState6(false);
3357
+ const [open, setOpen] = useState5(false);
2538
3358
  return /* @__PURE__ */ jsxs4(
2539
3359
  XStack5,
2540
3360
  {
@@ -2579,7 +3399,7 @@ function HoverTooltip({
2579
3399
  children,
2580
3400
  fullWidth = false
2581
3401
  }) {
2582
- const [open, setOpen] = useState6(false);
3402
+ const [open, setOpen] = useState5(false);
2583
3403
  if (!message) return /* @__PURE__ */ jsx4(Fragment2, { children });
2584
3404
  return /* @__PURE__ */ jsxs4(
2585
3405
  XStack5,
@@ -2664,11 +3484,11 @@ function AmountPicker({
2664
3484
  embedded = false
2665
3485
  }) {
2666
3486
  const streamSeed = useMemo3(() => resolveInitialStreamAmount(monthlyStreamG), [monthlyStreamG]);
2667
- const [depositAmount, setDepositAmount] = useState7(DEFAULT_DEPOSIT_AMOUNT);
2668
- const [streamAmount, setStreamAmount] = useState7(streamSeed);
2669
- const [quote, setQuote] = useState7(null);
2670
- const [quotePending, setQuotePending] = useState7(false);
2671
- const [isVerifyingGoodId, setIsVerifyingGoodId] = useState7(false);
3487
+ const [depositAmount, setDepositAmount] = useState6(DEFAULT_DEPOSIT_AMOUNT);
3488
+ const [streamAmount, setStreamAmount] = useState6(streamSeed);
3489
+ const [quote, setQuote] = useState6(null);
3490
+ const [quotePending, setQuotePending] = useState6(false);
3491
+ const [isVerifyingGoodId, setIsVerifyingGoodId] = useState6(false);
2672
3492
  const isStreamUpdateFlow = parseGAmount(streamSeed) > 0;
2673
3493
  useEffect3(() => {
2674
3494
  setStreamAmount(streamSeed);
@@ -2705,7 +3525,8 @@ function AmountPicker({
2705
3525
  [depositAmount, streamAmount, monthlyStreamG, minDepositUsd, minStreamUsd, quote, gdUsdPerToken, gBalance]
2706
3526
  );
2707
3527
  const minsLoaded = minStreamUsd !== null;
2708
- const canPay = status === "quote_ready" && minsLoaded && paymentValidation.hasPaymentAction && paymentValidation.vaultMinimumsMet && !paymentValidation.overBalance && !quotePending && quote !== null;
3528
+ const canRetryAfterFailure = status === "quote_ready" || status === "payment_failed";
3529
+ const canPay = canRetryAfterFailure && minsLoaded && paymentValidation.hasPaymentAction && paymentValidation.vaultMinimumsMet && !paymentValidation.overBalance && !quotePending && quote !== null;
2709
3530
  const payDisabledMessage = getPayDisabledMessage({
2710
3531
  canPay,
2711
3532
  minsLoaded,
@@ -2848,136 +3669,30 @@ function AmountPicker({
2848
3669
  ] });
2849
3670
  }
2850
3671
 
2851
- // src/components/buy/BuyCreditsFaq.tsx
2852
- import { useState as useState8 } from "react";
2853
- import { Card as Card6, Heading as Heading4, Icon as Icon4, Separator as Separator2, Text as Text6, XStack as XStack7, YStack as YStack6 } from "@goodwidget/ui";
2854
- import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
2855
- var FAQ_ITEMS = [
2856
- {
2857
- id: "what-are-credits",
2858
- question: "What are AI credits?",
2859
- 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."
2860
- },
2861
- {
2862
- id: "how-to-buy",
2863
- question: "How do I buy credits?",
2864
- 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)."
2865
- },
2866
- {
2867
- id: "deposit-vs-stream",
2868
- question: "What is a one-time deposit vs a monthly stream?",
2869
- 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."
2870
- },
2871
- {
2872
- id: "minimums",
2873
- question: "What are the minimum amounts?",
2874
- 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."
2875
- },
2876
- {
2877
- id: "goodid-bonus",
2878
- question: "How do GoodID bonuses work?",
2879
- 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."
2880
- },
2881
- {
2882
- id: "buyer-key",
2883
- question: "What is the buyer key?",
2884
- 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."
2885
- },
2886
- {
2887
- id: "operator-consent",
2888
- question: "Why do I authorize the Gooddollar operator?",
2889
- 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."
2890
- },
2891
- {
2892
- id: "when-credits-arrive",
2893
- question: "When do credits arrive?",
2894
- 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."
2895
- },
2896
- {
2897
- id: "withdraw",
2898
- question: "What funds can I withdraw?",
2899
- 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."
2900
- },
2901
- {
2902
- id: "api-setup",
2903
- question: "What is API setup?",
2904
- 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."
2905
- },
2906
- {
2907
- id: "support",
2908
- question: "Who do I contact for support?",
2909
- 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"
2910
- }
2911
- ];
2912
- function FaqItem({
2913
- question,
2914
- answer,
2915
- expanded,
2916
- onToggle
2917
- }) {
2918
- return /* @__PURE__ */ jsxs6(YStack6, { gap: "$1", children: [
2919
- /* @__PURE__ */ jsxs6(
2920
- XStack7,
2921
- {
2922
- justifyContent: "space-between",
2923
- alignItems: "center",
2924
- gap: "$2",
2925
- onPress: onToggle,
2926
- cursor: "pointer",
2927
- children: [
2928
- /* @__PURE__ */ jsx6(Text6, { fontSize: "$2", fontWeight: "600", flex: 1, children: question }),
2929
- /* @__PURE__ */ jsx6(Icon4, { name: expanded ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
2930
- ]
2931
- }
2932
- ),
2933
- expanded && /* @__PURE__ */ jsx6(YStack6, { gap: "$2", children: answer.split("\n\n").map((paragraph, index) => /* @__PURE__ */ jsx6(Text6, { fontSize: "$2", secondary: true, lineHeight: "$3", children: paragraph }, index)) })
2934
- ] });
2935
- }
2936
- function BuyCreditsFaq() {
2937
- const [expandedId, setExpandedId] = useState8(null);
2938
- return /* @__PURE__ */ jsxs6(Card6, { gap: "$3", children: [
2939
- /* @__PURE__ */ jsx6(Heading4, { level: 6, children: "FAQ" }),
2940
- /* @__PURE__ */ jsx6(YStack6, { gap: "$3", children: FAQ_ITEMS.map((item, index) => /* @__PURE__ */ jsxs6(YStack6, { gap: "$3", children: [
2941
- index > 0 && /* @__PURE__ */ jsx6(Separator2, {}),
2942
- /* @__PURE__ */ jsx6(
2943
- FaqItem,
2944
- {
2945
- question: item.question,
2946
- answer: item.answer,
2947
- expanded: expandedId === item.id,
2948
- onToggle: () => {
2949
- setExpandedId((current) => current === item.id ? null : item.id);
2950
- }
2951
- }
2952
- )
2953
- ] }, item.id)) })
2954
- ] });
2955
- }
2956
-
2957
3672
  // src/components/manage/CreditsManagementCard.tsx
2958
- import { useMemo as useMemo4, useState as useState9 } from "react";
3673
+ import { useMemo as useMemo4, useState as useState7 } from "react";
2959
3674
  import {
2960
3675
  Button as Button4,
2961
3676
  ButtonText as ButtonText4,
2962
- Card as Card7,
2963
- Heading as Heading5,
3677
+ Card as Card6,
3678
+ Heading as Heading4,
2964
3679
  Input as Input2,
2965
3680
  Spinner as Spinner4,
2966
- Text as Text7,
2967
- XStack as XStack8,
2968
- YStack as YStack7
3681
+ Text as Text6,
3682
+ XStack as XStack7,
3683
+ YStack as YStack6
2969
3684
  } from "@goodwidget/ui";
2970
3685
 
2971
3686
  // src/components/shared/constants.ts
2972
- 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.";
2973
- var BUYER_KEY_REQUIRED_WITHDRAW_TOOLTIP = "Sign with your payer wallet in Buyer & Operator below to generate the buyer private key before withdrawing funds.";
3687
+ 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.";
3688
+ var BUYER_KEY_REQUIRED_WITHDRAW_TOOLTIP = "Sign with your payer wallet in Signer Key below to generate the buyer private key before withdrawing funds.";
2974
3689
  var WITHDRAW_TOOLTIP = "Withdraws principal to your payer wallet (not bonus). Requires the buyer private key from this session.";
2975
3690
 
2976
3691
  // src/components/manage/CreditsManagementCard.tsx
2977
- import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
3692
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
2978
3693
  function StatCell({ label, children }) {
2979
- return /* @__PURE__ */ jsxs7(
2980
- YStack7,
3694
+ return /* @__PURE__ */ jsxs6(
3695
+ YStack6,
2981
3696
  {
2982
3697
  flex: 1,
2983
3698
  minWidth: "45%",
@@ -2989,8 +3704,8 @@ function StatCell({ label, children }) {
2989
3704
  minWidth: "28%"
2990
3705
  },
2991
3706
  children: [
2992
- /* @__PURE__ */ jsx7(Text7, { fontSize: "$1", secondary: true, children: label }),
2993
- /* @__PURE__ */ jsx7(YStack7, { justifyContent: "center", children })
3707
+ /* @__PURE__ */ jsx6(Text6, { fontSize: "$1", secondary: true, children: label }),
3708
+ /* @__PURE__ */ jsx6(YStack6, { justifyContent: "center", children })
2994
3709
  ]
2995
3710
  }
2996
3711
  );
@@ -2999,7 +3714,7 @@ function StatValueText({
2999
3714
  children,
3000
3715
  color
3001
3716
  }) {
3002
- return /* @__PURE__ */ jsx7(Text7, { fontSize: "$2", fontWeight: "700", color, children });
3717
+ return /* @__PURE__ */ jsx6(Text6, { fontSize: "$2", fontWeight: "700", color, children });
3003
3718
  }
3004
3719
  function formatCompactAmount(amount) {
3005
3720
  const value = Number.parseFloat(amount);
@@ -3018,16 +3733,16 @@ function formatExactGAmount(amount) {
3018
3733
  }).format(value)} G$`;
3019
3734
  }
3020
3735
  function CompactGStatValue({ amount }) {
3021
- const [open, setOpen] = useState9(false);
3736
+ const [open, setOpen] = useState7(false);
3022
3737
  const value = Number.parseFloat(amount);
3023
3738
  const compact = formatCompactAmount(amount);
3024
3739
  const exact = formatExactGAmount(amount);
3025
3740
  const needsExact = Number.isFinite(value) && value >= 1e3;
3026
3741
  if (!needsExact) {
3027
- return /* @__PURE__ */ jsx7(StatValueText, { children: compact });
3742
+ return /* @__PURE__ */ jsx6(StatValueText, { children: compact });
3028
3743
  }
3029
- return /* @__PURE__ */ jsxs7(
3030
- XStack8,
3744
+ return /* @__PURE__ */ jsxs6(
3745
+ XStack7,
3031
3746
  {
3032
3747
  position: "relative",
3033
3748
  cursor: "help",
@@ -3040,9 +3755,9 @@ function CompactGStatValue({ amount }) {
3040
3755
  onBlur: () => setOpen(false),
3041
3756
  onPress: () => setOpen((prev) => !prev),
3042
3757
  children: [
3043
- /* @__PURE__ */ jsx7(StatValueText, { children: compact }),
3044
- open && /* @__PURE__ */ jsx7(
3045
- YStack7,
3758
+ /* @__PURE__ */ jsx6(StatValueText, { children: compact }),
3759
+ open && /* @__PURE__ */ jsx6(
3760
+ YStack6,
3046
3761
  {
3047
3762
  position: "absolute",
3048
3763
  bottom: "100%",
@@ -3055,7 +3770,7 @@ function CompactGStatValue({ amount }) {
3055
3770
  padding: "$2",
3056
3771
  zIndex: 100,
3057
3772
  pointerEvents: "none",
3058
- children: /* @__PURE__ */ jsx7(Text7, { fontSize: "$1", lineHeight: "$2", color: "$color", whiteSpace: "nowrap", children: exact })
3773
+ children: /* @__PURE__ */ jsx6(Text6, { fontSize: "$1", lineHeight: "$2", color: "$color", whiteSpace: "nowrap", children: exact })
3059
3774
  }
3060
3775
  )
3061
3776
  ]
@@ -3071,10 +3786,10 @@ function formatUsdAmount(usdMicro) {
3071
3786
  }).format(value);
3072
3787
  }
3073
3788
  function CreditsManagementCard({ state, actions }) {
3074
- const [isClosing, setIsClosing] = useState9(false);
3075
- const [isWithdrawing, setIsWithdrawing] = useState9(false);
3076
- const [channelId, setChannelId] = useState9("");
3077
- const [withdrawAmount, setWithdrawAmount] = useState9("");
3789
+ const [isClosing, setIsClosing] = useState7(false);
3790
+ const [isWithdrawing, setIsWithdrawing] = useState7(false);
3791
+ const [channelId, setChannelId] = useState7("");
3792
+ const [withdrawAmount, setWithdrawAmount] = useState7("");
3078
3793
  const {
3079
3794
  totalCreditUsd,
3080
3795
  totalGdDepositedG,
@@ -3100,33 +3815,33 @@ function CreditsManagementCard({ state, actions }) {
3100
3815
  const hasWithdrawableBalance = withdrawableUsd !== null && BigInt(withdrawableUsd) > 0n;
3101
3816
  const canClose = Boolean(buyerPrvKey) && Boolean(channelId.trim()) && !isClosing;
3102
3817
  const canWithdraw = Boolean(buyerPrvKey) && hasWithdrawableBalance && Boolean(withdrawAmount.trim()) && !isWithdrawing;
3103
- return /* @__PURE__ */ jsxs7(Card7, { gap: "$3", children: [
3104
- /* @__PURE__ */ jsx7(Heading5, { level: 6, children: "AI Credits" }),
3105
- /* @__PURE__ */ jsxs7(XStack8, { gap: "$4", width: "100%", alignItems: "flex-start", flexWrap: "wrap", children: [
3106
- /* @__PURE__ */ jsxs7(YStack7, { gap: "$2", flex: 1, minWidth: 0, children: [
3107
- /* @__PURE__ */ jsx7(Text7, { fontSize: "$1", secondary: true, children: "Total Credit (US$)" }),
3108
- totalCreditDisplay !== null ? /* @__PURE__ */ jsx7(Heading5, { level: 5, children: totalCreditDisplay }) : /* @__PURE__ */ jsx7(Spinner4, { size: "sm" })
3818
+ return /* @__PURE__ */ jsxs6(Card6, { gap: "$3", children: [
3819
+ /* @__PURE__ */ jsx6(Heading4, { level: 6, children: "AI Credits" }),
3820
+ /* @__PURE__ */ jsxs6(XStack7, { gap: "$4", width: "100%", alignItems: "flex-start", flexWrap: "wrap", children: [
3821
+ /* @__PURE__ */ jsxs6(YStack6, { gap: "$2", flex: 1, minWidth: 0, children: [
3822
+ /* @__PURE__ */ jsx6(Text6, { fontSize: "$1", secondary: true, children: "Total Credit (US$)" }),
3823
+ totalCreditDisplay !== null ? /* @__PURE__ */ jsx6(Heading4, { level: 5, children: totalCreditDisplay }) : /* @__PURE__ */ jsx6(Spinner4, { size: "sm" })
3109
3824
  ] }),
3110
- /* @__PURE__ */ jsxs7(YStack7, { gap: "$2", flex: 1, minWidth: 0, children: [
3111
- /* @__PURE__ */ jsx7(Text7, { fontSize: "$1", secondary: true, children: "Est. Monthly Credit (US$)" }),
3112
- monthlyStreamUsdDisplay ? /* @__PURE__ */ jsxs7(Heading5, { level: 5, color: "$primary", children: [
3825
+ /* @__PURE__ */ jsxs6(YStack6, { gap: "$2", flex: 1, minWidth: 0, children: [
3826
+ /* @__PURE__ */ jsx6(Text6, { fontSize: "$1", secondary: true, children: "Est. Monthly Credit (US$)" }),
3827
+ monthlyStreamUsdDisplay ? /* @__PURE__ */ jsxs6(Heading4, { level: 5, color: "$primary", children: [
3113
3828
  "~",
3114
3829
  monthlyStreamUsdDisplay
3115
- ] }) : /* @__PURE__ */ jsx7(Heading5, { level: 5, children: "\u2014" })
3830
+ ] }) : /* @__PURE__ */ jsx6(Heading4, { level: 5, children: "\u2014" })
3116
3831
  ] })
3117
3832
  ] }),
3118
- /* @__PURE__ */ jsxs7(XStack8, { gap: "$2", width: "100%", flexWrap: "wrap", alignItems: "stretch", children: [
3119
- /* @__PURE__ */ jsx7(StatCell, { label: "Total Deposited (G$)", children: /* @__PURE__ */ jsx7(CompactGStatValue, { amount: totalGdDepositedG ?? "0.00" }) }),
3120
- /* @__PURE__ */ jsx7(StatCell, { label: "Monthly Stream (G$)", children: /* @__PURE__ */ jsx7(CompactGStatValue, { amount: monthlyStreamG ?? "0.00" }) }),
3121
- /* @__PURE__ */ jsx7(StatCell, { label: "Withdrawable (US$)", children: withdrawableDisplay !== null ? /* @__PURE__ */ jsx7(StatValueText, { children: withdrawableDisplay }) : /* @__PURE__ */ jsx7(Spinner4, { size: "sm" }) })
3833
+ /* @__PURE__ */ jsxs6(XStack7, { gap: "$2", width: "100%", flexWrap: "wrap", alignItems: "stretch", children: [
3834
+ /* @__PURE__ */ jsx6(StatCell, { label: "Total Deposited (G$)", children: /* @__PURE__ */ jsx6(CompactGStatValue, { amount: totalGdDepositedG ?? "0.00" }) }),
3835
+ /* @__PURE__ */ jsx6(StatCell, { label: "Monthly Stream (G$)", children: /* @__PURE__ */ jsx6(CompactGStatValue, { amount: monthlyStreamG ?? "0.00" }) }),
3836
+ /* @__PURE__ */ jsx6(StatCell, { label: "Withdrawable (US$)", children: withdrawableDisplay !== null ? /* @__PURE__ */ jsx6(StatValueText, { children: withdrawableDisplay }) : /* @__PURE__ */ jsx6(Spinner4, { size: "sm" }) })
3122
3837
  ] }),
3123
- /* @__PURE__ */ jsxs7(YStack7, { gap: "$1", children: [
3124
- /* @__PURE__ */ jsxs7(XStack8, { gap: "$1", alignItems: "center", children: [
3125
- /* @__PURE__ */ jsx7(Text7, { fontSize: "$1", variant: "label", children: "Withdraw" }),
3126
- /* @__PURE__ */ jsx7(InfoTooltip, { message: WITHDRAW_TOOLTIP })
3838
+ /* @__PURE__ */ jsxs6(YStack6, { gap: "$1", children: [
3839
+ /* @__PURE__ */ jsxs6(XStack7, { gap: "$1", alignItems: "center", children: [
3840
+ /* @__PURE__ */ jsx6(Text6, { fontSize: "$1", variant: "label", children: "Withdraw" }),
3841
+ /* @__PURE__ */ jsx6(InfoTooltip, { message: WITHDRAW_TOOLTIP })
3127
3842
  ] }),
3128
- /* @__PURE__ */ jsxs7(XStack8, { gap: "$2", alignItems: "center", children: [
3129
- /* @__PURE__ */ jsx7(YStack7, { flex: 1, children: /* @__PURE__ */ jsx7(
3843
+ /* @__PURE__ */ jsxs6(XStack7, { gap: "$2", alignItems: "center", children: [
3844
+ /* @__PURE__ */ jsx6(YStack6, { flex: 1, children: /* @__PURE__ */ jsx6(
3130
3845
  Input2,
3131
3846
  {
3132
3847
  size: "sm",
@@ -3135,7 +3850,7 @@ function CreditsManagementCard({ state, actions }) {
3135
3850
  placeholder: hasWithdrawableBalance && withdrawableDisplay ? `Max ${withdrawableDisplay} US$` : "Amount in US$"
3136
3851
  }
3137
3852
  ) }),
3138
- /* @__PURE__ */ jsx7(HoverTooltip, { message: !buyerPrvKey ? BUYER_KEY_REQUIRED_WITHDRAW_TOOLTIP : null, children: /* @__PURE__ */ jsx7(
3853
+ /* @__PURE__ */ jsx6(HoverTooltip, { message: !buyerPrvKey ? BUYER_KEY_REQUIRED_WITHDRAW_TOOLTIP : null, children: /* @__PURE__ */ jsx6(
3139
3854
  Button4,
3140
3855
  {
3141
3856
  variant: "outline",
@@ -3151,15 +3866,15 @@ function CreditsManagementCard({ state, actions }) {
3151
3866
  setWithdrawAmount("");
3152
3867
  });
3153
3868
  },
3154
- children: /* @__PURE__ */ jsx7(ButtonText4, { children: isWithdrawing ? "Withdrawing\u2026" : "Withdraw" })
3869
+ children: /* @__PURE__ */ jsx6(ButtonText4, { children: isWithdrawing ? "Withdrawing\u2026" : "Withdraw" })
3155
3870
  }
3156
3871
  ) })
3157
3872
  ] })
3158
3873
  ] }),
3159
- /* @__PURE__ */ jsxs7(YStack7, { gap: "$1", children: [
3160
- /* @__PURE__ */ jsx7(Text7, { fontSize: "$1", variant: "label", children: "Close Channel" }),
3161
- /* @__PURE__ */ jsxs7(XStack8, { gap: "$2", alignItems: "center", children: [
3162
- /* @__PURE__ */ jsx7(YStack7, { flex: 1, children: /* @__PURE__ */ jsx7(
3874
+ /* @__PURE__ */ jsxs6(YStack6, { gap: "$1", children: [
3875
+ /* @__PURE__ */ jsx6(Text6, { fontSize: "$1", variant: "label", children: "Close Channel" }),
3876
+ /* @__PURE__ */ jsxs6(XStack7, { gap: "$2", alignItems: "center", children: [
3877
+ /* @__PURE__ */ jsx6(YStack6, { flex: 1, children: /* @__PURE__ */ jsx6(
3163
3878
  Input2,
3164
3879
  {
3165
3880
  size: "sm",
@@ -3168,7 +3883,7 @@ function CreditsManagementCard({ state, actions }) {
3168
3883
  placeholder: "0x\u2026 (64 hex chars)"
3169
3884
  }
3170
3885
  ) }),
3171
- /* @__PURE__ */ jsx7(HoverTooltip, { message: !buyerPrvKey ? BUYER_KEY_REQUIRED_CLOSE_TOOLTIP : null, children: /* @__PURE__ */ jsx7(
3886
+ /* @__PURE__ */ jsx6(HoverTooltip, { message: !buyerPrvKey ? BUYER_KEY_REQUIRED_CLOSE_TOOLTIP : null, children: /* @__PURE__ */ jsx6(
3172
3887
  Button4,
3173
3888
  {
3174
3889
  variant: "outline",
@@ -3184,7 +3899,7 @@ function CreditsManagementCard({ state, actions }) {
3184
3899
  setChannelId("");
3185
3900
  });
3186
3901
  },
3187
- children: /* @__PURE__ */ jsx7(ButtonText4, { children: isClosing ? "Closing\u2026" : "Close" })
3902
+ children: /* @__PURE__ */ jsx6(ButtonText4, { children: isClosing ? "Closing\u2026" : "Close" })
3188
3903
  }
3189
3904
  ) })
3190
3905
  ] })
@@ -3193,149 +3908,430 @@ function CreditsManagementCard({ state, actions }) {
3193
3908
  }
3194
3909
 
3195
3910
  // src/components/manage/BuyerOperatorCard.tsx
3196
- import { useState as useState10 } from "react";
3197
- import { Button as Button6, ButtonText as ButtonText5, Card as Card8, Heading as Heading6, Icon as Icon6, Spinner as Spinner5, Text as Text9, XStack as XStack10, YStack as YStack9 } from "@goodwidget/ui";
3198
-
3199
- // src/components/shared/AddressView.tsx
3200
- import { Button as Button5, Icon as Icon5, Text as Text8, XStack as XStack9, YStack as YStack8 } from "@goodwidget/ui";
3201
- import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
3202
- function AddressView({ label, address }) {
3203
- const { copied, copy } = useCopyFeedback();
3204
- return /* @__PURE__ */ jsxs8(YStack8, { gap: "$1", children: [
3205
- /* @__PURE__ */ jsx8(Text8, { fontSize: "$1", secondary: true, children: label }),
3206
- /* @__PURE__ */ jsxs8(
3207
- XStack9,
3208
- {
3209
- backgroundColor: "$backgroundMuted",
3210
- borderRadius: "$2",
3211
- padding: "$2",
3212
- justifyContent: "space-between",
3213
- alignItems: "center",
3214
- children: [
3215
- /* @__PURE__ */ jsx8(
3216
- Text8,
3217
- {
3218
- fontSize: "$2",
3219
- fontFamily: "$mono",
3220
- flex: 1,
3221
- numberOfLines: 1,
3222
- style: monospaceSingleLineStyle,
3223
- children: truncateAddress(address)
3224
- }
3225
- ),
3226
- /* @__PURE__ */ jsx8(Button5, { size: "sm", variant: "ghost", iconSize: "sm", onPress: () => void copy(address), children: /* @__PURE__ */ jsx8(Icon5, { name: copied ? "check" : "copy", size: "xs", color: copied ? "success" : "text" }) })
3227
- ]
3228
- }
3229
- )
3230
- ] });
3231
- }
3911
+ import { useState as useState9 } from "react";
3912
+ import {
3913
+ Button as Button6,
3914
+ ButtonText as ButtonText6,
3915
+ Card as Card7,
3916
+ Heading as Heading6,
3917
+ Icon as Icon5,
3918
+ Spinner as Spinner5,
3919
+ Text as Text8,
3920
+ XStack as XStack9,
3921
+ YStack as YStack8
3922
+ } from "@goodwidget/ui";
3232
3923
 
3233
- // src/components/manage/BuyerOperatorCard.tsx
3234
- import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
3235
- function BuyerOperatorCard({ state, actions }) {
3236
- const { address, buyerPubKey, buyerPrvKey, operatorConsented } = state;
3237
- const { copied: copiedPrivate, copy: copyPrivate } = useCopyFeedback();
3238
- const [isPrivateKeyVisible, setIsPrivateKeyVisible] = useState10(false);
3239
- const [isGenerating, setIsGenerating] = useState10(false);
3240
- const [isSigning, setIsSigning] = useState10(false);
3241
- return /* @__PURE__ */ jsxs9(Card8, { gap: "$2", children: [
3242
- /* @__PURE__ */ jsx9(Heading6, { level: 6, children: "Buyer & Operator" }),
3243
- address && /* @__PURE__ */ jsx9(AddressView, { label: "Payer", address }),
3244
- buyerPubKey && /* @__PURE__ */ jsx9(AddressView, { label: "Buyer", address: buyerPubKey }),
3245
- /* @__PURE__ */ jsxs9(XStack10, { gap: "$2", alignItems: "stretch", width: "100%", children: [
3246
- /* @__PURE__ */ jsx9(
3247
- Button6,
3924
+ // src/components/setup/SignerKeyPanel.tsx
3925
+ import { useState as useState8 } from "react";
3926
+ import {
3927
+ Badge,
3928
+ BadgeText,
3929
+ Button as Button5,
3930
+ ButtonText as ButtonText5,
3931
+ Heading as Heading5,
3932
+ Input as Input3,
3933
+ Text as Text7,
3934
+ XStack as XStack8,
3935
+ YStack as YStack7,
3936
+ Icon as Icon4
3937
+ } from "@goodwidget/ui";
3938
+ import { Fragment as Fragment4, jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
3939
+ var ZERO_OPERATOR = "0x0000000000000000000000000000000000000000";
3940
+ function SignerKeyPanel({
3941
+ state,
3942
+ actions,
3943
+ onProceed,
3944
+ showHeading = true,
3945
+ proceedLabel: proceedLabelOverride,
3946
+ compact = false
3947
+ }) {
3948
+ const [choice, setChoice] = useState8(null);
3949
+ const [privateKey, setPrivateKey] = useState8("");
3950
+ const [isImporting, setIsImporting] = useState8(false);
3951
+ const [keyConfirmed, setKeyConfirmed] = useState8(false);
3952
+ const [importedAddress, setImportedAddress] = useState8(null);
3953
+ const leaveChoice = () => {
3954
+ setChoice(null);
3955
+ setImportedAddress(null);
3956
+ };
3957
+ const currentOperator = state.currentOperator?.toLowerCase();
3958
+ const expectedOperator = state.operatorAddress?.toLowerCase();
3959
+ const proceedLabel = proceedLabelOverride ?? (state.operatorConsented ? "Done" : "Continue to Authorize Wallet");
3960
+ const hasDifferentOperator = Boolean(currentOperator) && currentOperator !== ZERO_OPERATOR && Boolean(expectedOperator) && currentOperator !== expectedOperator;
3961
+ if (choice === "generate") {
3962
+ return /* @__PURE__ */ jsxs7(YStack7, { gap: "$3", children: [
3963
+ /* @__PURE__ */ jsxs7(Button5, { variant: "text", alignSelf: "flex-start", onPress: leaveChoice, children: [
3964
+ /* @__PURE__ */ jsx7(Icon4, { name: "arrow-left", size: "xs", color: "primary" }),
3965
+ /* @__PURE__ */ jsx7(ButtonText5, { children: "Back to Generate / Import" })
3966
+ ] }),
3967
+ /* @__PURE__ */ jsx7(
3968
+ BuyerKeyPanel,
3969
+ {
3970
+ embedded: true,
3971
+ buyerPubKey: state.buyerPubKey,
3972
+ buyerPrvKey: state.buyerPrvKey,
3973
+ buyerPubKeySaved: keyConfirmed,
3974
+ onGenerate: actions.generateBuyerKey,
3975
+ onConfirm: () => setKeyConfirmed(true)
3976
+ }
3977
+ ),
3978
+ keyConfirmed && /* @__PURE__ */ jsx7(Button5, { size: "sm", ...compactButtonProps, onPress: onProceed, children: /* @__PURE__ */ jsx7(ButtonText5, { children: proceedLabel }) })
3979
+ ] });
3980
+ }
3981
+ if (choice === "import") {
3982
+ const importedSigner = !isImporting && Boolean(importedAddress) && state.buyerPubKey?.toLowerCase() === importedAddress?.toLowerCase();
3983
+ const importedSignerBlocked = importedSigner && hasDifferentOperator;
3984
+ return /* @__PURE__ */ jsxs7(YStack7, { gap: "$3", children: [
3985
+ /* @__PURE__ */ jsxs7(Button5, { variant: "text", alignSelf: "flex-start", onPress: leaveChoice, children: [
3986
+ /* @__PURE__ */ jsx7(Icon4, { name: "arrow-left", size: "xs", color: "primary" }),
3987
+ /* @__PURE__ */ jsx7(ButtonText5, { children: "Back to Generate / Import" })
3988
+ ] }),
3989
+ /* @__PURE__ */ jsx7(Heading5, { level: 5, children: "Import Signer Key" }),
3990
+ /* @__PURE__ */ jsx7(Text7, { secondary: true, children: "Paste the private key from AntSeed. It will be checked against the operator configured for this signer before you can continue." }),
3991
+ /* @__PURE__ */ jsx7(
3992
+ Input3,
3248
3993
  {
3249
- flex: 1,
3250
- flexBasis: 0,
3251
- minWidth: 0,
3252
3994
  size: "sm",
3253
- ...compactButtonProps,
3254
- onPress: () => {
3255
- setIsGenerating(true);
3256
- void Promise.resolve(actions.generateBuyerKey()).finally(() => setIsGenerating(false));
3257
- },
3258
- disabled: isGenerating,
3259
- children: /* @__PURE__ */ jsx9(ButtonText5, { children: isGenerating ? "Signing\u2026" : "Sign & Generate" })
3995
+ value: privateKey,
3996
+ onChangeText: setPrivateKey,
3997
+ placeholder: "0x\u2026",
3998
+ autoCapitalize: "none"
3260
3999
  }
3261
4000
  ),
3262
- /* @__PURE__ */ jsx9(
3263
- Button6,
4001
+ state.error && /* @__PURE__ */ jsx7(Text7, { color: "$error", children: state.error }),
4002
+ /* @__PURE__ */ jsx7(
4003
+ Button5,
3264
4004
  {
3265
- flex: 1,
3266
- flexBasis: 0,
3267
- minWidth: 0,
3268
4005
  size: "sm",
3269
4006
  ...compactButtonProps,
4007
+ disabled: !privateKey.trim() || isImporting,
3270
4008
  onPress: () => {
3271
- setIsSigning(true);
3272
- void Promise.resolve(actions.signOperatorConsent()).finally(() => setIsSigning(false));
4009
+ setIsImporting(true);
4010
+ setImportedAddress(null);
4011
+ void actions.importBuyerFromPrivateKey(privateKey.trim()).then((buyerAddress) => setImportedAddress(buyerAddress)).catch(() => setImportedAddress(null)).finally(() => setIsImporting(false));
3273
4012
  },
3274
- disabled: operatorConsented || isSigning || !buyerPrvKey,
3275
- children: isSigning ? /* @__PURE__ */ jsx9(Spinner5, { size: "sm" }) : /* @__PURE__ */ jsx9(ButtonText5, { children: operatorConsented ? "Consented" : "Sign Consent" })
4013
+ children: /* @__PURE__ */ jsx7(ButtonText5, { children: isImporting ? "Checking signer\u2026" : "Import Signer Key" })
3276
4014
  }
3277
- )
3278
- ] }),
3279
- buyerPrvKey && /* @__PURE__ */ jsxs9(YStack9, { gap: "$2", children: [
3280
- /* @__PURE__ */ jsxs9(XStack10, { justifyContent: "space-between", alignItems: "center", children: [
3281
- /* @__PURE__ */ jsx9(Text9, { fontSize: "$1", secondary: true, children: "Buyer Private Key" }),
3282
- /* @__PURE__ */ jsx9(
3283
- Button6,
3284
- {
3285
- variant: "text",
3286
- size: "sm",
3287
- onPress: () => setIsPrivateKeyVisible((prev) => !prev),
3288
- children: /* @__PURE__ */ jsx9(ButtonText5, { children: isPrivateKeyVisible ? "Hide" : "Reveal" })
3289
- }
3290
- )
3291
- ] }),
3292
- /* @__PURE__ */ jsxs9(
3293
- XStack10,
3294
- {
3295
- backgroundColor: "$backgroundMuted",
3296
- borderRadius: "$2",
3297
- padding: "$2",
3298
- justifyContent: "space-between",
3299
- alignItems: "center",
3300
- children: [
3301
- /* @__PURE__ */ jsx9(Text9, { fontSize: "$2", style: monospaceSingleLineStyle, flex: 1, numberOfLines: 1, children: isPrivateKeyVisible ? buyerPrvKey : "\u2022".repeat(Math.min(48, buyerPrvKey.length)) }),
3302
- /* @__PURE__ */ jsx9(
3303
- Button6,
3304
- {
3305
- size: "sm",
3306
- variant: "ghost",
3307
- iconSize: "sm",
3308
- onPress: () => void copyPrivate(buyerPrvKey),
3309
- children: /* @__PURE__ */ jsx9(
3310
- Icon6,
3311
- {
3312
- name: copiedPrivate ? "check" : "copy",
3313
- size: "xs",
3314
- color: copiedPrivate ? "success" : "text"
3315
- }
3316
- )
3317
- }
3318
- )
3319
- ]
3320
- }
3321
- )
4015
+ ),
4016
+ importedSignerBlocked ? /* @__PURE__ */ jsxs7(YStack7, { gap: "$2", children: [
4017
+ /* @__PURE__ */ jsx7(Text7, { color: "$error", fontWeight: "700", children: "Signer key cannot be used" }),
4018
+ /* @__PURE__ */ jsx7(Text7, { 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." })
4019
+ ] }) : importedSigner ? /* @__PURE__ */ jsxs7(YStack7, { gap: "$2", children: [
4020
+ /* @__PURE__ */ jsx7(Text7, { color: "$success", fontWeight: "700", children: "Signer imported" }),
4021
+ /* @__PURE__ */ jsxs7(Text7, { secondary: true, children: [
4022
+ truncateAddress(state.buyerPubKey ?? ""),
4023
+ " is now your active signer."
4024
+ ] }),
4025
+ /* @__PURE__ */ jsx7(Text7, { 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." }),
4026
+ /* @__PURE__ */ jsx7(Button5, { size: "sm", ...compactButtonProps, onPress: onProceed, children: /* @__PURE__ */ jsx7(ButtonText5, { children: proceedLabel }) })
4027
+ ] }) : null
4028
+ ] });
4029
+ }
4030
+ const choices = /* @__PURE__ */ jsxs7(Fragment4, { children: [
4031
+ /* @__PURE__ */ jsxs7(
4032
+ Button5,
4033
+ {
4034
+ flex: compact ? void 0 : 1,
4035
+ alignSelf: compact ? "stretch" : void 0,
4036
+ size: compact ? "sm" : "lg",
4037
+ variant: "outline",
4038
+ ...compactButtonProps,
4039
+ onPress: () => setChoice("generate"),
4040
+ children: [
4041
+ !compact && /* @__PURE__ */ jsx7(Badge, { type: "success", children: /* @__PURE__ */ jsx7(BadgeText, { children: "Recommended" }) }),
4042
+ /* @__PURE__ */ jsx7(ButtonText5, { children: "Generate Signer Key" })
4043
+ ]
4044
+ }
4045
+ ),
4046
+ /* @__PURE__ */ jsx7(
4047
+ Button5,
4048
+ {
4049
+ flex: compact ? void 0 : 1,
4050
+ alignSelf: compact ? "stretch" : void 0,
4051
+ size: compact ? "sm" : "lg",
4052
+ variant: "outline",
4053
+ ...compactButtonProps,
4054
+ onPress: () => setChoice("import"),
4055
+ children: /* @__PURE__ */ jsx7(ButtonText5, { children: "Import Signer Key" })
4056
+ }
4057
+ )
4058
+ ] });
4059
+ return /* @__PURE__ */ jsxs7(YStack7, { gap: "$3", children: [
4060
+ showHeading && /* @__PURE__ */ jsx7(Heading5, { level: 5, children: "Signer Key" }),
4061
+ !compact && /* @__PURE__ */ jsx7(Text7, { secondary: true, children: "A dedicated identity used only to buy and spend AI credits \u2014 separate from your wallet." }),
4062
+ compact ? /* @__PURE__ */ jsx7(YStack7, { gap: "$2", children: choices }) : /* @__PURE__ */ jsx7(XStack8, { gap: "$3", children: choices }),
4063
+ !compact && /* @__PURE__ */ jsx7(Text7, { 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." })
4064
+ ] });
4065
+ }
4066
+
4067
+ // src/components/manage/BuyerOperatorCard.tsx
4068
+ import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
4069
+ function shortAddress(address) {
4070
+ return `${address.slice(0, 6)}\u2026${address.slice(-4)}`;
4071
+ }
4072
+ function DisclosureToggle({
4073
+ open,
4074
+ label,
4075
+ onPress
4076
+ }) {
4077
+ return /* @__PURE__ */ jsxs8(
4078
+ Button6,
4079
+ {
4080
+ variant: "text",
4081
+ size: "sm",
4082
+ alignSelf: "flex-start",
4083
+ gap: "$1.5",
4084
+ ...compactButtonProps,
4085
+ paddingHorizontal: "$0",
4086
+ "aria-expanded": open,
4087
+ onPress,
4088
+ children: [
4089
+ /* @__PURE__ */ jsx8(Icon5, { name: open ? "chevron-up" : "chevron-down", size: "xs", color: "primary" }),
4090
+ /* @__PURE__ */ jsx8(ButtonText6, { children: label })
4091
+ ]
4092
+ }
4093
+ );
4094
+ }
4095
+ function CopyableValue({ value, display }) {
4096
+ const { copied, copy } = useCopyFeedback();
4097
+ return /* @__PURE__ */ jsxs8(
4098
+ XStack9,
4099
+ {
4100
+ backgroundColor: "$backgroundMuted",
4101
+ borderRadius: "$2",
4102
+ padding: "$2",
4103
+ justifyContent: "space-between",
4104
+ alignItems: "center",
4105
+ gap: "$2",
4106
+ children: [
4107
+ /* @__PURE__ */ jsx8(Text8, { fontSize: "$2", flex: 1, numberOfLines: 1, style: monospaceSingleLineStyle, children: display ?? value }),
4108
+ /* @__PURE__ */ jsx8(Button6, { size: "sm", variant: "ghost", iconSize: "sm", onPress: () => void copy(value), children: /* @__PURE__ */ jsx8(Icon5, { name: copied ? "check" : "copy", size: "xs", color: copied ? "success" : "text" }) })
4109
+ ]
4110
+ }
4111
+ );
4112
+ }
4113
+ function SignerStatus({
4114
+ consented,
4115
+ size = "$1"
4116
+ }) {
4117
+ return /* @__PURE__ */ jsxs8(XStack9, { gap: "$1", alignItems: "center", children: [
4118
+ /* @__PURE__ */ jsx8(
4119
+ Icon5,
4120
+ {
4121
+ name: consented ? "check" : "alert-triangle",
4122
+ size: "2xs",
4123
+ color: consented ? "success" : "warning"
4124
+ }
4125
+ ),
4126
+ /* @__PURE__ */ jsx8(Text8, { fontSize: size, color: consented ? "$success" : "$warning", children: consented ? "Authorized" : "Not authorized" })
4127
+ ] });
4128
+ }
4129
+ function BuyerSelector({
4130
+ buyers,
4131
+ activeBuyerAddress,
4132
+ onSelect
4133
+ }) {
4134
+ return /* @__PURE__ */ jsx8(YStack8, { gap: "$1", children: buyers.map((buyer) => {
4135
+ const isActive = buyer.toLowerCase() === activeBuyerAddress?.toLowerCase();
4136
+ return /* @__PURE__ */ jsxs8(
4137
+ XStack9,
4138
+ {
4139
+ tag: "button",
4140
+ role: "option",
4141
+ "aria-selected": isActive,
4142
+ alignItems: "center",
4143
+ justifyContent: "space-between",
4144
+ gap: "$2",
4145
+ paddingHorizontal: "$2",
4146
+ paddingVertical: "$1.5",
4147
+ borderRadius: "$2",
4148
+ borderWidth: 1,
4149
+ borderColor: isActive ? "$primary" : "$borderColor",
4150
+ backgroundColor: isActive ? "$infoMuted" : "$backgroundDark",
4151
+ cursor: isActive ? "default" : "pointer",
4152
+ hoverStyle: isActive ? {} : { backgroundColor: "$backgroundPress" },
4153
+ onPress: () => {
4154
+ if (!isActive) void onSelect(buyer);
4155
+ },
4156
+ children: [
4157
+ /* @__PURE__ */ jsx8(
4158
+ Text8,
4159
+ {
4160
+ fontSize: "$2",
4161
+ fontWeight: isActive ? "700" : "500",
4162
+ color: isActive ? "$primary" : "$color",
4163
+ numberOfLines: 1,
4164
+ flex: 1,
4165
+ style: monospaceSingleLineStyle,
4166
+ children: shortAddress(buyer)
4167
+ }
4168
+ ),
4169
+ isActive ? /* @__PURE__ */ jsxs8(XStack9, { gap: "$1", alignItems: "center", children: [
4170
+ /* @__PURE__ */ jsx8(Text8, { fontSize: "$1", color: "$primary", children: "active" }),
4171
+ /* @__PURE__ */ jsx8(Icon5, { name: "check", size: "xs", color: "primary" })
4172
+ ] }) : null
4173
+ ]
4174
+ },
4175
+ buyer
4176
+ );
4177
+ }) });
4178
+ }
4179
+ function BuyerOperatorCard({ state, actions }) {
4180
+ const {
4181
+ buyerPubKey,
4182
+ buyerPrvKey,
4183
+ operatorSignature,
4184
+ operatorConsented,
4185
+ operatorConsentPending,
4186
+ buyers
4187
+ } = state;
4188
+ const [isExpanded, setIsExpanded] = useState9(false);
4189
+ const [showSwitcher, setShowSwitcher] = useState9(false);
4190
+ const [showReplacePanel, setShowReplacePanel] = useState9(false);
4191
+ const [showPrivateKey, setShowPrivateKey] = useState9(false);
4192
+ const [panelInstance, setPanelInstance] = useState9(0);
4193
+ const buyerCanSign = Boolean(buyerPrvKey || operatorSignature);
4194
+ return /* @__PURE__ */ jsxs8(Card7, { gap: "$3", "data-testid": "signer-key-card", children: [
4195
+ /* @__PURE__ */ jsxs8(
4196
+ XStack9,
4197
+ {
4198
+ tag: "button",
4199
+ "data-testid": "signer-key-toggle",
4200
+ alignItems: "center",
4201
+ justifyContent: "space-between",
4202
+ gap: "$2",
4203
+ width: "100%",
4204
+ backgroundColor: "transparent",
4205
+ borderWidth: 0,
4206
+ paddingHorizontal: "$0",
4207
+ paddingVertical: "$0",
4208
+ cursor: "pointer",
4209
+ "aria-expanded": isExpanded,
4210
+ onPress: () => setIsExpanded((prev) => !prev),
4211
+ children: [
4212
+ /* @__PURE__ */ jsxs8(YStack8, { gap: "$1", flex: 1, minWidth: 0, alignItems: "flex-start", children: [
4213
+ /* @__PURE__ */ jsx8(Heading6, { level: 6, children: "Signer Key" }),
4214
+ buyerPubKey ? /* @__PURE__ */ jsxs8(XStack9, { alignItems: "center", flexWrap: "wrap", children: [
4215
+ /* @__PURE__ */ jsx8(Text8, { fontSize: "$1", secondary: true, style: monospaceSingleLineStyle, children: `${truncateAddress(buyerPubKey)} \xB7 ` }),
4216
+ /* @__PURE__ */ jsx8(SignerStatus, { consented: operatorConsented })
4217
+ ] }) : /* @__PURE__ */ jsx8(Text8, { fontSize: "$1", secondary: true, children: "No signer key yet" })
4218
+ ] }),
4219
+ /* @__PURE__ */ jsx8(Icon5, { name: isExpanded ? "chevron-up" : "chevron-down", size: "sm", color: "muted" })
4220
+ ]
4221
+ }
4222
+ ),
4223
+ isExpanded && /* @__PURE__ */ jsxs8(YStack8, { gap: "$4", children: [
4224
+ buyerPubKey && /* @__PURE__ */ jsxs8(YStack8, { gap: "$2", children: [
4225
+ /* @__PURE__ */ jsx8(Text8, { variant: "label", secondary: true, children: "Active signer" }),
4226
+ /* @__PURE__ */ jsxs8(
4227
+ YStack8,
4228
+ {
4229
+ backgroundColor: "$backgroundDark",
4230
+ borderRadius: "$2",
4231
+ borderWidth: 1,
4232
+ borderColor: "$borderColor",
4233
+ padding: "$2",
4234
+ gap: "$2",
4235
+ children: [
4236
+ /* @__PURE__ */ jsx8(CopyableValue, { value: buyerPubKey, display: truncateAddress(buyerPubKey) }),
4237
+ /* @__PURE__ */ jsx8(SignerStatus, { consented: operatorConsented, size: "$2" }),
4238
+ !operatorConsented && /* @__PURE__ */ jsx8(
4239
+ Button6,
4240
+ {
4241
+ size: "sm",
4242
+ ...compactButtonProps,
4243
+ disabled: operatorConsentPending || !buyerCanSign,
4244
+ onPress: () => {
4245
+ void Promise.resolve(actions.signOperatorConsent());
4246
+ },
4247
+ children: operatorConsentPending ? /* @__PURE__ */ jsx8(Spinner5, { size: "sm" }) : /* @__PURE__ */ jsx8(ButtonText6, { children: "Authorize GoodDollar" })
4248
+ }
4249
+ )
4250
+ ]
4251
+ }
4252
+ )
4253
+ ] }),
4254
+ buyers.length > 1 && /* @__PURE__ */ jsxs8(YStack8, { gap: "$2", children: [
4255
+ /* @__PURE__ */ jsx8(
4256
+ DisclosureToggle,
4257
+ {
4258
+ open: showSwitcher,
4259
+ label: `Switch signer (${buyers.length})`,
4260
+ onPress: () => setShowSwitcher((prev) => !prev)
4261
+ }
4262
+ ),
4263
+ showSwitcher && /* @__PURE__ */ jsx8(
4264
+ BuyerSelector,
4265
+ {
4266
+ buyers,
4267
+ activeBuyerAddress: buyerPubKey,
4268
+ onSelect: actions.selectBuyer
4269
+ }
4270
+ )
4271
+ ] }),
4272
+ /* @__PURE__ */ jsxs8(YStack8, { gap: "$2", children: [
4273
+ buyerPubKey ? /* @__PURE__ */ jsx8(
4274
+ DisclosureToggle,
4275
+ {
4276
+ open: showReplacePanel,
4277
+ label: "Replace signer key",
4278
+ onPress: () => setShowReplacePanel((prev) => !prev)
4279
+ }
4280
+ ) : null,
4281
+ (showReplacePanel || !buyerPubKey) && /* @__PURE__ */ jsx8(
4282
+ SignerKeyPanel,
4283
+ {
4284
+ state,
4285
+ actions,
4286
+ showHeading: false,
4287
+ compact: Boolean(buyerPubKey),
4288
+ proceedLabel: "Done",
4289
+ onProceed: () => setPanelInstance((prev) => prev + 1)
4290
+ },
4291
+ panelInstance
4292
+ )
4293
+ ] }),
4294
+ buyerPrvKey && /* @__PURE__ */ jsxs8(YStack8, { gap: "$2", children: [
4295
+ /* @__PURE__ */ jsxs8(XStack9, { justifyContent: "space-between", alignItems: "center", gap: "$2", children: [
4296
+ /* @__PURE__ */ jsx8(Text8, { variant: "label", secondary: true, children: "Private key" }),
4297
+ /* @__PURE__ */ jsx8(
4298
+ Button6,
4299
+ {
4300
+ variant: "text",
4301
+ size: "sm",
4302
+ ...compactButtonProps,
4303
+ paddingHorizontal: "$0",
4304
+ onPress: () => setShowPrivateKey((prev) => !prev),
4305
+ children: /* @__PURE__ */ jsx8(ButtonText6, { children: showPrivateKey ? "Hide" : "Reveal" })
4306
+ }
4307
+ )
4308
+ ] }),
4309
+ /* @__PURE__ */ jsx8(
4310
+ CopyableValue,
4311
+ {
4312
+ value: buyerPrvKey,
4313
+ display: showPrivateKey ? buyerPrvKey : "\u2022".repeat(Math.min(48, buyerPrvKey.length))
4314
+ }
4315
+ ),
4316
+ /* @__PURE__ */ jsx8(Text8, { fontSize: "$1", color: "$warning", children: "Treat this like a password \u2014 anyone who has it can spend your credits." })
4317
+ ] })
3322
4318
  ] })
3323
4319
  ] });
3324
4320
  }
3325
4321
 
3326
4322
  // src/components/manage/SetupSnippet.tsx
3327
- import { useState as useState11 } from "react";
4323
+ import { useState as useState10 } from "react";
3328
4324
  import {
3329
4325
  Anchor,
3330
4326
  Button as Button7,
3331
- Card as Card9,
3332
- Icon as Icon7,
3333
- Text as Text10,
3334
- XStack as XStack11,
3335
- YStack as YStack10,
4327
+ Card as Card8,
4328
+ Icon as Icon6,
4329
+ Text as Text9,
4330
+ XStack as XStack10,
4331
+ YStack as YStack9,
3336
4332
  copyTextToClipboard as copyTextToClipboard2
3337
4333
  } from "@goodwidget/ui";
3338
- import { jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
4334
+ import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
3339
4335
  var ANTSEED_API_DOCS_URL = "https://antseed.com/docs/guides/using-the-api";
3340
4336
  var setupSnippetLineStyle = {
3341
4337
  fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",
@@ -3356,8 +4352,8 @@ function buildSetupSnippet() {
3356
4352
  ].join("\n");
3357
4353
  }
3358
4354
  function SetupSnippet() {
3359
- const [expanded, setExpanded] = useState11(false);
3360
- const [copied, setCopied] = useState11(false);
4355
+ const [expanded, setExpanded] = useState10(false);
4356
+ const [copied, setCopied] = useState10(false);
3361
4357
  const snippet = buildSetupSnippet();
3362
4358
  const copyText = snippet.replace(/\n\n+/g, "\n").trim();
3363
4359
  const lines = snippet.trim().split("\n");
@@ -3367,10 +4363,10 @@ function SetupSnippet() {
3367
4363
  setCopied(true);
3368
4364
  setTimeout(() => setCopied(false), 2e3);
3369
4365
  }
3370
- return /* @__PURE__ */ jsxs10(Card9, { gap: "$2", children: [
3371
- /* @__PURE__ */ jsxs10(XStack11, { justifyContent: "space-between", alignItems: "center", children: [
3372
- /* @__PURE__ */ jsxs10(
3373
- XStack11,
4366
+ return /* @__PURE__ */ jsxs9(Card8, { gap: "$2", children: [
4367
+ /* @__PURE__ */ jsxs9(XStack10, { justifyContent: "space-between", alignItems: "center", children: [
4368
+ /* @__PURE__ */ jsxs9(
4369
+ XStack10,
3374
4370
  {
3375
4371
  flex: 1,
3376
4372
  justifyContent: "space-between",
@@ -3378,29 +4374,29 @@ function SetupSnippet() {
3378
4374
  onPress: () => setExpanded((value) => !value),
3379
4375
  cursor: "pointer",
3380
4376
  children: [
3381
- /* @__PURE__ */ jsx10(Text10, { fontSize: "$3", fontWeight: "600", children: "API Setup" }),
3382
- /* @__PURE__ */ jsx10(Icon7, { name: expanded ? "chevron-up" : "chevron-right", size: "xs", color: "muted" })
4377
+ /* @__PURE__ */ jsx9(Text9, { fontSize: "$3", fontWeight: "600", children: "API Setup" }),
4378
+ /* @__PURE__ */ jsx9(Icon6, { name: expanded ? "chevron-up" : "chevron-right", size: "xs", color: "muted" })
3383
4379
  ]
3384
4380
  }
3385
4381
  ),
3386
- /* @__PURE__ */ jsx10(Button7, { size: "sm", variant: "ghost", iconSize: "sm", onPress: handleCopy, children: /* @__PURE__ */ jsx10(Icon7, { name: copied ? "check" : "copy", size: "xs", color: copied ? "success" : "text" }) })
4382
+ /* @__PURE__ */ jsx9(Button7, { size: "sm", variant: "ghost", iconSize: "sm", onPress: handleCopy, children: /* @__PURE__ */ jsx9(Icon6, { name: copied ? "check" : "copy", size: "xs", color: copied ? "success" : "text" }) })
3387
4383
  ] }),
3388
- expanded && /* @__PURE__ */ jsxs10(YStack10, { gap: "$2", children: [
3389
- /* @__PURE__ */ jsx10(
3390
- YStack10,
4384
+ expanded && /* @__PURE__ */ jsxs9(YStack9, { gap: "$2", children: [
4385
+ /* @__PURE__ */ jsx9(
4386
+ YStack9,
3391
4387
  {
3392
4388
  backgroundColor: "$backgroundMuted",
3393
4389
  borderRadius: "$2",
3394
4390
  padding: "$3",
3395
4391
  width: "100%",
3396
4392
  gap: "$1",
3397
- children: lines.map((line, index) => /* @__PURE__ */ jsx10(Text10, { color: "$text", style: setupSnippetLineStyle, children: line.length > 0 ? line : " " }, index))
4393
+ children: lines.map((line, index) => /* @__PURE__ */ jsx9(Text9, { color: "$text", style: setupSnippetLineStyle, children: line.length > 0 ? line : " " }, index))
3398
4394
  }
3399
4395
  ),
3400
- /* @__PURE__ */ jsxs10(Text10, { fontSize: "$1", secondary: true, children: [
4396
+ /* @__PURE__ */ jsxs9(Text9, { fontSize: "$1", secondary: true, children: [
3401
4397
  "To connect AI tools to the AntSeed AI provider, see the",
3402
4398
  " ",
3403
- /* @__PURE__ */ jsx10(Anchor, { href: ANTSEED_API_DOCS_URL, target: "_blank", children: "AntSeed API guide" }),
4399
+ /* @__PURE__ */ jsx9(Anchor, { href: ANTSEED_API_DOCS_URL, target: "_blank", children: "AntSeed API guide" }),
3404
4400
  "."
3405
4401
  ] })
3406
4402
  ] })
@@ -3408,20 +4404,20 @@ function SetupSnippet() {
3408
4404
  }
3409
4405
 
3410
4406
  // src/components/history/HistoryTab.tsx
3411
- import { useMemo as useMemo5, useState as useState12 } from "react";
4407
+ import { useMemo as useMemo5, useState as useState11 } from "react";
3412
4408
  import {
3413
4409
  Button as Button8,
3414
- ButtonText as ButtonText6,
3415
- Card as Card10,
4410
+ ButtonText as ButtonText7,
4411
+ Card as Card9,
3416
4412
  Heading as Heading7,
3417
- Icon as Icon8,
3418
- Input as Input3,
4413
+ Icon as Icon7,
4414
+ Input as Input4,
3419
4415
  Spinner as Spinner6,
3420
- Text as Text11,
3421
- XStack as XStack12,
3422
- YStack as YStack11
4416
+ Text as Text10,
4417
+ XStack as XStack11,
4418
+ YStack as YStack10
3423
4419
  } from "@goodwidget/ui";
3424
- import { jsx as jsx11, jsxs as jsxs11 } from "react/jsx-runtime";
4420
+ import { jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
3425
4421
  var STATUS_OPTIONS = [
3426
4422
  { label: "All", value: "all" },
3427
4423
  { label: "Funded", value: "funded" },
@@ -3493,10 +4489,10 @@ function entryDetailRows(entry) {
3493
4489
  return rows;
3494
4490
  }
3495
4491
  function EntryDetailRow({ label, value }) {
3496
- return /* @__PURE__ */ jsxs11(XStack12, { gap: "$2", alignItems: "flex-start", width: "100%", children: [
3497
- /* @__PURE__ */ jsx11(Text11, { fontSize: "$1", fontWeight: "600", secondary: true, minWidth: 72, flexShrink: 0, children: label }),
3498
- /* @__PURE__ */ jsx11(
3499
- Text11,
4492
+ return /* @__PURE__ */ jsxs10(XStack11, { gap: "$2", alignItems: "flex-start", width: "100%", children: [
4493
+ /* @__PURE__ */ jsx10(Text10, { fontSize: "$1", fontWeight: "600", secondary: true, minWidth: 72, flexShrink: 0, children: label }),
4494
+ /* @__PURE__ */ jsx10(
4495
+ Text10,
3500
4496
  {
3501
4497
  fontSize: "$1",
3502
4498
  flex: 1,
@@ -3616,9 +4612,9 @@ function CreditHistoryEntryRow({
3616
4612
  const amounts = amountLines(entry);
3617
4613
  const detailRows = entryDetailRows(entry);
3618
4614
  const titleColor = entry.fundingStatus === "failed" ? "$error" : "$color";
3619
- return /* @__PURE__ */ jsxs11(Card10, { gap: "$2", children: [
3620
- /* @__PURE__ */ jsxs11(
3621
- XStack12,
4615
+ return /* @__PURE__ */ jsxs10(Card9, { gap: "$2", children: [
4616
+ /* @__PURE__ */ jsxs10(
4617
+ XStack11,
3622
4618
  {
3623
4619
  alignItems: "center",
3624
4620
  gap: "$3",
@@ -3626,8 +4622,8 @@ function CreditHistoryEntryRow({
3626
4622
  cursor: "pointer",
3627
4623
  onPress: onToggle,
3628
4624
  children: [
3629
- /* @__PURE__ */ jsx11(
3630
- YStack11,
4625
+ /* @__PURE__ */ jsx10(
4626
+ YStack10,
3631
4627
  {
3632
4628
  width: 40,
3633
4629
  height: 40,
@@ -3636,8 +4632,8 @@ function CreditHistoryEntryRow({
3636
4632
  justifyContent: "center",
3637
4633
  backgroundColor: entryIconBackground(entry),
3638
4634
  flexShrink: 0,
3639
- children: /* @__PURE__ */ jsx11(
3640
- Icon8,
4635
+ children: /* @__PURE__ */ jsx10(
4636
+ Icon7,
3641
4637
  {
3642
4638
  name: entryIconName(entry),
3643
4639
  size: "sm",
@@ -3646,11 +4642,11 @@ function CreditHistoryEntryRow({
3646
4642
  )
3647
4643
  }
3648
4644
  ),
3649
- /* @__PURE__ */ jsxs11(YStack11, { flex: 1, gap: "$0.5", minWidth: 0, children: [
3650
- /* @__PURE__ */ jsx11(Text11, { fontSize: "$3", fontWeight: "700", color: titleColor, children: sourceLabel(entry.source) }),
3651
- /* @__PURE__ */ jsxs11(XStack12, { alignItems: "center", gap: "$1", children: [
3652
- /* @__PURE__ */ jsx11(
3653
- YStack11,
4645
+ /* @__PURE__ */ jsxs10(YStack10, { flex: 1, gap: "$0.5", minWidth: 0, children: [
4646
+ /* @__PURE__ */ jsx10(Text10, { fontSize: "$3", fontWeight: "700", color: titleColor, children: sourceLabel(entry.source) }),
4647
+ /* @__PURE__ */ jsxs10(XStack11, { alignItems: "center", gap: "$1", children: [
4648
+ /* @__PURE__ */ jsx10(
4649
+ YStack10,
3654
4650
  {
3655
4651
  width: 6,
3656
4652
  height: 6,
@@ -3658,18 +4654,18 @@ function CreditHistoryEntryRow({
3658
4654
  backgroundColor: accent
3659
4655
  }
3660
4656
  ),
3661
- /* @__PURE__ */ jsx11(Text11, { fontSize: "$1", fontWeight: "600", color: accent, letterSpacing: 0.4, children: statusLabel(entry.fundingStatus) })
4657
+ /* @__PURE__ */ jsx10(Text10, { fontSize: "$1", fontWeight: "600", color: accent, letterSpacing: 0.4, children: statusLabel(entry.fundingStatus) })
3662
4658
  ] })
3663
4659
  ] }),
3664
- /* @__PURE__ */ jsxs11(YStack11, { alignItems: "flex-end", gap: "$0.5", flexShrink: 0, children: [
3665
- amounts?.primary ? /* @__PURE__ */ jsx11(Text11, { fontSize: "$3", fontWeight: "700", color: amountColor, children: amounts.primary }) : null,
3666
- amounts?.secondary ? /* @__PURE__ */ jsx11(Text11, { fontSize: "$2", fontWeight: "600", color: amountColor, children: amounts.secondary }) : null,
3667
- /* @__PURE__ */ jsx11(Text11, { fontSize: "$1", secondary: true, children: formatEntryDate(entry.createdAt) })
4660
+ /* @__PURE__ */ jsxs10(YStack10, { alignItems: "flex-end", gap: "$0.5", flexShrink: 0, children: [
4661
+ amounts?.primary ? /* @__PURE__ */ jsx10(Text10, { fontSize: "$3", fontWeight: "700", color: amountColor, children: amounts.primary }) : null,
4662
+ amounts?.secondary ? /* @__PURE__ */ jsx10(Text10, { fontSize: "$2", fontWeight: "600", color: amountColor, children: amounts.secondary }) : null,
4663
+ /* @__PURE__ */ jsx10(Text10, { fontSize: "$1", secondary: true, children: formatEntryDate(entry.createdAt) })
3668
4664
  ] })
3669
4665
  ]
3670
4666
  }
3671
4667
  ),
3672
- expanded && detailRows.length > 0 ? /* @__PURE__ */ jsx11(YStack11, { gap: "$1.5", paddingTop: "$1", children: detailRows.map((row) => /* @__PURE__ */ jsx11(EntryDetailRow, { label: row.label, value: row.value }, row.label)) }) : null
4668
+ expanded && detailRows.length > 0 ? /* @__PURE__ */ jsx10(YStack10, { gap: "$1.5", paddingTop: "$1", children: detailRows.map((row) => /* @__PURE__ */ jsx10(EntryDetailRow, { label: row.label, value: row.value }, row.label)) }) : null
3673
4669
  ] });
3674
4670
  }
3675
4671
  function SourceFilterChip({
@@ -3677,8 +4673,8 @@ function SourceFilterChip({
3677
4673
  selected,
3678
4674
  onPress
3679
4675
  }) {
3680
- return /* @__PURE__ */ jsx11(
3681
- XStack12,
4676
+ return /* @__PURE__ */ jsx10(
4677
+ XStack11,
3682
4678
  {
3683
4679
  tag: "button",
3684
4680
  role: "checkbox",
@@ -3700,8 +4696,8 @@ function SourceFilterChip({
3700
4696
  },
3701
4697
  onPress,
3702
4698
  flexShrink: 0,
3703
- children: /* @__PURE__ */ jsx11(
3704
- Text11,
4699
+ children: /* @__PURE__ */ jsx10(
4700
+ Text10,
3705
4701
  {
3706
4702
  fontSize: "$2",
3707
4703
  fontWeight: selected ? "700" : "500",
@@ -3717,11 +4713,11 @@ function StatusFilterSelect({
3717
4713
  value,
3718
4714
  onValueChange
3719
4715
  }) {
3720
- const [open, setOpen] = useState12(false);
4716
+ const [open, setOpen] = useState11(false);
3721
4717
  const selected = STATUS_OPTIONS.find((option) => option.value === value);
3722
- return /* @__PURE__ */ jsxs11(YStack11, { flex: 1, minWidth: 0, position: "relative", zIndex: open ? 20 : 1, children: [
3723
- /* @__PURE__ */ jsxs11(
3724
- XStack12,
4718
+ return /* @__PURE__ */ jsxs10(YStack10, { flex: 1, minWidth: 0, position: "relative", zIndex: open ? 20 : 1, children: [
4719
+ /* @__PURE__ */ jsxs10(
4720
+ XStack11,
3725
4721
  {
3726
4722
  tag: "button",
3727
4723
  role: "combobox",
@@ -3737,16 +4733,16 @@ function StatusFilterSelect({
3737
4733
  cursor: "pointer",
3738
4734
  onPress: () => setOpen((current) => !current),
3739
4735
  children: [
3740
- /* @__PURE__ */ jsxs11(Text11, { fontSize: "$2", color: "$placeholderColor", numberOfLines: 1, flex: 1, children: [
4736
+ /* @__PURE__ */ jsxs10(Text10, { fontSize: "$2", color: "$placeholderColor", numberOfLines: 1, flex: 1, children: [
3741
4737
  "Status: ",
3742
4738
  selected?.label ?? "All"
3743
4739
  ] }),
3744
- /* @__PURE__ */ jsx11(Icon8, { name: open ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
4740
+ /* @__PURE__ */ jsx10(Icon7, { name: open ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
3745
4741
  ]
3746
4742
  }
3747
4743
  ),
3748
- open ? /* @__PURE__ */ jsx11(
3749
- YStack11,
4744
+ open ? /* @__PURE__ */ jsx10(
4745
+ YStack10,
3750
4746
  {
3751
4747
  position: "absolute",
3752
4748
  top: "100%",
@@ -3759,8 +4755,93 @@ function StatusFilterSelect({
3759
4755
  backgroundColor: "$backgroundDark",
3760
4756
  overflow: "hidden",
3761
4757
  zIndex: 30,
3762
- children: STATUS_OPTIONS.map((option) => /* @__PURE__ */ jsx11(
3763
- XStack12,
4758
+ children: STATUS_OPTIONS.map((option) => /* @__PURE__ */ jsx10(
4759
+ XStack11,
4760
+ {
4761
+ tag: "button",
4762
+ role: "option",
4763
+ paddingHorizontal: "$3",
4764
+ paddingVertical: "$2",
4765
+ cursor: "pointer",
4766
+ backgroundColor: option.value === value ? "$infoMuted" : "transparent",
4767
+ hoverStyle: { backgroundColor: "$backgroundPress" },
4768
+ onPress: () => {
4769
+ onValueChange(option.value);
4770
+ setOpen(false);
4771
+ },
4772
+ children: /* @__PURE__ */ jsx10(
4773
+ Text10,
4774
+ {
4775
+ fontSize: "$2",
4776
+ fontWeight: option.value === value ? "700" : "500",
4777
+ color: option.value === value ? "$primary" : "$color",
4778
+ children: option.label
4779
+ }
4780
+ )
4781
+ },
4782
+ option.value
4783
+ ))
4784
+ }
4785
+ ) : null
4786
+ ] });
4787
+ }
4788
+ function BuyerFilterSelect({
4789
+ value,
4790
+ buyers,
4791
+ onValueChange
4792
+ }) {
4793
+ const [open, setOpen] = useState11(false);
4794
+ if (buyers.length === 0) return null;
4795
+ const options = [
4796
+ { value: BUYER_FILTER_ALL, label: "All buyers" },
4797
+ ...buyers.map((b) => ({
4798
+ value: b.address,
4799
+ label: b.label ?? `${b.address.slice(0, 6)}\u2026${b.address.slice(-4)}`
4800
+ }))
4801
+ ];
4802
+ const selected = options.find((o) => o.value === value) ?? options[0];
4803
+ return /* @__PURE__ */ jsxs10(YStack10, { flex: 1, minWidth: 0, position: "relative", zIndex: open ? 25 : 1, children: [
4804
+ /* @__PURE__ */ jsxs10(
4805
+ XStack11,
4806
+ {
4807
+ tag: "button",
4808
+ role: "listbox",
4809
+ height: "$7",
4810
+ alignItems: "center",
4811
+ justifyContent: "space-between",
4812
+ gap: "$2",
4813
+ paddingHorizontal: "$3",
4814
+ borderRadius: "$3",
4815
+ borderWidth: 1,
4816
+ borderColor: "$borderColor",
4817
+ backgroundColor: "$backgroundDark",
4818
+ cursor: "pointer",
4819
+ onPress: () => setOpen((current) => !current),
4820
+ children: [
4821
+ /* @__PURE__ */ jsxs10(Text10, { fontSize: "$2", color: "$placeholderColor", numberOfLines: 1, flex: 1, children: [
4822
+ "Buyer: ",
4823
+ selected?.label ?? "All buyers"
4824
+ ] }),
4825
+ /* @__PURE__ */ jsx10(Icon7, { name: open ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
4826
+ ]
4827
+ }
4828
+ ),
4829
+ open ? /* @__PURE__ */ jsx10(
4830
+ YStack10,
4831
+ {
4832
+ position: "absolute",
4833
+ top: "100%",
4834
+ left: 0,
4835
+ right: 0,
4836
+ marginTop: "$1",
4837
+ borderRadius: "$3",
4838
+ borderWidth: 1,
4839
+ borderColor: "$borderColor",
4840
+ backgroundColor: "$backgroundDark",
4841
+ overflow: "hidden",
4842
+ zIndex: 35,
4843
+ children: options.map((option) => /* @__PURE__ */ jsx10(
4844
+ XStack11,
3764
4845
  {
3765
4846
  tag: "button",
3766
4847
  role: "option",
@@ -3773,8 +4854,8 @@ function StatusFilterSelect({
3773
4854
  onValueChange(option.value);
3774
4855
  setOpen(false);
3775
4856
  },
3776
- children: /* @__PURE__ */ jsx11(
3777
- Text11,
4857
+ children: /* @__PURE__ */ jsx10(
4858
+ Text10,
3778
4859
  {
3779
4860
  fontSize: "$2",
3780
4861
  fontWeight: option.value === value ? "700" : "500",
@@ -3789,10 +4870,11 @@ function StatusFilterSelect({
3789
4870
  ) : null
3790
4871
  ] });
3791
4872
  }
3792
- function HistoryTab({ state, actions }) {
4873
+ function HistoryTab({ state, actions, knownBuyers = [] }) {
3793
4874
  const {
3794
4875
  selectedSources,
3795
4876
  statusFilter,
4877
+ buyerAddressFilter,
3796
4878
  fromDate,
3797
4879
  toDate,
3798
4880
  entries,
@@ -3802,7 +4884,7 @@ function HistoryTab({ state, actions }) {
3802
4884
  error,
3803
4885
  activeSources
3804
4886
  } = state;
3805
- const [expandedEntryId, setExpandedEntryId] = useState12(null);
4887
+ const [expandedEntryId, setExpandedEntryId] = useState11(null);
3806
4888
  const defaultRange = useMemo5(() => getLast90DaysRange(), []);
3807
4889
  const isDefaultRange = fromDate === defaultRange.from && toDate === defaultRange.to;
3808
4890
  const rangeSummary = isDefaultRange ? `Last ${HISTORY_LOOKBACK_DAYS} days activity` : `${formatShortDate(fromDate)} \u2013 ${formatShortDate(toDate)}`;
@@ -3810,18 +4892,18 @@ function HistoryTab({ state, actions }) {
3810
4892
  () => formatAccumulatedG(sumFilteredGdWei(entries)),
3811
4893
  [entries]
3812
4894
  );
3813
- return /* @__PURE__ */ jsxs11(YStack11, { gap: "$3", width: "100%", children: [
3814
- /* @__PURE__ */ jsxs11(Card10, { gap: "$3", children: [
3815
- /* @__PURE__ */ jsx11(XStack12, { alignItems: "flex-start", justifyContent: "space-between", gap: "$2", width: "100%", children: /* @__PURE__ */ jsxs11(YStack11, { flex: 1, gap: "$0.5", minWidth: 0, children: [
3816
- /* @__PURE__ */ jsx11(Heading7, { level: 4, children: "AI Credit History" }),
3817
- /* @__PURE__ */ jsx11(Text11, { fontSize: "$1", secondary: true, children: rangeSummary })
4895
+ return /* @__PURE__ */ jsxs10(YStack10, { gap: "$3", width: "100%", children: [
4896
+ /* @__PURE__ */ jsxs10(Card9, { gap: "$3", children: [
4897
+ /* @__PURE__ */ jsx10(XStack11, { alignItems: "flex-start", justifyContent: "space-between", gap: "$2", width: "100%", children: /* @__PURE__ */ jsxs10(YStack10, { flex: 1, gap: "$0.5", minWidth: 0, children: [
4898
+ /* @__PURE__ */ jsx10(Heading7, { level: 4, children: "AI Credit History" }),
4899
+ /* @__PURE__ */ jsx10(Text10, { fontSize: "$1", secondary: true, children: rangeSummary })
3818
4900
  ] }) }),
3819
- /* @__PURE__ */ jsxs11(YStack11, { gap: "$1", children: [
3820
- /* @__PURE__ */ jsx11(Text11, { fontSize: "$1", fontWeight: "600", secondary: true, letterSpacing: 0.6, children: "TOTAL ACCUMULATED" }),
3821
- /* @__PURE__ */ jsx11(Text11, { fontSize: "$7", fontWeight: "700", color: "$color", children: accumulatedG })
4901
+ /* @__PURE__ */ jsxs10(YStack10, { gap: "$1", children: [
4902
+ /* @__PURE__ */ jsx10(Text10, { fontSize: "$1", fontWeight: "600", secondary: true, letterSpacing: 0.6, children: "TOTAL ACCUMULATED" }),
4903
+ /* @__PURE__ */ jsx10(Text10, { fontSize: "$7", fontWeight: "700", color: "$color", children: accumulatedG })
3822
4904
  ] })
3823
4905
  ] }),
3824
- /* @__PURE__ */ jsx11(XStack12, { gap: "$2", flexWrap: "wrap", width: "100%", children: SOURCE_PILL_OPTIONS.map((option) => /* @__PURE__ */ jsx11(
4906
+ /* @__PURE__ */ jsx10(XStack11, { gap: "$2", flexWrap: "wrap", width: "100%", children: SOURCE_PILL_OPTIONS.map((option) => /* @__PURE__ */ jsx10(
3825
4907
  SourceFilterChip,
3826
4908
  {
3827
4909
  label: option.label,
@@ -3830,16 +4912,26 @@ function HistoryTab({ state, actions }) {
3830
4912
  },
3831
4913
  option.id
3832
4914
  )) }),
3833
- /* @__PURE__ */ jsx11(XStack12, { gap: "$2", alignItems: "center", width: "100%", children: /* @__PURE__ */ jsx11(
3834
- StatusFilterSelect,
3835
- {
3836
- value: statusFilter,
3837
- onValueChange: actions.setStatusFilter
3838
- }
3839
- ) }),
3840
- /* @__PURE__ */ jsxs11(XStack12, { gap: "$2", width: "100%", children: [
3841
- /* @__PURE__ */ jsx11(YStack11, { flex: 1, minWidth: 0, children: /* @__PURE__ */ jsx11(
3842
- Input3,
4915
+ /* @__PURE__ */ jsxs10(XStack11, { gap: "$2", alignItems: "center", width: "100%", children: [
4916
+ /* @__PURE__ */ jsx10(
4917
+ StatusFilterSelect,
4918
+ {
4919
+ value: statusFilter,
4920
+ onValueChange: actions.setStatusFilter
4921
+ }
4922
+ ),
4923
+ /* @__PURE__ */ jsx10(
4924
+ BuyerFilterSelect,
4925
+ {
4926
+ value: buyerAddressFilter,
4927
+ buyers: knownBuyers,
4928
+ onValueChange: actions.setBuyerAddressFilter
4929
+ }
4930
+ )
4931
+ ] }),
4932
+ /* @__PURE__ */ jsxs10(XStack11, { gap: "$2", width: "100%", children: [
4933
+ /* @__PURE__ */ jsx10(YStack10, { flex: 1, minWidth: 0, children: /* @__PURE__ */ jsx10(
4934
+ Input4,
3843
4935
  {
3844
4936
  size: "sm",
3845
4937
  type: "date",
@@ -3848,8 +4940,8 @@ function HistoryTab({ state, actions }) {
3848
4940
  onChangeText: actions.setFromDate
3849
4941
  }
3850
4942
  ) }),
3851
- /* @__PURE__ */ jsx11(YStack11, { flex: 1, minWidth: 0, children: /* @__PURE__ */ jsx11(
3852
- Input3,
4943
+ /* @__PURE__ */ jsx10(YStack10, { flex: 1, minWidth: 0, children: /* @__PURE__ */ jsx10(
4944
+ Input4,
3853
4945
  {
3854
4946
  size: "sm",
3855
4947
  type: "date",
@@ -3859,10 +4951,10 @@ function HistoryTab({ state, actions }) {
3859
4951
  }
3860
4952
  ) })
3861
4953
  ] }),
3862
- /* @__PURE__ */ jsxs11(XStack12, { alignItems: "center", justifyContent: "space-between", gap: "$2", width: "100%", children: [
3863
- /* @__PURE__ */ jsx11(Text11, { fontSize: "$1", fontWeight: "700", secondary: true, letterSpacing: 0.6, children: "CREDIT HISTORY" }),
3864
- /* @__PURE__ */ jsx11(
3865
- XStack12,
4954
+ /* @__PURE__ */ jsxs10(XStack11, { alignItems: "center", justifyContent: "space-between", gap: "$2", width: "100%", children: [
4955
+ /* @__PURE__ */ jsx10(Text10, { fontSize: "$1", fontWeight: "700", secondary: true, letterSpacing: 0.6, children: "CREDIT HISTORY" }),
4956
+ /* @__PURE__ */ jsx10(
4957
+ XStack11,
3866
4958
  {
3867
4959
  tag: "button",
3868
4960
  backgroundColor: "transparent",
@@ -3876,16 +4968,16 @@ function HistoryTab({ state, actions }) {
3876
4968
  if (entries.length === 0) return;
3877
4969
  exportEntriesCsv(entries);
3878
4970
  },
3879
- children: /* @__PURE__ */ jsx11(Text11, { fontSize: "$2", fontWeight: "600", color: "$primary", children: "Export CSV" })
4971
+ children: /* @__PURE__ */ jsx10(Text10, { fontSize: "$2", fontWeight: "600", color: "$primary", children: "Export CSV" })
3880
4972
  }
3881
4973
  )
3882
4974
  ] }),
3883
- loading ? /* @__PURE__ */ jsx11(Card10, { gap: "$2", children: /* @__PURE__ */ jsxs11(YStack11, { alignItems: "center", paddingVertical: "$4", gap: "$2", children: [
3884
- /* @__PURE__ */ jsx11(Spinner6, { size: "sm" }),
3885
- /* @__PURE__ */ jsx11(Text11, { fontSize: "$2", secondary: true, children: "Loading credit history\u2026" })
3886
- ] }) }) : error ? /* @__PURE__ */ jsx11(Card10, { gap: "$2", children: /* @__PURE__ */ jsxs11(YStack11, { gap: "$2", paddingVertical: "$2", children: [
3887
- /* @__PURE__ */ jsx11(Text11, { color: "$error", fontSize: "$2", children: error }),
3888
- /* @__PURE__ */ jsx11(
4975
+ loading ? /* @__PURE__ */ jsx10(Card9, { gap: "$2", children: /* @__PURE__ */ jsxs10(YStack10, { alignItems: "center", paddingVertical: "$4", gap: "$2", children: [
4976
+ /* @__PURE__ */ jsx10(Spinner6, { size: "sm" }),
4977
+ /* @__PURE__ */ jsx10(Text10, { fontSize: "$2", secondary: true, children: "Loading credit history\u2026" })
4978
+ ] }) }) : error ? /* @__PURE__ */ jsx10(Card9, { gap: "$2", children: /* @__PURE__ */ jsxs10(YStack10, { gap: "$2", paddingVertical: "$2", children: [
4979
+ /* @__PURE__ */ jsx10(Text10, { color: "$error", fontSize: "$2", children: error }),
4980
+ /* @__PURE__ */ jsx10(
3889
4981
  Button8,
3890
4982
  {
3891
4983
  variant: "outline",
@@ -3895,10 +4987,10 @@ function HistoryTab({ state, actions }) {
3895
4987
  onPress: () => {
3896
4988
  void actions.reload();
3897
4989
  },
3898
- children: /* @__PURE__ */ jsx11(ButtonText6, { children: "Retry" })
4990
+ children: /* @__PURE__ */ jsx10(ButtonText7, { children: "Retry" })
3899
4991
  }
3900
4992
  )
3901
- ] }) }) : activeSources.length === 0 ? /* @__PURE__ */ jsx11(Card10, { children: /* @__PURE__ */ jsx11(Text11, { fontSize: "$2", secondary: true, children: "Select at least one source to view history." }) }) : entries.length === 0 ? /* @__PURE__ */ jsx11(Card10, { children: /* @__PURE__ */ jsx11(Text11, { fontSize: "$2", secondary: true, children: "No credit history matches these filters." }) }) : /* @__PURE__ */ jsx11(YStack11, { gap: "$2", width: "100%", children: entries.map((entry) => /* @__PURE__ */ jsx11(
4993
+ ] }) }) : activeSources.length === 0 ? /* @__PURE__ */ jsx10(Card9, { children: /* @__PURE__ */ jsx10(Text10, { fontSize: "$2", secondary: true, children: "Select at least one source to view history." }) }) : entries.length === 0 ? /* @__PURE__ */ jsx10(Card9, { children: /* @__PURE__ */ jsx10(Text10, { fontSize: "$2", secondary: true, children: "No credit history matches these filters." }) }) : /* @__PURE__ */ jsx10(YStack10, { gap: "$2", width: "100%", children: entries.map((entry) => /* @__PURE__ */ jsx10(
3902
4994
  CreditHistoryEntryRow,
3903
4995
  {
3904
4996
  entry,
@@ -3907,7 +4999,7 @@ function HistoryTab({ state, actions }) {
3907
4999
  },
3908
5000
  entry.id
3909
5001
  )) }),
3910
- !loading && !error && hasMore && /* @__PURE__ */ jsxs11(
5002
+ !loading && !error && hasMore && /* @__PURE__ */ jsxs10(
3911
5003
  Button8,
3912
5004
  {
3913
5005
  variant: "outline",
@@ -3919,36 +5011,558 @@ function HistoryTab({ state, actions }) {
3919
5011
  void actions.loadMore();
3920
5012
  },
3921
5013
  children: [
3922
- loadingMore ? /* @__PURE__ */ jsx11(Spinner6, { size: "sm" }) : null,
3923
- /* @__PURE__ */ jsx11(ButtonText6, { children: loadingMore ? "Loading\u2026" : "Load more" })
5014
+ loadingMore ? /* @__PURE__ */ jsx10(Spinner6, { size: "sm" }) : null,
5015
+ /* @__PURE__ */ jsx10(ButtonText7, { children: loadingMore ? "Loading\u2026" : "Load more" })
3924
5016
  ]
3925
5017
  }
3926
5018
  )
3927
5019
  ] });
3928
5020
  }
3929
5021
 
3930
- // src/components/flow/purchaseFlowUtils.ts
3931
- function mapStatusToActiveStep(state, buyerPubKeySaved) {
3932
- if (state.operatorConsented) return "pay";
3933
- if (!state.buyerPubKey || !state.buyerPrvKey) return "buyer_key";
3934
- if (!buyerPubKeySaved) return "buyer_key";
3935
- if (!state.operatorConsented) return "consent";
3936
- if (state.status === "purchase_setup" || state.status === "quote_ready" || state.status === "payment_pending" || state.status === "payment_confirmed" || state.status === "payment_failed")
3937
- return "pay";
3938
- return null;
3939
- }
3940
- function getAiCreditsActiveFlowStep(state, buyerPubKeySaved) {
3941
- return mapStatusToActiveStep(state, buyerPubKeySaved);
3942
- }
5022
+ // src/components/setup/SetupGuidanceCard.tsx
5023
+ import { Anchor as Anchor2, Button as Button9, ButtonText as ButtonText8, Icon as Icon9, Separator as Separator2, Text as Text12, XStack as XStack13, YStack as YStack12 } from "@goodwidget/ui";
5024
+
5025
+ // src/components/setup/SetupBonusHighlight.tsx
5026
+ import { useState as useState12 } from "react";
5027
+ import { Card as Card10, Icon as Icon8, Text as Text11, XStack as XStack12, YStack as YStack11 } from "@goodwidget/ui";
5028
+ import { Fragment as Fragment5, jsx as jsx11, jsxs as jsxs11 } from "react/jsx-runtime";
5029
+ function SetupBonusHighlight({
5030
+ depositBonusPercent,
5031
+ streamBonusPercent,
5032
+ isGoodIdVerified
5033
+ }) {
5034
+ const [isExpanded, setIsExpanded] = useState12(false);
5035
+ const maxBonusPercent = Math.max(depositBonusPercent, streamBonusPercent);
5036
+ if (maxBonusPercent <= 0) return null;
5037
+ return /* @__PURE__ */ jsxs11(Card10, { gap: "$2", padding: "$3", backgroundColor: "$backgroundHover", children: [
5038
+ /* @__PURE__ */ jsxs11(
5039
+ XStack12,
5040
+ {
5041
+ gap: "$3",
5042
+ alignItems: "center",
5043
+ cursor: "pointer",
5044
+ accessibilityRole: "button",
5045
+ "aria-expanded": isExpanded,
5046
+ onPress: () => setIsExpanded((previous) => !previous),
5047
+ children: [
5048
+ /* @__PURE__ */ jsx11(
5049
+ YStack11,
5050
+ {
5051
+ width: 34,
5052
+ height: 34,
5053
+ borderRadius: "$2",
5054
+ backgroundColor: "$backgroundPress",
5055
+ alignItems: "center",
5056
+ justifyContent: "center",
5057
+ flexShrink: 0,
5058
+ children: /* @__PURE__ */ jsx11(Icon8, { name: "party-popper", size: "sm", color: "primary" })
5059
+ }
5060
+ ),
5061
+ /* @__PURE__ */ jsxs11(YStack11, { flex: 1, gap: 2, children: [
5062
+ /* @__PURE__ */ jsxs11(Text11, { fontSize: "$3", fontWeight: "700", children: [
5063
+ "Up to ",
5064
+ maxBonusPercent,
5065
+ "% more AI credits"
5066
+ ] }),
5067
+ /* @__PURE__ */ jsxs11(Text11, { fontSize: "$2", lineHeight: "$3", children: [
5068
+ /* @__PURE__ */ jsxs11(Text11, { fontSize: "$2", fontWeight: "700", color: "$primary", children: [
5069
+ "+",
5070
+ depositBonusPercent,
5071
+ "%"
5072
+ ] }),
5073
+ /* @__PURE__ */ jsxs11(Text11, { fontSize: "$2", secondary: true, children: [
5074
+ " ",
5075
+ "on deposits,",
5076
+ " "
5077
+ ] }),
5078
+ /* @__PURE__ */ jsxs11(Text11, { fontSize: "$2", fontWeight: "700", color: "$primary", children: [
5079
+ "+",
5080
+ streamBonusPercent,
5081
+ "%"
5082
+ ] }),
5083
+ /* @__PURE__ */ jsxs11(Text11, { fontSize: "$2", secondary: true, children: [
5084
+ " ",
5085
+ "on streams \u2014 paid with G$"
5086
+ ] })
5087
+ ] })
5088
+ ] }),
5089
+ /* @__PURE__ */ jsx11(Icon8, { name: isExpanded ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
5090
+ ]
5091
+ }
5092
+ ),
5093
+ isExpanded && /* @__PURE__ */ jsx11(YStack11, { backgroundColor: "$background", borderRadius: "$2", padding: "$3", children: /* @__PURE__ */ jsx11(Text11, { fontSize: "$2", secondary: true, lineHeight: "$3", children: isGoodIdVerified ? /* @__PURE__ */ jsxs11(Fragment5, { children: [
5094
+ "Your wallet is",
5095
+ " ",
5096
+ /* @__PURE__ */ jsx11(Text11, { fontSize: "$2", fontWeight: "700", children: "GoodID verified" }),
5097
+ ", so the bonus is applied automatically to deposits and streams."
5098
+ ] }) : /* @__PURE__ */ jsxs11(Fragment5, { children: [
5099
+ "Bonus applies to",
5100
+ " ",
5101
+ /* @__PURE__ */ jsx11(Text11, { fontSize: "$2", fontWeight: "700", children: "verified GoodDollar wallets" }),
5102
+ " ",
5103
+ "only. Not verified? Claim UBI first via GoodWallet or GoodDapp \u2014 takes a minute, then this kicks in automatically."
5104
+ ] }) }) })
5105
+ ] });
5106
+ }
5107
+
5108
+ // src/components/setup/SetupGuidanceCard.tsx
5109
+ import { jsx as jsx12, jsxs as jsxs12 } from "react/jsx-runtime";
5110
+ var ANTSEED_SITE_URL = "https://antseed.com";
5111
+ function SetupGuidanceCard({
5112
+ onHowToUse,
5113
+ onFaq,
5114
+ activeHelpView,
5115
+ depositBonusPercent,
5116
+ streamBonusPercent,
5117
+ isGoodIdVerified
5118
+ }) {
5119
+ return (
5120
+ // Rendered flush on the widget background — no card surface, so it reads as
5121
+ // part of the header rather than a separate panel.
5122
+ /* @__PURE__ */ jsxs12(YStack12, { gap: "$3", paddingHorizontal: "$1", children: [
5123
+ /* @__PURE__ */ jsx12(Text12, { fontSize: "$3", secondary: true, lineHeight: "$4", children: "Buy AI credits with G$ for Claude Code, Codex, chat & other AI tools." }),
5124
+ /* @__PURE__ */ jsx12(
5125
+ SetupBonusHighlight,
5126
+ {
5127
+ depositBonusPercent,
5128
+ streamBonusPercent,
5129
+ isGoodIdVerified
5130
+ }
5131
+ ),
5132
+ /* @__PURE__ */ jsx12(YStack12, { gap: "$1", children: /* @__PURE__ */ jsx12(Text12, { variant: "label", secondary: true, fontSize: "$1", fontWeight: "700", letterSpacing: 1, children: "WHAT'S INVOLVED:" }) }),
5133
+ /* @__PURE__ */ jsxs12(YStack12, { gap: "$3", children: [
5134
+ /* @__PURE__ */ jsxs12(XStack13, { gap: "$3", alignItems: "flex-start", children: [
5135
+ /* @__PURE__ */ jsx12(
5136
+ YStack12,
5137
+ {
5138
+ width: 22,
5139
+ height: 22,
5140
+ borderRadius: "$full",
5141
+ backgroundColor: "$backgroundHover",
5142
+ alignItems: "center",
5143
+ justifyContent: "center",
5144
+ flexShrink: 0,
5145
+ marginTop: 2,
5146
+ children: /* @__PURE__ */ jsx12(Text12, { fontSize: "$1", fontWeight: "700", color: "$secondary", children: "1" })
5147
+ }
5148
+ ),
5149
+ /* @__PURE__ */ jsxs12(Text12, { fontSize: "$2", flex: 1, lineHeight: "$3", children: [
5150
+ /* @__PURE__ */ jsxs12(Text12, { fontSize: "$2", fontWeight: "700", children: [
5151
+ "Get G$",
5152
+ " "
5153
+ ] }),
5154
+ /* @__PURE__ */ jsx12(Text12, { fontSize: "$2", secondary: true, children: "\u2014 claim UBI via GoodWallet, or buy G$ with your wallet of choice" })
5155
+ ] })
5156
+ ] }),
5157
+ /* @__PURE__ */ jsxs12(XStack13, { gap: "$3", alignItems: "flex-start", children: [
5158
+ /* @__PURE__ */ jsx12(
5159
+ YStack12,
5160
+ {
5161
+ width: 22,
5162
+ height: 22,
5163
+ borderRadius: "$full",
5164
+ backgroundColor: "$backgroundHover",
5165
+ alignItems: "center",
5166
+ justifyContent: "center",
5167
+ flexShrink: 0,
5168
+ marginTop: 2,
5169
+ children: /* @__PURE__ */ jsx12(Text12, { fontSize: "$1", fontWeight: "700", color: "$secondary", children: "2" })
5170
+ }
5171
+ ),
5172
+ /* @__PURE__ */ jsxs12(Text12, { fontSize: "$2", flex: 1, lineHeight: "$3", children: [
5173
+ /* @__PURE__ */ jsxs12(Text12, { fontSize: "$2", fontWeight: "700", children: [
5174
+ "Download Antseed",
5175
+ " "
5176
+ ] }),
5177
+ /* @__PURE__ */ jsx12(Text12, { fontSize: "$2", secondary: true, children: "\u2014 the free desktop app that runs your credits locally" })
5178
+ ] })
5179
+ ] })
5180
+ ] }),
5181
+ /* @__PURE__ */ jsx12(Separator2, {}),
5182
+ /* @__PURE__ */ jsxs12(XStack13, { gap: "$2", flexWrap: "wrap", children: [
5183
+ /* @__PURE__ */ jsx12(
5184
+ Button9,
5185
+ {
5186
+ flexGrow: 1,
5187
+ flexBasis: "auto",
5188
+ size: "sm",
5189
+ variant: activeHelpView === "how-to-use" ? "default" : "outline",
5190
+ onPress: onHowToUse,
5191
+ borderRadius: "$3",
5192
+ paddingHorizontal: "$2",
5193
+ minWidth: 0,
5194
+ children: /* @__PURE__ */ jsx12(ButtonText8, { numberOfLines: 1, children: "How to use" })
5195
+ }
5196
+ ),
5197
+ /* @__PURE__ */ jsx12(
5198
+ Anchor2,
5199
+ {
5200
+ href: ANTSEED_SITE_URL,
5201
+ target: "_blank",
5202
+ style: { flexGrow: 1, flexBasis: "auto", textDecorationLine: "none", minWidth: 0 },
5203
+ children: /* @__PURE__ */ jsxs12(
5204
+ Button9,
5205
+ {
5206
+ size: "sm",
5207
+ variant: "outline",
5208
+ width: "100%",
5209
+ borderRadius: "$3",
5210
+ paddingHorizontal: "$2",
5211
+ gap: "$1",
5212
+ children: [
5213
+ /* @__PURE__ */ jsx12(ButtonText8, { numberOfLines: 1, children: "Antseed site" }),
5214
+ /* @__PURE__ */ jsx12(Icon9, { name: "external-link", size: "xs", color: "muted" })
5215
+ ]
5216
+ }
5217
+ )
5218
+ }
5219
+ ),
5220
+ /* @__PURE__ */ jsx12(
5221
+ Button9,
5222
+ {
5223
+ flexGrow: 1,
5224
+ flexBasis: "auto",
5225
+ size: "sm",
5226
+ variant: activeHelpView === "faq" ? "default" : "outline",
5227
+ onPress: onFaq,
5228
+ borderRadius: "$3",
5229
+ paddingHorizontal: "$2",
5230
+ minWidth: 0,
5231
+ children: /* @__PURE__ */ jsx12(ButtonText8, { numberOfLines: 1, children: "FAQs" })
5232
+ }
5233
+ )
5234
+ ] })
5235
+ ] })
5236
+ );
5237
+ }
5238
+
5239
+ // src/components/setup/HowToUseView.tsx
5240
+ import { Anchor as Anchor3, Badge as Badge2, BadgeText as BadgeText2, Button as Button10, ButtonText as ButtonText9, Card as Card11, Icon as Icon10, Text as Text13, XStack as XStack14, YStack as YStack13 } from "@goodwidget/ui";
5241
+ import { jsx as jsx13, jsxs as jsxs13 } from "react/jsx-runtime";
5242
+ var VIDEO_URL = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
5243
+ var WRITTEN_GUIDE_URL = "https://app.notion.com/p/gooddollar/Full-Setup-Walkthrough-Widget-AntSeed-VPR-3c0f258232f08184bee9cd440cc93059";
5244
+ var QUICK_SUMMARY_STEPS = [
5245
+ {
5246
+ index: 1,
5247
+ title: "First, connect your wallet",
5248
+ tabLabel: "Buy",
5249
+ description: "Any wallet holding G$ works. Verified GoodDollar wallets get the bonus automatically."
5250
+ },
5251
+ {
5252
+ index: 2,
5253
+ title: "Then complete the one-time setup",
5254
+ tabLabel: "Buy",
5255
+ description: "Download Antseed, generate your signer key, and authorize your wallet \u2014 three quick taps."
5256
+ },
5257
+ {
5258
+ index: 3,
5259
+ title: "Head to Manage to buy or stream credits",
5260
+ tabLabel: "Manage",
5261
+ description: "Deposit once (+10%) or stream continuously (+20%), then confirm."
5262
+ },
5263
+ {
5264
+ index: 4,
5265
+ title: "Finally, connect Antseed to start using them",
5266
+ tabLabel: "Connect",
5267
+ description: 'Import your signer key \u2014 no separate "start" step, it just works from there.'
5268
+ }
5269
+ ];
5270
+ function HowToUseView({ onBack }) {
5271
+ return /* @__PURE__ */ jsxs13(YStack13, { gap: "$4", children: [
5272
+ /* @__PURE__ */ jsxs13(Button10, { variant: "text", alignSelf: "flex-start", onPress: onBack, gap: "$1", children: [
5273
+ /* @__PURE__ */ jsx13(Icon10, { name: "arrow-left", size: "xs", color: "primary" }),
5274
+ /* @__PURE__ */ jsx13(ButtonText9, { color: "$primary", fontSize: "$2", children: "Back to setup" })
5275
+ ] }),
5276
+ /* @__PURE__ */ jsx13(Text13, { fontSize: "$2", secondary: true, lineHeight: "$3", children: "New here? Start with the 3-minute video \u2014 it covers the whole journey, start to finish." }),
5277
+ /* @__PURE__ */ jsx13(Anchor3, { href: VIDEO_URL, target: "_blank", style: { textDecorationLine: "none" }, children: /* @__PURE__ */ jsxs13(
5278
+ Card11,
5279
+ {
5280
+ backgroundColor: "$backgroundHover",
5281
+ gap: "$2",
5282
+ paddingVertical: "$4",
5283
+ paddingHorizontal: "$4",
5284
+ hoverStyle: { opacity: 0.9 },
5285
+ children: [
5286
+ /* @__PURE__ */ jsx13(XStack14, { justifyContent: "flex-end", children: /* @__PURE__ */ jsx13(Card11, { backgroundColor: "$backgroundPress", paddingHorizontal: "$2", paddingVertical: 2, children: /* @__PURE__ */ jsx13(Text13, { fontSize: "$1", fontWeight: "700", children: "3:12" }) }) }),
5287
+ /* @__PURE__ */ jsx13(XStack14, { justifyContent: "center", paddingVertical: "$6", children: /* @__PURE__ */ jsx13(
5288
+ YStack13,
5289
+ {
5290
+ width: 56,
5291
+ height: 56,
5292
+ borderRadius: "$full",
5293
+ backgroundColor: "$background",
5294
+ alignItems: "center",
5295
+ justifyContent: "center",
5296
+ children: /* @__PURE__ */ jsx13(Icon10, { name: "play", size: "md", color: "primary" })
5297
+ }
5298
+ ) }),
5299
+ /* @__PURE__ */ jsxs13(YStack13, { gap: "$1", children: [
5300
+ /* @__PURE__ */ jsx13(Text13, { fontSize: "$2", fontWeight: "700", children: "Getting started with AI credits" }),
5301
+ /* @__PURE__ */ jsx13(Text13, { fontSize: "$1", secondary: true, children: "Wallet \u2192 buy credits \u2192 connect Antseed" })
5302
+ ] })
5303
+ ]
5304
+ }
5305
+ ) }),
5306
+ /* @__PURE__ */ jsx13(Anchor3, { href: WRITTEN_GUIDE_URL, target: "_blank", style: { textDecorationLine: "none" }, children: /* @__PURE__ */ jsx13(Card11, { backgroundColor: "$backgroundHover", paddingVertical: "$3", paddingHorizontal: "$4", children: /* @__PURE__ */ jsxs13(XStack14, { gap: "$3", alignItems: "center", justifyContent: "space-between", children: [
5307
+ /* @__PURE__ */ jsxs13(XStack14, { gap: "$3", alignItems: "center", flex: 1, children: [
5308
+ /* @__PURE__ */ jsx13(Icon10, { name: "file-text", size: "md", color: "muted" }),
5309
+ /* @__PURE__ */ jsx13(YStack13, { flex: 1, gap: "$1", children: /* @__PURE__ */ jsxs13(Text13, { fontSize: "$2", lineHeight: "$3", children: [
5310
+ /* @__PURE__ */ jsxs13(Text13, { fontSize: "$2", fontWeight: "700", children: [
5311
+ "Full written guide",
5312
+ " "
5313
+ ] }),
5314
+ /* @__PURE__ */ jsx13(Text13, { fontSize: "$2", secondary: true, children: "Step-by-step walkthrough with screenshots, on Notion" })
5315
+ ] }) })
5316
+ ] }),
5317
+ /* @__PURE__ */ jsx13(Icon10, { name: "external-link", size: "xs", color: "muted" })
5318
+ ] }) }) }),
5319
+ /* @__PURE__ */ jsxs13(YStack13, { gap: "$3", children: [
5320
+ /* @__PURE__ */ jsx13(Text13, { variant: "label", secondary: true, fontSize: "$1", fontWeight: "700", letterSpacing: 1, children: "QUICK SUMMARY" }),
5321
+ /* @__PURE__ */ jsx13(YStack13, { gap: "$4", children: QUICK_SUMMARY_STEPS.map((step) => /* @__PURE__ */ jsxs13(XStack14, { gap: "$3", alignItems: "flex-start", children: [
5322
+ /* @__PURE__ */ jsx13(
5323
+ YStack13,
5324
+ {
5325
+ width: 24,
5326
+ height: 24,
5327
+ borderRadius: "$full",
5328
+ backgroundColor: "$backgroundHover",
5329
+ alignItems: "center",
5330
+ justifyContent: "center",
5331
+ flexShrink: 0,
5332
+ marginTop: 2,
5333
+ children: /* @__PURE__ */ jsx13(Text13, { fontSize: "$1", fontWeight: "700", color: "$secondary", children: step.index })
5334
+ }
5335
+ ),
5336
+ /* @__PURE__ */ jsxs13(YStack13, { flex: 1, gap: "$1", children: [
5337
+ /* @__PURE__ */ jsxs13(XStack14, { gap: "$2", alignItems: "center", flexWrap: "wrap", children: [
5338
+ /* @__PURE__ */ jsx13(Text13, { fontSize: "$2", fontWeight: "700", children: step.title }),
5339
+ /* @__PURE__ */ jsx13(Badge2, { size: "sm", children: /* @__PURE__ */ jsx13(BadgeText2, { children: step.tabLabel }) })
5340
+ ] }),
5341
+ /* @__PURE__ */ jsx13(Text13, { fontSize: "$2", secondary: true, lineHeight: "$3", children: step.description })
5342
+ ] })
5343
+ ] }, step.index)) }),
5344
+ /* @__PURE__ */ jsx13(Text13, { fontSize: "$1", secondary: true, textAlign: "center", paddingTop: "$1", children: "Your G$ wallet is never exposed \u2014 only the scoped signer key." })
5345
+ ] })
5346
+ ] });
5347
+ }
5348
+
5349
+ // src/components/setup/SetupFaqView.tsx
5350
+ import { useState as useState13 } from "react";
5351
+ import { Button as Button11, ButtonText as ButtonText10, Card as Card12, Icon as Icon11, Separator as Separator3, Text as Text14, XStack as XStack15, YStack as YStack14 } from "@goodwidget/ui";
5352
+ import { jsx as jsx14, jsxs as jsxs14 } from "react/jsx-runtime";
5353
+ var SETUP_FAQ_ITEMS = [
5354
+ {
5355
+ id: "goodwallet-only",
5356
+ question: "I only claim UBI with GoodWallet \u2014 can I still use this?",
5357
+ 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."
5358
+ },
5359
+ {
5360
+ id: "ubi-savings",
5361
+ question: "Will this ever touch my daily UBI savings?",
5362
+ 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."
5363
+ },
5364
+ {
5365
+ id: "deposit-vs-stream",
5366
+ question: "Deposit or stream \u2014 which should I pick?",
5367
+ 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."
5368
+ },
5369
+ {
5370
+ id: "lost-signer-key",
5371
+ question: "What if I lose my signer key?",
5372
+ 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.'
5373
+ },
5374
+ {
5375
+ id: "no-code",
5376
+ question: "Do I need to know how to code?",
5377
+ 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."
5378
+ },
5379
+ {
5380
+ id: "unused-credits",
5381
+ question: "Can I get unused credits back?",
5382
+ 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."
5383
+ },
5384
+ {
5385
+ id: "compatible-tools",
5386
+ question: "Which tools can I actually use my credits with?",
5387
+ 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."
5388
+ },
5389
+ {
5390
+ id: "antseed-safe",
5391
+ question: "Is Antseed safe? Can I check it myself?",
5392
+ 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."
5393
+ }
5394
+ ];
5395
+ function FaqItem({ question, answer, expanded, onToggle }) {
5396
+ return /* @__PURE__ */ jsxs14(YStack14, { gap: "$1", children: [
5397
+ /* @__PURE__ */ jsxs14(
5398
+ XStack15,
5399
+ {
5400
+ justifyContent: "space-between",
5401
+ alignItems: "center",
5402
+ gap: "$2",
5403
+ onPress: onToggle,
5404
+ cursor: "pointer",
5405
+ children: [
5406
+ /* @__PURE__ */ jsx14(Text14, { fontSize: "$2", fontWeight: "600", flex: 1, children: question }),
5407
+ /* @__PURE__ */ jsx14(Icon11, { name: expanded ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
5408
+ ]
5409
+ }
5410
+ ),
5411
+ expanded && /* @__PURE__ */ jsx14(Text14, { fontSize: "$2", secondary: true, lineHeight: "$3", children: answer })
5412
+ ] });
5413
+ }
5414
+ function SetupFaqView({ onBack }) {
5415
+ const [expandedId, setExpandedId] = useState13(null);
5416
+ return /* @__PURE__ */ jsxs14(YStack14, { gap: "$4", children: [
5417
+ /* @__PURE__ */ jsxs14(Button11, { variant: "text", alignSelf: "flex-start", onPress: onBack, gap: "$1", children: [
5418
+ /* @__PURE__ */ jsx14(Icon11, { name: "arrow-left", size: "xs", color: "primary" }),
5419
+ /* @__PURE__ */ jsx14(ButtonText10, { color: "$primary", fontSize: "$2", children: "Back to setup" })
5420
+ ] }),
5421
+ /* @__PURE__ */ jsx14(Card12, { gap: "$3", children: /* @__PURE__ */ jsx14(YStack14, { gap: "$3", children: SETUP_FAQ_ITEMS.map((item, index) => /* @__PURE__ */ jsxs14(YStack14, { gap: "$3", children: [
5422
+ index > 0 && /* @__PURE__ */ jsx14(Separator3, {}),
5423
+ /* @__PURE__ */ jsx14(
5424
+ FaqItem,
5425
+ {
5426
+ question: item.question,
5427
+ answer: item.answer,
5428
+ expanded: expandedId === item.id,
5429
+ onToggle: () => {
5430
+ setExpandedId((current) => current === item.id ? null : item.id);
5431
+ }
5432
+ }
5433
+ )
5434
+ ] }, item.id)) }) })
5435
+ ] });
5436
+ }
5437
+
5438
+ // src/components/setup/SetupOnboardingFlow.tsx
5439
+ import { useCallback as useCallback3, useState as useState14 } from "react";
5440
+ import { Drawer, ScrollArea, Stepper, YStack as YStack15 } from "@goodwidget/ui";
5441
+ import { Fragment as Fragment6, jsx as jsx15, jsxs as jsxs15 } from "react/jsx-runtime";
5442
+ var ANTSEED_DOWNLOAD_URL = "https://antseed.com";
5443
+ function SetupOnboardingFlow({ state, actions }) {
5444
+ const [downloadOpened, setDownloadOpened] = useState14(false);
5445
+ const [drawerOpen, setDrawerOpen] = useState14(false);
5446
+ const [drawerStep, setDrawerStep] = useState14(null);
5447
+ const hasSignerKey = Boolean(state.buyerPubKey);
5448
+ const downloadCompleted = downloadOpened || hasSignerKey;
5449
+ const steps = [
5450
+ {
5451
+ id: "download",
5452
+ title: "Download Antseed",
5453
+ description: "The app that runs your credits locally \u2014 required once",
5454
+ status: downloadCompleted ? "completed" : "ready"
5455
+ },
5456
+ {
5457
+ id: "signer",
5458
+ title: "Signer key",
5459
+ description: "Generate or import \u2014 separate from your wallet",
5460
+ status: !downloadCompleted ? "pending" : hasSignerKey ? "completed" : "ready"
5461
+ },
5462
+ {
5463
+ id: "authorize",
5464
+ title: "Authorize Wallet",
5465
+ description: "One-time permission \u2014 scoped to Base credits",
5466
+ status: !hasSignerKey ? "pending" : state.operatorConsented ? "completed" : "ready"
5467
+ }
5468
+ ];
5469
+ const openSignerDrawer = useCallback3(() => {
5470
+ setDrawerStep("signer");
5471
+ setDrawerOpen(true);
5472
+ }, []);
5473
+ const handleSignerReady = useCallback3(() => {
5474
+ if (state.operatorConsented) {
5475
+ setDrawerOpen(false);
5476
+ setDrawerStep(null);
5477
+ return;
5478
+ }
5479
+ setDrawerStep("authorize");
5480
+ }, [state.operatorConsented]);
5481
+ const handleStepPress = useCallback3(
5482
+ (stepId) => {
5483
+ if (stepId === "download") {
5484
+ if (typeof window !== "undefined") {
5485
+ window.open(ANTSEED_DOWNLOAD_URL, "_blank", "noopener,noreferrer");
5486
+ }
5487
+ setDownloadOpened(true);
5488
+ return;
5489
+ }
5490
+ if (stepId === "signer" && downloadCompleted) {
5491
+ openSignerDrawer();
5492
+ }
5493
+ if (stepId === "authorize" && hasSignerKey) {
5494
+ setDrawerStep("authorize");
5495
+ setDrawerOpen(true);
5496
+ }
5497
+ },
5498
+ [downloadCompleted, hasSignerKey, openSignerDrawer]
5499
+ );
5500
+ return /* @__PURE__ */ jsxs15(Fragment6, { children: [
5501
+ /* @__PURE__ */ jsx15(
5502
+ Stepper,
5503
+ {
5504
+ steps,
5505
+ activeStepId: downloadCompleted ? hasSignerKey ? "authorize" : "signer" : "download",
5506
+ onStepPress: handleStepPress
5507
+ }
5508
+ ),
5509
+ /* @__PURE__ */ jsx15(
5510
+ Drawer,
5511
+ {
5512
+ open: drawerOpen && drawerStep !== null,
5513
+ onClose: () => {
5514
+ setDrawerOpen(false);
5515
+ setDrawerStep(null);
5516
+ },
5517
+ height: "full",
5518
+ children: /* @__PURE__ */ jsx15(ScrollArea, { width: "100%", children: /* @__PURE__ */ jsxs15(YStack15, { gap: "$3", paddingBottom: "$4", width: "100%", children: [
5519
+ drawerStep === "signer" ? /* @__PURE__ */ jsx15(SignerKeyPanel, { state, actions, onProceed: handleSignerReady }) : null,
5520
+ drawerStep === "authorize" ? /* @__PURE__ */ jsx15(
5521
+ OperatorConsentStep,
5522
+ {
5523
+ embedded: true,
5524
+ buyerPubKey: state.buyerPubKey,
5525
+ buyerPrvKey: state.buyerPrvKey ?? null,
5526
+ operatorSignature: state.operatorSignature ?? null,
5527
+ operatorConsented: state.operatorConsented,
5528
+ operatorConsentPending: state.operatorConsentPending,
5529
+ onSign: actions.signOperatorConsent
5530
+ }
5531
+ ) : null
5532
+ ] }) })
5533
+ }
5534
+ )
5535
+ ] });
5536
+ }
5537
+
5538
+ // src/components/flow/purchaseFlowUtils.ts
5539
+ function isSelectedDerivedBuyer(state) {
5540
+ if (!state.buyerPubKey || !state.derivedBuyerAddress) return false;
5541
+ return state.buyerPubKey.toLowerCase() === state.derivedBuyerAddress.toLowerCase();
5542
+ }
5543
+ function mapStatusToActiveStep(state, buyerPubKeySaved) {
5544
+ if (state.operatorConsented) return "pay";
5545
+ if (!state.buyerPubKey) return "buyer_key";
5546
+ if (!state.buyerPrvKey && !state.operatorSignature) return "buyer_key";
5547
+ if (isSelectedDerivedBuyer(state) && state.buyerPrvKey && !buyerPubKeySaved) return "buyer_key";
5548
+ if (!state.operatorConsented) return "consent";
5549
+ if (state.status === "purchase_setup" || state.status === "quote_ready" || state.status === "payment_pending" || state.status === "payment_confirmed" || state.status === "payment_failed")
5550
+ return "pay";
5551
+ return null;
5552
+ }
5553
+ function getAiCreditsActiveFlowStep(state, buyerPubKeySaved) {
5554
+ return mapStatusToActiveStep(state, buyerPubKeySaved);
5555
+ }
3943
5556
  function getActiveFlowStepActionLabel(state, step, buyerPubKeySaved) {
3944
5557
  if (!step) return null;
3945
5558
  switch (step) {
3946
5559
  case "buyer_key":
3947
5560
  if (!state.buyerPubKey) return "Sign & Generate Key";
3948
- if (!buyerPubKeySaved) return "Continue Buyer Key";
3949
- return "View Buyer Key";
5561
+ if (!buyerPubKeySaved) return "Continue Signer Key";
5562
+ return "View Signer Key";
3950
5563
  case "consent":
3951
- return state.operatorConsented ? "View Operator Consent" : "Sign Operator Consent";
5564
+ if (state.operatorConsentPending) return "Submitting Authorization\u2026";
5565
+ return state.operatorConsented ? "View Authorization" : "Authorize Wallet";
3952
5566
  case "pay":
3953
5567
  return "Set Amounts & Pay";
3954
5568
  default:
@@ -3957,8 +5571,8 @@ function getActiveFlowStepActionLabel(state, step, buyerPubKeySaved) {
3957
5571
  }
3958
5572
 
3959
5573
  // src/components/flow/AiCreditsFlowStepper.tsx
3960
- import { Heading as Heading8, Stepper } from "@goodwidget/ui";
3961
- import { jsx as jsx12 } from "react/jsx-runtime";
5574
+ import { Heading as Heading8, Stepper as Stepper2 } from "@goodwidget/ui";
5575
+ import { jsx as jsx16 } from "react/jsx-runtime";
3962
5576
  var STEP_ORDER = ["buyer_key", "consent", "pay"];
3963
5577
  function AiCreditsFlowStepper({
3964
5578
  state,
@@ -3977,19 +5591,20 @@ function AiCreditsFlowStepper({
3977
5591
  if (step === "pay" && (state.status === "payment_pending" || state.status === "payment_confirmed")) {
3978
5592
  return "active";
3979
5593
  }
5594
+ if (step === "consent" && state.operatorConsentPending) return "active";
3980
5595
  return "ready";
3981
5596
  }
3982
5597
  const steps = [
3983
5598
  {
3984
5599
  id: "buyer_key",
3985
- title: "Buyer Key",
3986
- description: "Generate or provide your AI credits buyer key",
5600
+ title: "Signer Key",
5601
+ description: "Generate or import your AI credits signer key",
3987
5602
  status: getStepStatus("buyer_key")
3988
5603
  },
3989
5604
  {
3990
5605
  id: "consent",
3991
- title: "Operator Consent",
3992
- description: "Sign permission for the AntseedBuyerOperator",
5606
+ title: "Authorize Wallet",
5607
+ description: state.operatorConsentPending ? "Submitting authorization\u2026" : "Authorize GoodDollar to manage your Base credits",
3993
5608
  status: getStepStatus("consent")
3994
5609
  },
3995
5610
  {
@@ -4004,31 +5619,31 @@ function AiCreditsFlowStepper({
4004
5619
  if (!step || step.status === "completed" || step.status === "pending") return;
4005
5620
  onStepPress?.(stepId);
4006
5621
  }
4007
- return /* @__PURE__ */ jsx12(
4008
- Stepper,
5622
+ return /* @__PURE__ */ jsx16(
5623
+ Stepper2,
4009
5624
  {
4010
5625
  steps,
4011
5626
  activeStepId: activeStep,
4012
5627
  onStepPress: onStepPress ? handleStepPress : void 0,
4013
- header: /* @__PURE__ */ jsx12(Heading8, { level: 5, secondary: true, children: "Purchase Flow" })
5628
+ header: /* @__PURE__ */ jsx16(Heading8, { level: 5, secondary: true, children: "Purchase Flow" })
4014
5629
  }
4015
5630
  );
4016
5631
  }
4017
5632
 
4018
5633
  // src/components/flow/AiCreditsPurchaseFlow.tsx
4019
- import { useCallback as useCallback3, useEffect as useEffect4, useRef as useRef2, useState as useState13 } from "react";
4020
- import { Button as Button9, ButtonText as ButtonText7, Drawer, ScrollArea, YStack as YStack12 } from "@goodwidget/ui";
4021
- import { Fragment as Fragment4, jsx as jsx13, jsxs as jsxs12 } from "react/jsx-runtime";
5634
+ import { useCallback as useCallback4, useEffect as useEffect4, useRef as useRef2, useState as useState15 } from "react";
5635
+ import { Button as Button12, ButtonText as ButtonText11, Drawer as Drawer2, ScrollArea as ScrollArea2, YStack as YStack16 } from "@goodwidget/ui";
5636
+ import { Fragment as Fragment7, jsx as jsx17, jsxs as jsxs16 } from "react/jsx-runtime";
4022
5637
  function AiCreditsPurchaseFlow({
4023
5638
  state,
4024
5639
  actions,
4025
5640
  isPending,
4026
5641
  onPay
4027
5642
  }) {
4028
- const [buyerPubKeySaved, setBuyerPubKeySaved] = useState13(false);
5643
+ const [buyerPubKeySaved, setBuyerPubKeySaved] = useState15(false);
4029
5644
  const activeStep = getAiCreditsActiveFlowStep(state, buyerPubKeySaved);
4030
- const [drawerOpen, setDrawerOpen] = useState13(false);
4031
- const [drawerStep, setDrawerStep] = useState13(activeStep);
5645
+ const [drawerOpen, setDrawerOpen] = useState15(false);
5646
+ const [drawerStep, setDrawerStep] = useState15(null);
4032
5647
  const prevActiveStepRef = useRef2(null);
4033
5648
  const goodIdTabPendingRef = useRef2(false);
4034
5649
  useEffect4(() => {
@@ -4048,10 +5663,8 @@ function AiCreditsPurchaseFlow({
4048
5663
  }
4049
5664
  const previousStep = prevActiveStepRef.current;
4050
5665
  prevActiveStepRef.current = activeStep;
4051
- setDrawerStep(activeStep);
4052
- if (previousStep == null) {
4053
- setDrawerOpen(false);
4054
- } else if (previousStep !== activeStep) {
5666
+ if (previousStep != null && previousStep !== activeStep) {
5667
+ setDrawerStep(activeStep);
4055
5668
  setDrawerOpen(true);
4056
5669
  }
4057
5670
  }, [activeStep]);
@@ -4068,7 +5681,7 @@ function AiCreditsPurchaseFlow({
4068
5681
  window.addEventListener("focus", onFocus);
4069
5682
  return () => window.removeEventListener("focus", onFocus);
4070
5683
  }, [activeStep]);
4071
- const handleVerifyGoodId = useCallback3(async () => {
5684
+ const handleVerifyGoodId = useCallback4(async () => {
4072
5685
  try {
4073
5686
  const started = await actions.verifyGoodId();
4074
5687
  if (started) {
@@ -4081,7 +5694,7 @@ function AiCreditsPurchaseFlow({
4081
5694
  }
4082
5695
  }
4083
5696
  }, [actions, activeStep]);
4084
- const openDrawer = useCallback3(
5697
+ const openDrawer = useCallback4(
4085
5698
  (step) => {
4086
5699
  if (step !== activeStep && !(step === "pay" && state.status === "payment_failed")) return;
4087
5700
  setDrawerStep(step);
@@ -4089,7 +5702,7 @@ function AiCreditsPurchaseFlow({
4089
5702
  },
4090
5703
  [activeStep, state.status]
4091
5704
  );
4092
- const handleStepPress = useCallback3(
5705
+ const handleStepPress = useCallback4(
4093
5706
  (stepId) => {
4094
5707
  openDrawer(stepId);
4095
5708
  },
@@ -4100,7 +5713,7 @@ function AiCreditsPurchaseFlow({
4100
5713
  if (!step) return null;
4101
5714
  switch (step) {
4102
5715
  case "buyer_key":
4103
- return /* @__PURE__ */ jsx13(
5716
+ return /* @__PURE__ */ jsx17(
4104
5717
  BuyerKeyPanel,
4105
5718
  {
4106
5719
  embedded: true,
@@ -4112,18 +5725,20 @@ function AiCreditsPurchaseFlow({
4112
5725
  }
4113
5726
  );
4114
5727
  case "consent":
4115
- return /* @__PURE__ */ jsx13(
5728
+ return /* @__PURE__ */ jsx17(
4116
5729
  OperatorConsentStep,
4117
5730
  {
4118
5731
  embedded: true,
4119
5732
  buyerPubKey: state.buyerPubKey,
4120
5733
  buyerPrvKey: state.buyerPrvKey ?? null,
5734
+ operatorSignature: state.operatorSignature ?? null,
4121
5735
  operatorConsented: state.operatorConsented,
5736
+ operatorConsentPending: state.operatorConsentPending,
4122
5737
  onSign: actions.signOperatorConsent
4123
5738
  }
4124
5739
  );
4125
5740
  case "pay":
4126
- return /* @__PURE__ */ jsx13(
5741
+ return /* @__PURE__ */ jsx17(
4127
5742
  AmountPicker,
4128
5743
  {
4129
5744
  embedded: true,
@@ -4146,8 +5761,8 @@ function AiCreditsPurchaseFlow({
4146
5761
  return null;
4147
5762
  }
4148
5763
  }
4149
- return /* @__PURE__ */ jsxs12(Fragment4, { children: [
4150
- /* @__PURE__ */ jsx13(
5764
+ return /* @__PURE__ */ jsxs16(Fragment7, { children: [
5765
+ /* @__PURE__ */ jsx17(
4151
5766
  AiCreditsFlowStepper,
4152
5767
  {
4153
5768
  state,
@@ -4155,8 +5770,8 @@ function AiCreditsPurchaseFlow({
4155
5770
  onStepPress: handleStepPress
4156
5771
  }
4157
5772
  ),
4158
- !drawerOpen && actionLabel && activeStep && /* @__PURE__ */ jsx13(
4159
- Button9,
5773
+ !drawerOpen && actionLabel && activeStep && /* @__PURE__ */ jsx17(
5774
+ Button12,
4160
5775
  {
4161
5776
  fullWidth: true,
4162
5777
  size: "sm",
@@ -4164,33 +5779,136 @@ function AiCreditsPurchaseFlow({
4164
5779
  onPress: () => {
4165
5780
  openDrawer(activeStep);
4166
5781
  },
4167
- children: /* @__PURE__ */ jsx13(ButtonText7, { children: actionLabel })
5782
+ children: /* @__PURE__ */ jsx17(ButtonText11, { children: actionLabel })
4168
5783
  }
4169
5784
  ),
4170
- /* @__PURE__ */ jsx13(
4171
- Drawer,
5785
+ /* @__PURE__ */ jsx17(
5786
+ Drawer2,
4172
5787
  {
4173
5788
  open: drawerOpen && drawerStep !== null,
4174
5789
  onClose: () => {
4175
5790
  setDrawerOpen(false);
4176
5791
  },
4177
5792
  height: "full",
4178
- children: /* @__PURE__ */ jsx13(ScrollArea, { width: "100%", children: /* @__PURE__ */ jsx13(YStack12, { gap: "$3", paddingBottom: "$4", width: "100%", children: renderDrawerContent(drawerStep) }) })
5793
+ children: /* @__PURE__ */ jsx17(ScrollArea2, { width: "100%", children: /* @__PURE__ */ jsx17(YStack16, { gap: "$3", paddingBottom: "$4", width: "100%", children: renderDrawerContent(drawerStep) }) })
4179
5794
  }
4180
5795
  )
4181
5796
  ] });
4182
5797
  }
4183
5798
 
5799
+ // src/components/shared/WalletChip.tsx
5800
+ import { useEffect as useEffect5, useState as useState16 } from "react";
5801
+ import { Button as Button13, ButtonText as ButtonText12, Icon as Icon12, Text as Text15, XStack as XStack16, YStack as YStack17 } from "@goodwidget/ui";
5802
+ import { Fragment as Fragment8, jsx as jsx18, jsxs as jsxs17 } from "react/jsx-runtime";
5803
+ function shortAddress2(address) {
5804
+ return `${address.slice(0, 5)}\u2026${address.slice(-3)}`;
5805
+ }
5806
+ function WalletChip({
5807
+ address,
5808
+ onDisconnect,
5809
+ disconnectLabel = "Disconnect",
5810
+ disconnectIcon = "log-out",
5811
+ disabled = false
5812
+ }) {
5813
+ const [isMenuOpen, setIsMenuOpen] = useState16(false);
5814
+ const [disconnectMessage, setDisconnectMessage] = useState16(null);
5815
+ useEffect5(() => {
5816
+ if (disabled) setIsMenuOpen(false);
5817
+ }, [disabled]);
5818
+ return /* @__PURE__ */ jsxs17(XStack16, { position: "relative", alignItems: "center", opacity: disabled ? 0.5 : 1, children: [
5819
+ /* @__PURE__ */ jsxs17(
5820
+ XStack16,
5821
+ {
5822
+ gap: "$1.5",
5823
+ alignItems: "center",
5824
+ paddingHorizontal: "$2",
5825
+ paddingVertical: "$1",
5826
+ borderRadius: "$full",
5827
+ borderWidth: 1,
5828
+ borderColor: "$borderColor",
5829
+ cursor: disabled ? "not-allowed" : "pointer",
5830
+ onPress: () => {
5831
+ if (disabled) return;
5832
+ setDisconnectMessage(null);
5833
+ setIsMenuOpen((open) => !open);
5834
+ },
5835
+ "aria-label": "Wallet options",
5836
+ "aria-disabled": disabled,
5837
+ children: [
5838
+ /* @__PURE__ */ jsx18(YStack17, { width: 6, height: 6, borderRadius: "$full", backgroundColor: "$success" }),
5839
+ /* @__PURE__ */ jsx18(Text15, { fontSize: "$1", numberOfLines: 1, children: address ? shortAddress2(address) : "" }),
5840
+ /* @__PURE__ */ jsx18(Icon12, { name: "chevron-down", size: "2xs", color: "muted" })
5841
+ ]
5842
+ }
5843
+ ),
5844
+ isMenuOpen && !disabled && /* @__PURE__ */ jsxs17(Fragment8, { children: [
5845
+ /* @__PURE__ */ jsx18(
5846
+ XStack16,
5847
+ {
5848
+ position: "fixed",
5849
+ top: 0,
5850
+ left: 0,
5851
+ right: 0,
5852
+ bottom: 0,
5853
+ zIndex: 100,
5854
+ onPress: () => setIsMenuOpen(false)
5855
+ }
5856
+ ),
5857
+ /* @__PURE__ */ jsxs17(
5858
+ YStack17,
5859
+ {
5860
+ position: "absolute",
5861
+ top: "100%",
5862
+ right: 0,
5863
+ marginTop: "$1",
5864
+ backgroundColor: "$background",
5865
+ borderWidth: 1,
5866
+ borderColor: "$borderColor",
5867
+ borderRadius: "$3",
5868
+ padding: "$1",
5869
+ minWidth: 132,
5870
+ zIndex: 101,
5871
+ children: [
5872
+ /* @__PURE__ */ jsxs17(
5873
+ Button13,
5874
+ {
5875
+ size: "sm",
5876
+ variant: "list",
5877
+ height: "$6",
5878
+ paddingHorizontal: "$2",
5879
+ gap: "$1.5",
5880
+ onPress: async () => {
5881
+ if (!onDisconnect) {
5882
+ setDisconnectMessage("Disconnect should be done in your wallet's session");
5883
+ return;
5884
+ }
5885
+ setIsMenuOpen(false);
5886
+ await onDisconnect();
5887
+ },
5888
+ children: [
5889
+ /* @__PURE__ */ jsx18(Icon12, { name: disconnectIcon, size: "xs", color: "muted" }),
5890
+ /* @__PURE__ */ jsx18(ButtonText12, { fontSize: "$2", children: disconnectLabel })
5891
+ ]
5892
+ }
5893
+ ),
5894
+ disconnectMessage && /* @__PURE__ */ jsx18(Text15, { variant: "caption", tone: "secondary", padding: "$2", children: disconnectMessage })
5895
+ ]
5896
+ }
5897
+ )
5898
+ ] })
5899
+ ] });
5900
+ }
5901
+
4184
5902
  // src/AiCreditsWidget.tsx
4185
- import { Fragment as Fragment5, jsx as jsx14, jsxs as jsxs13 } from "react/jsx-runtime";
5903
+ import { Fragment as Fragment9, jsx as jsx19, jsxs as jsxs18 } from "react/jsx-runtime";
4186
5904
  var CELO_CHAIN_ID3 = 42220;
4187
- function DisconnectedPanel({
5905
+ function SetupConnectPrompt({
4188
5906
  onConnect,
4189
5907
  connecting
4190
5908
  }) {
4191
- return /* @__PURE__ */ jsx14(Card11, { children: /* @__PURE__ */ jsxs13(YStack13, { gap: "$5", paddingVertical: "$6", alignItems: "center", children: [
4192
- /* @__PURE__ */ jsx14(Text12, { secondary: true, children: "Connect your wallet to buy AI credits" }),
4193
- /* @__PURE__ */ jsx14(
5909
+ return /* @__PURE__ */ jsxs18(YStack18, { gap: "$5", alignItems: "center", paddingVertical: "$6", width: "100%", children: [
5910
+ /* @__PURE__ */ jsx19(Text16, { secondary: true, center: true, children: "Connect your wallet to get started" }),
5911
+ /* @__PURE__ */ jsx19(
4194
5912
  CircularActionButton,
4195
5913
  {
4196
5914
  label: connecting ? "Connecting..." : "Connect Wallet",
@@ -4201,31 +5919,57 @@ function DisconnectedPanel({
4201
5919
  }
4202
5920
  }
4203
5921
  )
4204
- ] }) });
5922
+ ] });
5923
+ }
5924
+ function SetupTabPanel({
5925
+ state,
5926
+ actions,
5927
+ onConnect
5928
+ }) {
5929
+ if (needsWalletConnection(state)) {
5930
+ return /* @__PURE__ */ jsx19(
5931
+ SetupConnectPrompt,
5932
+ {
5933
+ onConnect,
5934
+ connecting: state.status === "connecting"
5935
+ }
5936
+ );
5937
+ }
5938
+ return /* @__PURE__ */ jsxs18(YStack18, { gap: "$4", width: "100%", children: [
5939
+ /* @__PURE__ */ jsx19(
5940
+ AiCreditsHero,
5941
+ {
5942
+ gBalance: state.gBalance,
5943
+ isGoodIdVerified: state.isGoodIdVerified
5944
+ }
5945
+ ),
5946
+ /* @__PURE__ */ jsx19(Text16, { secondary: true, fontSize: "$2", children: "One-time setup, in order \u2014 each step unlocks the next:" }),
5947
+ /* @__PURE__ */ jsx19(SetupOnboardingFlow, { state, actions })
5948
+ ] });
4205
5949
  }
4206
5950
  function BuyCreditsPanel({ state, actions, isPending, onPay }) {
4207
5951
  let content;
4208
5952
  if (state.status === "unsupported_chain") {
4209
- content = /* @__PURE__ */ jsxs13(AiCreditsStatusNotice, { children: [
4210
- /* @__PURE__ */ jsx14(XStack13, { gap: "$2", alignItems: "center", children: /* @__PURE__ */ jsx14(Text12, { color: "$warning", fontWeight: "700", children: "Wrong Network" }) }),
4211
- /* @__PURE__ */ jsx14(Text12, { secondary: true, children: "Please switch to the Celo network to continue." }),
4212
- /* @__PURE__ */ jsx14(
4213
- Button10,
5953
+ content = /* @__PURE__ */ jsxs18(AiCreditsStatusNotice, { children: [
5954
+ /* @__PURE__ */ jsx19(XStack17, { gap: "$2", alignItems: "center", children: /* @__PURE__ */ jsx19(Text16, { color: "$warning", fontWeight: "700", children: "Wrong Network" }) }),
5955
+ /* @__PURE__ */ jsx19(Text16, { secondary: true, children: "Please switch to the Celo network to continue." }),
5956
+ /* @__PURE__ */ jsx19(
5957
+ Button14,
4214
5958
  {
4215
5959
  onPress: () => {
4216
5960
  void actions.switchChain();
4217
5961
  },
4218
- children: /* @__PURE__ */ jsx14(ButtonText8, { children: "Switch to Celo" })
5962
+ children: /* @__PURE__ */ jsx19(ButtonText13, { children: "Switch to Celo" })
4219
5963
  }
4220
5964
  )
4221
5965
  ] });
4222
5966
  } else if (state.status === "payment_failed") {
4223
- content = /* @__PURE__ */ jsxs13(Fragment5, { children: [
4224
- /* @__PURE__ */ jsxs13(AiCreditsStatusNotice, { children: [
4225
- /* @__PURE__ */ jsx14(Text12, { color: "$error", fontWeight: "700", children: "Payment Failed" }),
4226
- state.error && /* @__PURE__ */ jsx14(Text12, { secondary: true, children: state.error })
5967
+ content = /* @__PURE__ */ jsxs18(Fragment9, { children: [
5968
+ /* @__PURE__ */ jsxs18(AiCreditsStatusNotice, { children: [
5969
+ /* @__PURE__ */ jsx19(Text16, { color: "$error", fontWeight: "700", children: "Payment Failed" }),
5970
+ state.error && /* @__PURE__ */ jsx19(Text16, { secondary: true, children: state.error })
4227
5971
  ] }),
4228
- /* @__PURE__ */ jsx14(
5972
+ /* @__PURE__ */ jsx19(
4229
5973
  AiCreditsPurchaseFlow,
4230
5974
  {
4231
5975
  state,
@@ -4236,57 +5980,61 @@ function BuyCreditsPanel({ state, actions, isPending, onPay }) {
4236
5980
  )
4237
5981
  ] });
4238
5982
  } else if (state.status === "backend_unavailable") {
4239
- content = /* @__PURE__ */ jsxs13(AiCreditsStatusNotice, { children: [
4240
- /* @__PURE__ */ jsx14(Text12, { color: "$warning", fontWeight: "700", children: "Service Unavailable" }),
4241
- /* @__PURE__ */ jsx14(Text12, { secondary: true, children: "The AI credits service is temporarily unavailable. Your wallet has not been charged." }),
4242
- /* @__PURE__ */ jsx14(
4243
- Button10,
5983
+ content = /* @__PURE__ */ jsxs18(AiCreditsStatusNotice, { children: [
5984
+ /* @__PURE__ */ jsx19(Text16, { color: "$warning", fontWeight: "700", children: "Service Unavailable" }),
5985
+ /* @__PURE__ */ jsx19(Text16, { secondary: true, children: "The AI credits service is temporarily unavailable. Your wallet has not been charged." }),
5986
+ /* @__PURE__ */ jsx19(
5987
+ Button14,
4244
5988
  {
4245
5989
  onPress: () => {
4246
5990
  void actions.retry();
4247
5991
  },
4248
- children: /* @__PURE__ */ jsx14(ButtonText8, { children: "Retry" })
5992
+ children: /* @__PURE__ */ jsx19(ButtonText13, { children: "Retry" })
4249
5993
  }
4250
5994
  )
4251
5995
  ] });
4252
5996
  } else if (state.status === "insufficient_g_balance") {
4253
- content = /* @__PURE__ */ jsxs13(Fragment5, { children: [
4254
- /* @__PURE__ */ jsx14(
5997
+ content = /* @__PURE__ */ jsxs18(Fragment9, { children: [
5998
+ /* @__PURE__ */ jsx19(
4255
5999
  AiCreditsHero,
4256
6000
  {
4257
6001
  gBalance: state.gBalance,
4258
6002
  isGoodIdVerified: state.isGoodIdVerified
4259
6003
  }
4260
6004
  ),
4261
- /* @__PURE__ */ jsxs13(AiCreditsStatusNotice, { children: [
4262
- /* @__PURE__ */ jsx14(Text12, { color: "$warning", fontWeight: "700", children: "Insufficient G$ Balance" }),
4263
- /* @__PURE__ */ jsx14(Text12, { secondary: true, children: "You need at least 1 G$ to purchase AI credits. Top up your wallet and try again." })
6005
+ /* @__PURE__ */ jsxs18(AiCreditsStatusNotice, { children: [
6006
+ /* @__PURE__ */ jsx19(Text16, { color: "$warning", fontWeight: "700", children: "Insufficient G$ Balance" }),
6007
+ /* @__PURE__ */ jsx19(Text16, { secondary: true, children: "You need at least 1 G$ to purchase AI credits. Top up your wallet and try again." })
4264
6008
  ] })
4265
6009
  ] });
4266
6010
  } else if (state.status === "payment_pending" || state.status === "payment_confirmed") {
4267
6011
  const message = state.status === "payment_pending" ? "Transaction submitted \u2014 waiting for confirmation\u2026" : "Payment confirmed \u2014 settling credits on Base\u2026";
4268
- content = /* @__PURE__ */ jsxs13(Fragment5, { children: [
4269
- /* @__PURE__ */ jsx14(Card11, { children: /* @__PURE__ */ jsxs13(YStack13, { gap: "$4", alignItems: "center", padding: "$4", children: [
4270
- /* @__PURE__ */ jsx14(Spinner7, { size: "lg" }),
4271
- /* @__PURE__ */ jsx14(Text12, { center: true, secondary: true, children: message })
6012
+ content = /* @__PURE__ */ jsxs18(Fragment9, { children: [
6013
+ /* @__PURE__ */ jsx19(Card13, { children: /* @__PURE__ */ jsxs18(YStack18, { gap: "$4", alignItems: "center", padding: "$4", children: [
6014
+ /* @__PURE__ */ jsx19(Spinner7, { size: "lg" }),
6015
+ /* @__PURE__ */ jsx19(Text16, { center: true, secondary: true, children: message })
4272
6016
  ] }) }),
4273
- /* @__PURE__ */ jsx14(AiCreditsFlowStepper, { state, buyerPubKeySaved: true })
6017
+ /* @__PURE__ */ jsx19(AiCreditsFlowStepper, { state, buyerPubKeySaved: true })
4274
6018
  ] });
4275
6019
  } else {
4276
- content = /* @__PURE__ */ jsxs13(Fragment5, { children: [
4277
- state.address && /* @__PURE__ */ jsx14(
6020
+ content = /* @__PURE__ */ jsxs18(Fragment9, { children: [
6021
+ state.error && /* @__PURE__ */ jsxs18(AiCreditsStatusNotice, { children: [
6022
+ /* @__PURE__ */ jsx19(Text16, { color: "$error", fontWeight: "700", children: "Deep link unavailable" }),
6023
+ /* @__PURE__ */ jsx19(Text16, { secondary: true, children: state.error })
6024
+ ] }),
6025
+ state.address && /* @__PURE__ */ jsx19(
4278
6026
  AiCreditsHero,
4279
6027
  {
4280
6028
  gBalance: state.gBalance,
4281
6029
  isGoodIdVerified: state.isGoodIdVerified
4282
6030
  }
4283
6031
  ),
4284
- state.error && /* @__PURE__ */ jsxs13(AiCreditsStatusNotice, { children: [
4285
- /* @__PURE__ */ jsx14(Text12, { color: "$error", fontWeight: "700", children: "Request Failed" }),
4286
- /* @__PURE__ */ jsx14(Text12, { secondary: true, children: state.error })
6032
+ state.error && /* @__PURE__ */ jsxs18(AiCreditsStatusNotice, { children: [
6033
+ /* @__PURE__ */ jsx19(Text16, { color: "$error", fontWeight: "700", children: "Request Failed" }),
6034
+ /* @__PURE__ */ jsx19(Text16, { secondary: true, children: state.error })
4287
6035
  ] }),
4288
- state.gBalance !== null && Number.parseFloat(state.gBalance) <= 0 && /* @__PURE__ */ jsx14(AiCreditsStatusNotice, { children: /* @__PURE__ */ jsx14(Text12, { secondary: true, children: "You need G$ before you can buy AI credits." }) }),
4289
- /* @__PURE__ */ jsx14(
6036
+ state.gBalance !== null && Number.parseFloat(state.gBalance) <= 0 && /* @__PURE__ */ jsx19(AiCreditsStatusNotice, { children: /* @__PURE__ */ jsx19(Text16, { secondary: true, children: "You need G$ before you can buy AI credits." }) }),
6037
+ /* @__PURE__ */ jsx19(
4290
6038
  AiCreditsPurchaseFlow,
4291
6039
  {
4292
6040
  state,
@@ -4297,16 +6045,13 @@ function BuyCreditsPanel({ state, actions, isPending, onPay }) {
4297
6045
  )
4298
6046
  ] });
4299
6047
  }
4300
- return /* @__PURE__ */ jsxs13(YStack13, { gap: "$4", children: [
4301
- content,
4302
- /* @__PURE__ */ jsx14(BuyCreditsFaq, {})
4303
- ] });
6048
+ return /* @__PURE__ */ jsx19(YStack18, { gap: "$4", children: content });
4304
6049
  }
4305
6050
  function ManagePanel({
4306
6051
  state,
4307
6052
  actions
4308
6053
  }) {
4309
- const [refreshing, setRefreshing] = React11.useState(false);
6054
+ const [refreshing, setRefreshing] = React14.useState(false);
4310
6055
  const handleRefresh = async () => {
4311
6056
  setRefreshing(true);
4312
6057
  try {
@@ -4315,15 +6060,15 @@ function ManagePanel({
4315
6060
  setRefreshing(false);
4316
6061
  }
4317
6062
  };
4318
- return /* @__PURE__ */ jsxs13(YStack13, { gap: "$3", width: "100%", children: [
4319
- state.error && /* @__PURE__ */ jsx14(AiCreditsStatusNotice, { children: /* @__PURE__ */ jsx14(Text12, { color: "$error", fontSize: "$2", children: state.error }) }),
4320
- /* @__PURE__ */ jsx14(CreditsManagementCard, { state, actions }),
4321
- /* @__PURE__ */ jsx14(BuyerOperatorCard, { state, actions }),
4322
- /* @__PURE__ */ jsx14(SetupSnippet, {}),
4323
- /* @__PURE__ */ jsxs13(YStack13, { gap: "$2", width: "100%", alignItems: "center", children: [
4324
- state.error && /* @__PURE__ */ jsx14(Text12, { color: "$error", fontSize: "$2", textAlign: "center", children: state.error }),
4325
- /* @__PURE__ */ jsxs13(
4326
- Button10,
6063
+ return /* @__PURE__ */ jsxs18(YStack18, { gap: "$3", width: "100%", children: [
6064
+ state.error && /* @__PURE__ */ jsx19(AiCreditsStatusNotice, { children: /* @__PURE__ */ jsx19(Text16, { color: "$error", fontSize: "$2", children: state.error }) }),
6065
+ /* @__PURE__ */ jsx19(CreditsManagementCard, { state, actions }),
6066
+ /* @__PURE__ */ jsx19(BuyerOperatorCard, { state, actions }),
6067
+ /* @__PURE__ */ jsx19(SetupSnippet, {}),
6068
+ /* @__PURE__ */ jsxs18(YStack18, { gap: "$2", width: "100%", alignItems: "center", children: [
6069
+ state.error && /* @__PURE__ */ jsx19(Text16, { color: "$error", fontSize: "$2", textAlign: "center", children: state.error }),
6070
+ /* @__PURE__ */ jsxs18(
6071
+ Button14,
4327
6072
  {
4328
6073
  variant: "outline",
4329
6074
  size: "sm",
@@ -4335,8 +6080,8 @@ function ManagePanel({
4335
6080
  void handleRefresh();
4336
6081
  },
4337
6082
  children: [
4338
- refreshing ? /* @__PURE__ */ jsx14(Spinner7, { size: "sm" }) : /* @__PURE__ */ jsx14(Icon9, { name: "refresh", size: "sm", color: "muted" }),
4339
- /* @__PURE__ */ jsx14(ButtonText8, { children: refreshing ? "Refreshing\u2026" : "Refresh Balance" })
6083
+ refreshing ? /* @__PURE__ */ jsx19(Spinner7, { size: "sm" }) : /* @__PURE__ */ jsx19(Icon13, { name: "refresh", size: "sm", color: "muted" }),
6084
+ /* @__PURE__ */ jsx19(ButtonText13, { children: refreshing ? "Refreshing\u2026" : "Refresh Balance" })
4340
6085
  ]
4341
6086
  }
4342
6087
  )
@@ -4354,7 +6099,9 @@ function AiCreditsInner({
4354
6099
  adapterFactory,
4355
6100
  adapterOptions,
4356
6101
  onPaySuccess,
4357
- onPayError
6102
+ onPayError,
6103
+ showWalletControls = false,
6104
+ hasDisconnectOverride = false
4358
6105
  }) {
4359
6106
  const defaultAdapter = useAiCreditsAdapter({
4360
6107
  environment,
@@ -4371,18 +6118,26 @@ function AiCreditsInner({
4371
6118
  skipVaultPaymentValidation: adapterOptions?.skipVaultPaymentValidation,
4372
6119
  prepareSettlement: adapterOptions?.prepareSettlement
4373
6120
  });
4374
- const activeAdapter = useMemo6(
4375
- () => adapterFactory ? adapterFactory({ environment, backendUrl }) : defaultAdapter,
4376
- [adapterFactory, environment, backendUrl, defaultAdapter]
6121
+ const factoryAdapter = useMemo6(
6122
+ () => adapterFactory ? adapterFactory({ environment, backendUrl }) : null,
6123
+ [adapterFactory, environment, backendUrl]
4377
6124
  );
6125
+ const activeAdapter = factoryAdapter ?? defaultAdapter;
4378
6126
  const { state, actions } = activeAdapter;
6127
+ const onBuyersDiscoveredRef = React14.useRef(actions.discoverBuyers);
6128
+ onBuyersDiscoveredRef.current = actions.discoverBuyers;
6129
+ const onBuyersDiscovered = useCallback5((addresses) => {
6130
+ onBuyersDiscoveredRef.current(addresses);
6131
+ }, []);
4379
6132
  const history = useAiCreditsHistory({
4380
6133
  address: state.address,
4381
6134
  backendUrl,
6135
+ defaultBuyerFilter: state.buyerPubKey ?? "all",
4382
6136
  environment,
4383
- backendClient: adapterOptions?.backendClient
6137
+ backendClient: adapterOptions?.backendClient,
6138
+ onBuyersDiscovered
4384
6139
  });
4385
- const handlePay = useCallback4(
6140
+ const handlePay = useCallback5(
4386
6141
  async (quote) => {
4387
6142
  const toastId = createToast({
4388
6143
  message: "Submitting Celo transaction\u2026",
@@ -4406,47 +6161,117 @@ function AiCreditsInner({
4406
6161
  },
4407
6162
  [actions, state.error]
4408
6163
  );
6164
+ const [helpView, setHelpView] = useState17(null);
4409
6165
  const isPending = state.status === "payment_pending" || state.status === "payment_confirmed";
4410
- const handleTabChange = useCallback4(
6166
+ const handleTabChange = useCallback5(
4411
6167
  (tabId) => {
6168
+ if (tabId !== "setup") {
6169
+ setHelpView(null);
6170
+ }
4412
6171
  actions.setActiveTab(tabId);
4413
6172
  },
4414
6173
  [actions]
4415
6174
  );
4416
- const buyPanel = /* @__PURE__ */ jsx14(
4417
- BuyCreditsPanel,
4418
- {
4419
- state,
4420
- actions,
4421
- isPending,
4422
- onPay: (quote) => {
4423
- void handlePay(quote);
4424
- }
4425
- }
6175
+ const { disconnect, disconnectLabel, disconnectIcon } = useWallet2();
6176
+ const handleDisconnect = useCallback5(async () => {
6177
+ await disconnect();
6178
+ setHelpView(null);
6179
+ actions.setActiveTab("setup");
6180
+ }, [actions, disconnect]);
6181
+ const walletRequired = needsWalletConnection(state);
6182
+ const handleHelpViewOpen = useCallback5(
6183
+ (view) => {
6184
+ actions.setActiveTab("setup");
6185
+ setHelpView(view);
6186
+ },
6187
+ [actions]
4426
6188
  );
4427
- if (state.status === "disconnected" || state.status === "connecting") {
4428
- return /* @__PURE__ */ jsx14(YStack13, { gap: "$3", padding: "$3", width: "100%", children: /* @__PURE__ */ jsx14(DisconnectedPanel, { onConnect: actions.connect, connecting: state.status === "connecting" }) });
4429
- }
4430
- return /* @__PURE__ */ jsxs13(YStack13, { gap: "$3", padding: "$3", width: "100%", children: [
4431
- /* @__PURE__ */ jsx14(
6189
+ const handleHelpViewClose = useCallback5(() => {
6190
+ setHelpView(null);
6191
+ }, []);
6192
+ const setupPanel = helpView === "how-to-use" ? /* @__PURE__ */ jsx19(HowToUseView, { onBack: handleHelpViewClose }) : helpView === "faq" ? /* @__PURE__ */ jsx19(SetupFaqView, { onBack: handleHelpViewClose }) : /* @__PURE__ */ jsx19(SetupTabPanel, { state, actions, onConnect: actions.connect });
6193
+ return /* @__PURE__ */ jsxs18(YStack18, { gap: "$3", padding: "$3", width: "100%", children: [
6194
+ /* @__PURE__ */ jsxs18(
6195
+ XStack17,
6196
+ {
6197
+ justifyContent: "space-between",
6198
+ alignItems: "center",
6199
+ gap: "$2",
6200
+ paddingHorizontal: "$1",
6201
+ children: [
6202
+ /* @__PURE__ */ jsx19(Heading9, { level: 4, children: "GoodDollar" }),
6203
+ /* @__PURE__ */ jsxs18(XStack17, { gap: "$2", alignItems: "center", flexShrink: 1, minWidth: 0, children: [
6204
+ /* @__PURE__ */ jsx19(Badge3, { type: "info", children: /* @__PURE__ */ jsx19(BadgeText3, { children: getChainDisplayName(state.chainId ?? CELO_CHAIN_ID3) }) }),
6205
+ showWalletControls && state.address && /* @__PURE__ */ jsx19(
6206
+ WalletChip,
6207
+ {
6208
+ address: state.address,
6209
+ onDisconnect: hasDisconnectOverride ? handleDisconnect : void 0,
6210
+ disconnectLabel: hasDisconnectOverride ? disconnectLabel : void 0,
6211
+ disconnectIcon: hasDisconnectOverride ? disconnectIcon : void 0
6212
+ }
6213
+ )
6214
+ ] })
6215
+ ]
6216
+ }
6217
+ ),
6218
+ /* @__PURE__ */ jsx19(
6219
+ SetupGuidanceCard,
6220
+ {
6221
+ activeHelpView: helpView,
6222
+ onHowToUse: () => {
6223
+ handleHelpViewOpen("how-to-use");
6224
+ },
6225
+ onFaq: () => {
6226
+ handleHelpViewOpen("faq");
6227
+ },
6228
+ depositBonusPercent: state.depositBonusPercent,
6229
+ streamBonusPercent: state.streamBonusPercent,
6230
+ isGoodIdVerified: state.isGoodIdVerified
6231
+ }
6232
+ ),
6233
+ /* @__PURE__ */ jsx19(
4432
6234
  WidgetTabs,
4433
6235
  {
4434
6236
  tabs: [
6237
+ { id: "setup", label: "Setup" },
4435
6238
  { id: "buy", label: "Buy Credits" },
4436
6239
  { id: "manage", label: "Manage" },
4437
6240
  { id: "history", label: "History" }
4438
6241
  ],
4439
- activeTab: state.activeTab,
6242
+ activeTab: walletRequired ? "setup" : state.activeTab,
4440
6243
  onTabChange: handleTabChange,
4441
- chainId: state.chainId ?? CELO_CHAIN_ID3
6244
+ isTabDisabled: (tabId) => walletRequired && tabId !== "setup",
6245
+ withConnectionStatus: false
4442
6246
  }
4443
6247
  ),
4444
- state.activeTab === "manage" ? /* @__PURE__ */ jsx14(ManagePanel, { state, actions }) : state.activeTab === "history" ? /* @__PURE__ */ jsx14(HistoryTab, { state: history.state, actions: history.actions }) : buyPanel
6248
+ walletRequired || state.activeTab === "setup" ? setupPanel : state.activeTab === "manage" ? /* @__PURE__ */ jsx19(ManagePanel, { state, actions }) : state.activeTab === "history" ? /* @__PURE__ */ jsx19(
6249
+ HistoryTab,
6250
+ {
6251
+ state: history.state,
6252
+ actions: history.actions,
6253
+ knownBuyers: state.buyers.map((address) => ({ address }))
6254
+ }
6255
+ ) : /* @__PURE__ */ jsx19(
6256
+ BuyCreditsPanel,
6257
+ {
6258
+ state,
6259
+ actions,
6260
+ isPending,
6261
+ onPay: (quote) => {
6262
+ void handlePay(quote);
6263
+ }
6264
+ }
6265
+ )
4445
6266
  ] });
4446
6267
  }
4447
6268
  function AiCreditsWidget({
4448
6269
  provider,
4449
6270
  connectOverride,
6271
+ showWalletControls = false,
6272
+ disconnectOverride,
6273
+ disconnectLabel,
6274
+ disconnectIcon,
4450
6275
  environment = "production",
4451
6276
  backendUrl,
4452
6277
  baseRpcUrl,
@@ -4463,16 +6288,19 @@ function AiCreditsWidget({
4463
6288
  adapterOptions,
4464
6289
  testId
4465
6290
  }) {
4466
- return /* @__PURE__ */ jsx14(
6291
+ return /* @__PURE__ */ jsx19(
4467
6292
  GoodWidgetProvider,
4468
6293
  {
4469
6294
  provider,
4470
6295
  connectOverride,
6296
+ disconnectOverride,
6297
+ disconnectLabel,
6298
+ disconnectIcon,
4471
6299
  config,
4472
6300
  themeOverrides,
4473
6301
  defaultTheme,
4474
- children: /* @__PURE__ */ jsxs13(YStack13, { backgroundColor: "$background", width: "100%", "data-testid": testId, children: [
4475
- /* @__PURE__ */ jsx14(
6302
+ children: /* @__PURE__ */ jsxs18(YStack18, { backgroundColor: "$background", width: "100%", "data-testid": testId, children: [
6303
+ /* @__PURE__ */ jsx19(
4476
6304
  AiCreditsInner,
4477
6305
  {
4478
6306
  environment,
@@ -4485,16 +6313,28 @@ function AiCreditsWidget({
4485
6313
  adapterFactory,
4486
6314
  adapterOptions,
4487
6315
  onPaySuccess,
4488
- onPayError
6316
+ onPayError,
6317
+ showWalletControls,
6318
+ hasDisconnectOverride: Boolean(disconnectOverride)
4489
6319
  }
4490
6320
  ),
4491
- /* @__PURE__ */ jsx14(ToastContainer, {})
6321
+ /* @__PURE__ */ jsx19(ToastContainer, {})
4492
6322
  ] })
4493
6323
  }
4494
6324
  );
4495
6325
  }
4496
6326
 
4497
6327
  export {
6328
+ DEEP_LINK_MANUAL_FALLBACK_HINT,
6329
+ isValidBuyerAddress,
6330
+ isValidOperatorSignature,
6331
+ deepLinkManualFallbackMessage,
6332
+ readStoredDeepLinkParams,
6333
+ storeDeepLinkParams,
6334
+ clearStoredDeepLinkParams,
6335
+ parseDeepLinkParams,
6336
+ resolveDeepLinkParams,
6337
+ clearDeepLinkArtifacts,
4498
6338
  usdToCredits,
4499
6339
  buildQuoteAmounts,
4500
6340
  totalCreditUsdFromProfile,
@@ -4515,4 +6355,4 @@ export {
4515
6355
  useAiCreditsAdapter,
4516
6356
  AiCreditsWidget
4517
6357
  };
4518
- //# sourceMappingURL=chunk-5ABKU4SW.js.map
6358
+ //# sourceMappingURL=chunk-V7CAVLPS.js.map