Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard: stats widget #229

Merged
merged 27 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function getAPIBase() {
export default function endpoints() {
const [API_BASE_HTTP, API_BASE_WS] = getAPIBase()
const networkType =
rperez89 marked this conversation as resolved.
Show resolved Hide resolved
getNetworkType(CHAIN_ID) === 'local' ? 'rpc' : getNetworkType(CHAIN_ID)
getNetworkType(CHAIN_ID) === 'private' ? 'rpc' : getNetworkType(CHAIN_ID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here ? isLocalOrUnknownNetwork


const API_PATH =
networkType === 'main'
Expand Down
16 changes: 9 additions & 7 deletions src/flagged-disputes/precedence-campaign-disputes.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import {
networks,
getNetwork,
getInternalNetworkName,
RINKEBY_COURT,
RINKEBY_STAGING_COURT,
RINKEBY_USABILITY_COURT,
} from '../networks'
import { getNetworkType } from '../lib/web3-utils'

const PRECEDENCE_CAMPAIGN_DISPUTES = {
rpc: new Map([[networks.rpc.court, ['0']]]),
ropsten: new Map([[networks.ropsten.court, []]]),
main: new Map([[networks.main.court, []]]),
rinkeby: new Map([
[RINKEBY_COURT, []],
[RINKEBY_STAGING_COURT, []],
[RINKEBY_USABILITY_COURT, []],
]),
main: new Map([[networks.main.court, []]]),
ropsten: new Map([[networks.ropsten.court, []]]),
local: new Map([[networks.local.court, ['0']]]),
}

export function getPrecedenceCampaignDisputesByCourt() {
const networkType = getNetworkType()
const courtAddress = networks[networkType].court
const courtAddress = getNetwork().court

return PRECEDENCE_CAMPAIGN_DISPUTES[networkType].get(courtAddress)
return PRECEDENCE_CAMPAIGN_DISPUTES[getInternalNetworkName()].get(
courtAddress
)
}
23 changes: 11 additions & 12 deletions src/flagged-disputes/voided-disputes.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import {
networks,
getInternalNetworkName,
getNetwork,
RINKEBY_COURT,
RINKEBY_STAGING_COURT,
RINKEBY_USABILITY_COURT,
} from '../networks'
import { getNetworkType } from '../lib/web3-utils'
import env from '../environment'

const VOIDED_DISPUTES = {
local: new Map([[networks.local.court, new Map([])]]),
ropsten: new Map([[networks.ropsten.court, new Map([])]]),
rinkeby: new Map([
[RINKEBY_COURT, new Map([])],
[RINKEBY_USABILITY_COURT, new Map([])],
[RINKEBY_STAGING_COURT, new Map([])],
]),
main: new Map([
[
networks.main.court,
Expand All @@ -32,15 +26,20 @@ const VOIDED_DISPUTES = {
),
],
]),
rinkeby: new Map([
[RINKEBY_COURT, new Map([])],
[RINKEBY_USABILITY_COURT, new Map([])],
[RINKEBY_STAGING_COURT, new Map([])],
]),
ropsten: new Map([[networks.ropsten.court, new Map([])]]),
local: new Map([[networks.local.court, new Map([])]]),
}

export function getVoidedDisputesByCourt() {
if (env('SKIP_VOIDING')) {
return new Map([])
}
const courtAddress = getNetwork().court

const networkType = getNetworkType()
const courtAddress = networks[networkType].court

return VOIDED_DISPUTES[networkType].get(courtAddress)
return VOIDED_DISPUTES[getInternalNetworkName()].get(courtAddress)
}
10 changes: 7 additions & 3 deletions src/hooks/useCourtContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { captureException } from '@sentry/browser'
import { CourtModuleType } from '../types/court-module-types'
import { useContract, useContractReadOnly } from '../web3-contracts'
import { useCourtConfig } from '../providers/CourtConfig'
import { getFunctionSignature, getNetworkType } from '../lib/web3-utils'
import { getFunctionSignature } from '../lib/web3-utils'
import { bigNum, formatUnits } from '../lib/math-utils'
import {
hashVote,
Expand All @@ -14,7 +14,11 @@ import {
import { getModuleAddress } from '../utils/court-utils'
import { retryMax } from '../utils/retry-max'
import { useActivity } from '../components/Activity/ActivityProvider'
import { networkAgentAddress, networkReserveAddress } from '../networks'
import {
networkAgentAddress,
networkReserveAddress,
getInternalNetworkName,
} from '../networks'
import { getKnownToken } from '../utils/known-tokens'

import aragonCourtAbi from '../abi/AragonCourt.json'
Expand Down Expand Up @@ -578,7 +582,7 @@ export function useTotalANTStakedPolling(timeout = 1000) {
let cancelled = false
let timeoutId

if (getNetworkType() === 'local') {
if (getInternalNetworkName() === 'local') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use isLocalOrUnknownNetwork ?

setError(true)
return
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/web3-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { solidityKeccak256, id as keccak256 } from 'ethers/utils'

rperez89 marked this conversation as resolved.
Show resolved Hide resolved
export const soliditySha3 = solidityKeccak256
export const hash256 = keccak256
export const DEFAULT_LOCAL_CHAIN = 'local'
export const DEFAULT_LOCAL_CHAIN = 'private'
export const ETH_FAKE_ADDRESS = `0x${''.padEnd(40, '0')}`

const ETH_ADDRESS_SPLIT_REGEX = /(0x[a-fA-F0-9]{40}(?:\b|\.|,|\?|!|;))/g
Expand Down Expand Up @@ -123,7 +123,7 @@ export function getNetworkName(chainId = env('CHAIN_ID')) {
return 'unknown'
}

export function isLocalOrUnknownNetwork(chainId) {
export function isLocalOrUnknownNetwork(chainId = env('CHAIN_ID')) {
return getNetworkType(chainId) === DEFAULT_LOCAL_CHAIN
}

Expand Down
47 changes: 29 additions & 18 deletions src/networks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import environment from './environment'
import { getNetworkType } from './lib/web3-utils'
import { getNetworkType, isLocalOrUnknownNetwork } from './lib/web3-utils'

const SUBGRAPH_NAME = environment('SUBGRAPH_NAME')

Expand All @@ -11,25 +11,20 @@ export const RINKEBY_STAGING_COURT =
'0x52180Af656A1923024D1ACcF1D827AB85cE48878'

export const networks = {
local: { court: '0xD833215cBcc3f914bD1C9ece3EE7BF8B14f841bb' },
ropsten: { court: '0x3b26bc496aebaed5b3E0E81cDE6B582CDe71396e' },
rinkeby: {
// Use the 'usability' Court address if declared
court: getRinkebyCourtAddress(SUBGRAPH_NAME),
},
main: {
court: '0xee4650cBe7a2B23701D416f58b41D8B76b617797',
network_agent: '0x5e8c17a6065c35b172b10e80493d2266e2947df4',
network_reserve: '0xec0dd1579551964703246becfbf199c27cb84485',
},
rinkeby: {
// Use the 'usability' Court address if declared
court: getRinkebyCourtAddress(SUBGRAPH_NAME),
},
ropsten: { court: '0x3b26bc496aebaed5b3E0E81cDE6B582CDe71396e' },
local: { court: '0xD833215cBcc3f914bD1C9ece3EE7BF8B14f841bb' },
}

export const networkConfigs = {
local: {
nodes: {
defaultEth: 'http://localhost:8545',
},
},
main: {
nodes: {
defaultEth: 'https://mainnet.eth.aragon.network/',
Expand All @@ -40,17 +35,33 @@ export const networkConfigs = {
defaultEth: 'https://rinkeby.eth.aragon.network/',
},
},
rperez89 marked this conversation as resolved.
Show resolved Hide resolved
ropsten: {
nodes: {
defaultEth: 'https://ropsten.eth.aragon.network/',
},
},
local: {
nodes: {
defaultEth: 'http://localhost:8545',
},
},
}

export function getInternalNetworkName() {
return isLocalOrUnknownNetwork() ? 'local' : getNetworkType()
}

export function getNetwork() {
return networks[getInternalNetworkName()]
}

export function getNetworkConfig(networkType) {
return networkConfigs[networkType]
export function getNetworkConfig() {
return networkConfigs[getInternalNetworkName()]
}

export const networkAgentAddress =
networks[getNetworkType(environment('CHAIN_ID'))].network_agent
export const networkAgentAddress = getNetwork().network_agent

export const networkReserveAddress =
networks[getNetworkType(environment('CHAIN_ID'))].network_reserve
export const networkReserveAddress = getNetwork().network_reserve

function getRinkebyCourtAddress(subGraphName) {
if (subGraphName === 'usability') {
Expand Down
10 changes: 5 additions & 5 deletions src/providers/CourtConfig.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { useContext } from 'react'
import PropTypes from 'prop-types'
import environment from '../environment'
// import environment from '../environment'
import { useCourtConfigSubscription } from '../hooks/subscription-hooks'
import { getNetworkType } from '../lib/web3-utils'
import { networks } from '../networks'
// import { getNetworkType } from '../lib/web3-utils'
import { getNetwork } from '../networks'

const CHAIN_ID = environment('CHAIN_ID')
// const CHAIN_ID = environment('CHAIN_ID')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this comments

const CourtConfigContext = React.createContext()

function CourtConfigProvider({ children }) {
const courtAddress = networks[getNetworkType(CHAIN_ID)].court
const courtAddress = getNetwork().court
const courtConfig = useCourtConfigSubscription(courtAddress)

return (
Expand Down
5 changes: 2 additions & 3 deletions src/web3-contracts.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useMemo } from 'react'
import { Contract as EthersContract, providers as Providers } from 'ethers'
import { useWallet } from './providers/Wallet'
import { getNetworkType } from './lib/web3-utils'
import { networkConfigs } from './networks'
import { getNetworkConfig } from './networks'

export function useContract(address, abi, signer = true) {
const { account, ethers } = useWallet()
Expand All @@ -24,7 +23,7 @@ export function useContract(address, abi, signer = true) {
}

export function useContractReadOnly(address, abi) {
const ethEndpoint = networkConfigs[getNetworkType()].nodes.defaultEth
const ethEndpoint = getNetworkConfig().nodes.defaultEth

const ethProvider = useMemo(
() => (ethEndpoint ? new Providers.JsonRpcProvider(ethEndpoint) : null),
Copy link
Contributor

@sohkai sohkai Mar 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note for later: I think for now this is totally fine, since this provider uses http (it's maybe just a little memory in-efficient), but when we switch to websockets, we'll most likely want to initialize a singleton provider to maintain a single websocket connection for all contracts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let's keep that in mind

Expand Down