diff --git a/src/components/court-card.js b/src/components/court-card.js index f6537e5..9e55bc1 100644 --- a/src/components/court-card.js +++ b/src/components/court-card.js @@ -1,9 +1,12 @@ import { Button, Card } from 'antd' import React, { useMemo } from 'react' +import { useDrizzle, useDrizzleState } from '../temp/drizzle-react-hooks' import { ReactComponent as Close } from '../assets/images/close.svg' +import ETHAmount from './eth-amount' import { ReactComponent as Hexagon } from '../assets/images/hexagon.svg' import PropTypes from 'prop-types' import styled from 'styled-components/macro' +import { useDataloader } from '../bootstrap/dataloader' const StyledCard = styled(Card)` margin: 20px 0; @@ -38,7 +41,24 @@ const StyledAmountDiv = styled.div` font-weight: bold; ` const CourtCard = ({ ID }) => { - console.log(ID) + const { cacheCall } = useDrizzle() + const drizzleState = useDrizzleState(drizzleState => ({ + accounts: drizzleState.accounts + })) + const load = useDataloader() + let name + const policy = cacheCall('PolicyRegistry', 'policies', ID) + if (policy) { + const policyJSON = load(policy.fileURI) + if (policyJSON) name = policyJSON.name + } + const stake = cacheCall( + 'KlerosLiquid', + 'stakeOf', + drizzleState.accounts[0], + ID + ) + const subcourt = cacheCall('KlerosLiquid', 'courts', ID) return ( { )} extra={} hoverable - loading={false} - title="Air Transport" + loading={name === undefined} + title={name} > - 0PNK + + + + PNK - Min Stake350 PNK + Min Stake + + PNK + - Coherence Reward0.01 ETH + + Coherence Reward + + ETH + + + - Stake Locked Per Vote200 PNK + Stake Locked/Vote + + {' '} + PNK + ) } CourtCard.propTypes = { - ID: PropTypes.number.isRequired + ID: PropTypes.string.isRequired } export default CourtCard diff --git a/src/components/courts-list-card.js b/src/components/courts-list-card.js index a1a30ca..e1fb41f 100644 --- a/src/components/courts-list-card.js +++ b/src/components/courts-list-card.js @@ -30,7 +30,7 @@ const CourtsListCard = () => { } return undefined }) - const loading = !names || names.some(n => !n) + const loading = !names || names.some(n => n === undefined) return ( { return amount === null ? ( ) : ( - Number(drizzle.web3.utils.fromWei(amount)).toFixed(decimals) + Number( + drizzle.web3.utils.fromWei( + typeof amount === 'number' ? String(amount) : amount + ) + ).toFixed(decimals) ) } diff --git a/src/containers/courts.js b/src/containers/courts.js index f6e6ea4..572ec44 100644 --- a/src/containers/courts.js +++ b/src/containers/courts.js @@ -1,33 +1,41 @@ -import { Button, Col, Row } from 'antd' +import { Button, Col, Row, Spin } from 'antd' +import { useDrizzle, useDrizzleState } from '../temp/drizzle-react-hooks' import CourtCard from '../components/court-card' import React from 'react' import TopBanner from '../components/top-banner' -export default () => ( - <> - - Select Court - - } - title="Courts" - /> - My Courts - - - - - - - - - - - - - - - -) +export default () => { + const { cacheCall } = useDrizzle() + const drizzleState = useDrizzleState(drizzleState => ({ + accounts: drizzleState.accounts + })) + const subcourtIDs = cacheCall( + 'KlerosLiquid', + 'getJuror', + drizzleState.accounts[0] + ) + return ( + <> + + Select Court + + } + title="Courts" + /> + My Courts + + + {subcourtIDs && + subcourtIDs.map(ID => ( + + + + ))} + + + + ) +} diff --git a/src/temp/drizzle-react-hooks.js b/src/temp/drizzle-react-hooks.js index 24c68ca..c9d66b3 100644 --- a/src/temp/drizzle-react-hooks.js +++ b/src/temp/drizzle-react-hooks.js @@ -80,11 +80,11 @@ export const DrizzleProvider = ({ children, drizzle }) => { contract .getPastEvents(eventName, eventOptions) .then(pastEvents => setEvents(pastEvents)) - return drizzle.contracts[contractName].events[eventName]({ + const listener = drizzle.contracts[contractName].events[eventName]({ ...eventOptions, fromBlock: 'latest' }).on('data', event => setEvents(events => [...events, event])) - .unsubscribe + return listener.unsubscribe.bind(listener) }, [contractName, eventName, eventOptions] )