2022-01-07 22:56:14 +00:00
|
|
|
import clsx from 'clsx'
|
2022-02-04 03:04:56 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-01-07 22:56:14 +00:00
|
|
|
|
|
|
|
import { useUser } from '../hooks/use-user'
|
|
|
|
import { checkoutURL } from '../lib/service/stripe'
|
|
|
|
import { FundsSelector } from './yes-no-selector'
|
|
|
|
|
|
|
|
export function AddFundsButton(props: { className?: string }) {
|
|
|
|
const { className } = props
|
|
|
|
const user = useUser()
|
|
|
|
|
2022-04-10 00:09:06 +00:00
|
|
|
const [amountSelected, setAmountSelected] = useState<1000 | 2500 | 10000>(
|
|
|
|
2500
|
|
|
|
)
|
2022-01-07 22:56:14 +00:00
|
|
|
|
2022-02-04 03:04:56 +00:00
|
|
|
const location = useLocation()
|
|
|
|
|
2022-01-07 22:56:14 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<label
|
|
|
|
htmlFor="add-funds"
|
|
|
|
className={clsx(
|
2022-02-11 18:40:22 +00:00
|
|
|
'btn btn-xs btn-outline modal-button font-normal normal-case',
|
2022-01-07 22:56:14 +00:00
|
|
|
className
|
|
|
|
)}
|
|
|
|
>
|
2022-01-12 18:43:30 +00:00
|
|
|
Add funds
|
2022-01-07 22:56:14 +00:00
|
|
|
</label>
|
|
|
|
<input type="checkbox" id="add-funds" className="modal-toggle" />
|
|
|
|
|
|
|
|
<div className="modal">
|
|
|
|
<div className="modal-box">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="mb-6 text-xl">Get Manifold Dollars</div>
|
2022-01-07 22:56:14 +00:00
|
|
|
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="mb-6 text-gray-500">
|
2022-01-07 22:56:14 +00:00
|
|
|
Use Manifold Dollars to trade in your favorite markets. <br /> (Not
|
|
|
|
redeemable for cash.)
|
|
|
|
</div>
|
|
|
|
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="mb-2 text-sm text-gray-500">Amount</div>
|
2022-01-07 22:56:14 +00:00
|
|
|
<FundsSelector
|
|
|
|
selected={amountSelected}
|
|
|
|
onSelect={setAmountSelected}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div className="mt-6">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="mb-1 text-sm text-gray-500">Price USD</div>
|
2022-01-07 22:56:14 +00:00
|
|
|
<div className="text-xl">
|
|
|
|
${Math.round(amountSelected / 100)}.00
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="modal-action">
|
|
|
|
<label htmlFor="add-funds" className={clsx('btn btn-ghost')}>
|
|
|
|
Back
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<form
|
2022-02-04 03:04:56 +00:00
|
|
|
action={checkoutURL(user?.id || '', amountSelected, location)}
|
2022-01-07 22:56:14 +00:00
|
|
|
method="POST"
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
type="submit"
|
2022-02-11 18:40:22 +00:00
|
|
|
className="btn btn-primary bg-gradient-to-r from-teal-500 to-green-500 px-10 font-medium hover:from-teal-600 hover:to-green-600"
|
2022-01-07 22:56:14 +00:00
|
|
|
>
|
|
|
|
Checkout
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2022-02-04 03:04:56 +00:00
|
|
|
|
|
|
|
// needed in next js
|
|
|
|
// window not loaded at runtime
|
|
|
|
const useLocation = () => {
|
|
|
|
const [href, setHref] = useState('')
|
|
|
|
useEffect(() => {
|
|
|
|
setHref(window.location.href)
|
|
|
|
}, [])
|
|
|
|
return href
|
|
|
|
}
|