Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return only valid links #248

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/app-commons/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export const WALLET_INSTALL = process.env.NEXT_PUBLIC_WALLET_INSTALL;
export const WALLET_INSTALL_NEXT = process.env.NEXT_PUBLIC_WALLET_INSTALL_NEXT;
export const NODE_ENV = process.env.NODE_ENV;

export const BLOCK_EXPLORER_URL = process.env.NEXT_PUBLIC_BLOCK_EXPLORER_URL;

export const IS_PREVIEW = process.env.NEXT_PUBLIC_IS_PUBLIC_PREVIEW === 'true';
export const IS_DEVELOPMENT = process.env.NODE_ENV === 'development';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import { BLOCK_EXPLORER_URL, FUEL_CHAIN } from 'app-commons';
import { FUEL_CHAIN } from 'app-commons';
import { buildBlockExplorerUrl } from 'fuels';
import { useMemo } from 'react';

export type ExplorerLinkProps = {
network: 'ethereum' | 'fuel' | string | undefined;
network: 'ethereum' | 'fuel';
providerUrl?: string;
id?: string;
id: string;
};

export function useExplorerLink({
network,
providerUrl,
id,
}: ExplorerLinkProps) {
const href = useMemo(() => {
const href = useMemo<string>(() => {
if (network === 'ethereum') {
return `https://sepolia.etherscan.io/tx/${id}`;
}

if (network === 'fuel') {
if (providerUrl === FUEL_CHAIN.providerUrl) {
return `${BLOCK_EXPLORER_URL}tx/${id}`;
return `/tx/${id}`;
}

return buildBlockExplorerUrl({
path: `transaction/${id || ''}`,
path: `transaction/${id}`,
providerUrl,
});
}

return '';
}, [network, providerUrl, id]);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function useTxEthToFuel({ id }: { id: string }) {
const txId = id.startsWith('0x') ? (id as `0x${string}`) : undefined;
const { href: explorerLink } = useExplorerLink({
network: 'ethereum',
id: txId,
id,
});

const txEthToFuelState = store.useSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export function useTxFuelToEth({ txId }: { txId: string }) {
const { assets } = useAssets();
const { href: explorerLink } = useExplorerLink({
network: 'fuel',
providerUrl: fuelProvider?.url || '',
providerUrl: fuelProvider?.url,
id: txId,
});

Expand Down
Loading