Skip to content

Commit

Permalink
Merge pull request #53 from DarkFlorist/bigint-to-number
Browse files Browse the repository at this point in the history
convert bigint to number when receiving it
  • Loading branch information
KillariDev authored Sep 17, 2024
2 parents 42b4816 + 4f25ee7 commit b48d4a9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/ts/components/requirements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const Immutable = ( { checkBoxesArray } : { checkBoxesArray: Signal<Check
<div style = 'padding-top: 30px; padding-bottom: 30px; align-items: center; display: grid; width: 100%'>
{ checkBoxes.immutable ? <>
<p class = 'status-green'>
{`IMMUTABLE until ${ new Date(Number(checkBoxes.domainInfo.expiry) * 1000).toISOString() }` }
{`IMMUTABLE until ${ checkBoxes.domainInfo.expiry.toISOString() }` }
</p>
</>: <p class = 'status-red'> NOT IMMUTABLE </p> }
</div>
Expand Down Expand Up @@ -251,7 +251,7 @@ export const Create = ( { contentHashInput, resolutionAddressInput, loadingInfos
</div>
<div style = 'justify-content: center;'>
<p style = 'font-size: 24px;' >{ `Renew without renewing ${ checkBoxes.deepValue[0].domainInfo.subDomain }` }</p>
<button style = 'font-size: 3em;' class = 'button is-primary' disabled = { extending.value } onClick = { renewToMax }> { `Renew to ${ new Date(Number(checkBoxes.deepValue[0].domainInfo.expiry) * 1000).toISOString().substring(0, 10) }`} { extending.value ? <Spinner/> : <></> }</button>
<button style = 'font-size: 3em;' class = 'button is-primary' disabled = { extending.value } onClick = { renewToMax }> { `Renew to ${ checkBoxes.deepValue[0].domainInfo.expiry.toISOString().substring(0, 10) }` } { extending.value ? <Spinner/> : <></> }</button>
</div>
</> }
</div> : <>
Expand Down
2 changes: 1 addition & 1 deletion app/ts/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type DomainInfo = {
registeryOwner: `0x${ string }`,
data: readonly [`0x${ string }`, number, bigint],
fuses: readonly EnsFuseName[],
expiry: bigint,
expiry: Date,
label: string,
parentDomain: string,
subDomain: string,
Expand Down
4 changes: 2 additions & 2 deletions app/ts/utils/ensUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mainnet } from 'viem/chains'
import { ENS_WRAPPER_ABI } from '../abi/ens_wrapper_abi.js'
import 'viem/window'
import { ENS_REGISTRY_ABI } from '../abi/ens_registry_abi.js'
import { splitDomainToSubDomainAndParent, splitEnsStringToSubdomainPath } from './utilities.js'
import { bigIntToNumber, splitDomainToSubDomainAndParent, splitEnsStringToSubdomainPath } from './utilities.js'
import { ENS_PUBLIC_RESOLVER_ABI } from '../abi/ens_public_resolver_abi.js'
import { CAN_DO_EVERYTHING, ENS_ETH_REGISTRAR_CONTROLLER, ENS_ETHEREUM_NAME_SERVICE, ENS_FLAGS, ENS_PUBLIC_RESOLVER, ENS_REGISTRY_WITH_FALLBACK, ENS_TOKEN_WRAPPER, FINAL_CHILD_FUSES, MID_PARENT_FUSES, SINGLE_DOMAIN_FUSES, TOP_PARENT_FUSES } from './constants.js'
import { AccountAddress, DomainInfo, EnsFuseName } from '../types/types.js'
Expand Down Expand Up @@ -147,7 +147,7 @@ const getDomainInfo = async (accountAddress: AccountAddress | undefined, nameHas
registeryOwner: await registeryOwnerPromise,
data,
fuses: extractENSFuses(BigInt(data[1])),
expiry: data[2],
expiry: new Date(bigIntToNumber(data[2]) * 1000),
label,
registered: await registeredPromise,
contentHash: await contentHashPromise,
Expand Down
7 changes: 7 additions & 0 deletions app/ts/utils/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,10 @@ export const splitDomainToSubDomainAndParent = (domain: string): [string, string
if (index === -1) throw new Error('not proper domain')
return [domain.slice(0, index), domain.slice(index + 1)]
}

export function bigIntToNumber(value: bigint): number {
if (value <= Number.MAX_SAFE_INTEGER && value >= Number.MIN_SAFE_INTEGER) {
return Number(value)
}
throw new Error(`Value: "${ value }" is out of bounds to be a Number.`)
}

0 comments on commit b48d4a9

Please sign in to comment.