@stackedapp/utils 2.49.1 → 2.49.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.
@@ -226,27 +226,34 @@ function evaluateStakedTokens(cond, ctx) {
226
226
  return { isMet, details };
227
227
  }
228
228
  function evaluateLoginStreak(cond, ctx) {
229
- let trackerAmount;
230
- if (ctx.completionTrackers?.currentLoginStreak != null) {
231
- // Completion context: streak gained since offer surfaced
232
- trackerAmount = (ctx.snap.loginStreak || 0) - (ctx.completionTrackers.currentLoginStreak || 0) + 1;
229
+ const streakAtSurface = ctx.completionTrackers?.currentLoginStreak;
230
+ const currentStreak = ctx.snap.loginStreak || 0;
231
+ let isMet;
232
+ let displayAmount;
233
+ let displayGoal;
234
+ if (streakAtSurface != null) {
235
+ // Completion context: delta check, but display absolute values
236
+ const delta = currentStreak - streakAtSurface + 1;
237
+ isMet = delta >= cond.days;
238
+ displayAmount = currentStreak;
239
+ displayGoal = streakAtSurface + cond.days - 1;
233
240
  }
234
241
  else {
235
242
  // Surfacing context: absolute streak
236
- trackerAmount = ctx.snap.loginStreak || 0;
243
+ isMet = currentStreak >= cond.days;
244
+ displayAmount = currentStreak;
245
+ displayGoal = cond.days;
237
246
  }
238
- const trackerGoal = cond.days;
239
- const isMet = trackerAmount >= trackerGoal;
240
247
  return {
241
248
  isMet,
242
249
  details: [
243
250
  {
244
251
  isMet,
245
252
  kind: 'loginStreak',
246
- trackerAmount,
247
- trackerGoal,
248
- percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, isMet),
249
- text: templateText(cond, { current: trackerAmount, goal: trackerGoal }, `Login streak of ${trackerGoal || 0} days`),
253
+ trackerAmount: displayAmount,
254
+ trackerGoal: displayGoal,
255
+ percentCompleted: (0, helpers_1.calculatePercent)(displayAmount, displayGoal, isMet),
256
+ text: templateText(cond, { current: displayAmount, goal: displayGoal }, `Login streak of ${displayGoal || 0} days`),
250
257
  },
251
258
  ],
252
259
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackedapp/utils",
3
- "version": "2.49.1",
3
+ "version": "2.49.2",
4
4
  "description": "Public utilities for Stacked platform SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",