Skip to content

Commit

Permalink
fix: Parse latest proposal description correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahZinsmeister committed Nov 3, 2021
1 parent 377331c commit 188b321
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/constants/proposals/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const UNISWAP_GRANTS_START_BLOCK = 11473815
export const BRAVO_START_BLOCK = 13059344
export const ONE_BIP_START_BLOCK = 13551293
14 changes: 8 additions & 6 deletions src/state/governance/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { useCallback, useMemo } from 'react'
import { calculateGasMargin } from 'utils/calculateGasMargin'

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 { useLogs } from '../logs/hooks'
import { useSingleCallResult, useSingleContractMultipleData } from '../multicall/hooks'
Expand Down Expand Up @@ -104,14 +104,15 @@ function useFormattedProposalCreatedLogs(
?.filter((parsed) => indices.flat().some((i) => i === parsed.id.toNumber()))
?.map((parsed) => {
let description!: string

const startBlock = parseInt(parsed.startBlock?.toString())
try {
description = parsed.description
} catch (error) {
// replace invalid UTF-8 in the description with replacement characters
let onError = Utf8ErrorFuncs.replace

// Bravo proposal reverses the codepoints for U+2018 (‘) and U+2026 (…)
const startBlock = parseInt(parsed.startBlock?.toString())
if (startBlock === BRAVO_START_BLOCK) {
const U2018 = [0xe2, 0x80, 0x98].toString()
const U2026 = [0xe2, 0x80, 0xa6].toString()
Expand All @@ -131,12 +132,13 @@ function useFormattedProposalCreatedLogs(
}

description = JSON.parse(toUtf8String(error.error.value, onError)) || ''
}

// Bravo proposal omits newlines
if (startBlock === BRAVO_START_BLOCK) {
description = description.replace(/ /g, '\n').replace(/\d\. /g, '\n$&')
}
// Bravo and one bip proposals omit newlines
if (startBlock === BRAVO_START_BLOCK || startBlock === ONE_BIP_START_BLOCK) {
description = description.replace(/ /g, '\n').replace(/\d\. /g, '\n$&')
}

return {
description,
details: parsed.targets.map((target: string, i: number) => {
Expand Down

0 comments on commit 188b321

Please sign in to comment.