From 974d5878325ac6bd0dd43038f574d7c2c74242fa Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 12 Dec 2024 16:51:34 +0700 Subject: [PATCH 1/4] fix(social): get name from address directly --- client/src/hooks/helpers/useEntities.tsx | 8 +++++++- client/src/ui/modules/social/PlayerId.tsx | 6 ++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client/src/hooks/helpers/useEntities.tsx b/client/src/hooks/helpers/useEntities.tsx index 701ee1900..f567d6a38 100644 --- a/client/src/hooks/helpers/useEntities.tsx +++ b/client/src/hooks/helpers/useEntities.tsx @@ -277,6 +277,12 @@ export const useEntitiesUtils = () => { } }; + const getAddressName = (address: ContractAddress) => { + const addressName = getComponentValue(AddressName, getEntityIdFromKeys([BigInt(address)])); + + return addressName ? shortString.decodeShortString(addressName.name.toString()) : undefined; + }; + const getAddressNameFromEntity = (entityId: ID) => { const address = getPlayerAddressFromEntity(entityId); if (!address) return; @@ -293,5 +299,5 @@ export const useEntitiesUtils = () => { : undefined; }; - return { getEntityName, getEntityInfo, getAddressNameFromEntity, getPlayerAddressFromEntity }; + return { getEntityName, getEntityInfo, getAddressName, getAddressNameFromEntity, getPlayerAddressFromEntity }; }; diff --git a/client/src/ui/modules/social/PlayerId.tsx b/client/src/ui/modules/social/PlayerId.tsx index 2317890a6..b71c22812 100644 --- a/client/src/ui/modules/social/PlayerId.tsx +++ b/client/src/ui/modules/social/PlayerId.tsx @@ -68,7 +68,7 @@ export const PlayerId = ({ const { getEntityName } = useEntitiesUtils(); - const { getAddressNameFromEntity } = useEntitiesUtils(); + const { getAddressName } = useEntitiesUtils(); const playerEntityId = useMemo(() => { if (!selectedPlayer) return; @@ -83,9 +83,7 @@ export const PlayerId = ({ const playerName = useMemo(() => { if (!selectedPlayer) return; - if (!playerEntityId) return; - - const playerName = getAddressNameFromEntity(playerEntityId); + const playerName = getAddressName(selectedPlayer); return playerName; }, [selectedPlayer, playerEntityId]); From 99d204235ea728fa6270655eee2e61195c77c5ac Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 12 Dec 2024 16:54:11 +0700 Subject: [PATCH 2/4] chore: add has not settled realm yet --- client/src/ui/modules/social/PlayerId.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/ui/modules/social/PlayerId.tsx b/client/src/ui/modules/social/PlayerId.tsx index b71c22812..f67635aad 100644 --- a/client/src/ui/modules/social/PlayerId.tsx +++ b/client/src/ui/modules/social/PlayerId.tsx @@ -138,10 +138,10 @@ export const PlayerId = ({
- {hasBeenPlayingFor ? `Joined ${hasBeenPlayingFor} ago` : "No player selected"} + {hasBeenPlayingFor ? `Joined ${hasBeenPlayingFor} ago` : "Has not settled a realm yet"}
-
{playerEntityId ? `Player ID: ${playerEntityId}` : "No player selected"}
+
{playerEntityId ? `Player ID: ${playerEntityId}` : ""}
From f23882ecb6aac74a4ec59ec7b31d1374cfaa57b3 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 12 Dec 2024 16:56:14 +0700 Subject: [PATCH 3/4] undefined if no realm found --- client/src/ui/modules/social/PlayerId.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/ui/modules/social/PlayerId.tsx b/client/src/ui/modules/social/PlayerId.tsx index f67635aad..1507716fe 100644 --- a/client/src/ui/modules/social/PlayerId.tsx +++ b/client/src/ui/modules/social/PlayerId.tsx @@ -94,7 +94,7 @@ export const PlayerId = ({ SettleRealmData, Array.from(runQuery([HasValue(SettleRealmData, { owner_address: selectedPlayer })]))[0], ); - return formatTime((useUIStore.getState()?.nextBlockTimestamp ?? 0) - (realmSettleData?.timestamp ?? 0)); + return realmSettleData ? formatTime((useUIStore.getState()?.nextBlockTimestamp ?? 0) - (realmSettleData?.timestamp ?? 0)) : undefined; }, [selectedPlayer, playerEntityId]); const playerStructures = useMemo(() => { From b8df024bd74a8411cc6a828eb7a629bd98e4ab4f Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 12 Dec 2024 16:59:13 +0700 Subject: [PATCH 4/4] pretty --- client/src/ui/modules/social/PlayerId.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/ui/modules/social/PlayerId.tsx b/client/src/ui/modules/social/PlayerId.tsx index 1507716fe..06ec39532 100644 --- a/client/src/ui/modules/social/PlayerId.tsx +++ b/client/src/ui/modules/social/PlayerId.tsx @@ -94,7 +94,9 @@ export const PlayerId = ({ SettleRealmData, Array.from(runQuery([HasValue(SettleRealmData, { owner_address: selectedPlayer })]))[0], ); - return realmSettleData ? formatTime((useUIStore.getState()?.nextBlockTimestamp ?? 0) - (realmSettleData?.timestamp ?? 0)) : undefined; + return realmSettleData + ? formatTime((useUIStore.getState()?.nextBlockTimestamp ?? 0) - (realmSettleData?.timestamp ?? 0)) + : undefined; }, [selectedPlayer, playerEntityId]); const playerStructures = useMemo(() => {