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 showing warnings #1849

Merged
merged 5 commits into from
Feb 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { continueIfCalleDisconnected } from "api/utils";
import { enableAutoUpdatesForPackageWithConfirm } from "pages/system/components/AutoUpdates";
import Warnings from "./Steps/Warnings";
import { RequestedDnp, UserSettingsAllDnps } from "@dappnode/types";
import { diff } from "semver";

interface InstallDnpViewProps {
dnp: RequestedDnp;
Expand Down Expand Up @@ -62,15 +63,15 @@ const InstallDnpView: React.FC<InstallDnpViewProps> = ({
const {
dnpName,
reqVersion,
semVersion,
settings,
manifest,
setupWizard,
isInstalled
isInstalled,
installedVersion
} = dnp;
const isWarningUpdate =
manifest.warnings?.onMajorUpdate ||
manifest.warnings?.onMinorUpdate ||
manifest.warnings?.onPatchUpdate;
const updateType = installedVersion && diff(installedVersion, semVersion);
console.log("updateType", updateType);
const isCore = manifest.type === "dncore";
const permissions = dnp.specialPermissions;
const hasPermissions = Object.values(permissions).some(p => p.length > 0);
Expand Down Expand Up @@ -239,10 +240,10 @@ const InstallDnpView: React.FC<InstallDnpViewProps> = ({
goBack={goBack}
warnings={manifest.warnings || {}}
isInstalled={isInstalled}
updateType={updateType}
/>
),
available:
manifest.warnings?.onInstall || (isInstalled && isWarningUpdate)
available: manifest.warnings?.onInstall || (isInstalled && updateType)
},
{
name: "Disclaimer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ import { RequestedDnp } from "@dappnode/types";
import { Manifest } from "@dappnode/types";
import RenderMarkdown from "components/RenderMarkdown";
import Button from "components/Button";
import { ReleaseType } from "semver";

export default function Warnings({
goNext,
goBack,
warnings,
isInstalled
isInstalled,
updateType
}: {
goNext: () => void;
goBack: () => void;
warnings: Manifest["warnings"];
isInstalled: RequestedDnp["isInstalled"];
updateType?: ReleaseType | null | "";
}) {
if (!warnings)
return (
Expand All @@ -25,7 +28,7 @@ export default function Warnings({

return (
<Card>
{warnings.onInstall && (
{isInstalled && warnings.onInstall ? (
<div>
<div className="card-section-header">
<span>
Expand All @@ -36,8 +39,7 @@ export default function Warnings({
<RenderMarkdown source={warnings.onInstall} />
</div>
</div>
)}
{isInstalled && warnings.onPatchUpdate && (
) : updateType === "patch" && warnings.onPatchUpdate ? (
<div>
<div className="card-section-header">
<span>
Expand All @@ -48,8 +50,7 @@ export default function Warnings({
<RenderMarkdown source={warnings.onPatchUpdate} />
</div>
</div>
)}
{isInstalled && warnings.onMinorUpdate && (
) : updateType === "minor" && warnings.onMinorUpdate ? (
<div>
<div className="card-section-header">
<span>
Expand All @@ -60,8 +61,7 @@ export default function Warnings({
<RenderMarkdown source={warnings.onMinorUpdate} />
</div>
</div>
)}
{isInstalled && warnings.onMajorUpdate && (
) : updateType === "major" && warnings.onMajorUpdate ? (
<div>
<div className="card-section-header">
<span>
Expand All @@ -72,7 +72,7 @@ export default function Warnings({
<RenderMarkdown source={warnings.onMajorUpdate} />
</div>
</div>
)}
) : null}

<div className="button-group">
<Button onClick={goBack}>Back</Button>
Expand Down
8 changes: 8 additions & 0 deletions packages/dappmanager/src/calls/fetchDnpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export async function fetchDnpRequest({
imageSize: mainRelease.imageFile.size,
isUpdated: getIsUpdated(mainRelease, dnpList),
isInstalled: getIsInstalled(mainRelease, dnpList),
installedVersion: getInstalledVersion(mainRelease, dnpList),
// Prevent sending duplicated data
manifest: omit(mainRelease.manifest, ["setupWizard"]),
specialPermissions, // Decoupled metadata
Expand Down Expand Up @@ -214,3 +215,10 @@ function getReleaseSignedSafeMessage(release: PackageRelease): string {
}
}
}

function getInstalledVersion(
{ dnpName }: { dnpName: string },
dnpList: InstalledPackageData[]
): string | undefined {
return dnpList.find(dnp => dnp.dnpName === dnpName)?.version;
}
1 change: 1 addition & 0 deletions packages/types/src/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export interface RequestedDnp {
imageSize: number;
isUpdated: boolean;
isInstalled: boolean;
installedVersion?: string;
// Decoupled metadata
manifest: Manifest;
specialPermissions: SpecialPermissionAllDnps;
Expand Down
Loading