@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.
@@ -7,7 +7,7 @@ import {
7
7
  buildQuoteAmounts,
8
8
  buildSetOperatorPayload,
9
9
  totalCreditUsdFromProfile
10
- } from "../chunk-3QY3YZDH.js";
10
+ } from "../chunk-5AGZTMIN.js";
11
11
 
12
12
  // src/mocked/AiCreditsMockWidget.tsx
13
13
  import { useMemo } from "react";
package/dist/register.cjs CHANGED
@@ -30,6 +30,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
+ // package.json
34
+ var version;
35
+ var init_package = __esm({
36
+ "package.json"() {
37
+ version = "0.1.13";
38
+ }
39
+ });
40
+
33
41
  // src/signerKeyDerivation.ts
34
42
  function buildSignerKeyMessage(payerAddress) {
35
43
  return `Generate a key for G$ credits from payer wallet of '${payerAddress.toLowerCase()}'`;
@@ -141,20 +149,21 @@ function formatGValue(amount) {
141
149
  if (value < 0.01) return "<0.01";
142
150
  return gGrouped.format(value);
143
151
  }
144
- function formatGAmount(amount) {
145
- return `${formatGValue(amount)} G$`;
146
- }
147
152
  function isGValueCompacted(amount) {
148
153
  const value = toNumber(amount);
149
154
  return Number.isFinite(value) && value >= G_COMPACT_FROM;
150
155
  }
151
- function formatExactGAmount(amount) {
156
+ function formatExactGValue(amount) {
152
157
  const value = toNumber(amount);
153
- if (!Number.isFinite(value) || value <= 0) return "0 G$";
154
- return `${gGrouped.format(value)} G$`;
158
+ if (!Number.isFinite(value) || value <= 0) return "0";
159
+ if (value < 0.01) return "<0.01";
160
+ return gGrouped.format(value);
161
+ }
162
+ function formatExactGAmount(amount) {
163
+ return `${formatExactGValue(amount)} G$`;
155
164
  }
156
- function formatGWeiAmount(amountWei) {
157
- return formatGAmount(weiToNumber(amountWei));
165
+ function formatExactGWeiAmount(amountWei) {
166
+ return formatExactGAmount(weiToNumber(amountWei));
158
167
  }
159
168
  function formatUsdValue(amount) {
160
169
  const value = toNumber(amount);
@@ -182,7 +191,7 @@ var G_COMPACT_FROM, USD_MIN_VISIBLE, gGrouped, gCompact, usdGrouped;
182
191
  var init_format = __esm({
183
192
  "src/format.ts"() {
184
193
  "use strict";
185
- G_COMPACT_FROM = 1e6;
194
+ G_COMPACT_FROM = 1e3;
186
195
  USD_MIN_VISIBLE = 5e-3;
187
196
  gGrouped = new Intl.NumberFormat("en-US", {
188
197
  minimumFractionDigits: 0,
@@ -190,7 +199,7 @@ var init_format = __esm({
190
199
  });
191
200
  gCompact = new Intl.NumberFormat("en-US", {
192
201
  notation: "compact",
193
- maximumFractionDigits: 2
202
+ maximumFractionDigits: 1
194
203
  });
195
204
  usdGrouped = new Intl.NumberFormat("en-US", {
196
205
  minimumFractionDigits: 2,
@@ -571,7 +580,7 @@ async function signWithdrawPrincipal(params) {
571
580
  types: WITHDRAW_PRINCIPAL_TYPES,
572
581
  primaryType: "WithdrawPrincipal",
573
582
  message: {
574
- signer: params.signer,
583
+ buyer: params.signer,
575
584
  amount: params.amountMicro,
576
585
  recipient: params.recipient,
577
586
  nonce: params.nonce
@@ -626,7 +635,10 @@ var init_signerSignatures = __esm({
626
635
  };
627
636
  WITHDRAW_PRINCIPAL_TYPES = {
628
637
  WithdrawPrincipal: [
629
- { name: "signer", type: "address" },
638
+ // `buyer` is the contract's field name; the value is our signer address.
639
+ // EIP-712 hashes field names, so renaming this to `signer` changes the
640
+ // struct hash and the vault rejects the withdrawal with InvalidSignature().
641
+ { name: "buyer", type: "address" },
630
642
  { name: "amount", type: "uint256" },
631
643
  { name: "recipient", type: "address" },
632
644
  { name: "nonce", type: "uint256" }
@@ -1609,9 +1621,9 @@ var init_paymentErrors = __esm({
1609
1621
  function formatMinGDisplay(amountWei) {
1610
1622
  const raw = Number(amountWei) / 1e18;
1611
1623
  if (!Number.isFinite(raw) || raw <= 0) return "0";
1612
- if (raw >= 1e3) return formatGValue(Math.ceil(raw));
1613
- if (raw >= 10) return formatGValue(Math.ceil(raw * 10) / 10);
1614
- return formatGValue(Math.ceil(raw * 100) / 100);
1624
+ if (raw >= 1e3) return formatExactGValue(Math.ceil(raw));
1625
+ if (raw >= 10) return formatExactGValue(Math.ceil(raw * 10) / 10);
1626
+ return formatExactGValue(Math.ceil(raw * 100) / 100);
1615
1627
  }
1616
1628
  function formatMinUsdDisplay(usd) {
1617
1629
  return formatUsdDisplay(usd);
@@ -5137,7 +5149,7 @@ function formatEntryGAmount(gdAmountWei) {
5137
5149
  try {
5138
5150
  const amountWei = BigInt(gdAmountWei || "0");
5139
5151
  if (amountWei <= 0n) return null;
5140
- return formatGWeiAmount(amountWei);
5152
+ return formatExactGWeiAmount(amountWei);
5141
5153
  } catch {
5142
5154
  return null;
5143
5155
  }
@@ -5236,7 +5248,7 @@ function sumFilteredGdWei(entries) {
5236
5248
  }, 0n);
5237
5249
  }
5238
5250
  function formatAccumulatedG(amountWei) {
5239
- return formatGAmount(Number(amountWei) / 1e18);
5251
+ return formatExactGAmount(Number(amountWei) / 1e18);
5240
5252
  }
5241
5253
  function formatShortDate(dateValue) {
5242
5254
  const date = /* @__PURE__ */ new Date(`${dateValue}T00:00:00.000Z`);
@@ -7040,18 +7052,21 @@ function AiCreditsWidget({
7040
7052
  showWalletControls
7041
7053
  }
7042
7054
  ),
7043
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui20.ToastContainer, {})
7055
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui20.ToastContainer, {}),
7056
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui21.WidgetVersion, { name: "AI Credits", version })
7044
7057
  ] })
7045
7058
  }
7046
7059
  );
7047
7060
  }
7048
- var import_react18, import_core3, import_ui20, import_jsx_runtime19, CELO_CHAIN_ID3;
7061
+ var import_react18, import_core3, import_ui20, import_ui21, import_jsx_runtime19, CELO_CHAIN_ID3;
7049
7062
  var init_AiCreditsWidget = __esm({
7050
7063
  "src/AiCreditsWidget.tsx"() {
7051
7064
  "use strict";
7052
7065
  import_react18 = __toESM(require("react"), 1);
7053
7066
  import_core3 = require("@goodwidget/core");
7054
7067
  import_ui20 = require("@goodwidget/ui");
7068
+ init_package();
7069
+ import_ui21 = require("@goodwidget/ui");
7055
7070
  init_adapter();
7056
7071
  init_useAiCreditsHistory();
7057
7072
  init_components();