@@ -12,19 +12,13 @@ import { thirdwebClient } from "../../shared/utils/sdk";
12
12
import { getWalletBalance } from "thirdweb/wallets" ;
13
13
import type { Chain } from "thirdweb/chains" ;
14
14
import 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" ;
16
17
17
- interface WalletSubscriptionWithWebhook {
18
- id : string ;
19
- chainId : string ;
20
- walletAddress : string ;
18
+ type WalletSubscriptionWithWebhook = WalletSubscriptions & {
21
19
conditions : WalletCondition [ ] ;
22
- webhookId : number | null ;
23
20
webhook : Webhooks | null ;
24
- createdAt : Date ;
25
- updatedAt : Date ;
26
- deletedAt : Date | null ;
27
- }
21
+ } ;
28
22
29
23
// Split array into chunks of specified size
30
24
function chunk < T > ( arr : T [ ] , size : number ) : T [ ] [ ] {
@@ -45,7 +39,7 @@ async function verifyCondition({
45
39
condition : WalletCondition ;
46
40
walletAddress : string ;
47
41
chain : Chain ;
48
- } ) : Promise < string | undefined > {
42
+ } ) : Promise < string | null > {
49
43
switch ( condition . type ) {
50
44
case "token_balance_lt" :
51
45
case "token_balance_gt" : {
@@ -67,12 +61,7 @@ async function verifyCondition({
67
61
? currentBalance < threshold
68
62
: currentBalance > threshold ;
69
63
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 ;
76
65
}
77
66
}
78
67
}
@@ -112,7 +101,7 @@ async function processSubscriptions(
112
101
}
113
102
} catch ( error ) {
114
103
// Log error but continue processing other subscriptions
115
- const message = error instanceof Error ? error . message : String ( error ) ;
104
+ const message = prettifyError ( error ) ;
116
105
logger ( {
117
106
service : "worker" ,
118
107
level : "error" ,
@@ -127,7 +116,8 @@ async function processSubscriptions(
127
116
// Must be explicitly called for the worker to run on this host.
128
117
export const initWalletSubscriptionWorker = async ( ) => {
129
118
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
131
121
132
122
logger ( {
133
123
service : "worker" ,
@@ -152,10 +142,7 @@ export const initWalletSubscriptionWorker = async () => {
152
142
*/
153
143
const handler : Processor < string , void , string > = async ( _job : Job < string > ) => {
154
144
// 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 ( ) ;
159
146
if ( subscriptions . length === 0 ) {
160
147
return ;
161
148
}
0 commit comments