Skip to content

Commit

Permalink
feat: update watcher notification logic
Browse files Browse the repository at this point in the history
  • Loading branch information
serezhaolshan committed Sep 9, 2024
1 parent cfee909 commit b00e552
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/watcher/watcher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,7 @@ export class WatcherService {
const { data: { data: [txData] } } = txDataResponse;
const { from, to, value, timestamp, token, type } = txData;

if (!SUPPORTED_TX_TYPES.includes(type)) return;

// @dev To avoid sending notifications for node rewards transactions
// @dev To lower case for case-insensitive comparison
if (from.toLowerCase() === rewardsBankAddress.toLowerCase()) return;

// @dev Did it for hiding ERC-1155 and ERC-721 transfers for users
if (token && !(await isERC20Standard(token.address))) {
return;
}
if (!(await this.isNotificationNeeded(type, from, token!, value))) return;

const cutAddress = (addr: string) => addr ? `${addr.slice(0, 5)}...${addr.slice(-5)}` : "";

Expand Down Expand Up @@ -314,4 +305,26 @@ export class WatcherService {
private decodeWatcherToken(watcher: Watcher) {
watcher.pushToken = Buffer.from(watcher.pushToken, "base64").toString("utf-8");
}

private async isNotificationNeeded(
type: string,
from: string,
token: { address: string },
value: { wei: string }
) {
if (!SUPPORTED_TX_TYPES.includes(type)) return false;

// @dev To avoid sending notifications for node rewards transactions
// @dev To lower case for case-insensitive comparison
if (from.toLowerCase() === rewardsBankAddress.toLowerCase()) return false;

// @dev Did it for hiding ERC-1155 and ERC-721 transfers for users
if (token && !(await isERC20Standard(token.address))) {
return false;
}

if (value.wei === "0") return false;

return true;
}
}

0 comments on commit b00e552

Please sign in to comment.