Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PE-7610): block return name workflow if name set as primary name #675

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/components/forms/DomainSettings/DomainSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ArweaveID, {
import { ReassignNameModal } from '@src/components/modals/ant-management/ReassignNameModal/ReassignNameModal';
import { ReturnNameModal } from '@src/components/modals/ant-management/ReturnNameModal/ReturnNameModal';
import useDomainInfo from '@src/hooks/useDomainInfo';
import { usePrimaryName } from '@src/hooks/usePrimaryName';
import { ArweaveTransactionID } from '@src/services/arweave/ArweaveTransactionID';
import { useGlobalState } from '@src/state';
import dispatchANTInteraction from '@src/state/actions/dispatchANTInteraction';
Expand Down Expand Up @@ -78,6 +79,7 @@ function DomainSettings({
const [{ arioProcessId, antAoClient }] = useGlobalState();
const [{ interactionResult }, dispatch] = useTransactionState();
const [{ wallet, walletAddress }] = useWalletState();
const { data: primaryNameData } = usePrimaryName();
const { data, isLoading, refetch } = useDomainInfo({ domain, antId });

const [showReturnNameModal, setShowReturnNameModal] = useState(false);
Expand Down Expand Up @@ -169,13 +171,21 @@ function DomainSettings({
{data?.arnsRecord?.type == 'permabuy' && isOwner ? (
<Tooltip
message={
!antHandlers.includes('releaseName')
primaryNameData?.name === lowerCaseDomain(domain ?? '')
? 'Cannot return ArNS name while set as primary name. Remove name as primary name to enable return name workflow.'
: !antHandlers.includes('releaseName')
? 'Update ANT to access Release Name workflow'
: 'Returns the name to the ArNS protocol'
}
icon={
<button
disabled={!antHandlers.includes('releaseName')}
disabled={
primaryNameData?.name ===
lowerCaseDomain(domain ?? '') ||
(!antHandlers.includes('releaseName') &&
primaryNameData?.name !==
lowerCaseDomain(domain ?? ''))
}
onClick={() => setShowReturnNameModal(true)}
className={`flex flex-row text-[12px] rounded-[4px] p-[6px] px-[10px] border border-error bg-error-thin text-error whitespace-nowrap`}
>
Expand Down
16 changes: 14 additions & 2 deletions src/components/modals/PrimaryNameModal/PrimaryNameModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import useDomainInfo from '@src/hooks/useDomainInfo';
import { usePrimaryName } from '@src/hooks/usePrimaryName';
import { ArweaveTransactionID } from '@src/services/arweave/ArweaveTransactionID';
import {
useArNSState,
useGlobalState,
useTransactionState,
useWalletState,
} from '@src/state';
import dispatchANTInteraction from '@src/state/actions/dispatchANTInteraction';
import { dispatchANTUpdate } from '@src/state/actions/dispatchANTUpdate';
import dispatchArIOInteraction from '@src/state/actions/dispatchArIOInteraction';
import {
ANT_INTERACTION_TYPES,
Expand Down Expand Up @@ -73,12 +75,14 @@ function PrimaryNameModal({
setVisible: (visible: boolean) => void;
}) {
const queryClient = useQueryClient();
const [{ arioProcessId, arioContract, aoClient }] = useGlobalState();
const [{ arioProcessId, arioContract, aoClient, aoNetwork }] =
useGlobalState();
const [{ wallet, walletAddress }] = useWalletState();
const { data: primaryNameData, isLoading: isLoadingPrimaryNameData } =
usePrimaryName();

const [{ transactionData }, dispatchTransactionState] = useTransactionState();
const [, dispatchArNSState] = useArNSState();
const [fundingSource, setFundingSource] = useState<FundFrom | undefined>(
'balance',
);
Expand Down Expand Up @@ -220,11 +224,19 @@ function PrimaryNameModal({
name: workflow,
});
}
queryClient.invalidateQueries({
queryClient.resetQueries({
queryKey: ['primary-name'],
exact: false,
});

dispatchANTUpdate({
processId: domainData.processId,
dispatch: dispatchArNSState,
aoNetwork: aoNetwork,
walletAddress,
queryClient,
});

closeModal();
} catch (error) {
eventEmitter.emit('error', error);
Expand Down