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..06ec39532 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]); @@ -96,7 +94,9 @@ 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(() => { @@ -140,10 +140,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}` : ""}