@loafmarkets/ui 0.1.131 → 0.1.132

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 CHANGED
@@ -11828,6 +11828,42 @@ function PortfolioActivityPanel({
11828
11828
  const [activeTab, setActiveTab] = React5.useState(resolvedDefaultTab);
11829
11829
  const [activityPage, setActivityPage] = React5.useState(0);
11830
11830
  const [pendingCancelOrderId, setPendingCancelOrderId] = React5.useState(null);
11831
+ const [posSortKey, setPosSortKey] = React5.useState("asset");
11832
+ const [posSortAsc, setPosSortAsc] = React5.useState(true);
11833
+ const handlePosSort = (key) => {
11834
+ if (posSortKey === key) {
11835
+ setPosSortAsc((v) => !v);
11836
+ } else {
11837
+ setPosSortKey(key);
11838
+ setPosSortAsc(key === "asset");
11839
+ }
11840
+ };
11841
+ const sortedPositions = React5.useMemo(() => {
11842
+ const arr = [...positions];
11843
+ const dir = posSortAsc ? 1 : -1;
11844
+ arr.sort((a, b) => {
11845
+ switch (posSortKey) {
11846
+ case "asset":
11847
+ return dir * a.tokenName.localeCompare(b.tokenName);
11848
+ case "units":
11849
+ return dir * (a.quantity - b.quantity);
11850
+ case "value":
11851
+ return dir * (a.quantity * a.marketPrice - b.quantity * b.marketPrice);
11852
+ case "avgPrice":
11853
+ return dir * (a.averageEntryPrice - b.averageEntryPrice);
11854
+ case "currentPrice":
11855
+ return dir * (a.marketPrice - b.marketPrice);
11856
+ case "pnl": {
11857
+ const pnlA = a.propertyPnlPercent ?? a.percentChange ?? 0;
11858
+ const pnlB = b.propertyPnlPercent ?? b.percentChange ?? 0;
11859
+ return dir * (pnlA - pnlB);
11860
+ }
11861
+ default:
11862
+ return 0;
11863
+ }
11864
+ });
11865
+ return arr;
11866
+ }, [positions, posSortKey, posSortAsc]);
11831
11867
  const activeTabTotal = React5.useMemo(() => {
11832
11868
  switch (activeTab) {
11833
11869
  case "positions":
@@ -11910,15 +11946,33 @@ function PortfolioActivityPanel({
11910
11946
  positions.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(EmptyState, { children: "No positions yet. Subscribe to an offering or buy on the secondary market." }),
11911
11947
  positions.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
11912
11948
  /* @__PURE__ */ jsxRuntime.jsxs(PositionsHeader, { $hasClose: !!onClosePosition, children: [
11913
- /* @__PURE__ */ jsxRuntime.jsx(PositionsHeaderCell, { children: "Asset" }),
11914
- /* @__PURE__ */ jsxRuntime.jsx(PositionsHeaderCell, { children: "Units" }),
11915
- /* @__PURE__ */ jsxRuntime.jsx(PositionsHeaderCell, { children: "Position Value" }),
11916
- /* @__PURE__ */ jsxRuntime.jsx(PositionsHeaderCell, { children: "Avg Price" }),
11917
- /* @__PURE__ */ jsxRuntime.jsx(PositionsHeaderCell, { children: "Current Price" }),
11918
- /* @__PURE__ */ jsxRuntime.jsx(PositionsHeaderCell, { children: "PNL (%)" }),
11949
+ /* @__PURE__ */ jsxRuntime.jsxs(SortableHeaderCell, { $active: posSortKey === "asset", onClick: () => handlePosSort("asset"), children: [
11950
+ "Asset ",
11951
+ posSortKey === "asset" && (posSortAsc ? "\u2191" : "\u2193")
11952
+ ] }),
11953
+ /* @__PURE__ */ jsxRuntime.jsxs(SortableHeaderCell, { $active: posSortKey === "units", onClick: () => handlePosSort("units"), children: [
11954
+ "Units ",
11955
+ posSortKey === "units" && (posSortAsc ? "\u2191" : "\u2193")
11956
+ ] }),
11957
+ /* @__PURE__ */ jsxRuntime.jsxs(SortableHeaderCell, { $active: posSortKey === "value", onClick: () => handlePosSort("value"), children: [
11958
+ "Position Value ",
11959
+ posSortKey === "value" && (posSortAsc ? "\u2191" : "\u2193")
11960
+ ] }),
11961
+ /* @__PURE__ */ jsxRuntime.jsxs(SortableHeaderCell, { $active: posSortKey === "avgPrice", onClick: () => handlePosSort("avgPrice"), children: [
11962
+ "Avg Price ",
11963
+ posSortKey === "avgPrice" && (posSortAsc ? "\u2191" : "\u2193")
11964
+ ] }),
11965
+ /* @__PURE__ */ jsxRuntime.jsxs(SortableHeaderCell, { $active: posSortKey === "currentPrice", onClick: () => handlePosSort("currentPrice"), children: [
11966
+ "Current Price ",
11967
+ posSortKey === "currentPrice" && (posSortAsc ? "\u2191" : "\u2193")
11968
+ ] }),
11969
+ /* @__PURE__ */ jsxRuntime.jsxs(SortableHeaderCell, { $active: posSortKey === "pnl", onClick: () => handlePosSort("pnl"), children: [
11970
+ "PNL (%) ",
11971
+ posSortKey === "pnl" && (posSortAsc ? "\u2191" : "\u2193")
11972
+ ] }),
11919
11973
  onClosePosition && /* @__PURE__ */ jsxRuntime.jsx(PositionsHeaderCell, { children: "Close" })
11920
11974
  ] }),
11921
- pageSlice(positions).map((pos) => {
11975
+ pageSlice(sortedPositions).map((pos) => {
11922
11976
  const currentValue = pos.quantity * pos.marketPrice;
11923
11977
  const costBasis = pos.quantity * pos.averageEntryPrice;
11924
11978
  const pnl = pos.propertyPnl ?? currentValue - costBasis;
@@ -12347,6 +12401,16 @@ var PositionsHeaderCell = styled25__default.default.div`
12347
12401
  text-align: ${(p) => p.$align || "left"};
12348
12402
  white-space: nowrap;
12349
12403
  `;
12404
+ var SortableHeaderCell = styled25__default.default.div`
12405
+ font-size: 0.68rem;
12406
+ font-weight: 500;
12407
+ color: ${(p) => p.$active ? "rgba(255, 255, 255, 0.7)" : "rgba(255, 255, 255, 0.4)"};
12408
+ white-space: nowrap;
12409
+ cursor: pointer;
12410
+ user-select: none;
12411
+ transition: color 0.15s ease;
12412
+ &:hover { color: rgba(255, 255, 255, 0.7); }
12413
+ `;
12350
12414
  var PositionsRow = styled25__default.default.div`
12351
12415
  display: grid;
12352
12416
  grid-template-columns: ${(p) => p.$hasClose ? "1.4fr 0.8fr 1fr 1fr 1fr 1.1fr 110px" : "1.2fr 0.8fr 1fr 1fr 1fr 1.2fr"};