@sensiblestats/widget-react 0.108.0 → 0.108.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.js CHANGED
@@ -107,7 +107,7 @@ var STRINGS = {
107
107
  bettingKickoff: (kickoffUtc, now) => formatBettingKickoff(kickoffUtc, STRINGS.en, "en", now),
108
108
  tabChat: "Chat",
109
109
  tabFollowing: "Following",
110
- tabOdds: "Odds",
110
+ tabTrends: "Trends",
111
111
  pinLabel: "Track odds",
112
112
  unpinLabel: "Stop tracking odds",
113
113
  matchPinLabel: "Track match",
@@ -783,7 +783,7 @@ var STRINGS = {
783
783
  bettingKickoff: (kickoffUtc, now) => formatBettingKickoff(kickoffUtc, STRINGS.tr, "tr", now),
784
784
  tabChat: "Sohbet",
785
785
  tabFollowing: "Takip",
786
- tabOdds: "Oranlar",
786
+ tabTrends: "Trendler",
787
787
  pinLabel: "Oran\u0131 takip et",
788
788
  unpinLabel: "Oran takibini b\u0131rak",
789
789
  matchPinLabel: "Ma\xE7\u0131 takip et",
@@ -1411,7 +1411,7 @@ function isEnglishLocale(locale) {
1411
1411
  }
1412
1412
 
1413
1413
  // src/version.generated.ts
1414
- var WIDGET_REACT_VERSION = "0.108.0";
1414
+ var WIDGET_REACT_VERSION = "0.108.2";
1415
1415
 
1416
1416
  // src/config.ts
1417
1417
  function normalizeUi(cfg) {
@@ -1497,7 +1497,7 @@ function normalizeUi(cfg) {
1497
1497
  bettingKickoff: strings.bettingKickoff,
1498
1498
  tabChat: strings.tabChat,
1499
1499
  tabFollowing: strings.tabFollowing,
1500
- tabOdds: strings.tabOdds,
1500
+ tabTrends: strings.tabTrends,
1501
1501
  tabToday: strings.tabToday,
1502
1502
  tabFixtures: strings.tabFixtures,
1503
1503
  tabStandings: strings.tabStandings,
@@ -3988,7 +3988,7 @@ function useLiveMonitor(opts) {
3988
3988
  const marketKey = (mk, dev) => `${mk}:${dev}`;
3989
3989
  const getMarketOddsRef = useRef5(opts.getMarketOdds);
3990
3990
  getMarketOddsRef.current = opts.getMarketOdds;
3991
- const fetchMarket = useCallback4((matchId, dev, sport) => {
3991
+ const fetchMarket = useCallback4((matchId, dev, sport, background = false) => {
3992
3992
  const key = marketKey(monitorMatchKey(sport, matchId), dev);
3993
3993
  const existing = marketOddsRef.current[key];
3994
3994
  if (existing?.loading) return;
@@ -4003,15 +4003,33 @@ function useLiveMonitor(opts) {
4003
4003
  timer = setTimeout(() => reject(new Error("market timeout")), MARKET_FETCH_TIMEOUT_MS);
4004
4004
  });
4005
4005
  void Promise.race([request, timeout]).finally(() => clearTimeout(timer)).then((block) => {
4006
- const entry = { block: block ?? void 0, loading: false, error: false, fetchedAt: Date.now() };
4006
+ const kept = background ? marketOddsRef.current[key]?.block : void 0;
4007
+ const entry = { block: block ?? kept, loading: false, error: false, fetchedAt: Date.now() };
4007
4008
  marketOddsRef.current = { ...marketOddsRef.current, [key]: entry };
4008
4009
  setMarketOdds((prev) => ({ ...prev, [key]: entry }));
4009
4010
  }).catch(() => {
4010
- const entry = { ...marketOddsRef.current[key], loading: false, error: true };
4011
+ const cur = marketOddsRef.current[key];
4012
+ const entry = { ...cur, loading: false, error: !(background && cur?.block) };
4011
4013
  marketOddsRef.current = { ...marketOddsRef.current, [key]: entry };
4012
4014
  setMarketOdds((prev) => ({ ...prev, [key]: entry }));
4013
4015
  });
4014
4016
  }, []);
4017
+ const insightAskedAtRef = useRef5({});
4018
+ const refreshMissingInsight = useCallback4((snap) => {
4019
+ const pin = pinsRef.current.find((p) => p.kind === "match" && p.key === selectedRef.current);
4020
+ if (!pin) return;
4021
+ const mk = monitorMatchKey(pin.sport, pin.matchId);
4022
+ const dev = openMarketRef.current[mk];
4023
+ if (!dev) return;
4024
+ const available = matchFor(snap, pin)?.availableMarkets?.find((m) => m.marketDeveloperName === dev);
4025
+ if (!available?.hasInsight || available.suspended) return;
4026
+ const key = marketKey(mk, dev);
4027
+ const entry = marketOddsRef.current[key];
4028
+ if (!entry || entry.loading || entry.error || entry.block?.insight?.text) return;
4029
+ if (Date.now() - (insightAskedAtRef.current[key] ?? 0) < MARKET_FRESH_MS) return;
4030
+ insightAskedAtRef.current[key] = Date.now();
4031
+ fetchMarket(pin.matchId, dev, pin.sport, true);
4032
+ }, [fetchMarket]);
4015
4033
  const getPlayerPropsRef = useRef5(opts.getPlayerProps);
4016
4034
  getPlayerPropsRef.current = opts.getPlayerProps;
4017
4035
  const playerPropsRef = useRef5({});
@@ -4040,7 +4058,8 @@ function useLiveMonitor(opts) {
4040
4058
  if (!wasOpen && !marketUsable(existing)) {
4041
4059
  fetchMarket(matchId, dev, sport);
4042
4060
  }
4043
- }, [fetchMarket]);
4061
+ refreshMissingInsight(snapshotRef.current);
4062
+ }, [fetchMarket, refreshMissingInsight]);
4044
4063
  const retryMarket = useCallback4((matchId, dev, sport) => {
4045
4064
  fetchMarket(matchId, dev, sport);
4046
4065
  }, [fetchMarket]);
@@ -4060,7 +4079,8 @@ function useLiveMonitor(opts) {
4060
4079
  selectedRef.current = key;
4061
4080
  setSelectedMatchKey(key);
4062
4081
  openSelectedDefault(snapshotRef.current);
4063
- }, [openSelectedDefault]);
4082
+ refreshMissingInsight(snapshotRef.current);
4083
+ }, [openSelectedDefault, refreshMissingInsight]);
4064
4084
  const applySnapshot = useCallback4((next) => {
4065
4085
  if (next === null) {
4066
4086
  setEnabled(false);
@@ -4081,6 +4101,7 @@ function useLiveMonitor(opts) {
4081
4101
  }
4082
4102
  if (sawNewGoalOrRed && activeTabRef.current !== "following") setMatchesDot(true);
4083
4103
  openSelectedDefault(next);
4104
+ refreshMissingInsight(next);
4084
4105
  const marketPins = currentPins.filter((p) => p.kind !== "match");
4085
4106
  if (activeTabRef.current === "odds") {
4086
4107
  setLastViewedPrices((prevMap) => {
@@ -4119,7 +4140,7 @@ function useLiveMonitor(opts) {
4119
4140
  if (recoveredKeys.length > 0) store.clearGrace(recoveredKeys);
4120
4141
  snapshotRef.current = next;
4121
4142
  setSnapshotState(next);
4122
- }, [store, openSelectedDefault]);
4143
+ }, [store, openSelectedDefault, refreshMissingInsight]);
4123
4144
  const inFlightRef = useRef5(false);
4124
4145
  const pendingRef = useRef5(false);
4125
4146
  const inFlightKeysRef = useRef5("");
@@ -9292,7 +9313,7 @@ function TabBar({ monitor, ui, matchCount, oddsCount, todayCount, hasToday, game
9292
9313
  ] : [
9293
9314
  ...hasToday ? [{ tab: "today", label: ui.tabToday, count: todayCount, dot: monitor.todayDot }] : [],
9294
9315
  ...matchCount > 0 ? [{ tab: "following", label: ui.tabFollowing, count: matchCount, dot: monitor.matchesDot }] : [],
9295
- ...oddsCount > 0 ? [{ tab: "odds", label: ui.tabOdds, count: oddsCount, dot: monitor.oddsDot }] : []
9316
+ ...oddsCount > 0 ? [{ tab: "odds", label: ui.tabTrends, count: oddsCount, dot: monitor.oddsDot }] : []
9296
9317
  ],
9297
9318
  ...gamesEnabled ? [{ tab: "games", label: ui.tabGames, count: 0, dot: false }] : [],
9298
9319
  ...favouritesEnabled && !clubEnabled ? [{ tab: "favourites", label: ui.tabFavourites, count: 0, dot: false }] : []