2023-09-21 13:25:19 +00:00
|
|
|
import {
|
2023-10-23 14:57:18 +00:00
|
|
|
Loader,
|
2023-09-21 13:25:19 +00:00
|
|
|
TradingAnchorButton,
|
|
|
|
VegaIcon,
|
|
|
|
VegaIconNames,
|
|
|
|
} from '@vegaprotocol/ui-toolkit';
|
|
|
|
import { HowItWorksTable } from './how-it-works-table';
|
|
|
|
import { LandingBanner } from './landing-banner';
|
|
|
|
import { TiersContainer } from './tiers';
|
2023-10-23 14:57:18 +00:00
|
|
|
import { TabLink } from './buttons';
|
2023-09-21 13:25:19 +00:00
|
|
|
import { Outlet } from 'react-router-dom';
|
|
|
|
import { Routes } from '../../lib/links';
|
2023-09-22 11:06:02 +00:00
|
|
|
import { useVegaWallet } from '@vegaprotocol/wallet';
|
|
|
|
import { useReferral } from './hooks/use-referral';
|
2023-10-23 14:57:18 +00:00
|
|
|
import { REFERRAL_DOCS_LINK } from './constants';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { usePageTitleStore } from '../../stores';
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
import { titlefy } from '@vegaprotocol/utils';
|
|
|
|
import { t } from '@vegaprotocol/i18n';
|
|
|
|
|
|
|
|
const Nav = () => (
|
|
|
|
<div className="flex justify-center border-b border-vega-cdark-500">
|
|
|
|
<TabLink end to={Routes.REFERRALS}>
|
2023-10-24 15:43:33 +00:00
|
|
|
{t('I want a code')}
|
2023-10-23 14:57:18 +00:00
|
|
|
</TabLink>
|
2023-10-24 15:43:33 +00:00
|
|
|
<TabLink to={Routes.REFERRALS_APPLY_CODE}>{t('I have a code')}</TabLink>
|
2023-10-23 14:57:18 +00:00
|
|
|
</div>
|
|
|
|
);
|
2023-09-21 13:25:19 +00:00
|
|
|
|
|
|
|
export const Referrals = () => {
|
2023-09-22 11:06:02 +00:00
|
|
|
const { pubKey } = useVegaWallet();
|
2023-10-23 14:57:18 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
data: referee,
|
|
|
|
loading: refereeLoading,
|
|
|
|
error: refereeError,
|
|
|
|
} = useReferral({
|
|
|
|
pubKey,
|
|
|
|
role: 'referee',
|
|
|
|
});
|
|
|
|
const {
|
|
|
|
data: referrer,
|
|
|
|
loading: referrerLoading,
|
|
|
|
error: referrerError,
|
|
|
|
} = useReferral({
|
|
|
|
pubKey,
|
|
|
|
role: 'referrer',
|
|
|
|
});
|
|
|
|
|
|
|
|
const error = refereeError || referrerError;
|
|
|
|
const loading = refereeLoading || referrerLoading;
|
|
|
|
const showNav = !loading && !error && !referrer && !referee;
|
|
|
|
|
|
|
|
const { updateTitle } = usePageTitleStore((store) => ({
|
|
|
|
updateTitle: store.updateTitle,
|
|
|
|
}));
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
updateTitle(titlefy([t('Referrals')]));
|
|
|
|
}, [updateTitle]);
|
2023-09-22 11:06:02 +00:00
|
|
|
|
2023-09-21 13:25:19 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<LandingBanner />
|
2023-10-23 14:57:18 +00:00
|
|
|
|
|
|
|
{showNav && <Nav />}
|
|
|
|
<div
|
|
|
|
className={classNames({
|
|
|
|
'py-16': showNav,
|
|
|
|
'h-[300px] relative': loading || error,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{loading ? (
|
|
|
|
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2">
|
|
|
|
<Loader />
|
|
|
|
</div>
|
|
|
|
) : error ? (
|
|
|
|
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 text-center">
|
2023-10-24 15:43:33 +00:00
|
|
|
<p>{t('Something went wrong')}</p>
|
2023-10-23 14:57:18 +00:00
|
|
|
<span className="text-xs">{error.message}</span>
|
|
|
|
</div>
|
|
|
|
) : (
|
2023-09-21 13:25:19 +00:00
|
|
|
<Outlet />
|
2023-10-23 14:57:18 +00:00
|
|
|
)}
|
2023-09-21 13:25:19 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<TiersContainer />
|
|
|
|
|
|
|
|
<div className="mt-10 mb-5 text-center">
|
2023-10-24 15:43:33 +00:00
|
|
|
<h2 className="text-2xl">{t('How it works')}</h2>
|
2023-09-21 13:25:19 +00:00
|
|
|
</div>
|
|
|
|
<div className="md:w-[60%] mx-auto">
|
|
|
|
<HowItWorksTable />
|
|
|
|
<div className="mt-5">
|
|
|
|
<TradingAnchorButton
|
|
|
|
className="mx-auto w-max"
|
2023-10-23 14:57:18 +00:00
|
|
|
href={REFERRAL_DOCS_LINK}
|
2023-09-21 13:25:19 +00:00
|
|
|
target="_blank"
|
|
|
|
>
|
2023-10-24 15:43:33 +00:00
|
|
|
{t('Read the terms')}{' '}
|
|
|
|
<VegaIcon name={VegaIconNames.OPEN_EXTERNAL} />
|
2023-09-21 13:25:19 +00:00
|
|
|
</TradingAnchorButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|