• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 13709067365

06 Mar 2025 10:03PM UTC coverage: 45.436%. First build
13709067365

push

github

web-flow
Merge pull request #11321 from hicommonwealth/ryan/skip-delete-cast

Fix frame hash updates

1313 of 3207 branches covered (40.94%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 1 file covered. (0.0%)

2510 of 5207 relevant lines covered (48.2%)

38.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

2.63
/libs/model/src/contest/UpdateContestManagerFrameHashes.command.ts
1
import { Command } from '@hicommonwealth/core';
2
import { config, models } from '@hicommonwealth/model';
3
import * as schemas from '@hicommonwealth/schemas';
4
import { NeynarAPIClient } from '@neynar/nodejs-sdk';
5
import { Mutex } from 'async-mutex';
6
import _ from 'lodash';
7
import { Op } from 'sequelize';
8
import { mustExist } from '../middleware/guards';
9

10
const neynarMutex = new Mutex();
30✔
11

12
export function UpdateContestManagerFrameHashes(): Command<
13
  typeof schemas.UpdateContestManagerFrameHashes
14
> {
15
  return {
×
16
    ...schemas.UpdateContestManagerFrameHashes,
17
    auth: [],
18
    body: async ({ payload }) => {
19
      await neynarMutex.runExclusive(async () => {
×
20
        const contestManager = await models.ContestManager.findOne({
×
21
          where: {
22
            contest_address: payload.contest_address,
23
            cancelled: {
24
              [Op.not]: true,
25
            },
26
            ended: {
27
              [Op.not]: true,
28
            },
29
          },
30
        });
31
        mustExist('Contest Manager', contestManager);
×
32

33
        // find webhook by ID
34
        const client = new NeynarAPIClient(config.CONTESTS.NEYNAR_API_KEY!);
×
35
        const { webhook: existingCastWebhook } = await client.lookupWebhook(
×
36
          config.CONTESTS.NEYNAR_CAST_WEBHOOK_ID!,
37
        );
38
        mustExist('Neynar Webhook', existingCastWebhook);
×
39

40
        // remove and add hashes to subscription
NEW
41
        const allParentHashes = _.uniq([
×
42
          ...(existingCastWebhook?.subscription?.filters['cast.created']
×
43
            ?.parent_hashes || []),
44
          ...(existingCastWebhook?.subscription?.filters['cast.deleted']
×
45
            ?.parent_hashes || []),
46
        ])
47
          .filter((hash) => {
48
            return !(payload.frames_to_remove || []).includes(hash);
×
49
          })
50
          .concat(payload.frames_to_add || []);
×
51

52
        const subscription = {
×
53
          ...(existingCastWebhook.subscription?.filters || {}),
×
54
          // reply cast created on parent
55
          'cast.created': {
56
            ...(existingCastWebhook.subscription?.filters['cast.created'] ||
×
57
              {}),
58
            parent_hashes: allParentHashes,
59
          },
60
          // reply cast deleted on parent
61
          'cast.deleted': {
62
            ...(existingCastWebhook.subscription?.filters['cast.deleted'] ||
×
63
              {}),
64
            parent_hashes: allParentHashes,
65
          },
66
        };
67

68
        await client.updateWebhook(
×
69
          existingCastWebhook.webhook_id,
70
          existingCastWebhook.title,
71
          existingCastWebhook.target_url,
72
          {
73
            subscription,
74
          },
75
        );
76

77
        if (!payload.webhooks_only) {
×
78
          // update contest manager frame hashes
NEW
79
          contestManager.farcaster_frame_hashes = (
×
80
            contestManager.farcaster_frame_hashes || []
×
81
          )
82
            .filter((hash) => {
NEW
83
              return !(payload.frames_to_remove || []).includes(hash);
×
84
            })
85
            .concat(payload.frames_to_add || []);
×
86
          await contestManager.save();
×
87
        }
88
      });
89
    },
90
  };
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc