-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add email input * feat: add otp verification ui
- Loading branch information
1 parent
38c2b8d
commit 45e5daa
Showing
11 changed files
with
274 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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
3 changes: 3 additions & 0 deletions
3
src/lib/components/connect-wallet-modal/steps/otp-verification/index.ts
This file contains 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,3 @@ | ||
import OtpVerification from './otp-verification.svelte'; | ||
|
||
export { OtpVerification }; |
49 changes: 49 additions & 0 deletions
49
src/lib/components/connect-wallet-modal/steps/otp-verification/otp-verification.svelte
This file contains 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,49 @@ | ||
<script lang="ts"> | ||
import { Spinner } from '$/components/ui/spinner/index.js'; | ||
import { onMount } from 'svelte'; | ||
import type { ConnectWalletModalStepProps } from '../index.js'; | ||
import SvelteOtp from '@k4ung/svelte-otp'; | ||
import { cn } from '$/utils.js'; | ||
import { Button } from '$/components/ui/button/index.js'; | ||
type $$Props = ConnectWalletModalStepProps<'otp-verification'>; | ||
export let additionalProps: $$Props['additionalProps']; | ||
type AccountStatus = 'sending' | 'sent' | 'error'; | ||
let accountStatus: AccountStatus = 'sending'; | ||
let otp = ''; | ||
onMount(async () => { | ||
// TODO: send otp | ||
await new Promise((resolve) => setTimeout(resolve, 500)); | ||
accountStatus = 'sent'; | ||
}); | ||
</script> | ||
|
||
{#if accountStatus === 'sending'} | ||
<div class="twsv-flex twsv-flex-col twsv-items-center twsv-gap-8 twsv-py-12 twsv-text-center"> | ||
<Spinner /> | ||
</div> | ||
{:else} | ||
<div class="twsv-flex twsv-flex-col twsv-items-center twsv-gap-8 twsv-pt-8 twsv-text-center"> | ||
<div class="twsv-flex twsv-flex-col twsv-gap-1 twsv-font-medium"> | ||
<span class="twsv-text-muted-foreground">Enter the verification code sent to</span> | ||
<span>{additionalProps.email}</span> | ||
</div> | ||
<SvelteOtp | ||
numOfInputs={6} | ||
numberOnly | ||
inputClass={cn( | ||
'!twsv-w-10 !twsv-h-10 twsv-rounded-xl !twsv-border-2 !twsv-border-secondary !twsv-bg-transparent focus-visible:twsv-outline-none focus-visible:twsv-ring-2 focus-visible:twsv-ring-accent' | ||
)} | ||
bind:value={otp} | ||
/> | ||
<Button variant="accent" size="lg" class="twsv-w-full">Verify</Button> | ||
<div | ||
class="-twsv-ml-6 -twsv-mr-6 twsv-self-stretch twsv-border-t twsv-border-border twsv-pb-1 twsv-pt-4" | ||
> | ||
<Button variant="link" size="auto">Resend verification code</Button> | ||
</div> | ||
</div> | ||
{/if} |
70 changes: 70 additions & 0 deletions
70
src/lib/components/connect-wallet-modal/steps/provider-selector/email-input.svelte
This file contains 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,70 @@ | ||
<script lang="ts"> | ||
import { Button } from '$/components/ui/button/index.js'; | ||
import { Input, type FormInputEvent } from '$/components/ui/input/index.js'; | ||
import { cn } from '$/utils.js'; | ||
import { validateEmail } from '$/utils/validation.js'; | ||
import ArrowRight from 'lucide-svelte/icons/arrow-right'; | ||
import { onMount } from 'svelte'; | ||
import type { ConnectWalletModalStepProps } from '../index.js'; | ||
export let setStep: ConnectWalletModalStepProps<'provider-selector'>['setStep']; | ||
let value = ''; | ||
let error = ''; | ||
let showError = false; | ||
$: shownError = showError && error; | ||
onMount(() => { | ||
showError = false; | ||
}); | ||
const handleChange: (e: FormInputEvent<KeyboardEvent>) => void = (event) => { | ||
if (event.key === 'Enter') { | ||
showError = true; | ||
} | ||
const input = event.target as HTMLInputElement; | ||
value = input.value; | ||
if (!validateEmail(value)) { | ||
error = 'Invalid email address'; | ||
} else { | ||
error = ''; | ||
} | ||
}; | ||
const handleSubmit = (event: SubmitEvent) => { | ||
event.preventDefault(); | ||
showError = true; | ||
setStep('otp-verification', { email: value }); | ||
}; | ||
</script> | ||
|
||
<form class="twsv-relative" on:submit={handleSubmit}> | ||
<Input | ||
{value} | ||
on:keypress={handleChange} | ||
placeholder="Email address" | ||
class={cn('twsv-pr-16 twsv-text-base', shownError && '!twsv-border-red-500')} | ||
/> | ||
<div | ||
class="twsv-absolute twsv-right-0 twsv-top-1/2 twsv-h-12 twsv-w-12 -twsv-translate-y-1/2 twsv-p-px" | ||
> | ||
<Button | ||
size="auto" | ||
variant="ghost" | ||
class={cn( | ||
'twsv-h-full twsv-w-full twsv-rounded-l-none twsv-p-2 twsv-text-muted-foreground !twsv-outline-none !twsv-ring-0 !twsv-ring-offset-0 focus-visible:twsv-bg-secondary/50 focus-visible:twsv-text-secondary-foreground' | ||
)} | ||
type="submit" | ||
on:click={() => { | ||
showError = true; | ||
}} | ||
> | ||
<ArrowRight /> | ||
</Button> | ||
</div> | ||
</form> | ||
{#if shownError} | ||
<p class="twsv-mt-1 twsv-text-sm twsv-text-red-500">{shownError}</p> | ||
{/if} |
This file contains 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 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,29 @@ | ||
import Root from "./input.svelte"; | ||
|
||
export type FormInputEvent<T extends Event = Event> = T & { | ||
currentTarget: EventTarget & HTMLInputElement; | ||
}; | ||
export type InputEvents = { | ||
blur: FormInputEvent<FocusEvent>; | ||
change: FormInputEvent<Event>; | ||
click: FormInputEvent<MouseEvent>; | ||
focus: FormInputEvent<FocusEvent>; | ||
focusin: FormInputEvent<FocusEvent>; | ||
focusout: FormInputEvent<FocusEvent>; | ||
keydown: FormInputEvent<KeyboardEvent>; | ||
keypress: FormInputEvent<KeyboardEvent>; | ||
keyup: FormInputEvent<KeyboardEvent>; | ||
mouseover: FormInputEvent<MouseEvent>; | ||
mouseenter: FormInputEvent<MouseEvent>; | ||
mouseleave: FormInputEvent<MouseEvent>; | ||
mousemove: FormInputEvent<MouseEvent>; | ||
paste: FormInputEvent<ClipboardEvent>; | ||
input: FormInputEvent<InputEvent>; | ||
wheel: FormInputEvent<WheelEvent>; | ||
}; | ||
|
||
export { | ||
Root, | ||
// | ||
Root as Input, | ||
}; |
Oops, something went wrong.