@compass-labs/widgets 0.1.41 → 0.1.42

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
@@ -3,7 +3,7 @@ import { useQueryClient, useQuery, QueryClient, QueryClientProvider } from '@tan
3
3
  import { CompassApiSDK } from '@compass-labs/api-sdk';
4
4
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
5
5
  import { arbitrum, base, mainnet } from 'viem/chains';
6
- import { Wallet, Loader2, ArrowDownLeft, ArrowUpRight, Send, ArrowRight, X, CheckCircle, AlertCircle, CreditCard, ExternalLink, XCircle, Check, Copy, LogOut, ChevronDown, ArrowDownUp, ArrowLeftRight, TrendingUp, Plus, Minus, Circle, AlertTriangle, TrendingDown, ChevronRight, ArrowUpCircle, ArrowDownCircle, RotateCcw, Equal, ChevronUp, Inbox, Percent, Clock, Calendar } from 'lucide-react';
6
+ import { Wallet, Loader2, ArrowDownLeft, ArrowUpRight, Send, ArrowRight, X, CheckCircle, AlertCircle, CreditCard, ExternalLink, XCircle, Check, Copy, LogOut, ChevronDown, ArrowDownUp, ArrowLeftRight, TrendingUp, Plus, Minus, Circle, ChevronRight, AlertTriangle, TrendingDown, ArrowUpCircle, ArrowDownCircle, RotateCcw, Equal, ChevronUp, Inbox, Percent, Clock, Calendar } from 'lucide-react';
7
7
  import { isAddress, encodeFunctionData, parseUnits } from 'viem';
8
8
 
9
9
  // src/provider/CompassProvider.tsx
@@ -172,8 +172,10 @@ function EarnAccountProvider({ children }) {
172
172
  throw new Error(error.error || "Failed to create earn account");
173
173
  }
174
174
  const result = await response.json();
175
- await queryClient.invalidateQueries({
176
- queryKey: ["earnAccount", address, chainId]
175
+ queryClient.setQueryData(["earnAccount", address, chainId], {
176
+ earnAccountAddress: result.earnAccountAddress,
177
+ isDeployed: true,
178
+ needsCreation: false
177
179
  });
178
180
  return result.earnAccountAddress;
179
181
  } catch (error) {
@@ -255,8 +257,10 @@ function CreditAccountProvider({ children }) {
255
257
  throw new Error(error.error || "Failed to create credit account");
256
258
  }
257
259
  const result = await response.json();
258
- await queryClient.invalidateQueries({
259
- queryKey: ["creditAccount", address, chainId]
260
+ queryClient.setQueryData(["creditAccount", address, chainId], {
261
+ creditAccountAddress: result.creditAccountAddress,
262
+ isDeployed: true,
263
+ needsCreation: false
260
264
  });
261
265
  return result.creditAccountAddress;
262
266
  } catch (error) {
@@ -1201,7 +1205,7 @@ function WalletStatus({
1201
1205
  },
1202
1206
  children: [
1203
1207
  /* @__PURE__ */ jsx(Wallet, { size: compact ? 14 : 16 }),
1204
- !compact && /* @__PURE__ */ jsx("span", { className: "text-sm", children: "Connect Wallet" })
1208
+ !compact && /* @__PURE__ */ jsx("span", { className: "text-sm", children: "Sign in" })
1205
1209
  ]
1206
1210
  }
1207
1211
  );
@@ -5284,9 +5288,6 @@ function EarnAccount({
5284
5288
  );
5285
5289
  return Math.min(weightedSum / earnAccountTotal, 100);
5286
5290
  }
5287
- if (allMarkets.length > 0) {
5288
- return Math.min(Math.max(...allMarkets.map((m) => m.apy || 0)), 100);
5289
- }
5290
5291
  return 0;
5291
5292
  })();
5292
5293
  const needsActionSwap = selectedMarket ? selectedToken !== selectedMarket.underlyingToken : false;
@@ -5740,7 +5741,7 @@ function EarnAccount({
5740
5741
  },
5741
5742
  children: [
5742
5743
  /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center", style: { width: "100%", marginBottom: "12px", gap: "8px" }, children: [
5743
- showInterestRate && bestApy > 0 && /* @__PURE__ */ jsxs(
5744
+ showInterestRate && /* @__PURE__ */ jsxs(
5744
5745
  "div",
5745
5746
  {
5746
5747
  className: "flex items-center",
@@ -5865,11 +5866,11 @@ function EarnAccount({
5865
5866
  ] }) : "No active positions" })
5866
5867
  }
5867
5868
  ),
5868
- (balanceTokens.length > 0 || showTopUpButton) && /* @__PURE__ */ jsxs("div", { className: "flex", style: { gap: "8px", marginTop: "12px" }, children: [
5869
+ /* @__PURE__ */ jsxs("div", { className: "flex", style: { gap: "8px", marginTop: "12px" }, children: [
5869
5870
  showTopUpButton && /* @__PURE__ */ jsxs(
5870
5871
  "button",
5871
5872
  {
5872
- onClick: () => setIsFundModalOpen(true),
5873
+ onClick: () => isConnected ? setIsFundModalOpen(true) : login?.(),
5873
5874
  "aria-label": "Add money",
5874
5875
  className: "flex items-center justify-center",
5875
5876
  style: {
@@ -5887,10 +5888,10 @@ function EarnAccount({
5887
5888
  ]
5888
5889
  }
5889
5890
  ),
5890
- balanceTokens.length > 0 && /* @__PURE__ */ jsxs(
5891
+ /* @__PURE__ */ jsxs(
5891
5892
  "button",
5892
5893
  {
5893
- onClick: () => setIsSwapModalOpen(true),
5894
+ onClick: () => isConnected ? setIsSwapModalOpen(true) : login?.(),
5894
5895
  "aria-label": "Swap tokens",
5895
5896
  className: "flex items-center justify-center",
5896
5897
  style: {
@@ -6166,7 +6167,7 @@ function EarnAccount({
6166
6167
  },
6167
6168
  children: !isConnected ? /* @__PURE__ */ jsxs("span", { className: "flex items-center justify-center", style: { gap: "8px" }, children: [
6168
6169
  /* @__PURE__ */ jsx(Wallet, { size: 18 }),
6169
- "Connect Wallet"
6170
+ "Sign in"
6170
6171
  ] }) : isProcessing ? /* @__PURE__ */ jsxs("span", { className: "flex items-center justify-center", style: { gap: "4px", flexDirection: "column" }, children: [
6171
6172
  /* @__PURE__ */ jsxs("span", { className: "flex items-center justify-center", style: { gap: "8px" }, children: [
6172
6173
  /* @__PURE__ */ jsx(Loader2, { size: 16, className: "animate-spin" }),
@@ -9299,29 +9300,11 @@ function CreditAccount({
9299
9300
  ] }) : /* @__PURE__ */ jsx("span", { style: { color: "var(--compass-color-text-tertiary)", fontSize: "0.875rem" }, children: "No active positions" })
9300
9301
  }
9301
9302
  ),
9302
- !isConnected ? /* @__PURE__ */ jsx(
9303
- "button",
9304
- {
9305
- onClick: () => login?.(),
9306
- className: "flex items-center justify-center font-bold w-full",
9307
- style: {
9308
- backgroundColor: "var(--compass-color-primary)",
9309
- color: "var(--compass-color-primary-text, white)",
9310
- borderRadius: "var(--compass-border-radius-lg)",
9311
- padding: "12px",
9312
- minHeight: "44px",
9313
- fontSize: "1rem",
9314
- marginTop: "8px",
9315
- border: "none",
9316
- transition: "all 200ms ease"
9317
- },
9318
- children: "Connect Wallet"
9319
- }
9320
- ) : isDeployed && (balancesWithUsd.length > 0 || showTopUpButton) ? /* @__PURE__ */ jsxs("div", { className: "flex", style: { gap: "8px", marginTop: "8px" }, children: [
9303
+ /* @__PURE__ */ jsxs("div", { className: "flex", style: { gap: "8px", marginTop: "8px" }, children: [
9321
9304
  showTopUpButton && /* @__PURE__ */ jsxs(
9322
9305
  "button",
9323
9306
  {
9324
- onClick: () => setShowTopUp(true),
9307
+ onClick: () => isConnected ? setShowTopUp(true) : login?.(),
9325
9308
  className: "flex items-center justify-center",
9326
9309
  style: {
9327
9310
  height: "36px",
@@ -9338,10 +9321,10 @@ function CreditAccount({
9338
9321
  ]
9339
9322
  }
9340
9323
  ),
9341
- balancesWithUsd.length > 0 && /* @__PURE__ */ jsxs(
9324
+ /* @__PURE__ */ jsxs(
9342
9325
  "button",
9343
9326
  {
9344
- onClick: () => setShowSwap(true),
9327
+ onClick: () => isConnected ? setShowSwap(true) : login?.(),
9345
9328
  className: "flex items-center justify-center",
9346
9329
  style: {
9347
9330
  height: "36px",
@@ -9358,7 +9341,7 @@ function CreditAccount({
9358
9341
  ]
9359
9342
  }
9360
9343
  )
9361
- ] }) : null
9344
+ ] })
9362
9345
  ]
9363
9346
  }
9364
9347
  ),
@@ -9375,7 +9358,7 @@ function CreditAccount({
9375
9358
  flex: 1
9376
9359
  },
9377
9360
  children: [
9378
- isDeployed && /* @__PURE__ */ jsx(
9361
+ isDeployed ? /* @__PURE__ */ jsx(
9379
9362
  PositionsView,
9380
9363
  {
9381
9364
  allowedCollateralTokens,
@@ -9397,8 +9380,100 @@ function CreditAccount({
9397
9380
  setShowWithdraw(true);
9398
9381
  }
9399
9382
  }
9400
- ),
9401
- /* @__PURE__ */ jsx(WidgetFooter, {})
9383
+ ) : /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "8px" }, children: [
9384
+ /* @__PURE__ */ jsxs(
9385
+ "button",
9386
+ {
9387
+ type: "button",
9388
+ onClick: () => login?.(),
9389
+ className: "w-full p-3 flex items-center justify-between transition-opacity hover:opacity-80",
9390
+ style: {
9391
+ backgroundColor: "var(--compass-color-surface)",
9392
+ border: "1.5px solid var(--compass-color-border)",
9393
+ borderRadius: "var(--compass-border-radius-xl)"
9394
+ },
9395
+ children: [
9396
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-start gap-0.5", children: [
9397
+ /* @__PURE__ */ jsx(
9398
+ "span",
9399
+ {
9400
+ className: "text-xs font-medium uppercase tracking-wide",
9401
+ style: { color: "var(--compass-color-text-tertiary)" },
9402
+ children: "Collateral"
9403
+ }
9404
+ ),
9405
+ /* @__PURE__ */ jsx(
9406
+ "span",
9407
+ {
9408
+ className: "text-lg font-semibold tabular-nums",
9409
+ style: { color: "var(--compass-color-text)" },
9410
+ children: "$0.00"
9411
+ }
9412
+ )
9413
+ ] }),
9414
+ /* @__PURE__ */ jsx(ChevronRight, { className: "h-5 w-5", style: { color: "var(--compass-color-text-tertiary)" } })
9415
+ ]
9416
+ }
9417
+ ),
9418
+ /* @__PURE__ */ jsxs(
9419
+ "button",
9420
+ {
9421
+ type: "button",
9422
+ onClick: () => login?.(),
9423
+ className: "w-full p-3 flex items-center justify-between transition-opacity hover:opacity-80",
9424
+ style: {
9425
+ backgroundColor: "var(--compass-color-surface)",
9426
+ border: "1.5px solid var(--compass-color-border)",
9427
+ borderRadius: "var(--compass-border-radius-xl)"
9428
+ },
9429
+ children: [
9430
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-start gap-0.5", children: [
9431
+ /* @__PURE__ */ jsx(
9432
+ "span",
9433
+ {
9434
+ className: "text-xs font-medium uppercase tracking-wide",
9435
+ style: { color: "var(--compass-color-text-tertiary)" },
9436
+ children: "Debt"
9437
+ }
9438
+ ),
9439
+ /* @__PURE__ */ jsx(
9440
+ "span",
9441
+ {
9442
+ className: "text-lg font-semibold tabular-nums",
9443
+ style: { color: "var(--compass-color-text)" },
9444
+ children: "$0.00"
9445
+ }
9446
+ )
9447
+ ] }),
9448
+ /* @__PURE__ */ jsx(ChevronRight, { className: "h-5 w-5", style: { color: "var(--compass-color-text-tertiary)" } })
9449
+ ]
9450
+ }
9451
+ )
9452
+ ] }),
9453
+ /* @__PURE__ */ jsxs("div", { style: { marginTop: "auto", display: "flex", flexDirection: "column", gap: "8px" }, children: [
9454
+ !isConnected && /* @__PURE__ */ jsx(
9455
+ "button",
9456
+ {
9457
+ onClick: () => login?.(),
9458
+ className: "w-full font-bold",
9459
+ style: {
9460
+ backgroundColor: "var(--compass-color-primary)",
9461
+ color: "var(--compass-color-primary-text, white)",
9462
+ borderRadius: "var(--compass-border-radius-lg)",
9463
+ padding: "12px",
9464
+ minHeight: "44px",
9465
+ fontSize: "1rem",
9466
+ transition: "all 200ms ease",
9467
+ border: "none"
9468
+ },
9469
+ children: /* @__PURE__ */ jsxs("span", { className: "flex items-center justify-center", style: { gap: "8px" }, children: [
9470
+ /* @__PURE__ */ jsx(Wallet, { size: 18 }),
9471
+ "Sign in"
9472
+ ] })
9473
+ }
9474
+ ),
9475
+ /* @__PURE__ */ jsx(WidgetFooter, {})
9476
+ ] })
9402
9477
  ]
9403
9478
  }
9404
9479
  )
@@ -11699,7 +11774,7 @@ function RebalancingWidget({
11699
11774
  fontSize: "0.875rem",
11700
11775
  border: "none"
11701
11776
  },
11702
- children: "Connect Wallet"
11777
+ children: "Sign in"
11703
11778
  }
11704
11779
  )
11705
11780
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -12042,7 +12117,7 @@ function RebalancingWidget({
12042
12117
  border: "none",
12043
12118
  opacity: isConnected && (depositTxState.status !== "idle" && depositTxState.status !== "confirmed" && depositTxState.status !== "failed" || !selectedMarket || !depositAmount || parseFloat(depositAmount) <= 0 || parseFloat(depositAmount) > earnBalancesQuery) ? 0.4 : 1
12044
12119
  },
12045
- children: !isConnected ? "Connect Wallet" : depositTxState.status !== "idle" && depositTxState.status !== "confirmed" && depositTxState.status !== "failed" ? /* @__PURE__ */ jsxs("span", { className: "flex items-center justify-center", style: { gap: "8px" }, children: [
12120
+ children: !isConnected ? "Sign in" : depositTxState.status !== "idle" && depositTxState.status !== "confirmed" && depositTxState.status !== "failed" ? /* @__PURE__ */ jsxs("span", { className: "flex items-center justify-center", style: { gap: "8px" }, children: [
12046
12121
  /* @__PURE__ */ jsx(Loader2, { size: 16, className: "animate-spin" }),
12047
12122
  "Processing..."
12048
12123
  ] }) : !selectedMarket ? "Select a market" : needsSwap ? "Swap & Deposit" : "Deposit"