Skip to content
Draft
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
import { Webhook, WebhookEventType } from 'mock-account-service-lib'
import { TenantOptions } from './types'

function cannotHandleWebhook(tenantId: string) {
return process.env.OPERATOR_TENANT_ID && tenantId !== process.env.OPERATOR_TENANT_ID
}

export interface AmountJSON {
value: string
assetCode: string
Expand Down Expand Up @@ -40,6 +44,10 @@ export async function handleOutgoingPaymentCompletedFailed(wh: Webhook) {
throw new Error('Invalid event type when handling outgoing payment webhook')
}
const payment = wh.data
// Don't handle webhook if it is referring to a tenant.
if (
cannotHandleWebhook(wh.tenantId)
) return
const wa = payment['walletAddressId'] as string
const acc = await mockAccounts.getByWalletAddressId(wa)

Expand Down Expand Up @@ -144,6 +152,7 @@ export async function handleIncomingPaymentCompletedExpired(
throw new Error('Invalid event type when handling incoming payment webhook')
}

if (cannotHandleWebhook(wh.tenantId)) return
const payment = wh.data
const wa = payment['walletAddressId'] as string
const acc = await mockAccounts.getByWalletAddressId(wa)
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/webhook/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ async function sendWebhook(
const body = {
id: webhook.event.id,
type: webhook.event.type,
tenantId: webhook.event.tenantId,
data: webhook.event.data
}

Expand Down
1 change: 1 addition & 0 deletions packages/mock-account-service-lib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface Config {
}
export interface Webhook {
id: string
tenantId: string
type: WebhookEventType
data: Record<string, unknown>
}
Expand Down
Loading