From aee2e5fb8fe71835f7d4a004c328d301275b513b Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 25 Jan 2024 00:40:55 -0500 Subject: [PATCH 1/2] allow solana wallets and solana txhashes to create notifications --- .../validators/segmentAndMetadataValidators.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index bd59905..369e6c6 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -6,6 +6,7 @@ import { GIVETH_IO_EVENTS, NETWORK_IDS } from '../utils'; // does not care about calculating values, only validating fields const filterDateRegex = new RegExp('^[0-9]{8} [0-9]{2}:[0-9]{2}:[0-9]{2}$'); const ethereumWalletAddressRegex = /^0x[a-fA-F0-9]{40}$/; +const solanaWalletAddressRegex = /^[A-Za-z0-9]{43,44}$/; const txHashRegex = /^0x[a-fA-F0-9]{64}$/; const tokenSymbolRegex = /^[a-zA-Z0-9]{3,10}$/; @@ -65,14 +66,17 @@ const donationTrackerSchema = Joi.object({ projectOwnerId: Joi.string().allow(null, ''), slug: Joi.string().allow(null, ''), amount: Joi.number()?.greater(0).required(), - transactionId: Joi.string().required().pattern(txHashRegex).messages({ - 'string.pattern.base': errorMessages.INVALID_TRANSACTION_ID, - }), transactionNetworkId: Joi.number().required(), currency: Joi.string().required(), createdAt: Joi.string(), - toWalletAddress: Joi.string().required().pattern(ethereumWalletAddressRegex), - fromWalletAddress: Joi.string().pattern(ethereumWalletAddressRegex), + toWalletAddress: Joi.alternatives().try( + Joi.string().required().pattern(ethereumWalletAddressRegex), + Joi.string().required().pattern(solanaWalletAddressRegex), + ), + fromWalletAddress: Joi.alternatives().try( + Joi.string().required().pattern(ethereumWalletAddressRegex), + Joi.string().required().pattern(solanaWalletAddressRegex), + ), donationValueUsd: Joi.number().greater(0).allow(null), // in case it fails donationValueEth: Joi.number().greater(0).allow(null), verified: Joi.boolean().allow(null), From 1bbd4622effc3fdfd29031501a8c0641418fc4e9 Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 25 Jan 2024 00:46:35 -0500 Subject: [PATCH 2/2] validate transaction id --- src/utils/validators/segmentAndMetadataValidators.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index 369e6c6..3a5a438 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -6,6 +6,7 @@ import { GIVETH_IO_EVENTS, NETWORK_IDS } from '../utils'; // does not care about calculating values, only validating fields const filterDateRegex = new RegExp('^[0-9]{8} [0-9]{2}:[0-9]{2}:[0-9]{2}$'); const ethereumWalletAddressRegex = /^0x[a-fA-F0-9]{40}$/; +const solanaTxRegex = /^[A-Za-z0-9]{86,88}$/; const solanaWalletAddressRegex = /^[A-Za-z0-9]{43,44}$/; const txHashRegex = /^0x[a-fA-F0-9]{64}$/; const tokenSymbolRegex = /^[a-zA-Z0-9]{3,10}$/; @@ -66,6 +67,10 @@ const donationTrackerSchema = Joi.object({ projectOwnerId: Joi.string().allow(null, ''), slug: Joi.string().allow(null, ''), amount: Joi.number()?.greater(0).required(), + transactionId: Joi.alternatives().try( + Joi.string().required().pattern(txHashRegex, 'EVM transaction IDs'), + Joi.string().required().pattern(solanaTxRegex, 'Solana Transaction ID'), + ), transactionNetworkId: Joi.number().required(), currency: Joi.string().required(), createdAt: Joi.string(),