From 840eb421bca71b4ebc52a09e96fdcc0c7953e674 Mon Sep 17 00:00:00 2001 From: sepehr sanaee Date: Sat, 28 Oct 2023 23:38:49 +0330 Subject: [PATCH] show only available versions --- src/containers/defineProposal/index.tsx | 46 +++++++----- .../settings/versionInfoCard/index.tsx | 10 +-- .../updateListItem/updateListItem.tsx | 2 + .../versionSelectionMenu.tsx | 14 ++-- src/context/update.tsx | 73 +++++++++++++------ src/hooks/usePluginAvailableVersions.tsx | 12 +-- src/hooks/usePreparedPlugins.tsx | 12 +-- .../localStorage/preparePluginStorage.ts | 0 8 files changed, 104 insertions(+), 65 deletions(-) create mode 100644 src/utils/localStorage/preparePluginStorage.ts diff --git a/src/containers/defineProposal/index.tsx b/src/containers/defineProposal/index.tsx index 005ff241b..7ddf64d4a 100644 --- a/src/containers/defineProposal/index.tsx +++ b/src/containers/defineProposal/index.tsx @@ -19,6 +19,7 @@ import {UpdateListItem} from 'containers/updateListItem/updateListItem'; import {useParams} from 'react-router-dom'; import {VersionSelectionMenu} from 'containers/versionSelectionMenu/versionSelectionMenu'; import {useUpdateContext} from 'context/update'; +import {Loading} from 'components/temporary'; const DefineProposal: React.FC = () => { const {t} = useTranslation(); @@ -57,6 +58,7 @@ const DefineProposal: React.FC = () => { }); e?.stopPropagation(); }, + disabled: !osxAvailableVersions?.size, }, { id: 'plugin', @@ -86,6 +88,7 @@ const DefineProposal: React.FC = () => { }); e?.stopPropagation(); }, + disabled: !pluginAvailableVersions?.size, }, ]; @@ -120,6 +123,10 @@ const DefineProposal: React.FC = () => { } }, [setValue, type]); + if (!pluginSelectedVersion) { + return ; + } + if (type === 'os-update') { return ( @@ -130,24 +137,27 @@ const DefineProposal: React.FC = () => { control={control} render={({field: {onChange, value}}) => ( <> - {UpdateItems.map((data, index) => ( - - onChange({ - ...value, - [data.id]: !value?.[data.id], - }) - } - onClickActionPrimary={(e: React.MouseEvent) => { - e?.stopPropagation(); - handlePreparePlugin(data.id); - }} - /> - ))} + {UpdateItems.map((data, index) => { + if (!data.disabled) + return ( + { + onChange({ + ...value, + [data.id]: !value?.[data.id], + }); + }} + onClickActionPrimary={(e: React.MouseEvent) => { + e?.stopPropagation(); + handlePreparePlugin(data.id); + }} + /> + ); + })} )} /> diff --git a/src/containers/settings/versionInfoCard/index.tsx b/src/containers/settings/versionInfoCard/index.tsx index 9898d95b6..a26e9e5b9 100644 --- a/src/containers/settings/versionInfoCard/index.tsx +++ b/src/containers/settings/versionInfoCard/index.tsx @@ -36,9 +36,9 @@ export const VersionInfoCard: React.FC<{ SupportedNetworksArray.includes(translatedNetwork) ) { OSxAddress = - LIVE_CONTRACTS[ - `${versions?.[0]}.${versions?.[1]}.${versions?.[2]}` as SupportedVersion - ]?.[translatedNetwork]?.daoFactoryAddress; + LIVE_CONTRACTS[versions?.join('.') as SupportedVersion]?.[ + translatedNetwork + ]?.daoFactoryAddress; } // TODO: generate the links @@ -65,9 +65,7 @@ export const VersionInfoCard: React.FC<{ = ({ @@ -88,6 +89,7 @@ export const UpdateListItem: React.FC = ({ label={buttonSecondaryLabel} mode="secondary" bgWhite + disabled={disabled} size="medium" onClick={onClickActionSecondary} /> diff --git a/src/containers/versionSelectionMenu/versionSelectionMenu.tsx b/src/containers/versionSelectionMenu/versionSelectionMenu.tsx index dea5818fe..222363f5b 100644 --- a/src/containers/versionSelectionMenu/versionSelectionMenu.tsx +++ b/src/containers/versionSelectionMenu/versionSelectionMenu.tsx @@ -78,22 +78,22 @@ export const VersionSelectionMenu: React.FC = ({ subtitle={t('update.modalVersion.desc')} >
- {showModal.type === 'os' ? ( + {showModal.type === 'os' && ( ( + render={({field: {onChange, value: value23}}) => ( <> {osVersionList.map((data, index) => { - console.log('value23', value); return ( @@ -109,7 +109,9 @@ export const VersionSelectionMenu: React.FC = ({ )} /> - ) : ( + )} + + {showModal.type === 'plugin' && ( = ({children}) => { const pluginClient = usePluginClient(pluginType); const {data: pluginAvailableVersions, isLoading: availableVersionLoading} = usePluginAvailableVersions(pluginType, daoDetails?.address as string); + const {data: versions, isLoading} = useProtocolVersions(daoDetails?.address); const pluginSelectedVersion = getValues('pluginSelectedVersion'); @@ -164,19 +166,27 @@ const UpdateProvider: React.FC<{children: ReactElement}> = ({children}) => { const OSXVersions = new Map(); Object.keys(SupportedVersion).forEach(key => { - OSXVersions.set(SupportedVersion[key as keyof typeof SupportedVersion], { - version: SupportedVersion[ - key as keyof typeof SupportedVersion - ] as string, - ...(key === 'LATEST' && {isLatest: true}), - } as OSX); - - if (key === 'LATEST') + if ( + Number(SupportedVersion[key as keyof typeof SupportedVersion]) >= + Number(versions?.join('.')) + ) + OSXVersions.set( + SupportedVersion[key as keyof typeof SupportedVersion], + { + version: SupportedVersion[ + key as keyof typeof SupportedVersion + ] as string, + ...(key === 'LATEST' && {isLatest: true}), + } as OSX + ); + + if (key === 'LATEST') { setValue('osSelectedVersion', { version: SupportedVersion[ key as keyof typeof SupportedVersion ] as string, }); + } }); const pluginVersions = new Map(); @@ -187,25 +197,29 @@ const UpdateProvider: React.FC<{children: ReactElement}> = ({children}) => { }); release.builds.map((build, buildIndex) => { - pluginVersions.set(`${release.release}.${build.build}`, { + if ( + release.release >= daoDetails!.plugins[0].release && + build.build > daoDetails!.plugins[0].build + ) + pluginVersions.set(`${release.release}.${build.build}`, { + version: { + build: build.build, + release: release.release, + }, + isPrepared: false, + ...(releaseIndex === pluginAvailableVersions?.releases.length - 1 && + buildIndex === release.builds.length - 1 && { + isLatest: true, + }), + }); + + setValue('pluginSelectedVersion', { version: { - build: build.build, + build: release.builds[release.builds.length - 1].build, release: release.release, }, - isPrepared: false, - ...(releaseIndex === pluginAvailableVersions?.releases.length - 1 && - buildIndex === release.builds.length - 1 && { - isLatest: true, - }), }); }); - - setValue('pluginSelectedVersion', { - version: { - build: release.builds[release.builds.length - 1].build, - release: release.release, - }, - }); }); dispatch({ @@ -216,7 +230,13 @@ const UpdateProvider: React.FC<{children: ReactElement}> = ({children}) => { type: 'setOSXAvailableVersions', payload: OSXVersions, }); - }, [availableVersionLoading, pluginAvailableVersions, setValue]); + }, [ + availableVersionLoading, + daoDetails, + pluginAvailableVersions, + setValue, + versions, + ]); /************************************************* * Handlers * @@ -343,6 +363,13 @@ const UpdateProvider: React.FC<{children: ReactElement}> = ({children}) => { break; case PrepareUpdateStep.DONE: const pluginListTemp = state.pluginList; + localStorage.setItem( + 'preparePlugin', + JSON.stringify({ + daoAddress: daoDetails?.address, + ...step, + }) + ); pluginListTemp?.set( `${step.versionTag.release}.${step.versionTag.build}`, { diff --git a/src/hooks/usePluginAvailableVersions.tsx b/src/hooks/usePluginAvailableVersions.tsx index ac6fa9c0b..9e92bf5c6 100644 --- a/src/hooks/usePluginAvailableVersions.tsx +++ b/src/hooks/usePluginAvailableVersions.tsx @@ -56,12 +56,12 @@ export const usePluginAvailableVersions = ( ) { PluginRepoAddress = pluginType === 'multisig.plugin.dao.eth' - ? LIVE_CONTRACTS[ - `${versions?.[0]}.${versions?.[1]}.${versions?.[2]}` as SupportedVersion - ]?.[translatedNetwork].multisigRepoAddress - : LIVE_CONTRACTS[ - `${versions?.[0]}.${versions?.[1]}.${versions?.[2]}` as SupportedVersion - ]?.[translatedNetwork].tokenVotingRepoAddress; + ? LIVE_CONTRACTS[versions?.join('.') as SupportedVersion]?.[ + translatedNetwork + ].multisigRepoAddress + : LIVE_CONTRACTS[versions?.join('.') as SupportedVersion]?.[ + translatedNetwork + ].tokenVotingRepoAddress; } return useQuery({ diff --git a/src/hooks/usePreparedPlugins.tsx b/src/hooks/usePreparedPlugins.tsx index 415898e04..223fc1127 100644 --- a/src/hooks/usePreparedPlugins.tsx +++ b/src/hooks/usePreparedPlugins.tsx @@ -37,12 +37,12 @@ export function usePreparedPlugin( ) { PluginRepoAddress = pluginType === 'multisig.plugin.dao.eth' - ? LIVE_CONTRACTS[ - `${versions?.[0]}.${versions?.[1]}.${versions?.[2]}` as SupportedVersion - ]?.[translatedNetwork].multisigRepoAddress - : LIVE_CONTRACTS[ - `${versions?.[0]}.${versions?.[1]}.${versions?.[2]}` as SupportedVersion - ]?.[translatedNetwork].tokenVotingRepoAddress; + ? LIVE_CONTRACTS[versions?.join('.') as SupportedVersion]?.[ + translatedNetwork + ].multisigRepoAddress + : LIVE_CONTRACTS[versions?.join('.') as SupportedVersion]?.[ + translatedNetwork + ].tokenVotingRepoAddress; } useEffect(() => { diff --git a/src/utils/localStorage/preparePluginStorage.ts b/src/utils/localStorage/preparePluginStorage.ts new file mode 100644 index 000000000..e69de29bb