Skip to content

Commit a770f7e

Browse files
authored
fix to show first and last 8 of address (#152)
* fix to show first and last 8 of address Signed-off-by: JaeBrian <[email protected]> * commit truncate func Signed-off-by: JaeBrian <[email protected]> --------- Signed-off-by: JaeBrian <[email protected]>
1 parent 4497ab8 commit a770f7e

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/components/FloatingWalletButton.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useWalletStore } from "../stores/walletStore";
22
import { useState } from "react";
33
import LoadingOverlay from "./LoadingOverlay";
4+
import { truncateAddress } from "../utils/formatAddress";
45

56
const FloatingWalletButton = () => {
67
const { isConnected, stakeAddress, connect, disconnect } = useWalletStore();
@@ -32,9 +33,7 @@ const FloatingWalletButton = () => {
3233
<div className="bg-white rounded-lg shadow-lg border p-4 min-w-[200px]">
3334
<div className="text-xs text-gray-500 mb-2">Connected Wallet</div>
3435
<div className="text-sm font-medium text-gray-900 mb-3">
35-
{stakeAddress
36-
? `${stakeAddress.slice(0, 8)}...${stakeAddress.slice(-8)}`
37-
: "Connected"}
36+
{stakeAddress ? truncateAddress(stakeAddress) : "Connected"}
3837
</div>
3938
<button
4039
onClick={disconnect}

src/components/WalletModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import WalletConnection from "./WalletConnection";
22
import { useWalletStore } from "../stores/walletStore";
3+
import { truncateAddress } from "../utils/formatAddress";
34

45
interface WalletModalProps {
56
isOpen: boolean;
@@ -39,7 +40,7 @@ const WalletModal = ({ isOpen, onDisconnect }: WalletModalProps) => {
3940
Your Wallet
4041
</h3>
4142
<p className="text-white/70 text-md max-w-[15rem] py-1 truncate">
42-
{enabledWallet}: {walletAddress}
43+
{enabledWallet}: {truncateAddress(walletAddress)}
4344
</p>
4445
</div>
4546
</div>

src/utils/formatAddress.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const truncateAddress = (
2+
address: string | null | undefined,
3+
startChars = 8,
4+
endChars = 8,
5+
): string => {
6+
if (!address) return "";
7+
8+
if (address.length <= startChars + endChars) {
9+
return address;
10+
}
11+
12+
return `${address.slice(0, startChars)}...${address.slice(-endChars)}`;
13+
};
14+

0 commit comments

Comments
 (0)