Skip to content

Commit

Permalink
fix: format worker website
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed May 15, 2024
1 parent a5c2804 commit 10affea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/lib/formatters/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ export function addressFormatter(val: string, shortify?: boolean) {
const address = getAddress(val);
return shortify ? `${address.substring(0, 6)}...${address?.slice(-4)}` : address;
}

export function urlFormatter(val: string) {
val = val.trim().toLowerCase();
return val.startsWith('http://') || val.startsWith('https://')
? val
: val.replace(/^(?!(?:\w+?:)?\/\/)/, 'https://');
}
9 changes: 8 additions & 1 deletion src/pages/WorkersPage/WorkerStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
bytesFormatter,
numberWithSpacesFormatter,
percentFormatter,
urlFormatter,
} from '@lib/formatters/formatters.ts';
import { Box, Divider, Stack, styled } from '@mui/material';

Expand Down Expand Up @@ -78,7 +79,13 @@ export const WorkerStatistics = ({ worker }: { worker: BlockchainApiFullWorker }
<Stack direction="row">
<WorkerDescLabel>Website</WorkerDescLabel>
<WorkerDescValue>
{worker.website ? <a href={worker.website}>{worker.website}</a> : '-'}
{worker.website ? (
<a href={urlFormatter(worker.website)} target="_blank" rel="noreferrer">
{urlFormatter(worker.website)}
</a>
) : (
'-'
)}
</WorkerDescValue>
</Stack>
<Stack direction="row">
Expand Down

0 comments on commit 10affea

Please sign in to comment.