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 ; } return (

{t('Create a referral code')}

{t( 'Generate a referral code to share with your friends and access the commission benefits of the current program.' )}

{pubKey ? ( ) : ( {t('Connect wallet')} )}
); }; export const CreateCodeForm = () => { const t = useT(); const navigate = useNavigate(); const [dialogOpen, setDialogOpen] = useState(false); const { isReadOnly } = useVegaWallet(); return ( <> setDialogOpen(true)} className="w-full" > {t('Create a referral code')} Competitions Homepage, and earn rewards' } components={[ Compeitionts Homepage , ]} /> } > navigate(Links.COMPETITIONS_CREATE_TEAM())} className="w-full" > {t('Create a team')}

{t('Go to competitions')}

setDialogOpen(false)} size="small" > ); }; 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.')}

setDialogOpen(false)} > {t('Close')}
); } if (currentStakeAvailable < requiredStake) { return (

{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('Stake some $VEGA now')}
); } if (!programDetails) { return (
{(status === 'idle' || status === 'requested' || status === 'pending' || err) && ( <> {

{t( 'There is currently no referral program active, are you sure you want to create a code?' )}

} )} {status === 'confirmed' && code && (

{code}

} > {t('Copy')}
)} onSubmit({ createReferralSet: { isTeam: false } })} {...getButtonProps()} > {t('Yes')} {status === 'idle' && ( { refetch(); setDialogOpen(false); }} > {t('No')} )} {err && {err}}
{t('About the referral program')}
); } return (
{(status === 'idle' || status === 'requested' || status === 'pending' || err) && (

{t( 'Generate a referral code to share with your friends and access the commission benefits of the current program.' )}

)} {status === 'confirmed' && code && (

{code}

} > {t('Copy')}
)} {err && {err}}
{t('About the referral program')}
); };