Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
fix(utils): update logic for if a name is available
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Oct 31, 2023
1 parent 48b30c4 commit 6041c1b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,19 @@ export function isExistingActiveRecord({
record: ArNSNameData;
currentBlockTimestamp: BlockTimestamp;
}): boolean {
return (
record &&
record.endTimestamp &&
record.endTimestamp + SECONDS_IN_GRACE_PERIOD >
currentBlockTimestamp.valueOf()
);
if (!record) return false;

if (record.type === 'permabuy') {
return true;
}

if (record.type === 'lease') {
return (
record.endTimestamp &&
record.endTimestamp > currentBlockTimestamp.valueOf()
);
}
return false;
}

export function isShortNameRestricted({
Expand Down Expand Up @@ -171,10 +178,13 @@ export function isActiveReservedName({
const target = reservedName.target;
const endTimestamp = reservedName.endTimestamp;
const permanentlyReserved = !target && !endTimestamp;
if (permanentlyReserved) {
return true;
}
const callerNotTarget = !caller || target !== caller;
const notExpired =
endTimestamp && endTimestamp > currentBlockTimestamp.valueOf();
if (permanentlyReserved || (callerNotTarget && notExpired)) {
if (callerNotTarget && notExpired) {
return true;
}
return false;
Expand Down

0 comments on commit 6041c1b

Please sign in to comment.