@kodiak-finance/orderly-portfolio 2.8.22-beta.0 → 2.8.22-beta.1

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
@@ -9611,10 +9611,23 @@ var formatDateRange = (date) => {
9611
9611
  return void 0;
9612
9612
  return dateFns.format(date, "yyyy-MM-dd");
9613
9613
  };
9614
- var normalizeDateToUTC = (date) => {
9615
- const dateStr = dateFns.format(date, "yyyy-MM-dd");
9616
- const [year, month, day] = dateStr.split("-").map(Number);
9617
- return new Date(Date.UTC(year, month - 1, day));
9614
+ var getUtcStartOfDay = (date) => {
9615
+ return new Date(
9616
+ Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())
9617
+ );
9618
+ };
9619
+ var getUtcEndOfDay = (date) => {
9620
+ return new Date(
9621
+ Date.UTC(
9622
+ date.getFullYear(),
9623
+ date.getMonth(),
9624
+ date.getDate(),
9625
+ 23,
9626
+ 59,
9627
+ 59,
9628
+ 999
9629
+ )
9630
+ );
9618
9631
  };
9619
9632
  var useSymbolPerformanceScript = (symbol) => {
9620
9633
  const { wrongNetwork, disabledConnect } = orderlyReactApp.useAppContext();
@@ -9631,34 +9644,26 @@ var useSymbolPerformanceScript = (symbol) => {
9631
9644
  const [dateRange, setDateRange] = React12.useState(() => {
9632
9645
  const range = getDateRange("7D" /* WEEK */, today);
9633
9646
  return {
9634
- from: normalizeDateToUTC(range.from),
9635
- to: normalizeDateToUTC(range.to)
9647
+ from: range.from,
9648
+ to: range.to
9636
9649
  };
9637
9650
  });
9638
9651
  const onPeriodChange = (value) => {
9639
9652
  const newRange = getDateRange(value, today);
9640
9653
  setPeriod(value);
9641
9654
  setDateRange({
9642
- from: normalizeDateToUTC(newRange.from),
9643
- to: normalizeDateToUTC(newRange.to)
9655
+ from: newRange.from,
9656
+ to: newRange.to
9644
9657
  });
9645
9658
  };
9646
9659
  const onFilter = (filter) => {
9647
9660
  if (filter.name === "dateRange") {
9648
9661
  const newDateRange = filter.value;
9649
- const normalizedRange = {
9650
- from: normalizeDateToUTC(newDateRange.from),
9651
- to: normalizeDateToUTC(newDateRange.to)
9652
- };
9653
- setDateRange(normalizedRange);
9654
- if (normalizedRange.from && normalizedRange.to) {
9655
- const offsetDay = Math.abs(dateFns.differenceInDays(normalizedRange.from, normalizedRange.to)) + 1;
9662
+ setDateRange(newDateRange);
9663
+ if (newDateRange.from && newDateRange.to) {
9664
+ const offsetDay = Math.abs(dateFns.differenceInDays(newDateRange.from, newDateRange.to)) + 1;
9656
9665
  const range = getDateRange(offsetDay, today);
9657
- const normalizedRangeForComparison = {
9658
- from: normalizeDateToUTC(range.from),
9659
- to: normalizeDateToUTC(range.to)
9660
- };
9661
- if (formatDateRange(normalizedRangeForComparison.from) === formatDateRange(normalizedRange.from) && formatDateRange(normalizedRangeForComparison.to) === formatDateRange(normalizedRange.to)) {
9666
+ if (formatDateRange(range.from) === formatDateRange(newDateRange.from) && formatDateRange(range.to) === formatDateRange(newDateRange.to)) {
9662
9667
  setPeriod(
9663
9668
  Object.keys(PRESET_DAYS).find(
9664
9669
  (key) => PRESET_DAYS[key] === offsetDay
@@ -9672,10 +9677,15 @@ var useSymbolPerformanceScript = (symbol) => {
9672
9677
  };
9673
9678
  const startDate = dateRange.from;
9674
9679
  const endDate = dateRange.to;
9680
+ const startDateForAPI = React12.useMemo(() => {
9681
+ if (!startDate)
9682
+ return startDate;
9683
+ return getUtcStartOfDay(startDate);
9684
+ }, [startDate]);
9675
9685
  const endDateForAPI = React12.useMemo(() => {
9676
9686
  if (!endDate)
9677
9687
  return endDate;
9678
- return dateFns.endOfDay(endDate);
9688
+ return getUtcEndOfDay(endDate);
9679
9689
  }, [endDate]);
9680
9690
  const filterItems = React12.useMemo(() => {
9681
9691
  return [
@@ -9689,12 +9699,12 @@ var useSymbolPerformanceScript = (symbol) => {
9689
9699
  }, [dateRange]);
9690
9700
  const { trades, isLoading, error } = useTrades({
9691
9701
  symbol: selectedSymbol === "ALL_SYMBOLS" ? void 0 : selectedSymbol,
9692
- start_t: startDate ? startDate.getTime() : void 0,
9702
+ start_t: startDateForAPI ? startDateForAPI.getTime() : void 0,
9693
9703
  end_t: endDateForAPI ? endDateForAPI.getTime() : void 0
9694
9704
  });
9695
9705
  const performanceData = useSymbolPerformanceData(
9696
9706
  trades,
9697
- startDate,
9707
+ startDateForAPI,
9698
9708
  endDateForAPI,
9699
9709
  true
9700
9710
  );