Skip to content

Commit

Permalink
show only available versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sepehr2github committed Oct 28, 2023
1 parent 3b55845 commit 840eb42
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 65 deletions.
46 changes: 28 additions & 18 deletions src/containers/defineProposal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -57,6 +58,7 @@ const DefineProposal: React.FC = () => {
});
e?.stopPropagation();
},
disabled: !osxAvailableVersions?.size,
},
{
id: 'plugin',
Expand Down Expand Up @@ -86,6 +88,7 @@ const DefineProposal: React.FC = () => {
});
e?.stopPropagation();
},
disabled: !pluginAvailableVersions?.size,
},
];

Expand Down Expand Up @@ -120,6 +123,10 @@ const DefineProposal: React.FC = () => {
}
}, [setValue, type]);

if (!pluginSelectedVersion) {
return <Loading />;
}

if (type === 'os-update') {
return (
<UpdateContainer>
Expand All @@ -130,24 +137,27 @@ const DefineProposal: React.FC = () => {
control={control}
render={({field: {onChange, value}}) => (
<>
{UpdateItems.map((data, index) => (
<UpdateListItem
key={index}
{...data}
type={value?.[data.id] ? 'active' : 'default'}
multiSelect
onClick={() =>
onChange({
...value,
[data.id]: !value?.[data.id],
})
}
onClickActionPrimary={(e: React.MouseEvent) => {
e?.stopPropagation();
handlePreparePlugin(data.id);
}}
/>
))}
{UpdateItems.map((data, index) => {
if (!data.disabled)
return (
<UpdateListItem
key={index}
{...data}
type={value?.[data.id] ? 'active' : 'default'}
multiSelect
onClick={() => {
onChange({
...value,
[data.id]: !value?.[data.id],
});
}}
onClickActionPrimary={(e: React.MouseEvent) => {
e?.stopPropagation();
handlePreparePlugin(data.id);
}}
/>
);
})}
</>
)}
/>
Expand Down
10 changes: 4 additions & 6 deletions src/containers/settings/versionInfoCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -65,9 +65,7 @@ export const VersionInfoCard: React.FC<{
<FlexibleDefinition>
<Link
label={
!isLoading
? `Aragon OSx v${versions?.[0]}.${versions?.[1]}.${versions?.[2]}`
: 'Loading...'
!isLoading ? `Aragon OSx v${versions?.join('.')}` : 'Loading...'
}
description={OSxAddress ? shortenAddress(OSxAddress) : undefined}
type="primary"
Expand Down
2 changes: 2 additions & 0 deletions src/containers/updateListItem/updateListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const UpdateListItem: React.FC<CheckboxListItemProps> = ({
<ButtonText
label={buttonPrimaryLabel}
mode="primary"
disabled={disabled}
size="medium"
onClick={onClickActionPrimary}
/>
Expand All @@ -88,6 +89,7 @@ export const UpdateListItem: React.FC<CheckboxListItemProps> = ({
label={buttonSecondaryLabel}
mode="secondary"
bgWhite
disabled={disabled}
size="medium"
onClick={onClickActionSecondary}
/>
Expand Down
14 changes: 8 additions & 6 deletions src/containers/versionSelectionMenu/versionSelectionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ export const VersionSelectionMenu: React.FC<CheckboxListItemProps> = ({
subtitle={t('update.modalVersion.desc')}
>
<div className="grid gap-y-3 px-2 py-3">
{showModal.type === 'os' ? (
{showModal.type === 'os' && (
<Controller
name="osSelectedVersion"
rules={{required: 'Validate'}}
control={control}
render={({field: {onChange, value}}) => (
render={({field: {onChange, value: value23}}) => (
<>
<VersionListContainer>
{osVersionList.map((data, index) => {
console.log('value23', value);
return (
<UpdateListItem
{...data}
key={index}
type={
value?.version === data.version ? 'active' : 'default'
value23?.version === data.version
? 'active'
: 'default'
}
LinkLabel={t('update.item.releaseNotesLabel')}
onClick={() =>
Expand All @@ -109,7 +109,9 @@ export const VersionSelectionMenu: React.FC<CheckboxListItemProps> = ({
</>
)}
/>
) : (
)}

{showModal.type === 'plugin' && (
<Controller
name="pluginSelectedVersion"
rules={{required: 'Validate'}}
Expand Down
73 changes: 50 additions & 23 deletions src/context/update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {PluginTypes, usePluginClient} from 'hooks/usePluginClient';
import {useDaoDetailsQuery} from 'hooks/useDaoDetails';
import {usePluginAvailableVersions} from 'hooks/usePluginAvailableVersions';
import {usePreparedPlugin} from 'hooks/usePreparedPlugins';
import {useProtocolVersions} from 'hooks/useDaoVersions';

type UpdateContextType = {
/** Prepares the creation data and awaits user confirmation to start process */
Expand Down Expand Up @@ -143,6 +144,7 @@ const UpdateProvider: React.FC<{children: ReactElement}> = ({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');

Expand All @@ -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();
Expand All @@ -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({
Expand All @@ -216,7 +230,13 @@ const UpdateProvider: React.FC<{children: ReactElement}> = ({children}) => {
type: 'setOSXAvailableVersions',
payload: OSXVersions,
});
}, [availableVersionLoading, pluginAvailableVersions, setValue]);
}, [
availableVersionLoading,
daoDetails,
pluginAvailableVersions,
setValue,
versions,
]);

/*************************************************
* Handlers *
Expand Down Expand Up @@ -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}`,
{
Expand Down
12 changes: 6 additions & 6 deletions src/hooks/usePluginAvailableVersions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<pluginAvailableVersionsType | null>({
Expand Down
12 changes: 6 additions & 6 deletions src/hooks/usePreparedPlugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
Empty file.

0 comments on commit 840eb42

Please sign in to comment.