11import React from "react" ;
22import { CenteringBox , DataBox } from "./Common.styled" ;
33import { useFileStore } from "../lib/useFileStore" ;
4- import { useSubmitSources } from "../lib/useSubmitSources" ;
4+ import {
5+ DEFAULT_VERIFIER ,
6+ useSubmitSources ,
7+ useSubmitSourcesEntries ,
8+ } from "../lib/useSubmitSources" ;
59import { FileUploaderArea } from "./FileUploaderArea" ;
610import { FileTable } from "./FileTable" ;
711import CompilerSettings from "./CompilerSettings" ;
@@ -12,27 +16,97 @@ import { SECTIONS, STEPS, usePublishStore } from "../lib/usePublishSteps";
1216import { CircularProgress , Fade } from "@mui/material" ;
1317import { useTonAddress } from "@tonconnect/ui-react" ;
1418import ConnectButton from "./ConnectButton" ;
19+ import { VerifierWithId } from "../lib/wrappers/verifier-registry" ;
20+ import { ContractProofData } from "../lib/useLoadContractProof" ;
1521
1622const ContentBox = styled ( Box ) ( {
1723 padding : "15px 24px" ,
1824} ) ;
1925
20- export function AddSourcesBlock ( { contractAddress } : { contractAddress : string } ) {
26+ const PrefillButtonWrapper = styled ( Box ) ( {
27+ position : "absolute" ,
28+ top : 12 ,
29+ right : 12 ,
30+ zIndex : 2 ,
31+ } ) ;
32+
33+ type AddSourcesBlockProps = {
34+ contractAddress : string ;
35+ missingVerifiers ?: VerifierWithId [ ] ;
36+ availableProof ?: ContractProofData ;
37+ } ;
38+
39+ export function AddSourcesBlock ( {
40+ contractAddress,
41+ missingVerifiers = [ ] ,
42+ availableProof,
43+ } : AddSourcesBlockProps ) {
2144 const walletAddress = useTonAddress ( ) ;
22- const { hasFiles } = useFileStore ( ) ;
45+ const { hasFiles, addFiles , reset : resetFiles } = useFileStore ( ) ;
2346 const { step, proceedToPublish, toggleSection, currentSection } = usePublishStore ( ) ;
24- const { mutate, data, error, isLoading, compileStatus } = useSubmitSources ( contractAddress ) ;
47+ const activeVerifierName = missingVerifiers [ 0 ] ?. name ?? DEFAULT_VERIFIER ;
48+ const { mutate, data, error, isLoading } = useSubmitSources ( contractAddress , activeVerifierName ) ;
49+ const entries = useSubmitSourcesEntries ( contractAddress ) ;
2550
26- const canPublish = ! ! data ?. result ?. msgCell ;
51+ const readyPublishCount = missingVerifiers . length
52+ ? missingVerifiers . filter ( ( verifier ) => entries [ verifier . name ] ?. data ?. result ?. msgCell ) . length
53+ : data ?. result ?. msgCell
54+ ? 1
55+ : 0 ;
56+ const canPublish = readyPublishCount > 0 ;
2757
2858 const onSectionExpand = ( ) => toggleSection ( SECTIONS . SOURCES ) ;
2959
60+ const canPrefill = ! ! availableProof ?. files ?. length ;
61+
62+ const handlePrefill = async ( ) => {
63+ if ( ! availableProof ?. files ?. length ) return ;
64+ resetFiles ( ) ;
65+
66+ const generatedFiles = availableProof . files . map ( ( file ) => {
67+ const segments = file . name . split ( "/" ) ;
68+ const baseName = segments . pop ( ) ?? file . name ;
69+ const generated = new File ( [ file . content ] , baseName , { type : "text/plain" } ) ;
70+ const normalizedPath = segments . length > 0 ? `${ segments . join ( "/" ) } /${ baseName } ` : baseName ;
71+ Object . defineProperty ( generated , "path" , {
72+ value : normalizedPath ,
73+ configurable : true ,
74+ } ) ;
75+ return generated ;
76+ } ) ;
77+
78+ await addFiles ( generatedFiles ) ;
79+ } ;
80+
81+ const compileVerifiers =
82+ missingVerifiers . length > 0 ? missingVerifiers . map ( ( verifier ) => verifier . name ) : undefined ;
83+
3084 return (
3185 < DataBox >
3286 < Box
3387 sx = { { cursor : step === STEPS . PUBLISH && canPublish ? "pointer" : "inherit" } }
3488 onClick = { onSectionExpand } >
35- < FileUploaderArea />
89+ < Box sx = { { position : "relative" } } >
90+ < FileUploaderArea />
91+ { canPrefill && (
92+ < PrefillButtonWrapper
93+ onClick = { ( event ) => {
94+ event . stopPropagation ( ) ;
95+ } } >
96+ < AppButton
97+ fontSize = { 12 }
98+ fontWeight = { 600 }
99+ textColor = "#000"
100+ height = { 32 }
101+ width = { 180 }
102+ background = "#fff"
103+ hoverBackground = "#F5F5F5"
104+ onClick = { handlePrefill } >
105+ Load verified sources
106+ </ AppButton >
107+ </ PrefillButtonWrapper >
108+ ) }
109+ </ Box >
36110 </ Box >
37111 { currentSection === SECTIONS . SOURCES && (
38112 < Fade in = { currentSection === SECTIONS . SOURCES } >
@@ -60,7 +134,13 @@ export function AddSourcesBlock({ contractAddress }: { contractAddress: string }
60134 background = "#1976d2"
61135 hoverBackground = "#156cc2"
62136 onClick = { ( ) => {
63- mutate ( null ) ;
137+ mutate (
138+ compileVerifiers
139+ ? {
140+ verifiers : compileVerifiers ,
141+ }
142+ : null ,
143+ ) ;
64144 } } >
65145 { isLoading && (
66146 < CircularProgress
0 commit comments