diff --git a/lib/connect-wallet/config/chains.js b/lib/connect-wallet/config/chains.js
index 99c0c4927..840aad42c 100644
--- a/lib/connect-wallet/config/chains.js
+++ b/lib/connect-wallet/config/chains.js
@@ -190,7 +190,7 @@ export const ChainLogos = {
export const ChainAnalyticsColors = {
DEFAULT: '4E7DD9',
- 43113: '21AD8C',
+ 43113: 'E84142',
84531: '4E7DD9',
42161: '21AD8C',
1: '4E7DD9',
@@ -206,6 +206,10 @@ export const ChainColorsRGB = {
56: '202, 133, 4'
}
+export const getHexColorByChain = (chainId) => {
+ return `#${ChainAnalyticsColors[chainId] || ChainAnalyticsColors.DEFAULT}`
+}
+
export const explorer = {
address: {
56: 'https://bscscan.com/address/%s',
diff --git a/lib/dates.js b/lib/dates.js
index c4e7f1ccf..5bb6aab75 100644
--- a/lib/dates.js
+++ b/lib/dates.js
@@ -23,7 +23,7 @@ function getMonthsBetweenDates (locale, startDate, endDate) {
return months
}
-function formatDateByLocale (locale, date, overrides = {}) {
+function formatDateByLocale (locale = 'en', date, overrides = {}) {
return new Date(date).toLocaleString(locale, { month: 'short', year: '2-digit', ...overrides })
}
diff --git a/src/common/LiquidityForms/ProvideLiquidityForm.jsx b/src/common/LiquidityForms/ProvideLiquidityForm.jsx
index 812c9f1e3..326a81a19 100644
--- a/src/common/LiquidityForms/ProvideLiquidityForm.jsx
+++ b/src/common/LiquidityForms/ProvideLiquidityForm.jsx
@@ -28,7 +28,6 @@ import { Routes } from '@/src/config/routes'
import { useAppConstants } from '@/src/context/AppConstants'
import { useNetwork } from '@/src/context/Network'
import { useCalculatePods } from '@/src/hooks/useCalculatePods'
-import { useCoverActiveReportings } from '@/src/hooks/useCoverActiveReportings'
import { useProvideLiquidity } from '@/src/hooks/useProvideLiquidity'
import {
convertFromUnits,
@@ -44,6 +43,7 @@ import {
Trans
} from '@lingui/macro'
import { useLingui } from '@lingui/react'
+import { useActiveReportings } from '@/src/hooks/useActiveReportings'
export const ProvideLiquidityForm = ({ coverKey, info, isDiversified, underwrittenProducts }) => {
const [lqValue, setLqValue] = useState('')
@@ -107,7 +107,7 @@ export const ProvideLiquidityForm = ({ coverKey, info, isDiversified, underwritt
podAddress: vaultTokenAddress
})
- const { data: activeReportings } = useCoverActiveReportings({ coverKey })
+ const { data: activeReportings } = useActiveReportings()
const requiredStake = toBN(minStakeToAddLiquidity).minus(myStake).toString()
@@ -184,10 +184,12 @@ export const ProvideLiquidityForm = ({ coverKey, info, isDiversified, underwritt
const hasBothAllowances = hasLqTokenAllowance && hasNPMTokenAllowance
- if (activeReportings.length > 0) {
- const status = activeReportings[0].status
- const incidentDate = activeReportings[0].incidentDate
- const productKey = activeReportings[0].productKey
+ // @todo: Instead we could expose `isCoverNormalInternal` from smart contracts
+ const currentCoverActiveIncidents = activeReportings.incidentReports.filter(x => { return x.coverKey === coverKey })
+ if (currentCoverActiveIncidents.length > 0) {
+ const status = 'Reporting' // @todo: Update status to be dynamic from API or smart contracts
+ const incidentDate = currentCoverActiveIncidents[0].incidentDate
+ const productKey = currentCoverActiveIncidents[0].productKey
const statusLink = (
{
- return `
- {
- userPolicies(
- skip: ${limit * (page - 1)}
- first: ${limit}
- where: {
- expiresOn_gt: "${startOfMonth}"
- account: "${account}"
- coverKey: "${coverKey}"
- productKey: "${productKey}"
- }
- ) {
- id
- coverKey
- productKey
- cxToken {
- id
- creationDate
- expiryDate
- tokenSymbol
- tokenDecimals
- }
- totalAmountToCover
- expiresOn
- cover {
- id
- }
- }
- }
- `
-}
-
-export const useActivePoliciesByCover = ({
- coverKey,
- productKey,
- limit,
- page
-}) => {
- const [data, setData] = useState({
- userPolicies: []
- })
- const [loading, setLoading] = useState(false)
- const [hasMore, setHasMore] = useState(true)
-
- const { networkId } = useNetwork()
- const { account } = useWeb3React()
- const fetchActivePoliciesByCover = useSubgraphFetch(
- 'useActivePoliciesByCover'
- )
-
- useEffect(() => {
- if (!networkId || !account) {
- return
- }
-
- const startOfMonth = DateLib.toUnix(DateLib.getSomInUTC(Date.now()))
-
- setLoading(true)
-
- fetchActivePoliciesByCover(
- networkId,
- getQuery(limit, page, startOfMonth, account, coverKey, productKey)
- )
- .then((_data) => {
- if (!_data) { return }
-
- const isLastPage =
- _data.userPolicies.length === 0 || _data.userPolicies.length < limit
-
- if (isLastPage) {
- setHasMore(false)
- }
-
- setData((prev) => {
- return {
- userPolicies: [...prev.userPolicies, ..._data.userPolicies]
- }
- })
- })
- .catch((err) => {
- console.error(err)
- })
- .finally(() => {
- setLoading(false)
- })
- }, [
- account,
- coverKey,
- fetchActivePoliciesByCover,
- limit,
- networkId,
- page,
- productKey
- ])
-
- const totalActiveProtection = useMemo(() => {
- return sumOf(
- '0',
- ...data.userPolicies.map((x) => { return x.totalAmountToCover || '0' })
- )
- }, [data.userPolicies])
-
- return {
- data: {
- activePolicies: data.userPolicies,
- totalActiveProtection
- },
- loading,
- hasMore
- }
-}
diff --git a/src/hooks/useActiveReportings.jsx b/src/hooks/useActiveReportings.jsx
index 957f25ba2..071d01864 100644
--- a/src/hooks/useActiveReportings.jsx
+++ b/src/hooks/useActiveReportings.jsx
@@ -1,53 +1,36 @@
import { useState, useEffect, useCallback } from 'react'
import { useNetwork } from '@/src/context/Network'
import { CARDS_PER_PAGE } from '@/src/config/constants'
-import { useSubgraphFetch } from '@/src/hooks/useSubgraphFetch'
-
-const getQuery = (itemsToSkip) => {
- return `
- {
- incidentReports(
- skip: ${itemsToSkip}
- first: ${CARDS_PER_PAGE}
- orderBy: incidentDate
- orderDirection: desc
- where:{
- finalized: false
- }
- ) {
- id
- coverKey
- productKey
- incidentDate
- resolutionDeadline
- resolved
- finalized
- status
- resolutionTimestamp
- }
- }
- `
-}
+import { getActiveIncidents } from '@/src/services/api/consensus/active'
export const useActiveReportings = () => {
const [data, setData] = useState({ incidentReports: [] })
- const [loading, setLoading] = useState(false)
+ const [loading, setLoading] = useState(true)
const [itemsToSkip, setItemsToSkip] = useState(0)
const [hasMore, setHasMore] = useState(true)
const { networkId } = useNetwork()
- const fetchActiveReportings = useSubgraphFetch('useActiveReportings')
useEffect(() => {
+ setData({ incidentReports: [] })
+ setItemsToSkip(0)
+ setHasMore(true)
+ setLoading(true)
+ }, [networkId])
+
+ useEffect(() => {
+ let ignore = false
+
setLoading(true)
- fetchActiveReportings(networkId, getQuery(itemsToSkip))
+ // @ts-ignore
+ getActiveIncidents(networkId, itemsToSkip)
.then((_data) => {
- if (!_data) { return }
+ if (ignore || !_data) { return }
const isLastPage =
- _data.incidentReports.length === 0 ||
- _data.incidentReports.length < CARDS_PER_PAGE
+ _data.length === 0 ||
+ _data.length < CARDS_PER_PAGE
if (isLastPage) {
setHasMore(false)
@@ -55,7 +38,7 @@ export const useActiveReportings = () => {
setData((prev) => {
return {
- incidentReports: [...prev.incidentReports, ..._data.incidentReports]
+ incidentReports: [...prev.incidentReports, ..._data]
}
})
})
@@ -65,7 +48,11 @@ export const useActiveReportings = () => {
.finally(() => {
setLoading(false)
})
- }, [fetchActiveReportings, itemsToSkip, networkId])
+
+ return () => {
+ ignore = true
+ }
+ }, [itemsToSkip, networkId])
const handleShowMore = useCallback(() => {
setItemsToSkip((prev) => { return prev + CARDS_PER_PAGE })
diff --git a/src/hooks/useConsensusInsights.jsx b/src/hooks/useConsensusInsights.jsx
index 1ffa26007..3259d5972 100644
--- a/src/hooks/useConsensusInsights.jsx
+++ b/src/hooks/useConsensusInsights.jsx
@@ -5,33 +5,7 @@ import {
} from 'react'
import { useNetwork } from '@/src/context/Network'
-import { getSubgraphData } from '@/src/services/subgraph'
-
-const getQuery = () => {
- return `
- {
- incidentReports(
- orderBy: incidentDate
- orderDirection: desc
- where:{
- finalized: false
- }
- ) {
- id
- coverKey
- productKey
- incidentDate
- resolutionDeadline
- resolved
- finalized
- status
- resolutionTimestamp
- totalRefutedStake
- totalAttestedStake
- }
- }
-`
-}
+import { getActiveIncidents } from '@/src/services/api/consensus/active'
export const useConsensusInsights = () => {
const [data, setData] = useState({
@@ -49,13 +23,13 @@ export const useConsensusInsights = () => {
setLoading(true)
- getSubgraphData(networkId, getQuery())
+ getActiveIncidents(networkId)
.then((_data) => {
if (!_data) { return }
setData(() => {
return {
- incidentReports: _data.incidentReports
+ incidentReports: _data
}
})
diff --git a/src/hooks/useCoverActiveReportings.jsx b/src/hooks/useCoverActiveReportings.jsx
deleted file mode 100644
index 9f2916681..000000000
--- a/src/hooks/useCoverActiveReportings.jsx
+++ /dev/null
@@ -1,61 +0,0 @@
-import {
- useEffect,
- useState
-} from 'react'
-
-import { getNetworkId } from '@/src/config/environment'
-import { useSubgraphFetch } from '@/src/hooks/useSubgraphFetch'
-
-const getQuery = (coverKey) => {
- return `
- {
- incidentReports(where: {
- coverKey: "${coverKey}"
- finalized: false
- }) {
- id
- status
- productKey
- incidentDate
- }
- }
- `
-}
-
-// @todo: Instead we could expose `isCoverNormalInternal` from smart contracts
-/**
- *
- * @param {object} param
- * @param {string} param.coverKey
- * @returns
- */
-export const useCoverActiveReportings = ({ coverKey }) => {
- const [data, setData] = useState([])
- const [loading, setLoading] = useState(false)
- const fetchCoverActiveReportings = useSubgraphFetch(
- 'useCoverActiveReportings'
- )
-
- useEffect(() => {
- if (!coverKey || !getNetworkId()) {
- return
- }
-
- setLoading(true)
- fetchCoverActiveReportings(getNetworkId(), getQuery(coverKey))
- .then((result) => {
- if (!result) {
- return
- }
-
- return setData(result.incidentReports)
- })
- .catch((e) => { return console.error(e) })
- .finally(() => { return setLoading(false) })
- }, [coverKey, fetchCoverActiveReportings])
-
- return {
- data,
- loading
- }
-}
diff --git a/src/hooks/useCoverEarningInsights.jsx b/src/hooks/useCoverEarningInsights.jsx
index ae5a27627..2981a2030 100644
--- a/src/hooks/useCoverEarningInsights.jsx
+++ b/src/hooks/useCoverEarningInsights.jsx
@@ -1,4 +1,5 @@
import {
+ useCallback,
useEffect,
useMemo,
useState
@@ -9,9 +10,10 @@ import {
getMonthsBetweenDates
} from '@/lib/dates'
import { useAppConstants } from '@/src/context/AppConstants'
-import { useProtocolMonthData } from '@/src/hooks/useProtocolMonthData'
import { useLanguageContext } from '@/src/i18n/i18n'
import { toBN } from '@/utils/bn'
+import { getCoverEarnings } from '@/src/services/api/home/charts/cover-earnings'
+import { useNetwork } from '@/src/context/Network'
const getInitialDateRange = (from) => {
const currentDate = from
@@ -30,7 +32,10 @@ const getInitialDateRange = (from) => {
function useCoverEarningInsights () {
const [dateRange, setDateRange] = useState(getInitialDateRange(new Date()))
- const { data, loading, fetchData } = useProtocolMonthData()
+ const { networkId } = useNetwork()
+
+ const [loading, setLoading] = useState(true)
+ const [data, setData] = useState([])
const { liquidityTokenDecimals } = useAppConstants()
@@ -54,6 +59,21 @@ function useCoverEarningInsights () {
setDateRange(getInitialDateRange(newInitialDate))
}
+ const fetchData = useCallback(() => {
+ getCoverEarnings(networkId)
+ .then((_data) => {
+ if (_data) {
+ setData(_data)
+ }
+ })
+ .catch((err) => {
+ console.error(err)
+ })
+ .finally(() => {
+ setLoading(false)
+ })
+ }, [networkId])
+
useEffect(() => {
if (data) {
const newLabels = getMonthsBetweenDates(locale, dateRange[0], dateRange[1])
@@ -61,14 +81,14 @@ function useCoverEarningInsights () {
setLabels(newLabels)
const monthDataInRange = data.filter((monthData) => {
- const monthDate = new Date(monthData.id)
+ const monthDate = new Date(monthData.startDate)
const id = new Date(monthDate.getTime() + monthDate.getTimezoneOffset() * 60 * 1000)
return id >= dateRange[0] && id <= dateRange[1]
}).map(monthData => {
return {
...monthData,
- id: formatDateByLocale(locale, new Date(monthData.id), { timeZone: 'UTC' })
+ id: formatDateByLocale(locale, monthData.endDate, { timeZone: 'UTC' })
}
})
@@ -76,7 +96,7 @@ function useCoverEarningInsights () {
const foundMonth = monthDataInRange.find(monthData => { return monthData.id === lbl })
if (foundMonth) {
- return foundMonth.nonCumulativeCoverFee
+ return foundMonth.totalCoverFeeEarned
}
return '0'
diff --git a/src/hooks/useFetchCoverProductActiveReportings.jsx b/src/hooks/useFetchCoverProductActiveReportings.jsx
deleted file mode 100644
index a7d74606e..000000000
--- a/src/hooks/useFetchCoverProductActiveReportings.jsx
+++ /dev/null
@@ -1,59 +0,0 @@
-import { useState, useEffect } from 'react'
-import { getNetworkId } from '@/src/config/environment'
-import { useSubgraphFetch } from '@/src/hooks/useSubgraphFetch'
-
-const getQuery = (coverKey, productKey) => {
- return `
- {
- incidentReports(where: {
- coverKey: "${coverKey}"
- productKey: "${productKey}"
- finalized: false
- }) {
- id
- reporterInfo
- coverKey
- productKey
- incidentDate
- }
- }
- `
-}
-
-/**
- *
- * @param {object} param
- * @param {string} param.coverKey
- * @param {string} param.productKey
- * @returns
- */
-export const useFetchCoverProductActiveReportings = ({
- coverKey,
- productKey
-}) => {
- const [data, setData] = useState([])
- const [loading, setLoading] = useState(false)
- const fetchCoverProductActiveReportings = useSubgraphFetch(
- 'useFetchCoverProductActiveReportings'
- )
-
- useEffect(() => {
- if (productKey && coverKey) {
- setLoading(true)
- fetchCoverProductActiveReportings(
- getNetworkId(),
- getQuery(coverKey, productKey)
- )
- .then(({ incidentReports }) => {
- setData(incidentReports)
- })
- .catch((e) => { return console.error(e) })
- .finally(() => { return setLoading(false) })
- }
- }, [coverKey, fetchCoverProductActiveReportings, productKey])
-
- return {
- data,
- loading
- }
-}
diff --git a/src/hooks/useFetchReport.jsx b/src/hooks/useFetchReport.jsx
index 16f014275..48d4f40b6 100644
--- a/src/hooks/useFetchReport.jsx
+++ b/src/hooks/useFetchReport.jsx
@@ -1,64 +1,11 @@
import {
useCallback,
useEffect,
- useMemo,
useState
} from 'react'
-import { getNetworkId } from '@/src/config/environment'
-import { useSubgraphFetch } from '@/src/hooks/useSubgraphFetch'
-
-const getQuery = (reportId) => {
- return `
- {
- incidentReport(
- id: "${reportId}"
- ) {
- id
- coverKey
- productKey
- incidentDate
- resolutionDeadline
- resolved
- resolveTransaction{
- timestamp
- }
- emergencyResolved
- emergencyResolveTransaction{
- timestamp
- }
- finalized
- status
- decision
- resolutionTimestamp
- claimBeginsFrom
- claimExpiresAt
- reporter
- reporterInfo
- reporterStake
- disputer
- disputerInfo
- disputerStake
- totalAttestedStake
- totalAttestedCount
- totalRefutedStake
- totalRefutedCount
- reportTransaction {
- id
- timestamp
- }
- disputeTransaction {
- id
- timestamp
- }
- reportIpfsHash
- disputeIpfsHash
- reportIpfsData
- disputeIpfsData
- }
- }
- `
-}
+import { getIncidentDetail } from '@/src/services/api/consensus/detail'
+import { useNetwork } from '@/src/context/Network'
/**
*
@@ -70,31 +17,25 @@ const getQuery = (reportId) => {
*/
export const useFetchReport = ({ coverKey, productKey, incidentDate }) => {
const [data, setData] = useState(null)
- const [loading, setLoading] = useState(false)
- const fetchReport = useSubgraphFetch('useFetchReport')
+ const [loading, setLoading] = useState(true)
- const reportId = useMemo(() => {
- if (!coverKey || !productKey || !incidentDate) {
- return null
- }
-
- return `${coverKey}-${productKey}-${incidentDate}`
- }, [coverKey, incidentDate, productKey])
+ const { networkId } = useNetwork()
- const getData = useCallback(async () => {
- if (!reportId) {
+ const getData = useCallback(() => {
+ if (!coverKey || !productKey || !incidentDate) {
return
}
- try {
- const data = await fetchReport(getNetworkId(), getQuery(reportId))
- if (data && data.incidentReport) {
- setData(data.incidentReport)
- }
- } catch (e) {
- console.error(e)
- }
- }, [fetchReport, reportId])
+ return getIncidentDetail(networkId, coverKey, productKey, incidentDate)
+ .then(data => {
+ if (data) {
+ setData(data)
+ }
+ })
+ .catch(error => {
+ console.error(error)
+ })
+ }, [coverKey, productKey, incidentDate, networkId])
useEffect(() => {
async function updateData () {
diff --git a/src/hooks/useFetchReportsByKeyAndDate.jsx b/src/hooks/useFetchReportsByKeyAndDate.jsx
deleted file mode 100644
index d0e3e2b05..000000000
--- a/src/hooks/useFetchReportsByKeyAndDate.jsx
+++ /dev/null
@@ -1,54 +0,0 @@
-import { useState, useEffect } from 'react'
-import { getNetworkId } from '@/src/config/environment'
-import { useSubgraphFetch } from '@/src/hooks/useSubgraphFetch'
-
-const getQuery = (coverKey, incidentDate) => {
- return `
- {
- incidentReports (
- where: {
- coverKey: "${coverKey}"
- incidentDate: "${incidentDate}"
- decision: true
- resolved: true
- }
- ) {
- id
- claimExpiresAt
- }
- }
-
- `
-}
-
-/**
- *
- * @param {object} param
- * @param {string} param.coverKey
- * @param {string | string[]} param.incidentDate
- * @returns
- */
-export const useFetchReportsByKeyAndDate = ({ coverKey, incidentDate }) => {
- const [data, setData] = useState([])
- const [loading, setLoading] = useState(false)
- const fetchReportsByKeyAndDate = useSubgraphFetch(
- 'useFetchReportsByKeyAndDate'
- )
-
- useEffect(() => {
- if (coverKey && incidentDate) {
- setLoading(true)
- fetchReportsByKeyAndDate(getNetworkId(), getQuery(coverKey, incidentDate))
- .then(({ incidentReports }) => {
- setData(incidentReports)
- })
- .catch((e) => { return console.error(e) })
- .finally(() => { return setLoading(false) })
- }
- }, [coverKey, fetchReportsByKeyAndDate, incidentDate])
-
- return {
- data,
- loading
- }
-}
diff --git a/src/hooks/useProtectionChartData.jsx b/src/hooks/useProtectionChartData.jsx
index 83431121b..4172e7f28 100644
--- a/src/hooks/useProtectionChartData.jsx
+++ b/src/hooks/useProtectionChartData.jsx
@@ -1,25 +1,31 @@
import {
useCallback,
+ useMemo,
useRef,
useState
} from 'react'
+import { useRouter } from 'next/router'
+
import { useNetwork } from '@/src/context/Network'
import {
getProtectionByMonth
} from '@/src/services/api/home/charts/protection-by-month'
-import { sortDates } from '@/utils/sorting'
+import { formatDateByLocale } from '@/lib/dates'
-const getAggregatedDataWithLabels = (data = []) => {
+const getAggregatedDataWithLabels = (data = [], locale) => {
const aggregatedData = {}
let labels = []
data.forEach(item => {
+ const label = formatDateByLocale(locale, new Date(item.expiresOn || item.endDate), { timeZone: 'UTC' })
+
const chain = item.chainId
if (!aggregatedData[chain]) { aggregatedData[chain] = [] }
aggregatedData[chain].push({
- label: item.expiry,
+ label,
+ date: item.expiresOn || item.endDate,
protection: item.protection,
income: item.income,
expired: item.expired,
@@ -28,7 +34,6 @@ const getAggregatedDataWithLabels = (data = []) => {
incomePercent: item.feeRate
})
- const label = item.expiry
if (!labels.includes(label)) { labels.push(label) }
})
@@ -54,19 +59,18 @@ const getAggregatedDataWithLabels = (data = []) => {
Object.keys(aggregatedData).forEach(chain => {
const arr = aggregatedData[chain]
- const sortedArr = sortDates(
- arr,
- x => { return x.label }
- )
+
+ // @ts-ignore
+ const sortedArr = arr.sort((a, b) => { return new Date(b.date) - new Date(a.date) })
aggregatedData[chain] = sortedArr
})
- // @todo: Remove this once the backend API is updated
- Object.keys(aggregatedData).forEach(chain => {
- aggregatedData[chain].reverse()
- })
+ const keys = Object.keys(aggregatedData)
+
+ if (keys.length === 0) { return { data: {}, labels: [] } }
+
+ const key = keys[0]
- const key = Object.keys(aggregatedData)[0]
labels = aggregatedData[key].map(i => { return i.label })
return {
@@ -78,8 +82,9 @@ const getAggregatedDataWithLabels = (data = []) => {
export const useProtectionChartData = () => {
const fetched = useRef(false)
const [loading, setLoading] = useState(false)
- const [data, setData] = useState(null)
- const [labels, setLabels] = useState([])
+ const [_data, _setData] = useState(undefined)
+
+ const { locale } = useRouter()
const { networkId } = useNetwork()
@@ -91,11 +96,9 @@ export const useProtectionChartData = () => {
try {
const _data = await getProtectionByMonth(networkId)
- const { labels, data } = getAggregatedDataWithLabels(_data)
+ _setData(_data)
- setData(data)
fetched.current = true
- setLabels(labels)
} catch (err) {
console.error(err)
}
@@ -103,6 +106,10 @@ export const useProtectionChartData = () => {
setLoading(false)
}, [networkId])
+ const { data, labels } = useMemo(() => {
+ return getAggregatedDataWithLabels(_data, locale)
+ }, [locale, _data])
+
return {
fetchMonthlyProtectionData,
loading,
diff --git a/src/hooks/useProtocolMonthData.jsx b/src/hooks/useProtocolMonthData.jsx
deleted file mode 100644
index e74e22f32..000000000
--- a/src/hooks/useProtocolMonthData.jsx
+++ /dev/null
@@ -1,46 +0,0 @@
-import {
- useCallback,
- useRef,
- useState
-} from 'react'
-
-import { useNetwork } from '@/src/context/Network'
-import {
- getGroupedProtocolMonthData
-} from '@/src/services/aggregated-stats/protocol'
-
-export const useProtocolMonthData = (cache = true) => {
- const [data, setData] = useState(null)
- const [loading, setLoading] = useState(false)
-
- const fetched = useRef(false)
-
- const { networkId } = useNetwork()
-
- const fetchData = useCallback(() => {
- if ((cache && fetched.current)) { return }
-
- setLoading(true)
-
- getGroupedProtocolMonthData(networkId)
- .then((_data) => {
- if (!_data) { return }
-
- setData(_data)
-
- fetched.current = true
- })
- .catch((err) => {
- console.error(err)
- })
- .finally(() => {
- setLoading(false)
- })
- }, [cache, networkId])
-
- return {
- data,
- loading,
- fetchData
- }
-}
diff --git a/src/hooks/useResolvedReportings.jsx b/src/hooks/useResolvedReportings.jsx
index 359fd649a..8b9c46ac6 100644
--- a/src/hooks/useResolvedReportings.jsx
+++ b/src/hooks/useResolvedReportings.jsx
@@ -1,69 +1,36 @@
-import {
- useCallback,
- useEffect,
- useState
-} from 'react'
-
-import { CARDS_PER_PAGE } from '@/src/config/constants'
+import { useState, useEffect, useCallback } from 'react'
import { useNetwork } from '@/src/context/Network'
-import { useSubgraphFetch } from '@/src/hooks/useSubgraphFetch'
-
-const getQuery = (itemsToSkip) => {
- return `
- {
- incidentReports(
- skip: ${itemsToSkip}
- first: ${CARDS_PER_PAGE}
- orderBy: incidentDate
- orderDirection: desc
- where:{
- resolved: true
- }
- ) {
- id
- coverKey
- productKey
- incidentDate
- resolutionDeadline
- resolved
- emergencyResolved
- emergencyResolveTransaction{
- timestamp
- }
- resolveTransaction{
- timestamp
- }
- finalized
- status
- resolutionTimestamp
- totalAttestedStake
- totalRefutedStake
- }
- }
- `
-}
+import { CARDS_PER_PAGE } from '@/src/config/constants'
+import { getResolvedIncidents } from '@/src/services/api/consensus/resolved'
export const useResolvedReportings = () => {
- const [data, setData] = useState({
- incidentReports: []
- })
- const [loading, setLoading] = useState(false)
+ const [data, setData] = useState({ incidentReports: [] })
+ const [loading, setLoading] = useState(true)
const [itemsToSkip, setItemsToSkip] = useState(0)
const [hasMore, setHasMore] = useState(true)
const { networkId } = useNetwork()
- const fetchResolvedReportings = useSubgraphFetch('useResolvedReportings')
useEffect(() => {
+ setData({ incidentReports: [] })
+ setItemsToSkip(0)
+ setHasMore(true)
setLoading(true)
+ }, [networkId])
- fetchResolvedReportings(networkId, getQuery(itemsToSkip))
+ useEffect(() => {
+ let ignore = false
+
+ setLoading(true)
+
+ // @ts-ignore
+ getResolvedIncidents(networkId, itemsToSkip)
.then((_data) => {
- if (!_data) { return }
+ if (ignore || !_data) { return }
const isLastPage =
- _data.incidentReports.length === 0 ||
- _data.incidentReports.length < CARDS_PER_PAGE
+ _data.length === 0 ||
+ _data.length < CARDS_PER_PAGE
if (isLastPage) {
setHasMore(false)
@@ -71,7 +38,7 @@ export const useResolvedReportings = () => {
setData((prev) => {
return {
- incidentReports: [...prev.incidentReports, ..._data.incidentReports]
+ incidentReports: [...prev.incidentReports, ..._data]
}
})
})
@@ -81,7 +48,11 @@ export const useResolvedReportings = () => {
.finally(() => {
setLoading(false)
})
- }, [fetchResolvedReportings, itemsToSkip, networkId])
+
+ return () => {
+ ignore = true
+ }
+ }, [itemsToSkip, networkId])
const handleShowMore = useCallback(() => {
setItemsToSkip((prev) => { return prev + CARDS_PER_PAGE })
diff --git a/src/hooks/useValidReport.jsx b/src/hooks/useValidReport.jsx
deleted file mode 100644
index 46f8db39e..000000000
--- a/src/hooks/useValidReport.jsx
+++ /dev/null
@@ -1,64 +0,0 @@
-import { useState, useEffect } from 'react'
-import { useNetwork } from '@/src/context/Network'
-import { useSubgraphFetch } from '@/src/hooks/useSubgraphFetch'
-
-const isValidTimestamp = (_unix) => { return !!_unix && _unix !== '0' }
-
-const getQuery = (start, end, coverKey, productKey) => {
- return `
- {
- incidentReports(
- where: {
- incidentDate_gt: "${start}",
- incidentDate_lt: "${end}",
- coverKey: "${coverKey}"
- productKey: "${productKey}"
- },
- orderBy: incidentDate,
- orderDirection: desc
- ) {
- incidentDate
- resolutionDeadline
- status
- claimBeginsFrom
- claimExpiresAt
- }
- }
- `
-}
-
-export const useValidReport = ({ start, end, coverKey, productKey }) => {
- const [data, setData] = useState({
- incidentReports: []
- })
- const [loading, setLoading] = useState(false)
- const { networkId } = useNetwork()
- const fetchValidReport = useSubgraphFetch('useValidReport')
-
- useEffect(() => {
- if (!isValidTimestamp(start) || !isValidTimestamp(end)) {
- return
- }
-
- setLoading(true)
-
- fetchValidReport(networkId, getQuery(start, end, coverKey, productKey))
- .then((_data) => {
- if (!_data) { return }
- setData(_data)
- })
- .catch((err) => {
- console.error(err)
- })
- .finally(() => {
- setLoading(false)
- })
- }, [coverKey, end, fetchValidReport, networkId, productKey, start])
-
- return {
- data: {
- report: data?.incidentReports[0]
- },
- loading
- }
-}
diff --git a/src/modules/home/Hero.jsx b/src/modules/home/Hero.jsx
index 23da4e32f..56f43c27b 100644
--- a/src/modules/home/Hero.jsx
+++ b/src/modules/home/Hero.jsx
@@ -154,7 +154,7 @@ export const HomeHero = ({ breadcrumbs = [], title = '' }) => {
// Active Protection (or) Commitment
name: t(i18n)`Coverage`,
amount: formatCurrency(
- aggregated.totalCoveredAmount,
+ aggregated.activeCoveredAmount,
locale
).short
},
diff --git a/src/modules/insights/Consensus.jsx b/src/modules/insights/Consensus.jsx
index cd1065ca8..5bedad3b1 100644
--- a/src/modules/insights/Consensus.jsx
+++ b/src/modules/insights/Consensus.jsx
@@ -20,7 +20,6 @@ import {
getCoverImgSrc,
isValidProduct
} from '@/src/helpers/cover'
-import { convertFromUnits } from '@/utils/bn'
import { formatCurrency } from '@/utils/formatter/currency'
import { t } from '@lingui/macro'
import { useLingui } from '@lingui/react'
@@ -49,7 +48,7 @@ const renderAttestedStake = (row, { locale, NPMTokenSymbol }) => {
Yes
{DateLib.toDateFormat(
- incidentReport.resolutionTimestamp,
+ incidentReport.reportResolutionTimestamp,
router.locale,
{ month: 'short', day: 'numeric' },
'UTC'
diff --git a/src/modules/reporting/active/CastYourVote.jsx b/src/modules/reporting/active/CastYourVote.jsx
index d34595923..cbf1c522d 100644
--- a/src/modules/reporting/active/CastYourVote.jsx
+++ b/src/modules/reporting/active/CastYourVote.jsx
@@ -109,7 +109,7 @@ export const CastYourVote = ({ incidentReport, idPrefix, reporterCommission, min
const isFirstDispute =
votingType === 'false-reporting' &&
- incidentReport.totalRefutedCount === '0'
+ incidentReport.refutationCount.toString() === '0'
const handleReport = (onTxSuccess) => {
if (votingType === 'false-reporting') {
diff --git a/src/modules/reporting/details.jsx b/src/modules/reporting/details.jsx
index 143668925..e78af88c9 100644
--- a/src/modules/reporting/details.jsx
+++ b/src/modules/reporting/details.jsx
@@ -60,7 +60,7 @@ export const ReportingDetailsPage = ({
const now = DateLib.unix()
const showResolvedSummary = incidentReport.resolved && isPassedResolutionDeadline
- const reportingEnded = isGreater(now, incidentReport.resolutionTimestamp)
+ const reportingEnded = isGreater(now, incidentReport.reportResolutionTimestamp)
return (
{DateLib.toDateFormat(
- incidentReport.resolutionTimestamp,
+ incidentReport.reportResolutionTimestamp,
router.locale,
{ month: 'short', day: 'numeric' },
'UTC'
diff --git a/src/modules/reporting/resolved/ResolvedTBodyRow.jsx b/src/modules/reporting/resolved/ResolvedTBodyRow.jsx
index 3afd4fbd5..f86915481 100644
--- a/src/modules/reporting/resolved/ResolvedTBodyRow.jsx
+++ b/src/modules/reporting/resolved/ResolvedTBodyRow.jsx
@@ -28,8 +28,8 @@ export const ResolvedTBodyRow = ({
id,
coverKey,
productKey = safeFormatBytes32String(''),
- totalAttestedStake,
- totalRefutedStake
+ totalAttestationStake,
+ totalRefutationStake
} = report
const isDiversified = isValidProduct(productKey)
@@ -58,8 +58,8 @@ export const ResolvedTBodyRow = ({
locale: router.locale,
status,
resolvedOn,
- totalAttestedStake,
- totalRefutedStake,
+ totalAttestationStake,
+ totalRefutationStake,
NPMTokenSymbol
})
}
diff --git a/src/modules/reporting/resolved/UnstakeYourAmount.jsx b/src/modules/reporting/resolved/UnstakeYourAmount.jsx
index 52edd4b6b..c137de422 100644
--- a/src/modules/reporting/resolved/UnstakeYourAmount.jsx
+++ b/src/modules/reporting/resolved/UnstakeYourAmount.jsx
@@ -38,14 +38,12 @@ export const UnstakeYourAmount = ({ incidentReport, willReceive, refetchAll, pro
const { unstake, unstakeWithClaim, unstaking } = useUnstakeReportingStake({
coverKey: incidentReport.coverKey,
productKey: incidentReport.productKey,
- incidentDate: incidentReport.incidentDate,
- incidentStatus: incidentReport.status,
- willReceive
+ incidentDate: incidentReport.incidentDate
})
const isClaimExpired = useRetryUntilPassed(() => {
// If false reporting, we don't care about the claim period
- if (!incidentReport.decision) { return true }
+ if (!incidentReport.resolutionDecision) { return true }
const _now = DateLib.unix()
@@ -54,7 +52,7 @@ export const UnstakeYourAmount = ({ incidentReport, willReceive, refetchAll, pro
const isClaimStarted = useRetryUntilPassed(() => {
// If false reporting, we don't care about the claim period
- if (!incidentReport.decision) { return true }
+ if (!incidentReport.resolutionDecision) { return true }
const _now = DateLib.unix()
@@ -71,7 +69,7 @@ export const UnstakeYourAmount = ({ incidentReport, willReceive, refetchAll, pro
const now = DateLib.unix()
- const isIncidentOccurred = incidentReport.decision
+ const isIncidentOccurred = incidentReport.resolutionDecision
const notClaimableYet = isGreater(incidentReport.claimBeginsFrom, now)
const isClaimableNow =
isIncidentOccurred && !isClaimExpired && isClaimStarted
@@ -96,7 +94,7 @@ export const UnstakeYourAmount = ({ incidentReport, willReceive, refetchAll, pro
{ return router.push(getUrl(report.id)) }}
+ onClick={() => { return router.push(Routes.ViewReport(report.coverKey, report.productKey, report.incidentDate)) }}
>
+