@stackedapp/utils 1.15.12 → 1.16.0

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.
@@ -1,4 +1,4 @@
1
- import { StackedCompletionConditions, StackedOffer, StackedSnapshot, StackedBaseUserExtra, StackedBaseConditions, StackedClaimableConditions, StackedClaimableTrackers, StackedCompletionTrackers, StackedDynamicCondition, StackedDynamicGroup, StackedOfferTrackers } from '@stackedapp/types';
1
+ import { StackedCompletionConditions, StackedOffer, StackedSnapshot, StackedBaseUserExtra, StackedBaseConditions, StackedClaimableConditions, StackedClaimableTrackers, StackedCompletionTrackers, StackedDynamicCondition, StackedDynamicGroup, StackedOfferTrackers, ConditionDetail } from '@stackedapp/types';
2
2
  export declare const DEFAULT_ENTITY_KIND = "_default";
3
3
  export declare const meetsBaseConditions: ({ conditions, playerSnap, addDetails, playerOffer, additionalData, }: {
4
4
  conditions: StackedBaseConditions;
@@ -20,16 +20,7 @@ export declare const meetsBaseConditions: ({ conditions, playerSnap, addDetails,
20
20
  isValid: boolean;
21
21
  isComplete: boolean;
22
22
  percentCompleted: number;
23
- conditionData: {
24
- isMet: boolean;
25
- kind?: keyof StackedBaseConditions;
26
- /** @deprecated Use percentCompleted instead */
27
- trackerAmount?: number;
28
- /** @deprecated Use percentCompleted instead */
29
- trackerGoal?: number;
30
- percentCompleted: number;
31
- text: string;
32
- }[] | undefined;
23
+ conditionData: ConditionDetail[] | undefined;
33
24
  };
34
25
  export declare const hasCompletionConditions: (conditions: StackedCompletionConditions) => boolean;
35
26
  export declare const meetsLinkedEntityOffersCondition: ({ linkedEntityOffers, matchingLinks, linkedPOfferMap, }: {
@@ -58,16 +49,7 @@ export declare const offerMeetsCompletionConditions: (offer: StackedOffer, snaps
58
49
  isValid: boolean;
59
50
  isComplete: boolean;
60
51
  percentCompleted: number;
61
- conditionData: {
62
- isMet: boolean;
63
- kind?: keyof StackedCompletionConditions | "context";
64
- /** @deprecated Use percentCompleted instead */
65
- trackerAmount?: number;
66
- /** @deprecated Use percentCompleted instead */
67
- trackerGoal?: number;
68
- percentCompleted: number;
69
- text: string;
70
- }[];
52
+ conditionData: ConditionDetail[];
71
53
  availableClaimsNow: number;
72
54
  };
73
55
  export declare const meetsCompletionConditions: ({ completionConditions, completionTrackers, playerSnap, playerOffer, addDetails, maxClaimCount, additionalData, }: {
@@ -92,16 +74,7 @@ export declare const meetsCompletionConditions: ({ completionConditions, complet
92
74
  isValid: boolean;
93
75
  isComplete: boolean;
94
76
  percentCompleted: number;
95
- conditionData: {
96
- isMet: boolean;
97
- kind?: keyof StackedCompletionConditions | "context";
98
- /** @deprecated Use percentCompleted instead */
99
- trackerAmount?: number;
100
- /** @deprecated Use percentCompleted instead */
101
- trackerGoal?: number;
102
- percentCompleted: number;
103
- text: string;
104
- }[];
77
+ conditionData: ConditionDetail[];
105
78
  availableClaimsNow: number;
106
79
  };
107
80
  /**
@@ -635,6 +635,77 @@ additionalData, }) => {
635
635
  }
636
636
  }
637
637
  }
638
+ // Evaluate stackedAccount conditions
639
+ if (conditions?.stackedAccount) {
640
+ const { hasLinkedAccount, cryptoWallets } = conditions.stackedAccount;
641
+ // Check if player has linked stacked account
642
+ if (hasLinkedAccount !== undefined) {
643
+ const playerHasAccount = additionalData?.hasStackedAccount ?? false;
644
+ const isDisqualify = hasLinkedAccount !== playerHasAccount;
645
+ if (addDetails) {
646
+ conditionData.push({
647
+ isMet: !isDisqualify,
648
+ kind: 'stackedAccount.hasLinkedAccount',
649
+ trackerAmount: playerHasAccount ? 1 : 0,
650
+ trackerGoal: 1,
651
+ percentCompleted: !isDisqualify ? 100 : 0,
652
+ text: hasLinkedAccount ? 'Link a Stacked account' : 'Must not have Stacked account linked',
653
+ });
654
+ if (isDisqualify)
655
+ isValid = false;
656
+ }
657
+ else {
658
+ if (isDisqualify)
659
+ return { isValid: false, isComplete: false, percentCompleted: 0 };
660
+ }
661
+ }
662
+ // Check crypto wallet count
663
+ if (cryptoWallets) {
664
+ const walletCount = additionalData?.cryptoWallets?.length || 0;
665
+ if (cryptoWallets.min !== undefined) {
666
+ const trackerAmount = walletCount;
667
+ const trackerGoal = cryptoWallets.min;
668
+ const isDisqualify = trackerAmount < trackerGoal;
669
+ if (addDetails) {
670
+ conditionData.push({
671
+ isMet: !isDisqualify,
672
+ kind: 'stackedAccount.cryptoWallets',
673
+ trackerAmount,
674
+ trackerGoal,
675
+ percentCompleted: calculatePercent(trackerAmount, trackerGoal, !isDisqualify),
676
+ text: `Link at least ${trackerGoal} crypto wallet${trackerGoal === 1 ? '' : 's'}`,
677
+ });
678
+ if (isDisqualify)
679
+ isValid = false;
680
+ }
681
+ else {
682
+ if (isDisqualify)
683
+ return { isValid: false, isComplete: false, percentCompleted: 0 };
684
+ }
685
+ }
686
+ if (cryptoWallets.max !== undefined) {
687
+ const trackerAmount = walletCount;
688
+ const trackerGoal = cryptoWallets.max;
689
+ const isDisqualify = trackerAmount > trackerGoal;
690
+ if (addDetails) {
691
+ conditionData.push({
692
+ isMet: !isDisqualify,
693
+ kind: 'stackedAccount.cryptoWallets',
694
+ trackerAmount,
695
+ trackerGoal,
696
+ percentCompleted: !isDisqualify ? 100 : 0, // Binary for max conditions
697
+ text: `Have at most ${trackerGoal} crypto wallet${trackerGoal === 1 ? '' : 's'}`,
698
+ });
699
+ if (isDisqualify)
700
+ isValid = false;
701
+ }
702
+ else {
703
+ if (isDisqualify)
704
+ return { isValid: false, isComplete: false, percentCompleted: 0 };
705
+ }
706
+ }
707
+ }
708
+ }
638
709
  // Calculate top-level percentCompleted as average of all condition percentages
639
710
  const percentCompleted = conditionData.length > 0
640
711
  ? conditionData.reduce((sum, c) => sum + c.percentCompleted, 0) / conditionData.length
@@ -698,6 +769,8 @@ const hasCompletionConditions = (conditions) => {
698
769
  return true;
699
770
  if (Object.keys(compCond.contractInteractions || {}).length > 0)
700
771
  return true;
772
+ if (conditions.stackedAccount)
773
+ return true;
701
774
  return false;
702
775
  };
703
776
  exports.hasCompletionConditions = hasCompletionConditions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackedapp/utils",
3
- "version": "1.15.12",
3
+ "version": "1.16.0",
4
4
  "description": "Public utilities for Stacked platform SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",