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

blockcoders / ink-substrate-explorer-frontend / 3676862661

pending completion
3676862661

Pull #12

github

GitHub
Merge fc784ef38 into 94111f4ef
Pull Request #12: change binance-api to fetch from gecko

144 of 192 branches covered (75.0%)

Branch coverage included in aggregate %.

6 of 6 new or added lines in 1 file covered. (100.0%)

575 of 596 relevant lines covered (96.48%)

39.46 hits per line

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

89.09
/components/InfoCard/InfoCard.tsx
1
import { get } from 'lodash'
10✔
2
import Image from 'next/future/image'
10✔
3
import { useRouter } from 'next/router'
10✔
4
import { useState, useEffect } from 'react'
10✔
5
import { toast } from 'react-toastify'
10✔
6
import time from '../../assets/img/bxs_time.svg'
10✔
7
import coin from '../../assets/img/ph_coin-vertical-fill.svg'
10✔
8
import { useGetLastBlockQuery, GetLastBlockQuery, useVersionQuery, VersionQuery } from '../../generated'
10✔
9
import { useGetSyncQuery } from '../../generated/index'
10✔
10
import { useFormatIntl } from '../../hooks/useFormatIntl'
10✔
11
import { getTimeAgo } from '../../lib/utils'
10✔
12
import withApollo from '../../lib/withApollo'
10✔
13

14
function InfoCard() {
15
  const { format } = useFormatIntl()
6✔
16
  const { locale } = useRouter()
6✔
17
  const [price, setPrice] = useState(0)
6✔
18
  const { data } = useGetLastBlockQuery({ variables: { skip: 0, take: 1 } })
6✔
19
  const blocks = get(data, 'getBlocks', []) as GetLastBlockQuery['getBlocks']
6✔
20
  const { data: versionData } = useVersionQuery()
6✔
21
  const { data: syncData, refetch } = useGetSyncQuery()
6✔
22
  const [isSyncing, setIsSyncing] = useState(false)
6✔
23
  const [syncingFromBlock, setSyncingFromBlock] = useState(0)
6✔
24
  const version = get(versionData, 'version', []) as VersionQuery['version']
6✔
25
  const token = 'DOT'
6✔
26

27
  useEffect(() => {
6✔
28
    ;(async () => {
1✔
29
      try {
1✔
30
        const data = await fetch('https://api.coingecko.com/api/v3/simple/price?ids=polkadot&vs_currencies=usd')
1✔
31
        const price = await data.json()
1✔
32

33
        setPrice(price?.polkadot?.usd || 0)
1!
34
      } catch (error) {
35
        setPrice(0)
×
36
      }
37
    })()
38
  }, [])
39

40
  useEffect(() => {
6✔
41
    if (syncData) {
4✔
42
      const data = syncData.getSync
4✔
43
      if (!syncingFromBlock) setSyncingFromBlock(syncData?.getSync?.lastSynced)
4✔
44

45
      if (data?.status) {
4✔
46
        if (data?.status?.toLocaleLowerCase().includes('syncing') && syncingFromBlock) {
4✔
47
          setIsSyncing(true)
3✔
48
          toast.info(`${format('syncing')} ${syncingFromBlock}...`, {
3✔
49
            position: 'bottom-right',
50
            isLoading: true,
51
            closeButton: false,
52
            draggable: false,
53
            autoClose: false,
54
            closeOnClick: false,
55
            toastId: 'syncing',
56
          })
57

58
          setTimeout(() => {
3✔
59
            refetch()
×
60
          }, 60000)
61
        } else if (isSyncing) {
1!
62
          toast.dismiss()
×
63
          toast.success(format('all_block_synced'), {
×
64
            position: 'bottom-right',
65
            closeOnClick: false,
66
            toastId: 'synced',
67
          })
68
        }
69
      }
70
    }
71
  }, [syncData, syncingFromBlock])
72

73
  return (
6✔
74
    <>
75
      <div className="ink_infocard">
76
        <div className="ink_infocard-dot">
77
          <Image src={coin} alt="Icon" /> {token + `: $` + price}
78
        </div>
79
        <div className="ink_infocard-last">
80
          <Image src={time} alt="Icon" /> {format('lastest_block')}: {blocks[0]?.number} (
81
          {getTimeAgo(blocks[0]?.timestamp, locale)})
82
        </div>
83
        <div className="ink_infocard-sdk">SDK: {version}</div>
84
      </div>
85
    </>
86
  )
87
}
88

89
export default withApollo(InfoCard)
10✔
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

© 2025 Coveralls, Inc