From fc0bc98475cabbcfbe4d655a13b8ee872307ea64 Mon Sep 17 00:00:00 2001 From: Danial Date: Thu, 15 Aug 2024 13:44:41 +0900 Subject: [PATCH] Add logging message in the Notification --- packages/relay/scripts/notice_performance.ts | 29 +++++++++++++++++++ packages/relay/scripts/notice_shop.ts | 20 ++----------- packages/relay/scripts/notice_user.ts | 18 ++---------- .../relay/src/delegator/NotificationSender.ts | 1 + 4 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 packages/relay/scripts/notice_performance.ts diff --git a/packages/relay/scripts/notice_performance.ts b/packages/relay/scripts/notice_performance.ts new file mode 100644 index 00000000..a63d9820 --- /dev/null +++ b/packages/relay/scripts/notice_performance.ts @@ -0,0 +1,29 @@ +import { NotificationSender } from "../src/delegator/NotificationSender"; + +import { Config } from "../src/common/Config"; +import { ContractUtils } from "../src/utils/ContractUtils"; + +async function main() { + // Create with the arguments and read from file + const config = new Config(); + config.readFromFile("config/config.yaml"); + const notification: NotificationSender = new NotificationSender(config, undefined); + + const ids = ["ExponentPushToken[s__I-xJSSmcJCfLRPSobU_]", "ExponentPushToken[gr9g1_GA_54W9mUfYMYPtG]"]; + + for (let idx = 0; idx < 100; idx++) { + await send(notification, ids[idx % 2]); + await ContractUtils.delay(10); + } +} + +async function send(notification: NotificationSender, to: string) { + await notification.send(to, "테스트", "구매처 : 마이클2, 구매 금액 : 100 PHP, 포인트 사용 : 100 POINT", { + type: "info", + }); +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/packages/relay/scripts/notice_shop.ts b/packages/relay/scripts/notice_shop.ts index c7a4e198..8140ef6e 100644 --- a/packages/relay/scripts/notice_shop.ts +++ b/packages/relay/scripts/notice_shop.ts @@ -1,32 +1,18 @@ -import { BOACoin } from "../src/common/Amount"; - -import "@nomiclabs/hardhat-ethers"; -import * as hre from "hardhat"; -import { INotificationEventHandler, NotificationSender } from "../src/delegator/NotificationSender"; +import { NotificationSender } from "../src/delegator/NotificationSender"; import { Config } from "../src/common/Config"; async function main() { - const provider = hre.ethers.provider; - const account = "0x9E8549cc1B5b9036AC410Ed11966BB3c6B94A77d"; - const balance = await provider.getBalance(account); - console.log(`${account} : ${new BOACoin(balance).toBOAString()}`); - - const notificationEventHandler: INotificationEventHandler = { - receive: async (to: string, title: string, body: string, data: any) => { - console.log(to, title); - }, - }; // Create with the arguments and read from file const config = new Config(); config.readFromFile("config/config.yaml"); - const notification: NotificationSender = new NotificationSender(config, notificationEventHandler); + const notification: NotificationSender = new NotificationSender(config, undefined); await notification.send( "ExponentPushToken[gr9g1_GA_54W9mUfYMYPtG]", "상점 푸쉬 테스트", "구매처 : 마이클2, 구매 금액 : 100 PHP, 포인트 사용 : 100 POINT", - { type: "cancel" } + { type: "info" } ); } diff --git a/packages/relay/scripts/notice_user.ts b/packages/relay/scripts/notice_user.ts index 95144f15..f122158a 100644 --- a/packages/relay/scripts/notice_user.ts +++ b/packages/relay/scripts/notice_user.ts @@ -1,26 +1,12 @@ -import { BOACoin } from "../src/common/Amount"; - -import "@nomiclabs/hardhat-ethers"; -import * as hre from "hardhat"; -import { INotificationEventHandler, NotificationSender } from "../src/delegator/NotificationSender"; +import { NotificationSender } from "../src/delegator/NotificationSender"; import { Config } from "../src/common/Config"; async function main() { - const provider = hre.ethers.provider; - const account = "0x9E8549cc1B5b9036AC410Ed11966BB3c6B94A77d"; - const balance = await provider.getBalance(account); - console.log(`${account} : ${new BOACoin(balance).toBOAString()}`); - - const notificationEventHandler: INotificationEventHandler = { - receive: async (to: string, title: string, body: string, data: any) => { - console.log(to, title); - }, - }; // Create with the arguments and read from file const config = new Config(); config.readFromFile("config/config.yaml"); - const notification: NotificationSender = new NotificationSender(config, notificationEventHandler); + const notification: NotificationSender = new NotificationSender(config, undefined); await notification.send( "ExponentPushToken[s__I-xJSSmcJCfLRPSobU_]", diff --git a/packages/relay/src/delegator/NotificationSender.ts b/packages/relay/src/delegator/NotificationSender.ts index f72bd09e..3adb765c 100644 --- a/packages/relay/src/delegator/NotificationSender.ts +++ b/packages/relay/src/delegator/NotificationSender.ts @@ -48,6 +48,7 @@ export class NotificationSender implements INotificationSender { for (const chunk of chunks) { try { const ticketChunk = await expo.sendPushNotificationsAsync(chunk); + logger.info(`NotificationSender - to: ${to}, result: ${JSON.stringify(ticketChunk)}`); tickets.push(...ticketChunk); } catch (error) { logger.error(error);