Commit 42ea53d1 authored by isstuev's avatar isstuev

ssr referrer

parent 4a8f8a3d
...@@ -7,13 +7,11 @@ type Props = { ...@@ -7,13 +7,11 @@ type Props = {
pageProps: PageProps; pageProps: PageProps;
} }
const AppContext = createContext<PageProps>({ cookies: '' }); const AppContext = createContext<PageProps>({ cookies: '', referrer: '' });
export function AppWrapper({ children, pageProps }: Props) { export function AppWrapper({ children, pageProps }: Props) {
const appProps = { cookies: pageProps.cookies };
return ( return (
<AppContext.Provider value={ appProps }> <AppContext.Provider value={ pageProps }>
{ children } { children }
</AppContext.Provider> </AppContext.Provider>
); );
......
...@@ -2,12 +2,14 @@ import type { GetServerSideProps, GetServerSidePropsResult } from 'next'; ...@@ -2,12 +2,14 @@ import type { GetServerSideProps, GetServerSidePropsResult } from 'next';
export type Props = { export type Props = {
cookies: string; cookies: string;
referrer: string;
} }
export const getServerSideProps: GetServerSideProps = async({ req }): Promise<GetServerSidePropsResult<Props>> => { export const getServerSideProps: GetServerSideProps = async({ req }): Promise<GetServerSidePropsResult<Props>> => {
return { return {
props: { props: {
cookies: req.headers.cookie || '', cookies: req.headers.cookie || '',
referrer: req.headers.referer || '',
}, },
}; };
}; };
...@@ -7,6 +7,7 @@ import type { Transaction } from 'types/api/transaction'; ...@@ -7,6 +7,7 @@ import type { Transaction } from 'types/api/transaction';
import type { RoutedTab } from 'ui/shared/RoutedTabs/types'; import type { RoutedTab } from 'ui/shared/RoutedTabs/types';
import eastArrowIcon from 'icons/arrows/east.svg'; import eastArrowIcon from 'icons/arrows/east.svg';
import { useAppContext } from 'lib/appContext';
import useFetch from 'lib/hooks/useFetch'; import useFetch from 'lib/hooks/useFetch';
import isBrowser from 'lib/isBrowser'; import isBrowser from 'lib/isBrowser';
import networkExplorers from 'lib/networks/networkExplorers'; import networkExplorers from 'lib/networks/networkExplorers';
...@@ -32,6 +33,12 @@ const TABS: Array<RoutedTab> = [ ...@@ -32,6 +33,12 @@ const TABS: Array<RoutedTab> = [
const TransactionPageContent = () => { const TransactionPageContent = () => {
const router = useRouter(); const router = useRouter();
const fetch = useFetch(); const fetch = useFetch();
const appProps = useAppContext();
const isInBrowser = isBrowser();
const referrer = isInBrowser ? window.document.referrer : appProps.referrer;
const hasGoBackLink = referrer && referrer.includes('/txs');
const { data } = useQuery<unknown, unknown, Transaction>( const { data } = useQuery<unknown, unknown, Transaction>(
[ 'tx', router.query.id ], [ 'tx', router.query.id ],
...@@ -48,12 +55,10 @@ const TransactionPageContent = () => { ...@@ -48,12 +55,10 @@ const TransactionPageContent = () => {
return <ExternalLink key={ explorer.baseUrl } title={ `Open in ${ explorer.title }` } href={ url.toString() }/>; return <ExternalLink key={ explorer.baseUrl } title={ `Open in ${ explorer.title }` } href={ url.toString() }/>;
}); });
const hasGoBackLink = isBrowser() && window.document.referrer.includes('/txs');
return ( return (
<Page> <Page>
{ hasGoBackLink && ( { hasGoBackLink && (
<Link mb={ 6 } display="inline-flex" href={ window.document.referrer }> <Link mb={ 6 } display="inline-flex" href={ referrer }>
<Icon as={ eastArrowIcon } boxSize={ 6 } mr={ 2 } transform="rotate(180deg)"/> <Icon as={ eastArrowIcon } boxSize={ 6 } mr={ 2 } transform="rotate(180deg)"/>
Transactions Transactions
</Link> </Link>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment