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-7543): only owner will see primary name button #672

Merged
merged 2 commits 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
3 changes: 3 additions & 0 deletions src/components/data-display/tables/DomainsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ const DomainsTable = ({
arnsDomain={row.getValue('name')}
antId={row.getValue('processId')}
handlers={row.original.handlers}
state={
domainData.ants?.[row.getValue('processId') as string]?.state
}
/>
)}
tableClass="border-[1px] border-dark-grey"
Expand Down
133 changes: 70 additions & 63 deletions src/components/data-display/tables/UndernamesSubtable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AoANTHandler, AoANTRecord } from '@ar.io/sdk';
import { AoANTHandler, AoANTRecord, AoANTState } from '@ar.io/sdk';
import { ExternalLinkIcon, PencilIcon } from '@src/components/icons';
import ArweaveID, {
ArweaveIdTypes,
Expand Down Expand Up @@ -47,14 +47,19 @@ const UndernamesSubtable = ({
arnsDomain,
antId,
handlers,
state,
}: {
undernames: Record<string, AoANTRecord>;
arnsDomain: string;
handlers?: AoANTHandler[] | null;
antId: string;
state?: AoANTState | null;
}) => {
const [{ arioProcessId, antAoClient }] = useGlobalState();
const [{ wallet, walletAddress }] = useWalletState();
const isOwner = walletAddress
? state?.Owner === walletAddress.toString()
: false;
const [, dispatchTransactionState] = useTransactionState();
const [, dispatchModalState] = useModalState();
const { data: primaryNameData } = usePrimaryName();
Expand All @@ -80,72 +85,74 @@ const UndernamesSubtable = ({
ttlSeconds: record.ttlSeconds,
action: (
<span className="flex justify-end pr-3 gap-3">
<Tooltip
message={
!arnsDomain
? 'Loading...'
: !handlers?.includes('approvePrimaryName') ||
!handlers?.includes('removePrimaryNames')
? 'Update ANT to access Primary Names workflow'
: primaryNameData?.name ===
encodePrimaryName(undername + '_' + arnsDomain)
? 'Remove Primary Name'
: 'Set Primary Name'
}
icon={
<button
disabled={
!handlers?.includes('approvePrimaryName') ||
!handlers?.includes('removePrimaryNames')
}
onClick={() => {
if (!arnsDomain || !antId) return;
const targetName = encodePrimaryName(
undername + '_' + arnsDomain,
);
if (primaryNameData?.name === targetName) {
// remove primary name payload
dispatchTransactionState({
type: 'setTransactionData',
payload: {
names: [targetName],
arioProcessId,
assetId: antId,
functionName: 'removePrimaryNames',
},
});
} else {
dispatchTransactionState({
type: 'setTransactionData',
payload: {
name: targetName,
arioProcessId,
assetId: arioProcessId,
functionName: 'primaryNameRequest',
},
});
{isOwner && (
<Tooltip
message={
!arnsDomain
? 'Loading...'
: !handlers?.includes('approvePrimaryName') ||
!handlers?.includes('removePrimaryNames')
? 'Update ANT to access Primary Names workflow'
: primaryNameData?.name ===
encodePrimaryName(undername + '_' + arnsDomain)
? 'Remove Primary Name'
: 'Set Primary Name'
}
icon={
<button
disabled={
!handlers?.includes('approvePrimaryName') ||
!handlers?.includes('removePrimaryNames')
}
onClick={() => {
if (!arnsDomain || !antId) return;
const targetName = encodePrimaryName(
undername + '_' + arnsDomain,
);
if (primaryNameData?.name === targetName) {
// remove primary name payload
dispatchTransactionState({
type: 'setTransactionData',
payload: {
names: [targetName],
arioProcessId,
assetId: antId,
functionName: 'removePrimaryNames',
},
});
} else {
dispatchTransactionState({
type: 'setTransactionData',
payload: {
name: targetName,
arioProcessId,
assetId: arioProcessId,
functionName: 'primaryNameRequest',
},
});
}

dispatchModalState({
type: 'setModalOpen',
payload: { showPrimaryNameModal: true },
});
}}
>
<Star
className={
(encodePrimaryName(undername + '_' + arnsDomain) ==
primaryNameData?.name
? 'text-primary fill-primary'
: 'text-grey') +
`
dispatchModalState({
type: 'setModalOpen',
payload: { showPrimaryNameModal: true },
});
}}
>
<Star
className={
(encodePrimaryName(undername + '_' + arnsDomain) ==
primaryNameData?.name
? 'text-primary fill-primary'
: 'text-grey') +
`
w-[18px]
`
}
/>
</button>
}
/>
}
/>
</button>
}
/>
)}
<button
className="fill-grey hover:fill-white"
onClick={() => {
Expand Down
129 changes: 67 additions & 62 deletions src/components/data-display/tables/UndernamesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ const UndernamesTable = ({
const [searchParams, setSearchParams] = useSearchParams();
const [{ arioProcessId, antAoClient }] = useGlobalState();
const [{ wallet, walletAddress }] = useWalletState();
const isOwner = walletAddress
? info?.Owner === walletAddress.toString()
: false;
const [, dispatchTransactionState] = useTransactionState();
const [, dispatchModalState] = useModalState();
const { data: primaryNameData } = usePrimaryName();
Expand Down Expand Up @@ -189,72 +192,74 @@ const UndernamesTable = ({
className="flex flex-row justify-end pr-3 gap-3"
style={{ gap: '15px' }}
>
<Tooltip
message={
!arnsDomain
? 'Loading...'
: !antHandlers?.includes('approvePrimaryName') ||
!antHandlers?.includes('removePrimaryNames')
? 'Update ANT to access Primary Names workflow'
: primaryNameData?.name ===
encodePrimaryName(undername + '_' + arnsDomain)
? 'Remove Primary Name'
: 'Set Primary Name'
}
icon={
<button
disabled={
!antHandlers?.includes('approvePrimaryName') ||
!antHandlers?.includes('removePrimaryNames')
}
onClick={() => {
if (!arnsDomain || !antId) return;
const targetName = encodePrimaryName(
undername + '_' + arnsDomain,
);
if (primaryNameData?.name === targetName) {
// remove primary name payload
dispatchTransactionState({
type: 'setTransactionData',
payload: {
names: [targetName],
arioProcessId,
assetId: antId,
functionName: 'removePrimaryNames',
},
});
} else {
dispatchTransactionState({
type: 'setTransactionData',
payload: {
name: targetName,
arioProcessId,
assetId: arioProcessId,
functionName: 'primaryNameRequest',
},
});
{isOwner && (
<Tooltip
message={
!arnsDomain
? 'Loading...'
: !antHandlers?.includes('approvePrimaryName') ||
!antHandlers?.includes('removePrimaryNames')
? 'Update ANT to access Primary Names workflow'
: primaryNameData?.name ===
encodePrimaryName(undername + '_' + arnsDomain)
? 'Remove Primary Name'
: 'Set Primary Name'
}
icon={
<button
disabled={
!antHandlers?.includes('approvePrimaryName') ||
!antHandlers?.includes('removePrimaryNames')
}
onClick={() => {
if (!arnsDomain || !antId) return;
const targetName = encodePrimaryName(
undername + '_' + arnsDomain,
);
if (primaryNameData?.name === targetName) {
// remove primary name payload
dispatchTransactionState({
type: 'setTransactionData',
payload: {
names: [targetName],
arioProcessId,
assetId: antId,
functionName: 'removePrimaryNames',
},
});
} else {
dispatchTransactionState({
type: 'setTransactionData',
payload: {
name: targetName,
arioProcessId,
assetId: arioProcessId,
functionName: 'primaryNameRequest',
},
});
}

dispatchModalState({
type: 'setModalOpen',
payload: { showPrimaryNameModal: true },
});
}}
>
<Star
className={
(encodePrimaryName(undername + '_' + arnsDomain) ==
primaryNameData?.name
? 'text-primary fill-primary'
: 'text-grey') +
`
dispatchModalState({
type: 'setModalOpen',
payload: { showPrimaryNameModal: true },
});
}}
>
<Star
className={
(encodePrimaryName(undername + '_' + arnsDomain) ==
primaryNameData?.name
? 'text-primary fill-primary'
: 'text-grey') +
`
w-[18px]
`
}
/>
</button>
}
/>
}
/>
</button>
}
/>
)}
<button
className="fill-grey hover:fill-white"
onClick={() => {
Expand Down