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

Show Solidity Scan Summary #4969

Merged
merged 4 commits into from
Jul 9, 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
10 changes: 5 additions & 5 deletions libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useState, useEffect} from 'react' // eslint-disable-line
import { FormattedMessage, useIntl } from 'react-intl'
import { ContractPropertyName, ContractSelectionProps } from './types'
import { ContractPropertyName, ContractSelectionProps, ScanReport } from './types'
import {PublishToStorage} from '@remix-ui/publish-to-storage' // eslint-disable-line
import {TreeView, TreeViewItem} from '@remix-ui/tree-view' // eslint-disable-line
import {CopyToClipboard} from '@remix-ui/clipboard' // eslint-disable-line
Expand Down Expand Up @@ -312,10 +312,10 @@ export const ContractSelection = (props: ContractSelectionProps) => {
const url = data.payload.scan_details.link

const { data: scanData } = await axios.post('https://solidityscan.remixproject.org/downloadResult', { url })
const scanDetails: Record<string, any>[] = scanData.scan_report.multi_file_scan_details
const scanReport: ScanReport = scanData.scan_report

if (scanDetails && scanDetails.length) {
await plugin.call('terminal', 'logHtml', <SolScanTable scanDetails={scanDetails} fileName={fileName}/>)
if (scanReport?.multi_file_scan_details?.length) {
await plugin.call('terminal', 'logHtml', <SolScanTable scanReport={scanReport} fileName={fileName}/>)
} else {
const modal: AppModal = {
id: 'SolidityScanError',
Expand All @@ -338,7 +338,7 @@ export const ContractSelection = (props: ContractSelectionProps) => {
title: <FormattedMessage id="solidity.solScan.modalTitle" />,
message: <div className='d-flex flex-column'>
<span><FormattedMessage id="solidity.solScan.modalMessage" />
<a href={'https://solidityscan.com'}
<a href={'https://solidityscan.com/?utm_campaign=remix&utm_source=remix'}
target="_blank"
onClick={() => _paq.push(['trackEvent', 'solidityCompiler', 'solidityScan', 'learnMore'])}>
Learn more
Expand Down
31 changes: 21 additions & 10 deletions libs/remix-ui/solidity-compiler/src/lib/solScanTable.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
// eslint-disable-next-line no-use-before-define
import React from 'react'
import parse from 'html-react-parser'
import { ScanReport } from './types'
const _paq = (window._paq = window._paq || [])

interface SolScanTableProps {
scanDetails: Record<string, any>[],
scanReport: ScanReport
fileName: string
}

export function SolScanTable(props: SolScanTableProps) {
const { scanDetails, fileName } = props
const { scanReport, fileName } = props
const { multi_file_scan_details, multi_file_scan_summary } = scanReport

return (
<>
<br/>
<h6>SolidityScan result for <b>{fileName}</b>:</h6>
<p className='text-success'><b>{scanDetails.length} warnings </b> found. See the warning details below. For more details,&nbsp;
<a href="https://solidityscan.com/signup"
target='_blank'
onClick={() => _paq.push(['trackEvent', 'solidityCompiler', 'solidityScan', 'goToSolidityScan'])}>
go to SolidityScan.
</a>
</p>
<table className="table table-bordered table-hover">
<thead>
<tr>
Expand All @@ -35,7 +30,7 @@ export function SolScanTable(props: SolScanTableProps) {
</thead>
<tbody>
{
Array.from(scanDetails, (template, index) => {
Array.from(multi_file_scan_details, (template, index) => {
return (
<tr key={template.template_details.issue_id}>
<td scope="col">{index + 1}.</td>
Expand All @@ -51,6 +46,22 @@ export function SolScanTable(props: SolScanTableProps) {

</tbody>
</table>

{ multi_file_scan_summary ? (
<>
<p className='text-success'><b>Scan Summary: </b></p>
<p>&emsp; Lines Analyzed: {multi_file_scan_summary.lines_analyzed_count}</p>
<p>&emsp; Scan Score: {multi_file_scan_summary.score_v2}</p>
<p>&emsp; Issue Distribution: { JSON.stringify(multi_file_scan_summary.issue_severity_distribution, null, 1)} </p>
<p>For more details,&nbsp;
<a href="https://solidityscan.com/?utm_campaign=remix&utm_source=remix"
target='_blank'
onClick={() => _paq.push(['trackEvent', 'solidityCompiler', 'solidityScan', 'goToSolidityScan'])}>
go to SolidityScan.
</a>
</p>
</>
): null}
</>
)
}
34 changes: 34 additions & 0 deletions libs/remix-ui/solidity-compiler/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@ import { ICompilerApi, ConfigurationSettings, iSolJsonBinData } from '@remix-pro
import { CompileTabLogic } from '../logic/compileTabLogic'
export type onCurrentFileChanged = (fileName: string) => void

//// SolidityScan Types

export interface ScanTemplate {
issue_id: string
issue_name: string
issue_remediation?: string
issue_severity: string
issue_status: string
static_issue_description: string
issue_description?: string
issue_confidence: string
metric_wise_aggregated_findings?: Record<string, any>[]
}

export interface ScanDetails {
issue_id: string
no_of_findings: string
template_details: ScanTemplate
}

export interface ScanReport {
details_enabled: boolean
file_url_list: string[]
multi_file_scan_details: ScanDetails[]
multi_file_scan_summary: Record<string, any>
multi_file_scan_status: string
scan_id: string
scan_status: string
scan_type: string
// others
}

//// SolidityScan Types

export interface SolidityCompilerProps {
api: ICompilerApi
}
Expand Down
Loading