@@ -2,26 +2,13 @@ import { BaseTriggerHandler } from './base-trigger.service';
22import { DispatcherMessage , MessageProcessingResult } from '../../interfaces/dispatcher-message.interface' ;
33import { NotificationClientFactory } from '../notification/notification-factory.service' ;
44import { ISubscriptionClient } from '../../interfaces/subscription-client.interface' ;
5- import { AnticaptureClient } from '@notification-system/anticapture-client' ;
5+ import { AnticaptureClient , VoteWithDaoId } from '@notification-system/anticapture-client' ;
66import { formatTokenAmount } from '../../lib/number-formatter' ;
77import { voteConfirmationMessages , replacePlaceholders , buildButtons } from '@notification-system/messages' ;
8- import { FormattingService } from '../formatting.service' ;
9-
10- interface VoteEvent {
11- daoId : string ;
12- proposalId : string ;
13- voterAccountId : string ;
14- support : string ;
15- votingPower : string ;
16- timestamp : string ;
17- txHash : string ;
18- reason ?: string | null ;
19- proposalDescription ?: string | null ;
20- }
218
229interface UserVoteCombination {
2310 user : any ;
24- vote : VoteEvent ;
11+ vote : VoteWithDaoId ;
2512}
2613
2714interface ProcessingResult {
@@ -33,7 +20,7 @@ interface ProcessingResult {
3320type ProcessingStatus = 'sent' | 'skipped' ;
3421
3522
36- export class VoteConfirmationTriggerHandler extends BaseTriggerHandler < VoteEvent > {
23+ export class VoteConfirmationTriggerHandler extends BaseTriggerHandler < VoteWithDaoId > {
3724 constructor (
3825 protected readonly subscriptionClient : ISubscriptionClient ,
3926 protected readonly notificationFactory : NotificationClientFactory ,
@@ -42,7 +29,7 @@ export class VoteConfirmationTriggerHandler extends BaseTriggerHandler<VoteEvent
4229 super ( subscriptionClient , notificationFactory , anticaptureClient ) ;
4330 }
4431
45- async handleMessage ( message : DispatcherMessage < VoteEvent > ) : Promise < MessageProcessingResult > {
32+ async handleMessage ( message : DispatcherMessage < VoteWithDaoId > ) : Promise < MessageProcessingResult > {
4633 const events = message . events ;
4734
4835 if ( ! events || events . length === 0 ) {
@@ -54,7 +41,7 @@ export class VoteConfirmationTriggerHandler extends BaseTriggerHandler<VoteEvent
5441 }
5542
5643 // Extract unique voter addresses and batch fetch wallet owners
57- const voterAddresses = [ ...new Set ( events . map ( event => event . voterAccountId ) ) ] ;
44+ const voterAddresses = [ ...new Set ( events . map ( event => event . voterAddress ) ) ] ;
5845 const walletOwners = await this . subscriptionClient . getWalletOwnersBatch ( voterAddresses ) ;
5946
6047 // Create all user-vote combinations
@@ -75,11 +62,11 @@ export class VoteConfirmationTriggerHandler extends BaseTriggerHandler<VoteEvent
7562 * Creates combinations of users and votes for processing
7663 */
7764 private createUserVoteCombinations (
78- events : VoteEvent [ ] ,
65+ events : VoteWithDaoId [ ] ,
7966 walletOwners : Record < string , any [ ] >
8067 ) : UserVoteCombination [ ] {
8168 return events . flatMap ( voteEvent => {
82- const usersForWallet = walletOwners [ voteEvent . voterAccountId ] || [ ] ;
69+ const usersForWallet = walletOwners [ voteEvent . voterAddress ] || [ ] ;
8370 return usersForWallet . map ( user => ( { user, vote : voteEvent } ) ) ;
8471 } ) ;
8572 }
@@ -106,9 +93,9 @@ export class VoteConfirmationTriggerHandler extends BaseTriggerHandler<VoteEvent
10693 /**
10794 * Processes a single user-vote combination
10895 */
109- private async processUserVote ( user : any , vote : VoteEvent ) : Promise < ProcessingStatus > {
96+ private async processUserVote ( user : any , vote : VoteWithDaoId ) : Promise < ProcessingStatus > {
11097 // Check if user is subscribed to the DAO
111- const subscribers = await this . getSubscribers ( vote . daoId , vote . txHash , vote . timestamp ) ;
98+ const subscribers = await this . getSubscribers ( vote . daoId , vote . transactionHash , String ( vote . timestamp ) ) ;
11299 const isSubscribed = subscribers . some ( sub => sub . id === user . id ) ;
113100
114101 if ( ! isSubscribed ) {
@@ -117,9 +104,9 @@ export class VoteConfirmationTriggerHandler extends BaseTriggerHandler<VoteEvent
117104 }
118105
119106 // Check deduplication
120- const notifications = await this . subscriptionClient . shouldSend ( [ user ] , vote . txHash , vote . daoId ) ;
107+ const notifications = await this . subscriptionClient . shouldSend ( [ user ] , vote . transactionHash , vote . daoId ) ;
121108 if ( notifications . length === 0 ) {
122- console . log ( `[VoteConfirmationHandler] Notification already sent for vote ${ vote . txHash } ` ) ;
109+ console . log ( `[VoteConfirmationHandler] Notification already sent for vote ${ vote . transactionHash } ` ) ;
123110 return 'skipped' ;
124111 }
125112
@@ -133,55 +120,51 @@ export class VoteConfirmationTriggerHandler extends BaseTriggerHandler<VoteEvent
133120 /**
134121 * Sends notification for a single vote
135122 */
136- private async sendVoteNotification ( user : any , vote : VoteEvent ) : Promise < void > {
123+ private async sendVoteNotification ( user : any , vote : VoteWithDaoId ) : Promise < void > {
137124 const message = this . formatVoteMessage ( vote ) ;
138125 const chainId = await this . getChainIdForDao ( vote . daoId ) ;
139126
140127 // Build buttons
141128 const buttons = buildButtons ( {
142129 triggerType : 'voteConfirmation' ,
143- txHash : vote . txHash ,
130+ txHash : vote . transactionHash ,
144131 chainId
145132 } ) ;
146133
147134 await this . sendNotificationsToSubscribers (
148135 [ user ] ,
149136 message ,
150- vote . txHash ,
137+ vote . transactionHash ,
151138 vote . daoId ,
152139 {
153140 transaction : {
154- hash : vote . txHash ,
141+ hash : vote . transactionHash ,
155142 chainId
156143 } ,
157144 addresses : {
158- address : vote . voterAccountId
145+ address : vote . voterAddress
159146 } ,
160147 proposalId : vote . proposalId ,
161- support : vote . support ,
148+ support : String ( vote . support ) ,
162149 votingPower : vote . votingPower ,
163150 reason : vote . reason
164151 } ,
165152 buttons
166153 ) ;
167154 }
168155
169- private formatVoteMessage ( vote : VoteEvent ) : string {
170- const supportKey = voteConfirmationMessages . getSupportKey ( vote . support ) ;
156+ private formatVoteMessage ( vote : VoteWithDaoId ) : string {
157+ const supportKey = voteConfirmationMessages . getSupportKey ( String ( vote . support ) ) ;
171158 const votingPower = formatTokenAmount ( vote . votingPower , 18 ) ;
172159 const hasReason = vote . reason && vote . reason . trim ( ) ;
173- const proposalTitle = FormattingService . extractTitle (
174- vote . proposalDescription || '' ,
175- vote . proposalId
176- ) ;
177160
178161 const messageTemplate = hasReason
179162 ? voteConfirmationMessages . withReason [ supportKey ]
180163 : voteConfirmationMessages . withoutReason [ supportKey ] ;
181164
182165 return replacePlaceholders ( messageTemplate , {
183166 daoId : vote . daoId ,
184- proposalTitle,
167+ proposalTitle : vote . proposalTitle ,
185168 votingPower,
186169 ...( hasReason && { reason : vote . reason ! } )
187170 } ) ;
0 commit comments