-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from ethereum-optimism/11-20-feat_hook_up_depl…
…oy_wizard feat: hook up deploy wizard
- Loading branch information
Showing
30 changed files
with
623 additions
and
684 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import {Wizard} from '@/wizard/Wizard'; | ||
import {DeployCreate2Wizard} from '@/deploy-create2-wizard/DeployCreate2Wizard'; | ||
|
||
const Index = () => { | ||
return <Wizard onSubmit={form => console.log(form)} />; | ||
return <DeployCreate2Wizard />; | ||
}; | ||
|
||
export default Index; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/cli/src/deploy-create2-wizard/ConfigureConstructorArguments.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {useDeployCreate2WizardStore} from '@/deploy-create2-wizard/deployCreate2WizardStore'; | ||
import {getConstructorAbi} from '@/utils/abi'; | ||
import {Box} from 'ink'; | ||
import {AbiItemForm} from '@/deploy-create2-wizard/AbiItemForm'; | ||
import {getArtifactPathForContract} from '@/forge/foundryProject'; | ||
import {useForgeArtifact} from '@/queries/forgeArtifact'; | ||
import {Spinner} from '@inkjs/ui'; | ||
|
||
export const ConfigureConstructorArguments = () => { | ||
const {wizardState, submitConfigureConstructorArguments} = | ||
useDeployCreate2WizardStore(); | ||
|
||
if (wizardState.stepId !== 'configure-constructor-arguments') { | ||
throw new Error('Invalid state'); | ||
} | ||
|
||
const path = getArtifactPathForContract( | ||
wizardState.foundryProjectPath, | ||
wizardState.selectedContract, | ||
); | ||
|
||
const {data: artifact, isLoading} = useForgeArtifact(path); | ||
|
||
if (isLoading || !artifact) { | ||
return ( | ||
<Box flexDirection="column"> | ||
<Spinner label="Loading artifact..." /> | ||
</Box> | ||
); | ||
} | ||
|
||
const constructorAbi = getConstructorAbi(artifact.abi); | ||
|
||
if (!constructorAbi) { | ||
throw new Error('No constructor ABI found'); | ||
} | ||
|
||
return ( | ||
<Box flexDirection="column"> | ||
<AbiItemForm | ||
abiItem={constructorAbi} | ||
onSubmit={result => { | ||
// TODO fix type | ||
submitConfigureConstructorArguments({constructorArgs: result}); | ||
}} | ||
/> | ||
</Box> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {useDeployCreate2WizardStore} from '@/deploy-create2-wizard/deployCreate2WizardStore'; | ||
import {Box, Text} from 'ink'; | ||
import {TextInput} from '@inkjs/ui'; | ||
export const ConfigureSalt = () => { | ||
const {wizardState, submitConfigureSalt} = useDeployCreate2WizardStore(); | ||
|
||
if (wizardState.stepId !== 'configure-salt') { | ||
throw new Error('Invalid state'); | ||
} | ||
|
||
return ( | ||
<Box flexDirection="column"> | ||
<Box> | ||
<Text>Enter a salt value (press Enter to confirm):</Text> | ||
</Box> | ||
<TextInput | ||
onSubmit={salt => submitConfigureSalt({salt})} | ||
defaultValue={'ethers phoenix'} | ||
/> | ||
</Box> | ||
); | ||
}; |
140 changes: 140 additions & 0 deletions
140
packages/cli/src/deploy-create2-wizard/DeployCreate2Wizard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { | ||
deployCreate2WizardIndexByStepId, | ||
DeployCreate2WizardStepId, | ||
useDeployCreate2WizardStore, | ||
} from '@/deploy-create2-wizard/deployCreate2WizardStore'; | ||
import {Box, Text} from 'ink'; | ||
import {EnterFoundryProjectPath} from '@/deploy-create2-wizard/EnterFoundryProjectPath'; | ||
import {SelectContract} from '@/deploy-create2-wizard/SelectContract'; | ||
import {ConfigureConstructorArguments} from '@/deploy-create2-wizard/ConfigureConstructorArguments'; | ||
import {ConfigureSalt} from '@/deploy-create2-wizard/ConfigureSalt'; | ||
import {SelectNetwork} from '@/deploy-create2-wizard/SelectNetwork'; | ||
import {SelectChains} from '@/deploy-create2-wizard/SelectChains'; | ||
import {EnterPrivateKey} from '@/deploy-create2-wizard/EnterPrivateKey'; | ||
import DeployCreate2Command from '@/commands/deploy/create2'; | ||
import {getArtifactPathForContract} from '@/forge/foundryProject'; | ||
|
||
type StepStatus = 'done' | 'current' | 'upcoming'; | ||
|
||
type StepProgress = { | ||
status: StepStatus; | ||
title: string; | ||
summary?: string; | ||
}; | ||
|
||
const useStepProgress = ({ | ||
stepId, | ||
}: { | ||
stepId: DeployCreate2WizardStepId; | ||
}): StepProgress => { | ||
const {steps, wizardState} = useDeployCreate2WizardStore(); | ||
|
||
const currentIndex = deployCreate2WizardIndexByStepId[wizardState.stepId]; | ||
const stepIndex = deployCreate2WizardIndexByStepId[stepId]; | ||
|
||
const step = steps[stepIndex]!; | ||
|
||
if (stepIndex < currentIndex) { | ||
return { | ||
status: 'done' as const, | ||
title: step.title, | ||
summary: step.getSummary | ||
? step.getSummary(wizardState as unknown as any) | ||
: undefined, | ||
}; | ||
} | ||
|
||
if (stepIndex === currentIndex) { | ||
return { | ||
status: 'current' as const, | ||
title: step.title, | ||
}; | ||
} | ||
|
||
return { | ||
status: 'upcoming' as const, | ||
title: step.title, | ||
}; | ||
}; | ||
|
||
const WizardProgressForStep = ({ | ||
stepId, | ||
}: { | ||
stepId: DeployCreate2WizardStepId; | ||
}) => { | ||
const {status, title, summary} = useStepProgress({stepId}); | ||
|
||
return ( | ||
<Box gap={1} paddingX={1}> | ||
<Text | ||
color={ | ||
status === 'done' ? 'green' : status === 'current' ? 'blue' : 'gray' | ||
} | ||
> | ||
{status === 'done' ? '✓' : status === 'current' ? '>' : '○'} | ||
</Text> | ||
<Text color={status === 'current' ? 'blue' : 'white'}> {title}</Text> | ||
{status === 'done' && summary && <Text color="yellow">{summary}</Text>} | ||
</Box> | ||
); | ||
}; | ||
|
||
const WizardProgress = () => { | ||
const {steps, wizardState} = useDeployCreate2WizardStore(); | ||
if (wizardState.stepId === 'completed') { | ||
return ( | ||
<Box> | ||
<Text>Completed</Text> | ||
</Box> | ||
); | ||
} | ||
return ( | ||
<Box flexDirection="column"> | ||
{steps.map(({id}) => { | ||
return <WizardProgressForStep stepId={id} key={id} />; | ||
})} | ||
</Box> | ||
); | ||
}; | ||
|
||
export const DeployCreate2Wizard = () => { | ||
const {wizardState} = useDeployCreate2WizardStore(); | ||
|
||
const stepId = wizardState.stepId; | ||
|
||
if (stepId === 'completed') { | ||
return ( | ||
<DeployCreate2Command | ||
options={{ | ||
chains: wizardState.chainNames, | ||
privateKey: wizardState.privateKey, | ||
salt: wizardState.salt, | ||
forgeArtifactPath: getArtifactPathForContract( | ||
wizardState.foundryProjectPath, | ||
wizardState.selectedContract, | ||
), | ||
constructorArgs: wizardState.constructorArgs.join(','), | ||
network: wizardState.network, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<Box flexDirection="column" gap={1}> | ||
<Text bold color="blue"> | ||
🚀 Deploy Create2 Wizard | ||
</Text> | ||
<WizardProgress /> | ||
{stepId === 'enter-foundry-project-path' && <EnterFoundryProjectPath />} | ||
{stepId === 'select-contract' && <SelectContract />} | ||
{stepId === 'configure-constructor-arguments' && ( | ||
<ConfigureConstructorArguments /> | ||
)} | ||
{stepId === 'configure-salt' && <ConfigureSalt />} | ||
{stepId === 'select-network' && <SelectNetwork />} | ||
{stepId === 'select-chains' && <SelectChains />} | ||
{stepId === 'enter-private-key' && <EnterPrivateKey />} | ||
</Box> | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
packages/cli/src/deploy-create2-wizard/EnterFoundryProjectPath.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {useDeployCreate2WizardStore} from '@/deploy-create2-wizard/deployCreate2WizardStore'; | ||
import {Box, Text} from 'ink'; | ||
import {TextInput} from '@inkjs/ui'; | ||
|
||
export const EnterFoundryProjectPath = () => { | ||
const {wizardState, submitEnterFoundryProjectPath} = | ||
useDeployCreate2WizardStore(); | ||
|
||
if (wizardState.stepId !== 'enter-foundry-project-path') { | ||
throw new Error('Invalid state'); | ||
} | ||
|
||
return ( | ||
<Box flexDirection="column"> | ||
<Box> | ||
<Text>Enter the path to your foundry project:</Text> | ||
</Box> | ||
<TextInput | ||
onSubmit={foundryProjectPath => | ||
submitEnterFoundryProjectPath({ | ||
foundryProjectPath: foundryProjectPath.trim(), | ||
}) | ||
} | ||
/> | ||
</Box> | ||
); | ||
}; |
Oops, something went wrong.