import { TradingButton as Button, Dialog, Intent, Tooltip, VegaIcon, VegaIconNames, } from '@vegaprotocol/ui-toolkit'; import { useSimpleTransaction, useVegaWallet, type Status, } from '@vegaprotocol/wallet'; import { useT } from '../../lib/use-t'; import { type Team } from '../../lib/hooks/use-team'; import { useState } from 'react'; type JoinType = 'switch' | 'join'; export const JoinTeam = ({ team, partyTeam, refetch, }: { team: Team; partyTeam?: Team; refetch: () => void; }) => { const { pubKey, isReadOnly } = useVegaWallet(); const { send, status } = useSimpleTransaction({ onSuccess: refetch, }); const [confirmDialog, setConfirmDialog] = useState(); const joinTeam = () => { send({ joinTeam: { id: team.teamId, }, }); }; return ( <> setConfirmDialog(undefined)} > {confirmDialog !== undefined && ( setConfirmDialog(undefined)} /> )} ); }; export const JoinButton = ({ pubKey, isReadOnly, team, partyTeam, onJoin, }: { pubKey: string | null; isReadOnly: boolean; team: Team; partyTeam?: Team; onJoin: (type: JoinType) => void; }) => { const t = useT(); if (!pubKey || isReadOnly) { return ( ); } // Party is the creator of a team else if (partyTeam && partyTeam.referrer === pubKey) { // Party is the creator of THIS team if (partyTeam.teamId === team.teamId) { return ( ); } else { // Not creator of the team, but still can't switch because // creators cannot leave their own team return ( ); } } // Party is in a team, but not this one else if (partyTeam && partyTeam.teamId !== team.teamId) { return ( ); } // Joined. Current party is already in this team else if (partyTeam && partyTeam.teamId === team.teamId) { return ( ); } return ( ); }; const DialogContent = ({ type, status, team, partyTeam, onConfirm, onCancel, }: { type: JoinType; status: Status; team: Team; partyTeam?: Team; onConfirm: () => void; onCancel: () => void; }) => { const t = useT(); if (status === 'requested') { return

{t('Confirm in wallet...')}

; } if (status === 'pending') { return

{t('Confirming transaction...')}

; } if (status === 'confirmed') { if (type === 'switch') { return (

{t( 'Team switch successful. You will switch team at the end of the epoch.' )}

); } return

{t('Team joined')}

; } return (
{type === 'switch' && ( <>

{t('Switch team')}

{t( "Switching team will move you from '{{fromTeam}}' to '{{toTeam}}' at the end of the epoch. Are you sure?", { fromTeam: partyTeam?.name, toTeam: team.name, } )}

)} {type === 'join' && ( <>

{t('Join team')}

{t('Are you sure you want to join team: {{team}}', { team: team.name, })}

)}
); };