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

Frontend: hardcoded values #625

Closed
15 tasks done
kemuru opened this issue Mar 8, 2023 · 2 comments
Closed
15 tasks done

Frontend: hardcoded values #625

kemuru opened this issue Mar 8, 2023 · 2 comments
Labels
Milestone

Comments

@kemuru
Copy link
Contributor

kemuru commented Mar 8, 2023

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


@jaybuidl jaybuidl added the Package: Web Court web frontend label Mar 10, 2023
@nhestrompia
Copy link
Contributor

nhestrompia commented Mar 29, 2023

I found more hard-coded values within these files :



could use an API such as coingecko to retrieve values of PNK and ETH.

https://www.coingecko.com/en/api

could use an API such as coingecko to retrieve values of PNK and ETH.

https://www.coingecko.com/en/api

updating the seconds value of a year to 31,536,000:
const getOneYearAgoTimestamp: () => number = () => {
  const currentTime = new Date().getTime() / 1000;
  return currentTime - 31536000; // One year in seconds
};

Sorry, something went wrong.

@jaybuidl
Copy link
Member

jaybuidl commented Apr 11, 2023

More on the Cases page

Sorry, something went wrong.

@jaybuidl jaybuidl changed the title hardcoded values on "kleros-v2/web" Frontend: hardcoded values Jul 27, 2023
@jaybuidl jaybuidl added this to the alpha-testnet milestone Aug 2, 2023
@jaybuidl jaybuidl closed this as completed Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants