Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C-4402] Use completed at for cooldown check #8557

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const getCooldownChallengeInfo = (
challenge: UndisbursedUserChallenge,
now: Dayjs
) => {
const createdAt = utcToLocalTime(challenge.created_at)
const completedAt = utcToLocalTime(challenge.completed_at)
const cooldownDays = challenge.cooldown_days ?? 0
const diff = now.diff(createdAt, 'day')
const claimableDate = createdAt.add(cooldownDays, 'day')
const diff = now.diff(completedAt, 'day')
const claimableDate = completedAt.add(cooldownDays, 'day')
const isClose = cooldownDays - diff <= 1
let label = claimableDate.format('dddd')
if (diff === cooldownDays) {
Expand All @@ -47,8 +47,8 @@ export const formatCooldownChallenges = (
const now = dayjs().endOf('day')
const cooldownChallenges = new Array(challenges[0].cooldown_days)
challenges.forEach((c) => {
const createdAt = utcToLocalTime(c.created_at)
const diff = now.diff(createdAt, 'day')
const completedAt = utcToLocalTime(c.completed_at)
const diff = now.diff(completedAt, 'day')
cooldownChallenges[diff] = {
...cooldownChallenges[diff],
id: c.specifier,
Expand All @@ -74,7 +74,6 @@ export const useChallengeCooldownSchedule = ({
const challenges = useSelector(getUndisbursedUserChallenges)
.filter((c) => multiple || c.challenge_id === challengeId)
.filter((c) => !TRENDING_CHALLENGE_IDS.has(c.challenge_id))
.map((c) => ({ ...c, createdAtDate: dayjs.utc(c.created_at) }))

const [claimableChallenges, cooldownChallenges] = partition(
challenges,
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/store/pages/audio-rewards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type UndisbursedUserChallenge = Pick<
handle: string
wallet: string
created_at: string
completed_at: string
cooldown_days?: number
}

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/utils/challenges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export const isCooldownChallengeClaimable = (
) => {
return (
challenge.cooldown_days === undefined ||
dayjs.utc().diff(dayjs.utc(challenge.created_at), 'day') >=
dayjs.utc().diff(dayjs.utc(challenge.completed_at), 'day') >=
challenge.cooldown_days
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def setup_challenges(app):
current_step_count=1,
amount=5,
created_at="2023-10-16 17:51:31.105065+00",
completed_at="2023-10-16 17:51:31.105065+00",
),
UserChallenge(
challenge_id="test_challenge_1",
Expand All @@ -84,6 +85,7 @@ def setup_challenges(app):
completed_blocknumber=100,
amount=5,
created_at="2023-10-16 17:51:31.105065+00",
completed_at="2023-10-16 17:51:31.105065+00",
),
UserChallenge(
challenge_id="test_challenge_2",
Expand All @@ -92,6 +94,7 @@ def setup_challenges(app):
is_complete=False,
amount=5,
created_at="2023-10-16 17:51:31.105065+00",
completed_at="2023-10-16 17:51:31.105065+00",
),
UserChallenge(
challenge_id="test_challenge_2",
Expand All @@ -101,6 +104,7 @@ def setup_challenges(app):
completed_blocknumber=102,
amount=5,
created_at="2023-10-16 17:51:31.105065+00",
completed_at="2023-10-16 17:51:31.105065+00",
),
UserChallenge(
challenge_id="test_challenge_2",
Expand All @@ -110,6 +114,7 @@ def setup_challenges(app):
completed_blocknumber=102,
amount=5,
created_at="2023-10-16 17:51:31.105065+00",
completed_at="2023-10-16 17:51:31.105065+00",
),
UserChallenge(
challenge_id="test_challenge_3",
Expand All @@ -119,6 +124,7 @@ def setup_challenges(app):
completed_blocknumber=100,
amount=5,
created_at="2023-10-16 17:51:31.105065+00",
completed_at="2023-10-16 17:51:31.105065+00",
),
]

Expand Down Expand Up @@ -153,6 +159,7 @@ def test_undisbursed_challenges(app):
"handle": "TestHandle6",
"wallet": "0x6",
"created_at": "2023-10-16 17:51:31.105065+00:00",
"completed_at": "2023-10-16 17:51:31.105065",
"cooldown_days": None,
},
{
Expand All @@ -164,6 +171,7 @@ def test_undisbursed_challenges(app):
"handle": "TestHandle4",
"wallet": "0x4",
"created_at": "2023-10-16 17:51:31.105065+00:00",
"completed_at": "2023-10-16 17:51:31.105065",
"cooldown_days": None,
},
{
Expand All @@ -175,6 +183,7 @@ def test_undisbursed_challenges(app):
"handle": "TestHandle5",
"wallet": "0x5",
"created_at": "2023-10-16 17:51:31.105065+00:00",
"completed_at": "2023-10-16 17:51:31.105065",
"cooldown_days": None,
},
]
Expand All @@ -196,6 +205,7 @@ def test_undisbursed_challenges(app):
"handle": "TestHandle6",
"wallet": "0x6",
"created_at": "2023-10-16 17:51:31.105065+00:00",
"completed_at": "2023-10-16 17:51:31.105065",
"cooldown_days": None,
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class UndisbursedChallengeResponse(TypedDict):
handle: str
wallet: str
created_at: str
completed_at: str
cooldown_days: Optional[int]


Expand All @@ -35,6 +36,7 @@ def to_challenge_response(
"handle": handle,
"wallet": wallet,
"created_at": str(user_challenge.created_at),
"completed_at": str(user_challenge.completed_at),
"cooldown_days": challenge.cooldown_days,
}

Expand Down