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

Pre mock data #274

Merged
merged 4 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React from 'react'
import { BrowserRouter } from 'react-router-dom'
import { Main, ToastHub } from '@aragon/ui'
import theme from './theme-court'
import AppLoader from './components/AppLoader'
import GlobalErrorHandler from './GlobalErrorHandler'
import MainView from './components/MainView'
import OnboardingLoader from './components/OnboardingLoader'
import Routes from './Routes'
import { ActivityProvider } from './components/Activity/ActivityProvider'
import { CourtClockProvider } from './providers/CourtClock'
import { CourtConfigProvider } from './providers/CourtConfig'
import { WalletProvider } from './providers/Wallet'
import AppLoader from './components/AppLoader'
import OnboardingLoader from './components/OnboardingLoader'
import Routes from './Routes'
import GlobalErrorHandler from './GlobalErrorHandler'

function App() {
return (
Expand Down
1 change: 1 addition & 0 deletions src/components/Disputes/DisputeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ function InformationSection({
}

// Helper function that returns main attributes for the YourVoteInfo component
// TODO: Contemplate final round cases (when a juror has voted, the ANJ amount is pre-slashed)
const useInfoAttributes = ({
hasJurorVoted,
jurorDraft,
Expand Down
37 changes: 37 additions & 0 deletions src/graphql-exchanges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { fetchExchange, subscriptionExchange } from 'urql'
import { SubscriptionClient } from 'subscriptions-transport-ws'
import { captureMessage } from '@sentry/browser'
import endpoints from './endpoints'

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

// Default exchanges
const DEFAULT_FETCH_EXCHANGE = fetchExchange
const DEFAULT_SUBSCRIPTION_EXCHANGE = subscriptionExchange({
forwardSubscription: operation => subscriptionClient.request(operation),
})

export function getFetchExchange() {
return DEFAULT_FETCH_EXCHANGE
}

export function getSubscriptionExchange() {
return DEFAULT_SUBSCRIPTION_EXCHANGE
}

let connectionAttempts = 0
subscriptionClient.onConnected(() => (connectionAttempts = 0))

// Check for connection errors and if reaches max attempts send error log to Sentry
subscriptionClient.onError(err => {
const maxReconnectionAttempts = subscriptionClient.reconnectionAttempts

if (maxReconnectionAttempts === ++connectionAttempts) {
captureMessage(`Connection error, could not connect to ${err.target.url}`)
}
console.log('Retrying connection...')
})
6 changes: 3 additions & 3 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 { JurorFeesClaimed } from '../queries/juror'
import { ActiveJurors, FirstANJActivationMovement } from '../queries/balances'

export function useJurorDraftQuery(jurorId) {
const [result] = useQuery({
Expand Down Expand Up @@ -42,7 +42,7 @@ export function useJurorRewardsEverClaimedQuery(jurorId) {

export function useFirstANJActivationQuery(jurorId, { pause = false }) {
const [result] = useQuery({
query: FirstANJActivationMovement,
query: JurorFirstANJActivationMovement,
variables: { id: jurorId.toLowerCase() },
pause,
})
Expand Down
31 changes: 19 additions & 12 deletions src/hooks/subscription-hooks.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
import { useMemo } from 'react'
import { useSubscription } from 'urql'
import { useCourtConfig } from '../providers/CourtConfig'

// queries
import { OpenTasks } from '../queries/tasks'
import {
CourtConfig,
FeeMovements,
JurorsRegistryModule,
} from '../queries/court'
import { useCourtConfig } from '../providers/CourtConfig'
import { SingleDispute, AllDisputes } from '../queries/disputes'
import { AllDisputes, SingleDispute } from '../queries/disputes'
import { AppealsByMaker, AppealsByTaker } from '../queries/appeals'
import { ANJBalance, Juror, JurorTreasuryBalances } from '../queries/balances'
import {
JurorDraftsNotRewarded,
CurrentTermJurorDrafts,
} from '../queries/jurorDrafts'
import { CourtModuleType } from '../types/court-module-types'
JurorANJBalances,
JurorANJWalletBalance,
JurorTreasuryBalances,
} from '../queries/balances'
import { JurorDraftsFrom, JurorDraftsNotRewarded } from '../queries/jurorDrafts'

// utils
import { bigNum } from '../lib/math-utils'
import { dayjs } from '../utils/date-utils'
import { groupMovements } from '../utils/anj-movement-utils'
import { transformAppealDataAttributes } from '../utils/appeal-utils'
import { transformDisputeDataAttributes } from '../utils/dispute-utils'
import { transformJurorDataAttributes } from '../utils/juror-draft-utils'
import { transformClaimedFeesDataAttributes } from '../utils/subscription-utils'
import {
getModuleAddress,
transformCourtConfigDataAttributes,
} from '../utils/court-utils'
import { transformClaimedFeesDataAttributes } from '../utils/subscription-utils'

// types
import { CourtModuleType } from '../types/court-module-types'

const NO_AMOUNT = bigNum(0)

// Subscription to get juror's wallet balance
function useANJBalance(jurorId) {
const [{ data, error }] = useSubscription({
query: ANJBalance,
query: JurorANJWalletBalance,
variables: { id: jurorId.toLowerCase() },
})

Expand All @@ -48,7 +55,7 @@ function useJuror(jurorId) {
.unix()

const [{ data, error }] = useSubscription({
query: Juror,
query: JurorANJBalances,
variables: { id: jurorId.toLowerCase(), from: yesterday },
})

Expand Down Expand Up @@ -203,7 +210,7 @@ export function useDisputesSubscription() {

const disputes = useMemo(
() =>
data && data.disputes
data?.disputes
? data.disputes.map(dispute =>
transformDisputeDataAttributes(dispute, courtConfig)
)
Expand All @@ -227,7 +234,7 @@ export function useCurrentTermJurorDraftsSubscription(
pause
) {
const [result] = useSubscription({
query: CurrentTermJurorDrafts,
query: JurorDraftsFrom,
variables: { id: jurorId.toLowerCase(), from: termStartTime },
pause,
})
Expand Down
32 changes: 5 additions & 27 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import {
Provider as UrqlProvider,
cacheExchange,
debugExchange,
fetchExchange,
subscriptionExchange,
} from 'urql'
import { SubscriptionClient } from 'subscriptions-transport-ws'
import { captureMessage } from '@sentry/browser'
import { getFetchExchange, getSubscriptionExchange } from './graphql-exchanges'

import { devtoolsExchange } from '@urql/devtools'
import { createGlobalStyle } from 'styled-components'
import App from './App'
Expand All @@ -18,39 +16,19 @@ import initializeSentry from './sentry'

initializeSentry()

const [GRAPH_API_ENDPOINT_HTTP, GRAPH_API_ENDPOINT_WS] = endpoints()

const subscriptionClient = new SubscriptionClient(GRAPH_API_ENDPOINT_WS, {
reconnect: true,
reconnectionAttempts: 10,
})
const [GRAPH_API_ENDPOINT_HTTP] = endpoints()

const client = createClient({
url: GRAPH_API_ENDPOINT_HTTP,
exchanges: [
debugExchange,
devtoolsExchange,
cacheExchange,
fetchExchange,
subscriptionExchange({
forwardSubscription: operation => subscriptionClient.request(operation),
}),
getFetchExchange(),
getSubscriptionExchange(),
],
})

let connectionAttempts = 0
subscriptionClient.onConnected(() => (connectionAttempts = 0))

// Check for connection errors and if reaches max attempts send error log to Sentry
subscriptionClient.onError(err => {
const maxReconnectionAttempts = subscriptionClient.reconnectionAttempts

if (maxReconnectionAttempts === ++connectionAttempts) {
captureMessage(`Connection error, could not connect to ${err.target.url}`)
}
console.log('Retrying connection...')
})

const GlobalStyle = createGlobalStyle`
body img {
user-select:none;
Expand Down
4 changes: 2 additions & 2 deletions src/queries/appeals.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag'

export const AppealsByMaker = gql`
subscription($maker: Bytes!, $settled: Boolean!) {
subscription AppealsByMaker($maker: Bytes!, $settled: Boolean!) {
appeals(where: { maker: $maker, settled: $settled }) {
id
round {
Expand All @@ -27,7 +27,7 @@ export const AppealsByMaker = gql`
`

export const AppealsByTaker = gql`
subscription($taker: Bytes!, $settled: Boolean!) {
subscription AppealsByTaker($taker: Bytes!, $settled: Boolean!) {
appeals(where: { taker: $taker, settled: $settled }) {
id
round {
Expand Down
19 changes: 6 additions & 13 deletions src/queries/balances.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import gql from 'graphql-tag'

export const ANJBalance = gql`
subscription ANJBalance($id: ID!) {
export const JurorANJWalletBalance = gql`
subscription JurorANJWalletBalance($id: ID!) {
anjbalance(id: $id) {
amount
}
}
`

export const Juror = gql`
subscription Juror($id: ID!, $from: BigInt!) {
export const JurorANJBalances = gql`
subscription JurorANJBalances($id: ID!, $from: BigInt!) {
juror(id: $id) {
activeBalance
lockedBalance
Expand Down Expand Up @@ -47,8 +47,8 @@ export const JurorTreasuryBalances = gql`
}
`

export const FirstANJActivationMovement = gql`
query Juror($id: ID!) {
export const JurorFirstANJActivationMovement = gql`
query JurorFirstANJActivationMovement($id: ID!) {
juror(id: $id) {
anjMovements(
where: { type: "Activation" }
Expand All @@ -64,10 +64,3 @@ export const FirstANJActivationMovement = gql`
}
}
`
export const ActiveJurors = gql`
query Jurors {
jurors(first: 1000, where: { activeBalance_gt: 0 }) {
id
}
}
`
24 changes: 2 additions & 22 deletions src/queries/disputes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,34 @@ export const AllDisputes = gql`
subscription AllDisputes($limit: Int) {
disputes(first: $limit, orderBy: createdAt, orderDirection: desc) {
id
txHash
createTermId
possibleRulings
finalRuling
lastRoundId
state
metadata
createdAt
rounds {
id
state
number
draftTermId
jurorsNumber
settledPenalties
jurorFees
delayedTerms
selectedJurors
coherentJurors
collectedTokens
createdAt
jurors {
juror {
id
}
commitment
outcome
}
vote {
id
winningOutcome
}

appeal {
id
maker
appealedRuling
taker
opposedRuling
settled
createdAt
}
}
}
}
`

export const SingleDispute = gql`
subscription Dispute($id: ID!) {
subscription SingleDispute($id: ID!) {
dispute(id: $id) {
id
txHash
Expand Down
8 changes: 8 additions & 0 deletions src/queries/juror.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ export const JurorFeesClaimed = gql`
}
}
`

export const ActiveJurors = gql`
query ActiveJurors {
jurors(first: 1000, where: { activeBalance_gt: 0 }) {
id
}
}
`
Loading