Skip to content

Commit

Permalink
fix: safe truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
chalabi2 committed Jan 11, 2025
1 parent 416aaf5 commit 361197a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion components/react/addressCopy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const TruncatedAddressWithCopy = ({
}
};

const truncatedAddress = `${address?.slice(15, slice)}...${address?.slice(-6)}`;
const truncatedAddress = `${address?.slice(0, 24)}...`;
const iconSize = size === 'small' ? 10 : 16;

return (
Expand Down
4 changes: 1 addition & 3 deletions components/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ export const WalletSection: React.FC<WalletSectionProps> = ({ chainName }) => {
</p>
<div className="bg-base-100 dark:bg-base-200 rounded-full py-2 px-4 text-center mb-4 flex items-center flex-row justify-between w-full ">
<p className="text-xs truncate flex-grow">
{address
? `${address.slice(0, 12)}...${address.slice(-6)}`
: 'Address not available'}
{address ? `${address.slice(0, 24)}...` : 'Address not available'}
</p>
<button
onClick={() => {
Expand Down
2 changes: 1 addition & 1 deletion utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CombinedBalanceInfo } from './types';

export function truncateString(str: string, num: number) {
if (str.length > num) {
return str.slice(0, num) + '...' + str.slice(-6);
return str.slice(0, 24) + '...';
} else {
return str;
}
Expand Down

0 comments on commit 361197a

Please sign in to comment.