|
| 1 | +import {useState} from "nuxt/app"; |
| 2 | +import {CollectionList, CollectionSlug, RedditCollection} from "~/models/reddit_collection"; |
| 3 | +import {RedditCollectionTier, TierHash, TierList} from "~/models/reddit_collection_tier"; |
| 4 | +import {AvatarHash, AvatarList, RedditAvatar} from "~/models/reddit_avatar"; |
| 5 | +import {Alert, AlertHash, AlertList} from "~/models/alert"; |
| 6 | + |
| 7 | +export const useCollectionList = () => useState<CollectionList>('collection-list', () => new Map<CollectionSlug, RedditCollection>()); |
| 8 | +export const useTierList = () => useState<TierList>('tier-list', () => new Map<TierHash, RedditCollectionTier>()); |
| 9 | +export const useAvatarList = () => useState<AvatarList>('avatar-list', () => new Map<AvatarHash, RedditAvatar>()); |
| 10 | +export const useAlertList = () => useState<AlertList>('alert-list', () => new Map<AlertHash, Alert>()); |
| 11 | + |
| 12 | +async function update_tier_and_avatar_list() { |
| 13 | + let tierList: Map<TierHash, RedditCollectionTier> = new Map<TierHash, RedditCollectionTier>(); |
| 14 | + let avatarList: Map<AvatarHash, RedditAvatar> = new Map<AvatarHash, RedditAvatar>(); |
| 15 | + |
| 16 | + let collectionList = useCollectionList().value; |
| 17 | + |
| 18 | + collectionList.forEach((collection) => { |
| 19 | + collection.tiers.forEach( async (tier) => { |
| 20 | + tierList.set(await tier.calculate_hash(), tier); |
| 21 | + |
| 22 | + for (let mint = 1; mint <= tier.mints; mint++) { |
| 23 | + let avatar = new RedditAvatar( |
| 24 | + await tier.calculate_hash(), |
| 25 | + tier.contract_address, |
| 26 | + tier.tier, |
| 27 | + tier.name, |
| 28 | + mint, |
| 29 | + "" |
| 30 | + ); |
| 31 | + |
| 32 | + avatarList.set(await avatar.calculate_hash(), avatar); |
| 33 | + } |
| 34 | + }) |
| 35 | + }) |
| 36 | + |
| 37 | + useTierList().value = tierList; |
| 38 | + useAvatarList().value = avatarList; |
| 39 | +} |
| 40 | + |
| 41 | +export async function set_collection_list(collectionList: CollectionList) { |
| 42 | + useCollectionList().value = collectionList; |
| 43 | + |
| 44 | + await update_tier_and_avatar_list() |
| 45 | +} |
0 commit comments