@stackedapp/utils 1.17.1 → 1.17.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/conditions.js +87 -10
- package/package.json +3 -3
package/dist/conditions.js
CHANGED
|
@@ -1155,24 +1155,101 @@ const meetsCompletionConditions = ({ completionConditions, completionTrackers, p
|
|
|
1155
1155
|
// Evaluate contractInteractions completion trackers
|
|
1156
1156
|
if (conditions?.contractInteractions) {
|
|
1157
1157
|
for (const [conditionId, condition] of Object.entries(conditions.contractInteractions)) {
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
const
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1163
|
-
|
|
1158
|
+
// Tracker now stores { amount: number, count: number }
|
|
1159
|
+
// Default to { amount: 0, count: 0 } if missing
|
|
1160
|
+
const rawTracker = completionTrackers?.contractInteractions?.[conditionId];
|
|
1161
|
+
const trackerData = rawTracker || { amount: 0, count: 0 };
|
|
1162
|
+
const trackerAmount = trackerData.amount || 0;
|
|
1163
|
+
const trackerCount = trackerData.count || 0;
|
|
1164
|
+
// Goals
|
|
1165
|
+
const minAmount = condition.minAmount ? condition.minAmount * claimMultiplier : 0;
|
|
1166
|
+
const maxAmount = condition.maxAmount ? condition.maxAmount * claimMultiplier : undefined;
|
|
1167
|
+
const minCount = condition.minCount ? condition.minCount * claimMultiplier : 0;
|
|
1168
|
+
const maxCount = condition.maxCount ? condition.maxCount * claimMultiplier : undefined;
|
|
1169
|
+
let isDisqualify = false;
|
|
1170
|
+
// Check Amounts
|
|
1171
|
+
if (shouldScale) {
|
|
1172
|
+
// If we have scaling (claimMultiplier), we handle max claims calculation differently
|
|
1173
|
+
// For now, assume standard validation
|
|
1174
|
+
}
|
|
1175
|
+
if (minAmount > 0 && trackerAmount < minAmount)
|
|
1176
|
+
isDisqualify = true;
|
|
1177
|
+
if (maxAmount !== undefined && trackerAmount > maxAmount)
|
|
1178
|
+
isDisqualify = true;
|
|
1179
|
+
// Check Counts
|
|
1180
|
+
if (minCount > 0 && trackerCount < minCount)
|
|
1181
|
+
isDisqualify = true;
|
|
1182
|
+
if (maxCount !== undefined && trackerCount > maxCount)
|
|
1183
|
+
isDisqualify = true;
|
|
1184
|
+
if (shouldScale) {
|
|
1185
|
+
// Update max claims based on whatever allows the FEWEST claims
|
|
1186
|
+
// e.g. if I have enough Amount for 3 claims but enough Count for 1 claim, I can only make 1 claim.
|
|
1187
|
+
const possibleClaimsByAmount = condition.minAmount
|
|
1188
|
+
? Math.floor(trackerAmount / condition.minAmount)
|
|
1189
|
+
: Number.MAX_SAFE_INTEGER;
|
|
1190
|
+
const possibleClaimsByCount = condition.minCount
|
|
1191
|
+
? Math.floor(trackerCount / condition.minCount)
|
|
1192
|
+
: Number.MAX_SAFE_INTEGER;
|
|
1193
|
+
const possibleClaims = Math.min(possibleClaimsByAmount, possibleClaimsByCount);
|
|
1194
|
+
// Only update if we have at least ANY requirement (Amount or Count)
|
|
1195
|
+
// If both minAmount and minCount are 0/undefined, this logic might be weird, but usually one is set.
|
|
1196
|
+
if (condition.minAmount || condition.minCount) {
|
|
1197
|
+
updateMax(possibleClaims);
|
|
1198
|
+
}
|
|
1164
1199
|
}
|
|
1165
1200
|
if (addDetails) {
|
|
1201
|
+
// Determine primary metric for progress display
|
|
1202
|
+
// If minAmount is set, use amount. Else use count.
|
|
1203
|
+
let current = trackerAmount;
|
|
1204
|
+
let goal = minAmount;
|
|
1205
|
+
let percent = 0;
|
|
1206
|
+
// If both are set, display percent based on the average of the two
|
|
1207
|
+
const hasMin = minAmount > 0 || minCount > 0;
|
|
1208
|
+
const hasMax = (maxAmount !== undefined && maxAmount > 0) || (maxCount !== undefined && maxCount > 0);
|
|
1209
|
+
if (!hasMin && hasMax) {
|
|
1210
|
+
// If only max is set: > 0 progress = 100%, else 0%
|
|
1211
|
+
const maxAmountSet = maxAmount !== undefined && maxAmount > 0;
|
|
1212
|
+
const maxCountSet = maxCount !== undefined && maxCount > 0;
|
|
1213
|
+
let pcts = [];
|
|
1214
|
+
if (maxAmountSet) {
|
|
1215
|
+
pcts.push(trackerAmount > 0 ? 100 : 0);
|
|
1216
|
+
}
|
|
1217
|
+
if (maxCountSet) {
|
|
1218
|
+
pcts.push(trackerCount > 0 ? 100 : 0);
|
|
1219
|
+
}
|
|
1220
|
+
if (pcts.length > 0) {
|
|
1221
|
+
percent = pcts.reduce((a, b) => a + b, 0) / pcts.length;
|
|
1222
|
+
}
|
|
1223
|
+
else {
|
|
1224
|
+
percent = 0;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
else if (minAmount > 0 && minCount > 0) {
|
|
1228
|
+
const pctAmount = calculatePercent(trackerAmount, minAmount, true); // clamp to 100
|
|
1229
|
+
const pctCount = calculatePercent(trackerCount, minCount, true);
|
|
1230
|
+
percent = (pctAmount + pctCount) / 2;
|
|
1231
|
+
}
|
|
1232
|
+
else if (minCount > 0) {
|
|
1233
|
+
current = trackerCount;
|
|
1234
|
+
goal = minCount;
|
|
1235
|
+
percent = calculatePercent(current, goal, !isDisqualify);
|
|
1236
|
+
}
|
|
1237
|
+
else {
|
|
1238
|
+
percent = calculatePercent(trackerAmount, minAmount || 0, !isDisqualify);
|
|
1239
|
+
}
|
|
1166
1240
|
const displayText = (0, template_1.renderTemplate)(condition.template, {
|
|
1167
|
-
|
|
1168
|
-
|
|
1241
|
+
currentAmount: trackerAmount || 0,
|
|
1242
|
+
currentCount: trackerCount || 0,
|
|
1243
|
+
minAmount: minAmount || 0,
|
|
1244
|
+
maxAmount: maxAmount || 0,
|
|
1245
|
+
minCount: minCount || 0,
|
|
1246
|
+
maxCount: maxCount || 0,
|
|
1169
1247
|
});
|
|
1170
1248
|
conditionData.push({
|
|
1171
1249
|
isMet: !isDisqualify,
|
|
1172
1250
|
kind: 'contractInteractions',
|
|
1173
1251
|
trackerAmount,
|
|
1174
|
-
|
|
1175
|
-
percentCompleted: calculatePercent(trackerAmount, trackerGoal, !isDisqualify),
|
|
1252
|
+
percentCompleted: percent,
|
|
1176
1253
|
text: displayText,
|
|
1177
1254
|
});
|
|
1178
1255
|
if (isDisqualify)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackedapp/utils",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.3",
|
|
4
4
|
"description": "Public utilities for Stacked platform SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
26
|
-
"@semantic-release/gitlab": "^13.
|
|
27
|
-
"@semantic-release/npm": "^13.1.
|
|
26
|
+
"@semantic-release/gitlab": "^13.3.0",
|
|
27
|
+
"@semantic-release/npm": "^13.1.4",
|
|
28
28
|
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
29
29
|
"conventional-changelog-conventionalcommits": "^9.1.0"
|
|
30
30
|
}
|