diff --git a/api/resolvers/wallet.js b/api/resolvers/wallet.js index cec6cb2a..2d6c8626 100644 --- a/api/resolvers/wallet.js +++ b/api/resolvers/wallet.js @@ -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 } diff --git a/api/typeDefs/wallet.js b/api/typeDefs/wallet.js index e16897c0..ce05cde5 100644 --- a/api/typeDefs/wallet.js +++ b/api/typeDefs/wallet.js @@ -86,6 +86,7 @@ export default gql` satsFeePaid: Int status: String autoWithdraw: Boolean! + preimage: String } type Fact { diff --git a/fragments/wallet.js b/fragments/wallet.js index bcbb658e..9aa654c2 100644 --- a/fragments/wallet.js +++ b/fragments/wallet.js @@ -31,6 +31,7 @@ export const WITHDRAWL = gql` satsFeePaid status autoWithdraw + preimage } }` diff --git a/pages/withdrawals/[id].js b/pages/withdrawals/[id].js index 601291bb..9b9f9deb 100644 --- a/pages/withdrawals/[id].js +++ b/pages/withdrawals/[id].js @@ -112,7 +112,7 @@ function LoadWithdrawl () {
- +