Skip to content

Commit

Permalink
fix(social): get name from address directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Dec 12, 2024
1 parent 0fc5a97 commit 974d587
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 7 additions & 1 deletion client/src/hooks/helpers/useEntities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -293,5 +299,5 @@ export const useEntitiesUtils = () => {
: undefined;
};

return { getEntityName, getEntityInfo, getAddressNameFromEntity, getPlayerAddressFromEntity };
return { getEntityName, getEntityInfo, getAddressName, getAddressNameFromEntity, getPlayerAddressFromEntity };
};
6 changes: 2 additions & 4 deletions client/src/ui/modules/social/PlayerId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const PlayerId = ({

const { getEntityName } = useEntitiesUtils();

const { getAddressNameFromEntity } = useEntitiesUtils();
const { getAddressName } = useEntitiesUtils();

const playerEntityId = useMemo(() => {
if (!selectedPlayer) return;
Expand All @@ -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]);

Expand Down

0 comments on commit 974d587

Please sign in to comment.