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

Mock data #269

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
be74fd7
Draft: Initial query mock data implementation
fabriziovigevani Mar 9, 2020
6f994df
Implement initial subscription exchange
fabriziovigevani Mar 10, 2020
a292aba
Merge branch 'development' into mock-data
fabriziovigevani Mar 10, 2020
89a1e0f
Add first dashboard mock states
fabriziovigevani Mar 11, 2020
16b0438
Add first dispute data
fabriziovigevani Mar 16, 2020
850c0e8
Draft jurors
fabriziovigevani Mar 23, 2020
e9fd8c3
Merge branch 'development' into mock-data
fabriziovigevani Mar 27, 2020
9ffa60b
Merge branch 'development' into mock-data
fabriziovigevani Mar 27, 2020
79afdf6
Adapt to new changes
fabriziovigevani Mar 27, 2020
1f37b92
Support all new queries
fabriziovigevani Mar 29, 2020
3299864
Add disputes for different phases
fabriziovigevani Mar 30, 2020
7fb5164
Support final rounds
fabriziovigevani Mar 31, 2020
45072b0
Fix ANT stat issue
fabriziovigevani Apr 1, 2020
b560acc
Merge branch 'development' into mock-data
fabriziovigevani Apr 1, 2020
abba866
Draft previous rounds
fabriziovigevani Apr 7, 2020
7097957
Update src/queries/jurorDrafts.js
fabriziovigevani Apr 9, 2020
c653fb8
Merge branch 'mock-data' of https://github.com/aragon/court-dashboard…
fabriziovigevani Apr 9, 2020
f72573b
Merge branch 'development' into mock-data
fabriziovigevani Apr 9, 2020
c31743d
Mock data: use new networkConfig
fabriziovigevani Apr 9, 2020
a81aba6
Merge branch 'development' into mock-data
fabriziovigevani Apr 15, 2020
03afe1e
Rever juror wieght conversion
fabriziovigevani Apr 15, 2020
37f99f9
Do minor refactor and add comments
fabriziovigevani Apr 16, 2020
ce8ed6e
Minor fixes
fabriziovigevani Apr 16, 2020
7398a33
SubscriptionClient: Prevent reconnection attempt
fabriziovigevani Apr 16, 2020
f0a7bfa
Initialize jurors balances realtive to config min active balance
fabriziovigevani Apr 25, 2020
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@
"styled-components": "^4.4.1",
"subscriptions-transport-ws": "^0.9.16",
"urql": "^1.6.3",
"wonka": "^4.0.7",
"use-wallet": "^0.4.4"
},
"scripts": {
"start": "npm run sync-assets && REACT_APP_BUILD=$(git log --pretty=format:'%h' -n 1) react-app-rewired start",
"start:local": "REACT_APP_CHAIN_ID=1337 npm run start ",
"start:local:mock": "REACT_APP_MOCK_DATA=1 npm run start:local",
"start:mainnet": "REACT_APP_CHAIN_ID=1 npm run start",
"start:mainnet:mock": "REACT_APP_MOCK_DATA=1 npm run start:mainnet",
"start:ropsten": "REACT_APP_CHAIN_ID=3 npm run start",
"start:ropsten:mock": "REACT_APP_MOCK_DATA=1 npm run start:ropsten",
"start:rinkeby": "REACT_APP_CHAIN_ID=4 npm run start",
"start:rinkeby:mock": "REACT_APP_MOCK_DATA=1 npm run start:rinkeby",
"build": "./scripts/build.sh",
"build:local": "REACT_APP_CHAIN_ID=1337 npm run build",
"build:mainnet": "REACT_APP_CHAIN_ID=1 npm run build",
Expand Down
3 changes: 3 additions & 0 deletions src/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const ENV_VARS = {
ENABLE_SENTRY() {
return process.env.REACT_APP_ENABLE_SENTRY === '1'
},
MOCK_DATA() {
return process.env.REACT_APP_MOCK_DATA === '1'
},
DEFAULT_ETH_NODE() {
return process.env.REACT_APP_DEFAULT_ETH_NODE || ''
},
Expand Down
10 changes: 7 additions & 3 deletions src/graphql-exchanges.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { fetchExchange, subscriptionExchange } from 'urql'
import { SubscriptionClient } from 'subscriptions-transport-ws'
import { captureMessage } from '@sentry/browser'
import env from './environment'
import endpoints from './endpoints'
import { mockFetchExchange, mockSubscriptionExchange } from './mock/exchanges'

const GRAPH_API_ENDPOINTS = endpoints()
const subscriptionClient = new SubscriptionClient(GRAPH_API_ENDPOINTS[1], {
reconnect: true,
reconnect: !env('MOCK_DATA'),
reconnectionAttempts: 10,
})

Expand All @@ -16,11 +18,13 @@ const DEFAULT_SUBSCRIPTION_EXCHANGE = subscriptionExchange({
})

export function getFetchExchange() {
return DEFAULT_FETCH_EXCHANGE
return env('MOCK_DATA') ? mockFetchExchange : DEFAULT_FETCH_EXCHANGE
}

export function getSubscriptionExchange() {
return DEFAULT_SUBSCRIPTION_EXCHANGE
return env('MOCK_DATA')
? mockSubscriptionExchange
: DEFAULT_SUBSCRIPTION_EXCHANGE
}

let connectionAttempts = 0
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/query-hooks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useQuery } from 'urql'

import { JurorFirstANJActivationMovement } from '../queries/balances'
import { ActiveJurors, JurorFeesClaimed } from '../queries/juror'
import { JurorDrafts } from '../queries/jurorDrafts'
import { ActiveJurors, JurorFeesClaimed } from '../queries/juror'
import { JurorFirstANJActivationMovement } from '../queries/balances'

export function useJurorDraftQuery(jurorId) {
const [result] = useQuery({
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/subscription-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { useCourtConfig } from '../providers/CourtConfig'

// queries
import { OpenTasks } from '../queries/tasks'
import { AllDisputes, SingleDispute } from '../queries/disputes'
import { AppealsByMaker, AppealsByTaker } from '../queries/appeals'
import { JurorDraftsFrom, JurorDraftsNotRewarded } from '../queries/jurorDrafts'
import {
CourtConfig,
FeeMovements,
JurorsRegistryModule,
} from '../queries/court'
import { AllDisputes, SingleDispute } from '../queries/disputes'
import { AppealsByMaker, AppealsByTaker } from '../queries/appeals'
import {
JurorANJBalances,
JurorANJWalletBalance,
JurorTreasuryBalances,
} from '../queries/balances'
import { JurorDraftsFrom, JurorDraftsNotRewarded } from '../queries/jurorDrafts'

// utils
import { bigNum } from '../lib/math-utils'
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useCourtContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ export function useTotalANTStakedPolling(timeout = 1000) {
timeoutId = setTimeout(() => {
const agentBalancePromise = antContract.balanceOf(networkAgentAddress)
const vaultBalancePromise = antContract.balanceOf(networkReserveAddress)

return Promise.all([agentBalancePromise, vaultBalancePromise])
.then(([antInAgent, antInVault]) => {
if (!cancelled) {
Expand Down
58 changes: 0 additions & 58 deletions src/mock-data.js

This file was deleted.

61 changes: 61 additions & 0 deletions src/mock/data/CourtConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { getNetworkConfig } from '../../networks'
import { bigExp } from '../helper'
import dayjs from 'dayjs'

const TERM_DURATION = 60 // 1 minute
const CURRENT_TERM = 100
const COURT_START = dayjs() // Court started 100 terms ago
.subtract(TERM_DURATION * CURRENT_TERM, 'second')
.unix()

const anjToken = {
id: '',
name: 'Aragon Network Juror Token',
symbol: 'ANJ',
decimals: 18,
}

const feeToken = {
id: '',
name: 'Dai stablecoin',
symbol: 'DAI',
decimals: 18,
}

const courtConfig = {
id: getNetworkConfig().court,
currentTerm: CURRENT_TERM,
termDuration: TERM_DURATION, // 4 minutes
anjToken,
feeToken,
jurorFee: bigExp('10'),
draftFee: bigExp('18', 16),
settleFee: bigExp('1', 17),
evidenceTerms: 21,
commitTerms: '3',
revealTerms: '3',
appealTerms: '3',
appealConfirmationTerms: '3',
terms: [
{
startTime: COURT_START,
},
],
finalRoundReduction: '5000',
firstRoundJurorsNumber: '3',
appealStepFactor: '3',
maxRegularAppealRounds: '2',
appealCollateralFactor: '30000',
appealConfirmCollateralFactor: '20000',
minActiveBalance: bigExp('100'),
penaltyPct: '1000',
modules: [],
subscriptions: {
currentPeriod: '0',
feeAmount: bigExp('10'),
periodDuration: '600',
periods: [],
},
}

export default courtConfig
124 changes: 124 additions & 0 deletions src/mock/data/Disputes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import courtConfig from './CourtConfig'
import ROUNDS from './Rounds'
import { hash256 } from '../../lib/web3-utils'
import { dayjs } from '../../utils/date-utils'
import { DisputeState } from '../types'
import { accounts } from '../helper'

const DEFAULT_SUBMITTER = accounts[5]
const DEFAULT_EVIDENCE =
'0x697066733a516d55765a53545a3958767156786b624446664a576e6644394759703376376d71353778464d563173774e34314c'
const DEFAULT_IPFS_METADATA =
'QmPWJBAvLqdv5oNv7WvEFaghiMkWtcThDRJGFKu6kennpF/metadata.json'

// State of each dispute
const DISPUTES_DATA = [
{
state: DisputeState.Ruled,
description: 'Dispute finished (First round, In favor)',
rounds: [{ ...ROUNDS.ENDED.IN_FAVOR }],
},
{
state: DisputeState.Ruled,
description:
'Dispute finished (First round, Refused to vote, Penalties Settled)',
rounds: [{ ...ROUNDS.ENDED.REFUSED }],
},
{
state: DisputeState.Ruled,
description: 'Dispute finished (First round, No one voted)',
rounds: [{ ...ROUNDS.ENDED.NO_VOTES }],
},
{
state: DisputeState.Ruled,
description: 'Dispute finished (Final round, Against)',
rounds: [
...populatePreviousRounds(courtConfig.maxRegularAppealRounds),
{ ...ROUNDS.ENDED.FINAL_ROUND },
],
},
{
state: DisputeState.Adjudicating,
description: 'Dispute finished (Execute ruling)',
rounds: [{ ...ROUNDS.ENDED.IN_FAVOR }],
},
{
state: DisputeState.Drafting,
description: 'Dispute confirm appealed',
rounds: [populatePreviousRounds(1), { ...ROUNDS.CONFIRM_APPEALED }],
},
{
state: DisputeState.Adjudicating,
description: 'Dispute appealed',
rounds: [{ ...ROUNDS.APPEALED }],
},
{
state: DisputeState.Adjudicating,
description: 'Dispute appealing',
rounds: [{ ...ROUNDS.APPEALING }],
},
{
state: DisputeState.Adjudicating,
description: 'Dispute revealing',
rounds: [{ ...ROUNDS.REVEALING }],
},
{
state: DisputeState.Adjudicating,
description: 'Dispute comitting',
rounds: [{ ...ROUNDS.COMITTING }],
},
{
state: DisputeState.Evidence,
description: 'Dispute in evidence submission',
rounds: [{ ...ROUNDS.NOT_DRAFTED }],
},
]

function populatePreviousRounds(numberOfRounds) {
return Array.from({ length: numberOfRounds }).map((_, index) => ({
...ROUNDS.PREVIOUS,
jurorsNumber: courtConfig.appealStepFactor ** (index + 1),
}))
}

function generateDisputes() {
const disputes = []

for (let i = 0; i < DISPUTES_DATA.length; i++) {
const { description, rounds, state } = DISPUTES_DATA[i]

const disputeId = String(i)
const dispute = {
id: disputeId,
txHash: hash256(i),
createTermId: courtConfig.currentTerm,
createdAt: dayjs().unix(),
possibleRulings: 2,
state,
metadata: JSON.stringify({
description,
metadata: DEFAULT_IPFS_METADATA,
}),
lastRoundId: rounds.length - 1,
evidences: [
{
submitter: DEFAULT_SUBMITTER,
data: DEFAULT_EVIDENCE,
createdAt: dayjs().unix(),
},
],
}

dispute.rounds = rounds.map((round, index) => ({
...round,
number: String(index),
dispute,
}))

disputes.unshift(dispute)
}

return disputes
}

export default generateDisputes()
50 changes: 50 additions & 0 deletions src/mock/data/Jurors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { accounts } from '../helper'
import courtConfig from './CourtConfig'
import { ANJMovementType } from '../types'
import { bigNum } from '../../lib/math-utils'

const MIN_ACTIVE_BASE_MULTIPLIER = '10'
const numberOfJurors = 3

const JUROR_DEFAULT_DATA = {
// Wallet balance (from the subgraph we actually don't get this amount from the juror entity itself
// but in this case since we are mocking data doesn't really matter)
walletBalance: '0',
activeBalance: '0',
lockedBalance: '0',
availableBalance: '0',
deactivationBalance: '0',
treasuryTokens: [],
}

function generateJurors() {
return accounts.slice(0, numberOfJurors).map((account, index) => {
const activeBalance = bigNum(courtConfig.minActiveBalance).mul(
MIN_ACTIVE_BASE_MULTIPLIER * (index + 1)
)

return {
...JUROR_DEFAULT_DATA,
id: account,
activeBalance,

// Mimicking ANJ activation from wallet
anjMovements: [
{
amount: activeBalance,
effectiveTermId: 1,
type: ANJMovementType.Activation,
},
{
amount: activeBalance,
effectiveTermId: 1,
type: ANJMovementType.Stake,
},
],

drafts: [],
}
})
}

export default generateJurors()
Loading