@compass-labs/widgets 0.1.35 → 0.1.36

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/index.mjs CHANGED
@@ -6744,7 +6744,7 @@ function PositionsView({ allowedCollateralTokens, allowedDebtTokens, onBorrow, o
6744
6744
  "span",
6745
6745
  {
6746
6746
  className: "text-lg font-semibold tabular-nums",
6747
- style: { color: debtPositions.length > 0 ? "var(--compass-color-error)" : "var(--compass-color-text)" },
6747
+ style: { color: "var(--compass-color-text)" },
6748
6748
  children: totalDebtUsd
6749
6749
  }
6750
6750
  ),
@@ -7119,11 +7119,11 @@ function DebtPositionCard({
7119
7119
  ] }),
7120
7120
  /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between text-sm", children: [
7121
7121
  /* @__PURE__ */ jsx("span", { style: { color: "var(--compass-color-text-tertiary)" }, children: "Borrow APY" }),
7122
- /* @__PURE__ */ jsx("span", { style: { color: "var(--compass-color-error)" }, children: formatApy(position.borrowApy) })
7122
+ /* @__PURE__ */ jsx("span", { style: { color: "var(--compass-color-warning, #f59e0b)" }, children: formatApy(position.borrowApy) })
7123
7123
  ] }),
7124
7124
  position.interestPaid !== null && position.interestPaid !== void 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between text-sm", children: [
7125
7125
  /* @__PURE__ */ jsx("span", { style: { color: "var(--compass-color-text-tertiary)" }, children: "Interest paid" }),
7126
- /* @__PURE__ */ jsxs("span", { style: { color: "var(--compass-color-error)" }, children: [
7126
+ /* @__PURE__ */ jsxs("span", { style: { color: "var(--compass-color-text)" }, children: [
7127
7127
  formatNumber(position.interestPaid),
7128
7128
  " ",
7129
7129
  position.symbol
@@ -7285,7 +7285,7 @@ function BorrowModal({ isOpen, onClose, initialToken, allowedTokens }) {
7285
7285
  },
7286
7286
  children: isBusy ? /* @__PURE__ */ jsxs(Fragment, { children: [
7287
7287
  /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }),
7288
- txState.status === "preparing" ? "Preparing..." : txState.status === "signing" ? "Sign SafeTx..." : "Broadcasting..."
7288
+ txState.status === "preparing" ? "Preparing..." : txState.status === "signing" ? "Signing Borrow..." : "Broadcasting..."
7289
7289
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
7290
7290
  /* @__PURE__ */ jsx(TrendingUp, { className: "h-4 w-4" }),
7291
7291
  "Borrow"
@@ -7441,7 +7441,7 @@ function RepayModal({ isOpen, onClose, initialToken, allowedTokens }) {
7441
7441
  },
7442
7442
  children: isBusy ? /* @__PURE__ */ jsxs(Fragment, { children: [
7443
7443
  /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }),
7444
- txState.status === "preparing" ? "Preparing..." : txState.status === "signing" ? "Sign SafeTx..." : "Broadcasting..."
7444
+ txState.status === "preparing" ? "Preparing..." : txState.status === "signing" ? "Signing Repay..." : "Broadcasting..."
7445
7445
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
7446
7446
  /* @__PURE__ */ jsx(ArrowDownLeft, { className: "h-4 w-4" }),
7447
7447
  "Repay"
@@ -7597,7 +7597,7 @@ function SupplyModal({ isOpen, onClose, initialToken, allowedTokens }) {
7597
7597
  },
7598
7598
  children: isBusy ? /* @__PURE__ */ jsxs(Fragment, { children: [
7599
7599
  /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }),
7600
- txState.status === "preparing" ? "Preparing..." : txState.status === "signing" ? "Sign SafeTx..." : "Broadcasting..."
7600
+ txState.status === "preparing" ? "Preparing..." : txState.status === "signing" ? "Signing Supply..." : "Broadcasting..."
7601
7601
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
7602
7602
  /* @__PURE__ */ jsx(ArrowUpCircle, { className: "h-4 w-4" }),
7603
7603
  "Supply"
@@ -7611,12 +7611,20 @@ function WithdrawModal({ isOpen, onClose, initialToken, allowedTokens }) {
7611
7611
  const { address } = useEmbeddableWallet();
7612
7612
  const { isDeployed } = useCreditAccount();
7613
7613
  const { txState, executeBundle, resetState } = useCreditBundle();
7614
+ const { data: positionsData } = useCreditPositions();
7614
7615
  const prices = useTokenPrices();
7615
7616
  const [token, setToken] = useState(initialToken || "USDC");
7616
7617
  const [amount, setAmount] = useState("");
7617
7618
  useEffect(() => {
7618
7619
  if (initialToken) setToken(initialToken);
7619
7620
  }, [initialToken]);
7621
+ const suppliedAmount = (() => {
7622
+ if (!positionsData) return null;
7623
+ const pos = positionsData.collateralPositions.find((p) => p.symbol === token);
7624
+ if (!pos || !pos.amountSupplied) return null;
7625
+ const amt = parseFloat(pos.amountSupplied);
7626
+ return amt > 0 ? amt : null;
7627
+ })();
7620
7628
  const isValid = Number(amount) > 0 && !!address && isDeployed;
7621
7629
  const isBusy = txState.status === "preparing" || txState.status === "signing" || txState.status === "broadcasting";
7622
7630
  useEffect(() => {
@@ -7671,7 +7679,19 @@ function WithdrawModal({ isOpen, onClose, initialToken, allowedTokens }) {
7671
7679
  )
7672
7680
  ] }),
7673
7681
  /* @__PURE__ */ jsxs("div", { children: [
7674
- /* @__PURE__ */ jsx("label", { className: "block text-sm mb-1.5", style: labelStyle, children: "Amount" }),
7682
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-1.5", children: [
7683
+ /* @__PURE__ */ jsx("label", { className: "text-sm", style: labelStyle, children: "Amount" }),
7684
+ suppliedAmount !== null && /* @__PURE__ */ jsx(
7685
+ "button",
7686
+ {
7687
+ type: "button",
7688
+ onClick: () => setAmount(suppliedAmount.toFixed(6).replace(/\.?0+$/, "")),
7689
+ className: "text-xs font-medium transition-opacity hover:opacity-80",
7690
+ style: { color: "var(--compass-color-primary)" },
7691
+ children: "MAX"
7692
+ }
7693
+ )
7694
+ ] }),
7675
7695
  /* @__PURE__ */ jsxs("div", { className: "relative", children: [
7676
7696
  /* @__PURE__ */ jsx(
7677
7697
  "input",
@@ -7693,18 +7713,33 @@ function WithdrawModal({ isOpen, onClose, initialToken, allowedTokens }) {
7693
7713
  }
7694
7714
  )
7695
7715
  ] }),
7696
- formatUsdEstimate(amount, token, prices) && /* @__PURE__ */ jsxs(
7697
- "p",
7698
- {
7699
- className: "text-xs mt-1",
7700
- style: { color: "var(--compass-color-text-tertiary)" },
7701
- children: [
7702
- "\u2248",
7703
- " ",
7704
- formatUsdEstimate(amount, token, prices)
7705
- ]
7706
- }
7707
- )
7716
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mt-1", children: [
7717
+ formatUsdEstimate(amount, token, prices) ? /* @__PURE__ */ jsxs(
7718
+ "span",
7719
+ {
7720
+ className: "text-xs",
7721
+ style: { color: "var(--compass-color-text-tertiary)" },
7722
+ children: [
7723
+ "\u2248",
7724
+ " ",
7725
+ formatUsdEstimate(amount, token, prices)
7726
+ ]
7727
+ }
7728
+ ) : /* @__PURE__ */ jsx("span", {}),
7729
+ suppliedAmount !== null && /* @__PURE__ */ jsxs(
7730
+ "span",
7731
+ {
7732
+ className: "text-xs",
7733
+ style: { color: "var(--compass-color-text-tertiary)" },
7734
+ children: [
7735
+ "Supplied: ",
7736
+ suppliedAmount.toLocaleString(void 0, { maximumFractionDigits: 4 }),
7737
+ " ",
7738
+ token
7739
+ ]
7740
+ }
7741
+ )
7742
+ ] })
7708
7743
  ] })
7709
7744
  ] }),
7710
7745
  /* @__PURE__ */ jsx(
@@ -7722,7 +7757,7 @@ function WithdrawModal({ isOpen, onClose, initialToken, allowedTokens }) {
7722
7757
  },
7723
7758
  children: isBusy ? /* @__PURE__ */ jsxs(Fragment, { children: [
7724
7759
  /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }),
7725
- txState.status === "preparing" ? "Preparing..." : txState.status === "signing" ? "Sign SafeTx..." : "Broadcasting..."
7760
+ txState.status === "preparing" ? "Preparing..." : txState.status === "signing" ? "Signing Withdraw..." : "Broadcasting..."
7726
7761
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
7727
7762
  /* @__PURE__ */ jsx(ArrowDownCircle, { className: "h-4 w-4" }),
7728
7763
  "Withdraw"
@@ -8394,7 +8429,7 @@ function CreditSwapModal({ isOpen, onClose }) {
8394
8429
  },
8395
8430
  children: isBusy ? /* @__PURE__ */ jsxs(Fragment, { children: [
8396
8431
  /* @__PURE__ */ jsx(Loader2, { size: 16, className: "animate-spin" }),
8397
- txState.status === "preparing" ? "Preparing..." : txState.status === "signing" ? "Sign SafeTx..." : "Broadcasting..."
8432
+ txState.status === "preparing" ? "Preparing..." : txState.status === "signing" ? "Signing Swap..." : "Broadcasting..."
8398
8433
  ] }) : "Swap"
8399
8434
  }
8400
8435
  ),
@@ -8448,8 +8483,28 @@ function CreditAccount({
8448
8483
  const price = tokenPrices[b.tokenSymbol];
8449
8484
  const usdValue = amount > 0 && price != null ? amount * price : 0;
8450
8485
  return { ...b, usdValue };
8451
- }).filter((b) => b.usdValue >= 0.01);
8486
+ }).filter((b) => b.usdValue >= 0.01).sort((a, b) => a.tokenSymbol.localeCompare(b.tokenSymbol));
8452
8487
  const totalIdleUsd = balancesWithUsd.reduce((sum, b) => sum + b.usdValue, 0);
8488
+ const totalInterestEarnedUsd = (() => {
8489
+ if (!positions) return 0;
8490
+ let total = 0;
8491
+ for (const pos of positions.collateralPositions) {
8492
+ const interest = parseFloat(pos.interestEarned ?? "0");
8493
+ const price = tokenPrices[pos.symbol] ?? 0;
8494
+ if (interest > 0 && price > 0) total += interest * price;
8495
+ }
8496
+ return total;
8497
+ })();
8498
+ const totalInterestPaidUsd = (() => {
8499
+ if (!positions) return 0;
8500
+ let total = 0;
8501
+ for (const pos of positions.debtPositions) {
8502
+ const interest = parseFloat(pos.interestPaid ?? "0");
8503
+ const price = tokenPrices[pos.symbol] ?? 0;
8504
+ if (interest > 0 && price > 0) total += interest * price;
8505
+ }
8506
+ return total;
8507
+ })();
8453
8508
  const netPositionUsd = totalCollateral - totalDebt;
8454
8509
  const totalBalance = netPositionUsd + totalIdleUsd;
8455
8510
  const netInterestUsdPerYear = (() => {
@@ -8686,15 +8741,28 @@ function CreditAccount({
8686
8741
  /* @__PURE__ */ jsx(CopyableAddress, { address: creditAccountAddress, label: "Credit Account" })
8687
8742
  ] }),
8688
8743
  positions && positions.collateralPositions.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
8689
- /* @__PURE__ */ jsx(
8690
- "span",
8691
- {
8692
- className: "text-xs font-medium uppercase tracking-wide",
8693
- style: { color: "var(--compass-color-text-tertiary)" },
8694
- children: "Collateral"
8695
- }
8696
- ),
8697
- positions.collateralPositions.filter((p) => parseFloat(p.usdValue ?? "0") >= 0.01).map((p) => /* @__PURE__ */ jsxs(
8744
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
8745
+ /* @__PURE__ */ jsx(
8746
+ "span",
8747
+ {
8748
+ className: "text-xs font-medium uppercase tracking-wide",
8749
+ style: { color: "var(--compass-color-text-tertiary)" },
8750
+ children: "Collateral"
8751
+ }
8752
+ ),
8753
+ totalInterestEarnedUsd > 0 && /* @__PURE__ */ jsxs(
8754
+ "span",
8755
+ {
8756
+ className: "text-xs font-medium",
8757
+ style: { color: "var(--compass-color-success)" },
8758
+ children: [
8759
+ "Interest: +",
8760
+ formatUsd2(totalInterestEarnedUsd)
8761
+ ]
8762
+ }
8763
+ )
8764
+ ] }),
8765
+ [...positions.collateralPositions].filter((p) => parseFloat(p.usdValue ?? "0") >= 0.01).sort((a, b) => a.symbol.localeCompare(b.symbol)).map((p) => /* @__PURE__ */ jsxs(
8698
8766
  "div",
8699
8767
  {
8700
8768
  className: "flex items-center justify-between p-3 rounded-lg",
@@ -8717,15 +8785,28 @@ function CreditAccount({
8717
8785
  ))
8718
8786
  ] }),
8719
8787
  positions && positions.debtPositions.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
8720
- /* @__PURE__ */ jsx(
8721
- "span",
8722
- {
8723
- className: "text-xs font-medium uppercase tracking-wide",
8724
- style: { color: "var(--compass-color-text-tertiary)" },
8725
- children: "Debt"
8726
- }
8727
- ),
8728
- positions.debtPositions.filter((p) => parseFloat(p.usdValue ?? "0") >= 0.01).map((p) => /* @__PURE__ */ jsxs(
8788
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
8789
+ /* @__PURE__ */ jsx(
8790
+ "span",
8791
+ {
8792
+ className: "text-xs font-medium uppercase tracking-wide",
8793
+ style: { color: "var(--compass-color-text-tertiary)" },
8794
+ children: "Debt"
8795
+ }
8796
+ ),
8797
+ totalInterestPaidUsd > 0 && /* @__PURE__ */ jsxs(
8798
+ "span",
8799
+ {
8800
+ className: "text-xs font-medium",
8801
+ style: { color: "var(--compass-color-error, #ef4444)" },
8802
+ children: [
8803
+ "Interest: -",
8804
+ formatUsd2(totalInterestPaidUsd)
8805
+ ]
8806
+ }
8807
+ )
8808
+ ] }),
8809
+ [...positions.debtPositions].filter((p) => parseFloat(p.usdValue ?? "0") >= 0.01).sort((a, b) => a.symbol.localeCompare(b.symbol)).map((p) => /* @__PURE__ */ jsxs(
8729
8810
  "div",
8730
8811
  {
8731
8812
  className: "flex items-center justify-between p-3 rounded-lg",
@@ -8734,19 +8815,13 @@ function CreditAccount({
8734
8815
  border: "1px solid var(--compass-color-border)"
8735
8816
  },
8736
8817
  children: [
8737
- /* @__PURE__ */ jsx("span", { className: "font-medium", style: { color: "var(--compass-color-error, #ef4444)" }, children: p.symbol }),
8818
+ /* @__PURE__ */ jsx("span", { className: "font-medium", style: { color: "var(--compass-color-text)" }, children: p.symbol }),
8738
8819
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-end", children: [
8739
- /* @__PURE__ */ jsxs("span", { className: "font-mono font-medium", style: { color: "var(--compass-color-error, #ef4444)" }, children: [
8740
- "-",
8741
- parseFloat(p.amountBorrowed ?? "0").toLocaleString(void 0, {
8742
- minimumFractionDigits: 2,
8743
- maximumFractionDigits: 4
8744
- })
8745
- ] }),
8746
- /* @__PURE__ */ jsxs("span", { className: "text-xs", style: { color: "var(--compass-color-text-tertiary)" }, children: [
8747
- "-$",
8748
- parseFloat(p.usdValue ?? "0").toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })
8749
- ] })
8820
+ /* @__PURE__ */ jsx("span", { className: "font-mono font-medium", style: { color: "var(--compass-color-text)" }, children: parseFloat(p.amountBorrowed ?? "0").toLocaleString(void 0, {
8821
+ minimumFractionDigits: 2,
8822
+ maximumFractionDigits: 4
8823
+ }) }),
8824
+ /* @__PURE__ */ jsx("span", { className: "text-xs", style: { color: "var(--compass-color-text-tertiary)" }, children: formatUsd2(p.usdValue) })
8750
8825
  ] })
8751
8826
  ]
8752
8827
  },
@@ -8754,14 +8829,24 @@ function CreditAccount({
8754
8829
  ))
8755
8830
  ] }),
8756
8831
  balancesWithUsd.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
8757
- /* @__PURE__ */ jsx(
8758
- "span",
8759
- {
8760
- className: "text-xs font-medium uppercase tracking-wide",
8761
- style: { color: "var(--compass-color-text-tertiary)" },
8762
- children: "Available in Account"
8763
- }
8764
- ),
8832
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
8833
+ /* @__PURE__ */ jsx(
8834
+ "span",
8835
+ {
8836
+ className: "text-xs font-medium uppercase tracking-wide",
8837
+ style: { color: "var(--compass-color-text-tertiary)" },
8838
+ children: "Available in Account"
8839
+ }
8840
+ ),
8841
+ /* @__PURE__ */ jsx(
8842
+ "span",
8843
+ {
8844
+ className: "text-sm font-semibold",
8845
+ style: { color: "var(--compass-color-text)" },
8846
+ children: formatUsd2(totalIdleUsd)
8847
+ }
8848
+ )
8849
+ ] }),
8765
8850
  balancesWithUsd.map((b) => /* @__PURE__ */ jsxs(
8766
8851
  "div",
8767
8852
  {