stacker.news/pages/credits.js
Keyan 146b60278c
cowboy credits (aka nov-5 (aka jan-3)) (#1678)
* wip adding cowboy credits

* invite gift paid action

* remove balance limit

* remove p2p zap withdrawal notifications

* credits typedefs

* squash migrations

* remove wallet limit stuff

* CCs in item detail

* comments with meCredits

* begin including CCs in item stats/notifications

* buy credits ui/mutation

* fix old /settings/wallets paths

* bios don't get sats

* fix settings

* make invites work with credits

* restore migration from master

* inform backend of send wallets on zap

* satistics header

* default receive options to true and squash migrations

* fix paidAction query

* add nav for credits

* fix forever stacked count

* ek suggested fixes

* fix lint

* fix freebies wrt CCs

* add back disable freebies

* trigger cowboy hat job on CC depletion

* fix meMsats+meMcredits

* Update api/paidAction/README.md

Co-authored-by: ekzyis <ek@stacker.news>

* remove expireBoost migration that doesn't work

---------

Co-authored-by: ekzyis <ek@stacker.news>
2025-01-03 10:33:07 -06:00

109 lines
3.4 KiB
JavaScript

import { getGetServerSideProps } from '@/api/ssrApollo'
import { Form, Input, SubmitButton } from '@/components/form'
import { CenterLayout } from '@/components/layout'
import { useLightning } from '@/components/lightning'
import { useMe } from '@/components/me'
import { useShowModal } from '@/components/modal'
import { usePaidMutation } from '@/components/use-paid-mutation'
import { BUY_CREDITS } from '@/fragments/paidAction'
import { amountSchema } from '@/lib/validate'
import { Button, Col, InputGroup, Row } from 'react-bootstrap'
export const getServerSideProps = getGetServerSideProps({ authRequired: true })
export default function Credits () {
const { me } = useMe()
return (
<CenterLayout footer footerLinks>
<Row className='w-100 d-none d-sm-flex justify-content-center'>
<Col>
<h2 className='text-end me-1 me-md-3'>
<div className='text-monospace'>
{me?.privates?.credits}
</div>
<div className='text-muted'>cowboy credits</div>
<BuyCreditsButton />
</h2>
</Col>
<Col>
<h2 className='text-start ms-1 ms-md-3'>
<div className='text-monospace'>
{me?.privates?.sats - me?.privates?.credits}
</div>
<div className='text-muted'>sats</div>
<Button variant='success mt-3' href='/withdraw'>withdraw sats</Button>
</h2>
</Col>
</Row>
<Row className='w-100 d-flex d-sm-none justify-content-center my-5'>
<Row className='mb-5'>
<h2 className='text-start'>
<div className='text-monospace'>
{me?.privates?.credits}
</div>
<div className='text-muted'>cowboy credits</div>
<BuyCreditsButton />
</h2>
</Row>
<Row>
<h2 className='text-end'>
<div className='text-monospace'>
{me?.privates?.sats - me?.privates?.credits}
</div>
<div className='text-muted'>sats</div>
<Button variant='success mt-3' href='/withdraw'>withdraw sats</Button>
</h2>
</Row>
</Row>
</CenterLayout>
)
}
export function BuyCreditsButton () {
const showModal = useShowModal()
const strike = useLightning()
const [buyCredits] = usePaidMutation(BUY_CREDITS)
return (
<>
<Button
onClick={() => showModal(onClose => (
<Form
initial={{
amount: 10000
}}
schema={amountSchema}
onSubmit={async ({ amount }) => {
const { error } = await buyCredits({
variables: {
credits: Number(amount)
},
onCompleted: () => {
strike()
}
})
onClose()
if (error) throw error
}}
>
<Input
label='amount'
name='amount'
type='number'
required
autoFocus
append={<InputGroup.Text className='text-monospace'>sats</InputGroup.Text>}
/>
<div className='d-flex'>
<SubmitButton variant='secondary' className='ms-auto mt-1 px-4'>buy</SubmitButton>
</div>
</Form>
))}
className='mt-3'
variant='secondary'
>buy credits
</Button>
</>
)
}