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: ipfs links #174

Merged
merged 11 commits into from
Dec 12, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export const Navigation: FC = memo(() => {
{routes.map(({ name, path, icon }) => {
const isActive =
pathnameWithoutQuery === path ||
(path.length > 1 && pathnameWithoutQuery.startsWith(path));
(path.length > 1 && pathnameWithoutQuery.startsWith(path)) ||
// fix for withdrawals/claim
(pathname.indexOf('withdrawals') > -1 &&
solidovic marked this conversation as resolved.
Show resolved Hide resolved
path.indexOf('withdrawals') > -1);

return (
<LocalLink key={path} href={path}>
Expand Down
27 changes: 25 additions & 2 deletions shared/components/link-ipfs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import React, { ReactNode, MouseEventHandler, useCallback } from 'react';
import React, {
ReactNode,
MouseEventHandler,
useCallback,
useMemo,
} from 'react';

import { usePrefixedPush } from 'shared/hooks/use-prefixed-history';

Expand All @@ -13,16 +18,34 @@ export const LinkIpfs = ({ onClick, query, ...props }: Props) => {
const push = usePrefixedPush();
const { href } = props;

// Actual for click (opening in same tab)
const handleClick: MouseEventHandler<HTMLAnchorElement> = useCallback(
(event) => {
event.preventDefault();
void push(href, query);

if (typeof window !== 'undefined') {
window.scrollTo({ top: 0 });
solidovic marked this conversation as resolved.
Show resolved Hide resolved
}

onClick?.(event);
},
[onClick, push, href, query],
);

// Actual for opening in new tab
const basedHashHref = useMemo(() => {
let queryString = new URLSearchParams(query).toString();
queryString = queryString.length > 0 ? `?${queryString}` : '';

// Make a link:
// '/?<some_query_param>=<some_query_value>&...&<some_query_param_N>=<some_query_value_N>#/<hash_path>'
// e.g.: '/#/wrap'
// e.g.: '?ref=0x0000000000000000000000000000000000000000#/'
return `/${queryString}#${href}`;
}, [href, query]);

// TODO:
// eslint-disable-next-line jsx-a11y/anchor-has-content,jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
return <a {...props} onClick={handleClick} />;
return <a {...props} href={basedHashHref} onClick={handleClick} />;
};
solidovic marked this conversation as resolved.
Show resolved Hide resolved
Loading