@goodwidget/ai-credits-widget 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/element.cjs CHANGED
@@ -36,9 +36,9 @@ module.exports = __toCommonJS(element_exports);
36
36
  var import_embed = require("@goodwidget/embed");
37
37
 
38
38
  // src/AiCreditsWidget.tsx
39
- var import_react14 = __toESM(require("react"), 1);
39
+ var import_react17 = __toESM(require("react"), 1);
40
40
  var import_core2 = require("@goodwidget/core");
41
- var import_ui16 = require("@goodwidget/ui");
41
+ var import_ui21 = require("@goodwidget/ui");
42
42
 
43
43
  // src/adapter.ts
44
44
  var import_react = require("react");
@@ -531,13 +531,17 @@ function clampHistoryLimit(limit) {
531
531
  if (limit === void 0) return DEFAULT_HISTORY_LIMIT;
532
532
  return Math.min(Math.max(1, Math.floor(limit)), MAX_HISTORY_LIMIT);
533
533
  }
534
- function resolveBuyerAddress(entries) {
534
+ function collectBuyerAddressesFromEntries(entries) {
535
+ const seen = /* @__PURE__ */ new Set();
536
+ const result = [];
535
537
  for (const entry of entries) {
536
- if (entry.buyerAddress && (0, import_viem4.isAddress)(entry.buyerAddress)) {
537
- return normalizeAddress2(entry.buyerAddress);
538
- }
538
+ if (!entry.buyerAddress || !(0, import_viem4.isAddress)(entry.buyerAddress)) continue;
539
+ const key = normalizeAddress2(entry.buyerAddress);
540
+ if (seen.has(key)) continue;
541
+ seen.add(key);
542
+ result.push(key);
539
543
  }
540
- return null;
544
+ return result;
541
545
  }
542
546
  function defaultOperatorStatus(payer) {
543
547
  const account = normalizeAddress2(payer);
@@ -772,13 +776,11 @@ async function waitForOperatorConsent(chain, ref) {
772
776
  }
773
777
  async function buildAccountView(payer, backend, chain, options = {}) {
774
778
  const normalizedPayer = normalizeAddress2(payer);
775
- const [credit, outstanding, history] = await Promise.all([
779
+ const [credit, outstanding] = await Promise.all([
776
780
  backend.getAccountCredit(payer),
777
- backend.getOutstanding(payer),
778
- backend.getCreditHistory(payer, { limit: MAX_HISTORY_LIMIT, offset: 0 })
781
+ backend.getOutstanding(payer)
779
782
  ]);
780
- const sessionBuyer = options.buyerAddress && (0, import_viem4.isAddress)(options.buyerAddress) ? normalizeAddress2(options.buyerAddress) : null;
781
- const buyer = sessionBuyer ?? resolveBuyerAddress(history.items);
783
+ const buyer = options.buyerAddress && (0, import_viem4.isAddress)(options.buyerAddress) ? normalizeAddress2(options.buyerAddress) : null;
782
784
  const [operator, withdrawableUsd] = buyer ? await Promise.all([
783
785
  chain.getBuyerOperatorStatus({ payer: normalizedPayer, buyer }),
784
786
  chain.getWithdrawableUsd(buyer)
@@ -794,41 +796,376 @@ async function buildAccountView(payer, backend, chain, options = {}) {
794
796
  };
795
797
  }
796
798
 
799
+ // src/deepLinkParams.ts
800
+ var BUYER_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
801
+ var OPERATOR_SIGNATURE_RE = /^0x[0-9a-fA-F]{128}([0-9a-fA-F]{2})?$/;
802
+ var DEEP_LINK_STORAGE_KEY = "goodwidget.ai-credits.deepLink";
803
+ var DEEP_LINK_MANUAL_FALLBACK_HINT = "Generate or import a signer key manually to continue.";
804
+ function isValidBuyerAddress(value) {
805
+ return BUYER_ADDRESS_RE.test(value.trim());
806
+ }
807
+ function isValidOperatorSignature(value) {
808
+ return OPERATOR_SIGNATURE_RE.test(value.trim());
809
+ }
810
+ function deepLinkManualFallbackMessage(reason) {
811
+ return `${reason} ${DEEP_LINK_MANUAL_FALLBACK_HINT}`;
812
+ }
813
+ function canUseLocalStorage() {
814
+ return typeof window !== "undefined" && typeof window.localStorage !== "undefined";
815
+ }
816
+ function readStoredDeepLinkParams() {
817
+ if (!canUseLocalStorage()) return null;
818
+ try {
819
+ const raw = window.localStorage.getItem(DEEP_LINK_STORAGE_KEY);
820
+ if (!raw) return null;
821
+ const parsed = JSON.parse(raw);
822
+ const buyerAddress = typeof parsed.buyerAddress === "string" ? parsed.buyerAddress.trim() : "";
823
+ const operatorSignature = typeof parsed.operatorSignature === "string" ? parsed.operatorSignature.trim() : "";
824
+ if (!isValidBuyerAddress(buyerAddress) || !isValidOperatorSignature(operatorSignature)) {
825
+ clearStoredDeepLinkParams();
826
+ return null;
827
+ }
828
+ return { buyerAddress, operatorSignature };
829
+ } catch {
830
+ clearStoredDeepLinkParams();
831
+ return null;
832
+ }
833
+ }
834
+ function storeDeepLinkParams(value) {
835
+ if (!canUseLocalStorage()) return;
836
+ try {
837
+ window.localStorage.setItem(
838
+ DEEP_LINK_STORAGE_KEY,
839
+ JSON.stringify({
840
+ buyerAddress: value.buyerAddress.trim(),
841
+ operatorSignature: value.operatorSignature.trim()
842
+ })
843
+ );
844
+ } catch {
845
+ return;
846
+ }
847
+ }
848
+ function clearStoredDeepLinkParams() {
849
+ if (!canUseLocalStorage()) return;
850
+ try {
851
+ window.localStorage.removeItem(DEEP_LINK_STORAGE_KEY);
852
+ } catch {
853
+ return;
854
+ }
855
+ }
856
+ function parseDeepLinkParams(search = typeof window !== "undefined" ? window.location.search : "") {
857
+ const params = typeof search === "string" ? new URLSearchParams(search) : search;
858
+ const buyerAddress = params.get("buyerAddress")?.trim() ?? "";
859
+ const operatorSignature = params.get("operatorSignature")?.trim() ?? "";
860
+ const hasBuyer = buyerAddress.length > 0;
861
+ const hasSignature = operatorSignature.length > 0;
862
+ if (!hasBuyer && !hasSignature) return { status: "absent" };
863
+ if (hasBuyer && !hasSignature) return { status: "partial", present: "buyerAddress" };
864
+ if (!hasBuyer && hasSignature) return { status: "partial", present: "operatorSignature" };
865
+ if (!isValidBuyerAddress(buyerAddress)) {
866
+ return { status: "invalid", reason: "Deep-link buyerAddress is invalid" };
867
+ }
868
+ if (!isValidOperatorSignature(operatorSignature)) {
869
+ return {
870
+ status: "invalid",
871
+ reason: "Deep-link operatorSignature is invalid"
872
+ };
873
+ }
874
+ return {
875
+ status: "complete",
876
+ source: "url",
877
+ value: {
878
+ buyerAddress,
879
+ operatorSignature
880
+ }
881
+ };
882
+ }
883
+ function resolveDeepLinkParams(search = typeof window !== "undefined" ? window.location.search : "") {
884
+ const fromUrl = parseDeepLinkParams(search);
885
+ if (fromUrl.status === "complete") {
886
+ storeDeepLinkParams(fromUrl.value);
887
+ return fromUrl;
888
+ }
889
+ if (fromUrl.status === "partial" || fromUrl.status === "invalid") {
890
+ return fromUrl;
891
+ }
892
+ const stored = readStoredDeepLinkParams();
893
+ if (!stored) return { status: "absent" };
894
+ return { status: "complete", source: "storage", value: stored };
895
+ }
896
+ function stripDeepLinkParamsFromUrl() {
897
+ if (typeof window === "undefined") return;
898
+ const url = new URL(window.location.href);
899
+ if (!url.searchParams.has("buyerAddress") && !url.searchParams.has("operatorSignature")) {
900
+ return;
901
+ }
902
+ url.searchParams.delete("buyerAddress");
903
+ url.searchParams.delete("operatorSignature");
904
+ const next = `${url.pathname}${url.search}${url.hash}`;
905
+ window.history.replaceState(window.history.state, "", next);
906
+ }
907
+ function clearDeepLinkArtifacts() {
908
+ clearStoredDeepLinkParams();
909
+ stripDeepLinkParamsFromUrl();
910
+ }
911
+
797
912
  // src/payerSession.ts
798
- var payerWalletSessions = /* @__PURE__ */ new Map();
913
+ var STORAGE_KEY_PREFIX = "goodwidget.ai-credits.payerSession.";
799
914
  function payerSessionKey(address) {
800
915
  return address.toLowerCase();
801
916
  }
917
+ function normalizeBuyerAddress(address) {
918
+ return address.toLowerCase();
919
+ }
920
+ function canUseLocalStorage2() {
921
+ return typeof window !== "undefined" && typeof window.localStorage !== "undefined";
922
+ }
923
+ function formatBuyerAddress(address) {
924
+ const key = normalizeBuyerAddress(address);
925
+ return key.startsWith("0x") ? `0x${key.slice(2)}` : key;
926
+ }
927
+ function emptySession() {
928
+ return {
929
+ buyerKeys: {},
930
+ knownBuyers: [],
931
+ activeBuyerAddress: null,
932
+ derivedBuyerAddress: null
933
+ };
934
+ }
935
+ function isBuyerKeyEntry(value) {
936
+ if (!value || typeof value !== "object") return false;
937
+ const entry = value;
938
+ 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");
939
+ }
940
+ function migrateLegacySession(raw) {
941
+ const session = emptySession();
942
+ const known = /* @__PURE__ */ new Set();
943
+ const trackKnown = (address) => {
944
+ if (!address) return;
945
+ known.add(normalizeBuyerAddress(address));
946
+ };
947
+ if (typeof raw.buyerPubKey === "string" && raw.buyerPubKey) {
948
+ const address = normalizeBuyerAddress(raw.buyerPubKey);
949
+ session.activeBuyerAddress = address;
950
+ session.derivedBuyerAddress = address;
951
+ trackKnown(address);
952
+ if (typeof raw.buyerPrvKey === "string" && raw.buyerPrvKey) {
953
+ session.buyerKeys[address] = { privateKey: raw.buyerPrvKey };
954
+ }
955
+ }
956
+ if (Array.isArray(raw.buyers)) {
957
+ for (const item of raw.buyers) {
958
+ if (typeof item === "string" && item) {
959
+ trackKnown(item);
960
+ continue;
961
+ }
962
+ if (!item || typeof item !== "object") continue;
963
+ const buyer = item;
964
+ if (typeof buyer.address !== "string" || !buyer.address) continue;
965
+ const address = normalizeBuyerAddress(buyer.address);
966
+ trackKnown(address);
967
+ const entry = {};
968
+ if (typeof buyer.privateKey === "string" && buyer.privateKey) {
969
+ entry.privateKey = buyer.privateKey;
970
+ }
971
+ if (typeof buyer.operatorSignature === "string" && buyer.operatorSignature) {
972
+ entry.operatorSignature = buyer.operatorSignature;
973
+ }
974
+ if (typeof buyer.operatorConsented === "boolean") {
975
+ entry.operatorConsented = buyer.operatorConsented;
976
+ }
977
+ if (entry.privateKey || entry.operatorSignature || entry.operatorConsented !== void 0) {
978
+ session.buyerKeys[address] = {
979
+ ...session.buyerKeys[address],
980
+ ...entry
981
+ };
982
+ }
983
+ if (buyer.type === "derived" && entry.privateKey) {
984
+ session.derivedBuyerAddress = address;
985
+ }
986
+ }
987
+ }
988
+ if (Array.isArray(raw.knownBuyers)) {
989
+ for (const item of raw.knownBuyers) {
990
+ if (typeof item === "string" && item) trackKnown(item);
991
+ }
992
+ }
993
+ if (typeof raw.activeBuyerAddress === "string" && raw.activeBuyerAddress) {
994
+ session.activeBuyerAddress = normalizeBuyerAddress(raw.activeBuyerAddress);
995
+ trackKnown(session.activeBuyerAddress);
996
+ }
997
+ if (typeof raw.derivedBuyerAddress === "string" && raw.derivedBuyerAddress) {
998
+ session.derivedBuyerAddress = normalizeBuyerAddress(raw.derivedBuyerAddress);
999
+ trackKnown(session.derivedBuyerAddress);
1000
+ }
1001
+ if (typeof raw.operatorSignature === "string" && raw.operatorSignature && session.activeBuyerAddress) {
1002
+ const active = session.activeBuyerAddress;
1003
+ session.buyerKeys[active] = {
1004
+ ...session.buyerKeys[active],
1005
+ operatorSignature: raw.operatorSignature
1006
+ };
1007
+ }
1008
+ if (raw.buyerKeys && typeof raw.buyerKeys === "object") {
1009
+ for (const [address, entry] of Object.entries(raw.buyerKeys)) {
1010
+ if (!isBuyerKeyEntry(entry)) continue;
1011
+ const key = normalizeBuyerAddress(address);
1012
+ trackKnown(key);
1013
+ session.buyerKeys[key] = {
1014
+ ...session.buyerKeys[key],
1015
+ ...entry
1016
+ };
1017
+ }
1018
+ }
1019
+ if (typeof raw.operatorConsented === "boolean" && raw.operatorConsented && session.activeBuyerAddress) {
1020
+ const active = session.activeBuyerAddress;
1021
+ session.buyerKeys[active] = {
1022
+ ...session.buyerKeys[active],
1023
+ operatorConsented: true
1024
+ };
1025
+ }
1026
+ session.knownBuyers = [...known].map((key) => formatBuyerAddress(key));
1027
+ return session;
1028
+ }
1029
+ function parseStoredSession(raw) {
1030
+ try {
1031
+ const parsed = JSON.parse(raw);
1032
+ return migrateLegacySession(parsed);
1033
+ } catch {
1034
+ return null;
1035
+ }
1036
+ }
1037
+ function persistSession(address, session) {
1038
+ if (!canUseLocalStorage2()) return;
1039
+ try {
1040
+ window.localStorage.setItem(
1041
+ `${STORAGE_KEY_PREFIX}${payerSessionKey(address)}`,
1042
+ JSON.stringify(session)
1043
+ );
1044
+ } catch {
1045
+ return;
1046
+ }
1047
+ }
802
1048
  function readPayerSession(address) {
803
- if (!address) return null;
804
- return payerWalletSessions.get(payerSessionKey(address)) ?? null;
1049
+ if (!address || !canUseLocalStorage2()) return null;
1050
+ try {
1051
+ const raw = window.localStorage.getItem(
1052
+ `${STORAGE_KEY_PREFIX}${payerSessionKey(address)}`
1053
+ );
1054
+ if (!raw) return null;
1055
+ return parseStoredSession(raw);
1056
+ } catch {
1057
+ return null;
1058
+ }
805
1059
  }
806
- function patchPayerSession(address, patch) {
807
- const existing = readPayerSession(address);
808
- payerWalletSessions.set(payerSessionKey(address), {
809
- operatorConsented: false,
1060
+ function getBuyerKeyEntry(payer, buyerAddress) {
1061
+ const session = readPayerSession(payer);
1062
+ if (!session) return null;
1063
+ return session.buyerKeys[normalizeBuyerAddress(buyerAddress)] ?? null;
1064
+ }
1065
+ function setBuyerOperatorConsented(payer, buyerAddress, operatorConsented) {
1066
+ upsertBuyerKey(payer, buyerAddress, { operatorConsented }, { setActive: false });
1067
+ }
1068
+ function upsertBuyerKey(payer, buyerAddress, entry, options) {
1069
+ const existing = readPayerSession(payer) ?? emptySession();
1070
+ const key = normalizeBuyerAddress(buyerAddress);
1071
+ const previous = existing.buyerKeys[key] ?? {};
1072
+ const knownBuyers = mergeBuyerAddressList(existing.knownBuyers, key);
1073
+ const next = {
810
1074
  ...existing,
811
- ...patch
812
- });
1075
+ knownBuyers,
1076
+ buyerKeys: {
1077
+ ...existing.buyerKeys,
1078
+ [key]: {
1079
+ privateKey: entry.privateKey ?? previous.privateKey,
1080
+ operatorSignature: entry.operatorSignature ?? previous.operatorSignature,
1081
+ operatorConsented: entry.operatorConsented !== void 0 ? entry.operatorConsented : previous.operatorConsented
1082
+ }
1083
+ },
1084
+ activeBuyerAddress: options?.setActive === false ? existing.activeBuyerAddress : key,
1085
+ derivedBuyerAddress: options?.setDerived ? key : existing.derivedBuyerAddress
1086
+ };
1087
+ persistSession(payer, next);
1088
+ return next;
1089
+ }
1090
+ function setActiveBuyerAddress(payer, buyerAddress) {
1091
+ const existing = readPayerSession(payer) ?? emptySession();
1092
+ const normalized = buyerAddress ? normalizeBuyerAddress(buyerAddress) : null;
1093
+ const next = {
1094
+ ...existing,
1095
+ knownBuyers: normalized ? mergeBuyerAddressList(existing.knownBuyers, normalized) : existing.knownBuyers,
1096
+ activeBuyerAddress: normalized
1097
+ };
1098
+ persistSession(payer, next);
1099
+ return next;
1100
+ }
1101
+ function mergeBuyerAddressList(existingBuyers, ...extras) {
1102
+ const seen = /* @__PURE__ */ new Set();
1103
+ const result = [];
1104
+ for (const address of [...existingBuyers, ...extras]) {
1105
+ if (!address) continue;
1106
+ const key = normalizeBuyerAddress(address);
1107
+ if (seen.has(key)) continue;
1108
+ seen.add(key);
1109
+ result.push(formatBuyerAddress(key));
1110
+ }
1111
+ return result;
1112
+ }
1113
+ function listKnownBuyerAddresses(payer) {
1114
+ const session = readPayerSession(payer);
1115
+ if (!session) return [];
1116
+ return mergeBuyerAddressList(
1117
+ session.knownBuyers,
1118
+ ...Object.keys(session.buyerKeys),
1119
+ session.activeBuyerAddress,
1120
+ session.derivedBuyerAddress
1121
+ );
1122
+ }
1123
+ function rememberBuyerAddresses(payer, addresses) {
1124
+ const existing = readPayerSession(payer) ?? emptySession();
1125
+ const knownBuyers = mergeBuyerAddressList(existing.knownBuyers, ...addresses);
1126
+ if (knownBuyers.length === existing.knownBuyers.length && knownBuyers.every(
1127
+ (address, index) => address.toLowerCase() === existing.knownBuyers[index]?.toLowerCase()
1128
+ )) {
1129
+ return listKnownBuyerAddresses(payer);
1130
+ }
1131
+ persistSession(payer, { ...existing, knownBuyers });
1132
+ return listKnownBuyerAddresses(payer);
1133
+ }
1134
+ function buildBuyerStateFields(payer, buyers, selectedAddress) {
1135
+ const session = readPayerSession(payer);
1136
+ const entry = selectedAddress ? getBuyerKeyEntry(payer, selectedAddress) : null;
1137
+ return {
1138
+ buyers,
1139
+ buyerPubKey: selectedAddress,
1140
+ buyerPrvKey: entry?.privateKey ?? null,
1141
+ operatorSignature: entry?.operatorSignature ?? null,
1142
+ operatorConsented: Boolean(entry?.operatorConsented),
1143
+ derivedBuyerAddress: session?.derivedBuyerAddress ?? null
1144
+ };
813
1145
  }
814
1146
  function patchPayerSessionFields(address) {
815
1147
  const session = readPayerSession(address);
816
1148
  if (!session) {
817
1149
  return {
1150
+ buyerPubKey: null,
818
1151
  buyerPrvKey: null,
819
- operatorConsented: false
1152
+ operatorSignature: null,
1153
+ operatorConsented: false,
1154
+ activeBuyerAddress: null,
1155
+ derivedBuyerAddress: null
820
1156
  };
821
1157
  }
1158
+ const active = session.activeBuyerAddress;
1159
+ const entry = active ? session.buyerKeys[normalizeBuyerAddress(active)] : void 0;
822
1160
  return {
823
- buyerPubKey: session.buyerPubKey,
824
- buyerPrvKey: session.buyerPrvKey ?? null,
825
- operatorConsented: session.operatorConsented
1161
+ buyerPubKey: active,
1162
+ buyerPrvKey: entry?.privateKey ?? null,
1163
+ operatorSignature: entry?.operatorSignature ?? null,
1164
+ operatorConsented: Boolean(entry?.operatorConsented),
1165
+ activeBuyerAddress: active,
1166
+ derivedBuyerAddress: session.derivedBuyerAddress
826
1167
  };
827
1168
  }
828
- function addressesMatch(a, b) {
829
- if (!a || !b) return false;
830
- return payerSessionKey(a) === payerSessionKey(b);
831
- }
832
1169
 
833
1170
  // src/celoPayment.ts
834
1171
  var import_viem5 = require("viem");
@@ -1108,7 +1445,7 @@ function getPayDisabledMessage(params) {
1108
1445
  if (params.validation.streamBelowMin && params.minStreamUsd) {
1109
1446
  return `Monthly stream must be at least ${formatMinUsdDisplay(params.minStreamUsd)}.`;
1110
1447
  }
1111
- if (params.status !== "quote_ready") {
1448
+ if (params.status !== "quote_ready" && params.status !== "payment_failed") {
1112
1449
  return "Enter a deposit or change the monthly stream amount to continue.";
1113
1450
  }
1114
1451
  return "Adjust the amounts to continue.";
@@ -1244,8 +1581,11 @@ var INITIAL_STATE = {
1244
1581
  isGoodIdVerified: false,
1245
1582
  buyerPubKey: null,
1246
1583
  buyerPrvKey: null,
1584
+ operatorSignature: null,
1247
1585
  operatorConsented: false,
1586
+ operatorConsentPending: false,
1248
1587
  operatorAddress: null,
1588
+ currentOperator: null,
1249
1589
  minDepositUsd: null,
1250
1590
  minStreamUsd: null,
1251
1591
  totalGdDepositedG: null,
@@ -1254,7 +1594,9 @@ var INITIAL_STATE = {
1254
1594
  depositBonusPercent: DEFAULT_DISCOUNT_CONFIG.depositBonusPercent,
1255
1595
  streamBonusPercent: DEFAULT_DISCOUNT_CONFIG.streamBonusPercent,
1256
1596
  error: null,
1257
- activeTab: "buy"
1597
+ activeTab: "setup",
1598
+ buyers: [],
1599
+ derivedBuyerAddress: null
1258
1600
  };
1259
1601
  var WALLET_LOADING_STATE = {
1260
1602
  gBalance: null,
@@ -1266,17 +1608,59 @@ var WALLET_LOADING_STATE = {
1266
1608
  totalGdDepositedG: null,
1267
1609
  monthlyStreamG: null,
1268
1610
  withdrawableUsd: null,
1269
- operatorAddress: null
1611
+ operatorAddress: null,
1612
+ currentOperator: null
1270
1613
  };
1614
+ var BUYER_HISTORY_LOOKUP_LIMIT = 100;
1615
+ function resolveLocalBuyers(payer, preferredBuyer, ...extras) {
1616
+ const buyers = rememberBuyerAddresses(payer, [
1617
+ preferredBuyer,
1618
+ ...listKnownBuyerAddresses(payer),
1619
+ ...extras
1620
+ ]);
1621
+ return { buyers, selected: selectPreferredBuyer(buyers, preferredBuyer) };
1622
+ }
1623
+ async function discoverBuyersFromHistory(payer, backend, ...extras) {
1624
+ let historyBuyers = [];
1625
+ try {
1626
+ const history = await backend.getCreditHistory(payer, {
1627
+ limit: BUYER_HISTORY_LOOKUP_LIMIT,
1628
+ offset: 0
1629
+ });
1630
+ historyBuyers = collectBuyerAddressesFromEntries(history.items);
1631
+ } catch {
1632
+ historyBuyers = [];
1633
+ }
1634
+ return rememberBuyerAddresses(payer, [...historyBuyers, ...extras]);
1635
+ }
1636
+ function selectPreferredBuyer(buyers, preferredBuyer) {
1637
+ if (preferredBuyer && buyers.some((item) => item.toLowerCase() === preferredBuyer.toLowerCase())) {
1638
+ return preferredBuyer;
1639
+ }
1640
+ return buyers[0] ?? preferredBuyer ?? null;
1641
+ }
1271
1642
  function isNonBuyTab(tab) {
1272
- return tab === "manage" || tab === "history";
1643
+ return tab === "setup" || tab === "manage" || tab === "history";
1644
+ }
1645
+ function needsWalletConnection(state) {
1646
+ return !state.address || state.status === "disconnected" || state.status === "connecting";
1647
+ }
1648
+ function resolveDefaultActiveTab(payerAddress, totalCreditUsd) {
1649
+ if (hasCreditBalance(totalCreditUsd)) return "manage";
1650
+ if (payerAddress && listKnownBuyerAddresses(payerAddress).length > 0) return "buy";
1651
+ return "setup";
1273
1652
  }
1274
1653
  function resolveActiveTab(prev, overrides) {
1275
1654
  if (overrides.activeTab !== void 0) return overrides.activeTab;
1655
+ const payerAddress = overrides.address !== void 0 ? overrides.address : prev.address;
1656
+ const totalCreditUsd = overrides.totalCreditUsd !== void 0 ? overrides.totalCreditUsd : prev.totalCreditUsd;
1276
1657
  if (overrides.totalCreditUsd !== void 0 && overrides.totalCreditUsd !== null) {
1277
- return hasCreditBalance(overrides.totalCreditUsd) ? "manage" : "buy";
1658
+ return resolveDefaultActiveTab(payerAddress, overrides.totalCreditUsd);
1659
+ }
1660
+ if (overrides.address !== void 0 && overrides.address !== prev.address) {
1661
+ return resolveDefaultActiveTab(payerAddress, totalCreditUsd);
1278
1662
  }
1279
- return prev.activeTab ?? "buy";
1663
+ return prev.activeTab ?? resolveDefaultActiveTab(payerAddress, totalCreditUsd);
1280
1664
  }
1281
1665
  function hasCreditBalance(totalCreditUsd) {
1282
1666
  return totalCreditUsd !== null && BigInt(totalCreditUsd) > 0n;
@@ -1334,7 +1718,7 @@ function mergeStatePreservingNonBuyTab(prev, overrides) {
1334
1718
  }
1335
1719
  const activeTab = isNonBuyTab(nextTab) ? nextTab : prev.activeTab;
1336
1720
  const status = deriveStatus({
1337
- isConnected: true,
1721
+ isConnected: !needsWalletConnection(prev),
1338
1722
  chainId: overrides.chainId ?? prev.chainId,
1339
1723
  gBalance: overrides.gBalance ?? prev.gBalance,
1340
1724
  buyerPubKey: overrides.buyerPubKey ?? prev.buyerPubKey,
@@ -1358,31 +1742,15 @@ function viewToStatePatch(view, enriched, prev, options) {
1358
1742
  isGoodIdVerified: enriched.goodIdVerified,
1359
1743
  operatorConsented: operatorAccepted,
1360
1744
  operatorAddress: view.operator.operatorAddress ?? null,
1745
+ currentOperator: view.operator.currentOperator ?? null,
1361
1746
  withdrawableUsd: view.withdrawableUsd,
1362
1747
  totalGdDepositedG: enriched.totalGdDepositedG,
1363
- monthlyStreamG: enriched.monthlyStreamG,
1364
- ...view.buyer ? { buyerPubKey: view.buyer } : {}
1365
- };
1366
- }
1367
- function mergeSessionFields(prev, sessionPatch, accountPatch, accountSwitched) {
1368
- const buyerPubKey = sessionPatch.buyerPubKey ?? accountPatch.buyerPubKey ?? (accountSwitched ? null : prev.buyerPubKey);
1369
- const buyerPrvKey = sessionPatch.buyerPrvKey ?? (accountSwitched ? null : prev.buyerPrvKey);
1370
- const operatorConsented = accountSwitched ? sessionPatch.operatorConsented ?? accountPatch.operatorConsented ?? false : accountPatch.operatorConsented ?? sessionPatch.operatorConsented ?? prev.operatorConsented;
1371
- return {
1372
- buyerPubKey,
1373
- buyerPrvKey,
1374
- operatorConsented
1748
+ monthlyStreamG: enriched.monthlyStreamG
1375
1749
  };
1376
1750
  }
1377
- function syncOperatorConsentSession(address, operatorConsented) {
1378
- if (operatorConsented === void 0) return;
1379
- patchPayerSession(address, { operatorConsented });
1380
- }
1381
- function syncBuyerPubKeySession(address, buyerPubKey) {
1382
- if (!buyerPubKey) return;
1383
- const existing = readPayerSession(address);
1384
- if (existing?.buyerPubKey) return;
1385
- patchPayerSession(address, { buyerPubKey });
1751
+ function activateBuyerSelection(payer, buyers, selectedAddress) {
1752
+ setActiveBuyerAddress(payer, selectedAddress);
1753
+ return buildBuyerStateFields(payer, buyers, selectedAddress);
1386
1754
  }
1387
1755
  function useAiCreditsAdapter({
1388
1756
  environment = "production",
@@ -1406,6 +1774,9 @@ function useAiCreditsAdapter({
1406
1774
  const providerRef = (0, import_react.useRef)(null);
1407
1775
  providerRef.current = provider;
1408
1776
  const goodIdVerifyPendingRef = (0, import_react.useRef)(false);
1777
+ const pendingDeepLinkRef = (0, import_react.useRef)(null);
1778
+ const deepLinkParseDoneRef = (0, import_react.useRef)(false);
1779
+ const deepLinkApplyInFlightRef = (0, import_react.useRef)(false);
1409
1780
  const celoVault = vaultAddress ?? CELO_GD_ANTSEED_VAULT_FALLBACK;
1410
1781
  const backendClient = (0, import_react.useMemo)(
1411
1782
  () => backendClientOverride ?? createBackendClient(backendUrl),
@@ -1423,7 +1794,11 @@ function useAiCreditsAdapter({
1423
1794
  );
1424
1795
  (0, import_react.useEffect)(() => {
1425
1796
  if (!isConnected || !address) {
1426
- setState((prev) => prev.status === "connecting" ? prev : { ...INITIAL_STATE });
1797
+ setState((prev) => {
1798
+ if (prev.status === "connecting") return prev;
1799
+ if (!prev.address && prev.status === "disconnected" && prev.error === null) return prev;
1800
+ return { ...INITIAL_STATE };
1801
+ });
1427
1802
  return;
1428
1803
  }
1429
1804
  if (configurationError) {
@@ -1442,14 +1817,17 @@ function useAiCreditsAdapter({
1442
1817
  if (prev.status === "payment_pending" || prev.status === "payment_confirmed" || prev.status === "payment_failed") {
1443
1818
  return prev;
1444
1819
  }
1445
- const accountSwitched = !addressesMatch(prev.address, address);
1446
- const buyerFields = mergeSessionFields(prev, sessionPatch, {}, accountSwitched);
1447
1820
  return withDerivedStatus(
1448
1821
  prev,
1449
1822
  {
1450
1823
  address,
1451
1824
  chainId,
1452
- ...buyerFields,
1825
+ buyerPubKey: sessionPatch.buyerPubKey,
1826
+ buyerPrvKey: sessionPatch.buyerPrvKey,
1827
+ operatorSignature: sessionPatch.operatorSignature,
1828
+ operatorConsented: sessionPatch.operatorConsented,
1829
+ derivedBuyerAddress: sessionPatch.derivedBuyerAddress,
1830
+ buyers: prev.buyers,
1453
1831
  ...WALLET_LOADING_STATE,
1454
1832
  error: null,
1455
1833
  status: "connecting"
@@ -1472,8 +1850,11 @@ function useAiCreditsAdapter({
1472
1850
  functionName: "decimals"
1473
1851
  })
1474
1852
  ]);
1475
- const accountPromise = buildAccountView(address, backendClient, chainClient, {
1476
- buyerAddress: sessionPatch.buyerPubKey ?? null
1853
+ const pendingDeepLink = pendingDeepLinkRef.current;
1854
+ const sessionBuyer = patchPayerSessionFields(address).buyerPubKey;
1855
+ const preferredBuyer = pendingDeepLink?.buyerAddress ?? sessionBuyer ?? null;
1856
+ const accountPromise = pendingDeepLink || deepLinkApplyInFlightRef.current ? Promise.resolve(null) : buildAccountView(address, backendClient, chainClient, {
1857
+ buyerAddress: preferredBuyer
1477
1858
  }).then(async (view) => ({
1478
1859
  view,
1479
1860
  enriched: await enrichAccountView(view, chainClient)
@@ -1484,13 +1865,25 @@ function useAiCreditsAdapter({
1484
1865
  }) : fetchVaultPaymentMinimums(publicClient, celoVault, address).catch(() => null);
1485
1866
  const gdUsdPerTokenPromise = chainClient.fetchGdUsdPerToken().catch(() => null);
1486
1867
  const discountConfigPromise = backendClient.getDiscountConfig().catch(() => null);
1868
+ const buyersPromise = pendingDeepLink ? Promise.resolve(
1869
+ rememberBuyerAddresses(address, [
1870
+ preferredBuyer,
1871
+ ...listKnownBuyerAddresses(address)
1872
+ ])
1873
+ ) : discoverBuyersFromHistory(
1874
+ address,
1875
+ backendClient,
1876
+ preferredBuyer,
1877
+ ...listKnownBuyerAddresses(address)
1878
+ );
1487
1879
  try {
1488
- const [[rawBalance, decimals], account, minimums, gdUsdPerToken, discountConfig] = await Promise.all([
1880
+ const [[rawBalance, decimals], account, minimums, gdUsdPerToken, discountConfig, buyers] = await Promise.all([
1489
1881
  balancePromise,
1490
1882
  accountPromise,
1491
1883
  minimumsPromise,
1492
1884
  gdUsdPerTokenPromise,
1493
- discountConfigPromise
1885
+ discountConfigPromise,
1886
+ buyersPromise
1494
1887
  ]);
1495
1888
  if (cancelled) return;
1496
1889
  const patch = {
@@ -1503,41 +1896,54 @@ function useAiCreditsAdapter({
1503
1896
  depositBonusPercent: discountConfig?.depositBonusPercent ?? DEFAULT_DISCOUNT_CONFIG.depositBonusPercent,
1504
1897
  streamBonusPercent: discountConfig?.streamBonusPercent ?? DEFAULT_DISCOUNT_CONFIG.streamBonusPercent
1505
1898
  };
1506
- setState((prev) => {
1507
- const accountSwitched = !addressesMatch(prev.address, address);
1508
- const accountPatch = account ? viewToStatePatch(account.view, account.enriched, prev, {
1509
- balanceMode: "always"
1510
- }) : {};
1511
- const buyerFields = mergeSessionFields(prev, sessionPatch, accountPatch, accountSwitched);
1512
- if (address && accountPatch.operatorConsented !== void 0) {
1513
- syncOperatorConsentSession(address, accountPatch.operatorConsented);
1514
- }
1515
- if (address && account?.view.buyer) {
1516
- syncBuyerPubKeySession(address, account.view.buyer);
1517
- }
1518
- return withDerivedStatus(
1899
+ if (pendingDeepLink || deepLinkApplyInFlightRef.current) {
1900
+ setState(
1901
+ (prev) => withDerivedStatus(
1902
+ prev,
1903
+ {
1904
+ ...patch,
1905
+ buyers: mergeBuyerAddressList(prev.buyers, ...buyers)
1906
+ },
1907
+ true
1908
+ )
1909
+ );
1910
+ return;
1911
+ }
1912
+ const selectedBuyer = selectPreferredBuyer(buyers, preferredBuyer);
1913
+ const accountPatch = account ? viewToStatePatch(account.view, account.enriched, INITIAL_STATE, {
1914
+ balanceMode: "always"
1915
+ }) : {};
1916
+ if (selectedBuyer && accountPatch.operatorConsented !== void 0) {
1917
+ setBuyerOperatorConsented(address, selectedBuyer, accountPatch.operatorConsented);
1918
+ }
1919
+ const buyerFields = activateBuyerSelection(address, buyers, selectedBuyer);
1920
+ setState(
1921
+ (prev) => withDerivedStatus(
1519
1922
  prev,
1520
1923
  {
1521
1924
  ...patch,
1522
1925
  ...accountPatch,
1523
1926
  ...buyerFields,
1524
- ...account ? {} : { activeTab: "buy" }
1927
+ operatorConsented: accountPatch.operatorConsented ?? buyerFields.operatorConsented
1525
1928
  },
1526
1929
  true
1527
- );
1528
- });
1930
+ )
1931
+ );
1529
1932
  } catch {
1530
1933
  if (cancelled) return;
1531
1934
  setState((prev) => {
1532
- const accountSwitched = !addressesMatch(prev.address, address);
1533
- const buyerFields = mergeSessionFields(prev, sessionPatch, {}, accountSwitched);
1534
1935
  return withDerivedStatus(
1535
1936
  prev,
1536
1937
  {
1537
1938
  address,
1538
1939
  chainId,
1539
1940
  gBalance: "0",
1540
- ...buyerFields,
1941
+ buyers: [],
1942
+ derivedBuyerAddress: null,
1943
+ buyerPubKey: null,
1944
+ buyerPrvKey: null,
1945
+ operatorSignature: null,
1946
+ operatorConsented: false,
1541
1947
  status: chainId !== null && chainId !== CELO_CHAIN_ID2 ? "unsupported_chain" : "purchase_setup"
1542
1948
  },
1543
1949
  true
@@ -1576,14 +1982,32 @@ function useAiCreditsAdapter({
1576
1982
  setState(
1577
1983
  (prev) => withDerivedStatus(
1578
1984
  prev,
1579
- { error: "Connect your wallet before generating a buyer key" },
1985
+ { error: "Connect your wallet before generating a signer key" },
1580
1986
  true
1581
1987
  )
1582
1988
  );
1583
1989
  return;
1584
1990
  }
1991
+ const payerAddress = address;
1992
+ const session = readPayerSession(payerAddress);
1993
+ const derivedAddress = session?.derivedBuyerAddress ?? null;
1994
+ const existingKey = derivedAddress ? getBuyerKeyEntry(payerAddress, derivedAddress) : null;
1995
+ if (derivedAddress && existingKey?.privateKey) {
1996
+ const buyers = mergeBuyerAddressList(
1997
+ listKnownBuyerAddresses(payerAddress),
1998
+ derivedAddress
1999
+ );
2000
+ const buyerFields = activateBuyerSelection(payerAddress, buyers, derivedAddress);
2001
+ setState(
2002
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2003
+ ...buyerFields,
2004
+ error: null,
2005
+ ...!isNonBuyTab(prev.activeTab) ? { status: "purchase_setup" } : {}
2006
+ })
2007
+ );
2008
+ return;
2009
+ }
1585
2010
  try {
1586
- const payerAddress = address;
1587
2011
  const message = buildBuyerKeyMessage(payerAddress);
1588
2012
  const walletClient = (0, import_viem8.createWalletClient)({
1589
2013
  account: payerAddress,
@@ -1595,15 +2019,21 @@ function useAiCreditsAdapter({
1595
2019
  message
1596
2020
  });
1597
2021
  const privateKey = deriveBuyerPrivateKeyFromSignature(signature);
1598
- const account = (0, import_accounts4.privateKeyToAccount)(privateKey);
1599
- patchPayerSession(payerAddress, {
1600
- buyerPubKey: account.address,
1601
- buyerPrvKey: privateKey
1602
- });
2022
+ const buyerAccount = (0, import_accounts4.privateKeyToAccount)(privateKey);
2023
+ upsertBuyerKey(
2024
+ payerAddress,
2025
+ buyerAccount.address,
2026
+ { privateKey },
2027
+ { setActive: true, setDerived: true }
2028
+ );
2029
+ const buyers = mergeBuyerAddressList(
2030
+ listKnownBuyerAddresses(payerAddress),
2031
+ buyerAccount.address
2032
+ );
2033
+ const buyerFields = buildBuyerStateFields(payerAddress, buyers, buyerAccount.address);
1603
2034
  setState(
1604
2035
  (prev) => mergeStatePreservingNonBuyTab(prev, {
1605
- buyerPubKey: account.address,
1606
- buyerPrvKey: privateKey,
2036
+ ...buyerFields,
1607
2037
  error: null,
1608
2038
  ...!isNonBuyTab(prev.activeTab) ? { status: "purchase_setup" } : {}
1609
2039
  })
@@ -1620,64 +2050,332 @@ function useAiCreditsAdapter({
1620
2050
  );
1621
2051
  }
1622
2052
  }, [address]);
1623
- const handleSignOperatorConsent = (0, import_react.useCallback)(async () => {
1624
- const currentState = state;
1625
- if (!currentState.address || !currentState.buyerPubKey || !currentState.buyerPrvKey) {
2053
+ const handleSelectBuyer = (0, import_react.useCallback)(
2054
+ async (buyerAddress) => {
2055
+ if (!address) return;
2056
+ const known = listKnownBuyerAddresses(address);
2057
+ if (!known.some((item) => item.toLowerCase() === buyerAddress.toLowerCase())) {
2058
+ return;
2059
+ }
2060
+ const buyers = mergeBuyerAddressList(known, buyerAddress);
2061
+ const buyerFields = activateBuyerSelection(address, buyers, buyerAddress);
1626
2062
  setState(
1627
- (prev) => withDerivedStatus(
1628
- prev,
1629
- { error: "Generate a buyer key before signing operator consent" },
1630
- true
1631
- )
2063
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2064
+ ...buyerFields,
2065
+ operatorAddress: null,
2066
+ currentOperator: null,
2067
+ totalCreditUsd: null,
2068
+ withdrawableUsd: null,
2069
+ totalGdDepositedG: null,
2070
+ monthlyStreamG: null,
2071
+ operatorConsentPending: false,
2072
+ error: null
2073
+ })
1632
2074
  );
1633
- return;
1634
- }
1635
- const ref = { payer: currentState.address, buyer: currentState.buyerPubKey };
1636
- const onNonBuyTab = isNonBuyTab(currentState.activeTab);
1637
- try {
1638
- const operatorStatus = await chainClient.getBuyerOperatorStatus(ref);
1639
- if (!operatorStatus.enabled) {
1640
- throw new Error("Operator consent is not available");
2075
+ try {
2076
+ const view = await buildAccountView(address, backendClient, chainClient, {
2077
+ buyerAddress
2078
+ });
2079
+ const enriched = await enrichAccountView(view, chainClient);
2080
+ const accountPatch = viewToStatePatch(view, enriched, INITIAL_STATE, {
2081
+ balanceMode: "always"
2082
+ });
2083
+ if (accountPatch.operatorConsented !== void 0) {
2084
+ setBuyerOperatorConsented(address, buyerAddress, accountPatch.operatorConsented);
2085
+ }
2086
+ const nextBuyerFields = buildBuyerStateFields(address, buyers, buyerAddress);
2087
+ setState(
2088
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2089
+ ...accountPatch,
2090
+ ...nextBuyerFields,
2091
+ operatorConsented: accountPatch.operatorConsented ?? nextBuyerFields.operatorConsented,
2092
+ error: null
2093
+ })
2094
+ );
2095
+ } catch (err) {
2096
+ setState(
2097
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2098
+ error: err instanceof Error ? err.message : "Could not load buyer account"
2099
+ })
2100
+ );
1641
2101
  }
1642
- if (operatorStatus.operatorAccepted) {
1643
- patchPayerSession(currentState.address, { operatorConsented: true });
2102
+ },
2103
+ [address, backendClient, chainClient]
2104
+ );
2105
+ const handleDiscoverBuyers = (0, import_react.useCallback)(
2106
+ (addresses) => {
2107
+ if (!address || addresses.length === 0) return;
2108
+ const buyers = rememberBuyerAddresses(address, addresses);
2109
+ setState((prev) => {
2110
+ const sameLength = buyers.length === prev.buyers.length;
2111
+ const unchanged = sameLength && buyers.every(
2112
+ (item, index) => item.toLowerCase() === prev.buyers[index]?.toLowerCase()
2113
+ );
2114
+ if (unchanged) return prev;
2115
+ return { ...prev, buyers };
2116
+ });
2117
+ },
2118
+ [address]
2119
+ );
2120
+ const handleImportBuyerFromPrivateKey = (0, import_react.useCallback)(
2121
+ async (rawPrivateKey) => {
2122
+ if (!address) {
2123
+ setState(
2124
+ (prev) => withDerivedStatus(prev, { error: "Connect your wallet before importing a signer key" }, true)
2125
+ );
2126
+ return null;
2127
+ }
2128
+ const trimmed = rawPrivateKey.trim();
2129
+ const normalized = trimmed.startsWith("0x") ? trimmed : `0x${trimmed}`;
2130
+ if (!/^0x[0-9a-fA-F]{64}$/.test(normalized)) {
2131
+ setState(
2132
+ (prev) => withDerivedStatus(
2133
+ prev,
2134
+ { error: "Invalid private key format \u2014 expected 0x followed by 64 hex characters" },
2135
+ true
2136
+ )
2137
+ );
2138
+ return null;
2139
+ }
2140
+ try {
2141
+ const privateKey = normalized;
2142
+ const buyerAccount = (0, import_accounts4.privateKeyToAccount)(privateKey);
2143
+ upsertBuyerKey(address, buyerAccount.address, { privateKey }, { setActive: true });
2144
+ const buyers = mergeBuyerAddressList(
2145
+ listKnownBuyerAddresses(address),
2146
+ buyerAccount.address
2147
+ );
2148
+ const buyerFields = buildBuyerStateFields(address, buyers, buyerAccount.address);
1644
2149
  setState(
1645
2150
  (prev) => mergeStatePreservingNonBuyTab(prev, {
1646
- operatorConsented: true,
2151
+ ...buyerFields,
2152
+ operatorAddress: null,
2153
+ currentOperator: null,
2154
+ totalCreditUsd: null,
2155
+ withdrawableUsd: null,
2156
+ totalGdDepositedG: null,
2157
+ monthlyStreamG: null,
1647
2158
  error: null,
1648
- ...!onNonBuyTab ? { status: "purchase_setup" } : {}
2159
+ ...!isNonBuyTab(prev.activeTab) ? { status: "purchase_setup" } : {}
1649
2160
  })
1650
2161
  );
2162
+ try {
2163
+ const view = await buildAccountView(address, backendClient, chainClient, {
2164
+ buyerAddress: buyerAccount.address
2165
+ });
2166
+ const enriched = await enrichAccountView(view, chainClient);
2167
+ const accountPatch = viewToStatePatch(view, enriched, INITIAL_STATE, {
2168
+ balanceMode: "always"
2169
+ });
2170
+ if (accountPatch.operatorConsented !== void 0) {
2171
+ setBuyerOperatorConsented(
2172
+ address,
2173
+ buyerAccount.address,
2174
+ accountPatch.operatorConsented
2175
+ );
2176
+ }
2177
+ const nextBuyerFields = buildBuyerStateFields(
2178
+ address,
2179
+ buyers,
2180
+ buyerAccount.address
2181
+ );
2182
+ setState(
2183
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2184
+ ...accountPatch,
2185
+ ...nextBuyerFields,
2186
+ operatorConsented: accountPatch.operatorConsented ?? nextBuyerFields.operatorConsented,
2187
+ error: null
2188
+ })
2189
+ );
2190
+ } catch {
2191
+ return buyerAccount.address;
2192
+ }
2193
+ return buyerAccount.address;
2194
+ } catch {
2195
+ setState(
2196
+ (prev) => withDerivedStatus(prev, { error: "Could not derive an account from the provided private key" }, true)
2197
+ );
2198
+ return null;
2199
+ }
2200
+ },
2201
+ [address, backendClient, chainClient]
2202
+ );
2203
+ const resolveBuyerList = (0, import_react.useCallback)(
2204
+ (payer, preferredBuyer) => resolveLocalBuyers(payer, preferredBuyer),
2205
+ []
2206
+ );
2207
+ const handleApplyDeepLinkBuyer = (0, import_react.useCallback)(
2208
+ async (buyerAddress, operatorSignature) => {
2209
+ if (!address) {
1651
2210
  return;
1652
2211
  }
1653
- const payload = await chainClient.buildOperatorConsentPayload(ref, operatorStatus);
1654
- if (!payload.enabled || !payload.typedData) {
1655
- throw new Error("Operator consent is not available");
2212
+ const trimmedAddress = buyerAddress.trim();
2213
+ const trimmedSignature = operatorSignature.trim();
2214
+ if (!isValidBuyerAddress(trimmedAddress)) {
2215
+ setState(
2216
+ (prev) => withDerivedStatus(
2217
+ prev,
2218
+ {
2219
+ error: deepLinkManualFallbackMessage("Deep-link buyerAddress is invalid."),
2220
+ activeTab: "buy",
2221
+ status: "purchase_setup"
2222
+ },
2223
+ true
2224
+ )
2225
+ );
2226
+ return;
1656
2227
  }
1657
- const buyerSig = await signOperatorConsentFromTypedData(
1658
- currentState.buyerPrvKey,
1659
- payload.typedData
1660
- );
1661
- await backendClient.submitOperatorConsent(ref.buyer, {
1662
- nonce: operatorStatus.consentNonce,
1663
- signature: buyerSig
2228
+ if (!isValidOperatorSignature(trimmedSignature)) {
2229
+ setState(
2230
+ (prev) => withDerivedStatus(
2231
+ prev,
2232
+ {
2233
+ error: deepLinkManualFallbackMessage("Deep-link operatorSignature is invalid."),
2234
+ activeTab: "buy",
2235
+ status: "purchase_setup"
2236
+ },
2237
+ true
2238
+ )
2239
+ );
2240
+ return;
2241
+ }
2242
+ storeDeepLinkParams({
2243
+ buyerAddress: trimmedAddress,
2244
+ operatorSignature: trimmedSignature
1664
2245
  });
1665
- await waitForOperatorConsent(chainClient, ref);
1666
- patchPayerSession(currentState.address, { operatorConsented: true });
2246
+ upsertBuyerKey(
2247
+ address,
2248
+ trimmedAddress,
2249
+ { operatorSignature: trimmedSignature },
2250
+ { setActive: true }
2251
+ );
2252
+ const buyers = mergeBuyerAddressList(listKnownBuyerAddresses(address), trimmedAddress);
2253
+ const buyerFields = buildBuyerStateFields(address, buyers, trimmedAddress);
1667
2254
  setState(
1668
2255
  (prev) => mergeStatePreservingNonBuyTab(prev, {
2256
+ ...buyerFields,
2257
+ operatorAddress: null,
2258
+ currentOperator: null,
2259
+ totalCreditUsd: null,
2260
+ withdrawableUsd: null,
2261
+ totalGdDepositedG: null,
2262
+ monthlyStreamG: null,
2263
+ activeTab: "buy",
2264
+ operatorConsentPending: false,
2265
+ error: null
2266
+ })
2267
+ );
2268
+ },
2269
+ [address]
2270
+ );
2271
+ const handleSignOperatorConsent = (0, import_react.useCallback)(async () => {
2272
+ const currentState = state;
2273
+ if (!currentState.address || !currentState.buyerPubKey) {
2274
+ setState(
2275
+ (prev) => withDerivedStatus(
2276
+ prev,
2277
+ { error: "Select a buyer before authorizing your wallet" },
2278
+ true
2279
+ )
2280
+ );
2281
+ return;
2282
+ }
2283
+ const keyEntry = getBuyerKeyEntry(currentState.address, currentState.buyerPubKey);
2284
+ const storedOperatorSignature = currentState.operatorSignature ?? keyEntry?.operatorSignature ?? null;
2285
+ if (!currentState.buyerPrvKey && !storedOperatorSignature) {
2286
+ setState(
2287
+ (prev) => withDerivedStatus(
2288
+ prev,
2289
+ { error: "Generate a signer key before authorizing your wallet" },
2290
+ true
2291
+ )
2292
+ );
2293
+ return;
2294
+ }
2295
+ if (currentState.operatorConsentPending) return;
2296
+ const ref = { payer: currentState.address, buyer: currentState.buyerPubKey };
2297
+ const onNonBuyTab = isNonBuyTab(currentState.activeTab);
2298
+ setState((prev) => ({
2299
+ ...prev,
2300
+ operatorConsentPending: true,
2301
+ error: null
2302
+ }));
2303
+ try {
2304
+ const operatorStatus = await chainClient.getBuyerOperatorStatus(ref);
2305
+ if (!operatorStatus.enabled) {
2306
+ throw new Error("Operator consent is not available");
2307
+ }
2308
+ const hasDifferentOperator = operatorStatus.currentOperator !== "0x0000000000000000000000000000000000000000" && !operatorStatus.operatorAccepted;
2309
+ if (hasDifferentOperator) {
2310
+ throw new Error(
2311
+ "This signer key is already controlled by another operator. Import a different signer key or generate a new one."
2312
+ );
2313
+ }
2314
+ if (operatorStatus.operatorAccepted) {
2315
+ setBuyerOperatorConsented(currentState.address, currentState.buyerPubKey, true);
2316
+ const buyerList2 = resolveBuyerList(currentState.address, currentState.buyerPubKey);
2317
+ const buyerFields2 = buildBuyerStateFields(
2318
+ currentState.address,
2319
+ buyerList2.buyers,
2320
+ buyerList2.selected
2321
+ );
2322
+ setState(
2323
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2324
+ ...buyerFields2,
2325
+ operatorConsented: true,
2326
+ operatorConsentPending: false,
2327
+ error: null,
2328
+ ...!onNonBuyTab ? { status: "purchase_setup" } : {}
2329
+ })
2330
+ );
2331
+ clearDeepLinkArtifacts();
2332
+ return;
2333
+ }
2334
+ let buyerSig;
2335
+ if (currentState.buyerPrvKey) {
2336
+ const payload = await chainClient.buildOperatorConsentPayload(ref, operatorStatus);
2337
+ if (!payload.enabled || !payload.typedData) {
2338
+ throw new Error("Operator consent is not available");
2339
+ }
2340
+ buyerSig = await signOperatorConsentFromTypedData(
2341
+ currentState.buyerPrvKey,
2342
+ payload.typedData
2343
+ );
2344
+ } else if (storedOperatorSignature) {
2345
+ buyerSig = storedOperatorSignature;
2346
+ } else {
2347
+ throw new Error("Generate a signer key before authorizing your wallet");
2348
+ }
2349
+ await backendClient.submitOperatorConsent(ref.buyer, {
2350
+ nonce: operatorStatus.consentNonce,
2351
+ signature: buyerSig
2352
+ });
2353
+ await waitForOperatorConsent(chainClient, ref);
2354
+ setBuyerOperatorConsented(currentState.address, currentState.buyerPubKey, true);
2355
+ const buyerList = resolveBuyerList(currentState.address, currentState.buyerPubKey);
2356
+ const buyerFields = buildBuyerStateFields(
2357
+ currentState.address,
2358
+ buyerList.buyers,
2359
+ buyerList.selected
2360
+ );
2361
+ setState(
2362
+ (prev) => mergeStatePreservingNonBuyTab(prev, {
2363
+ ...buyerFields,
1669
2364
  operatorConsented: true,
2365
+ operatorConsentPending: false,
1670
2366
  error: null,
1671
2367
  ...!onNonBuyTab ? { status: "purchase_setup" } : {}
1672
2368
  })
1673
2369
  );
2370
+ clearDeepLinkArtifacts();
1674
2371
  } catch (err) {
1675
2372
  setState((prev) => ({
1676
2373
  ...prev,
2374
+ operatorConsentPending: false,
1677
2375
  error: err instanceof Error ? err.message : "Operator consent signature rejected"
1678
2376
  }));
1679
2377
  }
1680
- }, [state, backendClient, chainClient]);
2378
+ }, [state, backendClient, chainClient, resolveBuyerList]);
1681
2379
  const handleSyncOperatorConsentFromChain = (0, import_react.useCallback)(async () => {
1682
2380
  const currentState = state;
1683
2381
  if (!currentState.address || !currentState.buyerPubKey || currentState.operatorConsented) {
@@ -1687,7 +2385,7 @@ function useAiCreditsAdapter({
1687
2385
  const ref = { payer: currentState.address, buyer: currentState.buyerPubKey };
1688
2386
  const operatorStatus = await chainClient.getBuyerOperatorStatus(ref);
1689
2387
  if (!operatorStatus.operatorAccepted) return;
1690
- patchPayerSession(currentState.address, { operatorConsented: true });
2388
+ setBuyerOperatorConsented(currentState.address, currentState.buyerPubKey, true);
1691
2389
  const onNonBuyTab = isNonBuyTab(currentState.activeTab);
1692
2390
  setState(
1693
2391
  (prev) => mergeStatePreservingNonBuyTab(prev, {
@@ -1719,7 +2417,7 @@ function useAiCreditsAdapter({
1719
2417
  async (quote) => {
1720
2418
  const currentState = state;
1721
2419
  if (!currentState.address || !currentState.buyerPubKey || !providerRef.current) {
1722
- throw new Error("Connect your wallet and generate a buyer key before paying");
2420
+ throw new Error("Connect your wallet and generate a signer key before paying");
1723
2421
  }
1724
2422
  const hasDeposit = Number.parseFloat(quote.depositAmountG) > 0;
1725
2423
  const streamChanged = isStreamAmountChanged(quote.streamAmountG, currentState.monthlyStreamG);
@@ -1825,8 +2523,15 @@ function useAiCreditsAdapter({
1825
2523
  previousBalance: balanceBefore
1826
2524
  });
1827
2525
  const creditUsdMicro = (BigInt(totalCreditUsd) - BigInt(balanceBefore || "0")).toString();
2526
+ const buyerList = resolveBuyerList(currentState.address, currentState.buyerPubKey);
2527
+ const buyerFields = buildBuyerStateFields(
2528
+ currentState.address,
2529
+ buyerList.buyers,
2530
+ buyerList.selected
2531
+ );
1828
2532
  setState(
1829
2533
  (prev) => withDerivedStatus(prev, {
2534
+ ...buyerFields,
1830
2535
  totalCreditUsd,
1831
2536
  error: null,
1832
2537
  activeTab: "manage"
@@ -1861,6 +2566,7 @@ function useAiCreditsAdapter({
1861
2566
  celoVault,
1862
2567
  onPaySuccess,
1863
2568
  onPayError,
2569
+ resolveBuyerList,
1864
2570
  prepareSettlement,
1865
2571
  skipVaultPaymentValidation
1866
2572
  ]
@@ -1870,36 +2576,38 @@ function useAiCreditsAdapter({
1870
2576
  const currentState = state;
1871
2577
  if (!currentState.address) return;
1872
2578
  try {
1873
- const sessionBuyer = currentState.buyerPubKey ?? patchPayerSessionFields(currentState.address).buyerPubKey ?? null;
2579
+ const preferredBuyer = currentState.buyerPubKey;
2580
+ const buyerList = resolveBuyerList(currentState.address, preferredBuyer);
1874
2581
  const [view, discountConfig] = await Promise.all([
1875
2582
  buildAccountView(currentState.address, backendClient, chainClient, {
1876
- buyerAddress: sessionBuyer
2583
+ buyerAddress: preferredBuyer
1877
2584
  }),
1878
2585
  backendClient.getDiscountConfig().catch(() => null)
1879
2586
  ]);
1880
2587
  const enriched = await enrichAccountView(view, chainClient);
1881
- setState((prev) => {
1882
- const accountPatch = viewToStatePatch(view, enriched, prev, {
1883
- balanceMode: "always"
1884
- });
1885
- const sessionFields = mergeSessionFields(
1886
- prev,
1887
- patchPayerSessionFields(currentState.address),
1888
- accountPatch,
1889
- false
2588
+ const accountPatch = viewToStatePatch(view, enriched, INITIAL_STATE, {
2589
+ balanceMode: "always"
2590
+ });
2591
+ if (preferredBuyer && accountPatch.operatorConsented !== void 0 && currentState.address) {
2592
+ setBuyerOperatorConsented(
2593
+ currentState.address,
2594
+ preferredBuyer,
2595
+ accountPatch.operatorConsented
1890
2596
  );
1891
- if (accountPatch.operatorConsented !== void 0 && currentState.address) {
1892
- syncOperatorConsentSession(currentState.address, accountPatch.operatorConsented);
1893
- }
1894
- if (currentState.address && view.buyer) {
1895
- syncBuyerPubKeySession(currentState.address, view.buyer);
1896
- }
2597
+ }
2598
+ const buyerFields = buildBuyerStateFields(
2599
+ currentState.address,
2600
+ buyerList.buyers,
2601
+ buyerList.selected
2602
+ );
2603
+ setState((prev) => {
1897
2604
  const statusSeed = options?.afterGoodIdVerify && prev.status === "payment_failed" ? "quote_ready" : prev.status === "backend_unavailable" ? "purchase_setup" : prev.status;
1898
2605
  return withDerivedStatus(
1899
2606
  { ...prev, status: statusSeed },
1900
2607
  {
1901
2608
  ...accountPatch,
1902
- ...sessionFields,
2609
+ ...buyerFields,
2610
+ operatorConsented: accountPatch.operatorConsented ?? buyerFields.operatorConsented,
1903
2611
  activeTab: prev.activeTab,
1904
2612
  error: null,
1905
2613
  depositBonusPercent: discountConfig?.depositBonusPercent ?? prev.depositBonusPercent,
@@ -1917,7 +2625,7 @@ function useAiCreditsAdapter({
1917
2625
  );
1918
2626
  }
1919
2627
  },
1920
- [state, backendClient, chainClient]
2628
+ [state, backendClient, chainClient, resolveBuyerList]
1921
2629
  );
1922
2630
  const handleVerifyGoodId = (0, import_react.useCallback)(async () => {
1923
2631
  const currentState = state;
@@ -1988,7 +2696,7 @@ function useAiCreditsAdapter({
1988
2696
  if (!currentState.buyerPrvKey) {
1989
2697
  setState((prev) => ({
1990
2698
  ...prev,
1991
- error: "Sign with your payer wallet in Buyer & Operator below to generate the buyer private key before closing a channel"
2699
+ error: "Sign with your payer wallet in Signer Key below to generate the buyer private key before closing a channel"
1992
2700
  }));
1993
2701
  return;
1994
2702
  }
@@ -2025,7 +2733,7 @@ function useAiCreditsAdapter({
2025
2733
  if (!currentState.buyerPrvKey) {
2026
2734
  setState((prev) => ({
2027
2735
  ...prev,
2028
- error: "Sign with your payer wallet in Buyer & Operator below to generate the buyer private key before withdrawing funds"
2736
+ error: "Sign with your payer wallet in Signer Key below to generate the buyer private key before withdrawing funds"
2029
2737
  }));
2030
2738
  return;
2031
2739
  }
@@ -2091,22 +2799,76 @@ function useAiCreditsAdapter({
2091
2799
  await handleRefresh();
2092
2800
  }, [configurationError, handleRefresh]);
2093
2801
  const handleSetActiveTab = (0, import_react.useCallback)((tab) => {
2094
- if (tab === "buy") {
2802
+ setState((prev) => {
2803
+ if (needsWalletConnection(prev)) {
2804
+ if (tab === "setup") {
2805
+ return mergeStatePreservingNonBuyTab(prev, { activeTab: "setup", error: null });
2806
+ }
2807
+ return prev;
2808
+ }
2809
+ if (tab === "buy") {
2810
+ return withDerivedStatus(prev, { activeTab: "buy", status: "purchase_setup", error: null }, true);
2811
+ }
2812
+ return mergeStatePreservingNonBuyTab(prev, { activeTab: tab, error: null });
2813
+ });
2814
+ }, []);
2815
+ const handleStartPurchase = (0, import_react.useCallback)(() => {
2816
+ handleSetActiveTab("buy");
2817
+ }, [handleSetActiveTab]);
2818
+ (0, import_react.useEffect)(() => {
2819
+ if (typeof window === "undefined" || deepLinkParseDoneRef.current) return;
2820
+ deepLinkParseDoneRef.current = true;
2821
+ const parsed = resolveDeepLinkParams(window.location.search);
2822
+ if (parsed.status === "absent") return;
2823
+ if (parsed.status === "partial") {
2824
+ const missing = parsed.present === "buyerAddress" ? "operatorSignature" : "buyerAddress";
2825
+ setState(
2826
+ (prev) => withDerivedStatus(
2827
+ prev,
2828
+ {
2829
+ error: deepLinkManualFallbackMessage(`Deep link is missing ${missing}.`),
2830
+ activeTab: "buy",
2831
+ status: "purchase_setup"
2832
+ },
2833
+ false
2834
+ )
2835
+ );
2836
+ return;
2837
+ }
2838
+ if (parsed.status === "invalid") {
2095
2839
  setState(
2096
- (prev) => withDerivedStatus(prev, { activeTab: "buy", status: "purchase_setup", error: null }, true)
2840
+ (prev) => withDerivedStatus(
2841
+ prev,
2842
+ {
2843
+ error: deepLinkManualFallbackMessage(`${parsed.reason}.`),
2844
+ activeTab: "buy",
2845
+ status: "purchase_setup"
2846
+ },
2847
+ false
2848
+ )
2097
2849
  );
2098
2850
  return;
2099
2851
  }
2100
- setState((prev) => mergeStatePreservingNonBuyTab(prev, { activeTab: tab, error: null }));
2852
+ pendingDeepLinkRef.current = parsed.value;
2101
2853
  }, []);
2102
- const handleStartPurchase = (0, import_react.useCallback)(() => {
2103
- handleSetActiveTab("buy");
2104
- }, [handleSetActiveTab]);
2854
+ (0, import_react.useEffect)(() => {
2855
+ const pending = pendingDeepLinkRef.current;
2856
+ if (!address || !pending || deepLinkApplyInFlightRef.current) return;
2857
+ deepLinkApplyInFlightRef.current = true;
2858
+ void handleApplyDeepLinkBuyer(pending.buyerAddress, pending.operatorSignature).finally(() => {
2859
+ deepLinkApplyInFlightRef.current = false;
2860
+ pendingDeepLinkRef.current = null;
2861
+ });
2862
+ }, [address, handleApplyDeepLinkBuyer]);
2105
2863
  const actions = (0, import_react.useMemo)(
2106
2864
  () => ({
2107
2865
  connect: handleConnect,
2108
2866
  switchChain: handleSwitchChain,
2109
2867
  generateBuyerKey: handleGenerateBuyerKey,
2868
+ selectBuyer: handleSelectBuyer,
2869
+ discoverBuyers: handleDiscoverBuyers,
2870
+ importBuyerFromPrivateKey: handleImportBuyerFromPrivateKey,
2871
+ applyDeepLinkBuyer: handleApplyDeepLinkBuyer,
2110
2872
  signOperatorConsent: handleSignOperatorConsent,
2111
2873
  syncOperatorConsentFromChain: handleSyncOperatorConsentFromChain,
2112
2874
  buildQuote: handleBuildQuote,
@@ -2123,6 +2885,10 @@ function useAiCreditsAdapter({
2123
2885
  handleConnect,
2124
2886
  handleSwitchChain,
2125
2887
  handleGenerateBuyerKey,
2888
+ handleSelectBuyer,
2889
+ handleDiscoverBuyers,
2890
+ handleImportBuyerFromPrivateKey,
2891
+ handleApplyDeepLinkBuyer,
2126
2892
  handleSignOperatorConsent,
2127
2893
  handleSyncOperatorConsentFromChain,
2128
2894
  handleBuildQuote,
@@ -2143,6 +2909,8 @@ function useAiCreditsAdapter({
2143
2909
  var import_react2 = require("react");
2144
2910
  var HISTORY_PAGE_SIZE = 10;
2145
2911
  var HISTORY_LOOKBACK_DAYS = 90;
2912
+ var BUYER_FILTER_FILL_MAX_PAGES = 8;
2913
+ var BUYER_FILTER_ALL = "all";
2146
2914
  var HISTORY_SOURCE_OPTIONS = [
2147
2915
  { id: "deposit", label: "Deposit", defaultChecked: true },
2148
2916
  { id: "streamUpdate", label: "Stream update", defaultChecked: true },
@@ -2178,11 +2946,23 @@ function toIsoEndOfDay(dateValue) {
2178
2946
  if (Number.isNaN(parsed)) return void 0;
2179
2947
  return new Date(parsed).toISOString();
2180
2948
  }
2949
+ function matchesBuyerFilter(entry, filter) {
2950
+ if (filter === BUYER_FILTER_ALL) return true;
2951
+ return entry.buyerAddress?.toLowerCase() === filter.toLowerCase();
2952
+ }
2181
2953
  function useAiCreditsHistory(options) {
2182
- const { address, backendUrl, environment = "production", backendClient } = options;
2954
+ const {
2955
+ address,
2956
+ backendUrl,
2957
+ defaultBuyerFilter = BUYER_FILTER_ALL,
2958
+ environment = "production",
2959
+ backendClient,
2960
+ onBuyersDiscovered
2961
+ } = options;
2183
2962
  const defaultRange = (0, import_react2.useMemo)(() => getLast90DaysRange(), []);
2184
2963
  const [selectedSources, setSelectedSources] = (0, import_react2.useState)(createDefaultSelectedSources);
2185
2964
  const [statusFilter, setStatusFilter] = (0, import_react2.useState)("all");
2965
+ const [buyerAddressFilter, setBuyerAddressFilter] = (0, import_react2.useState)(defaultBuyerFilter);
2186
2966
  const [fromDate, setFromDate] = (0, import_react2.useState)(defaultRange.from);
2187
2967
  const [toDate, setToDate] = (0, import_react2.useState)(defaultRange.to);
2188
2968
  const [entries, setEntries] = (0, import_react2.useState)([]);
@@ -2191,6 +2971,9 @@ function useAiCreditsHistory(options) {
2191
2971
  const [loading, setLoading] = (0, import_react2.useState)(false);
2192
2972
  const [loadingMore, setLoadingMore] = (0, import_react2.useState)(false);
2193
2973
  const [error, setError] = (0, import_react2.useState)(null);
2974
+ (0, import_react2.useEffect)(() => {
2975
+ setBuyerAddressFilter(defaultBuyerFilter);
2976
+ }, [defaultBuyerFilter]);
2194
2977
  const activeSources = (0, import_react2.useMemo)(
2195
2978
  () => HISTORY_SOURCE_OPTIONS.map((option) => option.id).filter((id) => selectedSources[id]),
2196
2979
  [selectedSources]
@@ -2198,12 +2981,12 @@ function useAiCreditsHistory(options) {
2198
2981
  const loadHistory = (0, import_react2.useCallback)(
2199
2982
  async (nextOffset, append) => {
2200
2983
  if (!address) {
2201
- setEntries([]);
2202
- setOffset(0);
2203
- setHasMore(false);
2204
- setError(null);
2205
- setLoading(false);
2206
- setLoadingMore(false);
2984
+ setEntries((prev) => prev.length === 0 ? prev : []);
2985
+ setOffset((prev) => prev === 0 ? prev : 0);
2986
+ setHasMore((prev) => prev ? false : prev);
2987
+ setError((prev) => prev === null ? prev : null);
2988
+ setLoading((prev) => prev ? false : prev);
2989
+ setLoadingMore((prev) => prev ? false : prev);
2207
2990
  return;
2208
2991
  }
2209
2992
  if (activeSources.length === 0) {
@@ -2221,19 +3004,38 @@ function useAiCreditsHistory(options) {
2221
3004
  const client = backendClient ?? createBackendClient(backendUrl);
2222
3005
  const apiSource = activeSources.length === 1 ? activeSources[0] : void 0;
2223
3006
  const fundingStatus = statusFilter === "all" ? void 0 : statusFilter;
3007
+ const filterByBuyer = buyerAddressFilter !== BUYER_FILTER_ALL;
2224
3008
  try {
2225
- const response = await client.getCreditHistory(address, {
2226
- limit: HISTORY_PAGE_SIZE,
2227
- offset: nextOffset,
2228
- source: apiSource,
2229
- fundingStatus,
2230
- from: toIsoStartOfDay(fromDate),
2231
- to: toIsoEndOfDay(toDate)
2232
- });
2233
- const pageItems = activeSources.length === 1 ? response.items : response.items.filter((entry) => selectedSources[entry.source]);
2234
- setEntries((prev) => append ? [...prev, ...pageItems] : pageItems);
2235
- setOffset(nextOffset);
2236
- setHasMore(response.hasMore);
3009
+ const collected = [];
3010
+ let cursor = nextOffset;
3011
+ let apiHasMore = true;
3012
+ let pages = 0;
3013
+ while (pages < BUYER_FILTER_FILL_MAX_PAGES && collected.length < HISTORY_PAGE_SIZE && apiHasMore) {
3014
+ const response = await client.getCreditHistory(address, {
3015
+ limit: HISTORY_PAGE_SIZE,
3016
+ offset: cursor,
3017
+ source: apiSource,
3018
+ fundingStatus,
3019
+ from: toIsoStartOfDay(fromDate),
3020
+ to: toIsoEndOfDay(toDate)
3021
+ });
3022
+ const sourceFiltered = activeSources.length === 1 ? response.items : response.items.filter((entry) => selectedSources[entry.source]);
3023
+ const discoveredBuyers = sourceFiltered.map((entry) => entry.buyerAddress).filter((value) => Boolean(value));
3024
+ if (discoveredBuyers.length > 0) {
3025
+ onBuyersDiscovered?.(discoveredBuyers);
3026
+ }
3027
+ const buyerFiltered = sourceFiltered.filter(
3028
+ (entry) => matchesBuyerFilter(entry, buyerAddressFilter)
3029
+ );
3030
+ collected.push(...buyerFiltered);
3031
+ apiHasMore = response.hasMore;
3032
+ cursor = response.offset + response.limit;
3033
+ pages += 1;
3034
+ if (!filterByBuyer) break;
3035
+ }
3036
+ setEntries((prev) => append ? [...prev, ...collected] : collected);
3037
+ setOffset(cursor);
3038
+ setHasMore(apiHasMore);
2237
3039
  } catch (err) {
2238
3040
  if (!append) setEntries([]);
2239
3041
  setHasMore(false);
@@ -2250,9 +3052,11 @@ function useAiCreditsHistory(options) {
2250
3052
  backendClient,
2251
3053
  activeSources,
2252
3054
  statusFilter,
3055
+ buyerAddressFilter,
2253
3056
  fromDate,
2254
3057
  toDate,
2255
- selectedSources
3058
+ selectedSources,
3059
+ onBuyersDiscovered
2256
3060
  ]
2257
3061
  );
2258
3062
  (0, import_react2.useEffect)(() => {
@@ -2270,12 +3074,13 @@ function useAiCreditsHistory(options) {
2270
3074
  await loadHistory(0, false);
2271
3075
  }, [loadHistory]);
2272
3076
  const loadMore = (0, import_react2.useCallback)(async () => {
2273
- await loadHistory(offset + HISTORY_PAGE_SIZE, true);
3077
+ await loadHistory(offset, true);
2274
3078
  }, [loadHistory, offset]);
2275
3079
  return {
2276
3080
  state: {
2277
3081
  selectedSources,
2278
3082
  statusFilter,
3083
+ buyerAddressFilter,
2279
3084
  fromDate,
2280
3085
  toDate,
2281
3086
  entries,
@@ -2289,6 +3094,7 @@ function useAiCreditsHistory(options) {
2289
3094
  actions: {
2290
3095
  setSourceChecked,
2291
3096
  setStatusFilter,
3097
+ setBuyerAddressFilter,
2292
3098
  setFromDate,
2293
3099
  setToDate,
2294
3100
  reload,
@@ -2387,8 +3193,8 @@ function BuyerKeyPanel({
2387
3193
  }
2388
3194
  const Shell = embedded ? import_ui4.YStack : import_ui4.Card;
2389
3195
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Shell, { gap: "$3", children: [
2390
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Heading, { level: 5, children: "Buyer Key" }),
2391
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Text, { children: "Sign a message with your payer wallet to derive a deterministic AntSeed buyer key. Save the private key \u2014 you will need it to authenticate from your developer tools." }),
3196
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Heading, { level: 5, children: "Signer Key" }),
3197
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Text, { children: "Sign a message with your payer wallet to derive a dedicated AntSeed signer key. Save the private key \u2014 you will need it to authenticate from your developer tools." }),
2392
3198
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_ui4.YStack, { gap: "$3", children: [
2393
3199
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2394
3200
  import_ui4.Button,
@@ -2424,6 +3230,7 @@ function BuyerKeyPanel({
2424
3230
  }
2425
3231
  ),
2426
3232
  buyerPrvKey && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3233
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AiCreditsStatusNotice, { borderColor: "$warning", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Text, { color: "$warning", fontSize: "$2", children: "Back up any existing AntSeed signer key before importing this one. Importing replaces the signer used by your AntSeed account." }) }),
2427
3234
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_ui4.XStack, { justifyContent: "space-between", alignItems: "center", children: [
2428
3235
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Text, { variant: "label", secondary: true, children: "Private Key \u2014 save this securely" }),
2429
3236
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -2468,7 +3275,8 @@ function BuyerKeyPanel({
2468
3275
  )
2469
3276
  ]
2470
3277
  }
2471
- )
3278
+ ),
3279
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Text, { fontSize: "$2", secondary: true, children: "In AntSeed, open Settings \u2192 Signer key and import this private key. The public address above is the signer identity used for AI credits." })
2472
3280
  ] }),
2473
3281
  buyerPrvKey && !buyerPubKeySaved && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.Button, { size: "sm", ...compactButtonProps, onPress: onConfirm, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui4.ButtonText, { children: "I've Saved My Private Key" }) }),
2474
3282
  buyerPubKeySaved && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_ui4.XStack, { gap: "$2", alignItems: "center", children: [
@@ -2481,22 +3289,23 @@ function BuyerKeyPanel({
2481
3289
  }
2482
3290
 
2483
3291
  // src/components/buy/OperatorConsentStep.tsx
2484
- var import_react5 = require("react");
2485
3292
  var import_ui5 = require("@goodwidget/ui");
2486
3293
  var import_jsx_runtime3 = require("react/jsx-runtime");
2487
3294
  function OperatorConsentStep({
2488
3295
  buyerPubKey,
2489
3296
  buyerPrvKey,
3297
+ operatorSignature = null,
2490
3298
  operatorConsented,
3299
+ operatorConsentPending = false,
2491
3300
  onSign,
2492
3301
  embedded = false
2493
3302
  }) {
2494
- const [isSigning, setIsSigning] = (0, import_react5.useState)(false);
2495
- const canSign = Boolean(buyerPubKey && buyerPrvKey);
3303
+ const canSign = Boolean(buyerPubKey && (buyerPrvKey || operatorSignature));
3304
+ const isBusy = operatorConsentPending;
2496
3305
  const Shell = embedded ? import_ui5.YStack : import_ui5.Card;
2497
3306
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Shell, { gap: "$3", ...!embedded ? { backgroundColor: "$backgroundHover" } : {}, children: [
2498
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Heading, { level: 5, children: "Authorize AntSeed Operator" }),
2499
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Text, { fontSize: "$2", lineHeight: "$3", children: "Your buyer key signs an EIP-712 SetOperator message. The backend submits it to AntseedDeposits so the funding vault can act as your operator. No gas is required from you." }),
3307
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Heading, { level: 5, children: "Authorize Wallet" }),
3308
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Text, { fontSize: "$2", lineHeight: "$3", children: "GoodDollar needs this one-time authorization to fund and manage your AI credits on Base after you pay with G$ on Celo. It lets the GoodDollar operator move funds in your separate AI credits account, but never gives access to your payer wallet or G$. Granting this permission means trusting GoodDollar with that scoped Base role; you can revoke it later through the account controls." }),
2500
3309
  buyerPubKey && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui5.Text, { fontSize: "$2", lineHeight: "$2", children: [
2501
3310
  "Buyer address:",
2502
3311
  " ",
@@ -2504,38 +3313,35 @@ function OperatorConsentStep({
2504
3313
  ] }),
2505
3314
  operatorConsented ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui5.XStack, { gap: "$2", alignItems: "center", children: [
2506
3315
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Icon, { name: "check", size: "sm", color: "success" }),
2507
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Text, { color: "$success", children: "Operator consent accepted \u2014 ready to pay" })
3316
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Text, { color: "$success", children: "Wallet authorized \u2014 ready to pay" })
2508
3317
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2509
3318
  import_ui5.Button,
2510
3319
  {
2511
3320
  size: "sm",
2512
3321
  ...compactButtonProps,
2513
3322
  onPress: () => {
2514
- setIsSigning(true);
2515
- void onSign().finally(() => {
2516
- setIsSigning(false);
2517
- });
3323
+ void onSign();
2518
3324
  },
2519
- disabled: !canSign || isSigning,
2520
- children: isSigning ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui5.XStack, { gap: "$2", alignItems: "center", children: [
2521
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.ButtonText, { children: "Signing\u2026" }),
3325
+ disabled: !canSign || isBusy,
3326
+ children: isBusy ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui5.XStack, { gap: "$2", alignItems: "center", children: [
3327
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.ButtonText, { children: "Submitting\u2026" }),
2522
3328
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.Spinner, { size: "sm" })
2523
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.ButtonText, { children: "Sign Operator Consent" })
3329
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui5.ButtonText, { children: "Authorize Wallet" })
2524
3330
  }
2525
3331
  )
2526
3332
  ] });
2527
3333
  }
2528
3334
 
2529
3335
  // src/components/buy/AmountPicker.tsx
2530
- var import_react7 = require("react");
3336
+ var import_react6 = require("react");
2531
3337
  var import_ui7 = require("@goodwidget/ui");
2532
3338
 
2533
3339
  // src/components/shared/tooltips.tsx
2534
- var import_react6 = require("react");
3340
+ var import_react5 = require("react");
2535
3341
  var import_ui6 = require("@goodwidget/ui");
2536
3342
  var import_jsx_runtime4 = require("react/jsx-runtime");
2537
3343
  function InfoTooltip({ message }) {
2538
- const [open, setOpen] = (0, import_react6.useState)(false);
3344
+ const [open, setOpen] = (0, import_react5.useState)(false);
2539
3345
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2540
3346
  import_ui6.XStack,
2541
3347
  {
@@ -2580,7 +3386,7 @@ function HoverTooltip({
2580
3386
  children,
2581
3387
  fullWidth = false
2582
3388
  }) {
2583
- const [open, setOpen] = (0, import_react6.useState)(false);
3389
+ const [open, setOpen] = (0, import_react5.useState)(false);
2584
3390
  if (!message) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children });
2585
3391
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2586
3392
  import_ui6.XStack,
@@ -2664,17 +3470,17 @@ function AmountPicker({
2664
3470
  onVerifyGoodId,
2665
3471
  embedded = false
2666
3472
  }) {
2667
- const streamSeed = (0, import_react7.useMemo)(() => resolveInitialStreamAmount(monthlyStreamG), [monthlyStreamG]);
2668
- const [depositAmount, setDepositAmount] = (0, import_react7.useState)(DEFAULT_DEPOSIT_AMOUNT);
2669
- const [streamAmount, setStreamAmount] = (0, import_react7.useState)(streamSeed);
2670
- const [quote, setQuote] = (0, import_react7.useState)(null);
2671
- const [quotePending, setQuotePending] = (0, import_react7.useState)(false);
2672
- const [isVerifyingGoodId, setIsVerifyingGoodId] = (0, import_react7.useState)(false);
3473
+ const streamSeed = (0, import_react6.useMemo)(() => resolveInitialStreamAmount(monthlyStreamG), [monthlyStreamG]);
3474
+ const [depositAmount, setDepositAmount] = (0, import_react6.useState)(DEFAULT_DEPOSIT_AMOUNT);
3475
+ const [streamAmount, setStreamAmount] = (0, import_react6.useState)(streamSeed);
3476
+ const [quote, setQuote] = (0, import_react6.useState)(null);
3477
+ const [quotePending, setQuotePending] = (0, import_react6.useState)(false);
3478
+ const [isVerifyingGoodId, setIsVerifyingGoodId] = (0, import_react6.useState)(false);
2673
3479
  const isStreamUpdateFlow = parseGAmount(streamSeed) > 0;
2674
- (0, import_react7.useEffect)(() => {
3480
+ (0, import_react6.useEffect)(() => {
2675
3481
  setStreamAmount(streamSeed);
2676
3482
  }, [streamSeed]);
2677
- (0, import_react7.useEffect)(() => {
3483
+ (0, import_react6.useEffect)(() => {
2678
3484
  let cancelled = false;
2679
3485
  setQuotePending(true);
2680
3486
  void buildQuote(depositAmount, streamAmount).then((nextQuote) => {
@@ -2692,7 +3498,7 @@ function AmountPicker({
2692
3498
  const streamG = parseGAmount(streamAmount);
2693
3499
  const depositBonusLabel = isGoodIdVerified ? `+${depositBonusPercent}% bonus` : `Verify for +${depositBonusPercent}%`;
2694
3500
  const streamBonusLabel = isGoodIdVerified ? `+${streamBonusPercent}% bonus` : `Verify for +${streamBonusPercent}%`;
2695
- const paymentValidation = (0, import_react7.useMemo)(
3501
+ const paymentValidation = (0, import_react6.useMemo)(
2696
3502
  () => getPaymentAmountValidation({
2697
3503
  depositAmount,
2698
3504
  streamAmount,
@@ -2706,7 +3512,8 @@ function AmountPicker({
2706
3512
  [depositAmount, streamAmount, monthlyStreamG, minDepositUsd, minStreamUsd, quote, gdUsdPerToken, gBalance]
2707
3513
  );
2708
3514
  const minsLoaded = minStreamUsd !== null;
2709
- const canPay = status === "quote_ready" && minsLoaded && paymentValidation.hasPaymentAction && paymentValidation.vaultMinimumsMet && !paymentValidation.overBalance && !quotePending && quote !== null;
3515
+ const canRetryAfterFailure = status === "quote_ready" || status === "payment_failed";
3516
+ const canPay = canRetryAfterFailure && minsLoaded && paymentValidation.hasPaymentAction && paymentValidation.vaultMinimumsMet && !paymentValidation.overBalance && !quotePending && quote !== null;
2710
3517
  const payDisabledMessage = getPayDisabledMessage({
2711
3518
  canPay,
2712
3519
  minsLoaded,
@@ -2849,126 +3656,20 @@ function AmountPicker({
2849
3656
  ] });
2850
3657
  }
2851
3658
 
2852
- // src/components/buy/BuyCreditsFaq.tsx
2853
- var import_react8 = require("react");
2854
- var import_ui8 = require("@goodwidget/ui");
2855
- var import_jsx_runtime6 = require("react/jsx-runtime");
2856
- var FAQ_ITEMS = [
2857
- {
2858
- id: "what-are-credits",
2859
- question: "What are AI credits?",
2860
- 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."
2861
- },
2862
- {
2863
- id: "how-to-buy",
2864
- question: "How do I buy credits?",
2865
- 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)."
2866
- },
2867
- {
2868
- id: "deposit-vs-stream",
2869
- question: "What is a one-time deposit vs a monthly stream?",
2870
- 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."
2871
- },
2872
- {
2873
- id: "minimums",
2874
- question: "What are the minimum amounts?",
2875
- 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."
2876
- },
2877
- {
2878
- id: "goodid-bonus",
2879
- question: "How do GoodID bonuses work?",
2880
- 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."
2881
- },
2882
- {
2883
- id: "buyer-key",
2884
- question: "What is the buyer key?",
2885
- 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."
2886
- },
2887
- {
2888
- id: "operator-consent",
2889
- question: "Why do I authorize the Gooddollar operator?",
2890
- 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."
2891
- },
2892
- {
2893
- id: "when-credits-arrive",
2894
- question: "When do credits arrive?",
2895
- 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."
2896
- },
2897
- {
2898
- id: "withdraw",
2899
- question: "What funds can I withdraw?",
2900
- 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."
2901
- },
2902
- {
2903
- id: "api-setup",
2904
- question: "What is API setup?",
2905
- 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."
2906
- },
2907
- {
2908
- id: "support",
2909
- question: "Who do I contact for support?",
2910
- 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"
2911
- }
2912
- ];
2913
- function FaqItem({
2914
- question,
2915
- answer,
2916
- expanded,
2917
- onToggle
2918
- }) {
2919
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.YStack, { gap: "$1", children: [
2920
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2921
- import_ui8.XStack,
2922
- {
2923
- justifyContent: "space-between",
2924
- alignItems: "center",
2925
- gap: "$2",
2926
- onPress: onToggle,
2927
- cursor: "pointer",
2928
- children: [
2929
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$2", fontWeight: "600", flex: 1, children: question }),
2930
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Icon, { name: expanded ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
2931
- ]
2932
- }
2933
- ),
2934
- expanded && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.YStack, { gap: "$2", children: answer.split("\n\n").map((paragraph, index) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$2", secondary: true, lineHeight: "$3", children: paragraph }, index)) })
2935
- ] });
2936
- }
2937
- function BuyCreditsFaq() {
2938
- const [expandedId, setExpandedId] = (0, import_react8.useState)(null);
2939
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.Card, { gap: "$3", children: [
2940
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Heading, { level: 6, children: "FAQ" }),
2941
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.YStack, { gap: "$3", children: FAQ_ITEMS.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.YStack, { gap: "$3", children: [
2942
- index > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Separator, {}),
2943
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2944
- FaqItem,
2945
- {
2946
- question: item.question,
2947
- answer: item.answer,
2948
- expanded: expandedId === item.id,
2949
- onToggle: () => {
2950
- setExpandedId((current) => current === item.id ? null : item.id);
2951
- }
2952
- }
2953
- )
2954
- ] }, item.id)) })
2955
- ] });
2956
- }
2957
-
2958
3659
  // src/components/manage/CreditsManagementCard.tsx
2959
- var import_react9 = require("react");
2960
- var import_ui9 = require("@goodwidget/ui");
3660
+ var import_react7 = require("react");
3661
+ var import_ui8 = require("@goodwidget/ui");
2961
3662
 
2962
3663
  // src/components/shared/constants.ts
2963
- 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.";
2964
- var BUYER_KEY_REQUIRED_WITHDRAW_TOOLTIP = "Sign with your payer wallet in Buyer & Operator below to generate the buyer private key before withdrawing funds.";
3664
+ 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.";
3665
+ var BUYER_KEY_REQUIRED_WITHDRAW_TOOLTIP = "Sign with your payer wallet in Signer Key below to generate the buyer private key before withdrawing funds.";
2965
3666
  var WITHDRAW_TOOLTIP = "Withdraws principal to your payer wallet (not bonus). Requires the buyer private key from this session.";
2966
3667
 
2967
3668
  // src/components/manage/CreditsManagementCard.tsx
2968
- var import_jsx_runtime7 = require("react/jsx-runtime");
3669
+ var import_jsx_runtime6 = require("react/jsx-runtime");
2969
3670
  function StatCell({ label, children }) {
2970
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2971
- import_ui9.YStack,
3671
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
3672
+ import_ui8.YStack,
2972
3673
  {
2973
3674
  flex: 1,
2974
3675
  minWidth: "45%",
@@ -2980,8 +3681,8 @@ function StatCell({ label, children }) {
2980
3681
  minWidth: "28%"
2981
3682
  },
2982
3683
  children: [
2983
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", secondary: true, children: label }),
2984
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.YStack, { justifyContent: "center", children })
3684
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$1", secondary: true, children: label }),
3685
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.YStack, { justifyContent: "center", children })
2985
3686
  ]
2986
3687
  }
2987
3688
  );
@@ -2990,7 +3691,7 @@ function StatValueText({
2990
3691
  children,
2991
3692
  color
2992
3693
  }) {
2993
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$2", fontWeight: "700", color, children });
3694
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$2", fontWeight: "700", color, children });
2994
3695
  }
2995
3696
  function formatCompactAmount(amount) {
2996
3697
  const value = Number.parseFloat(amount);
@@ -3009,16 +3710,16 @@ function formatExactGAmount(amount) {
3009
3710
  }).format(value)} G$`;
3010
3711
  }
3011
3712
  function CompactGStatValue({ amount }) {
3012
- const [open, setOpen] = (0, import_react9.useState)(false);
3713
+ const [open, setOpen] = (0, import_react7.useState)(false);
3013
3714
  const value = Number.parseFloat(amount);
3014
3715
  const compact = formatCompactAmount(amount);
3015
3716
  const exact = formatExactGAmount(amount);
3016
3717
  const needsExact = Number.isFinite(value) && value >= 1e3;
3017
3718
  if (!needsExact) {
3018
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValueText, { children: compact });
3719
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StatValueText, { children: compact });
3019
3720
  }
3020
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
3021
- import_ui9.XStack,
3721
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
3722
+ import_ui8.XStack,
3022
3723
  {
3023
3724
  position: "relative",
3024
3725
  cursor: "help",
@@ -3031,9 +3732,9 @@ function CompactGStatValue({ amount }) {
3031
3732
  onBlur: () => setOpen(false),
3032
3733
  onPress: () => setOpen((prev) => !prev),
3033
3734
  children: [
3034
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValueText, { children: compact }),
3035
- open && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3036
- import_ui9.YStack,
3735
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StatValueText, { children: compact }),
3736
+ open && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3737
+ import_ui8.YStack,
3037
3738
  {
3038
3739
  position: "absolute",
3039
3740
  bottom: "100%",
@@ -3046,7 +3747,7 @@ function CompactGStatValue({ amount }) {
3046
3747
  padding: "$2",
3047
3748
  zIndex: 100,
3048
3749
  pointerEvents: "none",
3049
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", lineHeight: "$2", color: "$color", whiteSpace: "nowrap", children: exact })
3750
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$1", lineHeight: "$2", color: "$color", whiteSpace: "nowrap", children: exact })
3050
3751
  }
3051
3752
  )
3052
3753
  ]
@@ -3062,10 +3763,10 @@ function formatUsdAmount(usdMicro) {
3062
3763
  }).format(value);
3063
3764
  }
3064
3765
  function CreditsManagementCard({ state, actions }) {
3065
- const [isClosing, setIsClosing] = (0, import_react9.useState)(false);
3066
- const [isWithdrawing, setIsWithdrawing] = (0, import_react9.useState)(false);
3067
- const [channelId, setChannelId] = (0, import_react9.useState)("");
3068
- const [withdrawAmount, setWithdrawAmount] = (0, import_react9.useState)("");
3766
+ const [isClosing, setIsClosing] = (0, import_react7.useState)(false);
3767
+ const [isWithdrawing, setIsWithdrawing] = (0, import_react7.useState)(false);
3768
+ const [channelId, setChannelId] = (0, import_react7.useState)("");
3769
+ const [withdrawAmount, setWithdrawAmount] = (0, import_react7.useState)("");
3069
3770
  const {
3070
3771
  totalCreditUsd,
3071
3772
  totalGdDepositedG,
@@ -3075,7 +3776,7 @@ function CreditsManagementCard({ state, actions }) {
3075
3776
  withdrawableUsd,
3076
3777
  buyerPrvKey
3077
3778
  } = state;
3078
- const monthlyStreamUsdDisplay = (0, import_react9.useMemo)(() => {
3779
+ const monthlyStreamUsdDisplay = (0, import_react7.useMemo)(() => {
3079
3780
  if (!monthlyStreamG || !gdUsdPerToken) return null;
3080
3781
  if (Number.parseFloat(monthlyStreamG) <= 0) return null;
3081
3782
  const quote = { depositAmountG: "0", streamAmountG: monthlyStreamG };
@@ -3091,34 +3792,34 @@ function CreditsManagementCard({ state, actions }) {
3091
3792
  const hasWithdrawableBalance = withdrawableUsd !== null && BigInt(withdrawableUsd) > 0n;
3092
3793
  const canClose = Boolean(buyerPrvKey) && Boolean(channelId.trim()) && !isClosing;
3093
3794
  const canWithdraw = Boolean(buyerPrvKey) && hasWithdrawableBalance && Boolean(withdrawAmount.trim()) && !isWithdrawing;
3094
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Card, { gap: "$3", children: [
3095
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Heading, { level: 6, children: "AI Credits" }),
3096
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.XStack, { gap: "$4", width: "100%", alignItems: "flex-start", flexWrap: "wrap", children: [
3097
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$2", flex: 1, minWidth: 0, children: [
3098
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", secondary: true, children: "Total Credit (US$)" }),
3099
- totalCreditDisplay !== null ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Heading, { level: 5, children: totalCreditDisplay }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Spinner, { size: "sm" })
3795
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.Card, { gap: "$3", children: [
3796
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Heading, { level: 6, children: "AI Credits" }),
3797
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.XStack, { gap: "$4", width: "100%", alignItems: "flex-start", flexWrap: "wrap", children: [
3798
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.YStack, { gap: "$2", flex: 1, minWidth: 0, children: [
3799
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$1", secondary: true, children: "Total Credit (US$)" }),
3800
+ totalCreditDisplay !== null ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Heading, { level: 5, children: totalCreditDisplay }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Spinner, { size: "sm" })
3100
3801
  ] }),
3101
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$2", flex: 1, minWidth: 0, children: [
3102
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", secondary: true, children: "Est. Monthly Credit (US$)" }),
3103
- monthlyStreamUsdDisplay ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Heading, { level: 5, color: "$primary", children: [
3802
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.YStack, { gap: "$2", flex: 1, minWidth: 0, children: [
3803
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$1", secondary: true, children: "Est. Monthly Credit (US$)" }),
3804
+ monthlyStreamUsdDisplay ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.Heading, { level: 5, color: "$primary", children: [
3104
3805
  "~",
3105
3806
  monthlyStreamUsdDisplay
3106
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Heading, { level: 5, children: "\u2014" })
3807
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Heading, { level: 5, children: "\u2014" })
3107
3808
  ] })
3108
3809
  ] }),
3109
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.XStack, { gap: "$2", width: "100%", flexWrap: "wrap", alignItems: "stretch", children: [
3110
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Total Deposited (G$)", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CompactGStatValue, { amount: totalGdDepositedG ?? "0.00" }) }),
3111
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Monthly Stream (G$)", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CompactGStatValue, { amount: monthlyStreamG ?? "0.00" }) }),
3112
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Withdrawable (US$)", children: withdrawableDisplay !== null ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValueText, { children: withdrawableDisplay }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Spinner, { size: "sm" }) })
3810
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.XStack, { gap: "$2", width: "100%", flexWrap: "wrap", alignItems: "stretch", children: [
3811
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StatCell, { label: "Total Deposited (G$)", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CompactGStatValue, { amount: totalGdDepositedG ?? "0.00" }) }),
3812
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StatCell, { label: "Monthly Stream (G$)", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CompactGStatValue, { amount: monthlyStreamG ?? "0.00" }) }),
3813
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StatCell, { label: "Withdrawable (US$)", children: withdrawableDisplay !== null ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StatValueText, { children: withdrawableDisplay }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Spinner, { size: "sm" }) })
3113
3814
  ] }),
3114
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$1", children: [
3115
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.XStack, { gap: "$1", alignItems: "center", children: [
3116
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", variant: "label", children: "Withdraw" }),
3117
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(InfoTooltip, { message: WITHDRAW_TOOLTIP })
3815
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.YStack, { gap: "$1", children: [
3816
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.XStack, { gap: "$1", alignItems: "center", children: [
3817
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$1", variant: "label", children: "Withdraw" }),
3818
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(InfoTooltip, { message: WITHDRAW_TOOLTIP })
3118
3819
  ] }),
3119
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.XStack, { gap: "$2", alignItems: "center", children: [
3120
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.YStack, { flex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3121
- import_ui9.Input,
3820
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.XStack, { gap: "$2", alignItems: "center", children: [
3821
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.YStack, { flex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3822
+ import_ui8.Input,
3122
3823
  {
3123
3824
  size: "sm",
3124
3825
  value: withdrawAmount,
@@ -3126,8 +3827,8 @@ function CreditsManagementCard({ state, actions }) {
3126
3827
  placeholder: hasWithdrawableBalance && withdrawableDisplay ? `Max ${withdrawableDisplay} US$` : "Amount in US$"
3127
3828
  }
3128
3829
  ) }),
3129
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HoverTooltip, { message: !buyerPrvKey ? BUYER_KEY_REQUIRED_WITHDRAW_TOOLTIP : null, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3130
- import_ui9.Button,
3830
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(HoverTooltip, { message: !buyerPrvKey ? BUYER_KEY_REQUIRED_WITHDRAW_TOOLTIP : null, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3831
+ import_ui8.Button,
3131
3832
  {
3132
3833
  variant: "outline",
3133
3834
  size: "sm",
@@ -3142,16 +3843,16 @@ function CreditsManagementCard({ state, actions }) {
3142
3843
  setWithdrawAmount("");
3143
3844
  });
3144
3845
  },
3145
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: isWithdrawing ? "Withdrawing\u2026" : "Withdraw" })
3846
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.ButtonText, { children: isWithdrawing ? "Withdrawing\u2026" : "Withdraw" })
3146
3847
  }
3147
3848
  ) })
3148
3849
  ] })
3149
3850
  ] }),
3150
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$1", children: [
3151
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", variant: "label", children: "Close Channel" }),
3152
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.XStack, { gap: "$2", alignItems: "center", children: [
3153
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.YStack, { flex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3154
- import_ui9.Input,
3851
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.YStack, { gap: "$1", children: [
3852
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.Text, { fontSize: "$1", variant: "label", children: "Close Channel" }),
3853
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui8.XStack, { gap: "$2", alignItems: "center", children: [
3854
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.YStack, { flex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3855
+ import_ui8.Input,
3155
3856
  {
3156
3857
  size: "sm",
3157
3858
  value: channelId,
@@ -3159,8 +3860,8 @@ function CreditsManagementCard({ state, actions }) {
3159
3860
  placeholder: "0x\u2026 (64 hex chars)"
3160
3861
  }
3161
3862
  ) }),
3162
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HoverTooltip, { message: !buyerPrvKey ? BUYER_KEY_REQUIRED_CLOSE_TOOLTIP : null, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3163
- import_ui9.Button,
3863
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(HoverTooltip, { message: !buyerPrvKey ? BUYER_KEY_REQUIRED_CLOSE_TOOLTIP : null, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3864
+ import_ui8.Button,
3164
3865
  {
3165
3866
  variant: "outline",
3166
3867
  size: "sm",
@@ -3175,7 +3876,7 @@ function CreditsManagementCard({ state, actions }) {
3175
3876
  setChannelId("");
3176
3877
  });
3177
3878
  },
3178
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: isClosing ? "Closing\u2026" : "Close" })
3879
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui8.ButtonText, { children: isClosing ? "Closing\u2026" : "Close" })
3179
3880
  }
3180
3881
  ) })
3181
3882
  ] })
@@ -3184,140 +3885,400 @@ function CreditsManagementCard({ state, actions }) {
3184
3885
  }
3185
3886
 
3186
3887
  // src/components/manage/BuyerOperatorCard.tsx
3187
- var import_react10 = require("react");
3188
- var import_ui11 = require("@goodwidget/ui");
3189
-
3190
- // src/components/shared/AddressView.tsx
3888
+ var import_react9 = require("react");
3191
3889
  var import_ui10 = require("@goodwidget/ui");
3192
- var import_jsx_runtime8 = require("react/jsx-runtime");
3193
- function AddressView({ label, address }) {
3194
- const { copied, copy } = useCopyFeedback();
3195
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$1", children: [
3196
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: "$1", secondary: true, children: label }),
3197
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
3198
- import_ui10.XStack,
3199
- {
3200
- backgroundColor: "$backgroundMuted",
3201
- borderRadius: "$2",
3202
- padding: "$2",
3203
- justifyContent: "space-between",
3204
- alignItems: "center",
3205
- children: [
3206
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3207
- import_ui10.Text,
3208
- {
3209
- fontSize: "$2",
3210
- fontFamily: "$mono",
3211
- flex: 1,
3212
- numberOfLines: 1,
3213
- style: monospaceSingleLineStyle,
3214
- children: truncateAddress(address)
3215
- }
3216
- ),
3217
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Button, { size: "sm", variant: "ghost", iconSize: "sm", onPress: () => void copy(address), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Icon, { name: copied ? "check" : "copy", size: "xs", color: copied ? "success" : "text" }) })
3218
- ]
3219
- }
3220
- )
3221
- ] });
3222
- }
3223
3890
 
3224
- // src/components/manage/BuyerOperatorCard.tsx
3225
- var import_jsx_runtime9 = require("react/jsx-runtime");
3226
- function BuyerOperatorCard({ state, actions }) {
3227
- const { address, buyerPubKey, buyerPrvKey, operatorConsented } = state;
3228
- const { copied: copiedPrivate, copy: copyPrivate } = useCopyFeedback();
3229
- const [isPrivateKeyVisible, setIsPrivateKeyVisible] = (0, import_react10.useState)(false);
3230
- const [isGenerating, setIsGenerating] = (0, import_react10.useState)(false);
3231
- const [isSigning, setIsSigning] = (0, import_react10.useState)(false);
3232
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.Card, { gap: "$2", children: [
3233
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Heading, { level: 6, children: "Buyer & Operator" }),
3234
- address && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AddressView, { label: "Payer", address }),
3235
- buyerPubKey && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AddressView, { label: "Buyer", address: buyerPubKey }),
3236
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.XStack, { gap: "$2", alignItems: "stretch", width: "100%", children: [
3237
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3238
- import_ui11.Button,
3891
+ // src/components/setup/SignerKeyPanel.tsx
3892
+ var import_react8 = require("react");
3893
+ var import_ui9 = require("@goodwidget/ui");
3894
+ var import_jsx_runtime7 = require("react/jsx-runtime");
3895
+ var ZERO_OPERATOR = "0x0000000000000000000000000000000000000000";
3896
+ function SignerKeyPanel({
3897
+ state,
3898
+ actions,
3899
+ onProceed,
3900
+ showHeading = true,
3901
+ proceedLabel: proceedLabelOverride,
3902
+ compact = false
3903
+ }) {
3904
+ const [choice, setChoice] = (0, import_react8.useState)(null);
3905
+ const [privateKey, setPrivateKey] = (0, import_react8.useState)("");
3906
+ const [isImporting, setIsImporting] = (0, import_react8.useState)(false);
3907
+ const [keyConfirmed, setKeyConfirmed] = (0, import_react8.useState)(false);
3908
+ const [importedAddress, setImportedAddress] = (0, import_react8.useState)(null);
3909
+ const leaveChoice = () => {
3910
+ setChoice(null);
3911
+ setImportedAddress(null);
3912
+ };
3913
+ const currentOperator = state.currentOperator?.toLowerCase();
3914
+ const expectedOperator = state.operatorAddress?.toLowerCase();
3915
+ const proceedLabel = proceedLabelOverride ?? (state.operatorConsented ? "Done" : "Continue to Authorize Wallet");
3916
+ const hasDifferentOperator = Boolean(currentOperator) && currentOperator !== ZERO_OPERATOR && Boolean(expectedOperator) && currentOperator !== expectedOperator;
3917
+ if (choice === "generate") {
3918
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$3", children: [
3919
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Button, { variant: "text", alignSelf: "flex-start", onPress: leaveChoice, children: [
3920
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Icon, { name: "arrow-left", size: "xs", color: "primary" }),
3921
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: "Back to Generate / Import" })
3922
+ ] }),
3923
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3924
+ BuyerKeyPanel,
3925
+ {
3926
+ embedded: true,
3927
+ buyerPubKey: state.buyerPubKey,
3928
+ buyerPrvKey: state.buyerPrvKey,
3929
+ buyerPubKeySaved: keyConfirmed,
3930
+ onGenerate: actions.generateBuyerKey,
3931
+ onConfirm: () => setKeyConfirmed(true)
3932
+ }
3933
+ ),
3934
+ keyConfirmed && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Button, { size: "sm", ...compactButtonProps, onPress: onProceed, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: proceedLabel }) })
3935
+ ] });
3936
+ }
3937
+ if (choice === "import") {
3938
+ const importedSigner = !isImporting && Boolean(importedAddress) && state.buyerPubKey?.toLowerCase() === importedAddress?.toLowerCase();
3939
+ const importedSignerBlocked = importedSigner && hasDifferentOperator;
3940
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$3", children: [
3941
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Button, { variant: "text", alignSelf: "flex-start", onPress: leaveChoice, children: [
3942
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Icon, { name: "arrow-left", size: "xs", color: "primary" }),
3943
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: "Back to Generate / Import" })
3944
+ ] }),
3945
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Heading, { level: 5, children: "Import Signer Key" }),
3946
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { secondary: true, children: "Paste the private key from AntSeed. It will be checked against the operator configured for this signer before you can continue." }),
3947
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3948
+ import_ui9.Input,
3239
3949
  {
3240
- flex: 1,
3241
- flexBasis: 0,
3242
- minWidth: 0,
3243
3950
  size: "sm",
3244
- ...compactButtonProps,
3245
- onPress: () => {
3246
- setIsGenerating(true);
3247
- void Promise.resolve(actions.generateBuyerKey()).finally(() => setIsGenerating(false));
3248
- },
3249
- disabled: isGenerating,
3250
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.ButtonText, { children: isGenerating ? "Signing\u2026" : "Sign & Generate" })
3951
+ value: privateKey,
3952
+ onChangeText: setPrivateKey,
3953
+ placeholder: "0x\u2026",
3954
+ autoCapitalize: "none"
3251
3955
  }
3252
3956
  ),
3253
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3254
- import_ui11.Button,
3957
+ state.error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { color: "$error", children: state.error }),
3958
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3959
+ import_ui9.Button,
3255
3960
  {
3256
- flex: 1,
3257
- flexBasis: 0,
3258
- minWidth: 0,
3259
3961
  size: "sm",
3260
3962
  ...compactButtonProps,
3963
+ disabled: !privateKey.trim() || isImporting,
3261
3964
  onPress: () => {
3262
- setIsSigning(true);
3263
- void Promise.resolve(actions.signOperatorConsent()).finally(() => setIsSigning(false));
3965
+ setIsImporting(true);
3966
+ setImportedAddress(null);
3967
+ void actions.importBuyerFromPrivateKey(privateKey.trim()).then((buyerAddress) => setImportedAddress(buyerAddress)).catch(() => setImportedAddress(null)).finally(() => setIsImporting(false));
3264
3968
  },
3265
- disabled: operatorConsented || isSigning || !buyerPrvKey,
3266
- children: isSigning ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Spinner, { size: "sm" }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.ButtonText, { children: operatorConsented ? "Consented" : "Sign Consent" })
3969
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: isImporting ? "Checking signer\u2026" : "Import Signer Key" })
3267
3970
  }
3268
- )
3269
- ] }),
3270
- buyerPrvKey && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.YStack, { gap: "$2", children: [
3271
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.XStack, { justifyContent: "space-between", alignItems: "center", children: [
3272
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Text, { fontSize: "$1", secondary: true, children: "Buyer Private Key" }),
3273
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3274
- import_ui11.Button,
3275
- {
3276
- variant: "text",
3277
- size: "sm",
3278
- onPress: () => setIsPrivateKeyVisible((prev) => !prev),
3279
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.ButtonText, { children: isPrivateKeyVisible ? "Hide" : "Reveal" })
3280
- }
3281
- )
3282
- ] }),
3283
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
3284
- import_ui11.XStack,
3285
- {
3286
- backgroundColor: "$backgroundMuted",
3287
- borderRadius: "$2",
3288
- padding: "$2",
3289
- justifyContent: "space-between",
3290
- alignItems: "center",
3291
- children: [
3292
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Text, { fontSize: "$2", style: monospaceSingleLineStyle, flex: 1, numberOfLines: 1, children: isPrivateKeyVisible ? buyerPrvKey : "\u2022".repeat(Math.min(48, buyerPrvKey.length)) }),
3293
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3294
- import_ui11.Button,
3295
- {
3296
- size: "sm",
3297
- variant: "ghost",
3298
- iconSize: "sm",
3299
- onPress: () => void copyPrivate(buyerPrvKey),
3300
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3301
- import_ui11.Icon,
3302
- {
3303
- name: copiedPrivate ? "check" : "copy",
3304
- size: "xs",
3305
- color: copiedPrivate ? "success" : "text"
3306
- }
3307
- )
3308
- }
3309
- )
3310
- ]
3311
- }
3312
- )
3971
+ ),
3972
+ importedSignerBlocked ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$2", children: [
3973
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { color: "$error", fontWeight: "700", children: "Signer key cannot be used" }),
3974
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { secondary: true, children: "The imported signer key already has another operator configured. Paste a different signer key, or go back and generate a new one." })
3975
+ ] }) : importedSigner ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$2", children: [
3976
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { color: "$success", fontWeight: "700", children: "Signer imported" }),
3977
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Text, { secondary: true, children: [
3978
+ truncateAddress(state.buyerPubKey ?? ""),
3979
+ " is now your active signer."
3980
+ ] }),
3981
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { secondary: true, children: state.operatorConsented ? "GoodDollar is already configured as the operator." : currentOperator === ZERO_OPERATOR ? "No operator is configured yet. Continue to authorize GoodDollar." : "The configured operator is being checked." }),
3982
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Button, { size: "sm", ...compactButtonProps, onPress: onProceed, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: proceedLabel }) })
3983
+ ] }) : null
3984
+ ] });
3985
+ }
3986
+ const choices = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
3987
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
3988
+ import_ui9.Button,
3989
+ {
3990
+ flex: compact ? void 0 : 1,
3991
+ alignSelf: compact ? "stretch" : void 0,
3992
+ size: compact ? "sm" : "lg",
3993
+ variant: "outline",
3994
+ ...compactButtonProps,
3995
+ onPress: () => setChoice("generate"),
3996
+ children: [
3997
+ !compact && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Badge, { type: "success", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.BadgeText, { children: "Recommended" }) }),
3998
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: "Generate Signer Key" })
3999
+ ]
4000
+ }
4001
+ ),
4002
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4003
+ import_ui9.Button,
4004
+ {
4005
+ flex: compact ? void 0 : 1,
4006
+ alignSelf: compact ? "stretch" : void 0,
4007
+ size: compact ? "sm" : "lg",
4008
+ variant: "outline",
4009
+ ...compactButtonProps,
4010
+ onPress: () => setChoice("import"),
4011
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.ButtonText, { children: "Import Signer Key" })
4012
+ }
4013
+ )
4014
+ ] });
4015
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$3", children: [
4016
+ showHeading && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Heading, { level: 5, children: "Signer Key" }),
4017
+ !compact && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { secondary: true, children: "A dedicated identity used only to buy and spend AI credits \u2014 separate from your wallet." }),
4018
+ compact ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.YStack, { gap: "$2", children: choices }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.XStack, { gap: "$3", children: choices }),
4019
+ !compact && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$2", secondary: true, children: "Generate is recommended for a fresh signer. Either direction uses the same key once it is set up in AntSeed." })
4020
+ ] });
4021
+ }
4022
+
4023
+ // src/components/manage/BuyerOperatorCard.tsx
4024
+ var import_jsx_runtime8 = require("react/jsx-runtime");
4025
+ function shortAddress(address) {
4026
+ return `${address.slice(0, 6)}\u2026${address.slice(-4)}`;
4027
+ }
4028
+ function DisclosureToggle({
4029
+ open,
4030
+ label,
4031
+ onPress
4032
+ }) {
4033
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4034
+ import_ui10.Button,
4035
+ {
4036
+ variant: "text",
4037
+ size: "sm",
4038
+ alignSelf: "flex-start",
4039
+ gap: "$1.5",
4040
+ ...compactButtonProps,
4041
+ paddingHorizontal: "$0",
4042
+ "aria-expanded": open,
4043
+ onPress,
4044
+ children: [
4045
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Icon, { name: open ? "chevron-up" : "chevron-down", size: "xs", color: "primary" }),
4046
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.ButtonText, { children: label })
4047
+ ]
4048
+ }
4049
+ );
4050
+ }
4051
+ function CopyableValue({ value, display }) {
4052
+ const { copied, copy } = useCopyFeedback();
4053
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4054
+ import_ui10.XStack,
4055
+ {
4056
+ backgroundColor: "$backgroundMuted",
4057
+ borderRadius: "$2",
4058
+ padding: "$2",
4059
+ justifyContent: "space-between",
4060
+ alignItems: "center",
4061
+ gap: "$2",
4062
+ children: [
4063
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: "$2", flex: 1, numberOfLines: 1, style: monospaceSingleLineStyle, children: display ?? value }),
4064
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Button, { size: "sm", variant: "ghost", iconSize: "sm", onPress: () => void copy(value), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Icon, { name: copied ? "check" : "copy", size: "xs", color: copied ? "success" : "text" }) })
4065
+ ]
4066
+ }
4067
+ );
4068
+ }
4069
+ function SignerStatus({
4070
+ consented,
4071
+ size = "$1"
4072
+ }) {
4073
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.XStack, { gap: "$1", alignItems: "center", children: [
4074
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4075
+ import_ui10.Icon,
4076
+ {
4077
+ name: consented ? "check" : "alert-triangle",
4078
+ size: "2xs",
4079
+ color: consented ? "success" : "warning"
4080
+ }
4081
+ ),
4082
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: size, color: consented ? "$success" : "$warning", children: consented ? "Authorized" : "Not authorized" })
4083
+ ] });
4084
+ }
4085
+ function BuyerSelector({
4086
+ buyers,
4087
+ activeBuyerAddress,
4088
+ onSelect
4089
+ }) {
4090
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.YStack, { gap: "$1", children: buyers.map((buyer) => {
4091
+ const isActive = buyer.toLowerCase() === activeBuyerAddress?.toLowerCase();
4092
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4093
+ import_ui10.XStack,
4094
+ {
4095
+ tag: "button",
4096
+ role: "option",
4097
+ "aria-selected": isActive,
4098
+ alignItems: "center",
4099
+ justifyContent: "space-between",
4100
+ gap: "$2",
4101
+ paddingHorizontal: "$2",
4102
+ paddingVertical: "$1.5",
4103
+ borderRadius: "$2",
4104
+ borderWidth: 1,
4105
+ borderColor: isActive ? "$primary" : "$borderColor",
4106
+ backgroundColor: isActive ? "$infoMuted" : "$backgroundDark",
4107
+ cursor: isActive ? "default" : "pointer",
4108
+ hoverStyle: isActive ? {} : { backgroundColor: "$backgroundPress" },
4109
+ onPress: () => {
4110
+ if (!isActive) void onSelect(buyer);
4111
+ },
4112
+ children: [
4113
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4114
+ import_ui10.Text,
4115
+ {
4116
+ fontSize: "$2",
4117
+ fontWeight: isActive ? "700" : "500",
4118
+ color: isActive ? "$primary" : "$color",
4119
+ numberOfLines: 1,
4120
+ flex: 1,
4121
+ style: monospaceSingleLineStyle,
4122
+ children: shortAddress(buyer)
4123
+ }
4124
+ ),
4125
+ isActive ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.XStack, { gap: "$1", alignItems: "center", children: [
4126
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: "$1", color: "$primary", children: "active" }),
4127
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Icon, { name: "check", size: "xs", color: "primary" })
4128
+ ] }) : null
4129
+ ]
4130
+ },
4131
+ buyer
4132
+ );
4133
+ }) });
4134
+ }
4135
+ function BuyerOperatorCard({ state, actions }) {
4136
+ const {
4137
+ buyerPubKey,
4138
+ buyerPrvKey,
4139
+ operatorSignature,
4140
+ operatorConsented,
4141
+ operatorConsentPending,
4142
+ buyers
4143
+ } = state;
4144
+ const [isExpanded, setIsExpanded] = (0, import_react9.useState)(false);
4145
+ const [showSwitcher, setShowSwitcher] = (0, import_react9.useState)(false);
4146
+ const [showReplacePanel, setShowReplacePanel] = (0, import_react9.useState)(false);
4147
+ const [showPrivateKey, setShowPrivateKey] = (0, import_react9.useState)(false);
4148
+ const [panelInstance, setPanelInstance] = (0, import_react9.useState)(0);
4149
+ const buyerCanSign = Boolean(buyerPrvKey || operatorSignature);
4150
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.Card, { gap: "$3", "data-testid": "signer-key-card", children: [
4151
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4152
+ import_ui10.XStack,
4153
+ {
4154
+ tag: "button",
4155
+ "data-testid": "signer-key-toggle",
4156
+ alignItems: "center",
4157
+ justifyContent: "space-between",
4158
+ gap: "$2",
4159
+ width: "100%",
4160
+ backgroundColor: "transparent",
4161
+ borderWidth: 0,
4162
+ paddingHorizontal: "$0",
4163
+ paddingVertical: "$0",
4164
+ cursor: "pointer",
4165
+ "aria-expanded": isExpanded,
4166
+ onPress: () => setIsExpanded((prev) => !prev),
4167
+ children: [
4168
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$1", flex: 1, minWidth: 0, alignItems: "flex-start", children: [
4169
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Heading, { level: 6, children: "Signer Key" }),
4170
+ buyerPubKey ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.XStack, { alignItems: "center", flexWrap: "wrap", children: [
4171
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: "$1", secondary: true, style: monospaceSingleLineStyle, children: `${truncateAddress(buyerPubKey)} \xB7 ` }),
4172
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SignerStatus, { consented: operatorConsented })
4173
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: "$1", secondary: true, children: "No signer key yet" })
4174
+ ] }),
4175
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Icon, { name: isExpanded ? "chevron-up" : "chevron-down", size: "sm", color: "muted" })
4176
+ ]
4177
+ }
4178
+ ),
4179
+ isExpanded && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$4", children: [
4180
+ buyerPubKey && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$2", children: [
4181
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { variant: "label", secondary: true, children: "Active signer" }),
4182
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4183
+ import_ui10.YStack,
4184
+ {
4185
+ backgroundColor: "$backgroundDark",
4186
+ borderRadius: "$2",
4187
+ borderWidth: 1,
4188
+ borderColor: "$borderColor",
4189
+ padding: "$2",
4190
+ gap: "$2",
4191
+ children: [
4192
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CopyableValue, { value: buyerPubKey, display: truncateAddress(buyerPubKey) }),
4193
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SignerStatus, { consented: operatorConsented, size: "$2" }),
4194
+ !operatorConsented && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4195
+ import_ui10.Button,
4196
+ {
4197
+ size: "sm",
4198
+ ...compactButtonProps,
4199
+ disabled: operatorConsentPending || !buyerCanSign,
4200
+ onPress: () => {
4201
+ void Promise.resolve(actions.signOperatorConsent());
4202
+ },
4203
+ children: operatorConsentPending ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Spinner, { size: "sm" }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.ButtonText, { children: "Authorize GoodDollar" })
4204
+ }
4205
+ )
4206
+ ]
4207
+ }
4208
+ )
4209
+ ] }),
4210
+ buyers.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$2", children: [
4211
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4212
+ DisclosureToggle,
4213
+ {
4214
+ open: showSwitcher,
4215
+ label: `Switch signer (${buyers.length})`,
4216
+ onPress: () => setShowSwitcher((prev) => !prev)
4217
+ }
4218
+ ),
4219
+ showSwitcher && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4220
+ BuyerSelector,
4221
+ {
4222
+ buyers,
4223
+ activeBuyerAddress: buyerPubKey,
4224
+ onSelect: actions.selectBuyer
4225
+ }
4226
+ )
4227
+ ] }),
4228
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$2", children: [
4229
+ buyerPubKey ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4230
+ DisclosureToggle,
4231
+ {
4232
+ open: showReplacePanel,
4233
+ label: "Replace signer key",
4234
+ onPress: () => setShowReplacePanel((prev) => !prev)
4235
+ }
4236
+ ) : null,
4237
+ (showReplacePanel || !buyerPubKey) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4238
+ SignerKeyPanel,
4239
+ {
4240
+ state,
4241
+ actions,
4242
+ showHeading: false,
4243
+ compact: Boolean(buyerPubKey),
4244
+ proceedLabel: "Done",
4245
+ onProceed: () => setPanelInstance((prev) => prev + 1)
4246
+ },
4247
+ panelInstance
4248
+ )
4249
+ ] }),
4250
+ buyerPrvKey && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.YStack, { gap: "$2", children: [
4251
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui10.XStack, { justifyContent: "space-between", alignItems: "center", gap: "$2", children: [
4252
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { variant: "label", secondary: true, children: "Private key" }),
4253
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4254
+ import_ui10.Button,
4255
+ {
4256
+ variant: "text",
4257
+ size: "sm",
4258
+ ...compactButtonProps,
4259
+ paddingHorizontal: "$0",
4260
+ onPress: () => setShowPrivateKey((prev) => !prev),
4261
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.ButtonText, { children: showPrivateKey ? "Hide" : "Reveal" })
4262
+ }
4263
+ )
4264
+ ] }),
4265
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4266
+ CopyableValue,
4267
+ {
4268
+ value: buyerPrvKey,
4269
+ display: showPrivateKey ? buyerPrvKey : "\u2022".repeat(Math.min(48, buyerPrvKey.length))
4270
+ }
4271
+ ),
4272
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui10.Text, { fontSize: "$1", color: "$warning", children: "Treat this like a password \u2014 anyone who has it can spend your credits." })
4273
+ ] })
3313
4274
  ] })
3314
4275
  ] });
3315
4276
  }
3316
4277
 
3317
4278
  // src/components/manage/SetupSnippet.tsx
3318
- var import_react11 = require("react");
3319
- var import_ui12 = require("@goodwidget/ui");
3320
- var import_jsx_runtime10 = require("react/jsx-runtime");
4279
+ var import_react10 = require("react");
4280
+ var import_ui11 = require("@goodwidget/ui");
4281
+ var import_jsx_runtime9 = require("react/jsx-runtime");
3321
4282
  var ANTSEED_API_DOCS_URL = "https://antseed.com/docs/guides/using-the-api";
3322
4283
  var setupSnippetLineStyle = {
3323
4284
  fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",
@@ -3338,21 +4299,21 @@ function buildSetupSnippet() {
3338
4299
  ].join("\n");
3339
4300
  }
3340
4301
  function SetupSnippet() {
3341
- const [expanded, setExpanded] = (0, import_react11.useState)(false);
3342
- const [copied, setCopied] = (0, import_react11.useState)(false);
4302
+ const [expanded, setExpanded] = (0, import_react10.useState)(false);
4303
+ const [copied, setCopied] = (0, import_react10.useState)(false);
3343
4304
  const snippet = buildSetupSnippet();
3344
4305
  const copyText = snippet.replace(/\n\n+/g, "\n").trim();
3345
4306
  const lines = snippet.trim().split("\n");
3346
4307
  async function handleCopy() {
3347
- const copied2 = await (0, import_ui12.copyTextToClipboard)(copyText);
4308
+ const copied2 = await (0, import_ui11.copyTextToClipboard)(copyText);
3348
4309
  if (!copied2) return;
3349
4310
  setCopied(true);
3350
4311
  setTimeout(() => setCopied(false), 2e3);
3351
4312
  }
3352
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.Card, { gap: "$2", children: [
3353
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.XStack, { justifyContent: "space-between", alignItems: "center", children: [
3354
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
3355
- import_ui12.XStack,
4313
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.Card, { gap: "$2", children: [
4314
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.XStack, { justifyContent: "space-between", alignItems: "center", children: [
4315
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
4316
+ import_ui11.XStack,
3356
4317
  {
3357
4318
  flex: 1,
3358
4319
  justifyContent: "space-between",
@@ -3360,29 +4321,29 @@ function SetupSnippet() {
3360
4321
  onPress: () => setExpanded((value) => !value),
3361
4322
  cursor: "pointer",
3362
4323
  children: [
3363
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$3", fontWeight: "600", children: "API Setup" }),
3364
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Icon, { name: expanded ? "chevron-up" : "chevron-right", size: "xs", color: "muted" })
4324
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Text, { fontSize: "$3", fontWeight: "600", children: "API Setup" }),
4325
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Icon, { name: expanded ? "chevron-up" : "chevron-right", size: "xs", color: "muted" })
3365
4326
  ]
3366
4327
  }
3367
4328
  ),
3368
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Button, { size: "sm", variant: "ghost", iconSize: "sm", onPress: handleCopy, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Icon, { name: copied ? "check" : "copy", size: "xs", color: copied ? "success" : "text" }) })
4329
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Button, { size: "sm", variant: "ghost", iconSize: "sm", onPress: handleCopy, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Icon, { name: copied ? "check" : "copy", size: "xs", color: copied ? "success" : "text" }) })
3369
4330
  ] }),
3370
- expanded && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { gap: "$2", children: [
3371
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3372
- import_ui12.YStack,
4331
+ expanded && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.YStack, { gap: "$2", children: [
4332
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4333
+ import_ui11.YStack,
3373
4334
  {
3374
4335
  backgroundColor: "$backgroundMuted",
3375
4336
  borderRadius: "$2",
3376
4337
  padding: "$3",
3377
4338
  width: "100%",
3378
4339
  gap: "$1",
3379
- children: lines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { color: "$text", style: setupSnippetLineStyle, children: line.length > 0 ? line : " " }, index))
4340
+ children: lines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Text, { color: "$text", style: setupSnippetLineStyle, children: line.length > 0 ? line : " " }, index))
3380
4341
  }
3381
4342
  ),
3382
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.Text, { fontSize: "$1", secondary: true, children: [
4343
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui11.Text, { fontSize: "$1", secondary: true, children: [
3383
4344
  "To connect AI tools to the AntSeed AI provider, see the",
3384
4345
  " ",
3385
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Anchor, { href: ANTSEED_API_DOCS_URL, target: "_blank", children: "AntSeed API guide" }),
4346
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui11.Anchor, { href: ANTSEED_API_DOCS_URL, target: "_blank", children: "AntSeed API guide" }),
3386
4347
  "."
3387
4348
  ] })
3388
4349
  ] })
@@ -3390,9 +4351,9 @@ function SetupSnippet() {
3390
4351
  }
3391
4352
 
3392
4353
  // src/components/history/HistoryTab.tsx
3393
- var import_react12 = require("react");
3394
- var import_ui13 = require("@goodwidget/ui");
3395
- var import_jsx_runtime11 = require("react/jsx-runtime");
4354
+ var import_react11 = require("react");
4355
+ var import_ui12 = require("@goodwidget/ui");
4356
+ var import_jsx_runtime10 = require("react/jsx-runtime");
3396
4357
  var STATUS_OPTIONS = [
3397
4358
  { label: "All", value: "all" },
3398
4359
  { label: "Funded", value: "funded" },
@@ -3464,10 +4425,10 @@ function entryDetailRows(entry) {
3464
4425
  return rows;
3465
4426
  }
3466
4427
  function EntryDetailRow({ label, value }) {
3467
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.XStack, { gap: "$2", alignItems: "flex-start", width: "100%", children: [
3468
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$1", fontWeight: "600", secondary: true, minWidth: 72, flexShrink: 0, children: label }),
3469
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3470
- import_ui13.Text,
4428
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.XStack, { gap: "$2", alignItems: "flex-start", width: "100%", children: [
4429
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$1", fontWeight: "600", secondary: true, minWidth: 72, flexShrink: 0, children: label }),
4430
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4431
+ import_ui12.Text,
3471
4432
  {
3472
4433
  fontSize: "$1",
3473
4434
  flex: 1,
@@ -3587,9 +4548,9 @@ function CreditHistoryEntryRow({
3587
4548
  const amounts = amountLines(entry);
3588
4549
  const detailRows = entryDetailRows(entry);
3589
4550
  const titleColor = entry.fundingStatus === "failed" ? "$error" : "$color";
3590
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Card, { gap: "$2", children: [
3591
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3592
- import_ui13.XStack,
4551
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.Card, { gap: "$2", children: [
4552
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
4553
+ import_ui12.XStack,
3593
4554
  {
3594
4555
  alignItems: "center",
3595
4556
  gap: "$3",
@@ -3597,8 +4558,8 @@ function CreditHistoryEntryRow({
3597
4558
  cursor: "pointer",
3598
4559
  onPress: onToggle,
3599
4560
  children: [
3600
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3601
- import_ui13.YStack,
4561
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4562
+ import_ui12.YStack,
3602
4563
  {
3603
4564
  width: 40,
3604
4565
  height: 40,
@@ -3607,8 +4568,8 @@ function CreditHistoryEntryRow({
3607
4568
  justifyContent: "center",
3608
4569
  backgroundColor: entryIconBackground(entry),
3609
4570
  flexShrink: 0,
3610
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3611
- import_ui13.Icon,
4571
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4572
+ import_ui12.Icon,
3612
4573
  {
3613
4574
  name: entryIconName(entry),
3614
4575
  size: "sm",
@@ -3617,11 +4578,11 @@ function CreditHistoryEntryRow({
3617
4578
  )
3618
4579
  }
3619
4580
  ),
3620
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { flex: 1, gap: "$0.5", minWidth: 0, children: [
3621
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$3", fontWeight: "700", color: titleColor, children: sourceLabel(entry.source) }),
3622
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.XStack, { alignItems: "center", gap: "$1", children: [
3623
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3624
- import_ui13.YStack,
4581
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { flex: 1, gap: "$0.5", minWidth: 0, children: [
4582
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$3", fontWeight: "700", color: titleColor, children: sourceLabel(entry.source) }),
4583
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.XStack, { alignItems: "center", gap: "$1", children: [
4584
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4585
+ import_ui12.YStack,
3625
4586
  {
3626
4587
  width: 6,
3627
4588
  height: 6,
@@ -3629,18 +4590,18 @@ function CreditHistoryEntryRow({
3629
4590
  backgroundColor: accent
3630
4591
  }
3631
4592
  ),
3632
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$1", fontWeight: "600", color: accent, letterSpacing: 0.4, children: statusLabel(entry.fundingStatus) })
4593
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$1", fontWeight: "600", color: accent, letterSpacing: 0.4, children: statusLabel(entry.fundingStatus) })
3633
4594
  ] })
3634
4595
  ] }),
3635
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { alignItems: "flex-end", gap: "$0.5", flexShrink: 0, children: [
3636
- amounts?.primary ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$3", fontWeight: "700", color: amountColor, children: amounts.primary }) : null,
3637
- amounts?.secondary ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", fontWeight: "600", color: amountColor, children: amounts.secondary }) : null,
3638
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$1", secondary: true, children: formatEntryDate(entry.createdAt) })
4596
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { alignItems: "flex-end", gap: "$0.5", flexShrink: 0, children: [
4597
+ amounts?.primary ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$3", fontWeight: "700", color: amountColor, children: amounts.primary }) : null,
4598
+ amounts?.secondary ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$2", fontWeight: "600", color: amountColor, children: amounts.secondary }) : null,
4599
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$1", secondary: true, children: formatEntryDate(entry.createdAt) })
3639
4600
  ] })
3640
4601
  ]
3641
4602
  }
3642
4603
  ),
3643
- expanded && detailRows.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.YStack, { gap: "$1.5", paddingTop: "$1", children: detailRows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(EntryDetailRow, { label: row.label, value: row.value }, row.label)) }) : null
4604
+ expanded && detailRows.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.YStack, { gap: "$1.5", paddingTop: "$1", children: detailRows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(EntryDetailRow, { label: row.label, value: row.value }, row.label)) }) : null
3644
4605
  ] });
3645
4606
  }
3646
4607
  function SourceFilterChip({
@@ -3648,8 +4609,8 @@ function SourceFilterChip({
3648
4609
  selected,
3649
4610
  onPress
3650
4611
  }) {
3651
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3652
- import_ui13.XStack,
4612
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4613
+ import_ui12.XStack,
3653
4614
  {
3654
4615
  tag: "button",
3655
4616
  role: "checkbox",
@@ -3671,8 +4632,8 @@ function SourceFilterChip({
3671
4632
  },
3672
4633
  onPress,
3673
4634
  flexShrink: 0,
3674
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3675
- import_ui13.Text,
4635
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4636
+ import_ui12.Text,
3676
4637
  {
3677
4638
  fontSize: "$2",
3678
4639
  fontWeight: selected ? "700" : "500",
@@ -3688,11 +4649,11 @@ function StatusFilterSelect({
3688
4649
  value,
3689
4650
  onValueChange
3690
4651
  }) {
3691
- const [open, setOpen] = (0, import_react12.useState)(false);
4652
+ const [open, setOpen] = (0, import_react11.useState)(false);
3692
4653
  const selected = STATUS_OPTIONS.find((option) => option.value === value);
3693
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { flex: 1, minWidth: 0, position: "relative", zIndex: open ? 20 : 1, children: [
3694
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3695
- import_ui13.XStack,
4654
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { flex: 1, minWidth: 0, position: "relative", zIndex: open ? 20 : 1, children: [
4655
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
4656
+ import_ui12.XStack,
3696
4657
  {
3697
4658
  tag: "button",
3698
4659
  role: "combobox",
@@ -3708,16 +4669,16 @@ function StatusFilterSelect({
3708
4669
  cursor: "pointer",
3709
4670
  onPress: () => setOpen((current) => !current),
3710
4671
  children: [
3711
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$2", color: "$placeholderColor", numberOfLines: 1, flex: 1, children: [
4672
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.Text, { fontSize: "$2", color: "$placeholderColor", numberOfLines: 1, flex: 1, children: [
3712
4673
  "Status: ",
3713
4674
  selected?.label ?? "All"
3714
4675
  ] }),
3715
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Icon, { name: open ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
4676
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Icon, { name: open ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
3716
4677
  ]
3717
4678
  }
3718
4679
  ),
3719
- open ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3720
- import_ui13.YStack,
4680
+ open ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4681
+ import_ui12.YStack,
3721
4682
  {
3722
4683
  position: "absolute",
3723
4684
  top: "100%",
@@ -3730,8 +4691,93 @@ function StatusFilterSelect({
3730
4691
  backgroundColor: "$backgroundDark",
3731
4692
  overflow: "hidden",
3732
4693
  zIndex: 30,
3733
- children: STATUS_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3734
- import_ui13.XStack,
4694
+ children: STATUS_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4695
+ import_ui12.XStack,
4696
+ {
4697
+ tag: "button",
4698
+ role: "option",
4699
+ paddingHorizontal: "$3",
4700
+ paddingVertical: "$2",
4701
+ cursor: "pointer",
4702
+ backgroundColor: option.value === value ? "$infoMuted" : "transparent",
4703
+ hoverStyle: { backgroundColor: "$backgroundPress" },
4704
+ onPress: () => {
4705
+ onValueChange(option.value);
4706
+ setOpen(false);
4707
+ },
4708
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4709
+ import_ui12.Text,
4710
+ {
4711
+ fontSize: "$2",
4712
+ fontWeight: option.value === value ? "700" : "500",
4713
+ color: option.value === value ? "$primary" : "$color",
4714
+ children: option.label
4715
+ }
4716
+ )
4717
+ },
4718
+ option.value
4719
+ ))
4720
+ }
4721
+ ) : null
4722
+ ] });
4723
+ }
4724
+ function BuyerFilterSelect({
4725
+ value,
4726
+ buyers,
4727
+ onValueChange
4728
+ }) {
4729
+ const [open, setOpen] = (0, import_react11.useState)(false);
4730
+ if (buyers.length === 0) return null;
4731
+ const options = [
4732
+ { value: BUYER_FILTER_ALL, label: "All buyers" },
4733
+ ...buyers.map((b) => ({
4734
+ value: b.address,
4735
+ label: b.label ?? `${b.address.slice(0, 6)}\u2026${b.address.slice(-4)}`
4736
+ }))
4737
+ ];
4738
+ const selected = options.find((o) => o.value === value) ?? options[0];
4739
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { flex: 1, minWidth: 0, position: "relative", zIndex: open ? 25 : 1, children: [
4740
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
4741
+ import_ui12.XStack,
4742
+ {
4743
+ tag: "button",
4744
+ role: "listbox",
4745
+ height: "$7",
4746
+ alignItems: "center",
4747
+ justifyContent: "space-between",
4748
+ gap: "$2",
4749
+ paddingHorizontal: "$3",
4750
+ borderRadius: "$3",
4751
+ borderWidth: 1,
4752
+ borderColor: "$borderColor",
4753
+ backgroundColor: "$backgroundDark",
4754
+ cursor: "pointer",
4755
+ onPress: () => setOpen((current) => !current),
4756
+ children: [
4757
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.Text, { fontSize: "$2", color: "$placeholderColor", numberOfLines: 1, flex: 1, children: [
4758
+ "Buyer: ",
4759
+ selected?.label ?? "All buyers"
4760
+ ] }),
4761
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Icon, { name: open ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
4762
+ ]
4763
+ }
4764
+ ),
4765
+ open ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4766
+ import_ui12.YStack,
4767
+ {
4768
+ position: "absolute",
4769
+ top: "100%",
4770
+ left: 0,
4771
+ right: 0,
4772
+ marginTop: "$1",
4773
+ borderRadius: "$3",
4774
+ borderWidth: 1,
4775
+ borderColor: "$borderColor",
4776
+ backgroundColor: "$backgroundDark",
4777
+ overflow: "hidden",
4778
+ zIndex: 35,
4779
+ children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4780
+ import_ui12.XStack,
3735
4781
  {
3736
4782
  tag: "button",
3737
4783
  role: "option",
@@ -3744,8 +4790,8 @@ function StatusFilterSelect({
3744
4790
  onValueChange(option.value);
3745
4791
  setOpen(false);
3746
4792
  },
3747
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3748
- import_ui13.Text,
4793
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4794
+ import_ui12.Text,
3749
4795
  {
3750
4796
  fontSize: "$2",
3751
4797
  fontWeight: option.value === value ? "700" : "500",
@@ -3760,10 +4806,11 @@ function StatusFilterSelect({
3760
4806
  ) : null
3761
4807
  ] });
3762
4808
  }
3763
- function HistoryTab({ state, actions }) {
4809
+ function HistoryTab({ state, actions, knownBuyers = [] }) {
3764
4810
  const {
3765
4811
  selectedSources,
3766
4812
  statusFilter,
4813
+ buyerAddressFilter,
3767
4814
  fromDate,
3768
4815
  toDate,
3769
4816
  entries,
@@ -3773,26 +4820,26 @@ function HistoryTab({ state, actions }) {
3773
4820
  error,
3774
4821
  activeSources
3775
4822
  } = state;
3776
- const [expandedEntryId, setExpandedEntryId] = (0, import_react12.useState)(null);
3777
- const defaultRange = (0, import_react12.useMemo)(() => getLast90DaysRange(), []);
4823
+ const [expandedEntryId, setExpandedEntryId] = (0, import_react11.useState)(null);
4824
+ const defaultRange = (0, import_react11.useMemo)(() => getLast90DaysRange(), []);
3778
4825
  const isDefaultRange = fromDate === defaultRange.from && toDate === defaultRange.to;
3779
4826
  const rangeSummary = isDefaultRange ? `Last ${HISTORY_LOOKBACK_DAYS} days activity` : `${formatShortDate(fromDate)} \u2013 ${formatShortDate(toDate)}`;
3780
- const accumulatedG = (0, import_react12.useMemo)(
4827
+ const accumulatedG = (0, import_react11.useMemo)(
3781
4828
  () => formatAccumulatedG(sumFilteredGdWei(entries)),
3782
4829
  [entries]
3783
4830
  );
3784
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { gap: "$3", width: "100%", children: [
3785
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Card, { gap: "$3", children: [
3786
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.XStack, { alignItems: "flex-start", justifyContent: "space-between", gap: "$2", width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { flex: 1, gap: "$0.5", minWidth: 0, children: [
3787
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Heading, { level: 4, children: "AI Credit History" }),
3788
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$1", secondary: true, children: rangeSummary })
4831
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { gap: "$3", width: "100%", children: [
4832
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.Card, { gap: "$3", children: [
4833
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.XStack, { alignItems: "flex-start", justifyContent: "space-between", gap: "$2", width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { flex: 1, gap: "$0.5", minWidth: 0, children: [
4834
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Heading, { level: 4, children: "AI Credit History" }),
4835
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$1", secondary: true, children: rangeSummary })
3789
4836
  ] }) }),
3790
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { gap: "$1", children: [
3791
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$1", fontWeight: "600", secondary: true, letterSpacing: 0.6, children: "TOTAL ACCUMULATED" }),
3792
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$7", fontWeight: "700", color: "$color", children: accumulatedG })
4837
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { gap: "$1", children: [
4838
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$1", fontWeight: "600", secondary: true, letterSpacing: 0.6, children: "TOTAL ACCUMULATED" }),
4839
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$7", fontWeight: "700", color: "$color", children: accumulatedG })
3793
4840
  ] })
3794
4841
  ] }),
3795
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.XStack, { gap: "$2", flexWrap: "wrap", width: "100%", children: SOURCE_PILL_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
4842
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.XStack, { gap: "$2", flexWrap: "wrap", width: "100%", children: SOURCE_PILL_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3796
4843
  SourceFilterChip,
3797
4844
  {
3798
4845
  label: option.label,
@@ -3801,16 +4848,26 @@ function HistoryTab({ state, actions }) {
3801
4848
  },
3802
4849
  option.id
3803
4850
  )) }),
3804
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.XStack, { gap: "$2", alignItems: "center", width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3805
- StatusFilterSelect,
3806
- {
3807
- value: statusFilter,
3808
- onValueChange: actions.setStatusFilter
3809
- }
3810
- ) }),
3811
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.XStack, { gap: "$2", width: "100%", children: [
3812
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.YStack, { flex: 1, minWidth: 0, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3813
- import_ui13.Input,
4851
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.XStack, { gap: "$2", alignItems: "center", width: "100%", children: [
4852
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4853
+ StatusFilterSelect,
4854
+ {
4855
+ value: statusFilter,
4856
+ onValueChange: actions.setStatusFilter
4857
+ }
4858
+ ),
4859
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4860
+ BuyerFilterSelect,
4861
+ {
4862
+ value: buyerAddressFilter,
4863
+ buyers: knownBuyers,
4864
+ onValueChange: actions.setBuyerAddressFilter
4865
+ }
4866
+ )
4867
+ ] }),
4868
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.XStack, { gap: "$2", width: "100%", children: [
4869
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.YStack, { flex: 1, minWidth: 0, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4870
+ import_ui12.Input,
3814
4871
  {
3815
4872
  size: "sm",
3816
4873
  type: "date",
@@ -3819,8 +4876,8 @@ function HistoryTab({ state, actions }) {
3819
4876
  onChangeText: actions.setFromDate
3820
4877
  }
3821
4878
  ) }),
3822
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.YStack, { flex: 1, minWidth: 0, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3823
- import_ui13.Input,
4879
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.YStack, { flex: 1, minWidth: 0, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4880
+ import_ui12.Input,
3824
4881
  {
3825
4882
  size: "sm",
3826
4883
  type: "date",
@@ -3830,10 +4887,10 @@ function HistoryTab({ state, actions }) {
3830
4887
  }
3831
4888
  ) })
3832
4889
  ] }),
3833
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.XStack, { alignItems: "center", justifyContent: "space-between", gap: "$2", width: "100%", children: [
3834
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$1", fontWeight: "700", secondary: true, letterSpacing: 0.6, children: "CREDIT HISTORY" }),
3835
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3836
- import_ui13.XStack,
4890
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.XStack, { alignItems: "center", justifyContent: "space-between", gap: "$2", width: "100%", children: [
4891
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$1", fontWeight: "700", secondary: true, letterSpacing: 0.6, children: "CREDIT HISTORY" }),
4892
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4893
+ import_ui12.XStack,
3837
4894
  {
3838
4895
  tag: "button",
3839
4896
  backgroundColor: "transparent",
@@ -3847,17 +4904,17 @@ function HistoryTab({ state, actions }) {
3847
4904
  if (entries.length === 0) return;
3848
4905
  exportEntriesCsv(entries);
3849
4906
  },
3850
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", fontWeight: "600", color: "$primary", children: "Export CSV" })
4907
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$2", fontWeight: "600", color: "$primary", children: "Export CSV" })
3851
4908
  }
3852
4909
  )
3853
4910
  ] }),
3854
- loading ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Card, { gap: "$2", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { alignItems: "center", paddingVertical: "$4", gap: "$2", children: [
3855
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Spinner, { size: "sm" }),
3856
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", secondary: true, children: "Loading credit history\u2026" })
3857
- ] }) }) : error ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Card, { gap: "$2", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { gap: "$2", paddingVertical: "$2", children: [
3858
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { color: "$error", fontSize: "$2", children: error }),
3859
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3860
- import_ui13.Button,
4911
+ loading ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Card, { gap: "$2", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { alignItems: "center", paddingVertical: "$4", gap: "$2", children: [
4912
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Spinner, { size: "sm" }),
4913
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$2", secondary: true, children: "Loading credit history\u2026" })
4914
+ ] }) }) : error ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Card, { gap: "$2", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui12.YStack, { gap: "$2", paddingVertical: "$2", children: [
4915
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { color: "$error", fontSize: "$2", children: error }),
4916
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4917
+ import_ui12.Button,
3861
4918
  {
3862
4919
  variant: "outline",
3863
4920
  size: "sm",
@@ -3866,10 +4923,10 @@ function HistoryTab({ state, actions }) {
3866
4923
  onPress: () => {
3867
4924
  void actions.reload();
3868
4925
  },
3869
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.ButtonText, { children: "Retry" })
4926
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.ButtonText, { children: "Retry" })
3870
4927
  }
3871
4928
  )
3872
- ] }) }) : activeSources.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", secondary: true, children: "Select at least one source to view history." }) }) : entries.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", secondary: true, children: "No credit history matches these filters." }) }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.YStack, { gap: "$2", width: "100%", children: entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
4929
+ ] }) }) : activeSources.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$2", secondary: true, children: "Select at least one source to view history." }) }) : entries.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Text, { fontSize: "$2", secondary: true, children: "No credit history matches these filters." }) }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.YStack, { gap: "$2", width: "100%", children: entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3873
4930
  CreditHistoryEntryRow,
3874
4931
  {
3875
4932
  entry,
@@ -3878,8 +4935,8 @@ function HistoryTab({ state, actions }) {
3878
4935
  },
3879
4936
  entry.id
3880
4937
  )) }),
3881
- !loading && !error && hasMore && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3882
- import_ui13.Button,
4938
+ !loading && !error && hasMore && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
4939
+ import_ui12.Button,
3883
4940
  {
3884
4941
  variant: "outline",
3885
4942
  size: "sm",
@@ -3890,46 +4947,568 @@ function HistoryTab({ state, actions }) {
3890
4947
  void actions.loadMore();
3891
4948
  },
3892
4949
  children: [
3893
- loadingMore ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Spinner, { size: "sm" }) : null,
3894
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.ButtonText, { children: loadingMore ? "Loading\u2026" : "Load more" })
4950
+ loadingMore ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.Spinner, { size: "sm" }) : null,
4951
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui12.ButtonText, { children: loadingMore ? "Loading\u2026" : "Load more" })
3895
4952
  ]
3896
4953
  }
3897
4954
  )
3898
4955
  ] });
3899
4956
  }
3900
4957
 
3901
- // src/components/flow/purchaseFlowUtils.ts
3902
- function mapStatusToActiveStep(state, buyerPubKeySaved) {
3903
- if (state.operatorConsented) return "pay";
3904
- if (!state.buyerPubKey || !state.buyerPrvKey) return "buyer_key";
3905
- if (!buyerPubKeySaved) return "buyer_key";
3906
- if (!state.operatorConsented) return "consent";
3907
- if (state.status === "purchase_setup" || state.status === "quote_ready" || state.status === "payment_pending" || state.status === "payment_confirmed" || state.status === "payment_failed")
3908
- return "pay";
3909
- return null;
3910
- }
3911
- function getAiCreditsActiveFlowStep(state, buyerPubKeySaved) {
3912
- return mapStatusToActiveStep(state, buyerPubKeySaved);
3913
- }
3914
- function getActiveFlowStepActionLabel(state, step, buyerPubKeySaved) {
3915
- if (!step) return null;
3916
- switch (step) {
3917
- case "buyer_key":
3918
- if (!state.buyerPubKey) return "Sign & Generate Key";
3919
- if (!buyerPubKeySaved) return "Continue Buyer Key";
3920
- return "View Buyer Key";
3921
- case "consent":
3922
- return state.operatorConsented ? "View Operator Consent" : "Sign Operator Consent";
3923
- case "pay":
3924
- return "Set Amounts & Pay";
3925
- default:
4958
+ // src/components/setup/SetupGuidanceCard.tsx
4959
+ var import_ui14 = require("@goodwidget/ui");
4960
+
4961
+ // src/components/setup/SetupBonusHighlight.tsx
4962
+ var import_react12 = require("react");
4963
+ var import_ui13 = require("@goodwidget/ui");
4964
+ var import_jsx_runtime11 = require("react/jsx-runtime");
4965
+ function SetupBonusHighlight({
4966
+ depositBonusPercent,
4967
+ streamBonusPercent,
4968
+ isGoodIdVerified
4969
+ }) {
4970
+ const [isExpanded, setIsExpanded] = (0, import_react12.useState)(false);
4971
+ const maxBonusPercent = Math.max(depositBonusPercent, streamBonusPercent);
4972
+ if (maxBonusPercent <= 0) return null;
4973
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Card, { gap: "$2", padding: "$3", backgroundColor: "$backgroundHover", children: [
4974
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
4975
+ import_ui13.XStack,
4976
+ {
4977
+ gap: "$3",
4978
+ alignItems: "center",
4979
+ cursor: "pointer",
4980
+ accessibilityRole: "button",
4981
+ "aria-expanded": isExpanded,
4982
+ onPress: () => setIsExpanded((previous) => !previous),
4983
+ children: [
4984
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
4985
+ import_ui13.YStack,
4986
+ {
4987
+ width: 34,
4988
+ height: 34,
4989
+ borderRadius: "$2",
4990
+ backgroundColor: "$backgroundPress",
4991
+ alignItems: "center",
4992
+ justifyContent: "center",
4993
+ flexShrink: 0,
4994
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Icon, { name: "party-popper", size: "sm", color: "primary" })
4995
+ }
4996
+ ),
4997
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.YStack, { flex: 1, gap: 2, children: [
4998
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$3", fontWeight: "700", children: [
4999
+ "Up to ",
5000
+ maxBonusPercent,
5001
+ "% more AI credits"
5002
+ ] }),
5003
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$2", lineHeight: "$3", children: [
5004
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$2", fontWeight: "700", color: "$primary", children: [
5005
+ "+",
5006
+ depositBonusPercent,
5007
+ "%"
5008
+ ] }),
5009
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$2", secondary: true, children: [
5010
+ " ",
5011
+ "on deposits,",
5012
+ " "
5013
+ ] }),
5014
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$2", fontWeight: "700", color: "$primary", children: [
5015
+ "+",
5016
+ streamBonusPercent,
5017
+ "%"
5018
+ ] }),
5019
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_ui13.Text, { fontSize: "$2", secondary: true, children: [
5020
+ " ",
5021
+ "on streams \u2014 paid with G$"
5022
+ ] })
5023
+ ] })
5024
+ ] }),
5025
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Icon, { name: isExpanded ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
5026
+ ]
5027
+ }
5028
+ ),
5029
+ isExpanded && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.YStack, { backgroundColor: "$background", borderRadius: "$2", padding: "$3", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", secondary: true, lineHeight: "$3", children: isGoodIdVerified ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
5030
+ "Your wallet is",
5031
+ " ",
5032
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", fontWeight: "700", children: "GoodID verified" }),
5033
+ ", so the bonus is applied automatically to deposits and streams."
5034
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
5035
+ "Bonus applies to",
5036
+ " ",
5037
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_ui13.Text, { fontSize: "$2", fontWeight: "700", children: "verified GoodDollar wallets" }),
5038
+ " ",
5039
+ "only. Not verified? Claim UBI first via GoodWallet or GoodDapp \u2014 takes a minute, then this kicks in automatically."
5040
+ ] }) }) })
5041
+ ] });
5042
+ }
5043
+
5044
+ // src/components/setup/SetupGuidanceCard.tsx
5045
+ var import_jsx_runtime12 = require("react/jsx-runtime");
5046
+ var ANTSEED_SITE_URL = "https://antseed.com";
5047
+ function SetupGuidanceCard({
5048
+ onHowToUse,
5049
+ onFaq,
5050
+ activeHelpView,
5051
+ depositBonusPercent,
5052
+ streamBonusPercent,
5053
+ isGoodIdVerified
5054
+ }) {
5055
+ return (
5056
+ // Rendered flush on the widget background — no card surface, so it reads as
5057
+ // part of the header rather than a separate panel.
5058
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.YStack, { gap: "$3", paddingHorizontal: "$1", children: [
5059
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Text, { fontSize: "$3", secondary: true, lineHeight: "$4", children: "Buy AI credits with G$ for Claude Code, Codex, chat & other AI tools." }),
5060
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5061
+ SetupBonusHighlight,
5062
+ {
5063
+ depositBonusPercent,
5064
+ streamBonusPercent,
5065
+ isGoodIdVerified
5066
+ }
5067
+ ),
5068
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.YStack, { gap: "$1", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Text, { variant: "label", secondary: true, fontSize: "$1", fontWeight: "700", letterSpacing: 1, children: "WHAT'S INVOLVED:" }) }),
5069
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.YStack, { gap: "$3", children: [
5070
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.XStack, { gap: "$3", alignItems: "flex-start", children: [
5071
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5072
+ import_ui14.YStack,
5073
+ {
5074
+ width: 22,
5075
+ height: 22,
5076
+ borderRadius: "$full",
5077
+ backgroundColor: "$backgroundHover",
5078
+ alignItems: "center",
5079
+ justifyContent: "center",
5080
+ flexShrink: 0,
5081
+ marginTop: 2,
5082
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Text, { fontSize: "$1", fontWeight: "700", color: "$secondary", children: "1" })
5083
+ }
5084
+ ),
5085
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.Text, { fontSize: "$2", flex: 1, lineHeight: "$3", children: [
5086
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.Text, { fontSize: "$2", fontWeight: "700", children: [
5087
+ "Get G$",
5088
+ " "
5089
+ ] }),
5090
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Text, { fontSize: "$2", secondary: true, children: "\u2014 claim UBI via GoodWallet, or buy G$ with your wallet of choice" })
5091
+ ] })
5092
+ ] }),
5093
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.XStack, { gap: "$3", alignItems: "flex-start", children: [
5094
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5095
+ import_ui14.YStack,
5096
+ {
5097
+ width: 22,
5098
+ height: 22,
5099
+ borderRadius: "$full",
5100
+ backgroundColor: "$backgroundHover",
5101
+ alignItems: "center",
5102
+ justifyContent: "center",
5103
+ flexShrink: 0,
5104
+ marginTop: 2,
5105
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Text, { fontSize: "$1", fontWeight: "700", color: "$secondary", children: "2" })
5106
+ }
5107
+ ),
5108
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.Text, { fontSize: "$2", flex: 1, lineHeight: "$3", children: [
5109
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.Text, { fontSize: "$2", fontWeight: "700", children: [
5110
+ "Download Antseed",
5111
+ " "
5112
+ ] }),
5113
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Text, { fontSize: "$2", secondary: true, children: "\u2014 the free desktop app that runs your credits locally" })
5114
+ ] })
5115
+ ] })
5116
+ ] }),
5117
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Separator, {}),
5118
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_ui14.XStack, { gap: "$2", flexWrap: "wrap", children: [
5119
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5120
+ import_ui14.Button,
5121
+ {
5122
+ flexGrow: 1,
5123
+ flexBasis: "auto",
5124
+ size: "sm",
5125
+ variant: activeHelpView === "how-to-use" ? "default" : "outline",
5126
+ onPress: onHowToUse,
5127
+ borderRadius: "$3",
5128
+ paddingHorizontal: "$2",
5129
+ minWidth: 0,
5130
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.ButtonText, { numberOfLines: 1, children: "How to use" })
5131
+ }
5132
+ ),
5133
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5134
+ import_ui14.Anchor,
5135
+ {
5136
+ href: ANTSEED_SITE_URL,
5137
+ target: "_blank",
5138
+ style: { flexGrow: 1, flexBasis: "auto", textDecorationLine: "none", minWidth: 0 },
5139
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
5140
+ import_ui14.Button,
5141
+ {
5142
+ size: "sm",
5143
+ variant: "outline",
5144
+ width: "100%",
5145
+ borderRadius: "$3",
5146
+ paddingHorizontal: "$2",
5147
+ gap: "$1",
5148
+ children: [
5149
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.ButtonText, { numberOfLines: 1, children: "Antseed site" }),
5150
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Icon, { name: "external-link", size: "xs", color: "muted" })
5151
+ ]
5152
+ }
5153
+ )
5154
+ }
5155
+ ),
5156
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5157
+ import_ui14.Button,
5158
+ {
5159
+ flexGrow: 1,
5160
+ flexBasis: "auto",
5161
+ size: "sm",
5162
+ variant: activeHelpView === "faq" ? "default" : "outline",
5163
+ onPress: onFaq,
5164
+ borderRadius: "$3",
5165
+ paddingHorizontal: "$2",
5166
+ minWidth: 0,
5167
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.ButtonText, { numberOfLines: 1, children: "FAQs" })
5168
+ }
5169
+ )
5170
+ ] })
5171
+ ] })
5172
+ );
5173
+ }
5174
+
5175
+ // src/components/setup/HowToUseView.tsx
5176
+ var import_ui15 = require("@goodwidget/ui");
5177
+ var import_jsx_runtime13 = require("react/jsx-runtime");
5178
+ var VIDEO_URL = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
5179
+ var WRITTEN_GUIDE_URL = "https://app.notion.com/p/gooddollar/Full-Setup-Walkthrough-Widget-AntSeed-VPR-3c0f258232f08184bee9cd440cc93059";
5180
+ var QUICK_SUMMARY_STEPS = [
5181
+ {
5182
+ index: 1,
5183
+ title: "First, connect your wallet",
5184
+ tabLabel: "Buy",
5185
+ description: "Any wallet holding G$ works. Verified GoodDollar wallets get the bonus automatically."
5186
+ },
5187
+ {
5188
+ index: 2,
5189
+ title: "Then complete the one-time setup",
5190
+ tabLabel: "Buy",
5191
+ description: "Download Antseed, generate your signer key, and authorize your wallet \u2014 three quick taps."
5192
+ },
5193
+ {
5194
+ index: 3,
5195
+ title: "Head to Manage to buy or stream credits",
5196
+ tabLabel: "Manage",
5197
+ description: "Deposit once (+10%) or stream continuously (+20%), then confirm."
5198
+ },
5199
+ {
5200
+ index: 4,
5201
+ title: "Finally, connect Antseed to start using them",
5202
+ tabLabel: "Connect",
5203
+ description: 'Import your signer key \u2014 no separate "start" step, it just works from there.'
5204
+ }
5205
+ ];
5206
+ function HowToUseView({ onBack }) {
5207
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.YStack, { gap: "$4", children: [
5208
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.Button, { variant: "text", alignSelf: "flex-start", onPress: onBack, gap: "$1", children: [
5209
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Icon, { name: "arrow-left", size: "xs", color: "primary" }),
5210
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.ButtonText, { color: "$primary", fontSize: "$2", children: "Back to setup" })
5211
+ ] }),
5212
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$2", secondary: true, lineHeight: "$3", children: "New here? Start with the 3-minute video \u2014 it covers the whole journey, start to finish." }),
5213
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Anchor, { href: VIDEO_URL, target: "_blank", style: { textDecorationLine: "none" }, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
5214
+ import_ui15.Card,
5215
+ {
5216
+ backgroundColor: "$backgroundHover",
5217
+ gap: "$2",
5218
+ paddingVertical: "$4",
5219
+ paddingHorizontal: "$4",
5220
+ hoverStyle: { opacity: 0.9 },
5221
+ children: [
5222
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.XStack, { justifyContent: "flex-end", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Card, { backgroundColor: "$backgroundPress", paddingHorizontal: "$2", paddingVertical: 2, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$1", fontWeight: "700", children: "3:12" }) }) }),
5223
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.XStack, { justifyContent: "center", paddingVertical: "$6", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5224
+ import_ui15.YStack,
5225
+ {
5226
+ width: 56,
5227
+ height: 56,
5228
+ borderRadius: "$full",
5229
+ backgroundColor: "$background",
5230
+ alignItems: "center",
5231
+ justifyContent: "center",
5232
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Icon, { name: "play", size: "md", color: "primary" })
5233
+ }
5234
+ ) }),
5235
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.YStack, { gap: "$1", children: [
5236
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$2", fontWeight: "700", children: "Getting started with AI credits" }),
5237
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$1", secondary: true, children: "Wallet \u2192 buy credits \u2192 connect Antseed" })
5238
+ ] })
5239
+ ]
5240
+ }
5241
+ ) }),
5242
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Anchor, { href: WRITTEN_GUIDE_URL, target: "_blank", style: { textDecorationLine: "none" }, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Card, { backgroundColor: "$backgroundHover", paddingVertical: "$3", paddingHorizontal: "$4", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.XStack, { gap: "$3", alignItems: "center", justifyContent: "space-between", children: [
5243
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.XStack, { gap: "$3", alignItems: "center", flex: 1, children: [
5244
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Icon, { name: "file-text", size: "md", color: "muted" }),
5245
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.YStack, { flex: 1, gap: "$1", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.Text, { fontSize: "$2", lineHeight: "$3", children: [
5246
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.Text, { fontSize: "$2", fontWeight: "700", children: [
5247
+ "Full written guide",
5248
+ " "
5249
+ ] }),
5250
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$2", secondary: true, children: "Step-by-step walkthrough with screenshots, on Notion" })
5251
+ ] }) })
5252
+ ] }),
5253
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Icon, { name: "external-link", size: "xs", color: "muted" })
5254
+ ] }) }) }),
5255
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.YStack, { gap: "$3", children: [
5256
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { variant: "label", secondary: true, fontSize: "$1", fontWeight: "700", letterSpacing: 1, children: "QUICK SUMMARY" }),
5257
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.YStack, { gap: "$4", children: QUICK_SUMMARY_STEPS.map((step) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.XStack, { gap: "$3", alignItems: "flex-start", children: [
5258
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5259
+ import_ui15.YStack,
5260
+ {
5261
+ width: 24,
5262
+ height: 24,
5263
+ borderRadius: "$full",
5264
+ backgroundColor: "$backgroundHover",
5265
+ alignItems: "center",
5266
+ justifyContent: "center",
5267
+ flexShrink: 0,
5268
+ marginTop: 2,
5269
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$1", fontWeight: "700", color: "$secondary", children: step.index })
5270
+ }
5271
+ ),
5272
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.YStack, { flex: 1, gap: "$1", children: [
5273
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_ui15.XStack, { gap: "$2", alignItems: "center", flexWrap: "wrap", children: [
5274
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$2", fontWeight: "700", children: step.title }),
5275
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Badge, { size: "sm", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.BadgeText, { children: step.tabLabel }) })
5276
+ ] }),
5277
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$2", secondary: true, lineHeight: "$3", children: step.description })
5278
+ ] })
5279
+ ] }, step.index)) }),
5280
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.Text, { fontSize: "$1", secondary: true, textAlign: "center", paddingTop: "$1", children: "Your G$ wallet is never exposed \u2014 only the scoped signer key." })
5281
+ ] })
5282
+ ] });
5283
+ }
5284
+
5285
+ // src/components/setup/SetupFaqView.tsx
5286
+ var import_react13 = require("react");
5287
+ var import_ui16 = require("@goodwidget/ui");
5288
+ var import_jsx_runtime14 = require("react/jsx-runtime");
5289
+ var SETUP_FAQ_ITEMS = [
5290
+ {
5291
+ id: "goodwallet-only",
5292
+ question: "I only claim UBI with GoodWallet \u2014 can I still use this?",
5293
+ 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."
5294
+ },
5295
+ {
5296
+ id: "ubi-savings",
5297
+ question: "Will this ever touch my daily UBI savings?",
5298
+ 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."
5299
+ },
5300
+ {
5301
+ id: "deposit-vs-stream",
5302
+ question: "Deposit or stream \u2014 which should I pick?",
5303
+ 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."
5304
+ },
5305
+ {
5306
+ id: "lost-signer-key",
5307
+ question: "What if I lose my signer key?",
5308
+ 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.'
5309
+ },
5310
+ {
5311
+ id: "no-code",
5312
+ question: "Do I need to know how to code?",
5313
+ 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."
5314
+ },
5315
+ {
5316
+ id: "unused-credits",
5317
+ question: "Can I get unused credits back?",
5318
+ 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."
5319
+ },
5320
+ {
5321
+ id: "compatible-tools",
5322
+ question: "Which tools can I actually use my credits with?",
5323
+ 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."
5324
+ },
5325
+ {
5326
+ id: "antseed-safe",
5327
+ question: "Is Antseed safe? Can I check it myself?",
5328
+ 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."
5329
+ }
5330
+ ];
5331
+ function FaqItem({ question, answer, expanded, onToggle }) {
5332
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$1", children: [
5333
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
5334
+ import_ui16.XStack,
5335
+ {
5336
+ justifyContent: "space-between",
5337
+ alignItems: "center",
5338
+ gap: "$2",
5339
+ onPress: onToggle,
5340
+ cursor: "pointer",
5341
+ children: [
5342
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { fontSize: "$2", fontWeight: "600", flex: 1, children: question }),
5343
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Icon, { name: expanded ? "chevron-up" : "chevron-down", size: "xs", color: "muted" })
5344
+ ]
5345
+ }
5346
+ ),
5347
+ expanded && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { fontSize: "$2", secondary: true, lineHeight: "$3", children: answer })
5348
+ ] });
5349
+ }
5350
+ function SetupFaqView({ onBack }) {
5351
+ const [expandedId, setExpandedId] = (0, import_react13.useState)(null);
5352
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$4", children: [
5353
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.Button, { variant: "text", alignSelf: "flex-start", onPress: onBack, gap: "$1", children: [
5354
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Icon, { name: "arrow-left", size: "xs", color: "primary" }),
5355
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.ButtonText, { color: "$primary", fontSize: "$2", children: "Back to setup" })
5356
+ ] }),
5357
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Card, { gap: "$3", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.YStack, { gap: "$3", children: SETUP_FAQ_ITEMS.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$3", children: [
5358
+ index > 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Separator, {}),
5359
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5360
+ FaqItem,
5361
+ {
5362
+ question: item.question,
5363
+ answer: item.answer,
5364
+ expanded: expandedId === item.id,
5365
+ onToggle: () => {
5366
+ setExpandedId((current) => current === item.id ? null : item.id);
5367
+ }
5368
+ }
5369
+ )
5370
+ ] }, item.id)) }) })
5371
+ ] });
5372
+ }
5373
+
5374
+ // src/components/setup/SetupOnboardingFlow.tsx
5375
+ var import_react14 = require("react");
5376
+ var import_ui17 = require("@goodwidget/ui");
5377
+ var import_jsx_runtime15 = require("react/jsx-runtime");
5378
+ var ANTSEED_DOWNLOAD_URL = "https://antseed.com";
5379
+ function SetupOnboardingFlow({ state, actions }) {
5380
+ const [downloadOpened, setDownloadOpened] = (0, import_react14.useState)(false);
5381
+ const [drawerOpen, setDrawerOpen] = (0, import_react14.useState)(false);
5382
+ const [drawerStep, setDrawerStep] = (0, import_react14.useState)(null);
5383
+ const hasSignerKey = Boolean(state.buyerPubKey);
5384
+ const downloadCompleted = downloadOpened || hasSignerKey;
5385
+ const steps = [
5386
+ {
5387
+ id: "download",
5388
+ title: "Download Antseed",
5389
+ description: "The app that runs your credits locally \u2014 required once",
5390
+ status: downloadCompleted ? "completed" : "ready"
5391
+ },
5392
+ {
5393
+ id: "signer",
5394
+ title: "Signer key",
5395
+ description: "Generate or import \u2014 separate from your wallet",
5396
+ status: !downloadCompleted ? "pending" : hasSignerKey ? "completed" : "ready"
5397
+ },
5398
+ {
5399
+ id: "authorize",
5400
+ title: "Authorize Wallet",
5401
+ description: "One-time permission \u2014 scoped to Base credits",
5402
+ status: !hasSignerKey ? "pending" : state.operatorConsented ? "completed" : "ready"
5403
+ }
5404
+ ];
5405
+ const openSignerDrawer = (0, import_react14.useCallback)(() => {
5406
+ setDrawerStep("signer");
5407
+ setDrawerOpen(true);
5408
+ }, []);
5409
+ const handleSignerReady = (0, import_react14.useCallback)(() => {
5410
+ if (state.operatorConsented) {
5411
+ setDrawerOpen(false);
5412
+ setDrawerStep(null);
5413
+ return;
5414
+ }
5415
+ setDrawerStep("authorize");
5416
+ }, [state.operatorConsented]);
5417
+ const handleStepPress = (0, import_react14.useCallback)(
5418
+ (stepId) => {
5419
+ if (stepId === "download") {
5420
+ if (typeof window !== "undefined") {
5421
+ window.open(ANTSEED_DOWNLOAD_URL, "_blank", "noopener,noreferrer");
5422
+ }
5423
+ setDownloadOpened(true);
5424
+ return;
5425
+ }
5426
+ if (stepId === "signer" && downloadCompleted) {
5427
+ openSignerDrawer();
5428
+ }
5429
+ if (stepId === "authorize" && hasSignerKey) {
5430
+ setDrawerStep("authorize");
5431
+ setDrawerOpen(true);
5432
+ }
5433
+ },
5434
+ [downloadCompleted, hasSignerKey, openSignerDrawer]
5435
+ );
5436
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
5437
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5438
+ import_ui17.Stepper,
5439
+ {
5440
+ steps,
5441
+ activeStepId: downloadCompleted ? hasSignerKey ? "authorize" : "signer" : "download",
5442
+ onStepPress: handleStepPress
5443
+ }
5444
+ ),
5445
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5446
+ import_ui17.Drawer,
5447
+ {
5448
+ open: drawerOpen && drawerStep !== null,
5449
+ onClose: () => {
5450
+ setDrawerOpen(false);
5451
+ setDrawerStep(null);
5452
+ },
5453
+ height: "full",
5454
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_ui17.ScrollArea, { width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_ui17.YStack, { gap: "$3", paddingBottom: "$4", width: "100%", children: [
5455
+ drawerStep === "signer" ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SignerKeyPanel, { state, actions, onProceed: handleSignerReady }) : null,
5456
+ drawerStep === "authorize" ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5457
+ OperatorConsentStep,
5458
+ {
5459
+ embedded: true,
5460
+ buyerPubKey: state.buyerPubKey,
5461
+ buyerPrvKey: state.buyerPrvKey ?? null,
5462
+ operatorSignature: state.operatorSignature ?? null,
5463
+ operatorConsented: state.operatorConsented,
5464
+ operatorConsentPending: state.operatorConsentPending,
5465
+ onSign: actions.signOperatorConsent
5466
+ }
5467
+ ) : null
5468
+ ] }) })
5469
+ }
5470
+ )
5471
+ ] });
5472
+ }
5473
+
5474
+ // src/components/flow/purchaseFlowUtils.ts
5475
+ function isSelectedDerivedBuyer(state) {
5476
+ if (!state.buyerPubKey || !state.derivedBuyerAddress) return false;
5477
+ return state.buyerPubKey.toLowerCase() === state.derivedBuyerAddress.toLowerCase();
5478
+ }
5479
+ function mapStatusToActiveStep(state, buyerPubKeySaved) {
5480
+ if (state.operatorConsented) return "pay";
5481
+ if (!state.buyerPubKey) return "buyer_key";
5482
+ if (!state.buyerPrvKey && !state.operatorSignature) return "buyer_key";
5483
+ if (isSelectedDerivedBuyer(state) && state.buyerPrvKey && !buyerPubKeySaved) return "buyer_key";
5484
+ if (!state.operatorConsented) return "consent";
5485
+ if (state.status === "purchase_setup" || state.status === "quote_ready" || state.status === "payment_pending" || state.status === "payment_confirmed" || state.status === "payment_failed")
5486
+ return "pay";
5487
+ return null;
5488
+ }
5489
+ function getAiCreditsActiveFlowStep(state, buyerPubKeySaved) {
5490
+ return mapStatusToActiveStep(state, buyerPubKeySaved);
5491
+ }
5492
+ function getActiveFlowStepActionLabel(state, step, buyerPubKeySaved) {
5493
+ if (!step) return null;
5494
+ switch (step) {
5495
+ case "buyer_key":
5496
+ if (!state.buyerPubKey) return "Sign & Generate Key";
5497
+ if (!buyerPubKeySaved) return "Continue Signer Key";
5498
+ return "View Signer Key";
5499
+ case "consent":
5500
+ if (state.operatorConsentPending) return "Submitting Authorization\u2026";
5501
+ return state.operatorConsented ? "View Authorization" : "Authorize Wallet";
5502
+ case "pay":
5503
+ return "Set Amounts & Pay";
5504
+ default:
3926
5505
  return null;
3927
5506
  }
3928
5507
  }
3929
5508
 
3930
5509
  // src/components/flow/AiCreditsFlowStepper.tsx
3931
- var import_ui14 = require("@goodwidget/ui");
3932
- var import_jsx_runtime12 = require("react/jsx-runtime");
5510
+ var import_ui18 = require("@goodwidget/ui");
5511
+ var import_jsx_runtime16 = require("react/jsx-runtime");
3933
5512
  var STEP_ORDER = ["buyer_key", "consent", "pay"];
3934
5513
  function AiCreditsFlowStepper({
3935
5514
  state,
@@ -3948,19 +5527,20 @@ function AiCreditsFlowStepper({
3948
5527
  if (step === "pay" && (state.status === "payment_pending" || state.status === "payment_confirmed")) {
3949
5528
  return "active";
3950
5529
  }
5530
+ if (step === "consent" && state.operatorConsentPending) return "active";
3951
5531
  return "ready";
3952
5532
  }
3953
5533
  const steps = [
3954
5534
  {
3955
5535
  id: "buyer_key",
3956
- title: "Buyer Key",
3957
- description: "Generate or provide your AI credits buyer key",
5536
+ title: "Signer Key",
5537
+ description: "Generate or import your AI credits signer key",
3958
5538
  status: getStepStatus("buyer_key")
3959
5539
  },
3960
5540
  {
3961
5541
  id: "consent",
3962
- title: "Operator Consent",
3963
- description: "Sign permission for the AntseedBuyerOperator",
5542
+ title: "Authorize Wallet",
5543
+ description: state.operatorConsentPending ? "Submitting authorization\u2026" : "Authorize GoodDollar to manage your Base credits",
3964
5544
  status: getStepStatus("consent")
3965
5545
  },
3966
5546
  {
@@ -3975,42 +5555,42 @@ function AiCreditsFlowStepper({
3975
5555
  if (!step || step.status === "completed" || step.status === "pending") return;
3976
5556
  onStepPress?.(stepId);
3977
5557
  }
3978
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3979
- import_ui14.Stepper,
5558
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
5559
+ import_ui18.Stepper,
3980
5560
  {
3981
5561
  steps,
3982
5562
  activeStepId: activeStep,
3983
5563
  onStepPress: onStepPress ? handleStepPress : void 0,
3984
- header: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_ui14.Heading, { level: 5, secondary: true, children: "Purchase Flow" })
5564
+ header: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_ui18.Heading, { level: 5, secondary: true, children: "Purchase Flow" })
3985
5565
  }
3986
5566
  );
3987
5567
  }
3988
5568
 
3989
5569
  // src/components/flow/AiCreditsPurchaseFlow.tsx
3990
- var import_react13 = require("react");
3991
- var import_ui15 = require("@goodwidget/ui");
3992
- var import_jsx_runtime13 = require("react/jsx-runtime");
5570
+ var import_react15 = require("react");
5571
+ var import_ui19 = require("@goodwidget/ui");
5572
+ var import_jsx_runtime17 = require("react/jsx-runtime");
3993
5573
  function AiCreditsPurchaseFlow({
3994
5574
  state,
3995
5575
  actions,
3996
5576
  isPending,
3997
5577
  onPay
3998
5578
  }) {
3999
- const [buyerPubKeySaved, setBuyerPubKeySaved] = (0, import_react13.useState)(false);
5579
+ const [buyerPubKeySaved, setBuyerPubKeySaved] = (0, import_react15.useState)(false);
4000
5580
  const activeStep = getAiCreditsActiveFlowStep(state, buyerPubKeySaved);
4001
- const [drawerOpen, setDrawerOpen] = (0, import_react13.useState)(false);
4002
- const [drawerStep, setDrawerStep] = (0, import_react13.useState)(activeStep);
4003
- const prevActiveStepRef = (0, import_react13.useRef)(null);
4004
- const goodIdTabPendingRef = (0, import_react13.useRef)(false);
4005
- (0, import_react13.useEffect)(() => {
5581
+ const [drawerOpen, setDrawerOpen] = (0, import_react15.useState)(false);
5582
+ const [drawerStep, setDrawerStep] = (0, import_react15.useState)(null);
5583
+ const prevActiveStepRef = (0, import_react15.useRef)(null);
5584
+ const goodIdTabPendingRef = (0, import_react15.useRef)(false);
5585
+ (0, import_react15.useEffect)(() => {
4006
5586
  setBuyerPubKeySaved(false);
4007
5587
  }, [state.buyerPubKey]);
4008
- (0, import_react13.useEffect)(() => {
5588
+ (0, import_react15.useEffect)(() => {
4009
5589
  if (activeStep !== "consent" || state.operatorConsented) return;
4010
5590
  if (!state.address || !state.buyerPubKey) return;
4011
5591
  void actions.syncOperatorConsentFromChain();
4012
5592
  }, [activeStep, state.operatorConsented, state.address, state.buyerPubKey, actions]);
4013
- (0, import_react13.useEffect)(() => {
5593
+ (0, import_react15.useEffect)(() => {
4014
5594
  if (!activeStep) {
4015
5595
  setDrawerOpen(false);
4016
5596
  setDrawerStep(null);
@@ -4019,14 +5599,12 @@ function AiCreditsPurchaseFlow({
4019
5599
  }
4020
5600
  const previousStep = prevActiveStepRef.current;
4021
5601
  prevActiveStepRef.current = activeStep;
4022
- setDrawerStep(activeStep);
4023
- if (previousStep == null) {
4024
- setDrawerOpen(false);
4025
- } else if (previousStep !== activeStep) {
5602
+ if (previousStep != null && previousStep !== activeStep) {
5603
+ setDrawerStep(activeStep);
4026
5604
  setDrawerOpen(true);
4027
5605
  }
4028
5606
  }, [activeStep]);
4029
- (0, import_react13.useEffect)(() => {
5607
+ (0, import_react15.useEffect)(() => {
4030
5608
  if (typeof window === "undefined") return;
4031
5609
  const onFocus = () => {
4032
5610
  if (!goodIdTabPendingRef.current) return;
@@ -4039,7 +5617,7 @@ function AiCreditsPurchaseFlow({
4039
5617
  window.addEventListener("focus", onFocus);
4040
5618
  return () => window.removeEventListener("focus", onFocus);
4041
5619
  }, [activeStep]);
4042
- const handleVerifyGoodId = (0, import_react13.useCallback)(async () => {
5620
+ const handleVerifyGoodId = (0, import_react15.useCallback)(async () => {
4043
5621
  try {
4044
5622
  const started = await actions.verifyGoodId();
4045
5623
  if (started) {
@@ -4052,7 +5630,7 @@ function AiCreditsPurchaseFlow({
4052
5630
  }
4053
5631
  }
4054
5632
  }, [actions, activeStep]);
4055
- const openDrawer = (0, import_react13.useCallback)(
5633
+ const openDrawer = (0, import_react15.useCallback)(
4056
5634
  (step) => {
4057
5635
  if (step !== activeStep && !(step === "pay" && state.status === "payment_failed")) return;
4058
5636
  setDrawerStep(step);
@@ -4060,7 +5638,7 @@ function AiCreditsPurchaseFlow({
4060
5638
  },
4061
5639
  [activeStep, state.status]
4062
5640
  );
4063
- const handleStepPress = (0, import_react13.useCallback)(
5641
+ const handleStepPress = (0, import_react15.useCallback)(
4064
5642
  (stepId) => {
4065
5643
  openDrawer(stepId);
4066
5644
  },
@@ -4071,7 +5649,7 @@ function AiCreditsPurchaseFlow({
4071
5649
  if (!step) return null;
4072
5650
  switch (step) {
4073
5651
  case "buyer_key":
4074
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5652
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4075
5653
  BuyerKeyPanel,
4076
5654
  {
4077
5655
  embedded: true,
@@ -4083,18 +5661,20 @@ function AiCreditsPurchaseFlow({
4083
5661
  }
4084
5662
  );
4085
5663
  case "consent":
4086
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5664
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4087
5665
  OperatorConsentStep,
4088
5666
  {
4089
5667
  embedded: true,
4090
5668
  buyerPubKey: state.buyerPubKey,
4091
5669
  buyerPrvKey: state.buyerPrvKey ?? null,
5670
+ operatorSignature: state.operatorSignature ?? null,
4092
5671
  operatorConsented: state.operatorConsented,
5672
+ operatorConsentPending: state.operatorConsentPending,
4093
5673
  onSign: actions.signOperatorConsent
4094
5674
  }
4095
5675
  );
4096
5676
  case "pay":
4097
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5677
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4098
5678
  AmountPicker,
4099
5679
  {
4100
5680
  embedded: true,
@@ -4117,8 +5697,8 @@ function AiCreditsPurchaseFlow({
4117
5697
  return null;
4118
5698
  }
4119
5699
  }
4120
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
4121
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5700
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
5701
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4122
5702
  AiCreditsFlowStepper,
4123
5703
  {
4124
5704
  state,
@@ -4126,8 +5706,8 @@ function AiCreditsPurchaseFlow({
4126
5706
  onStepPress: handleStepPress
4127
5707
  }
4128
5708
  ),
4129
- !drawerOpen && actionLabel && activeStep && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4130
- import_ui15.Button,
5709
+ !drawerOpen && actionLabel && activeStep && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
5710
+ import_ui19.Button,
4131
5711
  {
4132
5712
  fullWidth: true,
4133
5713
  size: "sm",
@@ -4135,34 +5715,137 @@ function AiCreditsPurchaseFlow({
4135
5715
  onPress: () => {
4136
5716
  openDrawer(activeStep);
4137
5717
  },
4138
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.ButtonText, { children: actionLabel })
5718
+ children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_ui19.ButtonText, { children: actionLabel })
4139
5719
  }
4140
5720
  ),
4141
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4142
- import_ui15.Drawer,
5721
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
5722
+ import_ui19.Drawer,
4143
5723
  {
4144
5724
  open: drawerOpen && drawerStep !== null,
4145
5725
  onClose: () => {
4146
5726
  setDrawerOpen(false);
4147
5727
  },
4148
5728
  height: "full",
4149
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.ScrollArea, { width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui15.YStack, { gap: "$3", paddingBottom: "$4", width: "100%", children: renderDrawerContent(drawerStep) }) })
5729
+ children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_ui19.ScrollArea, { width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_ui19.YStack, { gap: "$3", paddingBottom: "$4", width: "100%", children: renderDrawerContent(drawerStep) }) })
4150
5730
  }
4151
5731
  )
4152
5732
  ] });
4153
5733
  }
4154
5734
 
5735
+ // src/components/shared/WalletChip.tsx
5736
+ var import_react16 = require("react");
5737
+ var import_ui20 = require("@goodwidget/ui");
5738
+ var import_jsx_runtime18 = require("react/jsx-runtime");
5739
+ function shortAddress2(address) {
5740
+ return `${address.slice(0, 5)}\u2026${address.slice(-3)}`;
5741
+ }
5742
+ function WalletChip({
5743
+ address,
5744
+ onDisconnect,
5745
+ disconnectLabel = "Disconnect",
5746
+ disconnectIcon = "log-out",
5747
+ disabled = false
5748
+ }) {
5749
+ const [isMenuOpen, setIsMenuOpen] = (0, import_react16.useState)(false);
5750
+ const [disconnectMessage, setDisconnectMessage] = (0, import_react16.useState)(null);
5751
+ (0, import_react16.useEffect)(() => {
5752
+ if (disabled) setIsMenuOpen(false);
5753
+ }, [disabled]);
5754
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_ui20.XStack, { position: "relative", alignItems: "center", opacity: disabled ? 0.5 : 1, children: [
5755
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
5756
+ import_ui20.XStack,
5757
+ {
5758
+ gap: "$1.5",
5759
+ alignItems: "center",
5760
+ paddingHorizontal: "$2",
5761
+ paddingVertical: "$1",
5762
+ borderRadius: "$full",
5763
+ borderWidth: 1,
5764
+ borderColor: "$borderColor",
5765
+ cursor: disabled ? "not-allowed" : "pointer",
5766
+ onPress: () => {
5767
+ if (disabled) return;
5768
+ setDisconnectMessage(null);
5769
+ setIsMenuOpen((open) => !open);
5770
+ },
5771
+ "aria-label": "Wallet options",
5772
+ "aria-disabled": disabled,
5773
+ children: [
5774
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui20.YStack, { width: 6, height: 6, borderRadius: "$full", backgroundColor: "$success" }),
5775
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui20.Text, { fontSize: "$1", numberOfLines: 1, children: address ? shortAddress2(address) : "" }),
5776
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui20.Icon, { name: "chevron-down", size: "2xs", color: "muted" })
5777
+ ]
5778
+ }
5779
+ ),
5780
+ isMenuOpen && !disabled && /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
5781
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
5782
+ import_ui20.XStack,
5783
+ {
5784
+ position: "fixed",
5785
+ top: 0,
5786
+ left: 0,
5787
+ right: 0,
5788
+ bottom: 0,
5789
+ zIndex: 100,
5790
+ onPress: () => setIsMenuOpen(false)
5791
+ }
5792
+ ),
5793
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
5794
+ import_ui20.YStack,
5795
+ {
5796
+ position: "absolute",
5797
+ top: "100%",
5798
+ right: 0,
5799
+ marginTop: "$1",
5800
+ backgroundColor: "$background",
5801
+ borderWidth: 1,
5802
+ borderColor: "$borderColor",
5803
+ borderRadius: "$3",
5804
+ padding: "$1",
5805
+ minWidth: 132,
5806
+ zIndex: 101,
5807
+ children: [
5808
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
5809
+ import_ui20.Button,
5810
+ {
5811
+ size: "sm",
5812
+ variant: "list",
5813
+ height: "$6",
5814
+ paddingHorizontal: "$2",
5815
+ gap: "$1.5",
5816
+ onPress: async () => {
5817
+ if (!onDisconnect) {
5818
+ setDisconnectMessage("Disconnect should be done in your wallet's session");
5819
+ return;
5820
+ }
5821
+ setIsMenuOpen(false);
5822
+ await onDisconnect();
5823
+ },
5824
+ children: [
5825
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui20.Icon, { name: disconnectIcon, size: "xs", color: "muted" }),
5826
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui20.ButtonText, { fontSize: "$2", children: disconnectLabel })
5827
+ ]
5828
+ }
5829
+ ),
5830
+ disconnectMessage && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui20.Text, { variant: "caption", tone: "secondary", padding: "$2", children: disconnectMessage })
5831
+ ]
5832
+ }
5833
+ )
5834
+ ] })
5835
+ ] });
5836
+ }
5837
+
4155
5838
  // src/AiCreditsWidget.tsx
4156
- var import_jsx_runtime14 = require("react/jsx-runtime");
5839
+ var import_jsx_runtime19 = require("react/jsx-runtime");
4157
5840
  var CELO_CHAIN_ID3 = 42220;
4158
- function DisconnectedPanel({
5841
+ function SetupConnectPrompt({
4159
5842
  onConnect,
4160
5843
  connecting
4161
5844
  }) {
4162
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$5", paddingVertical: "$6", alignItems: "center", children: [
4163
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: "Connect your wallet to buy AI credits" }),
4164
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4165
- import_ui16.CircularActionButton,
5845
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { gap: "$5", alignItems: "center", paddingVertical: "$6", width: "100%", children: [
5846
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, center: true, children: "Connect your wallet to get started" }),
5847
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
5848
+ import_ui21.CircularActionButton,
4166
5849
  {
4167
5850
  label: connecting ? "Connecting..." : "Connect Wallet",
4168
5851
  pending: connecting,
@@ -4172,31 +5855,57 @@ function DisconnectedPanel({
4172
5855
  }
4173
5856
  }
4174
5857
  )
4175
- ] }) });
5858
+ ] });
5859
+ }
5860
+ function SetupTabPanel({
5861
+ state,
5862
+ actions,
5863
+ onConnect
5864
+ }) {
5865
+ if (needsWalletConnection(state)) {
5866
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
5867
+ SetupConnectPrompt,
5868
+ {
5869
+ onConnect,
5870
+ connecting: state.status === "connecting"
5871
+ }
5872
+ );
5873
+ }
5874
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { gap: "$4", width: "100%", children: [
5875
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
5876
+ AiCreditsHero,
5877
+ {
5878
+ gBalance: state.gBalance,
5879
+ isGoodIdVerified: state.isGoodIdVerified
5880
+ }
5881
+ ),
5882
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, fontSize: "$2", children: "One-time setup, in order \u2014 each step unlocks the next:" }),
5883
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SetupOnboardingFlow, { state, actions })
5884
+ ] });
4176
5885
  }
4177
5886
  function BuyCreditsPanel({ state, actions, isPending, onPay }) {
4178
5887
  let content;
4179
5888
  if (state.status === "unsupported_chain") {
4180
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(AiCreditsStatusNotice, { children: [
4181
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.XStack, { gap: "$2", alignItems: "center", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$warning", fontWeight: "700", children: "Wrong Network" }) }),
4182
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: "Please switch to the Celo network to continue." }),
4183
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4184
- import_ui16.Button,
5889
+ content = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(AiCreditsStatusNotice, { children: [
5890
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.XStack, { gap: "$2", alignItems: "center", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$warning", fontWeight: "700", children: "Wrong Network" }) }),
5891
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: "Please switch to the Celo network to continue." }),
5892
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
5893
+ import_ui21.Button,
4185
5894
  {
4186
5895
  onPress: () => {
4187
5896
  void actions.switchChain();
4188
5897
  },
4189
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.ButtonText, { children: "Switch to Celo" })
5898
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.ButtonText, { children: "Switch to Celo" })
4190
5899
  }
4191
5900
  )
4192
5901
  ] });
4193
5902
  } else if (state.status === "payment_failed") {
4194
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
4195
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(AiCreditsStatusNotice, { children: [
4196
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$error", fontWeight: "700", children: "Payment Failed" }),
4197
- state.error && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: state.error })
5903
+ content = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
5904
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(AiCreditsStatusNotice, { children: [
5905
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$error", fontWeight: "700", children: "Payment Failed" }),
5906
+ state.error && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: state.error })
4198
5907
  ] }),
4199
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5908
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4200
5909
  AiCreditsPurchaseFlow,
4201
5910
  {
4202
5911
  state,
@@ -4207,57 +5916,61 @@ function BuyCreditsPanel({ state, actions, isPending, onPay }) {
4207
5916
  )
4208
5917
  ] });
4209
5918
  } else if (state.status === "backend_unavailable") {
4210
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(AiCreditsStatusNotice, { children: [
4211
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$warning", fontWeight: "700", children: "Service Unavailable" }),
4212
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: "The AI credits service is temporarily unavailable. Your wallet has not been charged." }),
4213
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4214
- import_ui16.Button,
5919
+ content = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(AiCreditsStatusNotice, { children: [
5920
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$warning", fontWeight: "700", children: "Service Unavailable" }),
5921
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: "The AI credits service is temporarily unavailable. Your wallet has not been charged." }),
5922
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
5923
+ import_ui21.Button,
4215
5924
  {
4216
5925
  onPress: () => {
4217
5926
  void actions.retry();
4218
5927
  },
4219
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.ButtonText, { children: "Retry" })
5928
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.ButtonText, { children: "Retry" })
4220
5929
  }
4221
5930
  )
4222
5931
  ] });
4223
5932
  } else if (state.status === "insufficient_g_balance") {
4224
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
4225
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5933
+ content = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
5934
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4226
5935
  AiCreditsHero,
4227
5936
  {
4228
5937
  gBalance: state.gBalance,
4229
5938
  isGoodIdVerified: state.isGoodIdVerified
4230
5939
  }
4231
5940
  ),
4232
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(AiCreditsStatusNotice, { children: [
4233
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$warning", fontWeight: "700", children: "Insufficient G$ Balance" }),
4234
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: "You need at least 1 G$ to purchase AI credits. Top up your wallet and try again." })
5941
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(AiCreditsStatusNotice, { children: [
5942
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$warning", fontWeight: "700", children: "Insufficient G$ Balance" }),
5943
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: "You need at least 1 G$ to purchase AI credits. Top up your wallet and try again." })
4235
5944
  ] })
4236
5945
  ] });
4237
5946
  } else if (state.status === "payment_pending" || state.status === "payment_confirmed") {
4238
5947
  const message = state.status === "payment_pending" ? "Transaction submitted \u2014 waiting for confirmation\u2026" : "Payment confirmed \u2014 settling credits on Base\u2026";
4239
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
4240
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$4", alignItems: "center", padding: "$4", children: [
4241
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Spinner, { size: "lg" }),
4242
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { center: true, secondary: true, children: message })
5948
+ content = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
5949
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { gap: "$4", alignItems: "center", padding: "$4", children: [
5950
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Spinner, { size: "lg" }),
5951
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { center: true, secondary: true, children: message })
4243
5952
  ] }) }),
4244
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(AiCreditsFlowStepper, { state, buyerPubKeySaved: true })
5953
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(AiCreditsFlowStepper, { state, buyerPubKeySaved: true })
4245
5954
  ] });
4246
5955
  } else {
4247
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
4248
- state.address && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5956
+ content = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
5957
+ state.error && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(AiCreditsStatusNotice, { children: [
5958
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$error", fontWeight: "700", children: "Deep link unavailable" }),
5959
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: state.error })
5960
+ ] }),
5961
+ state.address && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4249
5962
  AiCreditsHero,
4250
5963
  {
4251
5964
  gBalance: state.gBalance,
4252
5965
  isGoodIdVerified: state.isGoodIdVerified
4253
5966
  }
4254
5967
  ),
4255
- state.error && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(AiCreditsStatusNotice, { children: [
4256
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$error", fontWeight: "700", children: "Request Failed" }),
4257
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: state.error })
5968
+ state.error && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(AiCreditsStatusNotice, { children: [
5969
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$error", fontWeight: "700", children: "Request Failed" }),
5970
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: state.error })
4258
5971
  ] }),
4259
- state.gBalance !== null && Number.parseFloat(state.gBalance) <= 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(AiCreditsStatusNotice, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { secondary: true, children: "You need G$ before you can buy AI credits." }) }),
4260
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5972
+ state.gBalance !== null && Number.parseFloat(state.gBalance) <= 0 && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(AiCreditsStatusNotice, { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { secondary: true, children: "You need G$ before you can buy AI credits." }) }),
5973
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4261
5974
  AiCreditsPurchaseFlow,
4262
5975
  {
4263
5976
  state,
@@ -4268,16 +5981,13 @@ function BuyCreditsPanel({ state, actions, isPending, onPay }) {
4268
5981
  )
4269
5982
  ] });
4270
5983
  }
4271
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$4", children: [
4272
- content,
4273
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(BuyCreditsFaq, {})
4274
- ] });
5984
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.YStack, { gap: "$4", children: content });
4275
5985
  }
4276
5986
  function ManagePanel({
4277
5987
  state,
4278
5988
  actions
4279
5989
  }) {
4280
- const [refreshing, setRefreshing] = import_react14.default.useState(false);
5990
+ const [refreshing, setRefreshing] = import_react17.default.useState(false);
4281
5991
  const handleRefresh = async () => {
4282
5992
  setRefreshing(true);
4283
5993
  try {
@@ -4286,15 +5996,15 @@ function ManagePanel({
4286
5996
  setRefreshing(false);
4287
5997
  }
4288
5998
  };
4289
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$3", width: "100%", children: [
4290
- state.error && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(AiCreditsStatusNotice, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$error", fontSize: "$2", children: state.error }) }),
4291
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(CreditsManagementCard, { state, actions }),
4292
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(BuyerOperatorCard, { state, actions }),
4293
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SetupSnippet, {}),
4294
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$2", width: "100%", alignItems: "center", children: [
4295
- state.error && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Text, { color: "$error", fontSize: "$2", textAlign: "center", children: state.error }),
4296
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
4297
- import_ui16.Button,
5999
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { gap: "$3", width: "100%", children: [
6000
+ state.error && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(AiCreditsStatusNotice, { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$error", fontSize: "$2", children: state.error }) }),
6001
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(CreditsManagementCard, { state, actions }),
6002
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(BuyerOperatorCard, { state, actions }),
6003
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SetupSnippet, {}),
6004
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { gap: "$2", width: "100%", alignItems: "center", children: [
6005
+ state.error && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Text, { color: "$error", fontSize: "$2", textAlign: "center", children: state.error }),
6006
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
6007
+ import_ui21.Button,
4298
6008
  {
4299
6009
  variant: "outline",
4300
6010
  size: "sm",
@@ -4306,8 +6016,8 @@ function ManagePanel({
4306
6016
  void handleRefresh();
4307
6017
  },
4308
6018
  children: [
4309
- refreshing ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Spinner, { size: "sm" }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.Icon, { name: "refresh", size: "sm", color: "muted" }),
4310
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.ButtonText, { children: refreshing ? "Refreshing\u2026" : "Refresh Balance" })
6019
+ refreshing ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Spinner, { size: "sm" }) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Icon, { name: "refresh", size: "sm", color: "muted" }),
6020
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.ButtonText, { children: refreshing ? "Refreshing\u2026" : "Refresh Balance" })
4311
6021
  ]
4312
6022
  }
4313
6023
  )
@@ -4325,7 +6035,9 @@ function AiCreditsInner({
4325
6035
  adapterFactory,
4326
6036
  adapterOptions,
4327
6037
  onPaySuccess,
4328
- onPayError
6038
+ onPayError,
6039
+ showWalletControls = false,
6040
+ hasDisconnectOverride = false
4329
6041
  }) {
4330
6042
  const defaultAdapter = useAiCreditsAdapter({
4331
6043
  environment,
@@ -4342,33 +6054,41 @@ function AiCreditsInner({
4342
6054
  skipVaultPaymentValidation: adapterOptions?.skipVaultPaymentValidation,
4343
6055
  prepareSettlement: adapterOptions?.prepareSettlement
4344
6056
  });
4345
- const activeAdapter = (0, import_react14.useMemo)(
4346
- () => adapterFactory ? adapterFactory({ environment, backendUrl }) : defaultAdapter,
4347
- [adapterFactory, environment, backendUrl, defaultAdapter]
6057
+ const factoryAdapter = (0, import_react17.useMemo)(
6058
+ () => adapterFactory ? adapterFactory({ environment, backendUrl }) : null,
6059
+ [adapterFactory, environment, backendUrl]
4348
6060
  );
6061
+ const activeAdapter = factoryAdapter ?? defaultAdapter;
4349
6062
  const { state, actions } = activeAdapter;
6063
+ const onBuyersDiscoveredRef = import_react17.default.useRef(actions.discoverBuyers);
6064
+ onBuyersDiscoveredRef.current = actions.discoverBuyers;
6065
+ const onBuyersDiscovered = (0, import_react17.useCallback)((addresses) => {
6066
+ onBuyersDiscoveredRef.current(addresses);
6067
+ }, []);
4350
6068
  const history = useAiCreditsHistory({
4351
6069
  address: state.address,
4352
6070
  backendUrl,
6071
+ defaultBuyerFilter: state.buyerPubKey ?? "all",
4353
6072
  environment,
4354
- backendClient: adapterOptions?.backendClient
6073
+ backendClient: adapterOptions?.backendClient,
6074
+ onBuyersDiscovered
4355
6075
  });
4356
- const handlePay = (0, import_react14.useCallback)(
6076
+ const handlePay = (0, import_react17.useCallback)(
4357
6077
  async (quote) => {
4358
- const toastId = (0, import_ui16.createToast)({
6078
+ const toastId = (0, import_ui21.createToast)({
4359
6079
  message: "Submitting Celo transaction\u2026",
4360
6080
  status: "pending",
4361
6081
  duration: 0
4362
6082
  });
4363
6083
  try {
4364
6084
  await actions.pay(quote);
4365
- (0, import_ui16.updateToast)(toastId, {
6085
+ (0, import_ui21.updateToast)(toastId, {
4366
6086
  message: "Credits added successfully!",
4367
6087
  status: "success",
4368
6088
  duration: 4e3
4369
6089
  });
4370
6090
  } catch (err) {
4371
- (0, import_ui16.updateToast)(toastId, {
6091
+ (0, import_ui21.updateToast)(toastId, {
4372
6092
  message: err instanceof Error ? err.message : state.error ?? "Payment failed. Try again.",
4373
6093
  status: "error",
4374
6094
  duration: 4e3
@@ -4377,47 +6097,117 @@ function AiCreditsInner({
4377
6097
  },
4378
6098
  [actions, state.error]
4379
6099
  );
6100
+ const [helpView, setHelpView] = (0, import_react17.useState)(null);
4380
6101
  const isPending = state.status === "payment_pending" || state.status === "payment_confirmed";
4381
- const handleTabChange = (0, import_react14.useCallback)(
6102
+ const handleTabChange = (0, import_react17.useCallback)(
4382
6103
  (tabId) => {
6104
+ if (tabId !== "setup") {
6105
+ setHelpView(null);
6106
+ }
4383
6107
  actions.setActiveTab(tabId);
4384
6108
  },
4385
6109
  [actions]
4386
6110
  );
4387
- const buyPanel = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4388
- BuyCreditsPanel,
4389
- {
4390
- state,
4391
- actions,
4392
- isPending,
4393
- onPay: (quote) => {
4394
- void handlePay(quote);
4395
- }
4396
- }
6111
+ const { disconnect, disconnectLabel, disconnectIcon } = (0, import_core2.useWallet)();
6112
+ const handleDisconnect = (0, import_react17.useCallback)(async () => {
6113
+ await disconnect();
6114
+ setHelpView(null);
6115
+ actions.setActiveTab("setup");
6116
+ }, [actions, disconnect]);
6117
+ const walletRequired = needsWalletConnection(state);
6118
+ const handleHelpViewOpen = (0, import_react17.useCallback)(
6119
+ (view) => {
6120
+ actions.setActiveTab("setup");
6121
+ setHelpView(view);
6122
+ },
6123
+ [actions]
4397
6124
  );
4398
- if (state.status === "disconnected" || state.status === "connecting") {
4399
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.YStack, { gap: "$3", padding: "$3", width: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DisconnectedPanel, { onConnect: actions.connect, connecting: state.status === "connecting" }) });
4400
- }
4401
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { gap: "$3", padding: "$3", width: "100%", children: [
4402
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4403
- import_ui16.WidgetTabs,
6125
+ const handleHelpViewClose = (0, import_react17.useCallback)(() => {
6126
+ setHelpView(null);
6127
+ }, []);
6128
+ const setupPanel = helpView === "how-to-use" ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(HowToUseView, { onBack: handleHelpViewClose }) : helpView === "faq" ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SetupFaqView, { onBack: handleHelpViewClose }) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SetupTabPanel, { state, actions, onConnect: actions.connect });
6129
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { gap: "$3", padding: "$3", width: "100%", children: [
6130
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
6131
+ import_ui21.XStack,
6132
+ {
6133
+ justifyContent: "space-between",
6134
+ alignItems: "center",
6135
+ gap: "$2",
6136
+ paddingHorizontal: "$1",
6137
+ children: [
6138
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Heading, { level: 4, children: "GoodDollar" }),
6139
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.XStack, { gap: "$2", alignItems: "center", flexShrink: 1, minWidth: 0, children: [
6140
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.Badge, { type: "info", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.BadgeText, { children: (0, import_ui21.getChainDisplayName)(state.chainId ?? CELO_CHAIN_ID3) }) }),
6141
+ showWalletControls && state.address && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
6142
+ WalletChip,
6143
+ {
6144
+ address: state.address,
6145
+ onDisconnect: hasDisconnectOverride ? handleDisconnect : void 0,
6146
+ disconnectLabel: hasDisconnectOverride ? disconnectLabel : void 0,
6147
+ disconnectIcon: hasDisconnectOverride ? disconnectIcon : void 0
6148
+ }
6149
+ )
6150
+ ] })
6151
+ ]
6152
+ }
6153
+ ),
6154
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
6155
+ SetupGuidanceCard,
6156
+ {
6157
+ activeHelpView: helpView,
6158
+ onHowToUse: () => {
6159
+ handleHelpViewOpen("how-to-use");
6160
+ },
6161
+ onFaq: () => {
6162
+ handleHelpViewOpen("faq");
6163
+ },
6164
+ depositBonusPercent: state.depositBonusPercent,
6165
+ streamBonusPercent: state.streamBonusPercent,
6166
+ isGoodIdVerified: state.isGoodIdVerified
6167
+ }
6168
+ ),
6169
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
6170
+ import_ui21.WidgetTabs,
4404
6171
  {
4405
6172
  tabs: [
6173
+ { id: "setup", label: "Setup" },
4406
6174
  { id: "buy", label: "Buy Credits" },
4407
6175
  { id: "manage", label: "Manage" },
4408
6176
  { id: "history", label: "History" }
4409
6177
  ],
4410
- activeTab: state.activeTab,
6178
+ activeTab: walletRequired ? "setup" : state.activeTab,
4411
6179
  onTabChange: handleTabChange,
4412
- chainId: state.chainId ?? CELO_CHAIN_ID3
6180
+ isTabDisabled: (tabId) => walletRequired && tabId !== "setup",
6181
+ withConnectionStatus: false
4413
6182
  }
4414
6183
  ),
4415
- state.activeTab === "manage" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ManagePanel, { state, actions }) : state.activeTab === "history" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(HistoryTab, { state: history.state, actions: history.actions }) : buyPanel
6184
+ walletRequired || state.activeTab === "setup" ? setupPanel : state.activeTab === "manage" ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ManagePanel, { state, actions }) : state.activeTab === "history" ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
6185
+ HistoryTab,
6186
+ {
6187
+ state: history.state,
6188
+ actions: history.actions,
6189
+ knownBuyers: state.buyers.map((address) => ({ address }))
6190
+ }
6191
+ ) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
6192
+ BuyCreditsPanel,
6193
+ {
6194
+ state,
6195
+ actions,
6196
+ isPending,
6197
+ onPay: (quote) => {
6198
+ void handlePay(quote);
6199
+ }
6200
+ }
6201
+ )
4416
6202
  ] });
4417
6203
  }
4418
6204
  function AiCreditsWidget({
4419
6205
  provider,
4420
6206
  connectOverride,
6207
+ showWalletControls = false,
6208
+ disconnectOverride,
6209
+ disconnectLabel,
6210
+ disconnectIcon,
4421
6211
  environment = "production",
4422
6212
  backendUrl,
4423
6213
  baseRpcUrl,
@@ -4434,16 +6224,19 @@ function AiCreditsWidget({
4434
6224
  adapterOptions,
4435
6225
  testId
4436
6226
  }) {
4437
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
6227
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4438
6228
  import_core2.GoodWidgetProvider,
4439
6229
  {
4440
6230
  provider,
4441
6231
  connectOverride,
6232
+ disconnectOverride,
6233
+ disconnectLabel,
6234
+ disconnectIcon,
4442
6235
  config,
4443
6236
  themeOverrides,
4444
6237
  defaultTheme,
4445
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_ui16.YStack, { backgroundColor: "$background", width: "100%", "data-testid": testId, children: [
4446
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
6238
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_ui21.YStack, { backgroundColor: "$background", width: "100%", "data-testid": testId, children: [
6239
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4447
6240
  AiCreditsInner,
4448
6241
  {
4449
6242
  environment,
@@ -4456,10 +6249,12 @@ function AiCreditsWidget({
4456
6249
  adapterFactory,
4457
6250
  adapterOptions,
4458
6251
  onPaySuccess,
4459
- onPayError
6252
+ onPayError,
6253
+ showWalletControls,
6254
+ hasDisconnectOverride: Boolean(disconnectOverride)
4460
6255
  }
4461
6256
  ),
4462
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui16.ToastContainer, {})
6257
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.ToastContainer, {})
4463
6258
  ] })
4464
6259
  }
4465
6260
  );