Skip to content

Commit

Permalink
Merge pull request #2444 from BibliothecaDAO/fix-social
Browse files Browse the repository at this point in the history
fix(social): get name from address directly
  • Loading branch information
Larkooo authored Dec 12, 2024
2 parents 0fc5a97 + b8df024 commit e500824
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 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 };
};
14 changes: 7 additions & 7 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 All @@ -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(() => {
Expand Down Expand Up @@ -140,10 +140,10 @@ export const PlayerId = ({
</div>

<div className="text-xs italic">
{hasBeenPlayingFor ? `Joined ${hasBeenPlayingFor} ago` : "No player selected"}
{hasBeenPlayingFor ? `Joined ${hasBeenPlayingFor} ago` : "Has not settled a realm yet"}
</div>

<div className="text-xs">{playerEntityId ? `Player ID: ${playerEntityId}` : "No player selected"}</div>
<div className="text-xs">{playerEntityId ? `Player ID: ${playerEntityId}` : ""}</div>
</div>
</div>

Expand Down

0 comments on commit e500824

Please sign in to comment.