11import { PaybuttonTrigger , Prisma , UserProfile } from '@prisma/client'
22import axios from 'axios'
3- import { RESPONSE_MESSAGES , NETWORK_TICKERS_FROM_ID } from 'constants/index'
3+ import { RESPONSE_MESSAGES , NETWORK_TICKERS_FROM_ID , SUPPORTED_QUOTES_FROM_ID } from 'constants/index'
44import prisma from 'prisma/clientInstance'
55import { EMPTY_OP_RETURN , OpReturnData , parseTriggerPostData } from 'utils/validators'
66import { BroadcastTxData } from 'ws-service/types'
77import { fetchPaybuttonById , fetchPaybuttonWithTriggers } from './paybuttonService'
88import config from 'config'
99import { MAIL_FROM , MAIL_HTML_REPLACER , MAIL_SUBJECT , getMailerTransporter , SendEmailParameters } from 'constants/mail'
10+ import { getTransactionValue } from './transactionService'
1011
1112const triggerWithPaybutton = Prisma . validator < Prisma . PaybuttonTriggerDefaultArgs > ( ) ( {
1213 include : { paybutton : true }
@@ -247,14 +248,16 @@ export async function executeAddressTriggers (broadcastTxData: BroadcastTxData,
247248 rawMessage,
248249 inputAddresses
249250 } = tx
250-
251+ const values = getTransactionValue ( tx )
251252 const addressTriggers = await fetchTriggersForAddress ( address )
252253 if ( addressTriggers . length === 0 ) return
253254 console . log ( `[TRIGGER ${ currency } ]: Will execute ${ addressTriggers . length } triggers for tx ${ hash } and address ${ address } ` )
254255
255256 // Send post requests
256257 const posterTriggers = addressTriggers . filter ( t => ! t . isEmailTrigger )
257258 await Promise . all ( posterTriggers . map ( async ( trigger ) => {
259+ const userProfile = await fetchUserFromTriggerId ( trigger . id )
260+ const quoteSlug = SUPPORTED_QUOTES_FROM_ID [ userProfile . preferredCurrencyId ]
258261 const postDataParameters : PostDataParameters = {
259262 amount,
260263 currency,
@@ -269,8 +272,10 @@ export async function executeAddressTriggers (broadcastTxData: BroadcastTxData,
269272 rawMessage
270273 }
271274 : EMPTY_OP_RETURN ,
272- inputAddresses
275+ inputAddresses,
276+ value : values [ quoteSlug ] . toString ( )
273277 }
278+
274279 await postDataForTrigger ( trigger , postDataParameters )
275280 } ) )
276281
@@ -391,6 +396,7 @@ export interface PostDataParameters {
391396 address : string
392397 opReturn : OpReturnData
393398 inputAddresses ?: string [ ]
399+ value : string
394400}
395401
396402async function postDataForTrigger ( trigger : TriggerWithPaybutton , postDataParameters : PostDataParameters ) : Promise < void > {
0 commit comments