-
Notifications
You must be signed in to change notification settings - Fork 33
Add the Quick checkpoint flow for rewards #1948
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
Open
efstajas
wants to merge
2
commits into
main
Choose a base branch
from
wave-quick-checkpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import z from 'zod'; | ||
| import { authenticatedCall } from './call'; | ||
| import parseRes from './utils/parse-res'; | ||
|
|
||
| /** Areas that a checkpoint can be required for. */ | ||
| export const livenessCheckpointPurposes = ['grant_access'] as const; | ||
| export type LivenessCheckpointPurpose = (typeof livenessCheckpointPurposes)[number]; | ||
|
|
||
| /** | ||
| * Only the fields the UI actually needs. The API decides entirely on its own | ||
| * whether a check is due; the client never reproduces that logic, and anything | ||
| * else the response carries is deliberately not picked up here. | ||
| */ | ||
| export const livenessCheckpointStatusSchema = z.object({ | ||
| purpose: z.enum(livenessCheckpointPurposes), | ||
| satisfied: z.boolean(), | ||
| challengeStatus: z.enum(['pending', 'approved', 'rejected', 'expired']).nullable(), | ||
| locked: z.boolean(), | ||
| }); | ||
|
|
||
| export type LivenessCheckpointStatus = z.infer<typeof livenessCheckpointStatusSchema>; | ||
|
|
||
| export async function getLivenessCheckpointStatus(f = fetch, purpose: LivenessCheckpointPurpose) { | ||
| return parseRes( | ||
| livenessCheckpointStatusSchema, | ||
| await authenticatedCall(f, `/api/liveness-checkpoints/status?purpose=${purpose}`, { | ||
| method: 'GET', | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Starts (or resumes) a check and returns a SumSub token scoped to it. Throws | ||
| * if the user isn't currently allowed to start one. | ||
| */ | ||
| export async function startLivenessCheckpoint(f = fetch, purpose: LivenessCheckpointPurpose) { | ||
| return parseRes( | ||
| z.object({ | ||
| accessToken: z.string(), | ||
| checkpointId: z.uuid(), | ||
| }), | ||
| await authenticatedCall(f, `/api/liveness-checkpoints/session`, { | ||
| method: 'POST', | ||
| body: JSON.stringify({ purpose }), | ||
| }), | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { getLivenessCheckpointStatus } from '$lib/utils/wave/liveness.js'; | ||
| import { redirect } from '@sveltejs/kit'; | ||
|
|
||
| /** | ||
| * Sends the user to the checkpoint screen when the API says one is due. | ||
| * | ||
| * The API refuses the grants endpoints outright in that case, so without this | ||
| * guard the user would land on a broken page. Whether a check is actually due | ||
| * is entirely the API's call — this just asks and acts on the answer. | ||
| */ | ||
| export const load = async ({ parent, url, fetch, depends }) => { | ||
| depends('wave:liveness-checkpoint'); | ||
|
|
||
| const { user } = await parent(); | ||
|
|
||
| // Unauthenticated users are redirected to login by the child loads; there is | ||
| // no checkpoint to evaluate for them. | ||
| if (!user) return {}; | ||
|
|
||
| try { | ||
| const checkpoint = await getLivenessCheckpointStatus(fetch, 'grant_access'); | ||
|
|
||
| if (!checkpoint.satisfied) { | ||
| throw redirect( | ||
| 302, | ||
| `/wave/checkpoint?backTo=${encodeURIComponent(url.pathname + url.search)}`, | ||
| ); | ||
| } | ||
|
|
||
| return { checkpoint }; | ||
| } catch (err) { | ||
| // Preserve our own redirect above. | ||
| if (err && typeof err === 'object' && 'status' in err && err.status === 302) { | ||
| throw err; | ||
| } | ||
| // Let the child loads handle auth — they own the login redirect and the | ||
| // backTo round trip. | ||
| if (err && typeof err === 'object' && 'status' in err && err.status === 401) { | ||
| return {}; | ||
| } | ||
| throw err; | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <script lang="ts"> | ||
| import HeadMeta from '$lib/components/head-meta/head-meta.svelte'; | ||
|
|
||
| let { children } = $props(); | ||
| </script> | ||
|
|
||
| <HeadMeta title="Quick checkpoint | Wave" /> | ||
|
|
||
| {@render children?.()} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { getLivenessCheckpointStatus } from '$lib/utils/wave/liveness.js'; | ||
| import { redirect } from '@sveltejs/kit'; | ||
|
|
||
| export const load = async ({ parent, url, fetch, depends }) => { | ||
| depends('wave:liveness-checkpoint'); | ||
|
|
||
| const { user } = await parent(); | ||
|
|
||
| if (!user) { | ||
| throw redirect(302, `/wave/login?backTo=${encodeURIComponent(url.pathname + url.search)}`); | ||
| } | ||
|
|
||
| const checkpoint = await getLivenessCheckpointStatus(fetch, 'grant_access'); | ||
|
|
||
| return { | ||
| checkpoint, | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <script lang="ts"> | ||
| import AnnotationBox from '$lib/components/annotation-box/annotation-box.svelte'; | ||
| import Button from '$lib/components/button/button.svelte'; | ||
| import ArrowRight from '$lib/components/icons/ArrowRight.svelte'; | ||
| import ArrowBoxUpRight from '$lib/components/icons/ArrowBoxUpRight.svelte'; | ||
| import LockAndKeyEmoji from '$lib/components/icons/🔐.svelte'; | ||
| import FlowStepWrapper from '../shared/flow-step-wrapper.svelte'; | ||
|
|
||
| let { data } = $props(); | ||
| let { checkpoint, backTo } = $derived(data); | ||
|
|
||
| let previousAttemptFailed = $derived(checkpoint.challengeStatus === 'rejected'); | ||
|
|
||
| let description = $derived( | ||
| previousAttemptFailed | ||
| ? "That check didn't go through. Take a new selfie in good light with nothing covering your face." | ||
| : "Before you continue, we need to verify it's really you with a quick selfie.", | ||
| ); | ||
| </script> | ||
|
|
||
| <FlowStepWrapper icon={LockAndKeyEmoji} headline="Quick checkpoint" {description}> | ||
| {#if checkpoint.locked} | ||
| <AnnotationBox type="warning"> | ||
| <span class="typo-text-small-bold">You've run out of identity checks for now.</span> | ||
| Please get in touch with support and we'll help you sort it out. | ||
|
|
||
| {#snippet actions()} | ||
| <Button href="https://docs.drips.network/wave/contributors/faq" target="_blank"> | ||
| Contact support | ||
| </Button> | ||
| {/snippet} | ||
| </AnnotationBox> | ||
| {:else} | ||
| <AnnotationBox type="info"> | ||
| It usually takes less than a minute, and you'll be able to withdraw your rewards immediately | ||
| afterwards. | ||
|
|
||
| {#snippet actions()} | ||
| <Button | ||
| href="https://docs.drips.network/wave/contributors/solving-issues-and-earning-rewards#verifying-your-identity" | ||
| target="_blank" | ||
| icon={ArrowBoxUpRight} | ||
| > | ||
| Learn more | ||
| </Button> | ||
| {/snippet} | ||
| </AnnotationBox> | ||
| {/if} | ||
|
|
||
| {#snippet leftActions()} | ||
| <Button variant="ghost" href="/wave">Back to Wave</Button> | ||
| {/snippet} | ||
|
|
||
| {#snippet actions()} | ||
| {#if !checkpoint.locked} | ||
| <Button | ||
| variant="primary" | ||
| icon={ArrowRight} | ||
| href={`/wave/checkpoint/verify?backTo=${encodeURIComponent(backTo)}`} | ||
| > | ||
| {previousAttemptFailed ? 'Try again' : 'Start check'} | ||
| </Button> | ||
| {/if} | ||
| {/snippet} | ||
| </FlowStepWrapper> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { safeParseBackToParam } from '$lib/utils/safe-path'; | ||
| import { redirect } from '@sveltejs/kit'; | ||
|
|
||
| export const load = async ({ parent, url }) => { | ||
| const { checkpoint } = await parent(); | ||
|
|
||
| const backTo = safeParseBackToParam(url) || '/wave/rewards'; | ||
|
|
||
| // Nothing to ask for — either they're already through or the checkpoint | ||
| // doesn't apply to them. | ||
| if (checkpoint.satisfied) { | ||
| throw redirect(302, backTo); | ||
| } | ||
|
|
||
| return { | ||
| checkpoint, | ||
| backTo, | ||
| }; | ||
| }; |
18 changes: 18 additions & 0 deletions
18
src/routes/(pages)/wave/(flows)/checkpoint/success/+page.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <script lang="ts"> | ||
| import Button from '$lib/components/button/button.svelte'; | ||
| import ArrowRight from '$lib/components/icons/ArrowRight.svelte'; | ||
| import FlowStepWrapper from '../../shared/flow-step-wrapper.svelte'; | ||
|
|
||
| let { data } = $props(); | ||
| let { backTo } = $derived(data); | ||
| </script> | ||
|
|
||
| <FlowStepWrapper | ||
| confetti | ||
| headline="You're all set" | ||
| description="Thanks — that's you verified. Your rewards are unlocked and you can withdraw right away." | ||
| > | ||
| {#snippet actions()} | ||
| <Button variant="primary" icon={ArrowRight} href={backTo}>Continue</Button> | ||
| {/snippet} | ||
| </FlowStepWrapper> |
18 changes: 18 additions & 0 deletions
18
src/routes/(pages)/wave/(flows)/checkpoint/success/+page.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { safeParseBackToParam } from '$lib/utils/safe-path'; | ||
| import { redirect } from '@sveltejs/kit'; | ||
|
|
||
| export const load = async ({ parent, url }) => { | ||
| const { checkpoint } = await parent(); | ||
|
|
||
| const backTo = safeParseBackToParam(url) || '/wave/rewards'; | ||
|
|
||
| // Landing here without having passed means something went wrong on the way — | ||
| // send them back to the start rather than showing a success screen. | ||
| if (!checkpoint.satisfied) { | ||
| throw redirect(302, `/wave/checkpoint?backTo=${encodeURIComponent(backTo)}`); | ||
| } | ||
|
|
||
| return { | ||
| backTo, | ||
| }; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.