Skip to content

Commit adc1005

Browse files
authored
Merge pull request #74 from kleros/feat/subgraph-integration
Feat: subgraph integration
2 parents 6308cf6 + f4360e7 commit adc1005

File tree

213 files changed

+4636
-16567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

213 files changed

+4636
-16567
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ AVAILABLE_LANGUAGE_GROUP_PAIRS='["en|pt"]'
99
LINGUO_CONTRACT_ADDRESSES='{"<chain ID>":{"en|pt":["0x00...0000"],"en|es:["0x00..0000"]}}'
1010
USER_SETTINGS_API_BASE_URLS='{"<chain ID>": <Base URL>, ...}'
1111
JSON_RPC_URLS='{"<chain ID>": <URL>, ...}'
12+
SUBGRAPH_PROJECT_NAMES ='{"100":"<user>/<project>","5":"..."}'

.eslintrc.json

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"plugin:react-hooks/recommended",
66
"plugin:import/recommended",
77
"plugin:import/react",
8-
"plugin:security/recommended"
8+
"plugin:security/recommended",
9+
"prettier"
910
],
1011
"plugins": [
1112
"react",
@@ -28,7 +29,7 @@
2829
"ecmaFeatures": {
2930
"jsx": true
3031
},
31-
"ecmaVersion": 2018,
32+
"ecmaVersion": 2020,
3233
"sourceType": "module"
3334
},
3435
"settings": {
@@ -56,17 +57,6 @@
5657
"argsIgnorePattern": "(^_+[0-9]*$)|([iI]gnored$)|(^ignored)"
5758
}
5859
],
59-
"no-console": [
60-
"error",
61-
{
62-
"allow": [
63-
"warn",
64-
"error",
65-
"info",
66-
"debug"
67-
]
68-
}
69-
],
7060
"security/detect-object-injection": "off",
7161
"security/detect-non-literal-fs-filename": "off",
7262
"import/extensions": [

netlify.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
IPFS_GATEWAY_ADDRESS='https://ipfs.kleros.io'
66
AVAILABLE_LANGUAGE_GROUP_PAIRS='["en|fr","en|es","en|pt","de|en","en|ru","en|ja","en|ko","en|tr","en|zh"]'
77
USER_SETTINGS_API_BASE_URLS='{"1":"https://iioeu1ljqf.execute-api.us-east-2.amazonaws.com/mainnet","77":"https://xa1qxy0wp6.execute-api.us-east-2.amazonaws.com/sokol","100":"https://wcj9vww4nf.execute-api.us-east-2.amazonaws.com/xdai"}'
8-
LINGUO_CONTRACT_ADDRESSES='{"1":{"de|en":["0x54f1f7b58c1Dc646a6c639C5d909B62652129b33","0x950f5AB863075C685227EfEDb41Ef167Be0099ad"],"en|es":["0x460f688f655610de5e3d92beb7892fa200b9060d","0xD8F8019c025C2Ba6745543D9a3C338DE1b98C103"],"en|fr":["0xFEe86325d5C96AE9E20EaBe7B157813c67bBccFA","0xf1A9589880DbF393F32A5b2d5a0054Fa10385074"],"en|ja":["0x5Cd1ff55282db11e526Fe13fA0F7C014f74acF11","0xc3162705Af0e10108FF837E450A14669b2711129"],"en|ko":["0xf8D4c1436ACA89A5DEEf36F06f662bAdfEb5AE63","0xFE721DD8Ac8e47A4228A6147A25C65136f213EaA"],"en|pt":["0x48032Ad54DB49d8E0d4f135A687b98E5731961f9","0x1c839fd542563182BFD0C337c8AaD1Be412F0fd2"],"en|ru":["0x0Bc3B51673dCdF3b45c628066761dA7331E8fBA2","0x464c84c41f3C25Ba5a75B006D8B20600A8777306"],"en|tr":["0xa3E4348BDDc32AfcedC5e088e0E21FD6154A0180","0x44863f5b7AAb7ceE181C0d84E244540125eF7AF7"],"en|zh":["0xaB0D90943A58b1A64c0171Ee8e743d9998Be6AC3","0xD67C12734dC12240a6324Db63ccd426964B71Fe7"]},"77":{"de|en":["0x8539cb2fB9186f3DcF8F9A0AeD3De395Fd6d9870"],"en|es":["0x5a9F70ED50e16010f0B9d5bb5a3EFdb42fEcaD23"],"en|fr":["0x9CA979a165EF741BF120A3FEbb4F5C083De40708"],"en|ja":["0x753d611eAdF324B1f23A3A417BceB08eeda80ec6"],"en|ko":["0xC578de969Dd2A2a08d6Bd5A4F7AaA9b1a2e6A395"],"en|pt":["0x457b2BAb823c772fA4457517C97E6BF13065c21D"],"en|ru":["0x6cD5BAb73135966008d969bE23Ff940e6fa3Bb87"],"en|tr":["0xa9426b235E12897A99B015CbcF4D064e86fde418"],"en|zh":["0x09CE835FaB6051a18b2FC11743c01DAAD3122f1F"]},"100":{"de|en":["0xc3162705Af0e10108FF837E450A14669b2711129"],"en|es":["0xA2BfFF0553DE7405781FE0C39C04A383F04b9C80"],"en|fr":["0x464c84c41f3C25Ba5a75B006D8B20600A8777306"],"en|ja":["0x852550982e0984F9CCeF18a7276D35AFDc30242c"],"en|ko":["0xD67C12734dC12240a6324Db63ccd426964B71Fe7"],"en|pt":["0xFE721DD8Ac8e47A4228A6147A25C65136f213EaA"],"en|ru":["0x44863f5b7AAb7ceE181C0d84E244540125eF7AF7"],"en|tr":["0x1D48a279966f37385b4AB963530C6dC813b3A8Df"],"en|zh":["0x0B928165A67df8254412483ae8C3b8cc7F2b4D36"]}}'
8+
LINGUO_CONTRACT_ADDRESSES='{"1":{"de|en":["0x54f1f7b58c1Dc646a6c639C5d909B62652129b33","0x950f5AB863075C685227EfEDb41Ef167Be0099ad"],"en|es":["0x460f688f655610de5e3d92beb7892fa200b9060d","0xD8F8019c025C2Ba6745543D9a3C338DE1b98C103"],"en|fr":["0xFEe86325d5C96AE9E20EaBe7B157813c67bBccFA","0xf1A9589880DbF393F32A5b2d5a0054Fa10385074"],"en|ja":["0x5Cd1ff55282db11e526Fe13fA0F7C014f74acF11","0xc3162705Af0e10108FF837E450A14669b2711129"],"en|ko":["0xf8D4c1436ACA89A5DEEf36F06f662bAdfEb5AE63","0xFE721DD8Ac8e47A4228A6147A25C65136f213EaA"],"en|pt":["0x48032Ad54DB49d8E0d4f135A687b98E5731961f9","0x1c839fd542563182BFD0C337c8AaD1Be412F0fd2"],"en|ru":["0x0Bc3B51673dCdF3b45c628066761dA7331E8fBA2","0x464c84c41f3C25Ba5a75B006D8B20600A8777306"],"en|tr":["0xa3E4348BDDc32AfcedC5e088e0E21FD6154A0180","0x44863f5b7AAb7ceE181C0d84E244540125eF7AF7"],"en|zh":["0xaB0D90943A58b1A64c0171Ee8e743d9998Be6AC3","0xD67C12734dC12240a6324Db63ccd426964B71Fe7"]},"77":{"de|en":["0x8539cb2fB9186f3DcF8F9A0AeD3De395Fd6d9870"],"en|es":["0x5a9F70ED50e16010f0B9d5bb5a3EFdb42fEcaD23"],"en|fr":["0x9CA979a165EF741BF120A3FEbb4F5C083De40708"],"en|ja":["0x753d611eAdF324B1f23A3A417BceB08eeda80ec6"],"en|ko":["0xC578de969Dd2A2a08d6Bd5A4F7AaA9b1a2e6A395"],"en|pt":["0x457b2BAb823c772fA4457517C97E6BF13065c21D"],"en|ru":["0x6cD5BAb73135966008d969bE23Ff940e6fa3Bb87"],"en|tr":["0xa9426b235E12897A99B015CbcF4D064e86fde418"],"en|zh":["0x09CE835FaB6051a18b2FC11743c01DAAD3122f1F"]},"100":{"de|en":["0xc3162705Af0e10108FF837E450A14669b2711129"],"en|es":["0xA2BfFF0553DE7405781FE0C39C04A383F04b9C80"],"en|fr":["0x464c84c41f3C25Ba5a75B006D8B20600A8777306"],"en|ja":["0x852550982e0984F9CCeF18a7276D35AFDc30242c"],"en|ko":["0xD67C12734dC12240a6324Db63ccd426964B71Fe7"],"en|pt":["0xFE721DD8Ac8e47A4228A6147A25C65136f213EaA"],"en|ru":["0x44863f5b7AAb7ceE181C0d84E244540125eF7AF7"],"en|tr":["0x1D48a279966f37385b4AB963530C6dC813b3A8Df"],"en|zh":["0x0B928165A67df8254412483ae8C3b8cc7F2b4D36"]},"5":{"de|en":["0xDDFac50f2f9C60AD1b263C37253E7f157231dfF3"],"en|es":["0x5fB4B92c48dB367Dee88e34cA977Af0581D1a855"],"en|fr":["0x81F78a49E472B507B49ea7a01dF2760E1922dce4"],"en|ja":["0x9B926259A16F975f931E5587b5756EFAAC305B5f"],"en|ko":["0x558457cA2a4c22b9A50E8822FDf7927887D90D6c"],"en|pt":["0x3e05C4dEc668bd0A93668437577fea36Db77AB65"],"en|ru":["0xa0D5931DecB5Fb7265ac0417fDB6D2C39500F824"],"en|tr":["0x1bfEbB574A263D4d627ceF63d9fA23CD624E0e5c"],"en|zh":["0x5bd640A53E2E29984D405FCc0b1526c252A325D7"]}}'
9+
JSON_RPC_URLS='{"100":"https://rpc.ankr.com/gnosis","1":"https://mainnet.infura.io/v3/","77":"https://sokol.poa.network","5":"https://goerli.infura.io/v3/"}'
10+
SUBGRAPH_PROJECT_NAMES='{"100":"kleros/linguo-gnosis","5":"kleros/linguo-goerli"}'
11+
912
[context.production.environment]
1013
PRODUCTION='true'
1114

package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"caniuse-lite": "1.0.30001436"
2727
},
2828
"dependencies": {
29-
"3box": "^1.19.1",
3029
"3id-resolver": "^1.0.1",
3130
"@ant-design/icons": "^4.3.0",
3231
"@ethersproject/address": "^5.0.5",
@@ -41,13 +40,13 @@
4140
"@kleros/react-components": "^6.0.0",
4241
"@loadable/component": "^5.12.0",
4342
"@reduxjs/toolkit": "^1.6.1",
44-
"@rehooks/local-storage": "^2.2.3",
43+
"@rehooks/local-storage": "^2.4.4",
4544
"@uniswap/sdk": "^3.0.3",
4645
"@web3-react/abstract-connector": "^6.0.7",
47-
"@web3-react/core": "^6.1.1",
46+
"@web3-react/core": "^6.1.9",
4847
"@web3-react/injected-connector": "^6.0.7",
4948
"@web3-react/network-connector": "^6.1.5",
50-
"@web3-react/walletconnect-connector": "^6.2.4",
49+
"@web3-react/walletconnect-connector": "^6.2.13",
5150
"antd": "~4.16.0",
5251
"browserslist": "^4.21.4",
5352
"clsx": "^1.1.0",
@@ -57,34 +56,40 @@
5756
"deep-equal": "^2.0.5",
5857
"deepmerge": "^4.2.2",
5958
"did-resolver": "^2.1.2",
59+
"ethers": "^5.7.2",
60+
"graphql": "^16.6.0",
61+
"graphql-request": "^5.1.0",
6062
"history": "^4.10.1",
6163
"hoist-non-react-statics": "^3.3.2",
62-
"immer": "^9.0.6",
64+
"immer": "^9.0.19",
6365
"ipfs-http-client": "^42.0.0",
6466
"js-base64": "^3.6.0",
6567
"js-combinatorics": "^0.6.1",
6668
"localforage": "^1.10.0",
69+
"moment": "^2.29.4",
6770
"nanoid": "^3.1.9",
6871
"normalize.css": "^8.0.1",
6972
"path-to-regexp": "^6.1.0",
7073
"prop-types": "^15.7.2",
7174
"react": "^17.0.2",
7275
"react-blockies": "^1.4.1",
7376
"react-dom": "^17.0.2",
74-
"react-hot-loader": "^4.13.0",
77+
"react-hot-loader": "^4.13.1",
7578
"react-is": "^17.0.2",
7679
"react-redux": "^7.2.5",
7780
"react-router": "^5.1.2",
7881
"react-router-dom": "^5.1.2",
7982
"react-titled": "^1.0.1",
83+
"react-toastify": "^9.1.1",
8084
"react-visibility-sensor": "^5.1.1",
8185
"redux": "^4.1.1",
8286
"redux-persist": "^6.0.0",
8387
"redux-saga": "^1.1.3",
8488
"redux-saga-thunk": "^0.7.3",
8589
"scroll-into-view-if-needed": "^2.2.25",
8690
"serialize-error": "^7.0.1",
87-
"styled-components": "^5.3.1",
91+
"styled-components": "^5.3.6",
92+
"swr": "^2.0.3",
8893
"web3": "^1.5.2"
8994
},
9095
"devDependencies": {
@@ -106,7 +111,7 @@
106111
"@types/react": "^16.9.23",
107112
"autoprefixer": "^9.7.4",
108113
"babel-eslint": "^10.1.0",
109-
"babel-plugin-import": "^1.13.0",
114+
"babel-plugin-import": "^1.13.6",
110115
"babel-plugin-styled-components": "^1.10.7",
111116
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
112117
"cssnano": "^4.1.10",

src/adapters/price-oracle/makerDAOFeed/getEthPriceUsd.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import Web3 from 'web3';
2-
import { jsonRpcUrls } from '~/features/web3/supportedChains';
2+
import { RPC_URLS } from '~/consts/supportedChains';
3+
34
import abi from './assets/MedianEthUsd.json';
45

5-
const providerUrl = jsonRpcUrls[1];
6+
const providerUrl = RPC_URLS[1];
67
const provider = new Web3.providers.HttpProvider(providerUrl);
78
const web3 = new Web3(provider);
8-
const contract = new web3.eth.Contract(abi, '0x64de91f5a373cd4c28de3600cb34c7c6ce410c85');
9+
const contract = new web3.eth.Contract(abi, '0x64de91f5a373cd4c28de3600cb34c7c6ce410c85'); // https://mips.makerdao.com/mips/md-viewer#active-oracle-list
910

1011
async function getPriceFromLatestBlocks({ fromBlock }) {
1112
const events = await contract.getPastEvents('LogMedianPrice', {

src/app/App.jsx

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,23 @@
11
import React from 'react';
22
import { hot } from 'react-hot-loader';
3-
import t from 'prop-types';
43
import { createGlobalStyle, ThemeProvider } from 'styled-components';
5-
import { Web3ReactProvider } from '@web3-react/core';
6-
import Web3 from 'web3';
74
import theme from '~/features/ui/theme';
8-
import { useWatchLibrary, useWeb3ReactBootstrap } from '~/features/web3';
95
import MainRouter from './MainRouter';
6+
import Web3Provider from '../context/Web3Provider';
107

118
function App() {
129
return (
13-
<Web3ReactProvider getLibrary={getLibrary}>
10+
<Web3Provider>
1411
<ThemeProvider theme={theme}>
15-
<Initializer>
16-
<GlobalStyle />
17-
<MainRouter />
18-
</Initializer>
12+
<GlobalStyle />
13+
<MainRouter />
1914
</ThemeProvider>
20-
</Web3ReactProvider>
15+
</Web3Provider>
2116
);
2217
}
2318

2419
export default hot(module)(App);
2520

26-
function _Initializer({ children }) {
27-
useWeb3ReactBootstrap();
28-
useWatchLibrary();
29-
30-
return children;
31-
}
32-
33-
_Initializer.propTypes = {
34-
children: t.node,
35-
};
36-
37-
const Initializer = React.memo(_Initializer);
38-
39-
function getLibrary(provider) {
40-
return new Web3(provider);
41-
}
42-
4321
const GlobalStyle = createGlobalStyle`
4422
body {
4523
min-width: 24rem;

src/app/Content.jsx

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,26 @@
11
import React from 'react';
22
import t from 'prop-types';
33
import styled from 'styled-components';
4-
import { useDispatch, useSelector } from 'react-redux';
54
import { Layout } from 'antd';
65
import { nanoid } from 'nanoid';
7-
import {
8-
selectLatestBlock,
9-
subscribeToUpdates,
10-
unsubscribeFromUpdates,
11-
updateTransientNotifications,
12-
} from '~/features/tasks/tasksSlice';
6+
137
import { subscribeToEthPrice, unsubscribeFromEthPrice } from '~/features/tokens/tokensSlice';
14-
import { selectAccount, selectChainId } from '~/features/web3/web3Slice';
8+
import { useWeb3 } from '~/hooks/useWeb3';
9+
import { useDispatch } from 'react-redux';
1510

1611
export default function Content({ children }) {
17-
useTaskUpdatesSubscription();
1812
useEthPricePolling();
1913

2014
return <StyledContent>{children}</StyledContent>;
2115
}
2216

23-
function useTaskUpdatesSubscription() {
24-
const dispatch = useDispatch();
25-
26-
const account = useSelector(selectAccount);
27-
const chainId = useSelector(selectChainId);
28-
const latestBlock = useSelector(selectLatestBlock({ chainId, account }));
29-
30-
const subscribe = React.useCallback(
31-
() => dispatch(subscribeToUpdates({ chainId, account, fromBlock: latestBlock + 1 }, { meta: { groupId } })),
32-
[dispatch, account, chainId, latestBlock]
33-
);
34-
const unsubscribe = React.useCallback(() => dispatch(unsubscribeFromUpdates({}, { meta: { groupId } })), [dispatch]);
35-
36-
React.useEffect(() => {
37-
dispatch(updateTransientNotifications({ account, chainId }));
38-
}, [dispatch, account, chainId]);
39-
40-
React.useEffect(() => {
41-
if (account) {
42-
subscribe();
43-
44-
window.addEventListener('focus', subscribe);
45-
window.addEventListener('blur', unsubscribe);
46-
47-
return () => {
48-
unsubscribe();
49-
50-
window.removeEventListener('focus', subscribe);
51-
window.removeEventListener('blur', unsubscribe);
52-
};
53-
}
54-
}, [dispatch, account, subscribe, unsubscribe]);
55-
}
56-
5717
const groupId = nanoid(10);
5818
const _1_MINUTE = 60 * 1000;
5919

6020
function useEthPricePolling({ interval = _1_MINUTE } = {}) {
21+
const { chainId } = useWeb3();
6122
const dispatch = useDispatch();
6223

63-
const chainId = useSelector(selectChainId);
64-
6524
const subscribe = React.useCallback(
6625
() => dispatch(subscribeToEthPrice({ chainId, interval, immediate: true }, { meta: { groupId } })),
6726
[dispatch, chainId, interval]

0 commit comments

Comments
 (0)