@@ -12,19 +12,13 @@ import { thirdwebClient } from "../../shared/utils/sdk";
1212import { getWalletBalance } from "thirdweb/wallets" ;
1313import type { Chain } from "thirdweb/chains" ;
1414import type { WalletCondition } from "../../shared/schemas/wallet-subscription-conditions" ;
15- import type { Webhooks } from "@prisma/client" ;
15+ import type { WalletSubscriptions , Webhooks } from "@prisma/client" ;
16+ import { prettifyError } from "../../shared/utils/error" ;
1617
17- interface WalletSubscriptionWithWebhook {
18- id : string ;
19- chainId : string ;
20- walletAddress : string ;
18+ type WalletSubscriptionWithWebhook = WalletSubscriptions & {
2119 conditions : WalletCondition [ ] ;
22- webhookId : number | null ;
2320 webhook : Webhooks | null ;
24- createdAt : Date ;
25- updatedAt : Date ;
26- deletedAt : Date | null ;
27- }
21+ } ;
2822
2923// Split array into chunks of specified size
3024function chunk < T > ( arr : T [ ] , size : number ) : T [ ] [ ] {
@@ -45,7 +39,7 @@ async function verifyCondition({
4539 condition : WalletCondition ;
4640 walletAddress : string ;
4741 chain : Chain ;
48- } ) : Promise < string | undefined > {
42+ } ) : Promise < string | null > {
4943 switch ( condition . type ) {
5044 case "token_balance_lt" :
5145 case "token_balance_gt" : {
@@ -67,12 +61,7 @@ async function verifyCondition({
6761 ? currentBalance < threshold
6862 : currentBalance > threshold ;
6963
70- return isConditionMet ? currentBalance . toString ( ) : undefined ;
71- }
72- default : {
73- // For TypeScript exhaustiveness check
74- const _exhaustiveCheck : never = condition ;
75- return undefined ;
64+ return isConditionMet ? currentBalance . toString ( ) : null ;
7665 }
7766 }
7867}
@@ -112,7 +101,7 @@ async function processSubscriptions(
112101 }
113102 } catch ( error ) {
114103 // Log error but continue processing other subscriptions
115- const message = error instanceof Error ? error . message : String ( error ) ;
104+ const message = prettifyError ( error ) ;
116105 logger ( {
117106 service : "worker" ,
118107 level : "error" ,
@@ -127,7 +116,8 @@ async function processSubscriptions(
127116// Must be explicitly called for the worker to run on this host.
128117export const initWalletSubscriptionWorker = async ( ) => {
129118 const config = await getConfig ( ) ;
130- const cronPattern = config . walletSubscriptionsCronSchedule || "*/30 * * * * *" ; // Default to every 30 seconds
119+ const cronPattern =
120+ config . walletSubscriptionsCronSchedule || "*/30 * * * * *" ; // Default to every 30 seconds
131121
132122 logger ( {
133123 service : "worker" ,
@@ -152,10 +142,7 @@ export const initWalletSubscriptionWorker = async () => {
152142 */
153143const handler : Processor < string , void , string > = async ( _job : Job < string > ) => {
154144 // Get all active wallet subscriptions
155- const subscriptions = await getAllWalletSubscriptions ( {
156- page : 1 ,
157- limit : 1000 , // Process 1000 subscriptions at a time
158- } ) ;
145+ const subscriptions = await getAllWalletSubscriptions ( ) ;
159146 if ( subscriptions . length === 0 ) {
160147 return ;
161148 }
0 commit comments