-
Notifications
You must be signed in to change notification settings - Fork 51
Description
some hardcoded values, I have looked through all the "kleros-v2/web" files (and all its subfolders) and I've encountered these:
correct links, respectively:
https://forum.kleros.io/
https://snapshot.org/#/kleros.eth/
https://kleros.io/coop/
https://t.me/kleros
https://discord.com/invite/cAvWk8B23f
https://t.me/kleros
https://slack.kleros.io/
hmm, this wasn't a hardcode, in this file there should be declared all the supported chains
instead of hardcoding the chainId and arbitrableAddress on the "arbitrable" const, pass these values as parameters
on useEvidenceGroup, like this:
export const useEvidenceGroup = (
disputeID?: string,
arbitrableAddress?: string
chainId?: number // new parameter
)
and then create the arbitrable const like this:
const arbitrable = useConnectedContract(
"IMetaEvidence",
arbitrableAddress,
chainId
);
then depending on the chain who is calling it, the parameters will change.
exactly the same solution as the above in useEvidenceGroup()
create a .env and place this provider there, as:
ARB_GOERLI_PROVIDER=https://arb-goerli.g.alchemy.com/v2/HAAmSjN1RzxG1LNsGh9Je72bYVPsyFfQ
then create a .env.example and place it without the private key:
ARB_GOERLI_PROVIDER=https://arb-goerli.g.alchemy.com/v2/{key}
instead of hardcoding the string "View profile on Proof of Humanity" use a general solution like the one in Court V1 https://github.com/kleros/court/blob/a837a3a798795c00d4d5c04a3c7b4eb4434632ac/src/components/case-details-card.js#L654
and instead of hardcoding the URL of the interface (proof of humanity profile) use a general solution like the one in Court V1 https://github.com/kleros/court/blob/master/src/components/case-details-card.js#L348
you can do this subgraph query, passing as parameter the desired courtId (ex: "1"):
{
court(id: {courtId}) {
stake
stakedJurors(where: {id: "0xf50e77f2a2b6138d16c6c7511562e5c33c4b15a3-{courtId}"}) {
staked
}
}
}
It's requesting two fields for this court:
- The stake field, which returns the total amount of PNK staked in this court by all jurors.
- the staked field, which returns the amount of PNK staked by this juror in this court.
then you can get the juror odds with a formula, ex: (jurorBalance?.staked / totalStaked in that court) * 100
We can solve this problem with queries to the subgraph:
Make a query to thegraph and see in which courts the user is staked, we are interested specifically in the "id" and "name" of these courts:
{
user(id: "0xf50e77f2a2b6138d16c6c7511562e5c33c4b15a3") {
tokens {
court {
id
name
}
}
}
}
Now, we need to make more queries with each court id received earlier, to know how much PNK is staked and how much is locked in each court:
{
court(id: "{courtId}") {
id
name
stakedJurors(where: {id: "0xf50e77f2a2b6138d16c6c7511562e5c33c4b15a3-{courtId}" } ) {
staked
locked
}
}
}
Depending on the number of courts returned on the first query (array.length), we will use .map() to create that number of CourtCards, passing as parameters each court in which the user is staked, the total stake they have in that court, and how much stake is locked
in v2 subgraph, we have degreeOfCoherency, so we could fetch this from the subgraph, then we can compute the average of degreeOfCoherency for all the rounds in which the user has participated
for this, maybe we could do a subgraph query, and request the "shifts" field from the user, something like this:
"const { data } = await client.query({
query: gql`
{
user(id: "0xf50e77f2a2b6138d16c6c7511562e5c33c4b15a3") {
shifts {
tokenAmount
ethAmount
}
}
}
`
});
const shifts = data.user.shifts;
const totalTokenAmount = shifts.map(shift => parseInt(shift.tokenAmount)).reduce((acc, curr) => acc + curr, 0);
const totalEthAmount = shifts.map(shift => parseInt(shift.ethAmount)).reduce((acc, curr) => acc + curr, 0);
console.log(`Total tokenAmount: ${totalTokenAmount}`);
console.log(`Total ethAmount: ${totalEthAmount}`);"
looking at how Court V1 does it,
for getting the Unclaimed PNK amount: https://github.com/kleros/court/blob/4c27719ee3eb5f039efd4470f18bec5d07e2c202/src/components/claim-modal.js#L198
for getting the APY %: https://github.com/kleros/court/blob/master/src/components/claim-modal.js#L139
for getting the tokens rewarded: https://github.com/kleros/court/blob/4c27719ee3eb5f039efd4470f18bec5d07e2c202/src/components/claim-modal.js#L212