Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/services/ibex/webhook-server/routes/on-receive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,37 @@ const sendLightningNotification = async (
next()
}

const sendOnchainNotification = async (
req: PaymentRequest,
res: Response,
next: NextFunction
) => {
if (!req.paymentContext) return next()

const { transaction } = req.body;

const { receiverWallet, recipientAccount, recipientUser } = req.paymentContext;

const nResp = await NotificationsService().onChainTxReceived({
recipientAccountId: recipientAccount.id,
recipientWalletId: receiverWallet.id,
paymentAmount: toPaymentAmount(receiverWallet.currency)(transaction.amount),
displayPaymentAmount: await toDisplayAmount(recipientAccount.displayCurrency)(transaction.amount),
recipientDeviceTokens: recipientUser.deviceTokens,
recipientNotificationSettings: recipientAccount.notificationSettings,
recipientLanguage: recipientUser.language,
txHash: transaction.hash
})

if (nResp instanceof DeviceTokensNotRegisteredNotificationsServiceError) {
await removeDeviceTokens({ userId: recipientUser.id, deviceTokens: nResp.tokens })
} else if (nResp instanceof NotificationsServiceError) {
logger.error(nResp)
}

next()
}

const sendZapReceipt = async (
req: PaymentRequest,
_resp: Response,
Expand Down Expand Up @@ -169,8 +200,8 @@ router.post(paths.cashout, authenticate, logRequest, (_req, resp) => {
resp.status(200).end()
})

router.post(paths.onchain, authenticate, logRequest, (_req, resp) => {
baseLogger.info("Received onchain payment (not implemented).")
router.post(paths.onchain, authenticate, logRequest, fetchPaymentContext, sendOnchainNotification, (_req, resp) => {
baseLogger.info("Received onchain payment.")
resp.status(200).end()
})

Expand Down