Skip to content

Commit 8ee8f8c

Browse files
committed
styling: fixed formattinig
1 parent 267fb2f commit 8ee8f8c

File tree

1 file changed

+50
-40
lines changed

1 file changed

+50
-40
lines changed

src/event-handlers/court-emails.js

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,39 @@ const webpush = require('web-push');
1414
const timeAgo = new TimeAgo('en-US');
1515
const createEventHandlers = (chainId) => ({
1616
Draw: async (_, klerosLiquid, event) => {
17-
try {
18-
console.log('Calling .disputes() with disputeID:', event._disputeID);
19-
const dispute = await klerosLiquid.methods
20-
.disputes(event._disputeID)
21-
.call();
22-
return [
23-
{
24-
account: event._address,
25-
type: 'Draw',
26-
disputeID: event._disputeID,
27-
templateId: 'd-b4880ab92d004827929ad074a714a7cb',
28-
dynamic_template_data: {
29-
startDate:
17+
const dispute = await klerosLiquid.methods
18+
.disputes(event._disputeID)
19+
.call()
20+
21+
return [
22+
{
23+
account: event._address,
24+
type: 'Draw',
25+
disputeID: event._disputeID,
26+
templateId: 'd-b4880ab92d004827929ad074a714a7cb',
27+
dynamic_template_data: {
28+
startDate:
3029
event._appeal === '0'
31-
? `${timeAgo.format(
32-
(Number(dispute.lastPeriodChange) +
33-
Number(
34-
(
35-
await klerosLiquid.methods
36-
.getSubcourt(dispute.subcourtID)
37-
.call()
38-
).timesPerPeriod[0]
39-
)) *
40-
1000
41-
)}`
42-
: 'as soon as all other jurors are drawn',
43-
caseNumber: event._disputeID,
44-
caseUrl: `https://court.kleros.io/cases/${
30+
? `${timeAgo.format(
31+
(Number(dispute.lastPeriodChange) +
32+
Number(
33+
(
34+
await klerosLiquid.methods
35+
.getSubcourt(dispute.subcourtID)
36+
.call()
37+
).timesPerPeriod[0]
38+
)) *
39+
1000
40+
)}`
41+
: 'as soon as all other jurors are drawn',
42+
caseNumber: event._disputeID,
43+
caseUrl: `https://court.kleros.io/cases/${
4544
event._disputeID
4645
}?${qs.stringify({ requiredChainId: chainId })}`,
47-
},
48-
pushNotificationText: `You have been drawn in case #${event._disputeID}`,
49-
},
50-
];
51-
} catch (err) {
52-
console.warn('Ooops, got an error:', err);
53-
throw err;
54-
}
46+
},
47+
pushNotificationText: `You have been drawn in case #${event._disputeID}`,
48+
},
49+
];
5550
},
5651
Vote: async (_, klerosLiquid, event) => {
5752
const dispute = await klerosLiquid.methods
@@ -208,11 +203,26 @@ const createLambdaHandler = (createWeb3, createContract) => {
208203
);
209204

210205
const handlers = createEventHandlers(chainId);
211-
const notifications = await handlers[event.event](
212-
web3,
213-
createContract(web3),
214-
event
215-
);
206+
let notifications = []
207+
try {
208+
notifications = await handlers[event.event](
209+
web3,
210+
createContract(web3),
211+
event
212+
);
213+
} catch (err) {
214+
const { event: eventName, ...payload } = event
215+
console.info(`Error processing event ${event.event} with payload:`, payload)
216+
console.warn(err)
217+
218+
return callback(null, {
219+
statusCode: 500,
220+
headers: { 'Access-Control-Allow-Origin': '*' },
221+
body: JSON.stringify({
222+
error: err.message,
223+
}),
224+
});
225+
}
216226

217227
for (const notification of notifications) {
218228
const signedUnsubscribeKey = lambdaAccount.sign(notification.account);

0 commit comments

Comments
 (0)