From bbb5593992ca83970021c0cd58724f583ed16b34 Mon Sep 17 00:00:00 2001
From: David Llop <931684+sembrestels@users.noreply.github.com>
Date: Wed, 9 Sep 2020 00:12:35 +0200
Subject: [PATCH] Commons Stack + Panvala CV Pilot
---
src/assets/logo-cs.svg | 54 +++++
src/components/AddProposalPanel.js | 300 +++-----------------------
src/components/ConvictionBanner.js | 7 +-
src/components/FilterBar/FilterBar.js | 34 +--
src/components/Footer.js | 42 ++--
src/components/Header.js | 6 +-
src/components/Metrics.js | 72 ++-----
src/networks.js | 11 +-
src/screens/ProposalDetail.js | 3 +-
9 files changed, 142 insertions(+), 387 deletions(-)
create mode 100644 src/assets/logo-cs.svg
diff --git a/src/assets/logo-cs.svg b/src/assets/logo-cs.svg
new file mode 100644
index 0000000..cf56f9a
--- /dev/null
+++ b/src/assets/logo-cs.svg
@@ -0,0 +1,54 @@
+
diff --git a/src/components/AddProposalPanel.js b/src/components/AddProposalPanel.js
index e1cd2df..29293cb 100644
--- a/src/components/AddProposalPanel.js
+++ b/src/components/AddProposalPanel.js
@@ -1,129 +1,24 @@
import React, { useCallback, useMemo, useState } from 'react'
-import {
- Button,
- Checkbox,
- DropDown,
- Field,
- GU,
- Info,
- Link,
- isAddress,
- TextInput,
- useTheme,
-} from '@aragon/ui'
+import { Button, TextInput, Info, Field, GU, Link } from '@aragon/ui'
import { useAppState } from '../providers/AppState'
-import BigNumber from '../lib/bigNumber'
-import { toDecimals } from '../lib/math-utils'
-import { formatTokenAmount } from '../lib/token-utils'
-import { calculateThreshold, getMaxConviction } from '../lib/conviction'
-
import { ZERO_ADDR } from '../constants'
-const NULL_PROPOSAL_TYPE = -1
-const FUNDING_PROPOSAL = 1
-
-const BASE_IPFS_URI = 'https://ipfs.eth.aragon.network/ipfs/'
-const TC_IPFS_HASH = 'QmTSDxWVFnNUis8ZJ7aBfH2z71Jc4N62YLYM9PzJz8DUjt'
-
const DEFAULT_FORM_DATA = {
title: '',
link: '',
- proposalType: NULL_PROPOSAL_TYPE,
- amount: {
- value: '0',
- valueBN: new BigNumber(0),
- },
- beneficiary: '',
}
const AddProposalPanel = React.memo(({ onSubmit }) => {
- const [termsAccepted, setTermsAccepted] = useState(false)
- const theme = useTheme()
- const {
- alpha,
- maxRatio,
- requestToken,
- stakeToken,
- totalSupply,
- vaultBalance,
- weight,
- } = useAppState()
+ const { accountBalance } = useAppState()
const [formData, setFormData] = useState(DEFAULT_FORM_DATA)
- const fundingMode = formData.proposalType === FUNDING_PROPOSAL
-
- const handleAmountEditMode = useCallback(
- editMode => {
- setFormData(formData => {
- const { amount } = formData
-
- const newValue = amount.valueBN.gte(0)
- ? formatTokenAmount(
- amount.valueBN,
- stakeToken.decimals,
- false,
- false,
- {
- commas: !editMode,
- replaceZeroBy: editMode ? '' : '0',
- rounding: stakeToken.decimals,
- }
- )
- : ''
-
- return {
- ...formData,
- amount: {
- ...amount,
- value: newValue,
- },
- }
- })
- },
- [stakeToken]
- )
-
- const handleProposalTypeChange = useCallback(selected => {
- setFormData(formData => ({
- ...formData,
- proposalType: selected,
- }))
- }, [])
-
const handleTitleChange = useCallback(event => {
const updatedTitle = event.target.value
setFormData(formData => ({ ...formData, title: updatedTitle }))
}, [])
- const handleAmountChange = useCallback(
- event => {
- const updatedAmount = event.target.value
-
- const newAmountBN = new BigNumber(
- isNaN(updatedAmount)
- ? -1
- : toDecimals(updatedAmount, stakeToken.decimals)
- )
-
- setFormData(formData => ({
- ...formData,
- amount: {
- value: updatedAmount,
- valueBN: newAmountBN,
- },
- }))
- },
- [stakeToken.decimals]
- )
-
- const handleBeneficiaryChange = useCallback(event => {
- const updatedBeneficiary = event.target.value
-
- setFormData(formData => ({ ...formData, beneficiary: updatedBeneficiary }))
- }, [])
-
const handleLinkChange = useCallback(event => {
const updatedLink = event.target.value
setFormData(formData => ({ ...formData, link: updatedLink }))
@@ -133,82 +28,43 @@ const AddProposalPanel = React.memo(({ onSubmit }) => {
event => {
event.preventDefault()
- const { amount, beneficiary = ZERO_ADDR, link, title } = formData
- const convertedAmount = amount.valueBN.toFixed(0)
+ const { link, title } = formData
onSubmit({
title,
link,
- amount: convertedAmount,
- beneficiary: beneficiary || ZERO_ADDR,
+ amount: 0,
+ beneficiary: ZERO_ADDR,
})
},
[formData, onSubmit]
)
const errors = useMemo(() => {
- const errors = []
-
- const { amount, beneficiary, title } = formData
- if (requestToken) {
- if (amount.valueBN.eq(-1)) {
- errors.push('Invalid requested amount')
- }
-
- if (beneficiary && !isAddress(beneficiary)) {
- errors.push('Beneficiary is not a valid ethereum address')
- }
-
- return errors
- }
+ const { title } = formData
return !title
- }, [formData, requestToken])
-
- const neededThreshold = useMemo(() => {
- const threshold = calculateThreshold(
- formData.amount.valueBN,
- vaultBalance,
- totalSupply,
- alpha,
- maxRatio,
- weight
- )
+ }, [formData])
- const max = getMaxConviction(totalSupply, alpha)
- return Math.round((threshold / max) * 100)
- }, [alpha, formData.amount, maxRatio, totalSupply, vaultBalance, weight])
+ const submitDisabled = !formData.title || !formData.link
- const submitDisabled =
- formData.proposalType === NULL_PROPOSAL_TYPE ||
- (formData.proposalType === FUNDING_PROPOSAL &&
- (formData.amount.value === '0' || !formData.beneficiary)) ||
- !formData.title ||
- !termsAccepted
+ if (accountBalance.toString() === '0') {
+ return (
+