@kodiak-finance/orderly-trading-leaderboard 2.8.22-beta.1 → 2.8.22-beta.3

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,7 +1,7 @@
1
1
  import { subDays, parseISO, differenceInDays, isBefore, addDays, isAfter, isWithinInterval, format } from 'date-fns';
2
2
  import { createContext, lazy, memo, useState, useRef, useCallback, useEffect, useMemo, useContext, Suspense } from 'react';
3
+ import { useAccount, useConfig, useQuery, useInfiniteQuery, useSWR, useTrack, usePrivateQuery, noCacheConfig, useMemoizedFn, useLocalStorage, useMutation } from '@kodiak-finance/orderly-hooks';
3
4
  import { useTranslation, i18n, Trans } from '@kodiak-finance/orderly-i18n';
4
- import { useAccount, useConfig, useQuery, useInfiniteQuery, useSWR, useTrack, usePrivateQuery, noCacheConfig, useMemoizedFn, useMutation } from '@kodiak-finance/orderly-hooks';
5
5
  import { useEmblaCarousel, ChevronLeftIcon, ChevronRightIcon, cn, Text, useScreen, DataTable, Flex, Spinner, usePagination, Box, Select, Button, DataFilter, Input, CloseCircleFillIcon, Divider, ScrollIndicator as ScrollIndicator$1, Tabs, TabPanel, toast, Tooltip, InfoCircleIcon } from '@kodiak-finance/orderly-ui';
6
6
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
7
7
  import { TrendingUp, TrendingDown, Wallet, DollarSign, BarChart3 } from 'lucide-react';
@@ -235,7 +235,7 @@ var init_util = __esm({
235
235
  "src/components/ranking/shared/util.ts"() {
236
236
  }
237
237
  });
238
- var useRankingColumns, FirstRankIcon, SecondRankIcon, ThirdRankIcon, PnLColumnTitle, VolumeColumnTitle, PointsColumnTitle;
238
+ var useRankingColumns, getTierInfo, TierBadge, FirstRankIcon, SecondRankIcon, ThirdRankIcon, PnLColumnTitle, VolumeColumnTitle, PointsColumnTitle;
239
239
  var init_column = __esm({
240
240
  "src/components/ranking/shared/column.tsx"() {
241
241
  init_first_badge();
@@ -298,7 +298,7 @@ var init_column = __esm({
298
298
  if (!isYou) {
299
299
  if (record.rank === 1) ; else if (record.rank === 2) ; else if (record.rank === 3) ;
300
300
  }
301
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
301
+ return /* @__PURE__ */ jsx("div", { className: "oui-flex oui-flex-col", children: /* @__PURE__ */ jsxs(
302
302
  "a",
303
303
  {
304
304
  className: "oui-flex oui-items-start oui-gap-1",
@@ -329,6 +329,18 @@ var init_column = __esm({
329
329
  },
330
330
  width: 90
331
331
  },
332
+ {
333
+ title: "VIP Tier",
334
+ dataIndex: "tier",
335
+ render: (_value, record) => {
336
+ const tierInfo = getTierInfo(record);
337
+ if (!tierInfo?.label) {
338
+ return "-";
339
+ }
340
+ return /* @__PURE__ */ jsx(TierBadge, { label: tierInfo.label, imageUrl: tierInfo.imageUrl });
341
+ },
342
+ width: 120
343
+ },
332
344
  {
333
345
  title: /* @__PURE__ */ jsx(VolumeColumnTitle, {}),
334
346
  dataIndex: "volume",
@@ -394,6 +406,46 @@ var init_column = __esm({
394
406
  );
395
407
  }, [t, isMobile, address, fields, enableSort, type]);
396
408
  };
409
+ getTierInfo = (record) => {
410
+ if (!record) {
411
+ return {};
412
+ }
413
+ const tierValue = record.tier;
414
+ if (tierValue && typeof tierValue === "object") {
415
+ return {
416
+ label: tierValue.name || tierValue.label || tierValue.tier,
417
+ imageUrl: tierValue.badge_url || tierValue.badgeUrl || tierValue.image || tierValue.imageUrl
418
+ };
419
+ }
420
+ const label = record.vip_tier || record.vipTier || record.vip_tier_name || record.vipTierName || record.tier || record.tier_name || record.tierName || record.tier_label || record.tierLabel;
421
+ const imageUrl = record.vip_badge_url || record.vipBadgeUrl || record.vip_tier_image || record.vipTierImage || record.vip_tier_badge || record.vipTierBadge || record.tier_image || record.tierImage || record.tier_badge_url || record.tierBadgeUrl;
422
+ return { label, imageUrl };
423
+ };
424
+ TierBadge = ({
425
+ label,
426
+ imageUrl,
427
+ className
428
+ }) => {
429
+ return /* @__PURE__ */ jsxs(
430
+ Flex,
431
+ {
432
+ itemAlign: "center",
433
+ gap: 1,
434
+ className: cn("oui-text-2xs", className),
435
+ children: [
436
+ imageUrl && /* @__PURE__ */ jsx(
437
+ "img",
438
+ {
439
+ src: imageUrl,
440
+ alt: `${label} badge`,
441
+ className: "oui-h-4 oui-w-4 oui-object-contain"
442
+ }
443
+ ),
444
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-2xs", children: label })
445
+ ]
446
+ }
447
+ );
448
+ };
397
449
  FirstRankIcon = () => {
398
450
  return /* @__PURE__ */ jsxs(
399
451
  "svg",
@@ -664,7 +716,8 @@ function useGeneralRankingScript(options) {
664
716
  dateRange = getDateRange(90),
665
717
  address: searchValue,
666
718
  sortKey = "perp_volume",
667
- leaderboardEndpoint
719
+ leaderboardEndpoint,
720
+ foxifyOnly = false
668
721
  } = options || {};
669
722
  const [initialSort] = useState({
670
723
  sortKey,
@@ -712,6 +765,9 @@ function useGeneralRankingScript(options) {
712
765
  if (args.address) {
713
766
  searchParams.set("address", args.address);
714
767
  }
768
+ if (foxifyOnly) {
769
+ searchParams.set("foxify_only", "true");
770
+ }
715
771
  const baseUrl = leaderboardEndpoint || `/v1/broker/leaderboard/daily`;
716
772
  return `${baseUrl}?${searchParams.toString()}`;
717
773
  };
@@ -1026,12 +1082,13 @@ var init_generalRanking_widget = __esm({
1026
1082
  init_ranking_ui();
1027
1083
  init_generalRanking_script();
1028
1084
  GeneralRankingWidget = (props) => {
1029
- const { dateRange, address, fields, sortKey, leaderboardEndpoint, ...rest } = props;
1085
+ const { dateRange, address, fields, sortKey, leaderboardEndpoint, foxifyOnly, ...rest } = props;
1030
1086
  const state = useGeneralRankingScript({
1031
1087
  dateRange,
1032
1088
  address,
1033
1089
  sortKey,
1034
- leaderboardEndpoint
1090
+ leaderboardEndpoint,
1091
+ foxifyOnly
1035
1092
  });
1036
1093
  return /* @__PURE__ */ jsx(Ranking, { ...state, ...rest, fields, type: "general" });
1037
1094
  };
@@ -1067,23 +1124,23 @@ var TradingLeaderboardProvider = (props) => {
1067
1124
  var useTradingLeaderboardContext = () => {
1068
1125
  return useContext(TradingLeaderboardContext);
1069
1126
  };
1070
- var API_BASE = "https://backend.kodiak.finance/orderly/stats";
1127
+ var API_BASE = "https://staging.backend.kodiak.finance/orderly/stats";
1071
1128
  var formatDateLocal = (date) => {
1072
1129
  const year = date.getFullYear();
1073
1130
  const month = String(date.getMonth() + 1).padStart(2, "0");
1074
1131
  const day = String(date.getDate()).padStart(2, "0");
1075
1132
  return `${year}-${month}-${day}`;
1076
1133
  };
1077
- var getApiUrl = (dateRange) => {
1134
+ var getApiUrl = (dateRange, foxifyOnly) => {
1078
1135
  if (!dateRange?.from || !dateRange?.to) {
1079
1136
  const today = /* @__PURE__ */ new Date();
1080
1137
  const startDate2 = formatDateLocal(today);
1081
1138
  const endDate2 = formatDateLocal(today);
1082
- return `${API_BASE}?start_date=${startDate2}&end_date=${endDate2}`;
1139
+ return `${API_BASE}?start_date=${startDate2}&end_date=${endDate2}${foxifyOnly ? "&foxify_only=true" : ""}`;
1083
1140
  }
1084
1141
  const startDate = formatDateLocal(dateRange.from);
1085
1142
  const endDate = formatDateLocal(dateRange.to);
1086
- return `${API_BASE}?start_date=${startDate}&end_date=${endDate}`;
1143
+ return `${API_BASE}?start_date=${startDate}&end_date=${endDate}${foxifyOnly ? "&foxify_only=true" : ""}`;
1087
1144
  };
1088
1145
  var customFetcher = async (url) => {
1089
1146
  const response = await fetch(url);
@@ -1110,11 +1167,14 @@ var formatCurrency = (num, showSign = false) => {
1110
1167
  }
1111
1168
  return formatted;
1112
1169
  };
1113
- var BrokerStatsWidget = ({ dateRange }) => {
1170
+ var BrokerStatsWidget = ({
1171
+ dateRange,
1172
+ foxifyOnly
1173
+ }) => {
1114
1174
  const { isMobile } = useScreen();
1115
1175
  const url = useMemo(
1116
- () => getApiUrl(dateRange),
1117
- [dateRange?.from, dateRange?.to]
1176
+ () => getApiUrl(dateRange, foxifyOnly),
1177
+ [dateRange?.from, dateRange?.to, foxifyOnly]
1118
1178
  );
1119
1179
  const {
1120
1180
  data: apiData,
@@ -3100,6 +3160,18 @@ var LeaderboardTab = /* @__PURE__ */ ((LeaderboardTab2) => {
3100
3160
 
3101
3161
  // src/components/leaderboard/generalLeaderboard/generalLeaderboard.script.ts
3102
3162
  init_utils();
3163
+ var useLeaderboardLocalStorage = () => {
3164
+ const [foxifyOnly, setFoxifyOnly] = useLocalStorage(
3165
+ "leaderboard_foxify_only",
3166
+ false
3167
+ );
3168
+ return {
3169
+ foxifyOnly,
3170
+ setFoxifyOnly
3171
+ };
3172
+ };
3173
+
3174
+ // src/components/leaderboard/generalLeaderboard/generalLeaderboard.script.ts
3103
3175
  var FilterDays2 = [1, 7, 30, 90];
3104
3176
  function useGeneralLeaderboardScript(options) {
3105
3177
  const { campaignDateRange, timeRange } = options || {};
@@ -3122,12 +3194,14 @@ function useGeneralLeaderboardScript(options) {
3122
3194
  customTimeRange: parsedTimeRange
3123
3195
  });
3124
3196
  const searchState = useSearch();
3197
+ const foxifyState = useLeaderboardLocalStorage();
3125
3198
  const useCampaignDateRange = useMemo(() => {
3126
3199
  return !!campaignDateRange;
3127
3200
  }, [campaignDateRange]);
3128
3201
  return {
3129
3202
  ...filterState,
3130
3203
  ...searchState,
3204
+ ...foxifyState,
3131
3205
  activeTab,
3132
3206
  onTabChange: setActiveTab,
3133
3207
  useCampaignDateRange,
@@ -3281,6 +3355,17 @@ var LeaderboardFilter = (props) => {
3281
3355
  value
3282
3356
  );
3283
3357
  });
3358
+ const foxifyFilterButton = /* @__PURE__ */ jsx(
3359
+ "button",
3360
+ {
3361
+ className: `oui-px-3 oui-py-1 oui-rounded oui-text-xs oui-font-medium oui-transition-colors oui-whitespace-nowrap ${props.foxifyOnly ? "oui-bg-primary oui-text-white" : "oui-bg-base-6 oui-text-base-contrast-60 hover:oui-bg-base-4 hover:oui-text-base-contrast"}`,
3362
+ onClick: () => {
3363
+ props.setFoxifyOnly(!props.foxifyOnly);
3364
+ },
3365
+ title: t("tradingLeaderboard.foxifyOnly.tooltip"),
3366
+ children: t("tradingLeaderboard.foxifyOnly")
3367
+ }
3368
+ );
3284
3369
  if (isMobile) {
3285
3370
  return /* @__PURE__ */ jsxs(
3286
3371
  Flex,
@@ -3293,6 +3378,7 @@ var LeaderboardFilter = (props) => {
3293
3378
  className: cn("oui-mobile-trading-leaderboard-ranking-filter"),
3294
3379
  children: [
3295
3380
  input,
3381
+ /* @__PURE__ */ jsx(Flex, { gap: 2, width: "100%", mt: 3, itemAlign: "center", children: foxifyFilterButton }),
3296
3382
  useCampaignDateRange ? /* @__PURE__ */ jsx(Flex, { gap: 3, className: "oui-w-full oui-py-3", children: /* @__PURE__ */ jsx(ScrollIndicator$1, { className: "oui-w-full", children: weeklyView }) }) : /* @__PURE__ */ jsxs(Flex, { gap: 3, className: "oui-w-full", children: [
3297
3383
  dateRangeView,
3298
3384
  /* @__PURE__ */ jsx(ScrollIndicator$1, { className: "oui-w-full", children: /* @__PURE__ */ jsx(Flex, { gap: 3, children: filterDayView }) })
@@ -3314,7 +3400,10 @@ var LeaderboardFilter = (props) => {
3314
3400
  !useCampaignDateRange && dateRangeView,
3315
3401
  !useCampaignDateRange && filterDayView
3316
3402
  ] }),
3317
- /* @__PURE__ */ jsx(Box, { width: 240, children: input })
3403
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, itemAlign: "center", children: [
3404
+ foxifyFilterButton,
3405
+ /* @__PURE__ */ jsx(Box, { width: 240, children: input })
3406
+ ] })
3318
3407
  ]
3319
3408
  }
3320
3409
  );
@@ -3462,12 +3551,8 @@ var GeneralLeaderboard = (props) => {
3462
3551
  props.activeTab === "volume" /* Volume */ ? "volume" : "pnl"
3463
3552
  ];
3464
3553
  }
3465
- const baseFields = [
3466
- "rank",
3467
- "address",
3468
- "volume",
3469
- "pnl"
3470
- ];
3554
+ const baseFields = ["rank", "address"];
3555
+ baseFields.push("volume", "pnl");
3471
3556
  if (props.leaderboardEndpoint) {
3472
3557
  baseFields.push("points");
3473
3558
  }
@@ -3475,7 +3560,13 @@ var GeneralLeaderboard = (props) => {
3475
3560
  }, [isMobile, props.activeTab, props.leaderboardEndpoint]);
3476
3561
  if (isMobile) {
3477
3562
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3478
- /* @__PURE__ */ jsx(BrokerStatsWidget, { dateRange: props.dateRange }),
3563
+ /* @__PURE__ */ jsx(
3564
+ BrokerStatsWidget,
3565
+ {
3566
+ dateRange: props.dateRange,
3567
+ foxifyOnly: props.foxifyOnly
3568
+ }
3569
+ ),
3479
3570
  /* @__PURE__ */ jsxs(
3480
3571
  Box,
3481
3572
  {
@@ -3508,7 +3599,8 @@ var GeneralLeaderboard = (props) => {
3508
3599
  address: props.searchValue,
3509
3600
  sortKey: props.activeTab === "volume" /* Volume */ ? "perp_volume" : "realized_pnl",
3510
3601
  fields,
3511
- leaderboardEndpoint: props.leaderboardEndpoint
3602
+ leaderboardEndpoint: props.leaderboardEndpoint,
3603
+ foxifyOnly: props.foxifyOnly
3512
3604
  }
3513
3605
  ) })
3514
3606
  ]
@@ -3517,7 +3609,13 @@ var GeneralLeaderboard = (props) => {
3517
3609
  ] });
3518
3610
  }
3519
3611
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3520
- /* @__PURE__ */ jsx(BrokerStatsWidget, { dateRange: props.dateRange }),
3612
+ /* @__PURE__ */ jsx(
3613
+ BrokerStatsWidget,
3614
+ {
3615
+ dateRange: props.dateRange,
3616
+ foxifyOnly: props.foxifyOnly
3617
+ }
3618
+ ),
3521
3619
  /* @__PURE__ */ jsxs(
3522
3620
  Box,
3523
3621
  {
@@ -3540,7 +3638,8 @@ var GeneralLeaderboard = (props) => {
3540
3638
  dateRange: props.dateRange,
3541
3639
  address: props.searchValue,
3542
3640
  fields,
3543
- leaderboardEndpoint: props.leaderboardEndpoint
3641
+ leaderboardEndpoint: props.leaderboardEndpoint,
3642
+ foxifyOnly: props.foxifyOnly
3544
3643
  }
3545
3644
  ) })
3546
3645
  ]
@@ -7587,7 +7686,13 @@ var LeaderboardSection = (props) => {
7587
7686
  if (currentCampaignId === "general") {
7588
7687
  return /* @__PURE__ */ jsxs(Box, { px: 3, className: cn("oui-mix-blend-screen"), children: [
7589
7688
  /* @__PURE__ */ jsx(LeaderboardBackground, { backgroundSrc }),
7590
- /* @__PURE__ */ jsx(BrokerStatsWidget, { dateRange: memoizedDateRange }),
7689
+ /* @__PURE__ */ jsx(
7690
+ BrokerStatsWidget,
7691
+ {
7692
+ dateRange: memoizedDateRange,
7693
+ foxifyOnly: leaderboardScript.foxifyOnly
7694
+ }
7695
+ ),
7591
7696
  /* @__PURE__ */ jsx(
7592
7697
  GeneralLeaderboard,
7593
7698
  {
@@ -7599,7 +7704,13 @@ var LeaderboardSection = (props) => {
7599
7704
  }
7600
7705
  if (currentCampaign?.leaderboard_config?.use_general_leaderboard) {
7601
7706
  return /* @__PURE__ */ jsxs(Box, { px: 3, children: [
7602
- /* @__PURE__ */ jsx(BrokerStatsWidget, { dateRange: memoizedDateRange }),
7707
+ /* @__PURE__ */ jsx(
7708
+ BrokerStatsWidget,
7709
+ {
7710
+ dateRange: memoizedDateRange,
7711
+ foxifyOnly: leaderboardScript.foxifyOnly
7712
+ }
7713
+ ),
7603
7714
  /* @__PURE__ */ jsx(
7604
7715
  LeaderboardTitle,
7605
7716
  {
@@ -7620,7 +7731,13 @@ var LeaderboardSection = (props) => {
7620
7731
  }
7621
7732
  if (currentCampaign && !currentCampaign.hide_arena && currentCampaignId != "general") {
7622
7733
  return /* @__PURE__ */ jsxs(Box, { px: 3, children: [
7623
- /* @__PURE__ */ jsx(BrokerStatsWidget, { dateRange: memoizedDateRange }),
7734
+ /* @__PURE__ */ jsx(
7735
+ BrokerStatsWidget,
7736
+ {
7737
+ dateRange: memoizedDateRange,
7738
+ foxifyOnly: leaderboardScript.foxifyOnly
7739
+ }
7740
+ ),
7624
7741
  /* @__PURE__ */ jsx(
7625
7742
  LeaderboardTitle,
7626
7743
  {