import { useCallback } from 'react'
import { boolean, object } from 'yup'
import { Button } from 'react-bootstrap'
import { Form, ClientInput, SubmitButton, Checkbox } from '@/components/form'
import { useMe } from '@/components/me'
import { useShowModal } from '@/components/modal'
import Link from 'next/link'
import { useWallet } from '@/wallets/index'
import { useWalletConfigurator } from '@/wallets/config'
import styles from '@/styles/wallet.module.css'
import { externalLightningAddressValidator } from '@/lib/validate'
import { autowithdrawInitial } from '@/components/autowithdraw-shared'
import { useMutation } from '@apollo/client'
import { HIDE_WALLET_RECV_PROMPT_MUTATION } from '@/fragments/users'
import { useToast } from '@/components/toast'
export class WalletPromptClosed extends Error {
constructor () {
super('wallet prompt closed')
}
}
export function useWalletRecvPrompt () {
const { me } = useMe()
const showModal = useShowModal()
const toaster = useToast()
const onAttach = useCallback(({ onClose, resolve }) =>
() => {
toaster.success('lightning address saved', { persistOnNavigate: true })
resolve()
onClose()
}, [toaster])
const onSkip = useCallback(({ onClose, resolve }) =>
() => {
resolve()
onClose()
}, [])
return useCallback((e) => {
return new Promise((resolve, reject) => {
// TODO: check if user told us to not show again
if (!me || me.optional?.hasRecvWallet || me.privates?.hideWalletRecvPrompt) return resolve()
showModal(onClose => {
return (
<>