ekzyis 4961cc045b
Allow deletion of wallet logs (#1101)
* Allow deletion of wallet logs

* Refactor wallet logs client<>server glue code

* Use variant='link' and className='text-muted fw-bold nav-link' for clear & cancel

There is a bug though: 'clear' stays highlighted after modal is closed

* Include wallet in toast

* Delete logs on logout

* Fix ugly wallet name in confirm dialog

* Fix clear still highlighted after modal closed

* Only delete client wallet logs

* Fix ugly wallet name in toast

* Fix bad search and replace

* Use Wallet object as constant

* Also delete LNC logs on logout

---------

Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
2024-05-03 14:14:33 -05:00

93 lines
2.9 KiB
JavaScript

import { getGetServerSideProps } from '@/api/ssrApollo'
import { Form, ClientCheckbox, PasswordInput } from '@/components/form'
import { CenterLayout } from '@/components/layout'
import { WalletButtonBar, WalletCard, isConfigured } from '@/components/wallet-card'
import { nwcSchema } from '@/lib/validate'
import { useToast } from '@/components/toast'
import { useRouter } from 'next/router'
import { useNWC } from '@/components/webln/nwc'
import { WalletSecurityBanner } from '@/components/banners'
import { useWebLNConfigurator } from '@/components/webln'
import WalletLogs from '@/components/wallet-logs'
import { Wallet } from '@/lib/constants'
export const getServerSideProps = getGetServerSideProps({ authRequired: true })
export default function NWC () {
const { provider, enabledProviders, setProvider } = useWebLNConfigurator()
const nwc = useNWC()
const { name, nwcUrl, saveConfig, clearConfig, status } = nwc
const isDefault = provider?.name === name
const configured = isConfigured(status)
const toaster = useToast()
const router = useRouter()
return (
<CenterLayout>
<h2 className='pb-2'>Nostr Wallet Connect</h2>
<h6 className='text-muted text-center pb-3'>use Nostr Wallet Connect for payments</h6>
<WalletSecurityBanner />
<Form
initial={{
nwcUrl: nwcUrl || '',
isDefault: isDefault || false
}}
schema={nwcSchema}
onSubmit={async ({ isDefault, ...values }) => {
try {
await saveConfig(values)
if (isDefault) setProvider(nwc)
toaster.success('saved settings')
router.push('/settings/wallets')
} catch (err) {
console.error(err)
toaster.danger('failed to attach: ' + err.message || err.toString?.())
}
}}
>
<PasswordInput
initialValue={nwcUrl}
label='connection'
name='nwcUrl'
newPass
required
autoFocus
/>
<ClientCheckbox
disabled={!configured || isDefault || enabledProviders.length === 1}
initialValue={isDefault}
label='default payment method'
name='isDefault'
/>
<WalletButtonBar
status={status} onDelete={async () => {
try {
await clearConfig()
toaster.success('saved settings')
router.push('/settings/wallets')
} catch (err) {
console.error(err)
toaster.danger('failed to detach: ' + err.message || err.toString?.())
}
}}
/>
</Form>
<div className='mt-3 w-100'>
<WalletLogs wallet={Wallet.NWC} embedded />
</div>
</CenterLayout>
)
}
export function NWCCard () {
const { status } = useNWC()
return (
<WalletCard
title='NWC'
badges={['send only', 'non-custodialish', 'budgetable']}
provider='nwc'
status={status}
/>
)
}