diff --git a/types/api/contract.ts b/types/api/contract.ts index 845aa84b32..6918684841 100644 --- a/types/api/contract.ts +++ b/types/api/contract.ts @@ -104,29 +104,32 @@ export interface SmartContractVerificationError { name?: Array; } +// it's an external API proxy, we can't guarantee the responce types export type SolidityscanReport = { - scan_report: { - contractname: string; - scan_status: string; - scan_summary: { - issue_severity_distribution: { - critical: number; - gas: number; - high: number; - informational: number; - low: number; - medium: number; - }; - lines_analyzed_count: number; - scan_time_taken: number; - score: string; - score_v2: string; - threat_score: string; + scan_report?: { + contractname?: string; + scan_status?: string; + scan_summary?: { + issue_severity_distribution?: SolidityscanReportSeverityDistribution; + lines_analyzed_count?: number; + scan_time_taken?: number; + score?: string; + score_v2?: string; + threat_score?: string; }; - scanner_reference_url: string; + scanner_reference_url?: string; }; } +export type SolidityscanReportSeverityDistribution = { + critical?: number; + gas?: number; + high?: number; + informational?: number; + low?: number; + medium?: number; +}; + type SmartContractSecurityAudit = { audit_company_name: string; audit_publish_date: string; diff --git a/types/client/marketplace.ts b/types/client/marketplace.ts index 9b34c46206..368321bed6 100644 --- a/types/client/marketplace.ts +++ b/types/client/marketplace.ts @@ -1,4 +1,4 @@ -import type { SolidityscanReport } from 'types/api/contract'; +import type { SolidityscanReport, SolidityscanReportSeverityDistribution } from 'types/api/contract'; export type MarketplaceAppPreview = { id: string; @@ -54,7 +54,7 @@ export type MarketplaceAppSecurityReport = { solidityScanContractsNumber: number; securityScore: number; totalIssues?: number; - issueSeverityDistribution: SolidityscanReport['scan_report']['scan_summary']['issue_severity_distribution']; + issueSeverityDistribution: SolidityscanReportSeverityDistribution; }; contractsData: Array<{ address: string; diff --git a/ui/address/SolidityscanReport.tsx b/ui/address/SolidityscanReport.tsx index 78eef956c1..2d685b1651 100644 --- a/ui/address/SolidityscanReport.tsx +++ b/ui/address/SolidityscanReport.tsx @@ -29,13 +29,17 @@ const SolidityscanReport = ({ hash }: Props) => { }, }); - const score = Number(data?.scan_report.scan_summary.score_v2); + if (isError || !data?.scan_report?.scan_summary) { + return null; + } + + const score = Number(data.scan_report.scan_summary.score_v2); - if (isError || !score) { + if (!score) { return null; } - const vulnerabilities = data?.scan_report.scan_summary.issue_severity_distribution; + const vulnerabilities = data.scan_report.scan_summary.issue_severity_distribution; const vulnerabilitiesCounts = vulnerabilities ? Object.values(vulnerabilities) : []; const vulnerabilitiesCount = vulnerabilitiesCounts.reduce((acc, val) => acc + val, 0); diff --git a/ui/marketplace/ContractListModal.tsx b/ui/marketplace/ContractListModal.tsx index ec13977ba3..20508cd2f7 100644 --- a/ui/marketplace/ContractListModal.tsx +++ b/ui/marketplace/ContractListModal.tsx @@ -42,7 +42,7 @@ const ContractListModal = ({ onClose, onBack, type, contracts }: Props) => { return contracts .filter((contract) => Boolean(contract.solidityScanReport)) .sort((a, b) => - (parseFloat(b.solidityScanReport?.scan_summary.score_v2 ?? '0')) - (parseFloat(a.solidityScanReport?.scan_summary.score_v2 ?? '0')), + (parseFloat(b.solidityScanReport?.scan_summary?.score_v2 ?? '0')) - (parseFloat(a.solidityScanReport?.scan_summary?.score_v2 ?? '0')), ); case ContractListTypes.VERIFIED: return contracts.filter((contract) => contract.isVerified); diff --git a/ui/marketplace/ContractSecurityReport.tsx b/ui/marketplace/ContractSecurityReport.tsx index 5bf9f89ac5..7577d14eb5 100644 --- a/ui/marketplace/ContractSecurityReport.tsx +++ b/ui/marketplace/ContractSecurityReport.tsx @@ -27,7 +27,7 @@ const ContractSecurityReport = ({ securityReport }: Props) => { onToggle(); }, [ onToggle ]); - if (!securityReport) { + if (!securityReport?.scan_summary?.score_v2) { return null; } diff --git a/ui/shared/solidityscanReport/SolidityscanReportDetails.tsx b/ui/shared/solidityscanReport/SolidityscanReportDetails.tsx index 2d2a5cf140..0ab151ea1c 100644 --- a/ui/shared/solidityscanReport/SolidityscanReportDetails.tsx +++ b/ui/shared/solidityscanReport/SolidityscanReportDetails.tsx @@ -1,10 +1,10 @@ import { Box, Flex, Text, Grid, useColorModeValue, chakra } from '@chakra-ui/react'; import React from 'react'; -import type { SolidityscanReport } from 'types/api/contract'; +import type { SolidityscanReportSeverityDistribution } from 'types/api/contract'; type DistributionItem = { - id: keyof SolidityscanReport['scan_report']['scan_summary']['issue_severity_distribution']; + id: keyof SolidityscanReportSeverityDistribution; name: string; color: string; } @@ -19,29 +19,34 @@ const DISTRIBUTION_ITEMS: Array = [ ]; interface Props { - vulnerabilities: SolidityscanReport['scan_report']['scan_summary']['issue_severity_distribution']; + vulnerabilities: SolidityscanReportSeverityDistribution; vulnerabilitiesCount: number; } type ItemProps = { item: DistributionItem; - vulnerabilities: SolidityscanReport['scan_report']['scan_summary']['issue_severity_distribution']; + vulnerabilities: SolidityscanReportSeverityDistribution; vulnerabilitiesCount: number; } const SolidityScanReportItem = ({ item, vulnerabilities, vulnerabilitiesCount }: ItemProps) => { const bgBar = useColorModeValue('blackAlpha.50', 'whiteAlpha.50'); const yetAnotherGrayColor = useColorModeValue('gray.400', 'gray.500'); + const vulnerability = vulnerabilities[item.id]; + + if (vulnerability === undefined) { + return null; + } return ( <> { item.name } - 0 ? 'text' : yetAnotherGrayColor }>{ vulnerabilities[item.id] } + 0 ? 'text' : yetAnotherGrayColor }>{ vulnerabilities[item.id] } - + );