Files
TheGame/packages/web/utils/playerHelpers.ts
Hammad Jutt 7492ae5bd6 Remove unused pages / components and fix usage of Wrap with WrapItem (#284)
* Remove unused pages / components

* Add WrapItem around components inside Wrap component

New version of Chakra requires WrapItem around any components that have Wrap

* Update LoginButton to link to own profile and show Avatar (#285)

* Update LoginButton to link to own profile and show Avatar

* Change SetupUsername to explicitly mention "username"
2021-01-18 11:44:52 -07:00

24 lines
990 B
TypeScript

import BackgroundImage from 'assets/tile-background.jpg';
import { ethers } from 'ethers';
import { PlayerFragmentFragment } from '../graphql/autogen/types';
export const getPlayerImage = (player: PlayerFragmentFragment): string =>
player.box_profile?.imageUrl ||
`https://avatars.dicebear.com/api/jdenticon/${player.username}.svg`;
export const getPlayerCoverImage = (player: PlayerFragmentFragment): string =>
player.box_profile?.coverImageUrl || BackgroundImage;
export const getPlayerName = (player: PlayerFragmentFragment): string =>
player.box_profile?.name || formatUsernameIfAddress(player.username);
export const getPlayerDescription = (player: PlayerFragmentFragment): string =>
player.box_profile?.description || '';
export const formatAddress = (address = ''): string =>
`${address.slice(0, 6)}...${address.slice(-4)}`;
export const formatUsernameIfAddress = (username = ''): string =>
ethers.utils.isAddress(username) ? formatAddress(username) : username;