@goodwidget/ai-credits-widget 0.1.9 → 0.1.11

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
@@ -4161,14 +4161,43 @@ var WITHDRAW_TOOLTIP = "Withdraws principal to your payer wallet (not bonus). Re
4161
4161
 
4162
4162
  // src/components/manage/CreditsManagementCard.tsx
4163
4163
  var import_jsx_runtime7 = require("react/jsx-runtime");
4164
- function StatCell({ label, children }) {
4165
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Card, { raised: true, borderWidth: 0, flexGrow: 1, flexBasis: 0, children: [
4166
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", tone: "soft", children: label }),
4167
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.YStack, { justifyContent: "center", children })
4168
- ] });
4164
+ function StatCell({
4165
+ label,
4166
+ icon: Glyph,
4167
+ children
4168
+ }) {
4169
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
4170
+ import_ui9.Card,
4171
+ {
4172
+ raised: true,
4173
+ borderWidth: 0,
4174
+ flexGrow: 1,
4175
+ flexBasis: 0,
4176
+ padding: "$3",
4177
+ gap: "$1",
4178
+ children: [
4179
+ Glyph ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4180
+ import_ui9.XStack,
4181
+ {
4182
+ width: 28,
4183
+ height: 28,
4184
+ borderRadius: "$2",
4185
+ backgroundColor: "$background",
4186
+ alignItems: "center",
4187
+ justifyContent: "center",
4188
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Glyph, { size: 16, color: "$colorSoft" })
4189
+ }
4190
+ ) : null,
4191
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { children: [
4192
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", tone: "soft", children: label }),
4193
+ children
4194
+ ] })
4195
+ ]
4196
+ }
4197
+ );
4169
4198
  }
4170
4199
  function StatRow({ children }) {
4171
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.XStack, { gap: "$2", width: "100%", alignItems: "stretch", children });
4200
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.XStack, { gap: "$1", width: "100%", alignItems: "stretch", children });
4172
4201
  }
4173
4202
  function StatValueText({
4174
4203
  children,
@@ -4177,12 +4206,30 @@ function StatValueText({
4177
4206
  }) {
4178
4207
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize, fontWeight: "700", color, children });
4179
4208
  }
4209
+ function StatValue({
4210
+ value,
4211
+ unit,
4212
+ unitPosition,
4213
+ fontSize = "$2",
4214
+ unitFontSize = "$1",
4215
+ color
4216
+ }) {
4217
+ const hoistMarker = unitPosition === "prefix" && value.startsWith("<");
4218
+ const unitLabel = hoistMarker ? `<${unit}` : unit;
4219
+ const digits = hoistMarker ? value.slice(1) : value;
4220
+ const unitText = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: unitFontSize, fontWeight: "700", tone: "soft", children: unitLabel });
4221
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.XStack, { alignItems: "baseline", gap: "$1", children: [
4222
+ unitPosition === "prefix" ? unitText : null,
4223
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValueText, { fontSize, color, children: digits }),
4224
+ unitPosition === "suffix" ? unitText : null
4225
+ ] });
4226
+ }
4180
4227
  function CompactGStatValue({ amount }) {
4181
4228
  const [open, setOpen] = (0, import_react8.useState)(false);
4182
4229
  const display = formatGValue(amount);
4183
4230
  const exact = formatExactGAmount(amount);
4184
4231
  if (!isGValueCompacted(amount)) {
4185
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValueText, { children: display });
4232
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValue, { value: display, unit: "G$", unitPosition: "suffix" });
4186
4233
  }
4187
4234
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
4188
4235
  import_ui9.XStack,
@@ -4198,7 +4245,7 @@ function CompactGStatValue({ amount }) {
4198
4245
  onBlur: () => setOpen(false),
4199
4246
  onPress: () => setOpen((prev) => !prev),
4200
4247
  children: [
4201
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValueText, { children: display }),
4248
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValue, { value: display, unit: "G$", unitPosition: "suffix" }),
4202
4249
  open && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4203
4250
  import_ui9.YStack,
4204
4251
  {
@@ -4223,6 +4270,43 @@ function CompactGStatValue({ amount }) {
4223
4270
  function formatUsdAmount2(usdMicro) {
4224
4271
  return formatUsdMicroValue(usdMicro);
4225
4272
  }
4273
+ function CreditBalanceCard({
4274
+ balance,
4275
+ monthlyCredit
4276
+ }) {
4277
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Card, { raised: true, borderWidth: 0, width: "100%", gap: "$2", children: [
4278
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Text, { fontSize: "$1", tone: "soft", children: "Credit balance" }),
4279
+ balance !== null ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4280
+ StatValue,
4281
+ {
4282
+ value: balance,
4283
+ unit: "US$",
4284
+ unitPosition: "prefix",
4285
+ fontSize: "$8",
4286
+ unitFontSize: "$5"
4287
+ }
4288
+ ) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Spinner, { size: "sm" }),
4289
+ monthlyCredit ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
4290
+ import_ui9.XStack,
4291
+ {
4292
+ alignSelf: "flex-start",
4293
+ alignItems: "center",
4294
+ gap: "$1",
4295
+ paddingHorizontal: "$2",
4296
+ paddingVertical: "$1",
4297
+ borderRadius: "$full",
4298
+ backgroundColor: "$infoMuted",
4299
+ children: [
4300
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.TrendingUp, { size: 14, color: "$primary" }),
4301
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Text, { fontSize: "$1", fontWeight: "700", color: "$primary", children: [
4302
+ monthlyCredit.startsWith("<") ? monthlyCredit : `~${monthlyCredit}`,
4303
+ " / month"
4304
+ ] })
4305
+ ]
4306
+ }
4307
+ ) : null
4308
+ ] });
4309
+ }
4226
4310
  function CreditsManagementCard({ state, actions }) {
4227
4311
  const [isClosing, setIsClosing] = (0, import_react8.useState)(false);
4228
4312
  const [isWithdrawing, setIsWithdrawing] = (0, import_react8.useState)(false);
@@ -4247,7 +4331,7 @@ function CreditsManagementCard({ state, actions }) {
4247
4331
  streamBonusPercent: state.streamBonusPercent
4248
4332
  });
4249
4333
  if (usdMicro <= 0n) return null;
4250
- return formatUsdAmount2(usdMicro.toString());
4334
+ return formatUsdMicroAmount(usdMicro.toString());
4251
4335
  }, [
4252
4336
  monthlyStreamG,
4253
4337
  gdUsdPerToken,
@@ -4263,20 +4347,16 @@ function CreditsManagementCard({ state, actions }) {
4263
4347
  const canWithdraw = Boolean(signerPrvKey) && hasWithdrawableBalance && Boolean(withdrawAmount.trim()) && !isWithdrawing;
4264
4348
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.Card, { children: [
4265
4349
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Heading, { level: 6, children: "AI Credits" }),
4266
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(StatRow, { children: [
4267
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Credit balance (US$)", children: totalCreditDisplay !== null ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValueText, { fontSize: "$5", children: totalCreditDisplay }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Spinner, { size: "sm" }) }),
4268
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Monthly Credit (US$)", children: monthlyStreamUsdDisplay ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(StatValueText, { fontSize: "$5", color: "$primary", children: [
4269
- "~",
4270
- monthlyStreamUsdDisplay
4271
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValueText, { fontSize: "$5", children: "\u2014" }) })
4272
- ] }),
4273
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(StatRow, { children: [
4274
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Deposited (G$)", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CompactGStatValue, { amount: totalGdDepositedG ?? "0.00" }) }),
4275
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Monthly Stream (G$)", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CompactGStatValue, { amount: monthlyStreamG ?? "0.00" }) })
4276
- ] }),
4277
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(StatRow, { children: [
4278
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Bonus (US$)", children: totalBonusDisplay !== null ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValueText, { children: totalBonusDisplay }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Spinner, { size: "sm" }) }),
4279
- /* @__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" }) })
4350
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$2", width: "100%", children: [
4351
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CreditBalanceCard, { balance: totalCreditDisplay, monthlyCredit: monthlyStreamUsdDisplay }),
4352
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(StatRow, { children: [
4353
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Deposited", icon: import_ui9.Coins, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CompactGStatValue, { amount: totalGdDepositedG ?? "0.00" }) }),
4354
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Monthly Streaming", icon: import_ui9.Repeat, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CompactGStatValue, { amount: monthlyStreamG ?? "0.00" }) })
4355
+ ] }),
4356
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(StatRow, { children: [
4357
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Bonus", icon: import_ui9.Gift, children: totalBonusDisplay !== null ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValue, { value: totalBonusDisplay, unit: "US$", unitPosition: "prefix" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Spinner, { size: "sm" }) }),
4358
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatCell, { label: "Withdrawable", icon: import_ui9.Wallet, children: withdrawableDisplay !== null ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StatValue, { value: withdrawableDisplay, unit: "US$", unitPosition: "prefix" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui9.Spinner, { size: "sm" }) })
4359
+ ] })
4280
4360
  ] }),
4281
4361
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.YStack, { gap: "$1", width: "100%", children: [
4282
4362
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui9.XStack, { gap: "$1", alignItems: "center", children: [