@orderly.network/portfolio 2.11.1 → 2.11.2

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
@@ -12,7 +12,7 @@ import { Decimal, zero, numberToHumanStyle, commifyOptional, subtractDaysFromCur
12
12
  import { subDays, format, getYear, getMonth, getDate, set, differenceInDays, setHours } from 'date-fns';
13
13
  import { produce } from 'immer';
14
14
  import pick$1 from 'ramda/es/pick';
15
- import { AssetLineChart, PnLBarChart, PnlAreaChart, VolBarChart, VolumeAreaChart, AreaChart, Area, AssetAreaChart } from '@orderly.network/chart';
15
+ import { AssetLineChart, PnLBarChart, PnlAreaChart, VolBarChart, VolumeAreaChart, ResponsiveContainer, AreaChart, Area, AssetAreaChart } from '@orderly.network/chart';
16
16
  import { useScaffoldContext, Scaffold, SideBar, MainNavMobile, BottomNav, LanguageSwitcherWidget } from '@orderly.network/ui-scaffold';
17
17
  import { pick } from 'ramda';
18
18
  import { CombinePositionsWidget, PositionsWidget, PositionHistoryWidget, LiquidationWidget } from '@orderly.network/ui-positions';
@@ -4108,7 +4108,7 @@ var init_useAssetHistory = __esm({
4108
4108
  );
4109
4109
  const [userStatistics] = useUserStatistics();
4110
4110
  const todayVolume = useMemo(
4111
- () => userStatistics?.perp_trading_volume_last_24_hours ?? 0,
4111
+ () => userStatistics?.perp_trading_volume_today ?? 0,
4112
4112
  [userStatistics]
4113
4113
  );
4114
4114
  const lastBalanceEventRef = useRef(0);
@@ -4265,6 +4265,7 @@ var init_useAssetHistory = __esm({
4265
4265
  ...lastItem2,
4266
4266
  date: getUTCStr(today),
4267
4267
  perp_volume: todayVol,
4268
+ base_account_value: lastItem2?.account_value ?? 0,
4268
4269
  account_value: totalValue2 !== null ? totalValue2 : lastItem2?.account_value ?? 0,
4269
4270
  pnl: calculateLastPnl({
4270
4271
  lastItem: lastItem2,
@@ -4323,6 +4324,25 @@ var init_useAssetHistory = __esm({
4323
4324
  totalTransferOut,
4324
4325
  todayVolume
4325
4326
  ]);
4327
+ const todayPerformance = useMemo(() => {
4328
+ if (!Array.isArray(calculatedData) || calculatedData.length === 0) {
4329
+ return null;
4330
+ }
4331
+ const todayRow = calculatedData[calculatedData.length - 1];
4332
+ if (!todayRow.__isCalculated) {
4333
+ return null;
4334
+ }
4335
+ const baseAccountValue = typeof todayRow.base_account_value === "number" ? todayRow.base_account_value : todayRow.account_value ?? 0;
4336
+ let roi = zero;
4337
+ if (baseAccountValue) {
4338
+ roi = new Decimal(todayRow.pnl).div(baseAccountValue);
4339
+ }
4340
+ return {
4341
+ pnl: todayRow.pnl,
4342
+ roi: roi.toNumber(),
4343
+ vol: todayRow.perp_volume ?? 0
4344
+ };
4345
+ }, [calculatedData]);
4326
4346
  const aggregateValue = useMemo(() => {
4327
4347
  let vol = zero;
4328
4348
  let pnl = zero;
@@ -4362,7 +4382,8 @@ var init_useAssetHistory = __esm({
4362
4382
  // calculatedData,
4363
4383
  aggregateValue,
4364
4384
  createFakeData,
4365
- volumeUpdateDate: data?.[data.length - 1]?.date ?? ""
4385
+ volumeUpdateDate: data?.[data.length - 1]?.date ?? "",
4386
+ todayPerformance
4366
4387
  };
4367
4388
  };
4368
4389
  }
@@ -4472,7 +4493,7 @@ var init_performance_ui = __esm({
4472
4493
  formatForChart = (value, dp = 2) => {
4473
4494
  if (value == null) return 0;
4474
4495
  const decimal = new Decimal(value);
4475
- return Number(decimal.toFixed(dp, Decimal.ROUND_DOWN));
4496
+ return Number(decimal.toFixed(dp, Decimal.ROUND_HALF_UP));
4476
4497
  };
4477
4498
  PerformanceUI = (props) => {
4478
4499
  const {
@@ -5077,7 +5098,7 @@ var init_apiManager_script = __esm({
5077
5098
  hideCreateDialog();
5078
5099
  setGenerateKey({
5079
5100
  key,
5080
- screctKey: secretKey,
5101
+ secretKey,
5081
5102
  ip,
5082
5103
  permissions: scope?.split(",")?.map((e) => capitalizeFirstChar(e)).join(", ")
5083
5104
  });
@@ -5498,7 +5519,7 @@ var init_createdApiKey = __esm({
5498
5519
  copyIconSize: 16,
5499
5520
  className: "oui-break-all",
5500
5521
  onCopy: props.onCopyApiSecretKey,
5501
- children: props.generateKey?.screctKey
5522
+ children: props.generateKey?.secretKey
5502
5523
  }
5503
5524
  ),
5504
5525
  " "
@@ -5942,18 +5963,24 @@ var init_apiManager_ui = __esm({
5942
5963
  dataIndex: "orderly_key",
5943
5964
  width: 150,
5944
5965
  render: (value) => {
5945
- return /* @__PURE__ */ jsx(
5946
- Text.formatted,
5947
- {
5948
- rule: "",
5949
- copyable: true,
5950
- copyIconSize: 16,
5951
- onCopy: () => {
5952
- props.onCopyApiKey?.(value);
5953
- },
5954
- children: formatKey(value)
5955
- }
5956
- );
5966
+ const fullKey = typeof value === "string" ? value : `${value ?? ""}`;
5967
+ const displayKey = formatKey(fullKey);
5968
+ return /* @__PURE__ */ jsxs(Flex, { gap: 1, itemAlign: "center", children: [
5969
+ /* @__PURE__ */ jsx("div", { className: "oui-overflow-hidden oui-overflow-ellipsis", children: /* @__PURE__ */ jsx(Text.formatted, { rule: "", children: displayKey }) }),
5970
+ !!fullKey && /* @__PURE__ */ jsx(Box, { width: 16, height: 16, className: "oui-cursor-pointer", children: /* @__PURE__ */ jsx(
5971
+ CopyIcon,
5972
+ {
5973
+ color: "white",
5974
+ opacity: 0.54,
5975
+ size: 16,
5976
+ onClick: (e) => {
5977
+ e.stopPropagation();
5978
+ navigator.clipboard.writeText(fullKey);
5979
+ props.onCopyApiKey?.(fullKey);
5980
+ }
5981
+ }
5982
+ ) })
5983
+ ] });
5957
5984
  }
5958
5985
  },
5959
5986
  {
@@ -6756,8 +6783,10 @@ init_assetChart();
6756
6783
 
6757
6784
  // src/pages/overview/portfolioChartsMobile/portfolioChartsMobile.script.ts
6758
6785
  init_type();
6786
+ init_overviewContext();
6759
6787
  var usePortfolioChartsState = () => {
6760
6788
  const [data] = usePositionStream();
6789
+ const overview = useOverviewContext();
6761
6790
  const [visible, setVisible] = useLocalStorage(
6762
6791
  ORDERLY_ASSETS_VISIBLE_KEY,
6763
6792
  true
@@ -6766,6 +6795,9 @@ var usePortfolioChartsState = () => {
6766
6795
  return modal.show(PerformanceMobileSheetId);
6767
6796
  }, []);
6768
6797
  return {
6798
+ todaysPnl: overview?.todayPerformance?.pnl ?? null,
6799
+ todaysRoi: overview?.todayPerformance?.roi ?? null,
6800
+ todaysVol: overview?.todayPerformance?.vol ?? null,
6769
6801
  unrealPnL: data?.aggregated.total_unreal_pnl,
6770
6802
  unrealROI: data?.totalUnrealizedROI,
6771
6803
  visible,
@@ -6774,7 +6806,15 @@ var usePortfolioChartsState = () => {
6774
6806
  };
6775
6807
  };
6776
6808
  var PortfolioChartsMobileUI = (props) => {
6777
- const { data, invisible, unrealPnL, unrealROI, visible, onPerformanceClick } = props;
6809
+ const {
6810
+ data,
6811
+ invisible,
6812
+ todaysPnl,
6813
+ todaysRoi,
6814
+ todaysVol,
6815
+ visible,
6816
+ onPerformanceClick
6817
+ } = props;
6778
6818
  const { t } = useTranslation();
6779
6819
  const colorId = useId();
6780
6820
  return /* @__PURE__ */ jsxs(
@@ -6782,62 +6822,55 @@ var PortfolioChartsMobileUI = (props) => {
6782
6822
  {
6783
6823
  p: 4,
6784
6824
  width: "100%",
6785
- itemAlign: "center",
6786
- justify: "between",
6825
+ direction: "column",
6787
6826
  className: cn(
6788
6827
  "oui-relative oui-overflow-hidden oui-rounded-2xl oui-border oui-border-solid oui-border-line-12 oui-bg-base-9"
6789
6828
  ),
6790
6829
  children: [
6791
- /* @__PURE__ */ jsxs(
6792
- Flex,
6793
- {
6794
- width: "100%",
6795
- justify: "center",
6796
- itemAlign: "start",
6797
- direction: "column",
6798
- gap: 2,
6799
- children: [
6800
- /* @__PURE__ */ jsx(Text, { size: "xs", intensity: 54, children: t("common.unrealizedPnl") }),
6801
- /* @__PURE__ */ jsxs(Flex, { justify: "start", itemAlign: "center", children: [
6802
- /* @__PURE__ */ jsx(Text.pnl, { coloring: true, size: "base", weight: "semibold", visible, children: unrealPnL }),
6803
- /* @__PURE__ */ jsx(
6804
- Text.roi,
6805
- {
6806
- coloring: true,
6807
- rule: "percentages",
6808
- size: "sm",
6809
- weight: "semibold",
6810
- prefix: "(",
6811
- suffix: ")",
6812
- visible,
6813
- children: unrealROI
6814
- }
6815
- )
6816
- ] }),
6817
- /* @__PURE__ */ jsxs(
6818
- Text,
6830
+ /* @__PURE__ */ jsxs(Flex, { width: "100%", justify: "between", itemAlign: "start", mb: 3, children: [
6831
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 1, children: [
6832
+ /* @__PURE__ */ jsx(Text, { size: "sm", intensity: 54, children: t("portfolio.overview.todaysPnl") }),
6833
+ /* @__PURE__ */ jsxs(Flex, { justify: "start", itemAlign: "center", gapX: 1, children: [
6834
+ /* @__PURE__ */ jsx(Text.pnl, { coloring: true, size: "base", weight: "semibold", visible, children: invisible || todaysPnl == null ? "--" : todaysPnl }),
6835
+ /* @__PURE__ */ jsx(
6836
+ Text.roi,
6819
6837
  {
6820
- size: "xs",
6821
- intensity: 54,
6822
- className: "oui-flex oui-items-center oui-justify-start oui-gap-1",
6823
- onClick: onPerformanceClick,
6824
- children: [
6825
- t("portfolio.overview.performance"),
6826
- /* @__PURE__ */ jsx(ChevronRightIcon, { className: "oui-text-base-contrast-54" })
6827
- ]
6838
+ coloring: true,
6839
+ rule: "percentages",
6840
+ size: "sm",
6841
+ weight: "semibold",
6842
+ prefix: "(",
6843
+ suffix: ")",
6844
+ visible,
6845
+ children: invisible || todaysRoi == null ? "--" : todaysRoi
6828
6846
  }
6829
6847
  )
6830
- ]
6831
- }
6832
- ),
6848
+ ] })
6849
+ ] }),
6850
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 1, itemAlign: "end", children: [
6851
+ /* @__PURE__ */ jsx(Text, { size: "sm", intensity: 54, children: t("portfolio.overview.todaysVol") }),
6852
+ /* @__PURE__ */ jsx(
6853
+ Text.numeral,
6854
+ {
6855
+ size: "sm",
6856
+ rule: "human",
6857
+ dp: 2,
6858
+ visible,
6859
+ prefix: "$",
6860
+ children: invisible || todaysVol == null ? "--" : todaysVol
6861
+ }
6862
+ )
6863
+ ] })
6864
+ ] }),
6833
6865
  /* @__PURE__ */ jsx(
6834
6866
  Flex,
6835
6867
  {
6836
6868
  width: "100%",
6837
6869
  justify: "center",
6838
6870
  itemAlign: "center",
6839
- direction: "column",
6840
- children: /* @__PURE__ */ jsx(AreaChart, { data: data || EMPTY_LIST, width: 160, height: 52, children: !invisible && /* @__PURE__ */ jsxs(Fragment, { children: [
6871
+ mb: 3,
6872
+ className: "oui-px-1",
6873
+ children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: 52, children: /* @__PURE__ */ jsx(AreaChart, { data: data || EMPTY_LIST, children: !invisible && /* @__PURE__ */ jsxs(Fragment, { children: [
6841
6874
  /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id: colorId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
6842
6875
  /* @__PURE__ */ jsx(
6843
6876
  "stop",
@@ -6868,9 +6901,22 @@ var PortfolioChartsMobileUI = (props) => {
6868
6901
  fill: `url(#${colorId})`
6869
6902
  }
6870
6903
  )
6871
- ] }) })
6904
+ ] }) }) })
6872
6905
  }
6873
- )
6906
+ ),
6907
+ /* @__PURE__ */ jsx(Flex, { width: "100%", justify: "start", itemAlign: "center", mt: 1, children: /* @__PURE__ */ jsxs(
6908
+ Text,
6909
+ {
6910
+ size: "xs",
6911
+ intensity: 54,
6912
+ className: "oui-flex oui-items-center oui-justify-start oui-gap-1",
6913
+ onClick: onPerformanceClick,
6914
+ children: [
6915
+ t("portfolio.overview.performance"),
6916
+ /* @__PURE__ */ jsx(ChevronRightIcon, { className: "oui-text-base-contrast-54" })
6917
+ ]
6918
+ }
6919
+ ) })
6874
6920
  ]
6875
6921
  }
6876
6922
  );