Skip to content

Commit

Permalink
Add logging message in the Notification
Browse files Browse the repository at this point in the history
  • Loading branch information
danial303065 committed Aug 15, 2024
1 parent b99ddc5 commit fc0bc98
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
29 changes: 29 additions & 0 deletions packages/relay/scripts/notice_performance.ts
Original file line number Diff line number Diff line change
@@ -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;
});
20 changes: 3 additions & 17 deletions packages/relay/scripts/notice_shop.ts
Original file line number Diff line number Diff line change
@@ -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" }
);
}

Expand Down
18 changes: 2 additions & 16 deletions packages/relay/scripts/notice_user.ts
Original file line number Diff line number Diff line change
@@ -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_]",
Expand Down
1 change: 1 addition & 0 deletions packages/relay/src/delegator/NotificationSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fc0bc98

Please sign in to comment.