@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.mjs CHANGED
@@ -11802,6 +11802,42 @@ function PortfolioActivityPanel({
11802
11802
  const [activeTab, setActiveTab] = useState(resolvedDefaultTab);
11803
11803
  const [activityPage, setActivityPage] = useState(0);
11804
11804
  const [pendingCancelOrderId, setPendingCancelOrderId] = useState(null);
11805
+ const [posSortKey, setPosSortKey] = useState("asset");
11806
+ const [posSortAsc, setPosSortAsc] = useState(true);
11807
+ const handlePosSort = (key) => {
11808
+ if (posSortKey === key) {
11809
+ setPosSortAsc((v) => !v);
11810
+ } else {
11811
+ setPosSortKey(key);
11812
+ setPosSortAsc(key === "asset");
11813
+ }
11814
+ };
11815
+ const sortedPositions = useMemo(() => {
11816
+ const arr = [...positions];
11817
+ const dir = posSortAsc ? 1 : -1;
11818
+ arr.sort((a, b) => {
11819
+ switch (posSortKey) {
11820
+ case "asset":
11821
+ return dir * a.tokenName.localeCompare(b.tokenName);
11822
+ case "units":
11823
+ return dir * (a.quantity - b.quantity);
11824
+ case "value":
11825
+ return dir * (a.quantity * a.marketPrice - b.quantity * b.marketPrice);
11826
+ case "avgPrice":
11827
+ return dir * (a.averageEntryPrice - b.averageEntryPrice);
11828
+ case "currentPrice":
11829
+ return dir * (a.marketPrice - b.marketPrice);
11830
+ case "pnl": {
11831
+ const pnlA = a.propertyPnlPercent ?? a.percentChange ?? 0;
11832
+ const pnlB = b.propertyPnlPercent ?? b.percentChange ?? 0;
11833
+ return dir * (pnlA - pnlB);
11834
+ }
11835
+ default:
11836
+ return 0;
11837
+ }
11838
+ });
11839
+ return arr;
11840
+ }, [positions, posSortKey, posSortAsc]);
11805
11841
  const activeTabTotal = useMemo(() => {
11806
11842
  switch (activeTab) {
11807
11843
  case "positions":
@@ -11884,15 +11920,33 @@ function PortfolioActivityPanel({
11884
11920
  positions.length === 0 && /* @__PURE__ */ jsx(EmptyState, { children: "No positions yet. Subscribe to an offering or buy on the secondary market." }),
11885
11921
  positions.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
11886
11922
  /* @__PURE__ */ jsxs(PositionsHeader, { $hasClose: !!onClosePosition, children: [
11887
- /* @__PURE__ */ jsx(PositionsHeaderCell, { children: "Asset" }),
11888
- /* @__PURE__ */ jsx(PositionsHeaderCell, { children: "Units" }),
11889
- /* @__PURE__ */ jsx(PositionsHeaderCell, { children: "Position Value" }),
11890
- /* @__PURE__ */ jsx(PositionsHeaderCell, { children: "Avg Price" }),
11891
- /* @__PURE__ */ jsx(PositionsHeaderCell, { children: "Current Price" }),
11892
- /* @__PURE__ */ jsx(PositionsHeaderCell, { children: "PNL (%)" }),
11923
+ /* @__PURE__ */ jsxs(SortableHeaderCell, { $active: posSortKey === "asset", onClick: () => handlePosSort("asset"), children: [
11924
+ "Asset ",
11925
+ posSortKey === "asset" && (posSortAsc ? "\u2191" : "\u2193")
11926
+ ] }),
11927
+ /* @__PURE__ */ jsxs(SortableHeaderCell, { $active: posSortKey === "units", onClick: () => handlePosSort("units"), children: [
11928
+ "Units ",
11929
+ posSortKey === "units" && (posSortAsc ? "\u2191" : "\u2193")
11930
+ ] }),
11931
+ /* @__PURE__ */ jsxs(SortableHeaderCell, { $active: posSortKey === "value", onClick: () => handlePosSort("value"), children: [
11932
+ "Position Value ",
11933
+ posSortKey === "value" && (posSortAsc ? "\u2191" : "\u2193")
11934
+ ] }),
11935
+ /* @__PURE__ */ jsxs(SortableHeaderCell, { $active: posSortKey === "avgPrice", onClick: () => handlePosSort("avgPrice"), children: [
11936
+ "Avg Price ",
11937
+ posSortKey === "avgPrice" && (posSortAsc ? "\u2191" : "\u2193")
11938
+ ] }),
11939
+ /* @__PURE__ */ jsxs(SortableHeaderCell, { $active: posSortKey === "currentPrice", onClick: () => handlePosSort("currentPrice"), children: [
11940
+ "Current Price ",
11941
+ posSortKey === "currentPrice" && (posSortAsc ? "\u2191" : "\u2193")
11942
+ ] }),
11943
+ /* @__PURE__ */ jsxs(SortableHeaderCell, { $active: posSortKey === "pnl", onClick: () => handlePosSort("pnl"), children: [
11944
+ "PNL (%) ",
11945
+ posSortKey === "pnl" && (posSortAsc ? "\u2191" : "\u2193")
11946
+ ] }),
11893
11947
  onClosePosition && /* @__PURE__ */ jsx(PositionsHeaderCell, { children: "Close" })
11894
11948
  ] }),
11895
- pageSlice(positions).map((pos) => {
11949
+ pageSlice(sortedPositions).map((pos) => {
11896
11950
  const currentValue = pos.quantity * pos.marketPrice;
11897
11951
  const costBasis = pos.quantity * pos.averageEntryPrice;
11898
11952
  const pnl = pos.propertyPnl ?? currentValue - costBasis;
@@ -12321,6 +12375,16 @@ var PositionsHeaderCell = styled25.div`
12321
12375
  text-align: ${(p) => p.$align || "left"};
12322
12376
  white-space: nowrap;
12323
12377
  `;
12378
+ var SortableHeaderCell = styled25.div`
12379
+ font-size: 0.68rem;
12380
+ font-weight: 500;
12381
+ color: ${(p) => p.$active ? "rgba(255, 255, 255, 0.7)" : "rgba(255, 255, 255, 0.4)"};
12382
+ white-space: nowrap;
12383
+ cursor: pointer;
12384
+ user-select: none;
12385
+ transition: color 0.15s ease;
12386
+ &:hover { color: rgba(255, 255, 255, 0.7); }
12387
+ `;
12324
12388
  var PositionsRow = styled25.div`
12325
12389
  display: grid;
12326
12390
  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"};