fix: Parse latest proposal description correctly

This commit is contained in:
Noah Zinsmeister 2021-11-03 13:12:39 -04:00
parent 377331c44e
commit 188b321cc9
No known key found for this signature in database
GPG Key ID: 83022DD49188C9F2
2 changed files with 10 additions and 7 deletions

@ -1,2 +1,3 @@
export const UNISWAP_GRANTS_START_BLOCK = 11473815 export const UNISWAP_GRANTS_START_BLOCK = 11473815
export const BRAVO_START_BLOCK = 13059344 export const BRAVO_START_BLOCK = 13059344
export const ONE_BIP_START_BLOCK = 13551293

@ -21,7 +21,7 @@ import { useCallback, useMemo } from 'react'
import { calculateGasMargin } from 'utils/calculateGasMargin' import { calculateGasMargin } from 'utils/calculateGasMargin'
import { SupportedChainId } from '../../constants/chains' import { SupportedChainId } from '../../constants/chains'
import { BRAVO_START_BLOCK, UNISWAP_GRANTS_START_BLOCK } from '../../constants/proposals' import { BRAVO_START_BLOCK, ONE_BIP_START_BLOCK, UNISWAP_GRANTS_START_BLOCK } from '../../constants/proposals'
import { UNI } from '../../constants/tokens' import { UNI } from '../../constants/tokens'
import { useLogs } from '../logs/hooks' import { useLogs } from '../logs/hooks'
import { useSingleCallResult, useSingleContractMultipleData } from '../multicall/hooks' import { useSingleCallResult, useSingleContractMultipleData } from '../multicall/hooks'
@ -104,6 +104,8 @@ function useFormattedProposalCreatedLogs(
?.filter((parsed) => indices.flat().some((i) => i === parsed.id.toNumber())) ?.filter((parsed) => indices.flat().some((i) => i === parsed.id.toNumber()))
?.map((parsed) => { ?.map((parsed) => {
let description!: string let description!: string
const startBlock = parseInt(parsed.startBlock?.toString())
try { try {
description = parsed.description description = parsed.description
} catch (error) { } catch (error) {
@ -111,7 +113,6 @@ function useFormattedProposalCreatedLogs(
let onError = Utf8ErrorFuncs.replace let onError = Utf8ErrorFuncs.replace
// Bravo proposal reverses the codepoints for U+2018 () and U+2026 (…) // Bravo proposal reverses the codepoints for U+2018 () and U+2026 (…)
const startBlock = parseInt(parsed.startBlock?.toString())
if (startBlock === BRAVO_START_BLOCK) { if (startBlock === BRAVO_START_BLOCK) {
const U2018 = [0xe2, 0x80, 0x98].toString() const U2018 = [0xe2, 0x80, 0x98].toString()
const U2026 = [0xe2, 0x80, 0xa6].toString() const U2026 = [0xe2, 0x80, 0xa6].toString()
@ -131,12 +132,13 @@ function useFormattedProposalCreatedLogs(
} }
description = JSON.parse(toUtf8String(error.error.value, onError)) || '' description = JSON.parse(toUtf8String(error.error.value, onError)) || ''
}
// Bravo proposal omits newlines // Bravo and one bip proposals omit newlines
if (startBlock === BRAVO_START_BLOCK) { if (startBlock === BRAVO_START_BLOCK || startBlock === ONE_BIP_START_BLOCK) {
description = description.replace(/ /g, '\n').replace(/\d\. /g, '\n$&') description = description.replace(/ /g, '\n').replace(/\d\. /g, '\n$&')
} }
}
return { return {
description, description,
details: parsed.targets.map((target: string, i: number) => { details: parsed.targets.map((target: string, i: number) => {