@ -6,7 +6,10 @@ import { FuncABI } from '@remix-project/core-plugin'
import { CopyToClipboard } from '@remix-ui/clipboard'
import { CopyToClipboard } from '@remix-ui/clipboard'
import * as remixLib from '@remix-project/remix-lib'
import * as remixLib from '@remix-project/remix-lib'
import * as ethJSUtil from '@ethereumjs/util'
import * as ethJSUtil from '@ethereumjs/util'
import axios from 'axios'
import { AppModal } from '@remix-ui/app'
import { ContractGUI } from './contractGUI'
import { ContractGUI } from './contractGUI'
import { SolScanTable } from './solScanTable'
import { TreeView , TreeViewItem } from '@remix-ui/tree-view'
import { TreeView , TreeViewItem } from '@remix-ui/tree-view'
import { BN } from 'bn.js'
import { BN } from 'bn.js'
import { CustomTooltip , is0XPrefixed , isHexadecimal , isNumeric , shortenAddress } from '@remix-ui/helper'
import { CustomTooltip , is0XPrefixed , isHexadecimal , isNumeric , shortenAddress } from '@remix-ui/helper'
@ -217,6 +220,100 @@ export function UniversalDappUI(props: UdappProps) {
setCalldataValue ( value )
setCalldataValue ( value )
}
}
const handleScanContinue = async ( ) = > {
await props . plugin . call ( 'notification' , 'toast' , 'Processing data to scan...' )
_paq . push ( [ 'trackEvent' , 'udapp' , 'solidityScan' , 'initiateScan' ] )
const workspace = await props . plugin . call ( 'filePanel' , 'getCurrentWorkspace' )
const fileName = props . instance . filePath || ` ${ workspace . name } / ${ props . instance . contractData . contract . file } `
const filePath = ` .workspaces/ ${ fileName } `
const file = await props . plugin . call ( 'fileManager' , 'readFile' , filePath )
const urlResponse = await axios . post ( ` https://solidityscan.remixproject.org/uploadFile ` , { file , fileName } )
if ( urlResponse . data . status === 'success' ) {
const ws = new WebSocket ( 'wss://solidityscan.remixproject.org/solidityscan' )
ws . addEventListener ( 'error' , console . error ) ;
ws . addEventListener ( 'open' , async ( event ) = > {
await props . plugin . call ( 'notification' , 'toast' , 'Initiating scan...' )
} )
ws . addEventListener ( 'message' , async ( event ) = > {
const data = JSON . parse ( event . data )
if ( data . type === "auth_token_register" && data . payload . message === "Auth token registered." ) {
// Message on Bearer token successful registration
const reqToInitScan = {
"action" : "message" ,
"payload" : {
"type" : "private_project_scan_initiate" ,
"body" : {
"file_urls" : [
urlResponse . data . result . url
] ,
"project_name" : "RemixProject" ,
"project_type" : "new"
}
}
}
ws . send ( JSON . stringify ( reqToInitScan ) )
} else if ( data . type === "scan_status" && data . payload . scan_status === "download_failed" ) {
// Message on failed scan
_paq . push ( [ 'trackEvent' , 'udapp' , 'solidityScan' , 'scanFailed' ] )
const modal : AppModal = {
id : 'SolidityScanError' ,
title : < FormattedMessage id = "udapp.solScan.errModalTitle" / > ,
message : data.payload.scan_status_err_message ,
okLabel : 'Close'
}
await props . plugin . call ( 'notification' , 'modal' , modal )
} else if ( data . type === "scan_status" && data . payload . scan_status === "scan_done" ) {
// Message on successful scan
_paq . push ( [ 'trackEvent' , 'udapp' , 'solidityScan' , 'scanSuccess' ] )
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
let modal : AppModal
if ( scanDetails && scanDetails . length ) {
modal = {
id : 'SolidityScanSuccess' ,
title : < FormattedMessage id = "udapp.solScan.successModalTitle" / > ,
message : < SolScanTable scanDetails = { scanDetails } fileName = { fileName } / > ,
okLabel : 'Close' ,
modalParentClass : 'modal-xl'
}
} else {
modal = {
id : 'SolidityScanError' ,
title : < FormattedMessage id = "udapp.solScan.errModalTitle" / > ,
message : "Some error occurred! Please try again" ,
okLabel : 'Close'
}
}
await props . plugin . call ( 'notification' , 'modal' , modal )
}
} )
}
}
const askPermissionToScan = async ( ) = > {
_paq . push ( [ 'trackEvent' , 'udapp' , 'solidityScan' , 'askPermissionToScan' ] )
const modal : AppModal = {
id : 'SolidityScanPermissionHandler' ,
title : < FormattedMessage id = "udapp.solScan.modalTitle" / > ,
message : < FormattedMessage id = "udapp.solScan.modalMessage" / > ,
okLabel : < FormattedMessage id = "udapp.solScan.modalOkLabel" / > ,
okFn : handleScanContinue ,
cancelLabel : < FormattedMessage id = "udapp.solScan.modalCancelLabel" / >
}
await props . plugin . call ( 'notification' , 'modal' , modal )
}
const label = ( key : string | number , value : string ) = > {
const label = ( key : string | number , value : string ) = > {
return (
return (
< div className = "d-flex mt-2 flex-row label_item" >
< div className = "d-flex mt-2 flex-row label_item" >
@ -293,20 +390,26 @@ export function UniversalDappUI(props: UdappProps) {
< / div >
< / div >
< div className = "udapp_cActionsWrapper" data - id = "universalDappUiContractActionWrapper" >
< div className = "udapp_cActionsWrapper" data - id = "universalDappUiContractActionWrapper" >
< div className = "udapp_contractActionsContainer" >
< div className = "udapp_contractActionsContainer" >
< div className = "d-flex justify-content-between" data - id = "instanceContractBal" >
< div className = "d-flex flex-row justify-content-between align-items-center pb-2 " data - id = "instanceContractBal" >
< label >
< span className = "remixui_runtabBalance label run-tab" >
< b > < FormattedMessage id = "udapp.balance" / > : < / b > { instanceBalance } ETH
< b > < FormattedMessage id = "udapp.balance" / > : < / b > { instanceBalance } ETH
< / label >
< / span >
{ props . exEnvironment && props . exEnvironment . startsWith ( 'injected' ) && (
< div > < / div >
< CustomTooltip placement = "top" tooltipClasses = "text-nowrap" tooltipId = "udapp_udappEditTooltip" tooltipText = { < FormattedMessage id = "udapp.tooltipTextEdit" / > } >
< div className = "d-flex align-self-center" >
< i
{ props . exEnvironment && props . exEnvironment . startsWith ( 'injected' ) && (
className = "fas fa-edit btn btn-sm p-0"
< CustomTooltip placement = "top" tooltipClasses = "text-nowrap" tooltipId = "udapp_udappEditTooltip" tooltipText = { < FormattedMessage id = "udapp.tooltipTextEdit" / > } >
onClick = { ( ) = > {
< i
props . editInstance ( props . instance )
className = "fas fa-edit pr-3"
} }
onClick = { ( ) = > {
> < / i >
props . editInstance ( props . instance )
} }
> < / i >
< / CustomTooltip >
) }
< CustomTooltip placement = "top" tooltipClasses = "text-nowrap" tooltipId = "udapp_udappSolScanTooltip" tooltipText = { < FormattedMessage id = "udapp.solScan.iconTooltip" / > } >
< i className = "fas fa-qrcode p-0" onClick = { askPermissionToScan } > < / i >
< / CustomTooltip >
< / CustomTooltip >
) }
< / div >
< / div >
< / div >
{ props . isPinnedContract && props . instance . pinnedAt ? (
{ props . isPinnedContract && props . instance . pinnedAt ? (
< div className = "d-flex" data - id = "instanceContractPinnedAt" >
< div className = "d-flex" data - id = "instanceContractPinnedAt" >