Skip to content

Commit

Permalink
Merge pull request #263 from NethermindEth/fix/deploy-ui-flow
Browse files Browse the repository at this point in the history
Fix Erratic UI Behavior: Deploy Tab Automatically Closes After Contract Deployment
  • Loading branch information
varex83 authored Sep 4, 2024
2 parents 387f80b + 2abe57b commit 0a347ca
Show file tree
Hide file tree
Showing 4 changed files with 394 additions and 296 deletions.
95 changes: 68 additions & 27 deletions plugin/src/atoms/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { atom } from 'jotai'
import { type CallDataObject, type Input } from '../utils/types/contracts'

export type Status = 'IDLE' | 'IN_PROGRESS' | 'ERROR' | 'DONE'
const isDeployingAtom = atom<boolean>(false)

const deployStatusAtom = atom<string>('')
const deployStatusAtom = atom<Status>('IDLE')

const isDelcaringAtom = atom<boolean>(false)

const declStatusAtom = atom<string>('')
const declStatusAtom = atom<Status>('IDLE')

const constructorCalldataAtom = atom<CallDataObject>({})

Expand All @@ -19,38 +20,78 @@ const declTxHashAtom = atom<string>('')

const deployTxHashAtom = atom<string>('')

type Key = 'isDeploying' | 'deployStatus' | 'isDeclaring' | 'declStatus' | 'constructorCalldata' | 'constructorInputs' | 'notEnoughInputs' | 'declTxHash' | 'deployTxHash'
type Key =
| 'isDeploying'
| 'deployStatus'
| 'isDeclaring'
| 'declStatus'
| 'constructorCalldata'
| 'constructorInputs'
| 'notEnoughInputs'
| 'declTxHash'
| 'deployTxHash'

interface SetDeploymentAtom {
key: Key
value: string | boolean | CallDataObject | Input[]
}

const deploymentAtom = atom((get) => {
return {
isDeploying: get(isDeployingAtom),
deployStatus: get(deployStatusAtom),
isDeclaring: get(isDelcaringAtom),
declStatus: get(declStatusAtom),
constructorCalldata: get(constructorCalldataAtom),
constructorInputs: get(constructorInputsAtom),
notEnoughInputs: get(notEnoughInputsAtom),
declTxHash: get(declTxHashAtom),
deployTxHash: get(deployTxHashAtom)
const deploymentAtom = atom(
(get) => {
return {
isDeploying: get(isDeployingAtom),
deployStatus: get(deployStatusAtom),
isDeclaring: get(isDelcaringAtom),
declStatus: get(declStatusAtom),
constructorCalldata: get(constructorCalldataAtom),
constructorInputs: get(constructorInputsAtom),
notEnoughInputs: get(notEnoughInputsAtom),
declTxHash: get(declTxHashAtom),
deployTxHash: get(deployTxHashAtom)
}
},
(_get, set, newValue: SetDeploymentAtom) => {
switch (newValue?.key) {
case 'isDeploying':
typeof newValue?.value === 'boolean' &&
set(isDeployingAtom, newValue?.value)
break
case 'deployStatus':
typeof newValue?.value === 'string' &&
set(deployStatusAtom, newValue?.value as Status)
break
case 'isDeclaring':
typeof newValue?.value === 'boolean' &&
set(isDelcaringAtom, newValue?.value)
break
case 'declStatus':
typeof newValue?.value === 'string' &&
set(declStatusAtom, newValue?.value as Status)
break
case 'constructorCalldata':
typeof newValue?.value === 'object' &&
!Array.isArray(newValue?.value) &&
set(constructorCalldataAtom, newValue?.value)
break
case 'constructorInputs':
Array.isArray(newValue?.value) &&
set(constructorInputsAtom, newValue?.value)
break
case 'notEnoughInputs':
typeof newValue?.value === 'boolean' &&
set(notEnoughInputsAtom, newValue?.value)
break
case 'declTxHash':
typeof newValue?.value === 'string' &&
set(declTxHashAtom, newValue?.value)
break
case 'deployTxHash':
typeof newValue?.value === 'string' &&
set(deployTxHashAtom, newValue?.value)
break
}
}
}, (_get, set, newValue: SetDeploymentAtom) => {
switch (newValue?.key) {
case 'isDeploying': typeof newValue?.value === 'boolean' && set(isDeployingAtom, newValue?.value); break
case 'deployStatus': typeof newValue?.value === 'string' && set(deployStatusAtom, newValue?.value); break
case 'isDeclaring': typeof newValue?.value === 'boolean' && set(isDelcaringAtom, newValue?.value); break
case 'declStatus': typeof newValue?.value === 'string' && set(declStatusAtom, newValue?.value); break
case 'constructorCalldata': typeof newValue?.value === 'object' && !Array.isArray(newValue?.value) && set(constructorCalldataAtom, newValue?.value); break
case 'constructorInputs': Array.isArray(newValue?.value) && set(constructorInputsAtom, newValue?.value); break
case 'notEnoughInputs': typeof newValue?.value === 'boolean' && set(notEnoughInputsAtom, newValue?.value); break
case 'declTxHash': typeof newValue?.value === 'string' && set(declTxHashAtom, newValue?.value); break
case 'deployTxHash': typeof newValue?.value === 'string' && set(deployTxHashAtom, newValue?.value); break
}
})
)

export {
isDeployingAtom,
Expand Down
Loading

0 comments on commit 0a347ca

Please sign in to comment.