@orderly.network/portfolio 3.0.0-beta.1 → 3.0.0-beta.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
@@ -1,8 +1,8 @@
1
1
  import React12, { createContext, useMemo, useId, useContext, useState, useCallback, useRef, createElement, useEffect } from 'react';
2
- import { useLocalStorage, useAccount, useIndexPricesStream, useCollateral, usePrivateQuery, useStatisticsDaily, useUserStatistics, useBalanceTopic, useAssetsHistory, useFeeState, useMediaQuery, useAccountInfo, useWalletConnector, usePositionStream, useLeverage, useMaxWithdrawal, useGetClaimed, DistributionId, TWType, useCurEpochEstimate, useAllBrokers, noCacheConfig, useEpochInfo, useConfig, useGetEnv, useMutation, useOrderlyContext, useDebouncedCallback, useAppStore, parseJSON, useChains, useTransferHistory, useChainInfo, useSymbolsInfo, useFundingFeeHistory, useSubAccountQuery, useApiKeyManager, useDistributionHistory, useVaultsHistory } from '@orderly.network/hooks';
2
+ import { useLocalStorage, useAccount, useIndexPricesStream, useCollateral, usePrivateQuery, useStatisticsDaily, useUserStatistics, useBalanceTopic, useAssetsHistory, useFeeState, useMediaQuery, useAccountInfo, useWalletConnector, usePositionStream, useLeverage, useMaxWithdrawal, useGetClaimed, DistributionId, TWType, useCurEpochEstimate, useAllBrokers, noCacheConfig, useEpochInfo, useConfig, useGetEnv, useMutation, useOrderlyContext, useDebouncedCallback, useAppStore, parseJSON, useChains, useTransferHistory, useChainInfo, useBadgeBySymbol, useSymbolsInfo, useFundingFeeHistory, useSubAccountQuery, useApiKeyManager, useDistributionHistory, useVaultsHistory } from '@orderly.network/hooks';
3
3
  import { useAppContext, useDataTap, useCanTrade } from '@orderly.network/react-app';
4
4
  import { AccountStatusEnum, ChainNamespace, EMPTY_LIST, AssetHistoryStatusEnum, AssetHistorySideEnum } from '@orderly.network/types';
5
- import { registerSimpleSheet, registerSimpleDialog, Tabs, TabPanel, Flex, Text, modal, useModal, SimpleDialog, DataTable, SimpleSheet, TokenIcon, Divider, toast, useScreen, CardTitle, Select, Box, cn, Statistic, CopyIcon, Grid, formatAddress, DataFilter, Tooltip, InfoCircleIcon, Button, EmptyDataState, Card, Either, gradientTextVariants, EyeIcon, EyeCloseIcon, useOrderlyTheme, ArrowDownSquareFillIcon, ArrowLeftRightIcon, ArrowUpSquareFillIcon, ArrowRightShortIcon, CalendarMinusIcon, AffiliateIcon, ChevronRightIcon, TraderMobileIcon, SettingFillIcon, Switch, ChainIcon, capitalizeFirstLetter, usePagination, ListView, Badge, ArrowDownShortIcon, ScrollIndicator, PlusIcon, FeeTierIcon, ServerFillIcon, ArrowLeftRightSquareFill, VaultsIcon } from '@orderly.network/ui';
5
+ import { registerSimpleSheet, registerSimpleDialog, Tabs, TabPanel, Flex, Text, modal, useModal, SimpleDialog, DataTable, SimpleSheet, TokenIcon, Divider, toast, useScreen, CardTitle, Select, Box, cn, Statistic, CopyIcon, Grid, formatAddress, DataFilter, Tooltip, InfoCircleIcon, Button, EmptyDataState, Card, Either, gradientTextVariants, EyeIcon, EyeCloseIcon, useOrderlyTheme, ArrowDownSquareFillIcon, ArrowLeftRightIcon, ArrowUpSquareFillIcon, ArrowRightShortIcon, CalendarMinusIcon, AffiliateIcon, ChevronRightIcon, TraderMobileIcon, SettingFillIcon, Switch, ChainIcon, capitalizeFirstLetter, usePagination, ListView, Badge, ArrowDownShortIcon, ScrollIndicator, PlusIcon, SymbolBadge as SymbolBadge$1, FeeTierIcon, ServerFillIcon, ArrowLeftRightSquareFill, VaultsIcon } from '@orderly.network/ui';
6
6
  import { LeverageWidgetWithDialogId } from '@orderly.network/ui-leverage';
7
7
  import { DepositAndWithdrawWithSheetId, DepositAndWithdrawWithDialogId, TransferSheetId, TransferDialogId, DepositStatusWidget } from '@orderly.network/ui-transfer';
8
8
  import { i18n, useTranslation, Trans } from '@orderly.network/i18n';
@@ -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';
@@ -838,9 +838,24 @@ var init_assetHistory = __esm({
838
838
  init_assetHistory_widget();
839
839
  }
840
840
  });
841
- var useFundingHistoryColumns;
841
+ var SymbolBadge, useFundingHistoryColumns;
842
842
  var init_column2 = __esm({
843
843
  "src/pages/overview/funding/column.tsx"() {
844
+ SymbolBadge = (props) => {
845
+ const { brokerId, brokerName, brokerNameRaw } = useBadgeBySymbol(
846
+ props.symbol
847
+ );
848
+ return /* @__PURE__ */ jsx(
849
+ Text.symbolBadge,
850
+ {
851
+ badge: brokerName ?? brokerId ?? void 0,
852
+ fullName: brokerNameRaw,
853
+ className: "oui-cursor-pointer",
854
+ showIcon: true,
855
+ children: props.symbol
856
+ }
857
+ );
858
+ };
844
859
  useFundingHistoryColumns = () => {
845
860
  const { t } = useTranslation();
846
861
  const columns = useMemo(() => {
@@ -849,10 +864,7 @@ var init_column2 = __esm({
849
864
  title: t("common.symbol"),
850
865
  dataIndex: "symbol",
851
866
  width: 80,
852
- rule: "symbol",
853
- textProps: {
854
- showIcon: true
855
- }
867
+ render: (value) => /* @__PURE__ */ jsx(SymbolBadge, { symbol: value })
856
868
  },
857
869
  {
858
870
  title: t("common.time"),
@@ -980,9 +992,22 @@ var init_fundingHistory_ui = __esm({
980
992
  };
981
993
  }
982
994
  });
995
+ var SymbolBadge2;
996
+ var init_symbolBadge = __esm({
997
+ "src/pages/overview/funding/symbolBadge.tsx"() {
998
+ SymbolBadge2 = (props) => {
999
+ const { brokerId, brokerName, brokerNameRaw } = useBadgeBySymbol(
1000
+ props.symbol
1001
+ );
1002
+ const badge = brokerName ?? brokerId ?? void 0;
1003
+ return /* @__PURE__ */ jsx(SymbolBadge$1, { badge, fullName: brokerNameRaw });
1004
+ };
1005
+ }
1006
+ });
983
1007
  var FundingHistoryMobile;
984
1008
  var init_fundingHistory_ui_mobile = __esm({
985
1009
  "src/pages/overview/funding/fundingHistory.ui.mobile.tsx"() {
1010
+ init_symbolBadge();
986
1011
  FundingHistoryMobile = (props) => {
987
1012
  const { dataSource: dataSource2, queryParameter, onFilter, isLoading, pagination } = props;
988
1013
  const symbols = useSymbolsInfo();
@@ -1019,11 +1044,16 @@ var init_fundingHistory_ui_mobile = __esm({
1019
1044
  Text.formatted,
1020
1045
  {
1021
1046
  rule: "symbol",
1047
+ formatString: "base",
1022
1048
  className: "oui-text-base-contrast oui-mr-1 oui-text-sm",
1049
+ suffix: /* @__PURE__ */ jsxs(Flex, { direction: "row", gap: 1, children: [
1050
+ " ",
1051
+ /* @__PURE__ */ jsx(Badge, { color: "neutral", size: "xs", children: switchPaymentType(item.payment_type) }),
1052
+ /* @__PURE__ */ jsx(SymbolBadge2, { symbol: item.symbol })
1053
+ ] }),
1023
1054
  children: item.symbol
1024
1055
  }
1025
1056
  ),
1026
- /* @__PURE__ */ jsx(Badge, { color: "neutral", size: "xs", children: switchPaymentType(item.payment_type) }),
1027
1057
  /* @__PURE__ */ jsx(
1028
1058
  Text.formatted,
1029
1059
  {
@@ -4108,7 +4138,7 @@ var init_useAssetHistory = __esm({
4108
4138
  );
4109
4139
  const [userStatistics] = useUserStatistics();
4110
4140
  const todayVolume = useMemo(
4111
- () => userStatistics?.perp_trading_volume_last_24_hours ?? 0,
4141
+ () => userStatistics?.perp_trading_volume_today ?? 0,
4112
4142
  [userStatistics]
4113
4143
  );
4114
4144
  const lastBalanceEventRef = useRef(0);
@@ -4265,6 +4295,7 @@ var init_useAssetHistory = __esm({
4265
4295
  ...lastItem2,
4266
4296
  date: getUTCStr(today),
4267
4297
  perp_volume: todayVol,
4298
+ base_account_value: lastItem2?.account_value ?? 0,
4268
4299
  account_value: totalValue2 !== null ? totalValue2 : lastItem2?.account_value ?? 0,
4269
4300
  pnl: calculateLastPnl({
4270
4301
  lastItem: lastItem2,
@@ -4323,6 +4354,25 @@ var init_useAssetHistory = __esm({
4323
4354
  totalTransferOut,
4324
4355
  todayVolume
4325
4356
  ]);
4357
+ const todayPerformance = useMemo(() => {
4358
+ if (!Array.isArray(calculatedData) || calculatedData.length === 0) {
4359
+ return null;
4360
+ }
4361
+ const todayRow = calculatedData[calculatedData.length - 1];
4362
+ if (!todayRow.__isCalculated) {
4363
+ return null;
4364
+ }
4365
+ const baseAccountValue = typeof todayRow.base_account_value === "number" ? todayRow.base_account_value : todayRow.account_value ?? 0;
4366
+ let roi = zero;
4367
+ if (baseAccountValue) {
4368
+ roi = new Decimal(todayRow.pnl).div(baseAccountValue);
4369
+ }
4370
+ return {
4371
+ pnl: todayRow.pnl,
4372
+ roi: roi.toNumber(),
4373
+ vol: todayRow.perp_volume ?? 0
4374
+ };
4375
+ }, [calculatedData]);
4326
4376
  const aggregateValue = useMemo(() => {
4327
4377
  let vol = zero;
4328
4378
  let pnl = zero;
@@ -4362,7 +4412,8 @@ var init_useAssetHistory = __esm({
4362
4412
  // calculatedData,
4363
4413
  aggregateValue,
4364
4414
  createFakeData,
4365
- volumeUpdateDate: data?.[data.length - 1]?.date ?? ""
4415
+ volumeUpdateDate: data?.[data.length - 1]?.date ?? "",
4416
+ todayPerformance
4366
4417
  };
4367
4418
  };
4368
4419
  }
@@ -4472,7 +4523,7 @@ var init_performance_ui = __esm({
4472
4523
  formatForChart = (value, dp = 2) => {
4473
4524
  if (value == null) return 0;
4474
4525
  const decimal = new Decimal(value);
4475
- return Number(decimal.toFixed(dp, Decimal.ROUND_DOWN));
4526
+ return Number(decimal.toFixed(dp, Decimal.ROUND_HALF_UP));
4476
4527
  };
4477
4528
  PerformanceUI = (props) => {
4478
4529
  const {
@@ -5077,7 +5128,7 @@ var init_apiManager_script = __esm({
5077
5128
  hideCreateDialog();
5078
5129
  setGenerateKey({
5079
5130
  key,
5080
- screctKey: secretKey,
5131
+ secretKey,
5081
5132
  ip,
5082
5133
  permissions: scope?.split(",")?.map((e) => capitalizeFirstChar(e)).join(", ")
5083
5134
  });
@@ -5498,7 +5549,7 @@ var init_createdApiKey = __esm({
5498
5549
  copyIconSize: 16,
5499
5550
  className: "oui-break-all",
5500
5551
  onCopy: props.onCopyApiSecretKey,
5501
- children: props.generateKey?.screctKey
5552
+ children: props.generateKey?.secretKey
5502
5553
  }
5503
5554
  ),
5504
5555
  " "
@@ -5942,18 +5993,24 @@ var init_apiManager_ui = __esm({
5942
5993
  dataIndex: "orderly_key",
5943
5994
  width: 150,
5944
5995
  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
- );
5996
+ const fullKey = typeof value === "string" ? value : `${value ?? ""}`;
5997
+ const displayKey = formatKey(fullKey);
5998
+ return /* @__PURE__ */ jsxs(Flex, { gap: 1, itemAlign: "center", children: [
5999
+ /* @__PURE__ */ jsx("div", { className: "oui-overflow-hidden oui-overflow-ellipsis", children: /* @__PURE__ */ jsx(Text.formatted, { rule: "", children: displayKey }) }),
6000
+ !!fullKey && /* @__PURE__ */ jsx(Box, { width: 16, height: 16, className: "oui-cursor-pointer", children: /* @__PURE__ */ jsx(
6001
+ CopyIcon,
6002
+ {
6003
+ color: "white",
6004
+ opacity: 0.54,
6005
+ size: 16,
6006
+ onClick: (e) => {
6007
+ e.stopPropagation();
6008
+ navigator.clipboard.writeText(fullKey);
6009
+ props.onCopyApiKey?.(fullKey);
6010
+ }
6011
+ }
6012
+ ) })
6013
+ ] });
5957
6014
  }
5958
6015
  },
5959
6016
  {
@@ -6756,8 +6813,10 @@ init_assetChart();
6756
6813
 
6757
6814
  // src/pages/overview/portfolioChartsMobile/portfolioChartsMobile.script.ts
6758
6815
  init_type();
6816
+ init_overviewContext();
6759
6817
  var usePortfolioChartsState = () => {
6760
6818
  const [data] = usePositionStream();
6819
+ const overview = useOverviewContext();
6761
6820
  const [visible, setVisible] = useLocalStorage(
6762
6821
  ORDERLY_ASSETS_VISIBLE_KEY,
6763
6822
  true
@@ -6766,6 +6825,9 @@ var usePortfolioChartsState = () => {
6766
6825
  return modal.show(PerformanceMobileSheetId);
6767
6826
  }, []);
6768
6827
  return {
6828
+ todaysPnl: overview?.todayPerformance?.pnl ?? null,
6829
+ todaysRoi: overview?.todayPerformance?.roi ?? null,
6830
+ todaysVol: overview?.todayPerformance?.vol ?? null,
6769
6831
  unrealPnL: data?.aggregated.total_unreal_pnl,
6770
6832
  unrealROI: data?.totalUnrealizedROI,
6771
6833
  visible,
@@ -6774,7 +6836,15 @@ var usePortfolioChartsState = () => {
6774
6836
  };
6775
6837
  };
6776
6838
  var PortfolioChartsMobileUI = (props) => {
6777
- const { data, invisible, unrealPnL, unrealROI, visible, onPerformanceClick } = props;
6839
+ const {
6840
+ data,
6841
+ invisible,
6842
+ todaysPnl,
6843
+ todaysRoi,
6844
+ todaysVol,
6845
+ visible,
6846
+ onPerformanceClick
6847
+ } = props;
6778
6848
  const { t } = useTranslation();
6779
6849
  const colorId = useId();
6780
6850
  return /* @__PURE__ */ jsxs(
@@ -6782,62 +6852,55 @@ var PortfolioChartsMobileUI = (props) => {
6782
6852
  {
6783
6853
  p: 4,
6784
6854
  width: "100%",
6785
- itemAlign: "center",
6786
- justify: "between",
6855
+ direction: "column",
6787
6856
  className: cn(
6788
6857
  "oui-relative oui-overflow-hidden oui-rounded-2xl oui-border oui-border-solid oui-border-line-12 oui-bg-base-9"
6789
6858
  ),
6790
6859
  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,
6860
+ /* @__PURE__ */ jsxs(Flex, { width: "100%", justify: "between", itemAlign: "start", mb: 3, children: [
6861
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 1, children: [
6862
+ /* @__PURE__ */ jsx(Text, { size: "sm", intensity: 54, children: t("portfolio.overview.todaysPnl") }),
6863
+ /* @__PURE__ */ jsxs(Flex, { justify: "start", itemAlign: "center", gapX: 1, children: [
6864
+ /* @__PURE__ */ jsx(Text.pnl, { coloring: true, size: "base", weight: "semibold", visible, children: invisible || todaysPnl == null ? "--" : todaysPnl }),
6865
+ /* @__PURE__ */ jsx(
6866
+ Text.roi,
6819
6867
  {
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
- ]
6868
+ coloring: true,
6869
+ rule: "percentages",
6870
+ size: "sm",
6871
+ weight: "semibold",
6872
+ prefix: "(",
6873
+ suffix: ")",
6874
+ visible,
6875
+ children: invisible || todaysRoi == null ? "--" : todaysRoi
6828
6876
  }
6829
6877
  )
6830
- ]
6831
- }
6832
- ),
6878
+ ] })
6879
+ ] }),
6880
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 1, itemAlign: "end", children: [
6881
+ /* @__PURE__ */ jsx(Text, { size: "sm", intensity: 54, children: t("portfolio.overview.todaysVol") }),
6882
+ /* @__PURE__ */ jsx(
6883
+ Text.numeral,
6884
+ {
6885
+ size: "sm",
6886
+ rule: "human",
6887
+ dp: 2,
6888
+ visible,
6889
+ prefix: "$",
6890
+ children: invisible || todaysVol == null ? "--" : todaysVol
6891
+ }
6892
+ )
6893
+ ] })
6894
+ ] }),
6833
6895
  /* @__PURE__ */ jsx(
6834
6896
  Flex,
6835
6897
  {
6836
6898
  width: "100%",
6837
6899
  justify: "center",
6838
6900
  itemAlign: "center",
6839
- direction: "column",
6840
- children: /* @__PURE__ */ jsx(AreaChart, { data: data || EMPTY_LIST, width: 160, height: 52, children: !invisible && /* @__PURE__ */ jsxs(Fragment, { children: [
6901
+ mb: 3,
6902
+ className: "oui-px-1",
6903
+ children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: 52, children: /* @__PURE__ */ jsx(AreaChart, { data: data || EMPTY_LIST, children: !invisible && /* @__PURE__ */ jsxs(Fragment, { children: [
6841
6904
  /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id: colorId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
6842
6905
  /* @__PURE__ */ jsx(
6843
6906
  "stop",
@@ -6868,9 +6931,22 @@ var PortfolioChartsMobileUI = (props) => {
6868
6931
  fill: `url(#${colorId})`
6869
6932
  }
6870
6933
  )
6871
- ] }) })
6934
+ ] }) }) })
6872
6935
  }
6873
- )
6936
+ ),
6937
+ /* @__PURE__ */ jsx(Flex, { width: "100%", justify: "start", itemAlign: "center", mt: 1, children: /* @__PURE__ */ jsxs(
6938
+ Text,
6939
+ {
6940
+ size: "xs",
6941
+ intensity: 54,
6942
+ className: "oui-flex oui-items-center oui-justify-start oui-gap-1",
6943
+ onClick: onPerformanceClick,
6944
+ children: [
6945
+ t("portfolio.overview.performance"),
6946
+ /* @__PURE__ */ jsx(ChevronRightIcon, { className: "oui-text-base-contrast-54" })
6947
+ ]
6948
+ }
6949
+ ) })
6874
6950
  ]
6875
6951
  }
6876
6952
  );