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]);