predikt/oracle/web/components/onboarding-verify-phone.tsx
caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
Working tree is now the canonical repo. Off-chain play-money + trustless on-chain
(FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution,
mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 23:29:50 +03:00

157 lines
4.6 KiB
TypeScript

import { Col } from 'web/components/layout/col'
import { Button } from 'web/components/buttons/button'
import { api } from 'web/lib/api/api'
import { useState } from 'react'
import { Input } from 'web/components/widgets/input'
import { PhoneInput } from 'react-international-phone'
import { toast } from 'react-hot-toast'
import 'react-international-phone/style.css'
import { Title } from 'web/components/widgets/title'
import { Row } from 'web/components/layout/row'
import { PHONE_VERIFICATION_BONUS } from 'common/economy'
import { formatMoney } from 'common/util/format'
import { track } from 'web/lib/service/analytics'
import { TokenNumber } from 'web/components/widgets/token-number'
import clsx from 'clsx'
export const StyledPhoneInput = (props: {
phoneNumber: string
setPhoneNumber: (phone: string) => void
className?: string
}) => {
const { phoneNumber, setPhoneNumber, className } = props
return (
<PhoneInput
defaultCountry={'us'}
value={phoneNumber}
onChange={(phone) => setPhoneNumber(phone)}
placeholder={'Phone Number'}
className={clsx('mx-auto mb-1', className)}
inputClassName="!bg-canvas-0 !border-ink-300 !text-ink-1000 !text-sm !px-4 !py-6"
countrySelectorStyleProps={{
buttonClassName: '!bg-transparent !border-ink-300 !px-2 !py-6',
}}
/>
)
}
export function OnboardingVerifyPhone(props: { onClose: () => void }) {
const { onClose } = props
const requestOTP = async () => {
setLoading(true)
await toast
.promise(
api('request-otp', {
phoneNumber,
}),
{
loading: 'Sending code to your phone...',
success: 'Code sent! Check your phone.',
error: (e) => e.message,
}
)
.then(() => setPage(1))
.catch((e) => console.error(e))
.finally(() => setLoading(false))
}
const verifyPhone = async () => {
setLoading(true)
await toast
.promise(
api('verify-phone-number', {
phoneNumber,
code: otp,
}),
{
loading: 'Verifying code...',
success: 'Phone verified!',
error: (e) => e.message,
}
)
.then(() => onClose())
.catch((e) => console.error(e))
.finally(() => setLoading(false))
await track('verify phone')
}
const [loading, setLoading] = useState(false)
const [otp, setOtp] = useState('')
const [phoneNumber, setPhoneNumber] = useState('')
const [page, setPage] = useState(0)
return (
<Col className="text-lg">
{page === 0 && (
<Col className="items-center justify-center gap-2">
<span className={'mb-2 mt-2 text-center text-xl'}>
Verify your phone number to collect a{' '}
<TokenNumber
amount={PHONE_VERIFICATION_BONUS}
className={'font-bold'}
isInline
/>{' '}
signup bonus.
<br />
<br />
<span className={'text-lg italic'}>
(We won't send you any other messages.)
</span>
</span>
<StyledPhoneInput
phoneNumber={phoneNumber}
setPhoneNumber={setPhoneNumber}
/>
<Row
className={
'mb-4 mt-4 w-full justify-between px-8 sm:mt-8 sm:justify-center sm:gap-8'
}
>
<Button color={'gray-white'} onClick={onClose}>
Skip
</Button>
<Button
disabled={phoneNumber.length < 7 || loading}
loading={loading}
onClick={requestOTP}
>
Request code
</Button>
</Row>
</Col>
)}
{page === 1 && (
<Col className="h-full items-center justify-between gap-2 sm:justify-start">
<Col className={'gap-2'}>
<Title>Enter verification code</Title>
<Input
type={'number'}
className={'w-36 self-center'}
value={otp}
onChange={(e) => setOtp(e.target.value)}
placeholder="123456"
/>
</Col>
<Row
className={
'mb-4 mt-4 w-full justify-between px-8 sm:mt-8 sm:justify-center sm:gap-8'
}
>
<Button color={'gray-white'} onClick={() => setPage(0)}>
Back
</Button>
<Button
disabled={otp.length < 6 || loading}
loading={loading}
onClick={verifyPhone}
>
Verify & claim {formatMoney(PHONE_VERIFICATION_BONUS)}
</Button>
</Row>
</Col>
)}
</Col>
)
}