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

safe-global / safe-react / 3677785727

12 Dec 2022 04:39PM UTC coverage: 41.909%. First build
3677785727

Pull #4133

github

GitHub
<a href="https://github.com/safe-global/safe-react/commit/<a class=hub.com/safe-global/safe-react/commit/<a class="double-link" href="https://git"><a class=hub.com/safe-global/safe-react/commit/<a class="double-link" href="https://git"><a class=hub.com/safe-global/safe-react/commit/<a class="double-link" href="https://git"><a class=hub.com/safe-global/safe-react/commit/010208b12576ce68cb833c8acf87b4780cedff65">010208b12">&lt;a href=&quot;https://github.com/safe-global/safe-react/commit/</a><a class="double-link" href="https://github.com/safe-global/safe-react/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/safe-global/safe-react/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/safe-global/safe-react/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/safe-global/safe-react/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/safe-global/safe-react/commit/010208b12576ce68cb833c8acf87b4780cedff65">010208b12</a><a href="https://github.com/safe-global/safe-react/commit/010208b12576ce68cb833c8acf87b4780cedff65">&quot;&gt;&amp;lt;a href=&amp;quot;https://github.com/safe-global/safe-react/commit/&lt;/a&gt;&lt;a class=&quot;double-link&quot; href=&quot;https://github.com/safe-global/safe-react/commit/&amp;lt;a class=&amp;quot;double-link&amp;quot; href=&amp;quot;https://git&quot;&gt;&amp;lt;a class=&lt;/a&gt;hub.com/safe-global/safe-react/commit/&amp;lt;a class=&amp;quot;double-link&amp;quot; href=&amp;quot;https://git&quot;&gt;&amp;lt;a class=&lt;/a&gt;hub.com/safe-global/safe-react/commit/&amp;lt;a class=&amp;quot;double-link&amp;quot; href=&amp;quot;https://git&quot;&gt;&amp;lt;a class=&lt;/a&gt;hub.com/safe-global/safe-react/commit/010208b12576ce68cb833c8acf87b4780cedff65&quot;&gt;010208b12&lt;/a&gt;&lt;a href=&quot;https://github.com/safe-global/safe-react/commit/010208b12576ce68cb833c8acf87b4780cedff65&quot;&gt;&amp;quot;&amp;gt;&amp;amp;lt;a href=&amp;amp;quot;https://github.com/safe-global/safe-react/commit/&amp;lt;/a&amp;gt;&amp;lt;a class=&amp;quot;double-link&amp;quot; href=&amp;quot;https://github.com/safe-global/safe-react/commit/&amp;amp;lt;a class=&amp;amp;quot;double-link&amp;amp;quot; href=&amp;amp;quo... (continued)
Pull Request #4133: Desktop v3.33.2

1787 of 5260 branches covered (33.97%)

Branch coverage included in aggregate %.

1278 of 2627 new or added lines in 284 files covered. (48.65%)

4778 of 10405 relevant lines covered (45.92%)

39.02 hits per line

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

0.0
/src/utils/intercom.ts
1
import crypto from 'crypto'
2
import { CookieAttributes } from 'js-cookie'
3
import { COOKIES_KEY_INTERCOM, IntercomCookieType } from 'src/logic/cookies/model/cookie'
4
import { loadFromCookie, saveCookie } from 'src/logic/cookies/utils'
5
import { INTERCOM_ID } from 'src/utils/constants'
6
import { trackEvent } from 'src/utils/googleTagManager'
7
import { OVERVIEW_EVENTS } from 'src/utils/events/overview'
8

9
let intercomLoaded = false
×
10

11
export const isIntercomLoaded = (): boolean => intercomLoaded
×
12

13
const getIntercomUserId = () => {
×
14
  const cookiesState = loadFromCookie<IntercomCookieType>(COOKIES_KEY_INTERCOM)
×
15
  if (!cookiesState) {
×
16
    const userId = crypto.randomBytes(32).toString('hex')
×
17
    const newCookieState = { userId }
×
18
    const cookieConfig: CookieAttributes = {
×
19
      expires: 365,
20
    }
21
    saveCookie<IntercomCookieType>(COOKIES_KEY_INTERCOM, newCookieState, cookieConfig)
×
22
    return userId
×
23
  }
24
  const { userId } = cookiesState
×
25
  return userId
×
26
}
27

28
// eslint-disable-next-line consistent-return
29
export const loadIntercom = (): void => {
×
30
  const APP_ID = INTERCOM_ID
×
31
  if (!APP_ID) {
×
32
    console.error('[Intercom] - In order to use Intercom you need to add an appID')
×
33
    return
×
34
  }
35
  const d = document
×
36
  const s = d.createElement('script')
×
37
  s.type = 'text/javascript'
×
38
  s.async = true
×
39
  s.src = `https://widget.intercom.io/widget/${APP_ID}`
×
40
  const x = d.getElementsByTagName('script')[0]
×
41
  x?.parentNode?.insertBefore(s, x)
×
42

43
  const intercomUserId = getIntercomUserId()
×
44

45
  s.onload = () => {
×
46
    ;(window as any).Intercom('boot', {
×
47
      app_id: APP_ID,
48
      user_id: intercomUserId,
49
    })
50
    intercomLoaded = true
×
NEW
51
    ;(window as any).Intercom('onShow', () => {
×
NEW
52
      trackEvent(OVERVIEW_EVENTS.OPEN_INTERCOM)
×
53
    })
54
  }
55
}
56

57
export const closeIntercom = (): void => {
×
58
  if (!isIntercomLoaded()) return
×
59
  intercomLoaded = false
×
60
  ;(window as any).Intercom('shutdown')
×
61
}
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