@@ -19,6 +19,12 @@ type WebhookDetail = {
19
19
revokedAt : Date | null ;
20
20
} ;
21
21
22
+ type WebhookConfig = {
23
+ address : string ;
24
+ chainId : number ;
25
+ threshold : number ;
26
+ } ;
27
+
22
28
export const trackAddressBalance = async ( ) => {
23
29
const today = Date . now ( ) ;
24
30
const oneDayAgo = today - 24 * 60 * 60 * 1000 ;
@@ -38,8 +44,9 @@ export const trackAddressBalance = async () => {
38
44
let promises = [ ] ;
39
45
let ids = [ ] ;
40
46
for ( const webhookDetail of webhookDetails ) {
41
- if ( ! webhookDetail . config ?. address ) continue ;
42
- if ( ! webhookDetail . config ?. chainId ) continue ;
47
+ const config = webhookDetail . config as WebhookConfig | null ;
48
+ if ( ! config ?. address ) continue ;
49
+ if ( ! config ?. chainId ) continue ;
43
50
44
51
ids . push ( webhookDetail . id ) ;
45
52
promises . push (
@@ -67,7 +74,7 @@ export const trackAddressBalance = async () => {
67
74
} ;
68
75
69
76
const _checkBalanceAndEnqueueWebhook = async ( webhookDetail : WebhookDetail ) => {
70
- const { address, chainId, threshold } = webhookDetail . config ;
77
+ const { address, chainId, threshold } = webhookDetail . config as WebhookConfig ;
71
78
72
79
// get native balance of address
73
80
const balanceData = await getWalletBalance ( {
@@ -78,14 +85,14 @@ const _checkBalanceAndEnqueueWebhook = async (webhookDetail: WebhookDetail) => {
78
85
const currentBalance = balanceData . displayValue ;
79
86
80
87
// dont do anything if has enough balance
81
- if ( currentBalance > threshold ) return ;
88
+ if ( Number . parseFloat ( currentBalance ) > threshold ) return ;
82
89
83
90
await SendWebhookQueue . enqueueWebhook ( {
84
91
type : WebhooksEventTypes . BACKEND_WALLET_BALANCE ,
85
92
body : {
86
93
chainId,
87
94
walletAddress : address ,
88
- minimumBalance : threshold ,
95
+ minimumBalance : threshold . toString ( ) ,
89
96
currentBalance : currentBalance ,
90
97
message : `LowBalance: The address ${ address } on chain ${ chainId } has ${ Number . parseFloat (
91
98
currentBalance ,
0 commit comments