@@ -183,7 +183,8 @@ export async function fetchTransactionsByAddressListWithPagination (
183183 pageSize : number ,
184184 orderBy ?: string ,
185185 orderDesc = true ,
186- networkIdsListFilter ?: number [ ]
186+ networkIdsListFilter ?: number [ ] ,
187+ includeInputs = false
187188) : Promise < TransactionsWithPaybuttonsAndPrices [ ] > {
188189 const orderDescString : Prisma . SortOrder = orderDesc ? 'desc' : 'asc'
189190
@@ -209,6 +210,14 @@ export async function fetchTransactionsByAddressListWithPagination (
209210 }
210211 }
211212
213+ // Build include conditionally - exclude inputs by default unless explicitly requested
214+ const include = includeInputs
215+ ? includePaybuttonsAndPricesAndInvoices
216+ : ( ( ) => {
217+ const { inputs, ...rest } = includePaybuttonsAndPricesAndInvoices
218+ return rest
219+ } ) ( )
220+
212221 return await prisma . transaction . findMany ( {
213222 where : {
214223 addressId : {
@@ -220,11 +229,11 @@ export async function fetchTransactionsByAddressListWithPagination (
220229 }
221230 }
222231 } ,
223- include : includePaybuttonsAndPricesAndInvoices ,
232+ include,
224233 orderBy : orderByQuery ,
225234 skip : page * pageSize ,
226235 take : pageSize
227- } )
236+ } ) as unknown as TransactionsWithPaybuttonsAndPrices [ ]
228237}
229238
230239export async function fetchTxCountByAddressString ( addressString : string ) : Promise < number > {
@@ -570,6 +579,7 @@ export async function createManyTransactions (
570579 timestamp : tx . timestamp ,
571580 addressId : tx . addressId ,
572581 confirmed : tx . confirmed ?? false ,
582+ isPayment : tx . amount > 0 ,
573583 opReturn : tx . opReturn ?? '' ,
574584 orphaned : false
575585 } ) )
@@ -823,15 +833,19 @@ export async function fetchTransactionsByPaybuttonIdWithPagination (
823833 pageSize : number ,
824834 orderDesc : boolean ,
825835 orderBy ?: string ,
826- networkIds ?: number [ ] ) : Promise < TransactionsWithPaybuttonsAndPrices [ ] > {
836+ networkIds ?: number [ ] ,
837+ includeInputs = false
838+ ) : Promise < TransactionsWithPaybuttonsAndPrices [ ] > {
827839 const addressIdList = await fetchAddressesByPaybuttonId ( paybuttonId )
828840 const transactions = await fetchTransactionsByAddressListWithPagination (
829841 addressIdList ,
830842 page ,
831843 pageSize ,
832844 orderBy ,
833845 orderDesc ,
834- networkIds )
846+ networkIds ,
847+ includeInputs
848+ )
835849
836850 return transactions
837851}
@@ -935,7 +949,7 @@ export async function getPaymentsByUserIdOrderedByButtonName (
935949 LEFT JOIN \`PricesOnTransactions\` pt ON t.\`id\` = pt.\`transactionId\`
936950 LEFT JOIN \`Price\` pb ON pt.\`priceId\` = pb.\`id\`
937951 LEFT JOIN \`Invoice\` i ON i.\`transactionId\` = t.\`id\`
938- WHERE t.\`amount \` > 0
952+ WHERE t.\`isPayment \` = TRUE
939953 AND EXISTS (
940954 SELECT 1
941955 FROM \`AddressesOnUserProfiles\` au
@@ -1005,7 +1019,8 @@ export async function fetchAllPaymentsByUserIdWithPagination (
10051019 buttonIds ?: string [ ] ,
10061020 years ?: string [ ] ,
10071021 startDate ?: string ,
1008- endDate ?: string
1022+ endDate ?: string ,
1023+ includeInputs = false
10091024) : Promise < Payment [ ] > {
10101025 const orderDescString : Prisma . SortOrder = orderDesc ? 'desc' : 'asc'
10111026
@@ -1042,7 +1057,7 @@ export async function fetchAllPaymentsByUserIdWithPagination (
10421057 address : {
10431058 userProfiles : { some : { userId } }
10441059 } ,
1045- amount : { gt : 0 }
1060+ isPayment : true
10461061 }
10471062
10481063 if ( startDate !== undefined && endDate !== undefined && startDate !== '' && endDate !== '' ) {
@@ -1061,9 +1076,17 @@ export async function fetchAllPaymentsByUserIdWithPagination (
10611076 }
10621077 }
10631078
1079+ // Build include conditionally - exclude inputs by default unless explicitly requested
1080+ const include = includeInputs
1081+ ? includePaybuttonsAndPricesAndInvoices
1082+ : ( ( ) => {
1083+ const { inputs, ...rest } = includePaybuttonsAndPricesAndInvoices
1084+ return rest
1085+ } ) ( )
1086+
10641087 const transactions = await prisma . transaction . findMany ( {
10651088 where,
1066- include : includePaybuttonsAndPricesAndInvoices ,
1089+ include,
10671090 orderBy : orderByQuery ,
10681091 skip : page * Number ( pageSize ) ,
10691092 take : Number ( pageSize )
@@ -1073,7 +1096,7 @@ export async function fetchAllPaymentsByUserIdWithPagination (
10731096 for ( let index = 0 ; index < transactions . length ; index ++ ) {
10741097 const tx = transactions [ index ]
10751098 if ( Number ( tx . amount ) > 0 ) {
1076- const payment = await generatePaymentFromTxWithInvoices ( tx , userId )
1099+ const payment = generatePaymentFromTxWithInvoices ( tx as unknown as TransactionWithAddressAndPricesAndInvoices , userId )
10771100 transformedData . push ( payment )
10781101 }
10791102 }
@@ -1160,9 +1183,7 @@ export async function fetchAllPaymentsByUserId (
11601183 in : networkIds ?? Object . values ( NETWORK_IDS )
11611184 }
11621185 } ,
1163- amount : {
1164- gt : 0
1165- }
1186+ isPayment : true
11661187 }
11671188
11681189 if ( buttonIds !== undefined && buttonIds . length > 0 ) {
@@ -1216,7 +1237,7 @@ export const getFilteredTransactionCount = async (
12161237 some : { userId }
12171238 }
12181239 } ,
1219- amount : { gt : 0 }
1240+ isPayment : true
12201241 }
12211242 if ( buttonIds !== undefined && buttonIds . length > 0 ) {
12221243 where . address ! . paybuttons = {
@@ -1243,8 +1264,7 @@ export const fetchDistinctPaymentYearsByUser = async (userId: string): Promise<n
12431264 FROM Transaction t
12441265 JOIN Address a ON a.id = t.addressId
12451266 JOIN AddressesOnUserProfiles ap ON ap.addressId = a.id
1246- WHERE ap.userId = ${ userId } AND
1247- t.amount > 0
1267+ WHERE ap.userId = ${ userId }
12481268 ORDER BY year ASC
12491269 `
12501270
0 commit comments