2024-04-27 02:22:30 +00:00
import { getGetServerSideProps } from '@/api/ssrApollo'
import { WalletSecurityBanner } from '@/components/banners'
import { ClientCheckbox , Form , PasswordInput } from '@/components/form'
import Info from '@/components/info'
import { CenterLayout } from '@/components/layout'
import Text from '@/components/text'
import { useToast } from '@/components/toast'
2024-04-28 00:02:16 +00:00
import { WalletButtonBar , WalletCard , isConfigured } from '@/components/wallet-card'
2024-04-27 02:22:30 +00:00
import WalletLogs from '@/components/wallet-logs'
import { Status , useWebLNConfigurator } from '@/components/webln'
import { XXX _DEFAULT _PASSWORD , useLNC } from '@/components/webln/lnc'
import { lncSchema } from '@/lib/validate'
import { useRouter } from 'next/router'
import { useEffect , useRef } from 'react'
2024-05-03 19:14:33 +00:00
import { Wallet } from '@/lib/constants'
2024-04-27 02:22:30 +00:00
export const getServerSideProps = getGetServerSideProps ( { authRequired : true } )
export default function LNC ( ) {
const { provider , enabledProviders , setProvider } = useWebLNConfigurator ( )
const toaster = useToast ( )
const router = useRouter ( )
const lnc = useLNC ( )
const { status , clearConfig , saveConfig , config , name , unlock } = lnc
const isDefault = provider ? . name === name
const unlocking = useRef ( false )
2024-04-28 00:02:16 +00:00
const configured = isConfigured ( status )
2024-04-27 02:22:30 +00:00
useEffect ( ( ) => {
if ( ! unlocking . current && status === Status . Locked ) {
unlocking . current = true
unlock ( )
}
} , [ status , unlock ] )
const defaultPassword = config ? . password === XXX _DEFAULT _PASSWORD
return (
< CenterLayout >
< h2 > Lightning Node Connect for LND < / h 2 >
< h6 className = 'text-muted text-center pb-3' > use Lightning Node Connect for LND payments < / h 6 >
< WalletSecurityBanner / >
< Form
initial = { {
pairingPhrase : config ? . pairingPhrase || '' ,
password : ( ! config ? . password || defaultPassword ) ? '' : config . password
} }
schema = { lncSchema }
onSubmit = { async ( { isDefault , ... values } ) => {
try {
await saveConfig ( values )
if ( isDefault ) setProvider ( lnc )
toaster . success ( 'saved settings' )
router . push ( '/settings/wallets' )
} catch ( err ) {
console . error ( err )
toaster . danger ( 'failed to attach: ' + err . message || err . toString ? . ( ) )
}
} }
>
< PasswordInput
label = {
< div className = 'd-flex align-items-center' > pairing phrase
< Info label = 'help' >
< Text >
2024-05-03 00:46:27 +00:00
{ 'We only need permissions for the uri `/lnrpc.Lightning/SendPaymentSync`\n\nCreate a budgeted account with narrow permissions:\n\n```$ litcli accounts create --balance <budget>```\n\n```$ litcli sessions add --type custom --label <your label> --account_id <account_id> --uri /lnrpc.Lightning/SendPaymentSync```\n\nGrab the `pairing_secret_mnemonic` from the output and paste it here.' }
2024-04-27 02:22:30 +00:00
< / T e x t >
< / I n f o >
< / d i v >
}
name = 'pairingPhrase'
initialValue = { config ? . pairingPhrase }
newPass = { config ? . pairingPhrase === undefined }
2024-04-28 00:02:16 +00:00
readOnly = { configured }
2024-04-27 02:22:30 +00:00
required
autoFocus
/ >
< PasswordInput
label = { < > password < small className = 'text-muted ms-2' > optional < /small></ > }
name = 'password'
initialValue = { defaultPassword ? '' : config ? . password }
newPass = { config ? . password === undefined || defaultPassword }
2024-04-28 00:02:16 +00:00
readOnly = { configured }
2024-04-27 02:22:30 +00:00
hint = 'encrypts your pairing phrase when stored locally'
/ >
< ClientCheckbox
2024-04-28 18:03:37 +00:00
disabled = { ! configured || isDefault || enabledProviders ? . length === 1 }
2024-04-27 02:22:30 +00:00
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 )
2024-04-27 23:37:31 +00:00
toaster . danger ( 'failed to detach: ' + err . message || err . toString ? . ( ) )
2024-04-27 02:22:30 +00:00
}
} }
/ >
< / F o r m >
< div className = 'mt-3 w-100' >
2024-05-03 19:14:33 +00:00
< WalletLogs wallet = { Wallet . LNC } embedded / >
2024-04-27 02:22:30 +00:00
< / d i v >
< / C e n t e r L a y o u t >
)
}
export function LNCCard ( ) {
const { status } = useLNC ( )
return (
< WalletCard
title = 'LNC'
badges = { [ 'send only' , 'non-custodial' , 'budgetable' ] }
provider = 'lnc'
status = { status }
/ >
)
}