Skip to content

Commit

Permalink
Merge pull request #1837 from ResearchHub/claim-fixes
Browse files Browse the repository at this point in the history
[Paper Claim] Updating claim requirements
  • Loading branch information
yattias authored Sep 20, 2024
2 parents df90c6d + 198b45a commit b709f62
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
6 changes: 4 additions & 2 deletions components/Author/Tabs/FeedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ function FeedCard({
: parsedDoc.authors;
} catch (error) { }

const visibleDate = parsedDoc?.publishedDate || parsedDoc?.createdDate;

const parsedHubs = (hubs || []).map(parseHub);
const router = useRouter();
const [isPreviewing, setIsPreviewing] = useState(false);
Expand Down Expand Up @@ -360,12 +362,12 @@ function FeedCard({
)}
{authors?.length > 1 && <span>{` et al.`}</span>}

{parsedDoc?.createdDate && (
{visibleDate && (
<>
{authors?.length > 0 && (
<span className={css(styles.metaDivider)}></span>
)}
{parsedDoc?.createdDate}
{visibleDate}
</>
)}

Expand Down
12 changes: 10 additions & 2 deletions components/ResearchCoin/lib/rewardsUtil.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { FullAuthorProfile } from "~/components/Author/lib/types";
import { AuthorProfile } from "~/config/types/root_types";
import { isNewerThanFiveYearsAgo } from "~/config/utils/dates";

export type ineligibleReason =
| "NOT_OPEN_ACCESS"
| "NOT_SUPPORTED_TYPE"
| "NOT_FIRST_AUTHOR"
| "OLD_PAPER"
| null;

export type RewardsEligibilityInfo = {
isEligibleForRewards: boolean;
reason: "NOT_OPEN_ACCESS" | "NOT_SUPPORTED_TYPE" | "NOT_FIRST_AUTHOR" | null;
reason: ineligibleReason;
};

export const getRewardsEligibilityInfo = ({
Expand All @@ -23,6 +25,7 @@ export const getRewardsEligibilityInfo = ({
targetDoc: any;
isOpenAccess: boolean;
}): RewardsEligibilityInfo => {

const isFirstAuthor = authors.find(
(author) =>
author?.authorship?.authorPosition === "first" &&
Expand All @@ -32,6 +35,8 @@ export const getRewardsEligibilityInfo = ({
targetDoc?.work_type
);

const isPublishedDateWithinFiveYears = isNewerThanFiveYearsAgo(targetDoc?.paper_publish_date);

let ineligibleReason: ineligibleReason = null;
if (!isOpenAccess) {
ineligibleReason = "NOT_OPEN_ACCESS";
Expand All @@ -40,9 +45,12 @@ export const getRewardsEligibilityInfo = ({
} else if (!isSupportedType) {
ineligibleReason = "NOT_SUPPORTED_TYPE";
}
else if (!isPublishedDateWithinFiveYears) {
ineligibleReason = "OLD_PAPER";
}

return {
isEligibleForRewards: Boolean(isFirstAuthor && isSupportedType),
isEligibleForRewards: Boolean(isFirstAuthor && isSupportedType && isOpenAccess && isPublishedDateWithinFiveYears),
reason: ineligibleReason,
};
};
2 changes: 2 additions & 0 deletions components/shared/ClaimRewardsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const getTooltipContent = (rewardEligibilityInfo: RewardsEligibilityInfo) => {
"Only primary literature is eligible for rewards at this time."}
{rewardEligibilityInfo.reason === "NOT_OPEN_ACCESS" &&
"Only open access papers are eligible for rewards at this time."}
{rewardEligibilityInfo.reason === "OLD_PAPER" &&
"Only papers published within the last five years are eligible for rewards at this time."}
</div>
</div>
);
Expand Down
8 changes: 8 additions & 0 deletions config/utils/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,11 @@ export function calculateScopeFromSlug(scopeId) {

return scope;
}

export function isNewerThanFiveYearsAgo(date) {
const now = moment();
const fiveYearsAgo = now.subtract(5, "year");
const dateObj = moment(date);

return dateObj.isAfter(fiveYearsAgo) || dateObj.isSame(fiveYearsAgo);
}

0 comments on commit b709f62

Please sign in to comment.