Skip to content

Commit 0b5eae9

Browse files
committed
Final fix
1 parent 5c05873 commit 0b5eae9

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

cdk/functions/fetcher.ts

+24-12
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,35 @@ async function checkIfTxStatusChanged(env: string, event: Event) {
3131
to: event.detail.accountAddress,
3232
})
3333
);
34-
const items = res.data["items"] as Array<Item>;
34+
const items = res.data["items"] as Array<VoyagerItem>;
3535
for (const item of items) {
3636
if (item.status === "Accepted on L1") {
3737
continue;
3838
}
3939
const previousItem = await getPreviousItem(item.hash);
4040
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}-`);
4242
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+
) {
4447
console.log(`Transaction status changed to ${item.status}`);
4548
await setTransactionStatus(item);
4649
await sendNotification(env, item, event.detail.chatId);
4750
}
4851
}
4952
}
5053

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> {
5260
const params = {
5361
TableName: process.env.TX_STATUSES_TABLE,
54-
Key: { hash: { S: hash } },
62+
Key: { transactionHash: { S: transactionHash } },
5563
};
5664
console.log(
5765
`Calling previous items with command: ${JSON.stringify(params, null, 2)}`
@@ -65,13 +73,13 @@ async function getPreviousItem(hash: string): Promise<Item | null> {
6573
return unmarshall(res.Item) as Item;
6674
}
6775

68-
async function setTransactionStatus(item: Item) {
76+
async function setTransactionStatus(item: VoyagerItem) {
6977
const ddb = new DynamoDBClient({});
7078
const params = {
7179
TableName: process.env.TX_STATUSES_TABLE,
7280
Item: {
73-
hash: { S: item.hash },
74-
status: { S: item.status },
81+
transactionHash: { S: item.hash },
82+
transactionStatus: { S: item.status },
7583
},
7684
};
7785

@@ -81,8 +89,8 @@ async function setTransactionStatus(item: Item) {
8189
}
8290

8391
interface Item {
84-
hash: string;
85-
status: string;
92+
transactionHash: string;
93+
transactionStatus: string;
8694
}
8795

8896
const getBaseUrl = ({ to, env }: { to: string; env: string }) => {
@@ -92,11 +100,15 @@ const getBaseUrl = ({ to, env }: { to: string; env: string }) => {
92100
return `https://${env}.voyager.online/api/txns?to=${to}`;
93101
};
94102

95-
async function sendNotification(env: string, item: Item, chatId: string) {
103+
async function sendNotification(
104+
env: string,
105+
item: VoyagerItem,
106+
chatId: string
107+
) {
96108
const confirmationMessage = `✨ Congrats! Your transaction ${formatTx(
97109
env,
98110
item.hash
99-
)} went through with status *${item.status}* 🚀`;
111+
)} went through with transactionStatus *${item.status}* 🚀`;
100112
const BOT_API_KEY = getFromEnv("BOT_API_KEY");
101113
const baseUrl = `https://api.telegram.org/bot${BOT_API_KEY}/sendMessage?chat_id=${chatId}&text=${confirmationMessage}&parse_mode=markdown`;
102114
await axios.post(baseUrl);

0 commit comments

Comments
 (0)