diff --git a/public/svg/hand/leftHand0.svg b/public/svg/leftHand/leftHand0.svg similarity index 100% rename from public/svg/hand/leftHand0.svg rename to public/svg/leftHand/leftHand0.svg diff --git a/public/svg/hand/leftHand1.svg b/public/svg/leftHand/leftHand1.svg similarity index 100% rename from public/svg/hand/leftHand1.svg rename to public/svg/leftHand/leftHand1.svg diff --git a/public/svg/hand/leftHand2.svg b/public/svg/leftHand/leftHand2.svg similarity index 100% rename from public/svg/hand/leftHand2.svg rename to public/svg/leftHand/leftHand2.svg diff --git a/public/svg/hand/leftHand3.svg b/public/svg/leftHand/leftHand3.svg similarity index 100% rename from public/svg/hand/leftHand3.svg rename to public/svg/leftHand/leftHand3.svg diff --git a/public/svg/hand/rightHand0.svg b/public/svg/rightHand/rightHand0.svg similarity index 100% rename from public/svg/hand/rightHand0.svg rename to public/svg/rightHand/rightHand0.svg diff --git a/public/svg/hand/rightHand1.svg b/public/svg/rightHand/rightHand1.svg similarity index 100% rename from public/svg/hand/rightHand1.svg rename to public/svg/rightHand/rightHand1.svg diff --git a/public/svg/hand/rightHand2.svg b/public/svg/rightHand/rightHand2.svg similarity index 100% rename from public/svg/hand/rightHand2.svg rename to public/svg/rightHand/rightHand2.svg diff --git a/public/svg/hand/rightHand3.svg b/public/svg/rightHand/rightHand3.svg similarity index 100% rename from public/svg/hand/rightHand3.svg rename to public/svg/rightHand/rightHand3.svg diff --git a/src/app/displayCartoon/page.tsx b/src/app/displayCartoon/page.tsx index 1e3ecf2..d629966 100644 --- a/src/app/displayCartoon/page.tsx +++ b/src/app/displayCartoon/page.tsx @@ -1,32 +1,28 @@ "use client"; import ACommonCartoonList from "@/components/ACommonCartoonList"; -import ADisplayHeader from "@/components/ADisplayHeader"; -import { TapData } from "@/components/aibum"; +import ADisplayHeader, { urlToSigninFromAlbum } from "@/components/ADisplayHeader"; import { HelpTip } from "@/components/tips"; -import { useCartoonList } from "@/hooks/useCartoonList"; import { useCopy } from "@/hooks/useCopy"; import backendApi from "@/lib/api"; import { SVGS } from "@/svg"; -import { useRouter } from "next/navigation"; -import { useEffect, useState } from "react"; +import { useQuery } from "@tanstack/react-query"; +import { useRouter, useSearchParams } from "next/navigation"; import { FaXTwitter } from "react-icons/fa6"; import { IoShareSocialSharp } from "react-icons/io5"; -import { useSetState } from "react-use"; import { toast } from "sonner"; import { useAuthContext } from "../context/AuthContext"; +import { cn } from "@nextui-org/react"; const DispalyCartoon = () => { const ac = useAuthContext(); const user = ac.queryUserInfo?.data; const r = useRouter() - const params = new URLSearchParams(window.location.search); - const uid = params.get("uid") || '' - const name = params.get("name") || '' + const sp = useSearchParams() + const uid = sp.get("uid") || '' + const name = sp.get("name") || '' const username = name?.split('@')[0] || '' - const [liked, setLiked] = useState(false) - const [data, setData] = useSetState<{ data?: TapData, loading?: boolean, }>({ data: { like: 0, list: [] }, loading: true }) const copy = useCopy(); const shareLink = `${origin}/displayCartoon?referral=${user?.inviteCode}&uid=${user?.id}&name=${user?.email}`; @@ -44,30 +40,16 @@ Join EnReach Season 1 and earn BERRY points by running a super lite node in Chro window.open(postXUrl, "_blank"); }; - const gerCartoonList = async () => { - const params = new URLSearchParams(window.location.search); - const uid = params.get("uid") || '' - try { - if (uid) { - if (ac.user?.userId && uid) { - const likedRes = await backendApi.userIsLiked(uid) - setLiked(likedRes.liked) - } - const sharedList = await backendApi.getShareUserList(uid) - setData({ data: sharedList, loading: false }) - } - } catch (error) { - setData({ loading: false }) - console.error("Error fetching data:", error); - } - - } - - - useEffect(() => { - gerCartoonList() - }, []) + const { data: likeStat, refetch: refetchLikeStat, isLoading: isLoadingLikeStat } = useQuery({ + queryKey: ['queryLikeStat', uid, user?.id], + enabled: Boolean(uid), + initialData: { liked: false, likeCount: 0 }, + queryFn: async () => { + const [liked, likeCount] = await Promise.all([backendApi.userIsLiked(uid).catch(_e => false), backendApi.userLikeCount(uid)]) + return { liked, likeCount } + } + }) let clicked = false const onLike = async () => { if (clicked) return @@ -75,13 +57,9 @@ Join EnReach Season 1 and earn BERRY points by running a super lite node in Chro if (user?.id === uid) { return } else if (!user?.id) { - const params = new URLSearchParams(window.location.search); - const referral = params.get("referral"); - const uid = params.get("uid"); - const name = params.get("name"); - r.push(`signin/?page=displayCartoon&referral=${referral}&uid=${uid}&name=${name}`) + r.push(urlToSigninFromAlbum()) return - } else if (liked) { + } else if (likeStat?.liked) { toast.success("You have liked this album."); clicked = false return @@ -89,7 +67,7 @@ Join EnReach Season 1 and earn BERRY points by running a super lite node in Chro backendApi.currentUserLike('like', uid).then((res) => { if (res.message === 'success') { - gerCartoonList() + refetchLikeStat() } }).catch((e) => { toast.error(`You need to update to Teen Berry (Lv.2 User) to unlock 'Like'.`); @@ -99,8 +77,6 @@ Join EnReach Season 1 and earn BERRY points by running a super lite node in Chro }) } - const cartoonList = useCartoonList(data.data) - return ( <> @@ -108,15 +84,15 @@ Join EnReach Season 1 and earn BERRY points by running a super lite node in Chro
{`${(uid === user?.id ? 'My Berry Album' : username && (username + '‘s Berry Album') || '')} `}
-
+
- {data.data?.like} + {likeStat.likeCount}
{user?.id === uid && @@ -135,7 +111,7 @@ Join EnReach Season 1 and earn BERRY points by running a super lite node in Chro }
- +
diff --git a/src/components/ACartoonImage.tsx b/src/components/ACartoonImage.tsx index 0dee086..d751b8d 100644 --- a/src/components/ACartoonImage.tsx +++ b/src/components/ACartoonImage.tsx @@ -1,19 +1,47 @@ -import { singleCartoon } from "./ACommonCartoonList"; -const ASSET_PATH = "/svg"; +import { useMemo } from "react"; +export type singleCartoon = { + hat: number, + head: number, + eyes: number, + clothes: number, + leftHand: number, + rightHand: number, + pants: number, + shoes: number, + logo: number, +} interface ACartoonImageProps { - data: singleCartoon; + data: singleCartoon | string; // size?: number } +const Types = [{ type: "shoes", count: 4 }, { type: "pants", count: 4 }, { type: 'leftHand', count: 4 }, { type: 'rightHand', count: 4 }, { type: "clothes", count: 5 }, { type: "logo", count: 4 }, { type: "eyes", count: 4 }, { type: "head", count: 4 }, { type: "hat", count: 4 }] as const const getSvgPath = ( - type: "hand" | "shoes" | "pants" | "clothes" | "logo" | "eyes" | "head" | "hat", + type: (typeof Types)[number]['type'], index: number | null = 0, - otherSvgPath?: string -) => `${ASSET_PATH}/${type}/${otherSvgPath || type}${index}.svg`; +) => `/svg/${type}/${type}${index}.svg`; +const toIndex = (data: string, index: number, mod: number) => { + try { + const num = parseInt(data.slice(Math.round((index * 2)), Math.round(index * 2 + 2))) + if (Number.isSafeInteger(num)) return num % mod + return 0 + } catch (error) { + return 0 + } +} const ACartoonImage: React.FC = ({ data, size = 200 }) => { - + const mdata = useMemo(() => { + if (typeof data == 'string') { + const sc = {} as singleCartoon + Types.forEach((item, index) => { + sc[item.type] = toIndex(data, index, item.count) + }) + return sc + } + return data + }, [data]) return (
@@ -28,55 +56,55 @@ const ACartoonImage: React.FC = ({ data, size = 200 }) => {
shoes pants leftHand rightHand clothes logo eyes head hat = ({ cartoonList, loading, showEmpty }) => { - const [userClickedCartoon, setUserClickedCartoon] = useState<{ value?: cartoonType, isOpen: boolean }>({ value: undefined, isOpen: false }) - const onShowOne = (item: cartoonType) => { +const ACommonCartoonList: FC = ({ showEmpty, loadType }) => { + const ac = useAuthContext() + const sp = useSearchParams() + const uid = sp.get('uid') + const { data, isFetching, fetchNextPage } = useInfiniteQuery({ + queryKey: ['queryCartoonListByUid', loadType, loadType == 'auth' ? ac.user : uid], + enabled: loadType == 'auth' ? Boolean(ac.user) : Boolean(uid), + queryFn: async ({ pageParam: pageNum }) => { + const pageSize = 10 + const pageParams = { pageSize, pageNum } + const data = await (loadType == 'auth' ? backendApi.getCartoonList(pageParams) : backendApi.getAlbumItemList(uid!, pageParams)) + return { data: data.list, next: data.list.length < 10 ? null : pageNum + 1 } + }, + initialPageParam: 1, + getNextPageParam: (lastPage) => lastPage.next + }) + const ref = useRef(null) + const intersection = useIntersection(ref, { root: null, }) + const inView = intersection && intersection.intersectionRatio >= 1 + useEffect(() => { inView && !isFetching && fetchNextPage() }, [inView, isFetching]) + + const [userClickedCartoon, setUserClickedCartoon] = useState<{ value?: TapItem, isOpen: boolean }>({ value: undefined, isOpen: false }) + const onShowOne = (item: TapItem) => { setUserClickedCartoon({ value: item, isOpen: true }) } - + const pages = data?.pages || [] + const isEmpty = !pages || pages.length == 0 || pages[0].data.length == 0 return
- {(!cartoonList || cartoonList.length == 0) && !loading && showEmpty &&
Oops! Nothing here yet.
} + {(isEmpty) && !isFetching && showEmpty &&
Oops! Nothing here yet.
}
{ - cartoonList && cartoonList.map((item, index) => { - return
onShowOne(item)} > - {item.name} -
- {item.one && } - {item.two && } -
-
- }) + pages.map(({ data }, pi) => + { + data.map((item, index) => { + return
onShowOne(item)} > + {item.content} +
+ {item.tapFromUserId && } + {item.tapToUserId && } +
+
+ }) + } +
) } { - loading && <> + isFetching && <>
@@ -58,10 +72,10 @@ const ACommonCartoonList: FC = ({ cartoonList, loading, showE tit="" msg={
- {userClickedCartoon.value?.name} + {userClickedCartoon.value?.content}
- {userClickedCartoon.value?.one && } - {userClickedCartoon.value?.two && } + {userClickedCartoon.value?.tapFromUserId && } + {userClickedCartoon.value?.tapToUserId && }
@@ -77,6 +91,7 @@ const ACommonCartoonList: FC = ({ cartoonList, loading, showE /> }
+
} diff --git a/src/components/ADisplayHeader.tsx b/src/components/ADisplayHeader.tsx index b15fb76..7c808cf 100644 --- a/src/components/ADisplayHeader.tsx +++ b/src/components/ADisplayHeader.tsx @@ -2,17 +2,20 @@ import { useAuthContext } from "@/app/context/AuthContext"; import { MAvatar } from "./avatar"; import { useRouter } from "next/navigation"; +export function urlToSigninFromAlbum() { + const params = new URLSearchParams(window.location.search); + const referral = params.get("referral"); + const uid = params.get("uid"); + const name = params.get("name"); + return `signin/?referral=${referral}&uid=${uid}&name=${name}&redirect=${encodeURIComponent(location.pathname + location.search)}` +} const ADisplayHeader = () => { const ac = useAuthContext(); const user = ac.queryUserInfo?.data; const r = useRouter() const onSwitchToHome = () => { - const params = new URLSearchParams(window.location.search); - const referral = params.get("referral"); - const uid = params.get("uid"); - const name = params.get("name"); - r.push(`signin/?referral=${referral}&uid=${uid}&name=${name}&redirect=${encodeURIComponent(location.pathname + location.search)}`) + r.push(urlToSigninFromAlbum()) } return
diff --git a/src/components/aibum.tsx b/src/components/aibum.tsx index 2917c64..663edd3 100644 --- a/src/components/aibum.tsx +++ b/src/components/aibum.tsx @@ -1,5 +1,4 @@ import { useAuthContext } from "@/app/context/AuthContext"; -import { useCartoonList } from "@/hooks/useCartoonList"; import { useCopy } from "@/hooks/useCopy"; import backendApi from "@/lib/api"; import { SVGS } from "@/svg"; @@ -44,42 +43,42 @@ Join EnReach Season 1 and earn BERRY points by running a super lite node in Chro const postXUrl = `https://x.com/intent/post?text=${encodeURIComponent(text)}&url=${encodeURIComponent(shareLink)}`; window.open(postXUrl, "_blank"); }; - const { data, isFetching: loading, refetch } = useQuery({ - queryKey: ["cartoonList"], - queryFn: backendApi.getCartoonList, - }); - const cartoonList = useCartoonList(data) + const { data: likeCount, refetch: refetchLikeCount } = useQuery({ + queryKey: ['queryLikeCount', user?.id], + enabled: Boolean(user), + initialData: 0, + queryFn: async () => { + return backendApi.userLikeCount(user?.id) + } + }) return
{/* {mc.current.contentName} */}
- {cartoonList[0]?.name && -
-
-
- {data?.like ? : } -
- - - {data?.like || 0} - +
+
+
+ {likeCount > 0 ? : }
- - - - - - + + {likeCount} +
- } + + + + + + +
- +
; }; diff --git a/src/components/inputs.tsx b/src/components/inputs.tsx index 70a10bc..19ddbac 100644 --- a/src/components/inputs.tsx +++ b/src/components/inputs.tsx @@ -5,7 +5,7 @@ import { useToggle } from "react-use"; import VerificationInput from "react-verification-input"; const inputClassNames: SlotsToClasses = { - inputWrapper: "flip_item h-[2.625rem] rounded-full bg-l1 border-none backdrop-blur-lg shadow-1 text-xs", + inputWrapper: "flip_item h-[2.625rem] rounded-full bg-l1 border-none backdrop-blur-lg shadow-1 text-xs px-4", label: "text-xs", input: "text-xs !text-white", }; diff --git a/src/components/my-dashboard.tsx b/src/components/my-dashboard.tsx index c4ac442..317f6ff 100644 --- a/src/components/my-dashboard.tsx +++ b/src/components/my-dashboard.tsx @@ -8,18 +8,18 @@ import { IconCard, TitCard } from "./cards"; import { useAuthContext } from "@/app/context/AuthContext"; import { useCopy } from "@/hooks/useCopy"; import backendApi from "@/lib/api"; -import { fmtDate, truncateEmail } from "@/lib/utils"; +import { fmtDate } from "@/lib/utils"; import { useQuery } from "@tanstack/react-query"; import EChartsReact from "echarts-for-react"; import _ from "lodash"; +import numbro from "numbro"; import { useDebounce, useMeasure } from "react-use"; import { UseMeasureRef } from "react-use/lib/useMeasure"; import { IconBtn } from "./btns"; import { fmtBerry, fmtBoost } from "./fmtData"; +import { levels } from "./level"; import { CurrentTask } from "./tasks"; import { HelpTip } from "./tips"; -import { levels } from "./level"; -import numbro from "numbro"; export function DupleInfo({ tit, diff --git a/src/hooks/useCartoonList.ts b/src/hooks/useCartoonList.ts deleted file mode 100644 index 9df80f8..0000000 --- a/src/hooks/useCartoonList.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { cartoonType, singleCartoon } from "@/components/ACommonCartoonList"; -import { TapData } from "@/components/aibum"; -import { convertNumber, convertToNew, mapDigitsToAttributes } from "@/lib/utils"; -import { useMemo } from "react"; - -export function useCartoonList(data?: TapData) { - return useMemo(() => { - if (!data?.list) return []; - const updatedList = data.list.map((item) => ({ - ...item, - tapFromUserId2: convertNumber(convertToNew(item.tapFromUserId)), - tapToUserId2: convertNumber(convertToNew(item.tapToUserId)), - })); - const createEmptyAttributes = (): singleCartoon => ({ - hat: 0, - head: 0, - eyes: 0, - clothes: 0, - hand: [0, 0], - pants: 0, - shoes: 0, - logo: 0, - }); - return updatedList.map((item, index) => { - const carton: cartoonType = { - one: createEmptyAttributes(), - two: createEmptyAttributes(), - name: item.content, - }; - mapDigitsToAttributes(carton.one!, item.tapFromUserId2); - mapDigitsToAttributes(carton.two!, item.tapToUserId2); - return carton; - }); - }, [data]); -} diff --git a/src/hooks/useShowParamsError.ts b/src/hooks/useShowParamsError.ts index d64422f..2a55441 100644 --- a/src/hooks/useShowParamsError.ts +++ b/src/hooks/useShowParamsError.ts @@ -1,4 +1,4 @@ -import { useSearchParams } from "next/navigation"; +import { useRouter, useSearchParams } from "next/navigation"; import { useEffect } from "react"; import { toast } from "sonner"; @@ -9,8 +9,14 @@ export function handlerErrForBind(err?: string | null) { } export function useShowParamsError() { const sp = useSearchParams(); + const r = useRouter(); const error = sp.get("err"); useEffect(() => { handlerErrForBind(error); + if (error) { + const usp = new URLSearchParams(location.search); + usp.delete("err"); + r.replace(location.pathname + "?" + usp.toString()); + } }, [error]); } diff --git a/src/lib/api.ts b/src/lib/api.ts index 40a1dd6..7878524 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -5,7 +5,7 @@ import axios from "axios"; import { ENV } from "./env"; import _ from "lodash"; import { fmtBoost } from "@/components/fmtData"; -import { TapData } from "@/components/aibum"; +import { TapData, TapItem } from "@/components/aibum"; const API_MAP: { [k in typeof ENV]: string } = { beta: "https://dev-api.enreach.network/api", @@ -30,9 +30,7 @@ export type RES = { const backendApi = { setAuth: (auth?: string) => { if (auth) { - Api.defaults.headers.common["Authorization"] = auth.startsWith("Bearer") - ? auth - : `Bearer ${auth}`; + Api.defaults.headers.common["Authorization"] = auth.startsWith("Bearer") ? auth : `Bearer ${auth}`; } else { delete Api.defaults.headers.common["Authorization"]; } @@ -43,29 +41,16 @@ const backendApi = { return response.data.data; }, loginByGoogleApi: async (data: { accessToken: string }) => { - const response = await Api.post>( - "/user/google/signIn", - data - ); + const response = await Api.post>("/user/google/signIn", data); backendApi.setAuth(response.data.data.token); return response.data.data; }, - loginSetReferralApi: async (data: { - accessToken: string; - referralCode?: string; - }) => { - const response = await Api.post>( - "/user/referral/by", - data - ); + loginSetReferralApi: async (data: { accessToken: string; referralCode?: string }) => { + const response = await Api.post>("/user/referral/by", data); backendApi.setAuth(response.data.data.token); return response.data.data; }, - registerApi: async (data: { - email: string; - password: string; - referralCode?: string; - }) => { + registerApi: async (data: { email: string; password: string; referralCode?: string }) => { const response = await Api.post>("/user/signUp", { ...data, }); @@ -84,9 +69,7 @@ const backendApi = { return true; }, verifyRegisterCode: async (uid: string, code: string) => { - const response = await Api.post>( - `/user/verify/${uid}/${code}` - ); + const response = await Api.post>(`/user/verify/${uid}/${code}`); return response.data.data; }, userInfo: async () => { @@ -96,8 +79,7 @@ const backendApi = { p[key] = _.toNumber(p[key]); }); // p.total = _.toNumber(fmtBoost(response.data.data.stat.extraBoost)) * p.total; - p.network = - _.toNumber(fmtBoost(response.data.data.stat.extraBoost)) * p.network; + p.network = _.toNumber(fmtBoost(response.data.data.stat.extraBoost)) * p.network; p.total = p.referral + p.network; return response.data.data; }, @@ -105,18 +87,11 @@ const backendApi = { await Api.post>("/user/password/reset/send", { email }); return true; }, - resetPassword: async (data: { - email: string; - password: string; - verifyCode: string; - }) => { + resetPassword: async (data: { email: string; password: string; verifyCode: string }) => { await Api.post>("/user/password/reset", data); return true; }, - userUpdate: async (data: { - username?: string; - disconnect?: { x?: boolean; tg?: boolean; discord?: boolean }; - }) => { + userUpdate: async (data: { username?: string; disconnect?: { x?: boolean; tg?: boolean; discord?: boolean } }) => { await Api.post>("/user/profile/update", data); return true; }, @@ -139,9 +114,7 @@ const backendApi = { }, getAccessToken: async () => { - const response = await Api.get>( - "/user/accessToken" - ); + const response = await Api.get>("/user/accessToken"); return response.data.data.accessToken; }, @@ -155,36 +128,31 @@ const backendApi = { updateNodeName: async (node: NodeItem, name: string) => { // /api/node/rename/{clientId}/{name} - await Api.post>( - `/node/rename/${node.connectionId}/${encodeURIComponent( - node.ipAddress - )}/${encodeURIComponent(name)}` - ); + await Api.post>(`/node/rename/${node.connectionId}/${encodeURIComponent(node.ipAddress)}/${encodeURIComponent(name)}`); return true; }, - getCartoonList: async () => { - const response = await Api.get>(`/extension/tap/list`); - + getCartoonList: async (params?: { pageNum: number; pageSize: number }) => { + const response = await Api.get>(`/extension/tap/list`, { params }); return response.data.data; }, currentUserLike: async (like: "like" | "unlike", uuid?: string) => { - const response = await Api.post>( - `/extension/tap/${uuid}/${like}` - ); + const response = await Api.post>(`/extension/tap/${uuid}/${like}`); return response.data; }, - getShareUserList: async (uuid: string) => { - const response = await Api.get>(`/common/tap/${uuid}/list`); + getAlbumItemList: async (uuid: string, params?: { pageNum: number; pageSize: number }) => { + const response = await Api.get>(`/common/tap/${uuid}/list`, { params }); return response.data.data; }, userIsLiked: async (uuid?: string) => { - const response = await Api.get>( - `/extension/tap/${uuid}/liked` - ); - return response.data.data; + const response = await Api.get>(`/extension/tap/${uuid}/liked`); + return response.data.data.liked; + }, + userLikeCount: async (uuid?: string) => { + const response = await Api.get>(`/common/tap/${uuid}/like`); + return response.data.data.like; }, }; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index c7fa13a..6866f8a 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,9 +1,8 @@ -import { toast } from "sonner"; +import { AxiosError } from "axios"; import dayjs from "dayjs"; import plugDur from "dayjs/plugin/duration"; -import { AxiosError } from "axios"; import _ from "lodash"; -import { cartoonType } from "@/components/ACommonCartoonList"; +import { toast } from "sonner"; dayjs.extend(plugDur); export function strToSearchParams(str: string) { @@ -14,8 +13,7 @@ export function getErrorMsg(error: any) { // msg let msg = "Unkown"; if (typeof error == "string") msg = error; - else if (error instanceof AxiosError) - msg = error.response?.data?.message || error.message; + else if (error instanceof AxiosError) msg = error.response?.data?.message || error.message; else if (typeof error?.msg == "string") msg = error?.msg; else if (typeof error?.message == "string") msg = error?.message; // replace @@ -56,127 +54,12 @@ export function truncateEmail(email: string = "", maxLength = 25) { return `${localPart.slice(0, 7)}...@${domainPart}`; } -export const convertNumber = (num?: string) => { - if (!num) return; - - return num - .toString() - .split("") - .map((digit) => ((parseInt(digit) % 3) + 1).toString()) - .join(""); -}; export const convertToNew = (hexString?: string | undefined) => { - if (!hexString) return; + if (!hexString) return ""; const cleanedHex = hexString.split("-").slice(1).join(""); - return BigInt(`0x${cleanedHex}`).toString().slice(0, 9); -}; -export const createEmptyAttributes = () => ({ - hat: null, - head: null, - eyes: null, - clothes: null, - hand: null, - pants: null, - shoes: null, - logo: null, -}); - -export const mapDigitsToAttributes = ( - obj: { [key: string]: number | number[] | null }, - digits?: string -) => { - const keys = [ - "hat", - "head", - "eyes", - "clothes", - "hand", - "pants", - "shoes", - "logo", - ]; - if (!digits) return; - - digits.split("").forEach((digit, index) => { - if (keys[index]) { - obj[keys[index]] = - keys[index] === "hand" ? [Number(digit), Number(digit)] : Number(digit); - } - }); + return BigInt(`0x${cleanedHex}`).toString().slice(0, 20); }; -export const cartoonList: cartoonType[] = [ - { - one: { - hat: 0, - head: 1, - eyes: 0, - clothes: 1, - hand: [0, 0], - pants: 0, - shoes: 1, - logo: 1, - }, - two: { - hat: 3, - head: 3, - eyes: 2, - clothes: 4, - hand: [0, 0], - pants: 1, - shoes: 2, - logo: 0, - }, - }, - { - one: { - hat: 1, - head: 0, - eyes: 2, - clothes: 0, - hand: [0, 0], - pants: 1, - shoes: 0, - logo: 0, - }, - }, - { - one: { - hat: 2, - head: 2, - eyes: 2, - clothes: 2, - hand: [0, 0], - pants: 1, - shoes: 1, - logo: 0, - }, - }, - { - one: { - hat: 3, - head: 3, - eyes: 2, - clothes: 4, - hand: [0, 0], - pants: 1, - shoes: 2, - logo: 0, - }, - }, - { - one: { - hat: 1, - head: 0, - eyes: 3, - clothes: 3, - hand: [0, 0], - pants: 1, - shoes: 3, - logo: 0, - }, - }, -];