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

Disable Token Actions if Not Available #2326

Merged
merged 1 commit into from
May 7, 2024
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
21 changes: 12 additions & 9 deletions src/components/frame/Extensions/layouts/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const useCalamityBannerInfo = (): UseCalamityBannerInfoReturnType => {

export const useMainMenuItems = (hasTransactionId: boolean) => {
const {
colony: { metadata },
colony: { metadata, status },
} = useColonyContext();

const {
Expand Down Expand Up @@ -293,14 +293,6 @@ export const useMainMenuItems = (hasTransactionId: boolean) => {
[ACTION_TYPE_FIELD_NAME]: Action.ManageTokens,
}),
},
{
key: '9',
label: formatText({ id: 'actions.mintTokens' }),
onClick: () =>
toggleActionSidebarOn({
[ACTION_TYPE_FIELD_NAME]: Action.MintTokens,
}),
},
],
},
},
Expand Down Expand Up @@ -387,6 +379,17 @@ export const useMainMenuItems = (hasTransactionId: boolean) => {
},
];

if (status?.nativeToken?.mintable) {
mainMenuItems[3].relatedActionsProps?.items?.push({
key: '9',
label: formatText({ id: 'actions.mintTokens' }),
onClick: () =>
toggleActionSidebarOn({
[ACTION_TYPE_FIELD_NAME]: Action.MintTokens,
}),
});
}

return mainMenuItems;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const BalanceTable: FC = () => {
),
icon: ArrowSquareOut,
},
...(isTokenNative
...(isTokenNative && nativeTokenStatus?.mintable
? [
{
key: 'mint_tokens',
Expand Down
18 changes: 13 additions & 5 deletions src/components/v5/common/ActionSidebar/hooks/useActionsList.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useMemo } from 'react';

import { Action } from '~constants/actions.ts';
import { useColonyContext } from '~context/ColonyContext/ColonyContext.ts';
import { type SearchSelectOptionProps } from '~v5/shared/SearchSelect/types.ts';

const useActionsList = () => {
return useMemo(
(): SearchSelectOptionProps[] => [
const { colony } = useColonyContext();
return useMemo((): SearchSelectOptionProps[] => {
const actionsListOptions: SearchSelectOptionProps[] = [
{
key: '1',
title: { id: 'actions.payments' },
Expand Down Expand Up @@ -129,9 +131,15 @@ const useActionsList = () => {
// },
],
},
],
[],
);
];
if (!colony?.status?.nativeToken?.mintable) {
actionsListOptions[2].options[1].isDisabled = true;
}
if (!colony?.status?.nativeToken?.unlockable) {
actionsListOptions[2].options[2].isDisabled = true;
}
return actionsListOptions;
}, [colony]);
};

export default useActionsList;
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ const SearchItem: FC<SearchItemProps> = ({
label,
value,
isDisabled,
isComingSoon,
avatar,
showAvatar,
color,
walletAddress = '',
token,
isVerified,
}) => {
const firstDisabledOption = options.filter(
(option) => option.isDisabled,
)[0];
const comingSoonOption = isComingSoon || (isDisabled && isComingSoon);
const labelText = formatText(label || '');

const hasAvatar = showAvatar || !!color || !!token;
Expand Down Expand Up @@ -122,7 +121,7 @@ const SearchItem: FC<SearchItemProps> = ({
/>
)}
{!label && <span className="truncate">{walletAddress}</span>}
{firstDisabledOption?.value === value && (
{comingSoonOption && (
<div className="absolute right-0 top-1/2 -translate-y-1/2 transform">
<ExtensionsStatusBadge
mode="coming-soon"
Expand Down
1 change: 1 addition & 0 deletions src/components/v5/shared/SearchSelect/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface SearchSelectOption {
label: MessageDescriptor | string;
value: string | number;
isDisabled?: boolean;
isComingSoon?: boolean;
avatar?: string;
thumbnail?: string;
showAvatar?: boolean;
Expand Down
Loading