import { useRouter } from 'next/router' import { Form, Input, SubmitButton } from '../components/form' import Link from 'next/link' import Button from 'react-bootstrap/Button' import * as Yup from 'yup' import { gql, useMutation } from '@apollo/client' import { LnQRSkeleton } from '../components/lnqr' import LayoutCenter from '../components/layout-center' import InputGroup from 'react-bootstrap/InputGroup' import { WithdrawlSkeleton } from './withdrawals/[id]' import { useMe } from '../components/me' import { useEffect } from 'react' import { requestProvider } from 'webln' export async function getServerSideProps () { return { props: {} } } export default function Wallet () { return ( ) } function YouHaveSats () { const me = useMe() return (

you have {me && me.sats} sats

) } export function WalletForm () { const router = useRouter() if (!router.query.type) { return (
or
) } if (router.query.type === 'fund') { return } else { return } } export const FundSchema = Yup.object({ amount: Yup.number().typeError('must be a number').required('required') .positive('must be positive').integer('must be whole') }) export function FundForm () { const router = useRouter() const [createInvoice, { called, error }] = useMutation(gql` mutation createInvoice($amount: Int!) { createInvoice(amount: $amount) { id } }`) if (called && !error) { return } return ( <>
{ const { data } = await createInvoice({ variables: { amount: Number(amount) } }) router.push(`/invoices/${data.createInvoice.id}`) }} > sats} /> generate invoice
) } export const WithdrawlSchema = Yup.object({ invoice: Yup.string().required('required'), maxFee: Yup.number().typeError('must be a number').required('required') .min(0, 'must be positive').integer('must be whole') }) const MAX_FEE_DEFAULT = 10 export function WithdrawlForm () { const router = useRouter() const me = useMe() const [createWithdrawl, { called, error }] = useMutation(gql` mutation createWithdrawl($invoice: String!, $maxFee: Int!) { createWithdrawl(invoice: $invoice, maxFee: $maxFee) { id } }`) useEffect(async () => { try { const provider = await requestProvider() const { paymentRequest: invoice } = await provider.makeInvoice({ defaultMemo: `Withdrawal for @${me.name} on SN` }) const { data } = await createWithdrawl({ variables: { invoice, maxFee: MAX_FEE_DEFAULT } }) router.push(`/withdrawals/${data.createWithdrawl.id}`) } catch (e) { console.log(e.message) } }, []) if (called && !error) { return } return ( <>
{ const { data } = await createWithdrawl({ variables: { invoice, maxFee: Number(maxFee) } }) router.push(`/withdrawals/${data.createWithdrawl.id}`) }} > sats} /> withdraw
) }