@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.d.mts CHANGED
@@ -341,7 +341,7 @@ interface WalletAdapter {
341
341
  switchChain?: (chainId: number) => Promise<void>;
342
342
  /**
343
343
  * Trigger wallet connection (optional)
344
- * If provided, widgets will show a "Connect Wallet" button
344
+ * If provided, widgets will show a "Sign in" button
345
345
  */
346
346
  login?: () => void;
347
347
  /**
package/dist/index.d.ts CHANGED
@@ -341,7 +341,7 @@ interface WalletAdapter {
341
341
  switchChain?: (chainId: number) => Promise<void>;
342
342
  /**
343
343
  * Trigger wallet connection (optional)
344
- * If provided, widgets will show a "Connect Wallet" button
344
+ * If provided, widgets will show a "Sign in" button
345
345
  */
346
346
  login?: () => void;
347
347
  /**
package/dist/index.js CHANGED
@@ -174,8 +174,10 @@ function EarnAccountProvider({ children }) {
174
174
  throw new Error(error.error || "Failed to create earn account");
175
175
  }
176
176
  const result = await response.json();
177
- await queryClient.invalidateQueries({
178
- queryKey: ["earnAccount", address, chainId]
177
+ queryClient.setQueryData(["earnAccount", address, chainId], {
178
+ earnAccountAddress: result.earnAccountAddress,
179
+ isDeployed: true,
180
+ needsCreation: false
179
181
  });
180
182
  return result.earnAccountAddress;
181
183
  } catch (error) {
@@ -257,8 +259,10 @@ function CreditAccountProvider({ children }) {
257
259
  throw new Error(error.error || "Failed to create credit account");
258
260
  }
259
261
  const result = await response.json();
260
- await queryClient.invalidateQueries({
261
- queryKey: ["creditAccount", address, chainId]
262
+ queryClient.setQueryData(["creditAccount", address, chainId], {
263
+ creditAccountAddress: result.creditAccountAddress,
264
+ isDeployed: true,
265
+ needsCreation: false
262
266
  });
263
267
  return result.creditAccountAddress;
264
268
  } catch (error) {
@@ -1203,7 +1207,7 @@ function WalletStatus({
1203
1207
  },
1204
1208
  children: [
1205
1209
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Wallet, { size: compact ? 14 : 16 }),
1206
- !compact && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm", children: "Connect Wallet" })
1210
+ !compact && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm", children: "Sign in" })
1207
1211
  ]
1208
1212
  }
1209
1213
  );
@@ -5286,9 +5290,6 @@ function EarnAccount({
5286
5290
  );
5287
5291
  return Math.min(weightedSum / earnAccountTotal, 100);
5288
5292
  }
5289
- if (allMarkets.length > 0) {
5290
- return Math.min(Math.max(...allMarkets.map((m) => m.apy || 0)), 100);
5291
- }
5292
5293
  return 0;
5293
5294
  })();
5294
5295
  const needsActionSwap = selectedMarket ? selectedToken !== selectedMarket.underlyingToken : false;
@@ -5742,7 +5743,7 @@ function EarnAccount({
5742
5743
  },
5743
5744
  children: [
5744
5745
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center", style: { width: "100%", marginBottom: "12px", gap: "8px" }, children: [
5745
- showInterestRate && bestApy > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
5746
+ showInterestRate && /* @__PURE__ */ jsxRuntime.jsxs(
5746
5747
  "div",
5747
5748
  {
5748
5749
  className: "flex items-center",
@@ -5867,11 +5868,11 @@ function EarnAccount({
5867
5868
  ] }) : "No active positions" })
5868
5869
  }
5869
5870
  ),
5870
- (balanceTokens.length > 0 || showTopUpButton) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex", style: { gap: "8px", marginTop: "12px" }, children: [
5871
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex", style: { gap: "8px", marginTop: "12px" }, children: [
5871
5872
  showTopUpButton && /* @__PURE__ */ jsxRuntime.jsxs(
5872
5873
  "button",
5873
5874
  {
5874
- onClick: () => setIsFundModalOpen(true),
5875
+ onClick: () => isConnected ? setIsFundModalOpen(true) : login?.(),
5875
5876
  "aria-label": "Add money",
5876
5877
  className: "flex items-center justify-center",
5877
5878
  style: {
@@ -5889,10 +5890,10 @@ function EarnAccount({
5889
5890
  ]
5890
5891
  }
5891
5892
  ),
5892
- balanceTokens.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
5893
+ /* @__PURE__ */ jsxRuntime.jsxs(
5893
5894
  "button",
5894
5895
  {
5895
- onClick: () => setIsSwapModalOpen(true),
5896
+ onClick: () => isConnected ? setIsSwapModalOpen(true) : login?.(),
5896
5897
  "aria-label": "Swap tokens",
5897
5898
  className: "flex items-center justify-center",
5898
5899
  style: {
@@ -6168,7 +6169,7 @@ function EarnAccount({
6168
6169
  },
6169
6170
  children: !isConnected ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center justify-center", style: { gap: "8px" }, children: [
6170
6171
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Wallet, { size: 18 }),
6171
- "Connect Wallet"
6172
+ "Sign in"
6172
6173
  ] }) : isProcessing ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center justify-center", style: { gap: "4px", flexDirection: "column" }, children: [
6173
6174
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center justify-center", style: { gap: "8px" }, children: [
6174
6175
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { size: 16, className: "animate-spin" }),
@@ -9301,29 +9302,11 @@ function CreditAccount({
9301
9302
  ] }) : /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "var(--compass-color-text-tertiary)", fontSize: "0.875rem" }, children: "No active positions" })
9302
9303
  }
9303
9304
  ),
9304
- !isConnected ? /* @__PURE__ */ jsxRuntime.jsx(
9305
- "button",
9306
- {
9307
- onClick: () => login?.(),
9308
- className: "flex items-center justify-center font-bold w-full",
9309
- style: {
9310
- backgroundColor: "var(--compass-color-primary)",
9311
- color: "var(--compass-color-primary-text, white)",
9312
- borderRadius: "var(--compass-border-radius-lg)",
9313
- padding: "12px",
9314
- minHeight: "44px",
9315
- fontSize: "1rem",
9316
- marginTop: "8px",
9317
- border: "none",
9318
- transition: "all 200ms ease"
9319
- },
9320
- children: "Connect Wallet"
9321
- }
9322
- ) : isDeployed && (balancesWithUsd.length > 0 || showTopUpButton) ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex", style: { gap: "8px", marginTop: "8px" }, children: [
9305
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex", style: { gap: "8px", marginTop: "8px" }, children: [
9323
9306
  showTopUpButton && /* @__PURE__ */ jsxRuntime.jsxs(
9324
9307
  "button",
9325
9308
  {
9326
- onClick: () => setShowTopUp(true),
9309
+ onClick: () => isConnected ? setShowTopUp(true) : login?.(),
9327
9310
  className: "flex items-center justify-center",
9328
9311
  style: {
9329
9312
  height: "36px",
@@ -9340,10 +9323,10 @@ function CreditAccount({
9340
9323
  ]
9341
9324
  }
9342
9325
  ),
9343
- balancesWithUsd.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
9326
+ /* @__PURE__ */ jsxRuntime.jsxs(
9344
9327
  "button",
9345
9328
  {
9346
- onClick: () => setShowSwap(true),
9329
+ onClick: () => isConnected ? setShowSwap(true) : login?.(),
9347
9330
  className: "flex items-center justify-center",
9348
9331
  style: {
9349
9332
  height: "36px",
@@ -9360,7 +9343,7 @@ function CreditAccount({
9360
9343
  ]
9361
9344
  }
9362
9345
  )
9363
- ] }) : null
9346
+ ] })
9364
9347
  ]
9365
9348
  }
9366
9349
  ),
@@ -9377,7 +9360,7 @@ function CreditAccount({
9377
9360
  flex: 1
9378
9361
  },
9379
9362
  children: [
9380
- isDeployed && /* @__PURE__ */ jsxRuntime.jsx(
9363
+ isDeployed ? /* @__PURE__ */ jsxRuntime.jsx(
9381
9364
  PositionsView,
9382
9365
  {
9383
9366
  allowedCollateralTokens,
@@ -9399,8 +9382,100 @@ function CreditAccount({
9399
9382
  setShowWithdraw(true);
9400
9383
  }
9401
9384
  }
9402
- ),
9403
- /* @__PURE__ */ jsxRuntime.jsx(WidgetFooter, {})
9385
+ ) : /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "8px" }, children: [
9386
+ /* @__PURE__ */ jsxRuntime.jsxs(
9387
+ "button",
9388
+ {
9389
+ type: "button",
9390
+ onClick: () => login?.(),
9391
+ className: "w-full p-3 flex items-center justify-between transition-opacity hover:opacity-80",
9392
+ style: {
9393
+ backgroundColor: "var(--compass-color-surface)",
9394
+ border: "1.5px solid var(--compass-color-border)",
9395
+ borderRadius: "var(--compass-border-radius-xl)"
9396
+ },
9397
+ children: [
9398
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-start gap-0.5", children: [
9399
+ /* @__PURE__ */ jsxRuntime.jsx(
9400
+ "span",
9401
+ {
9402
+ className: "text-xs font-medium uppercase tracking-wide",
9403
+ style: { color: "var(--compass-color-text-tertiary)" },
9404
+ children: "Collateral"
9405
+ }
9406
+ ),
9407
+ /* @__PURE__ */ jsxRuntime.jsx(
9408
+ "span",
9409
+ {
9410
+ className: "text-lg font-semibold tabular-nums",
9411
+ style: { color: "var(--compass-color-text)" },
9412
+ children: "$0.00"
9413
+ }
9414
+ )
9415
+ ] }),
9416
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "h-5 w-5", style: { color: "var(--compass-color-text-tertiary)" } })
9417
+ ]
9418
+ }
9419
+ ),
9420
+ /* @__PURE__ */ jsxRuntime.jsxs(
9421
+ "button",
9422
+ {
9423
+ type: "button",
9424
+ onClick: () => login?.(),
9425
+ className: "w-full p-3 flex items-center justify-between transition-opacity hover:opacity-80",
9426
+ style: {
9427
+ backgroundColor: "var(--compass-color-surface)",
9428
+ border: "1.5px solid var(--compass-color-border)",
9429
+ borderRadius: "var(--compass-border-radius-xl)"
9430
+ },
9431
+ children: [
9432
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-start gap-0.5", children: [
9433
+ /* @__PURE__ */ jsxRuntime.jsx(
9434
+ "span",
9435
+ {
9436
+ className: "text-xs font-medium uppercase tracking-wide",
9437
+ style: { color: "var(--compass-color-text-tertiary)" },
9438
+ children: "Debt"
9439
+ }
9440
+ ),
9441
+ /* @__PURE__ */ jsxRuntime.jsx(
9442
+ "span",
9443
+ {
9444
+ className: "text-lg font-semibold tabular-nums",
9445
+ style: { color: "var(--compass-color-text)" },
9446
+ children: "$0.00"
9447
+ }
9448
+ )
9449
+ ] }),
9450
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "h-5 w-5", style: { color: "var(--compass-color-text-tertiary)" } })
9451
+ ]
9452
+ }
9453
+ )
9454
+ ] }),
9455
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginTop: "auto", display: "flex", flexDirection: "column", gap: "8px" }, children: [
9456
+ !isConnected && /* @__PURE__ */ jsxRuntime.jsx(
9457
+ "button",
9458
+ {
9459
+ onClick: () => login?.(),
9460
+ className: "w-full font-bold",
9461
+ style: {
9462
+ backgroundColor: "var(--compass-color-primary)",
9463
+ color: "var(--compass-color-primary-text, white)",
9464
+ borderRadius: "var(--compass-border-radius-lg)",
9465
+ padding: "12px",
9466
+ minHeight: "44px",
9467
+ fontSize: "1rem",
9468
+ transition: "all 200ms ease",
9469
+ border: "none"
9470
+ },
9471
+ children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center justify-center", style: { gap: "8px" }, children: [
9472
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Wallet, { size: 18 }),
9473
+ "Sign in"
9474
+ ] })
9475
+ }
9476
+ ),
9477
+ /* @__PURE__ */ jsxRuntime.jsx(WidgetFooter, {})
9478
+ ] })
9404
9479
  ]
9405
9480
  }
9406
9481
  )
@@ -11701,7 +11776,7 @@ function RebalancingWidget({
11701
11776
  fontSize: "0.875rem",
11702
11777
  border: "none"
11703
11778
  },
11704
- children: "Connect Wallet"
11779
+ children: "Sign in"
11705
11780
  }
11706
11781
  )
11707
11782
  ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
@@ -12044,7 +12119,7 @@ function RebalancingWidget({
12044
12119
  border: "none",
12045
12120
  opacity: isConnected && (depositTxState.status !== "idle" && depositTxState.status !== "confirmed" && depositTxState.status !== "failed" || !selectedMarket || !depositAmount || parseFloat(depositAmount) <= 0 || parseFloat(depositAmount) > earnBalancesQuery) ? 0.4 : 1
12046
12121
  },
12047
- children: !isConnected ? "Connect Wallet" : depositTxState.status !== "idle" && depositTxState.status !== "confirmed" && depositTxState.status !== "failed" ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center justify-center", style: { gap: "8px" }, children: [
12122
+ children: !isConnected ? "Sign in" : depositTxState.status !== "idle" && depositTxState.status !== "confirmed" && depositTxState.status !== "failed" ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center justify-center", style: { gap: "8px" }, children: [
12048
12123
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { size: 16, className: "animate-spin" }),
12049
12124
  "Processing..."
12050
12125
  ] }) : !selectedMarket ? "Select a market" : needsSwap ? "Swap & Deposit" : "Deposit"