798253f887
* Challenge bets * Store avatar url * Fix before and after probs * Check balance before creation * Calculate winning shares * pretty * Change winning value * Set shares to equal each other * Fix share challenge link * pretty * remove lib refs * Probability of bet is set to market * Remove peer pill * Cleanup * Button on contract page * don't show challenge if not binary or if resolved * challenge button (WIP) * fix accept challenge: don't change pool/probability * Opengraph preview [WIP] * elim lib * Edit og card props * Change challenge text * New card gen attempt * Get challenge on server * challenge button styling * Use env domain * Remove other window ref * Use challenge creator as avatar * Remove user name * Remove s from property, replace prob with outcome * challenge form * share text * Add in challenge parts to template and url * Challenge url params optional * Add challenge params to parse request * Parse please * Don't remove prob * Challenge card styling * Challenge card styling * Challenge card styling * Challenge card styling * Challenge card styling * Challenge card styling * Challenge card styling * Challenge card styling * Add to readme about how to dev og-image * Add emojis * button: gradient background, 2xl size * beautify accept bet screen * update question button * Add separate challenge template * Accepted challenge sharing card, fix accept bet call * accept challenge button * challenge winner page * create challenge screen * Your outcome/cost=> acceptorOutcome/cost * New create challenge panel * Fix main merge * Add challenge slug to bet and filter by it * Center title * Add helper text * Add FAQ section * Lint * Columnize the user areas in preview link too * Absolutely position * Spacing * Orientation * Restyle challenges list, cache contract name * Make copying easy on mobile * Link spacing * Fix spacing * qr codes! * put your challenges first * eslint * Changes to contract buttons and create challenge modal * Change titles around for current bet * Add back in contract title after winning * Cleanup * Add challenge enabled flag * Spacing of switch button * Put sharing qr code in modal Co-authored-by: mantikoros <sgrugett@gmail.com>
96 lines
3.0 KiB
TypeScript
96 lines
3.0 KiB
TypeScript
import { useRouter } from 'next/router'
|
|
import { useEffect, useState } from 'react'
|
|
import { SEO } from 'web/components/SEO'
|
|
import { Title } from 'web/components/title'
|
|
import { claimManalink } from 'web/lib/firebase/api'
|
|
import { useManalink } from 'web/lib/firebase/manalinks'
|
|
import { ManalinkCard } from 'web/components/manalink-card'
|
|
import { useUser } from 'web/hooks/use-user'
|
|
import { firebaseLogin, getUser } from 'web/lib/firebase/users'
|
|
import { Row } from 'web/components/layout/row'
|
|
import { Button } from 'web/components/button'
|
|
import { useSaveReferral } from 'web/hooks/use-save-referral'
|
|
import { User } from 'common/user'
|
|
import { Manalink } from 'common/manalink'
|
|
|
|
export default function ClaimPage() {
|
|
const user = useUser()
|
|
const router = useRouter()
|
|
const { slug } = router.query as { slug: string }
|
|
const manalink = useManalink(slug)
|
|
const [claiming, setClaiming] = useState(false)
|
|
const [error, setError] = useState<string | undefined>(undefined)
|
|
|
|
useReferral(user, manalink)
|
|
|
|
if (!manalink) {
|
|
return <></>
|
|
}
|
|
|
|
const info = { ...manalink, uses: manalink.claims.length }
|
|
return (
|
|
<>
|
|
<SEO
|
|
title="Send Mana"
|
|
description="Send mana to anyone via link!"
|
|
url="/send"
|
|
/>
|
|
<div className="mx-auto max-w-xl px-2">
|
|
<Row className="items-center justify-between">
|
|
<Title text={`Claim M$${manalink.amount} mana`} />
|
|
<div className="my-auto"></div>
|
|
</Row>
|
|
|
|
<ManalinkCard info={info} />
|
|
|
|
{error && (
|
|
<section className="my-5 text-red-500">
|
|
<p>Failed to claim manalink.</p>
|
|
<p>{error}</p>
|
|
</section>
|
|
)}
|
|
|
|
<Row className="items-center">
|
|
<Button
|
|
onClick={async () => {
|
|
setClaiming(true)
|
|
try {
|
|
if (user == null) {
|
|
await firebaseLogin()
|
|
setClaiming(false)
|
|
return
|
|
}
|
|
if (user?.id == manalink.fromId) {
|
|
throw new Error("You can't claim your own manalink.")
|
|
}
|
|
await claimManalink({ slug: manalink.slug })
|
|
user && router.push(`/${user.username}?claimed-mana=yes`)
|
|
} catch (e) {
|
|
console.log(e)
|
|
const message =
|
|
e && e instanceof Object ? e.toString() : 'An error occurred.'
|
|
setError(message)
|
|
}
|
|
setClaiming(false)
|
|
}}
|
|
disabled={claiming}
|
|
size="lg"
|
|
>
|
|
{user ? `Claim M$${manalink.amount}` : 'Login to claim'}
|
|
</Button>
|
|
</Row>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
const useReferral = (user: User | undefined | null, manalink?: Manalink) => {
|
|
const [creator, setCreator] = useState<User | undefined>(undefined)
|
|
|
|
useEffect(() => {
|
|
if (manalink?.fromId) getUser(manalink.fromId).then(setCreator)
|
|
}, [manalink])
|
|
|
|
useSaveReferral(user, { defaultReferrerUsername: creator?.username })
|
|
}
|