diff --git a/components/Paybutton/PaybuttonTrigger.tsx b/components/Paybutton/PaybuttonTrigger.tsx index 56c5d7e41..5f72f8a1b 100644 --- a/components/Paybutton/PaybuttonTrigger.tsx +++ b/components/Paybutton/PaybuttonTrigger.tsx @@ -213,6 +213,8 @@ export default ({ paybuttonId, emailCredits }: IProps): JSX.Element => {
<opReturn>
<signature>
<inputAddresses>
+
<value>
+ {/* Tooltip */} diff --git a/constants/index.ts b/constants/index.ts index fac95ffd6..c646db747 100644 --- a/constants/index.ts +++ b/constants/index.ts @@ -241,7 +241,8 @@ export const TRIGGER_POST_VARIABLES = [ '', '', '', - '' + '', + '' ] export const PAYBUTTON_TRANSACTIONS_FILE_HEADERS = { diff --git a/services/transactionService.ts b/services/transactionService.ts index 4fa9a8d2a..6b58bf98e 100644 --- a/services/transactionService.ts +++ b/services/transactionService.ts @@ -10,7 +10,7 @@ import { OpReturnData, parseAddress } from 'utils/validators' import { generatePaymentFromTx } from 'redis/paymentCache' import { ButtonDisplayData, Payment } from 'redis/types' -export function getTransactionValue (transaction: TransactionWithPrices | TransactionsWithPaybuttonsAndPrices): QuoteValues { +export function getTransactionValue (transaction: TransactionWithPrices | TransactionsWithPaybuttonsAndPrices | SimplifiedTransaction): QuoteValues { const ret: QuoteValues = { usd: new Prisma.Decimal(0), cad: new Prisma.Decimal(0) @@ -62,7 +62,8 @@ export function getSimplifiedTrasaction (tx: TransactionWithAddressAndPrices, in timestamp, message: parsedOpReturn?.message ?? '', rawMessage: parsedOpReturn?.rawMessage ?? '', - inputAddresses: inputAddresses ?? [] + inputAddresses: inputAddresses ?? [], + prices: tx.prices } return simplifiedTransaction diff --git a/services/triggerService.ts b/services/triggerService.ts index 9598f083d..a7ac4494c 100644 --- a/services/triggerService.ts +++ b/services/triggerService.ts @@ -1,12 +1,13 @@ import { PaybuttonTrigger, Prisma, UserProfile } from '@prisma/client' import axios from 'axios' -import { RESPONSE_MESSAGES, NETWORK_TICKERS_FROM_ID } from 'constants/index' +import { RESPONSE_MESSAGES, NETWORK_TICKERS_FROM_ID, SUPPORTED_QUOTES_FROM_ID } from 'constants/index' import prisma from 'prisma/clientInstance' import { EMPTY_OP_RETURN, OpReturnData, parseTriggerPostData } from 'utils/validators' import { BroadcastTxData } from 'ws-service/types' import { fetchPaybuttonById, fetchPaybuttonWithTriggers } from './paybuttonService' import config from 'config' import { MAIL_FROM, MAIL_HTML_REPLACER, MAIL_SUBJECT, getMailerTransporter, SendEmailParameters } from 'constants/mail' +import { getTransactionValue } from './transactionService' const triggerWithPaybutton = Prisma.validator()({ include: { paybutton: true } @@ -247,7 +248,7 @@ export async function executeAddressTriggers (broadcastTxData: BroadcastTxData, rawMessage, inputAddresses } = tx - + const values = getTransactionValue(tx) const addressTriggers = await fetchTriggersForAddress(address) if (addressTriggers.length === 0) return console.log(`[TRIGGER ${currency}]: Will execute ${addressTriggers.length} triggers for tx ${hash} and address ${address}`) @@ -255,6 +256,8 @@ export async function executeAddressTriggers (broadcastTxData: BroadcastTxData, // Send post requests const posterTriggers = addressTriggers.filter(t => !t.isEmailTrigger) await Promise.all(posterTriggers.map(async (trigger) => { + const userProfile = await fetchUserFromTriggerId(trigger.id) + const quoteSlug = SUPPORTED_QUOTES_FROM_ID[userProfile.preferredCurrencyId] const postDataParameters: PostDataParameters = { amount, currency, @@ -269,8 +272,10 @@ export async function executeAddressTriggers (broadcastTxData: BroadcastTxData, rawMessage } : EMPTY_OP_RETURN, - inputAddresses + inputAddresses, + value: values[quoteSlug].toString() } + await postDataForTrigger(trigger, postDataParameters) })) @@ -399,6 +404,7 @@ export interface PostDataParameters { address: string opReturn: OpReturnData inputAddresses?: string[] + value: string } async function postDataForTrigger (trigger: TriggerWithPaybutton, postDataParameters: PostDataParameters): Promise { diff --git a/tests/unittests/validators.test.ts b/tests/unittests/validators.test.ts index b405e99ee..6bbf8dd2e 100644 --- a/tests/unittests/validators.test.ts +++ b/tests/unittests/validators.test.ts @@ -413,7 +413,8 @@ describe('Signature payload', () => { message: 'my custom opReturn data', paymentId: '123paymentId', rawMessage: 'my custom opReturn data' - } + }, + value: '0.0002189581274' } it('Gets payload for single variable', () => { const postData = '{"myVar": 3, "amount": }' @@ -457,7 +458,8 @@ describe('Signature payload', () => { message: '', paymentId: '', rawMessage: '' - } + }, + value: '0.0002189581274' } const postData = '{"id": , "coin": , "myVar": 3, "OP_RETURN": , "name": , "amount": , "ts": }' const result = v.exportedForTesting.getSignaturePayload(postData, params) @@ -482,7 +484,8 @@ describe('Sign post data', () => { message: 'my custom opReturn data', paymentId: '123paymentId', rawMessage: 'my custom opReturn data' - } + }, + value: '0.0002189581274' } it('Sign full payload', () => { const postData = '{"id": , "coin": , "myVar": 3, "OP_RETURN": , "to":
, "name": , "amount": , "ts": }' diff --git a/utils/validators.ts b/utils/validators.ts index 98cd6d571..27f20eb0e 100644 --- a/utils/validators.ts +++ b/utils/validators.ts @@ -273,6 +273,8 @@ export function parseTriggerPostData ({ userId, postData, postDataParameters }: .replace('', opReturn) .replace('', `${JSON.stringify(signature, undefined, 2)}`) .replace('', `${JSON.stringify(postDataParameters.inputAddresses, undefined, 2)}`) + .replace('', `"${postDataParameters.value}"`) + const parsedResultingData = JSON.parse(resultingData) return parsedResultingData } catch (err: any) { @@ -316,7 +318,8 @@ export const parsePaybuttonTriggerPOSTRequest = function (params: PaybuttonTrigg address: '', timestamp: 0, opReturn: EMPTY_OP_RETURN, - inputAddresses: [] + inputAddresses: [], + value: '' } const parsed = parseTriggerPostData({ userId: params.userId, diff --git a/ws-service/types.ts b/ws-service/types.ts index 827fe5866..9cafc5928 100644 --- a/ws-service/types.ts +++ b/ws-service/types.ts @@ -18,6 +18,12 @@ export interface SimplifiedTransaction { address: string rawMessage: string inputAddresses: string[] + prices: Array<{ + price: { + value: Prisma.Decimal + quoteId: number + } + }> } export interface CreateQuoteAndShiftData {