From 974f86fe531fe73f76444d03c13d55f73ed4fef8 Mon Sep 17 00:00:00 2001 From: notV4l Date: Mon, 11 Nov 2024 11:32:52 +0100 Subject: [PATCH] fix shitty nul chars --- web/src/components/pages/home/ClaimModal.tsx | 4 ++-- web/src/components/pages/home/HallOfFame.tsx | 4 ++-- web/src/components/pages/home/Leaderboard.tsx | 5 +++-- web/src/components/pages/profile/Profile.tsx | 6 +++--- web/src/components/pages/profile/ShareButton.tsx | 4 ++-- web/src/dojo/stores/game.tsx | 4 +--- web/src/pages/[gameId]/end.tsx | 4 ++-- web/src/pages/[gameId]/event/decision.tsx | 4 ++-- web/src/pages/[gameId]/logs.tsx | 10 ++++------ web/src/pages/game/history/[playerId]/index.tsx | 4 ++-- web/src/pages/season/[seasonId]/index.tsx | 4 ++-- 11 files changed, 25 insertions(+), 28 deletions(-) diff --git a/web/src/components/pages/home/ClaimModal.tsx b/web/src/components/pages/home/ClaimModal.tsx index 1cb7d132..0d27cdc5 100644 --- a/web/src/components/pages/home/ClaimModal.tsx +++ b/web/src/components/pages/home/ClaimModal.tsx @@ -24,7 +24,7 @@ import { Claimable } from "./ClaimReward"; import { PaperIcon } from "@/components/icons"; import { Dopewars_Game as Game } from "@/generated/graphql"; import { HustlerIcon, Hustlers } from "@/components/hustlers"; -import { shortString } from "starknet"; +import { num, shortString } from "starknet"; export const ClaimModal = ({ claimable, @@ -92,7 +92,7 @@ export const ClaimModal = ({ - {shortString.decodeShortString(game.player_name?.value)} + {shortString.decodeShortString(num.toHexString(BigInt(game.player_name?.value)))} diff --git a/web/src/components/pages/home/HallOfFame.tsx b/web/src/components/pages/home/HallOfFame.tsx index 7d1e7392..08ee7254 100644 --- a/web/src/components/pages/home/HallOfFame.tsx +++ b/web/src/components/pages/home/HallOfFame.tsx @@ -11,7 +11,7 @@ import { Card, HStack, SimpleGrid, Text, VStack } from "@chakra-ui/react"; import { useAccount } from "@starknet-react/core"; import { observer } from "mobx-react-lite"; import { useCallback, useMemo } from "react"; -import { AccountInterface, shortString } from "starknet"; +import { AccountInterface, num, shortString } from "starknet"; export const HallOfFame = observer(() => { const { config } = useConfigStore(); @@ -77,7 +77,7 @@ const HallOfFameEntry = ({ game, account }: { game: Game; account: AccountInterf - {shortString.decodeShortString(game?.player_name?.value)} {isSelf && "(you)"} + {shortString.decodeShortString(num.toHexString(BigInt(game?.player_name?.value)))} {isSelf && "(you)"} {formatCash(game.final_score)} diff --git a/web/src/components/pages/home/Leaderboard.tsx b/web/src/components/pages/home/Leaderboard.tsx index 63532095..8bfa628b 100644 --- a/web/src/components/pages/home/Leaderboard.tsx +++ b/web/src/components/pages/home/Leaderboard.tsx @@ -15,7 +15,7 @@ import { useEffect, useRef, useState } from "react"; import Countdown from "react-countdown"; import { Arrow, InfosIcon, PaperIcon, Skull, Trophy } from "../../icons"; import { Dopewars_Game as Game } from "@/generated/graphql"; -import { shortString } from "starknet"; +import { num, shortString } from "starknet"; import { Config, ConfigStoreClass } from "@/dojo/stores/config"; import { getPayedCount } from "@/dojo/helpers"; @@ -145,6 +145,7 @@ export const Leaderboard = observer(({ config }: { config?: Config }) => { "scrollbar-width": "none", }} > + {isFetchingRegisteredGames && } {!isFetchingRegisteredGames && ( @@ -154,7 +155,7 @@ export const Leaderboard = observer(({ config }: { config?: Config }) => { const color = isOwn ? colors.yellow["400"].toString() : colors.neon["200"].toString(); const avatarColor = isOwn ? "yellow" : "green"; const displayName = game.player_name?.value - ? `${shortString.decodeShortString(game.player_name?.value)}${isOwn ? " (you)" : ""}` + ? `${shortString.decodeShortString(num.toHexString(BigInt(game.player_name?.value)))}${isOwn ? " (you)" : ""}` : "Anonymous"; return ( diff --git a/web/src/components/pages/profile/Profile.tsx b/web/src/components/pages/profile/Profile.tsx index 96f14ae4..b98c226b 100644 --- a/web/src/components/pages/profile/Profile.tsx +++ b/web/src/components/pages/profile/Profile.tsx @@ -5,7 +5,7 @@ import { Box, HStack, MenuItem, Text } from "@chakra-ui/react"; import { useAccount } from "@starknet-react/core"; import { useState } from "react"; import { HustlerIcon, Hustlers } from "../../hustlers"; -import { shortString } from "starknet"; +import { num, shortString } from "starknet"; export const ProfileLink = () => { const { router, gameId } = useRouterContext(); @@ -56,7 +56,7 @@ export const ProfileLinkMobile = () => { <> - {shortString.decodeShortString(gameInfos.player_name?.value)} + {shortString.decodeShortString(num.toHexString(BigInt(gameInfos.player_name?.value)))} ); @@ -82,7 +82,7 @@ export const ProfileLinkDrawer = () => { return ( - {shortString.decodeShortString(gameInfos.player_name?.value)} + {shortString.decodeShortString(num.toHexString(BigInt(gameInfos.player_name?.value)))} ); }; diff --git a/web/src/components/pages/profile/ShareButton.tsx b/web/src/components/pages/profile/ShareButton.tsx index 376b2419..040bf4b7 100644 --- a/web/src/components/pages/profile/ShareButton.tsx +++ b/web/src/components/pages/profile/ShareButton.tsx @@ -5,7 +5,7 @@ import { Dopewars_Game as Game } from "@/generated/graphql"; import { formatCash } from "@/utils/ui"; import { Link as ChakraLink, StyleProps } from "@chakra-ui/react"; import { useAccount } from "@starknet-react/core"; -import { shortString } from "starknet"; +import { num, shortString } from "starknet"; import { Twitter } from "../../icons"; const ShareButton = ({ ...props }: { variant?: string } & StyleProps) => { @@ -30,7 +30,7 @@ const ShareButton = ({ ...props }: { variant?: string } & StyleProps) => { }; const getShareText = (game: GameClass, gameInfos: Game): string => { - const playerName = shortString.decodeShortString(gameInfos.player_name?.value); + const playerName = shortString.decodeShortString(num.toHexString(BigInt(gameInfos.player_name?.value))); if (game.player.health > 0) { return encodeURIComponent( `I reached Day ${game.player.turn} with ${formatCash( diff --git a/web/src/dojo/stores/game.tsx b/web/src/dojo/stores/game.tsx index 2e7e367e..f504e14b 100644 --- a/web/src/dojo/stores/game.tsx +++ b/web/src/dojo/stores/game.tsx @@ -174,12 +174,10 @@ export class GameStoreClass { const gameEntity = Object.values(entities)[0]; if (!gameEntity) return; + const gameInfos = parseStruct(gameEntity["dopewars-Game"]) as Game; const gameStorePacked = parseStruct(gameEntity["dopewars-GameStorePacked"]) as GameStorePacked; - // console.log("gameInfos", gameInfos); - // console.log("gameStorePacked", gameStorePacked); - this.gameInfos = gameInfos; this.gameStorePacked = gameStorePacked; } diff --git a/web/src/pages/[gameId]/end.tsx b/web/src/pages/[gameId]/end.tsx index 10b35521..b53189ca 100644 --- a/web/src/pages/[gameId]/end.tsx +++ b/web/src/pages/[gameId]/end.tsx @@ -33,7 +33,7 @@ import { formatCash } from "@/utils/ui"; import { useAccount } from "@starknet-react/core"; import { observer } from "mobx-react-lite"; import { ReactNode, useCallback, useEffect, useState } from "react"; -import { shortString } from "starknet"; +import { num, shortString } from "starknet"; import { GameClass } from "@/dojo/class/Game"; import { Dopewars_Game as Game } from "@/generated/graphql"; import { useToast } from "@/hooks/toast"; @@ -161,7 +161,7 @@ const EndContent = ({ game }: { game: GameClass }) => { } /> {game.gameInfos.game_mode == "Ranked" && ( diff --git a/web/src/pages/[gameId]/event/decision.tsx b/web/src/pages/[gameId]/event/decision.tsx index d837bd92..d8e8c501 100644 --- a/web/src/pages/[gameId]/event/decision.tsx +++ b/web/src/pages/[gameId]/event/decision.tsx @@ -17,7 +17,7 @@ import { formatCash, formatCashHeader } from "@/utils/ui"; import { Box, Card, Divider, HStack, Heading, Image, StyleProps, Text, VStack } from "@chakra-ui/react"; import { observer } from "mobx-react-lite"; import React, { useEffect, useState } from "react"; -import { shortString } from "starknet"; +import { num, shortString } from "starknet"; const Decision = observer(() => { const { router, gameId } = useRouterContext(); @@ -300,7 +300,7 @@ const Encounter = observer( - {shortString.decodeShortString(game.gameInfos.player_name?.value)} + {shortString.decodeShortString(num.toHexString(BigInt(game.gameInfos.player_name?.value)))} diff --git a/web/src/pages/[gameId]/logs.tsx b/web/src/pages/[gameId]/logs.tsx index 7f12190d..32a5d5af 100644 --- a/web/src/pages/[gameId]/logs.tsx +++ b/web/src/pages/[gameId]/logs.tsx @@ -38,7 +38,7 @@ import { import { useAccount } from "@starknet-react/core"; import { observer } from "mobx-react-lite"; import { useEffect, useRef, useState } from "react"; -import { shortString } from "starknet"; +import { num, shortString } from "starknet"; type IndexedDojoEvent = { index: number; @@ -203,6 +203,7 @@ export default observer(Logs); const CustomLeftPanel = () => { const { game, gameInfos } = useGameStore(); const { router } = useRouterContext(); + return ( { router.push(`/game/history/0x${BigInt(game?.gameInfos.player_id || 0).toString(16)}`); }} > - {shortString.decodeShortString(gameInfos?.player_name?.value || "")} + {shortString.decodeShortString(num.toHexString(BigInt(gameInfos?.player_name?.value)) || "")} @@ -433,10 +434,7 @@ const FightLine = ({ {icon && icon({ boxSize: "24px" })} - + {text} diff --git a/web/src/pages/game/history/[playerId]/index.tsx b/web/src/pages/game/history/[playerId]/index.tsx index b24ced8e..3b1130b9 100644 --- a/web/src/pages/game/history/[playerId]/index.tsx +++ b/web/src/pages/game/history/[playerId]/index.tsx @@ -44,7 +44,7 @@ import { Flex, } from "@chakra-ui/react"; -import { shortString } from "starknet"; +import { num, shortString } from "starknet"; export default function History() { const { router, playerId } = useRouterContext(); @@ -125,7 +125,7 @@ const GameList = ({ games }: { games?: GameClass[] }) => { {games.map((game: GameClass, index: number) => { - const playerName = shortString.decodeShortString(game.gameInfos.player_name?.value); + const playerName = shortString.decodeShortString(num.toHexString(BigInt(game.gameInfos.player_name?.value))); return ( onClick(game)}> diff --git a/web/src/pages/season/[seasonId]/index.tsx b/web/src/pages/season/[seasonId]/index.tsx index 9f671544..82b2fccb 100644 --- a/web/src/pages/season/[seasonId]/index.tsx +++ b/web/src/pages/season/[seasonId]/index.tsx @@ -69,7 +69,7 @@ import { } from "@chakra-ui/react"; import { useAccount } from "@starknet-react/core"; import { useEffect, useState } from "react"; -import { shortString } from "starknet"; +import { num, shortString } from "starknet"; interface Claimable { totalClaimable: number; @@ -270,7 +270,7 @@ export const GamesTable = ({ games }: { games: Game[] }) => { - {shortString.decodeShortString(game.player_name?.value)} + {shortString.decodeShortString(num.toHexString(BigInt(game.player_name?.value)))} {formatCashHeader(game.final_score)}