@goodwidget/ai-credits-widget 0.1.11 → 0.1.13

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
@@ -40,6 +40,12 @@ var import_react18 = __toESM(require("react"), 1);
40
40
  var import_core3 = require("@goodwidget/core");
41
41
  var import_ui20 = require("@goodwidget/ui");
42
42
 
43
+ // package.json
44
+ var version = "0.1.13";
45
+
46
+ // src/AiCreditsWidget.tsx
47
+ var import_ui21 = require("@goodwidget/ui");
48
+
43
49
  // src/adapter.ts
44
50
  var import_react = require("react");
45
51
  var import_core2 = require("@goodwidget/core");
@@ -135,7 +141,7 @@ async function signOperatorConsentFromTypedData(signerPrivateKey, typedData) {
135
141
  var import_viem2 = require("viem");
136
142
 
137
143
  // src/format.ts
138
- var G_COMPACT_FROM = 1e6;
144
+ var G_COMPACT_FROM = 1e3;
139
145
  var USD_MIN_VISIBLE = 5e-3;
140
146
  var gGrouped = new Intl.NumberFormat("en-US", {
141
147
  minimumFractionDigits: 0,
@@ -143,7 +149,7 @@ var gGrouped = new Intl.NumberFormat("en-US", {
143
149
  });
144
150
  var gCompact = new Intl.NumberFormat("en-US", {
145
151
  notation: "compact",
146
- maximumFractionDigits: 2
152
+ maximumFractionDigits: 1
147
153
  });
148
154
  var usdGrouped = new Intl.NumberFormat("en-US", {
149
155
  minimumFractionDigits: 2,
@@ -169,20 +175,21 @@ function formatGValue(amount) {
169
175
  if (value < 0.01) return "<0.01";
170
176
  return gGrouped.format(value);
171
177
  }
172
- function formatGAmount(amount) {
173
- return `${formatGValue(amount)} G$`;
174
- }
175
178
  function isGValueCompacted(amount) {
176
179
  const value = toNumber(amount);
177
180
  return Number.isFinite(value) && value >= G_COMPACT_FROM;
178
181
  }
179
- function formatExactGAmount(amount) {
182
+ function formatExactGValue(amount) {
180
183
  const value = toNumber(amount);
181
- if (!Number.isFinite(value) || value <= 0) return "0 G$";
182
- return `${gGrouped.format(value)} G$`;
184
+ if (!Number.isFinite(value) || value <= 0) return "0";
185
+ if (value < 0.01) return "<0.01";
186
+ return gGrouped.format(value);
187
+ }
188
+ function formatExactGAmount(amount) {
189
+ return `${formatExactGValue(amount)} G$`;
183
190
  }
184
- function formatGWeiAmount(amountWei) {
185
- return formatGAmount(weiToNumber(amountWei));
191
+ function formatExactGWeiAmount(amountWei) {
192
+ return formatExactGAmount(weiToNumber(amountWei));
186
193
  }
187
194
  function formatUsdValue(amount) {
188
195
  const value = toNumber(amount);
@@ -552,7 +559,10 @@ var ANTSEED_BUYER_OPERATOR_DOMAIN = {
552
559
  };
553
560
  var WITHDRAW_PRINCIPAL_TYPES = {
554
561
  WithdrawPrincipal: [
555
- { name: "signer", type: "address" },
562
+ // `buyer` is the contract's field name; the value is our signer address.
563
+ // EIP-712 hashes field names, so renaming this to `signer` changes the
564
+ // struct hash and the vault rejects the withdrawal with InvalidSignature().
565
+ { name: "buyer", type: "address" },
556
566
  { name: "amount", type: "uint256" },
557
567
  { name: "recipient", type: "address" },
558
568
  { name: "nonce", type: "uint256" }
@@ -588,7 +598,7 @@ async function signWithdrawPrincipal(params) {
588
598
  types: WITHDRAW_PRINCIPAL_TYPES,
589
599
  primaryType: "WithdrawPrincipal",
590
600
  message: {
591
- signer: params.signer,
601
+ buyer: params.signer,
592
602
  amount: params.amountMicro,
593
603
  recipient: params.recipient,
594
604
  nonce: params.nonce
@@ -1561,9 +1571,9 @@ var VAULT_MINIMUMS_ABI = (0, import_viem7.parseAbi)([
1561
1571
  function formatMinGDisplay(amountWei) {
1562
1572
  const raw = Number(amountWei) / 1e18;
1563
1573
  if (!Number.isFinite(raw) || raw <= 0) return "0";
1564
- if (raw >= 1e3) return formatGValue(Math.ceil(raw));
1565
- if (raw >= 10) return formatGValue(Math.ceil(raw * 10) / 10);
1566
- return formatGValue(Math.ceil(raw * 100) / 100);
1574
+ if (raw >= 1e3) return formatExactGValue(Math.ceil(raw));
1575
+ if (raw >= 10) return formatExactGValue(Math.ceil(raw * 10) / 10);
1576
+ return formatExactGValue(Math.ceil(raw * 100) / 100);
1567
1577
  }
1568
1578
  function formatMinUsdDisplay(usd) {
1569
1579
  return formatUsdDisplay(usd);
@@ -4952,7 +4962,7 @@ function formatEntryGAmount(gdAmountWei) {
4952
4962
  try {
4953
4963
  const amountWei = BigInt(gdAmountWei || "0");
4954
4964
  if (amountWei <= 0n) return null;
4955
- return formatGWeiAmount(amountWei);
4965
+ return formatExactGWeiAmount(amountWei);
4956
4966
  } catch {
4957
4967
  return null;
4958
4968
  }
@@ -5051,7 +5061,7 @@ function sumFilteredGdWei(entries) {
5051
5061
  }, 0n);
5052
5062
  }
5053
5063
  function formatAccumulatedG(amountWei) {
5054
- return formatGAmount(Number(amountWei) / 1e18);
5064
+ return formatExactGAmount(Number(amountWei) / 1e18);
5055
5065
  }
5056
5066
  function formatShortDate(dateValue) {
5057
5067
  const date = /* @__PURE__ */ new Date(`${dateValue}T00:00:00.000Z`);
@@ -6772,7 +6782,8 @@ function AiCreditsWidget({
6772
6782
  showWalletControls
6773
6783
  }
6774
6784
  ),
6775
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui20.ToastContainer, {})
6785
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui20.ToastContainer, {}),
6786
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.WidgetVersion, { name: "AI Credits", version })
6776
6787
  ] })
6777
6788
  }
6778
6789
  );