@loafmarkets/ui 0.1.2 → 0.1.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.d.mts CHANGED
@@ -280,7 +280,7 @@ declare const YourOrders: React.ForwardRefExoticComponent<React.HTMLAttributes<H
280
280
  renderOrderActions?: (order: YourOrder) => React.ReactNode;
281
281
  } & React.RefAttributes<HTMLDivElement>>;
282
282
 
283
- type PriceChartRange = "1D" | "1W" | "1M" | "3M" | "1Y";
283
+ type PriceChartRange = "15m" | "1h" | "4h" | "24h" | "1W" | "1M";
284
284
  type PriceChartCandle = {
285
285
  time: LightweightCharts.Time;
286
286
  open: number;
package/dist/index.d.ts CHANGED
@@ -280,7 +280,7 @@ declare const YourOrders: React.ForwardRefExoticComponent<React.HTMLAttributes<H
280
280
  renderOrderActions?: (order: YourOrder) => React.ReactNode;
281
281
  } & React.RefAttributes<HTMLDivElement>>;
282
282
 
283
- type PriceChartRange = "1D" | "1W" | "1M" | "3M" | "1Y";
283
+ type PriceChartRange = "15m" | "1h" | "4h" | "24h" | "1W" | "1M";
284
284
  type PriceChartCandle = {
285
285
  time: LightweightCharts.Time;
286
286
  open: number;
package/dist/index.js CHANGED
@@ -4567,7 +4567,97 @@ var YourOrders = o__namespace.forwardRef(
4567
4567
  }
4568
4568
  );
4569
4569
  YourOrders.displayName = "YourOrders";
4570
- var defaultRanges = ["1D", "1W", "1M", "3M", "1Y"];
4570
+ var timeToDate = (time) => {
4571
+ if (typeof time === "number") {
4572
+ return new Date(time * 1e3);
4573
+ }
4574
+ if (typeof time === "object" && time !== null && "year" in time && "month" in time && "day" in time) {
4575
+ const { year, month, day } = time;
4576
+ return new Date(Date.UTC(year, month - 1, day));
4577
+ }
4578
+ return null;
4579
+ };
4580
+ var createTickFormatter = (formatOptions) => {
4581
+ return (time, _tickMarkType, locale) => {
4582
+ const date = timeToDate(time);
4583
+ if (!date) return "";
4584
+ return date.toLocaleString(locale || void 0, formatOptions);
4585
+ };
4586
+ };
4587
+ var getTimeScaleOptions = (range) => {
4588
+ switch (range) {
4589
+ case "15m":
4590
+ return {
4591
+ timeVisible: true,
4592
+ secondsVisible: false,
4593
+ borderColor: "rgba(255,255,255,0.06)",
4594
+ tickMarkFormatter: createTickFormatter({ hour: "2-digit", minute: "2-digit" })
4595
+ };
4596
+ case "1h":
4597
+ return {
4598
+ timeVisible: true,
4599
+ secondsVisible: false,
4600
+ borderColor: "rgba(255,255,255,0.06)",
4601
+ tickMarkFormatter: createTickFormatter({ hour: "2-digit", minute: "2-digit" })
4602
+ };
4603
+ case "4h":
4604
+ return {
4605
+ timeVisible: true,
4606
+ secondsVisible: false,
4607
+ borderColor: "rgba(255,255,255,0.06)",
4608
+ tickMarkFormatter: createTickFormatter({ weekday: "short", hour: "2-digit" })
4609
+ };
4610
+ case "24h":
4611
+ return {
4612
+ timeVisible: true,
4613
+ secondsVisible: false,
4614
+ borderColor: "rgba(255,255,255,0.06)",
4615
+ tickMarkFormatter: createTickFormatter({ month: "short", day: "numeric" })
4616
+ };
4617
+ case "1W":
4618
+ return {
4619
+ timeVisible: true,
4620
+ secondsVisible: false,
4621
+ borderColor: "rgba(255,255,255,0.06)",
4622
+ tickMarkFormatter: createTickFormatter({ month: "short", day: "numeric" })
4623
+ };
4624
+ case "1M":
4625
+ return {
4626
+ timeVisible: true,
4627
+ secondsVisible: false,
4628
+ borderColor: "rgba(255,255,255,0.06)",
4629
+ tickMarkFormatter: createTickFormatter({ month: "short", year: "2-digit" })
4630
+ };
4631
+ default:
4632
+ return {
4633
+ timeVisible: true,
4634
+ secondsVisible: false,
4635
+ borderColor: "rgba(255,255,255,0.06)"
4636
+ };
4637
+ }
4638
+ };
4639
+ var getPriceScaleOptions = (data) => {
4640
+ if (!data.length) return {
4641
+ borderColor: "rgba(230, 200, 126, 0.25)",
4642
+ textColor: "rgba(230, 200, 126, 0.7)"
4643
+ };
4644
+ const prices = data.flatMap((d2) => [d2.open, d2.high, d2.low, d2.close]);
4645
+ const minPrice = Math.min(...prices);
4646
+ const maxPrice = Math.max(...prices);
4647
+ const priceRange = maxPrice - minPrice;
4648
+ let scaleMargins = { top: 0.1, bottom: 0.1 };
4649
+ if (priceRange < 1) {
4650
+ scaleMargins = { top: 0.2, bottom: 0.2 };
4651
+ } else if (priceRange > 1e3) {
4652
+ scaleMargins = { top: 0.05, bottom: 0.05 };
4653
+ }
4654
+ return {
4655
+ borderColor: "rgba(230, 200, 126, 0.25)",
4656
+ textColor: "rgba(230, 200, 126, 0.7)",
4657
+ scaleMargins
4658
+ };
4659
+ };
4660
+ var defaultRanges = ["15m", "1h", "4h", "24h", "1W", "1M"];
4571
4661
  var formatPrice = (value, currencySymbol) => {
4572
4662
  return `${currencySymbol}${value.toLocaleString(void 0, {
4573
4663
  minimumFractionDigits: 2,
@@ -4636,15 +4726,8 @@ var PriceChart = o__namespace.forwardRef(
4636
4726
  vertLines: { color: "rgba(255,255,255,0.06)" },
4637
4727
  horzLines: { color: "rgba(255,255,255,0.06)" }
4638
4728
  },
4639
- rightPriceScale: {
4640
- borderColor: "rgba(230, 200, 126, 0.25)",
4641
- textColor: "rgba(230, 200, 126, 0.7)"
4642
- },
4643
- timeScale: {
4644
- borderColor: "rgba(255,255,255,0.06)",
4645
- timeVisible: true,
4646
- secondsVisible: false
4647
- },
4729
+ rightPriceScale: getPriceScaleOptions(data),
4730
+ timeScale: getTimeScaleOptions(selectedRange || defaultRanges[0]),
4648
4731
  crosshair: {
4649
4732
  vertLine: { color: "rgba(255,255,255,0.12)" },
4650
4733
  horzLine: { color: "rgba(255,255,255,0.12)" }
@@ -4665,11 +4748,22 @@ var PriceChart = o__namespace.forwardRef(
4665
4748
  chart.remove();
4666
4749
  };
4667
4750
  }, []);
4751
+ o__namespace.useEffect(() => {
4752
+ const chart = chartRef.current;
4753
+ if (!chart) return;
4754
+ const effectiveRange = selectedRange ?? ranges?.[0] ?? "1D";
4755
+ chart.applyOptions({
4756
+ timeScale: getTimeScaleOptions(effectiveRange)
4757
+ });
4758
+ }, [selectedRange, ranges]);
4668
4759
  o__namespace.useEffect(() => {
4669
4760
  const chart = chartRef.current;
4670
4761
  const series = seriesRef.current;
4671
4762
  if (!chart || !series) return;
4672
4763
  series.setData(data);
4764
+ chart.applyOptions({
4765
+ rightPriceScale: getPriceScaleOptions(data)
4766
+ });
4673
4767
  if (priceLineRef.current) {
4674
4768
  series.removePriceLine(priceLineRef.current);
4675
4769
  priceLineRef.current = null;