Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix max title length #180

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ export async function getSpace(id) {
return null;
}
}

export function truncate(string: string, length: number) {
return string.length > length
? `${string.substring(0, length - 1)}…`
: string;
}
19 changes: 14 additions & 5 deletions src/providers/walletconnectNotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import snapshot from '@snapshot-labs/snapshot.js';
import { capture } from '@snapshot-labs/snapshot-sentry';
import { timeOutgoingRequest, outgoingMessages } from '../helpers/metrics';
import type { Event } from '../types';
import { truncate } from '../helpers/utils';

const WALLETCONNECT_NOTIFY_SERVER_URL =
process.env.WALLETCONNECT_NOTIFY_SERVER_URL;
Expand All @@ -28,7 +29,11 @@ const isConfigured =
WALLETCONNECT_PROJECT_ID &&
WALLETCONNECT_NOTIFICATION_TYPE;

async function queueNotificationsToSend(notification_id: string, notification, accounts: string[]) {
async function queueNotificationsToSend(
notification_id: string,
notification,
accounts: string[]
) {
for (let i = 0; i < accounts.length; i += MAX_ACCOUNTS_PER_REQUEST) {
await sendNotification(
notification_id,
Expand All @@ -40,7 +45,11 @@ async function queueNotificationsToSend(notification_id: string, notification, a
}
}

export async function sendNotification(notification_id: string, notification, accounts: string[]) {
export async function sendNotification(
notification_id: string,
notification,
accounts: string[]
) {
const notifyUrl = `${WALLETCONNECT_NOTIFY_SERVER_URL}/${WALLETCONNECT_PROJECT_ID}/notify`;

const body = {
Expand Down Expand Up @@ -86,12 +95,12 @@ function formatMessage(event: Event, proposal) {
if (!space) return null;

const notificationType = WALLETCONNECT_NOTIFICATION_TYPE;
const notificationBody = `🟢 New proposal on ${space.name} @${space.id}\n\n`;
// const notificationBody = `🟢 New proposal on ${space.name} @${space.id}\n\n`;

const url = `${proposal.link}?app=web3inbox`;
return {
title: proposal.title,
body: notificationBody,
title: truncate(proposal.title, 64),
// body: notificationBody,
wa0x6e marked this conversation as resolved.
Show resolved Hide resolved
url,
type: notificationType
};
Expand Down
Loading