Skip to content

Commit

Permalink
Merge pull request #89 from DarkFlorist/error-showing
Browse files Browse the repository at this point in the history
cleanup, fix invalid ens domain error
  • Loading branch information
KillariDev authored Nov 7, 2024
2 parents f5dd487 + ab99c6f commit 778eb30
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
22 changes: 11 additions & 11 deletions app/ts/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ const LoadingSpinner = ({ loading }: LoadingSpinnerProps) => {
</div>
}

interface ErrorComponentProps {
show: boolean
message: string | OptionalSignal<string>
}
const ErrorComponent = ({ show, message }: ErrorComponentProps) => {
if (show === false) return <></>
return <p class = 'error-component'> { message } </p>
type ErrorComponentProps = { displayError: boolean, message: string } | { message: OptionalSignal<string> }
const ErrorComponent = (props: ErrorComponentProps) => {
if (!('displayError' in props)) {
if (props.message.value === undefined) return <></>
return <p class = 'error-component'> { props.message.value } </p>
}
if (props.displayError === false) return <></>
return <p class = 'error-component'> { props.message } </p>
}

interface EnsRegistryErrorProps {
Expand Down Expand Up @@ -83,7 +84,6 @@ export function App() {
return
}
const ensured = ensureError(error)
console.error(error)
errorString.deepValue = ensured.message
}

Expand Down Expand Up @@ -146,7 +146,7 @@ export function App() {
const ensSubDomain = inputValue.value.toLowerCase()
if (!isValidEnsSubDomain(ensSubDomain)) {
clear()
return setError(`${ ensSubDomain } is not a valid ENS subdomain. The format should be similar to "2.horswap.eth" or "1.lunaria.darkflorist.eth."`)
return setError(`${ ensSubDomain } is not a valid ENS subdomain. The format should be similar to "2.horswap.eth" or "1.lunaria.darkflorist.eth".`)
}
setError(undefined)
updateInfos(true)
Expand Down Expand Up @@ -219,8 +219,8 @@ export function App() {
/>

<LoadingSpinner loading = { loadingInfos.value === true || loadingAccount.value }/>
<ErrorComponent message = { errorString } show = { errorString.deepValue !== undefined } />
<ErrorComponent show = { chainId.value !== undefined && chainId.value !== 1 } message = { 'PetalLock functions only on Ethereum Mainnet. Please switch to Ethereum Mainnet.' }/>
<ErrorComponent message = { errorString }/>
<ErrorComponent displayError = { chainId.value !== undefined && chainId.value !== 1 } message = { 'PetalLock functions only on Ethereum Mainnet. Please switch to Ethereum Mainnet.' }/>
<EnsRegistryError checkBoxes = { checkBoxes } />
<Immutable checkBoxesArray = { checkBoxes } />
<Requirements checkBoxesArray = { checkBoxes }/>
Expand Down
38 changes: 15 additions & 23 deletions app/ts/components/requirements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,14 @@ export const DeployContract = ({ areContractsDeployed, deploy }: DeployProps) =>
return <></>
}

interface DisplayErrorStringIfNotUndefinedProps {
maybeString: Signal<string | undefined>
}
const DisplayErrorStringIfNotUndefined = ({ maybeString }: DisplayErrorStringIfNotUndefinedProps) => {
if (maybeString.value === undefined) return <></>
return <p class = 'paragraph' style = 'color: #b43c42'> { maybeString.value } </p>
}

interface DisplayErrorStringIfVariableTrueProps {
displayError: boolean
message: string
}
const DisplayErrorStringIfVariableTrue = ({ message, displayError }: DisplayErrorStringIfVariableTrueProps) => {
if (displayError === false) return <></>
return <p class = 'paragraph' style = 'color: #b43c42'> { message } </p>
type DisplayErrorProps = { displayError: boolean, message: string } | { message: OptionalSignal<string> | ReadonlySignal<string | undefined> }
const DisplayError = (props: DisplayErrorProps) => {
if (!('displayError' in props)) {
if (props.message.value === undefined) return <></>
return <p class = 'paragraph' style = 'color: #b43c42'> { props.message.value } </p>
}
if (props.displayError === false) return <></>
return <p class = 'paragraph' style = 'color: #b43c42'> { props.message } </p>
}

interface ContentHashErrorProps {
Expand All @@ -169,11 +162,10 @@ const ContentHashError = ({ contentHashInput, validContenthash }: ContentHashErr
if (validContenthash.value === true) return <></>
if (contentHashInput.value.length === 0) return <></>
const separator = contentHashInput.value.includes('://')
if (separator === false) return <DisplayErrorStringIfVariableTrue displayError = { true } message = ' - Content hash needs to include protocol and hash, eg ("ipfs://bafy...")'/>
return <DisplayErrorStringIfVariableTrue displayError = { true } message = ' - Content hash is not valid'/>
if (separator === false) return <DisplayError displayError = { true } message = ' - Content hash needs to include protocol and hash, eg ("ipfs://bafy...")'/>
return <DisplayError displayError = { true } message = ' - Content hash is not valid'/>
}


interface ImmutableDomainProps {
checkBoxes: OptionalSignal<CheckBoxes>
extendYear: Signal<number>
Expand Down Expand Up @@ -333,12 +325,12 @@ const NonImmutableDomain = ({ checkBoxes, maybeAccountAddress, updateInfos, crea
</div>
</div>
<div style = 'padding: 10px; display: block;' key = 'issues'>
<DisplayErrorStringIfNotUndefined maybeString = { domainExistIssue } />
<DisplayError message = { domainExistIssue } />
<ContentHashError validContenthash = { validContenthash } contentHashInput = { contentHashInput }/>
<DisplayErrorStringIfVariableTrue displayError = { !(validResolutionAddress.value || resolutionAddressInput.value.length === 0) } message = ' - Resolution address is not a valid address'/>
<DisplayErrorStringIfVariableTrue displayError = { !(validContenthash.value || validResolutionAddress.value) } message = ' - Set content hash or resolution address or both'/>
<DisplayErrorStringIfNotUndefined maybeString = { wrappedIssues } />
<DisplayErrorStringIfNotUndefined maybeString = { ownershipIssues } />
<DisplayError displayError = { !(validResolutionAddress.value || resolutionAddressInput.value.length === 0) } message = ' - Resolution address is not a valid address'/>
<DisplayError displayError = { !(validContenthash.value || validResolutionAddress.value) } message = ' - Set content hash or resolution address or both'/>
<DisplayError message = { wrappedIssues } />
<DisplayError message = { ownershipIssues } />
<SwitchAddress requirementsMet = { loadingInfos.value } maybeAccountAddress = { maybeAccountAddress } maybeSigningAddress = { maybeSigningAddress }/>
</div>
<button style = 'font-size: 3em;' class = 'button is-primary' disabled = { ownershipIssues.value !== undefined || wrappedIssues.value !== undefined || areContractsDeployed.value !== true || !contentSetProperly.value || !rightAddress.value || checkBoxes.deepValue === undefined || loadingInfos.value || creating.value } onClick = { makeImmutable }> Make immutable { creating.value ? <Spinner/> : <></> }</button>
Expand Down
2 changes: 0 additions & 2 deletions app/ts/utils/ensUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ export const getRequiredFusesWithoutApproval = (domainIndex: number, domainInfos
}

export const getRequiredFusesWithApproval = (domainIndex: number, domainInfos: readonly DomainInfo[]) => {
console.log('getRequiredFusesWithApproval')
console.log(domainInfos)
if (domainInfos.length === 1) return SINGLE_DOMAIN_FUSES
if (domainIndex === 0 && domainInfos.length > 1) return TOP_PARENT_FUSES
if (domainIndex === domainInfos.length - 1) return FINAL_CHILD_FUSES
Expand Down

0 comments on commit 778eb30

Please sign in to comment.