Show preimage of confirmed withdrawals (#1106)

* Show preimage of confirmed withdrawals

* Assign preimage in one-liner
This commit is contained in:
ekzyis 2024-04-26 02:33:24 +02:00 committed by GitHub
parent 13eda4c120
commit 95b03c4bbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import { getIdentity, createHodlInvoice, createInvoice, decodePaymentRequest, payViaPaymentRequest, cancelHodlInvoice, getInvoice as getInvoiceFromLnd, getNode, authenticatedLndGrpc, deletePayment } from 'ln-service'
import { getIdentity, createHodlInvoice, createInvoice, decodePaymentRequest, payViaPaymentRequest, cancelHodlInvoice, getInvoice as getInvoiceFromLnd, getNode, authenticatedLndGrpc, deletePayment, getPayment } from 'ln-service'
import { GraphQLError } from 'graphql'
import crypto from 'crypto'
import serialize from './serial'
@ -45,8 +45,7 @@ export async function getInvoice (parent, { id }, { me, models, lnd }) {
try {
if (inv.confirmedAt) {
const lnInv = await getInvoiceFromLnd({ id: inv.hash, lnd })
inv.confirmedPreimage = lnInv.secret
inv.confirmedPreimage = (await getInvoiceFromLnd({ id: inv.hash, lnd })).secret
}
} catch (err) {
console.error('error fetching invoice from LND', err)
@ -55,7 +54,7 @@ export async function getInvoice (parent, { id }, { me, models, lnd }) {
return inv
}
export async function getWithdrawl (parent, { id }, { me, models }) {
export async function getWithdrawl (parent, { id }, { me, models, lnd }) {
if (!me) {
throw new GraphQLError('you must be logged in', { extensions: { code: 'FORBIDDEN' } })
}
@ -77,6 +76,14 @@ export async function getWithdrawl (parent, { id }, { me, models }) {
throw new GraphQLError('not ur withdrawal', { extensions: { code: 'FORBIDDEN' } })
}
try {
if (wdrwl.status === 'CONFIRMED') {
wdrwl.preimage = (await getPayment({ id: wdrwl.hash, lnd })).payment.secret
}
} catch (err) {
console.error('error fetching payment from LND', err)
}
return wdrwl
}

View File

@ -86,6 +86,7 @@ export default gql`
satsFeePaid: Int
status: String
autoWithdraw: Boolean!
preimage: String
}
type Fact {

View File

@ -31,6 +31,7 @@ export const WITHDRAWL = gql`
satsFeePaid
status
autoWithdraw
preimage
}
}`

View File

@ -112,7 +112,7 @@ function LoadWithdrawl () {
</div>
<InvoiceStatus variant={variant} status={status} />
<div className='w-100 mt-3'>
<Bolt11Info bolt11={data.withdrawl.bolt11}>
<Bolt11Info bolt11={data.withdrawl.bolt11} preimage={data.withdrawl.preimage}>
<PrivacyOption wd={data.withdrawl} />
</Bolt11Info>
</div>