-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ffb56a
commit 83a1afe
Showing
5 changed files
with
140 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client' | ||
|
||
import { useStarkProfile } from '@starknet-react/core' | ||
import { BlockieAvatar } from './BlockieAvatar' | ||
|
||
interface AttackerIdentifierProps { | ||
address: string | ||
} | ||
|
||
export const AttackerIdentifier = ({ address }: AttackerIdentifierProps) => { | ||
// Normalize the address for StarkNet: remove 0x prefix if present, pad to 64 characters, then add 0x prefix | ||
const normalizedAddress = address.startsWith('0x') | ||
? `0x${address.slice(2).padStart(64, '0')}` | ||
: `0x${address.padStart(64, '0')}` | ||
|
||
// Cast to the required type for the hook | ||
const starknetAddress = normalizedAddress as `0x${string}` | ||
|
||
const { data: profile } = useStarkProfile({ address: starknetAddress }) | ||
const formattedAddress = `${address.slice(0, 6)}...${address.slice(-4)}` | ||
|
||
// Only use StarkNet profile information if there's a name available | ||
const hasStarknetName = Boolean(profile?.name) | ||
|
||
return ( | ||
<div className="flex items-center gap-2"> | ||
{/* Show StarkNet profile picture or Blockie avatar */} | ||
{hasStarknetName && profile?.profilePicture ? ( | ||
<img | ||
src={profile.profilePicture} | ||
alt={profile.name} | ||
className="h-5 w-5 rounded-full" | ||
/> | ||
) : ( | ||
<BlockieAvatar address={address} size={20} /> | ||
)} | ||
<span> | ||
{hasStarknetName ? ( | ||
<span className="font-medium">{profile!.name}</span> | ||
) : ( | ||
formattedAddress | ||
)} | ||
</span> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use client' | ||
|
||
import Blockies from 'react-blockies' | ||
|
||
interface BlockieAvatarProps { | ||
address: string | ||
size?: number | ||
} | ||
|
||
export const BlockieAvatar = ({ address, size = 24 }: BlockieAvatarProps) => { | ||
// Normalize the address: remove 0x prefix if present, then pad to 64 characters | ||
const normalizedAddress = address.startsWith('0x') | ||
? address.slice(2).padStart(64, '0') | ||
: address.padStart(64, '0') | ||
|
||
// Add 0x prefix back for the seed | ||
const seed = `0x${normalizedAddress}`.toLowerCase() | ||
|
||
return ( | ||
<div | ||
className="overflow-hidden rounded-full" | ||
style={{ | ||
height: `${size}px`, | ||
width: `${size}px`, | ||
minWidth: `${size}px` | ||
}} | ||
> | ||
<Blockies | ||
seed={seed} | ||
size={8} // Number of blocks | ||
scale={size / 8} // Size of each block | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.