diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index e747deda..2d93fc29 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -11,7 +11,8 @@ const { ErrorCode } = Constants const { sendPaymentV2Invoice, - decodePayReq + decodePayReq, + myLNDPub } = require('../../../utils/lightningServices/v2') /** @@ -21,6 +22,7 @@ const { const Getters = require('./getters') const Key = require('./key') const Utils = require('./utils') +const { writeCoordinate } = require('../../coordinates') /** * @typedef {import('./SimpleGUN').GUNNode} GUNNode @@ -1074,6 +1076,26 @@ const sendSpontaneousPayment = async ( payment_request: orderResponse.response }) + await writeCoordinate(payment.payment_hash, { + id: payment.payment_hash, + type: (() => { + if (opts.type === 'post') { + return 'tip' + } else if (opts.type === 'user') { + return 'spontaneousPayment' + } + // ensures we handle all possible types + /** @type {never} */ + const assertNever = opts.type + + return assertNever && opts.type // please TS + })(), + amount: Number(payment.value_sat), + inbound: false, + timestamp: Date.now(), + toLndPub: await myLNDPub() + }) + return payment } catch (e) { logger.error('Error inside sendPayment()')