Skip to content

Commit

Permalink
Voting: rxjs upgrade fixes (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
2color authored Mar 21, 2019
1 parent 5f3fb51 commit 2773ccc
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 53 deletions.
2 changes: 1 addition & 1 deletion apps/voting/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"license": "AGPL-3.0-or-later",
"dependencies": {
"@aragon/client": "^1.1.0",
"@aragon/api": "^1.0.0-beta.1",
"@aragon/ui": "^0.31.0",
"bn.js": "^4.11.8",
"date-fns": "2.0.0-alpha.22",
Expand Down
103 changes: 53 additions & 50 deletions apps/voting/app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import { Main, SidePanel, observe } from '@aragon/ui'
import BN from 'bn.js'
import { map } from 'rxjs/operators'
import EmptyState from './screens/EmptyState'
import Votes from './screens/Votes'
import tokenAbi from './abi/token-balanceOfAt.json'
Expand Down Expand Up @@ -271,62 +272,64 @@ class App extends React.Component {

export default observe(
observable =>
observable.map(state => {
const appStateReady = hasLoadedVoteSettings(state)
if (!appStateReady) {
return {
...state,
appStateReady,
observable.pipe(
map(state => {
const appStateReady = hasLoadedVoteSettings(state)
if (!appStateReady) {
return {
...state,
appStateReady,
}
}
}

const { pctBase, tokenDecimals, voteTime, votes } = state
const { pctBase, tokenDecimals, voteTime, votes } = state

const pctBaseNum = parseInt(pctBase, 10)
const tokenDecimalsNum = parseInt(tokenDecimals, 10)
const tokenDecimalsBaseNum = Math.pow(10, tokenDecimalsNum)
const pctBaseNum = parseInt(pctBase, 10)
const tokenDecimalsNum = parseInt(tokenDecimals, 10)
const tokenDecimalsBaseNum = Math.pow(10, tokenDecimalsNum)

return {
...state,
return {
...state,

appStateReady,
pctBase: new BN(pctBase),
tokenDecimals: new BN(tokenDecimals),
appStateReady,
pctBase: new BN(pctBase),
tokenDecimals: new BN(tokenDecimals),

numData: {
pctBase: pctBaseNum,
tokenDecimals: tokenDecimalsNum,
},
numData: {
pctBase: pctBaseNum,
tokenDecimals: tokenDecimalsNum,
},

// Transform the vote data for the frontend
votes: votes
? votes.map(vote => {
const { data } = vote
return {
...vote,
data: {
...data,
endDate: new Date(data.startDate + voteTime),
minAcceptQuorum: new BN(data.minAcceptQuorum),
nay: new BN(data.nay),
supportRequired: new BN(data.supportRequired),
votingPower: new BN(data.votingPower),
yea: new BN(data.yea),
},
numData: {
minAcceptQuorum:
parseInt(data.minAcceptQuorum, 10) / pctBaseNum,
nay: parseInt(data.nay, 10) / tokenDecimalsBaseNum,
supportRequired:
parseInt(data.supportRequired, 10) / pctBaseNum,
votingPower:
parseInt(data.votingPower, 10) / tokenDecimalsBaseNum,
yea: parseInt(data.yea, 10) / tokenDecimalsBaseNum,
},
}
})
: [],
}
}),
// Transform the vote data for the frontend
votes: votes
? votes.map(vote => {
const { data } = vote
return {
...vote,
data: {
...data,
endDate: new Date(data.startDate + voteTime),
minAcceptQuorum: new BN(data.minAcceptQuorum),
nay: new BN(data.nay),
supportRequired: new BN(data.supportRequired),
votingPower: new BN(data.votingPower),
yea: new BN(data.yea),
},
numData: {
minAcceptQuorum:
parseInt(data.minAcceptQuorum, 10) / pctBaseNum,
nay: parseInt(data.nay, 10) / tokenDecimalsBaseNum,
supportRequired:
parseInt(data.supportRequired, 10) / pctBaseNum,
votingPower:
parseInt(data.votingPower, 10) / tokenDecimalsBaseNum,
yea: parseInt(data.yea, 10) / tokenDecimalsBaseNum,
},
}
})
: [],
}
})
),
{}
)(App)
2 changes: 1 addition & 1 deletion apps/voting/app/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom'
import Aragon, { providers } from '@aragon/client'
import Aragon, { providers } from '@aragon/api'
import App from './App'

class ConnectedApp extends React.Component {
Expand Down
2 changes: 1 addition & 1 deletion apps/voting/app/src/script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Aragon from '@aragon/client'
import Aragon from '@aragon/api'
import { of } from 'rxjs'
import voteSettings, { hasLoadedVoteSettings } from './vote-settings'
import { EMPTY_CALLSCRIPT } from './evmscript-utils'
Expand Down

0 comments on commit 2773ccc

Please sign in to comment.