Skip to content

Commit

Permalink
fix shitty nul chars
Browse files Browse the repository at this point in the history
  • Loading branch information
notV4l committed Nov 11, 2024
1 parent 2a25098 commit 974f86f
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 28 deletions.
4 changes: 2 additions & 2 deletions web/src/components/pages/home/ClaimModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -92,7 +92,7 @@ export const ClaimModal = ({
<Td>
<HStack>
<HustlerIcon hustler={game.hustler_id as Hustlers} />
<Text>{shortString.decodeShortString(game.player_name?.value)}</Text>
<Text>{shortString.decodeShortString(num.toHexString(BigInt(game.player_name?.value)))}</Text>
</HStack>
</Td>
<Td color="yellow.400" isNumeric>
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/pages/home/HallOfFame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -77,7 +77,7 @@ const HallOfFameEntry = ({ game, account }: { game: Game; account: AccountInterf

<VStack w="full" alignItems="flex-start" gap={1}>
<Text>
{shortString.decodeShortString(game?.player_name?.value)} {isSelf && "(you)"}
{shortString.decodeShortString(num.toHexString(BigInt(game?.player_name?.value)))} {isSelf && "(you)"}
</Text>
<Text>{formatCash(game.final_score)}</Text>
</VStack>
Expand Down
5 changes: 3 additions & 2 deletions web/src/components/pages/home/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -145,6 +145,7 @@ export const Leaderboard = observer(({ config }: { config?: Config }) => {
"scrollbar-width": "none",
}}
>

{isFetchingRegisteredGames && <Loader />}
{!isFetchingRegisteredGames && (
<UnorderedList boxSize="full" variant="dotted" h="auto">
Expand All @@ -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 (
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/pages/profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -56,7 +56,7 @@ export const ProfileLinkMobile = () => {
<>
<MenuItem h="48px" borderRadius={0} onClick={onClick} /*justifyContent="center"*/>
<HustlerIcon hustler={gameInfos.hustler_id as Hustlers} />
<Text ml="10px">{shortString.decodeShortString(gameInfos.player_name?.value)}</Text>
<Text ml="10px">{shortString.decodeShortString(num.toHexString(BigInt(gameInfos.player_name?.value)))}</Text>
</MenuItem>
</>
);
Expand All @@ -82,7 +82,7 @@ export const ProfileLinkDrawer = () => {
return (
<HStack borderRadius={0} onClick={onClick} /*justifyContent="center"*/>
<HustlerIcon hustler={gameInfos.hustler_id as Hustlers} />
<Text ml="4px">{shortString.decodeShortString(gameInfos.player_name?.value)}</Text>
<Text ml="4px">{shortString.decodeShortString(num.toHexString(BigInt(gameInfos.player_name?.value)))}</Text>
</HStack>
);
};
4 changes: 2 additions & 2 deletions web/src/components/pages/profile/ShareButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions web/src/dojo/stores/game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/[gameId]/end.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -161,7 +161,7 @@ const EndContent = ({ game }: { game: GameClass }) => {
</VStack>
<VStack flex="1">
<StatsItem
text={shortString.decodeShortString(game.gameInfos.player_name?.value)}
text={shortString.decodeShortString(num.toHexString(BigInt(game.gameInfos.player_name?.value)))}
icon={<HustlerIcon hustler={game.gameInfos.hustler_id as Hustlers} w="24px" h="24px" />}
/>
{game.gameInfos.game_mode == "Ranked" && (
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/[gameId]/event/decision.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -300,7 +300,7 @@ const Encounter = observer(
<HStack w="full" px="10px" py="6px" justifyContent="space-between">
<HStack w="full" justifyContent="center">
<HustlerIcon hustler={gameInfos?.hustler_id as Hustlers} color={colors.yellow["400"].toString()} />
<Text>{shortString.decodeShortString(game.gameInfos.player_name?.value)}</Text>
<Text>{shortString.decodeShortString(num.toHexString(BigInt(game.gameInfos.player_name?.value)))}</Text>
</HStack>

<Divider h="26px" orientation="vertical" borderWidth="1px" borderColor="neon.600" />
Expand Down
10 changes: 4 additions & 6 deletions web/src/pages/[gameId]/logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -203,6 +203,7 @@ export default observer(Logs);
const CustomLeftPanel = () => {
const { game, gameInfos } = useGameStore();
const { router } = useRouterContext();

return (
<VStack
flex={1}
Expand All @@ -222,7 +223,7 @@ const CustomLeftPanel = () => {
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)) || "")}
</Heading>

<Box maxW="350px" w="100%">
Expand Down Expand Up @@ -433,10 +434,7 @@ const FightLine = ({
<HStack w="full">
<HStack flex="4" color="yellow.400">
<Box w="30px">{icon && icon({ boxSize: "24px" })}</Box>
<Tooltip
label={action}
placement="right-end"
>
<Tooltip label={action} placement="right-end">
<Text>{text}</Text>
</Tooltip>
</HStack>
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/game/history/[playerId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -125,7 +125,7 @@ const GameList = ({ games }: { games?: GameClass[] }) => {
</Tr>

{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 (
<Tr key={game.gameInfos.game_id} cursor="pointer" onClick={() => onClick(game)}>
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/season/[seasonId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -270,7 +270,7 @@ export const GamesTable = ({ games }: { games: Game[] }) => {
<Td>
<HStack>
<HustlerIcon hustler={game.hustler_id as Hustlers} color={color} />
<Text>{shortString.decodeShortString(game.player_name?.value)}</Text>
<Text>{shortString.decodeShortString(num.toHexString(BigInt(game.player_name?.value)))}</Text>
</HStack>
</Td>
<Td isNumeric>{formatCashHeader(game.final_score)}</Td>
Expand Down

0 comments on commit 974f86f

Please sign in to comment.