diff --git a/app/ts/components/requirements.tsx b/app/ts/components/requirements.tsx index 7760fd3..cc38549 100644 --- a/app/ts/components/requirements.tsx +++ b/app/ts/components/requirements.tsx @@ -148,71 +148,101 @@ const ContentHashError = ({ contentHashInput, validContenthash }: ContentHashErr return } -interface CreateProps { - contentHashInput: Signal - handleContentHashInput: (input: string) => void - resolutionAddressInput: Signal - handleResolutionAddressInput: (input: string) => void - loadingInfos: Signal - immutable: Signal - maybeAccountAddress: OptionalSignal + +interface ImmutableDomainProps { checkBoxes: OptionalSignal - updateInfos: (showLoading: boolean) => Promise - creating: Signal - areContractsDeployed: Signal extendYear: Signal extending: Signal + maybeAccountAddress: OptionalSignal + updateInfos: (showLoading: boolean) => Promise } -export const Create = ( { contentHashInput, resolutionAddressInput, loadingInfos, immutable, handleContentHashInput, handleResolutionAddressInput, maybeAccountAddress, checkBoxes, updateInfos, creating, areContractsDeployed, extendYear, extending }: CreateProps) => { +const ImmutableDomain = ({ checkBoxes, extendYear, extending, maybeAccountAddress, updateInfos }: ImmutableDomainProps) => { const isYearValid = useSignal(true) + if (checkBoxes.deepValue === undefined) return <> + const level2DomainExpiryBiggerThanLowestLevelExpiry = computed(() => { + if (checkBoxes.deepValue === undefined) return false + const first = checkBoxes.deepValue[0] + const last = checkBoxes.deepValue[checkBoxes.deepValue.length - 1] + if (first === undefined || last == undefined) return false + return first.domainInfo.expiry.toISOString() !== last.domainInfo.expiry.toISOString() + }) - const makeImmutable = async () => { + const renewByYear = async () => { const account = maybeAccountAddress.peek() if (account === undefined) throw new Error('missing maybeAccountAddress') if (checkBoxes.deepValue === undefined) return try { - creating.value = true - await callPetalLock(account.value, checkBoxes.deepValue.map((value) => value.domainInfo), contentHashInput.value.trim(), resolutionAddressInput.value.trim()) + extending.value = true + await renewDomainByYear(account.value, extendYear.value, checkBoxes.deepValue.map((value) => value.domainInfo)) await updateInfos(false) - } catch(e) { - throw e } finally { - creating.value = false + extending.value = false } } - const deploy = async () => { - const account = maybeAccountAddress.peek() - if (account === undefined) throw new Error('missing maybeAccountAddress') - await deployPetalLockAndRenewalManager(account.value) - await updateInfos(false) - areContractsDeployed.value = true - } - - const renewByYear = async () => { + const renewToMax = async () => { const account = maybeAccountAddress.peek() if (account === undefined) throw new Error('missing maybeAccountAddress') if (checkBoxes.deepValue === undefined) return try { extending.value = true - await renewDomainByYear(account.value, extendYear.value, checkBoxes.deepValue.map((value) => value.domainInfo)) + await renewDomainToMax(account.value, checkBoxes.deepValue.map((value) => value.domainInfo)) await updateInfos(false) } finally { extending.value = false } } - const renewToMax = async () => { + const finalChild = checkBoxes.deepValue[checkBoxes.deepValue.length - 1] + const subDomain = finalChild?.domainInfo.subDomain + if (subDomain === undefined) throw new Error('missing subdomain') + return
+ { !(finalChild?.type === 'finalChild' && finalChild.ownershipOpenRenewalContract) ?

{ `Warning: ${ subDomain } cannot be renewed. It will become mutable when expired.` }

: <> +

{ `Renew ${ subDomain }` }

+
+

Renew by 

 years

+ +
+ { !level2DomainExpiryBiggerThanLowestLevelExpiry.value || checkBoxes.deepValue[0] === undefined ? <> : <> +
+

OR

+
+
+

{ `Renew without renewing ${ checkBoxes.deepValue[0].domainInfo.subDomain }` }

+ +
+ } + } +
+} + +interface NonImmutableDomainProps { + maybeAccountAddress: OptionalSignal + resolutionAddressInput: Signal + checkBoxes: OptionalSignal + updateInfos: (showLoading: boolean) => Promise + creating: Signal + contentHashInput: Signal + handleContentHashInput: (input: string) => void + handleResolutionAddressInput: (input: string) => void + loadingInfos: Signal + areContractsDeployed: Signal +} + +const NonImmutableDomain = ({ checkBoxes, maybeAccountAddress, updateInfos, creating, contentHashInput, resolutionAddressInput, handleContentHashInput, handleResolutionAddressInput, loadingInfos, areContractsDeployed }: NonImmutableDomainProps) => { + const makeImmutable = async () => { const account = maybeAccountAddress.peek() if (account === undefined) throw new Error('missing maybeAccountAddress') if (checkBoxes.deepValue === undefined) return try { - extending.value = true - await renewDomainToMax(account.value, checkBoxes.deepValue.map((value) => value.domainInfo)) + creating.value = true + await callPetalLock(account.value, checkBoxes.deepValue.map((value) => value.domainInfo), contentHashInput.value.trim(), resolutionAddressInput.value.trim()) await updateInfos(false) + } catch(e) { + throw e } finally { - extending.value = false + creating.value = false } } @@ -224,6 +254,7 @@ export const Create = ( { contentHashInput, resolutionAddressInput, loadingInfos const rightAddress = computed(() => isSameAddress(maybeSigningAddress.value, maybeAccountAddress.deepValue)) const validContenthash = computed(() => isValidContentHashString(contentHashInput.value.trim())) const validResolutionAddress = computed(() => isAddress(resolutionAddressInput.value.trim())) + const wrappedIssues = computed(() => { const nonWrappedTokens = checkBoxes.deepValue?.filter((x) => x.exists && !x.isWrapped) if (nonWrappedTokens === undefined || nonWrappedTokens.length === 0) return undefined @@ -248,75 +279,95 @@ export const Create = ( { contentHashInput, resolutionAddressInput, loadingInfos return false }) - const level2DomainExpiryBiggerThanLowestLevelExpiry = computed(() => { - if (checkBoxes.deepValue === undefined) return false - const first = checkBoxes.deepValue[0] - const last = checkBoxes.deepValue[checkBoxes.deepValue.length - 1] - if (first === undefined || last == undefined) return false - return first.domainInfo.expiry.toISOString() !== last.domainInfo.expiry.toISOString() - }) + return
+
+

Make the domain immutable!

+
+

{ `Content hash:` }

+ handleContentHashInput(e.currentTarget.value) } + /> +
+
+

Resolution address:

+ handleResolutionAddressInput(e.currentTarget.value) } + /> +
+
+
+ + + + + + + +
+ +
+} + +interface CreateProps { + contentHashInput: Signal + handleContentHashInput: (input: string) => void + resolutionAddressInput: Signal + handleResolutionAddressInput: (input: string) => void + loadingInfos: Signal + immutable: Signal + maybeAccountAddress: OptionalSignal + checkBoxes: OptionalSignal + updateInfos: (showLoading: boolean) => Promise + creating: Signal + areContractsDeployed: Signal + extendYear: Signal + extending: Signal +} + +export const Create = ( { contentHashInput, resolutionAddressInput, loadingInfos, immutable, handleContentHashInput, handleResolutionAddressInput, maybeAccountAddress, checkBoxes, updateInfos, creating, areContractsDeployed, extendYear, extending }: CreateProps) => { + const deploy = async () => { + const account = maybeAccountAddress.peek() + if (account === undefined) throw new Error('missing maybeAccountAddress') + await deployPetalLockAndRenewalManager(account.value) + await updateInfos(false) + areContractsDeployed.value = true + } if (checkBoxes.deepValue === undefined) return <> const finalChild = checkBoxes.deepValue[checkBoxes.deepValue.length - 1] const subDomain = finalChild?.domainInfo.subDomain if (subDomain === undefined) throw new Error('missing subdomain') return
- { immutable.value ?
- { !(finalChild?.type === 'finalChild' && finalChild.ownershipOpenRenewalContract) ?

{ `Warning: ${ subDomain } cannot be renewed. It will become mutable when expired.` }

: <> -

{ `Renew ${ subDomain }` }

-
-

Renew by 

 years

- -
- { !level2DomainExpiryBiggerThanLowestLevelExpiry.value || checkBoxes.deepValue[0] === undefined ? <> : <> -
-

OR

-
-
-

{ `Renew without renewing ${ checkBoxes.deepValue[0].domainInfo.subDomain }` }

- -
- } - } -
:
-
-

Make the domain immutable!

-
-

{ `Content hash:` }

- handleContentHashInput(e.currentTarget.value) } - /> -
-
-

Resolution address:

- handleResolutionAddressInput(e.currentTarget.value) } - /> -
-
-
- - - - - - - -
- -
} + { immutable.value ? : }
}