• 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/components/AppLayout/Header/components/SafeTokenWidget/useSafeTokenAllocation.ts
1
import { useEffect, useState } from 'react'
2
import useAsync from 'src/logic/hooks/useAsync'
3
import { useSelector } from 'react-redux'
4
import { currentChainId } from 'src/logic/config/store/selectors'
5
import useSafeAddress from 'src/logic/currentSession/hooks/useSafeAddress'
6
import { BigNumber } from 'bignumber.js'
7

NEW
8
export const VESTING_URL = 'https://safe-claiming-app-data.gnosis-safe.io/allocations/'
×
9

10
export type VestingData = {
11
  tag: 'user' | 'ecosystem'
12
  account: string
13
  chainId: number
14
  contract: string
15
  vestingId: string
16
  durationWeeks: number
17
  startDate: number
18
  amount: string
19
  curve: 0 | 1
20
  proof: string[]
21
}
22

NEW
23
const fetchAllocation = async (chainId: string, safeAddress: string) => {
×
NEW
24
  try {
×
NEW
25
    const response = await fetch(`${VESTING_URL}${chainId}/${safeAddress}.json`)
×
26

NEW
27
    if (response.ok) {
×
NEW
28
      return response.json() as Promise<VestingData[]>
×
29
    }
30

NEW
31
    if (response.status === 404) {
×
32
      // No file exists => the safe is not part of any vesting
NEW
33
      return Promise.resolve([]) as Promise<VestingData[]>
×
34
    }
35
  } catch (err) {
NEW
36
    throw Error(`Error fetching vestings: ${err}`)
×
37
  }
38
}
39

NEW
40
const useSafeTokenAllocation = (): string => {
×
NEW
41
  const [allocation, setAllocation] = useState<string>('0')
×
NEW
42
  const chainId = useSelector(currentChainId)
×
NEW
43
  const { safeAddress } = useSafeAddress()
×
44

NEW
45
  const [allocationData] = useAsync<VestingData[] | undefined>(
×
NEW
46
    () => fetchAllocation(chainId, safeAddress),
×
47
    [chainId, safeAddress],
48
  )
49

NEW
50
  useEffect(() => {
×
NEW
51
    if (!allocationData) return
×
52

NEW
53
    const userAllocation = allocationData.find((data) => data.tag === 'user')
×
NEW
54
    const ecosystemAllocation = allocationData.find((data) => data.tag === 'ecosystem')
×
55

NEW
56
    const totalAllocation = new BigNumber(userAllocation?.amount || '0')
×
57
      .plus(ecosystemAllocation?.amount || '0')
×
58
      .toString()
59

NEW
60
    setAllocation(totalAllocation)
×
61
  }, [allocationData])
62

NEW
63
  return allocation
×
64
}
65

66
export default useSafeTokenAllocation
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