Skip to content

Commit

Permalink
evolution/ evolution limit
Browse files Browse the repository at this point in the history
  • Loading branch information
MGrudule committed Oct 22, 2024
1 parent c01c153 commit ecf7b8b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 12 additions & 1 deletion apps/verification-portal/src/lib/features/DOTphin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export async function updateMultipassStateForAddress(address: string) {
DID: data.dotphinDID,
pending: false,
},
evolution: {
level: data.dotphin ? getLevelAttributeValue(data.dotphin) : 0,
maxLevel: data.dotphinMaxLevel,
},
});

if (data.dotphinDID) {
Expand Down Expand Up @@ -121,7 +125,13 @@ async function fetchNFTDataByDID(did: string) {
console.error('Error fetching NFT data:', error);
}
}

// Get Level Attribute Value
function getLevelAttributeValue(asset: DeepAsset): number {
const levelAttribute = asset.attributes?.find(
(attr) => attr.trait_type === 'level'
);
return levelAttribute ? Number(levelAttribute.value) : 0;
}
// Find Proof by Trait Type
function findProofByTraitType(
proofs: DeepAsset[],
Expand Down Expand Up @@ -192,6 +202,7 @@ export async function evolveDOTphinNFT(
},
nft: { DID: dotphinDID, data: evolveData, pending: true },
evolution: {
...currentState.evolution,
level: currentState.evolution.level + 1,
},
});
Expand Down
10 changes: 7 additions & 3 deletions apps/verification-portal/src/lib/features/MultipassStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const canEvolve = isFeatureEnabled('dotphinEvolution');

import {
MAX_EVOLUTION_LEVEL,
EVOLUTION_LIMIT,
initialStepConfig,
STATUS,
} from '$lib/shared/multipassConfig';
Expand Down Expand Up @@ -39,6 +38,7 @@ export type MultipassData = {
};
evolution: {
level: number;
maxLevel: number;
};
};

Expand All @@ -58,6 +58,7 @@ const initialState: MultipassData = {
},
evolution: {
level: 0,
maxLevel: MAX_EVOLUTION_LEVEL, // set limit same as max
},
};

Expand Down Expand Up @@ -112,7 +113,9 @@ export const evolveStepState = derived(
return 'INITIAL';
} else if ($multipassData.evolution.level >= MAX_EVOLUTION_LEVEL) {
return 'COMPLETE';
} else if ($multipassData.evolution.level >= EVOLUTION_LIMIT) {
} else if (
$multipassData.evolution.level >= $multipassData.evolution.maxLevel
) {
return 'LIMITED';
} else {
return 'EVOLVING';
Expand Down Expand Up @@ -159,7 +162,8 @@ export const multipassStepConfig = derived(
: proofsStatus === STATUS.COMPLETE && nftStatus === STATUS.COMPLETE
? $multipassData.evolution.level >= MAX_EVOLUTION_LEVEL
? STATUS.COMPLETE
: $multipassData.evolution.level >= EVOLUTION_LIMIT
: $multipassData.evolution.level >=
$multipassData.evolution.maxLevel
? STATUS.LOCKED
: STATUS.ACTIVE
: STATUS.LOCKED;
Expand Down

0 comments on commit ecf7b8b

Please sign in to comment.