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