@compass-labs/widgets 0.1.3 → 0.1.4

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
@@ -2787,22 +2787,24 @@ function formatAPY(apy) {
2787
2787
  function VaultCard({
2788
2788
  vault,
2789
2789
  showApy,
2790
- apyPeriods,
2790
+ sortBy,
2791
2791
  showTvl,
2792
2792
  showUserPosition,
2793
2793
  onClick
2794
2794
  }) {
2795
- const getApyValue = (period) => {
2796
- switch (period) {
2797
- case "7d":
2798
- return vault.apy7d;
2799
- case "30d":
2800
- return vault.apy30d;
2801
- case "90d":
2802
- return vault.apy90d;
2795
+ const getDisplayApy = () => {
2796
+ switch (sortBy) {
2797
+ case "apy_30d":
2798
+ return { value: vault.apy30d, period: "30d" };
2799
+ case "apy_90d":
2800
+ return { value: vault.apy90d, period: "90d" };
2801
+ case "apy_7d":
2802
+ case "tvl":
2803
+ default:
2804
+ return { value: vault.apy7d, period: "7d" };
2803
2805
  }
2804
2806
  };
2805
- const primaryApy = getApyValue(apyPeriods[0] || "7d");
2807
+ const displayApy = getDisplayApy();
2806
2808
  const hasPosition = vault.userPosition && parseFloat(vault.userPosition.balance) > 0;
2807
2809
  return /* @__PURE__ */ jsxs(
2808
2810
  "button",
@@ -2814,8 +2816,8 @@ function VaultCard({
2814
2816
  borderColor: hasPosition ? "var(--compass-color-primary)" : "var(--compass-color-border)"
2815
2817
  },
2816
2818
  children: [
2817
- /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between", children: [
2818
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2819
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
2820
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
2819
2821
  /* @__PURE__ */ jsx(
2820
2822
  "h3",
2821
2823
  {
@@ -2836,20 +2838,33 @@ function VaultCard({
2836
2838
  }
2837
2839
  )
2838
2840
  ] }),
2839
- showApy && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
2840
- /* @__PURE__ */ jsx(TrendingUp, { size: 14, style: { color: "var(--compass-color-success)" } }),
2841
- /* @__PURE__ */ jsx(
2841
+ showApy && /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-end", children: [
2842
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
2843
+ /* @__PURE__ */ jsx(TrendingUp, { size: 16, style: { color: "var(--compass-color-success)" } }),
2844
+ /* @__PURE__ */ jsx(
2845
+ "span",
2846
+ {
2847
+ className: "font-mono text-lg font-bold",
2848
+ style: { color: "var(--compass-color-success)" },
2849
+ children: formatAPY(displayApy.value)
2850
+ }
2851
+ )
2852
+ ] }),
2853
+ /* @__PURE__ */ jsxs(
2842
2854
  "span",
2843
2855
  {
2844
- className: "font-mono font-semibold",
2845
- style: { color: "var(--compass-color-success)" },
2846
- children: formatAPY(primaryApy)
2856
+ className: "text-xs",
2857
+ style: { color: "var(--compass-color-text-tertiary)" },
2858
+ children: [
2859
+ displayApy.period,
2860
+ " APY"
2861
+ ]
2847
2862
  }
2848
2863
  )
2849
2864
  ] })
2850
2865
  ] }),
2851
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mt-3 pt-3 border-t", style: { borderColor: "var(--compass-color-border)" }, children: [
2852
- showTvl && /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
2866
+ (showTvl || showUserPosition && hasPosition) && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mt-3 pt-3 border-t", style: { borderColor: "var(--compass-color-border)" }, children: [
2867
+ showTvl && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
2853
2868
  /* @__PURE__ */ jsx(
2854
2869
  "span",
2855
2870
  {
@@ -2867,13 +2882,13 @@ function VaultCard({
2867
2882
  }
2868
2883
  )
2869
2884
  ] }),
2870
- showUserPosition && hasPosition && /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-end", children: [
2885
+ showUserPosition && hasPosition && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
2871
2886
  /* @__PURE__ */ jsx(
2872
2887
  "span",
2873
2888
  {
2874
2889
  className: "text-xs",
2875
2890
  style: { color: "var(--compass-color-text-tertiary)" },
2876
- children: "Your Position"
2891
+ children: "Position"
2877
2892
  }
2878
2893
  ),
2879
2894
  /* @__PURE__ */ jsxs(
@@ -3183,7 +3198,7 @@ function VaultsList({
3183
3198
  {
3184
3199
  vault,
3185
3200
  showApy,
3186
- apyPeriods,
3201
+ sortBy,
3187
3202
  showTvl,
3188
3203
  showUserPosition,
3189
3204
  onClick: () => handleVaultClick(vault)
@@ -3232,9 +3247,9 @@ function useAaveData(options = {}) {
3232
3247
  const { client } = useEmbeddableApi();
3233
3248
  const { address } = useEmbeddableWallet();
3234
3249
  const { chainId } = useChain();
3235
- const { sortBy = "supply_apy", assetFilter } = options;
3250
+ const { assetFilter } = options;
3236
3251
  const marketsQuery = useQuery({
3237
- queryKey: ["aaveMarkets", chainId, sortBy, assetFilter],
3252
+ queryKey: ["aaveMarkets", chainId, assetFilter],
3238
3253
  queryFn: async () => {
3239
3254
  const response = await client.earn.earnAaveMarkets({
3240
3255
  chain: chainId
@@ -3255,9 +3270,7 @@ function useAaveData(options = {}) {
3255
3270
  reserveSymbol: symbol,
3256
3271
  underlyingSymbol: symbol,
3257
3272
  supplyApy: chainData.supplyApy?.toString() ?? null,
3258
- borrowApy: chainData.borrowApy?.toString() ?? null,
3259
- // Aave API doesn't provide TVL
3260
- tvlUsd: null
3273
+ borrowApy: chainData.borrowApy?.toString() ?? null
3261
3274
  });
3262
3275
  }
3263
3276
  }
@@ -3323,34 +3336,20 @@ function formatAPY2(apy) {
3323
3336
  const num = parseFloat(apy);
3324
3337
  return `${num.toFixed(2)}%`;
3325
3338
  }
3326
- function formatTVL2(tvl) {
3327
- if (!tvl) return "$0";
3328
- const num = parseFloat(tvl);
3329
- if (num >= 1e9) return `$${(num / 1e9).toFixed(2)}B`;
3330
- if (num >= 1e6) return `$${(num / 1e6).toFixed(2)}M`;
3331
- if (num >= 1e3) return `$${(num / 1e3).toFixed(2)}K`;
3332
- return `$${num.toFixed(2)}`;
3333
- }
3334
3339
  function AaveMarketsList({
3335
3340
  showApy = true,
3336
- showTvl = false,
3337
- // Aave API doesn't provide TVL data
3338
3341
  showUserPosition = true,
3339
3342
  showPnL = true,
3340
3343
  showHistory = true,
3341
3344
  showSearch = true,
3342
- showSort = false,
3343
- // Only one sort option (APY), so hide by default
3344
- defaultSort = "supply_apy",
3345
3345
  assetFilter,
3346
3346
  onMarketSelect,
3347
3347
  onSupply,
3348
3348
  onWithdraw
3349
3349
  }) {
3350
3350
  const [searchQuery, setSearchQuery] = useState("");
3351
- const [sortBy, setSortBy] = useState(defaultSort);
3352
3351
  const [selectedMarket, setSelectedMarket] = useState(null);
3353
- const { markets, isLoading, isError, refetch } = useAaveData({ sortBy, assetFilter });
3352
+ const { markets, isLoading, isError, refetch } = useAaveData({ assetFilter });
3354
3353
  const filteredMarkets = useMemo(() => {
3355
3354
  if (!searchQuery) return markets;
3356
3355
  const query = searchQuery.toLowerCase();
@@ -3378,46 +3377,30 @@ function AaveMarketsList({
3378
3377
  /* @__PURE__ */ jsx(WalletStatus, { compact: true })
3379
3378
  ] })
3380
3379
  ] }),
3381
- (showSearch || showSort) && /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
3382
- showSearch && /* @__PURE__ */ jsxs(
3383
- "div",
3384
- {
3385
- className: "flex-1 flex items-center gap-2 px-3 py-2 rounded-lg border",
3386
- style: {
3387
- backgroundColor: "var(--compass-color-background)",
3388
- borderColor: "var(--compass-color-border)"
3389
- },
3390
- children: [
3391
- /* @__PURE__ */ jsx(Search, { size: 16, style: { color: "var(--compass-color-text-tertiary)" } }),
3392
- /* @__PURE__ */ jsx(
3393
- "input",
3394
- {
3395
- type: "text",
3396
- placeholder: "Search markets...",
3397
- value: searchQuery,
3398
- onChange: (e) => setSearchQuery(e.target.value),
3399
- className: "flex-1 bg-transparent outline-none text-sm",
3400
- style: { color: "var(--compass-color-text)" }
3401
- }
3402
- )
3403
- ]
3404
- }
3405
- ),
3406
- showSort && /* @__PURE__ */ jsx(
3407
- "select",
3408
- {
3409
- value: sortBy,
3410
- onChange: (e) => setSortBy(e.target.value),
3411
- className: "px-3 py-2 rounded-lg border text-sm cursor-pointer",
3412
- style: {
3413
- backgroundColor: "var(--compass-color-background)",
3414
- borderColor: "var(--compass-color-border)",
3415
- color: "var(--compass-color-text)"
3416
- },
3417
- children: /* @__PURE__ */ jsx("option", { value: "supply_apy", children: "Supply APY" })
3418
- }
3419
- )
3420
- ] }),
3380
+ showSearch && /* @__PURE__ */ jsxs(
3381
+ "div",
3382
+ {
3383
+ className: "flex items-center gap-2 px-3 py-2 rounded-lg border",
3384
+ style: {
3385
+ backgroundColor: "var(--compass-color-background)",
3386
+ borderColor: "var(--compass-color-border)"
3387
+ },
3388
+ children: [
3389
+ /* @__PURE__ */ jsx(Search, { size: 16, style: { color: "var(--compass-color-text-tertiary)" } }),
3390
+ /* @__PURE__ */ jsx(
3391
+ "input",
3392
+ {
3393
+ type: "text",
3394
+ placeholder: "Search markets...",
3395
+ value: searchQuery,
3396
+ onChange: (e) => setSearchQuery(e.target.value),
3397
+ className: "flex-1 bg-transparent outline-none text-sm",
3398
+ style: { color: "var(--compass-color-text)" }
3399
+ }
3400
+ )
3401
+ ]
3402
+ }
3403
+ ),
3421
3404
  isLoading ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-12", children: /* @__PURE__ */ jsx(Loader2, { size: 24, className: "animate-spin", style: { color: "var(--compass-color-primary)" } }) }) : isError ? /* @__PURE__ */ jsx(
3422
3405
  "div",
3423
3406
  {
@@ -3481,48 +3464,28 @@ function AaveMarketsList({
3481
3464
  )
3482
3465
  ] })
3483
3466
  ] }),
3484
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mt-3 pt-3 border-t", style: { borderColor: "var(--compass-color-border)" }, children: [
3485
- showTvl && /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
3486
- /* @__PURE__ */ jsx(
3487
- "span",
3488
- {
3489
- className: "text-xs",
3490
- style: { color: "var(--compass-color-text-tertiary)" },
3491
- children: "TVL"
3492
- }
3493
- ),
3494
- /* @__PURE__ */ jsx(
3495
- "span",
3496
- {
3497
- className: "font-mono text-sm",
3498
- style: { color: "var(--compass-color-text-secondary)" },
3499
- children: formatTVL2(market.tvlUsd)
3500
- }
3501
- )
3502
- ] }),
3503
- showUserPosition && hasPosition && /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-end", children: [
3504
- /* @__PURE__ */ jsx(
3505
- "span",
3506
- {
3507
- className: "text-xs",
3508
- style: { color: "var(--compass-color-text-tertiary)" },
3509
- children: "Your Position"
3510
- }
3511
- ),
3512
- /* @__PURE__ */ jsxs(
3513
- "span",
3514
- {
3515
- className: "font-mono text-sm font-medium",
3516
- style: { color: "var(--compass-color-primary)" },
3517
- children: [
3518
- parseFloat(market.userPosition.balance).toFixed(4),
3519
- " ",
3520
- market.underlyingSymbol
3521
- ]
3522
- }
3523
- )
3524
- ] })
3525
- ] })
3467
+ showUserPosition && hasPosition && /* @__PURE__ */ jsx("div", { className: "flex items-center justify-end mt-3 pt-3 border-t", style: { borderColor: "var(--compass-color-border)" }, children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-end", children: [
3468
+ /* @__PURE__ */ jsx(
3469
+ "span",
3470
+ {
3471
+ className: "text-xs",
3472
+ style: { color: "var(--compass-color-text-tertiary)" },
3473
+ children: "Your Position"
3474
+ }
3475
+ ),
3476
+ /* @__PURE__ */ jsxs(
3477
+ "span",
3478
+ {
3479
+ className: "font-mono text-sm font-medium",
3480
+ style: { color: "var(--compass-color-primary)" },
3481
+ children: [
3482
+ parseFloat(market.userPosition.balance).toFixed(4),
3483
+ " ",
3484
+ market.underlyingSymbol
3485
+ ]
3486
+ }
3487
+ )
3488
+ ] }) })
3526
3489
  ]
3527
3490
  },
3528
3491
  market.marketAddress
@@ -3673,7 +3636,7 @@ function formatExpiry(expiry) {
3673
3636
  const date = new Date(expiry);
3674
3637
  return date.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" });
3675
3638
  }
3676
- function formatTVL3(tvl) {
3639
+ function formatTVL2(tvl) {
3677
3640
  if (!tvl) return "$0";
3678
3641
  const num = parseFloat(tvl);
3679
3642
  if (num >= 1e9) return `$${(num / 1e9).toFixed(2)}B`;
@@ -3925,7 +3888,7 @@ function PendleMarketsList({
3925
3888
  {
3926
3889
  className: "font-mono text-sm",
3927
3890
  style: { color: "var(--compass-color-text-secondary)" },
3928
- children: formatTVL3(market.tvlUsd)
3891
+ children: formatTVL2(market.tvlUsd)
3929
3892
  }
3930
3893
  )
3931
3894
  ] }),