@@ -4,9 +4,11 @@ import * as erc20 from '../contractCode/erc20'
44import * as erc721 from '../contractCode/erc721'
55import * as erc1155 from '../contractCode/erc1155'
66import { AccessControlType , ContractTypeStrategy , ContractWizardAction } from '../../types/template-explorer-types'
7- import { contractWizardReducer } from '../../reducers/contract-wizard-reducer'
87import { getErc1155ContractCode , getErc20ContractCode , getErc721ContractCode } from '../utils/contractWizardUtils'
98import { TemplateExplorerContext } from '../../context/template-explorer-context'
9+ import { CustomTooltip } from '@remix-ui/helper'
10+ import { OverlayTrigger , Tooltip } from 'react-bootstrap'
11+ import { TemplateExplorerModalFacade } from '../utils/workspaceUtils'
1012
1113const defaultStrategy : ContractTypeStrategy = {
1214 contractType : 'erc20' ,
@@ -26,16 +28,8 @@ const defaultStrategy: ContractTypeStrategy = {
2628}
2729
2830export function ContractWizard ( ) {
29- const [ tokenName , setTokenName ] = useState ( 'MyToken' )
30-
31- const [ accessControl , setAccessControl ] = useState < 'ownable' | 'roles' | 'managed' | '' > ( '' )
32- const [ upgradability , setUpgradability ] = useState ( {
33- uups : false ,
34- transparent : false
35- } )
36- const [ initGit , setInitGit ] = useState ( false )
3731 const [ showEditModal , setShowEditModal ] = useState ( false )
38- const { state, dispatch } = useContext ( TemplateExplorerContext )
32+ const { state, dispatch, theme , makeWorkspace } = useContext ( TemplateExplorerContext )
3933 const strategy = state
4034
4135 function toggleContractOption ( key : keyof typeof strategy . contractOptions ) {
@@ -58,10 +52,10 @@ export function ContractWizard () {
5852 }
5953 function updateContractName ( contractName : string ) {
6054 dispatch ( { type : ContractWizardAction . CONTRACT_NAME_UPDATE , payload : contractName } )
55+ dispatch ( { type : ContractWizardAction . TOKEN_NAME_UPDATE , payload : contractName } )
6156 }
6257
6358 useEffect ( ( ) => {
64- // console.log('strategy', strategy)
6559 if ( strategy . contractType === 'erc20' ) {
6660 dispatch ( { type : ContractWizardAction . CONTRACT_CODE_UPDATE , payload : getErc20ContractCode ( strategy . contractType , strategy ) } )
6761 } else if ( strategy . contractType === 'erc721' ) {
@@ -76,7 +70,9 @@ export function ContractWizard () {
7670 < div className = "row g-3" >
7771 < div className = "col-12 d-flex align-items-center justify-content-between" >
7872 < div className = "d-flex align-items-center gap-2" >
79- { showEditModal ? < input className = "form-control form-control-sm" value = { tokenName } onChange = { ( e ) => setTokenName ( e . target . value ) } /> : < span className = "fw-semibold" > { tokenName } </ span > }
73+ { showEditModal ? < input className = "form-control form-control-sm" value = { state . tokenName } onChange = { ( e ) => updateContractName ( e . target . value ) } /> : < span className = { `fw-semibold fs-6 ${ theme . currentTheme ( ) . name === 'Light' ? 'text-dark' : 'text-light' } ` } >
74+ { state . tokenName }
75+ </ span > }
8076 < i className = "fas fa-edit" onClick = { ( ) => setShowEditModal ( true ) } > </ i >
8177 </ div >
8278 < div className = "d-flex align-items-center gap-2" >
@@ -98,7 +94,7 @@ export function ContractWizard () {
9894 < div className = "mb-3" >
9995 < div className = "fw-semibold mb-2" > Contract settings</ div >
10096 < label className = "form-label text-uppercase small mb-1" > Token name</ label >
101- < input className = "form-control form-control-sm" placeholder = "My Token" value = { tokenName } onChange = { ( e ) => updateTokenName ( e . target . value ) } />
97+ < input className = "form-control form-control-sm" placeholder = "My Token" value = { state . tokenName } readOnly />
10298 </ div >
10399
104100 < div className = "mb-3" >
@@ -154,16 +150,30 @@ export function ContractWizard () {
154150 < Editor
155151 height = "460px"
156152 defaultLanguage = "typescript"
157- options = { { readOnly : true , minimap : { enabled : false } , theme : 'vs-dark' } }
153+ options = { { readOnly : true , minimap : { enabled : false } , theme : theme . currentTheme ( ) . name === 'Light' ? 'vs' : 'vs-dark' } }
158154 value = { strategy . contractCode as string }
159155 />
160156 </ div >
161157 < div className = "d-flex justify-content-between align-items-center gap-3 mt-3" >
162158 < div className = "form-check m-0" >
163- < input className = "form-check-input" type = "checkbox" id = "initGit" checked = { initGit } onChange = { ( e ) => setInitGit ( e . target . checked ) } />
164- < label className = "form-check-label" htmlFor = "initGit" > Initialize as a Git repository</ label >
159+ < >
160+ < input className = "form-check-input" type = "checkbox" id = "initGit" checked = { state . initializeAsGitRepo }
161+ onChange = { ( e ) => dispatch ( { type : ContractWizardAction . INITIALIZE_AS_GIT_REPO_UPDATE , payload : e . target . checked } ) } />
162+ < label className = "form-check-label" htmlFor = "initGit" > Initialize as a Git repository</ label >
163+ </ >
165164 </ div >
166- < button className = "btn btn-primary btn-sm" > Validate workspace</ button >
165+
166+ < button className = "btn btn-primary btn-sm" data-id = "validateWorkspaceButton" onClick = { async ( ) => {
167+ console . log ( 'about to create workspace' )
168+ await makeWorkspace . createWorkspace ( {
169+ workspaceName : state . workspaceTemplateChosen . displayName ,
170+ workspaceTemplateName : state . workspaceTemplateChosen . value ,
171+ opts : { mintable : state . contractOptions . mintable , burnable : state . contractOptions . burnable , pausable : state . contractOptions . pausable , uups : state . contractUpgradability . uups , transparent : state . contractUpgradability . transparent } ,
172+ isEmpty : false ,
173+ isGitRepo : state . initializeAsGitRepo ,
174+ createCommit : true
175+ } )
176+ } } > Validate workspace</ button >
167177 </ div >
168178 </ div >
169179 </ div >
0 commit comments