@@ -31,27 +31,35 @@ async function checkIfTxStatusChanged(env: string, event: Event) {
31
31
to : event . detail . accountAddress ,
32
32
} )
33
33
) ;
34
- const items = res . data [ "items" ] as Array < Item > ;
34
+ const items = res . data [ "items" ] as Array < VoyagerItem > ;
35
35
for ( const item of items ) {
36
36
if ( item . status === "Accepted on L1" ) {
37
37
continue ;
38
38
}
39
39
const previousItem = await getPreviousItem ( item . hash ) ;
40
40
console . log ( `Previous item: ${ JSON . stringify ( previousItem , null , 2 ) } ` ) ;
41
- console . log ( `Previous item status -${ previousItem ?. status } -` ) ;
41
+ console . log ( `Previous item status -${ previousItem ?. transactionStatus } -` ) ;
42
42
console . log ( `Item status -${ item ?. status } -` ) ;
43
- if ( previousItem === null || previousItem . status !== item . status ) {
43
+ if (
44
+ previousItem === null ||
45
+ previousItem . transactionStatus !== item . status
46
+ ) {
44
47
console . log ( `Transaction status changed to ${ item . status } ` ) ;
45
48
await setTransactionStatus ( item ) ;
46
49
await sendNotification ( env , item , event . detail . chatId ) ;
47
50
}
48
51
}
49
52
}
50
53
51
- async function getPreviousItem ( hash : string ) : Promise < Item | null > {
54
+ interface VoyagerItem {
55
+ hash : string ;
56
+ status : string ;
57
+ }
58
+
59
+ async function getPreviousItem ( transactionHash : string ) : Promise < Item | null > {
52
60
const params = {
53
61
TableName : process . env . TX_STATUSES_TABLE ,
54
- Key : { hash : { S : hash } } ,
62
+ Key : { transactionHash : { S : transactionHash } } ,
55
63
} ;
56
64
console . log (
57
65
`Calling previous items with command: ${ JSON . stringify ( params , null , 2 ) } `
@@ -65,13 +73,13 @@ async function getPreviousItem(hash: string): Promise<Item | null> {
65
73
return unmarshall ( res . Item ) as Item ;
66
74
}
67
75
68
- async function setTransactionStatus ( item : Item ) {
76
+ async function setTransactionStatus ( item : VoyagerItem ) {
69
77
const ddb = new DynamoDBClient ( { } ) ;
70
78
const params = {
71
79
TableName : process . env . TX_STATUSES_TABLE ,
72
80
Item : {
73
- hash : { S : item . hash } ,
74
- status : { S : item . status } ,
81
+ transactionHash : { S : item . hash } ,
82
+ transactionStatus : { S : item . status } ,
75
83
} ,
76
84
} ;
77
85
@@ -81,8 +89,8 @@ async function setTransactionStatus(item: Item) {
81
89
}
82
90
83
91
interface Item {
84
- hash : string ;
85
- status : string ;
92
+ transactionHash : string ;
93
+ transactionStatus : string ;
86
94
}
87
95
88
96
const getBaseUrl = ( { to, env } : { to : string ; env : string } ) => {
@@ -92,11 +100,15 @@ const getBaseUrl = ({ to, env }: { to: string; env: string }) => {
92
100
return `https://${ env } .voyager.online/api/txns?to=${ to } ` ;
93
101
} ;
94
102
95
- async function sendNotification ( env : string , item : Item , chatId : string ) {
103
+ async function sendNotification (
104
+ env : string ,
105
+ item : VoyagerItem ,
106
+ chatId : string
107
+ ) {
96
108
const confirmationMessage = `✨ Congrats! Your transaction ${ formatTx (
97
109
env ,
98
110
item . hash
99
- ) } went through with status *${ item . status } * 🚀`;
111
+ ) } went through with transactionStatus *${ item . status } * 🚀`;
100
112
const BOT_API_KEY = getFromEnv ( "BOT_API_KEY" ) ;
101
113
const baseUrl = `https://api.telegram.org/bot${ BOT_API_KEY } /sendMessage?chat_id=${ chatId } &text=${ confirmationMessage } &parse_mode=markdown` ;
102
114
await axios . post ( baseUrl ) ;
0 commit comments