import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
import { RainbowButton } from '../../components/rainbow-button';
import { useState } from 'react';
import {
CopyWithTooltip,
Dialog,
ExternalLink,
InputError,
Intent,
Tooltip,
TradingAnchorButton,
TradingButton,
VegaIcon,
VegaIconNames,
} from '@vegaprotocol/ui-toolkit';
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
import { DApp, TokenStaticLinks, useLinks } from '@vegaprotocol/environment';
import { ABOUT_REFERRAL_DOCS_LINK } from './constants';
import { useIsInReferralSet, useReferral } from './hooks/use-referral';
import { useT } from '../../lib/use-t';
import { Link, Navigate, useNavigate } from 'react-router-dom';
import { Links, Routes } from '../../lib/links';
import { useReferralProgram } from './hooks/use-referral-program';
import { useReferralSetTransaction } from '../../lib/hooks/use-referral-set-transaction';
import { Trans } from 'react-i18next';
export const CreateCodeContainer = () => {
const t = useT();
const { pubKey, isReadOnly } = useVegaWallet();
const isInReferralSet = useIsInReferralSet(pubKey);
const openWalletDialog = useVegaWalletDialogStore(
(store) => store.openVegaWalletDialog
);
// Navigate to the index page when already in the referral set.
if (isInReferralSet) {
return
{t( 'Generate a referral code to share with your friends and access the commission benefits of the current program.' )}
{t('Go to competitions')}
> ); }; const CreateCodeDialog = ({ setDialogOpen, }: { setDialogOpen: (open: boolean) => void; }) => { const t = useT(); const createLink = useLinks(DApp.Governance); const { pubKey } = useVegaWallet(); const { refetch } = useReferral({ pubKey, role: 'referrer' }); const { err, code, status, stakeAvailable: currentStakeAvailable, requiredStake, onSubmit, } = useReferralSetTransaction(); const { details: programDetails } = useReferralProgram(); const getButtonProps = () => { if (status === 'idle') { return { children: t('Generate code'), onClick: () => onSubmit({ createReferralSet: { isTeam: false } }), }; } if (status === 'requested') { return { children: t('Confirm in wallet...'), disabled: true, }; } if (status === 'pending') { return { children: t('Waiting for transaction...'), disabled: true, }; } if (status === 'confirmed') { return { children: t('Close'), intent: Intent.Success, onClick: () => { refetch(); setDialogOpen(false); }, }; } }; if (!pubKey || currentStakeAvailable == null || requiredStake == null) { return ({t('You must be connected to the Vega wallet.')}
{t( 'You need at least {{requiredStake}} VEGA staked to generate a referral code and participate in the referral program.', { requiredStake: addDecimalsFormatNumber( requiredStake.toString(), 18 ), } )}
{t( 'There is currently no referral program active, are you sure you want to create a code?' )}
} > )} {status === 'confirmed' && code && ({code}
{t( 'Generate a referral code to share with your friends and access the commission benefits of the current program.' )}
)} {status === 'confirmed' && code && ({code}