Skip to content

Commit

Permalink
chore(PGIO-119): Create function to return explorer link (#150)
Browse files Browse the repository at this point in the history
* chore: create a utils fn to get the explorer URL, clean unneeded old fns
  • Loading branch information
ElRodrigote authored Dec 30, 2024
1 parent 46ba7d0 commit 3d8b5c9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
12 changes: 6 additions & 6 deletions app/(main)/markets/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import { Icon, IconButton } from '@swapr/ui';
import { trackEvent } from 'fathom-client';

import { FA_EVENTS } from '@/analytics';
import { GNOSIS_SCAN_URL, KLEROS_URL, REALITY_QUESTION_URL } from '@/constants';
import { KLEROS_URL, REALITY_QUESTION_URL } from '@/constants';
import { FixedProductMarketMaker } from '@/queries/omen';
import { shortenAddress } from '@/utils';
import { getExplorerAddressUrl, shortenAddress } from '@/utils';

interface InfoProps {
fixedProductMarketMaker: FixedProductMarketMaker;
}
export const Info = ({ fixedProductMarketMaker }: InfoProps) => {
const [clipboardIcon, setClipboardIcon] = useState<'copy' | 'tick'>('copy');
const id = fixedProductMarketMaker.id;
const address = fixedProductMarketMaker.id;
const questionId = fixedProductMarketMaker.question?.id;

return (
<>
<div className="flex items-center space-x-1 py-4">
<span>{shortenAddress(id)}</span>
<span>{shortenAddress(address)}</span>
<IconButton
onClick={() => {
navigator.clipboard.writeText(id);
navigator.clipboard.writeText(address);
setClipboardIcon('tick');

setTimeout(() => {
Expand All @@ -35,7 +35,7 @@ export const Info = ({ fixedProductMarketMaker }: InfoProps) => {
/>
</div>
<a
href={`${GNOSIS_SCAN_URL}/address/${id}`}
href={getExplorerAddressUrl(address)}
target="_blank"
className="flex items-center space-x-1 py-4"
onClick={() => trackEvent(FA_EVENTS.MARKETS.DETAILS.INFO.CONTRACT)}
Expand Down
4 changes: 2 additions & 2 deletions app/(main)/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Address, formatEther, isAddress } from 'viem';
import {
calcSellAmountInCollateral,
formatValueWithFixedDecimals,
getGnosisAddressExplorerLink,
getExplorerAddressUrl,
shortenAddress,
} from '@/utils';
import { TabBody, TabGroup, TabHeader, Tag } from '@swapr/ui';
Expand Down Expand Up @@ -265,7 +265,7 @@ export default function ProfilePage() {
<Avatar address={address} className="size-14" />
<div>
<AddressLink
href={getGnosisAddressExplorerLink(address)}
href={getExplorerAddressUrl(address)}
address={address}
isAIAgent={isAIAgent}
className="text-xl font-semibold md:text-2xl"
Expand Down
8 changes: 2 additions & 6 deletions app/components/TransactionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@swapr/ui';
import { ModalId, useModal } from '@/context/ModalContext';
import Image from 'next/image';
import { GNOSIS_SCAN_URL } from '@/constants';
import { getExplorerTxUrl } from '@/utils';

interface TransactionModalProps {
isLoading: boolean;
Expand Down Expand Up @@ -103,11 +103,7 @@ export const TransactionModal = ({
</DialogBody>
{txHash && (
<DialogFooter>
<a
href={`${GNOSIS_SCAN_URL}/tx/${txHash}`}
target="_blank"
className="w-full"
>
<a href={getExplorerTxUrl(txHash)} target="_blank" className="w-full">
<Button
width="full"
colorScheme={isLoading ? 'primary' : isError ? 'error' : 'success'}
Expand Down
9 changes: 2 additions & 7 deletions app/components/toasts.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
'use client';

import { shortenAddress } from '@/utils';
import { getExplorerTxUrl, shortenAddress } from '@/utils';
import { successToast, toast } from '@swapr/ui';
import { GNOSIS_SCAN_URL } from '@/constants';
import { Outcome, Token } from '@/entities';
import { Spinner } from './Spinner';

const AddressLink = ({ txHash }: { txHash: string }) => (
<a
href={`${GNOSIS_SCAN_URL}/tx/${txHash}`}
target="_blank"
className="inline-block underline"
>
<a href={getExplorerTxUrl(txHash)} target="_blank" className="inline-block underline">
{shortenAddress(txHash)}
</a>
);
Expand Down
11 changes: 8 additions & 3 deletions utils/token.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { GNOSIS_SCAN_URL } from '@/constants';

export const getExplorerAddressUrl = (address: string) => {
return `${GNOSIS_SCAN_URL}/address/${address}`;
};

export const getExplorerTxUrl = (txHash: string) => {
return `${GNOSIS_SCAN_URL}/tx/${txHash}`;
};

export const shortenAddress = (address: string) =>
`${address.slice(0, 6)}...${address.slice(-4)}`;

export const getGnosisAddressExplorerLink = (address: string) =>
`${GNOSIS_SCAN_URL}/address/${address}`;

0 comments on commit 3d8b5c9

Please sign in to comment.