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

1Market #1

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.idea
54 changes: 17 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,24 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## 1Market Demo

## Available Scripts
### Deploy a new market
1. Generate random hash string with length 64: https://www.browserling.com/tools/random-hex

In the project directory, you can run:
2. Change description and hash in <root>/`market.config.js`

### `yarn start`
3. Redeploy the contract:

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
Locally:
```shell
ganache-cli -d
truffle migrate
```

The page will reload if you make edits.<br />
You will also see any lint errors in the console.
On harmony network:
```shell
truffle migrate --network harmony --reset
```

### `yarn test`
### Misc
Original tutorial: https://docs.gnosis.io/conditionaltokens/docs/pmtutorial1

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
Hash generator: https://www.browserling.com/tools/random-hex
8 changes: 5 additions & 3 deletions markets.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = [
{
questionId: "0x4b22fe478b95fdaa835ddddf631ab29f12900b62061e0c5fd8564ddb7b684333",
title: "Will the summer 2020 in Germany break again weather records? ",
questionId: "0x4019d230428b2490a17046cab81ad2ccddd4b942d2f8d53bd25a72105011ec3c",
title: "Will Trump say 'Crypto/Bitcoin' during the debates?",
expirationTimestamp: Date.parse('31 Oct 2024 00:00:00 GMT').valueOf(),
outcomes: [
{
title: "Yes",
Expand All @@ -11,6 +12,7 @@ module.exports = [
title: "No",
short: "No"
}
]
],
imageUrl: 'https://polymarket.com/_next/image?url=https%3A%2F%2Fpolymarket-upload.s3.us-east-2.amazonaws.com%2Fwhat-will-trump-say-during-michigan-rally-aYFXl7b0S2r8.jpg&w=256&q=100'
}
];
2 changes: 1 addition & 1 deletion migrations/05_collateral.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function(deployer) {
deployer.deploy(artifacts.require("WETH9"), { overwrite: false });
deployer.deploy(artifacts.require("WETH9"), { overwrite: true });
};
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@
"@types/react": "^17.0.20",
"@types/react-dom": "^17.0.9",
"@walletconnect/web3-provider": "^1.6.5",
"bignumber.js": "^9.0.1",
"antd": "^5.20.6",
"bignumber.js": "^9.1.2",
"canonical-weth": "^1.4.0",
"decimal.js-light": "^2.5.1",
"dotenv": "^10.0.0",
"grommet": "^2.40.1",
"moment": "^2.30.1",
"prettier": "^2.3.2",
"react": "^17.0.2",
"react-app-rewired": "^2.1.8",
"react-dev-utils": "^11.0.4",
"react-dom": "^17.0.2",
"react-scripts": "^4.0.3",
"styled-components": "^6.1.13",
"typescript": "~4.4.2",
"web3": "^1.5.2",
"web3connect": "^1.0.0-beta.33"
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"start": "react-app-rewired --openssl-legacy-provider start",
"build": "react-app-rewired --openssl-legacy-provider build",
"test": "react-app-rewired test",
"eject": "react-scripts eject",
"prettier": "prettier --write './src/**/*.{ts,tsx}'",
Expand Down
8 changes: 6 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Conditional Tokens Tutorial App Example"
content="1Market | Demo"
/>
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>Conditional Tokens Tutorial</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Rubik:wght@400;500;600&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<title>1Market | Demo</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
1 change: 1 addition & 0 deletions src/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import App from 'src/components/App'
import './index.css'

const Root: React.FC = () => <App />

Expand Down
42 changes: 42 additions & 0 deletions src/components/Account/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { useState } from 'react'
import { Box } from 'grommet'
import Web3ConnectButton from '../Web3Connect'
import Market from '../Market'
import Web3 from 'web3'
import { getWeb3Account } from '../../utils/web3'
import { useOneMarket } from '../../provider/DataProvider'

export const Account = () => {
const {
state: {
web3,
account
},
setState
} = useOneMarket()

const setProviderData = async (provider: any) => {
let newWeb3, newAccount
if (provider) {
newWeb3 = new Web3(provider)
newAccount = await getWeb3Account(newWeb3)
} else {
newWeb3 = null
newAccount = null
}
setState({
web3: newWeb3,
account: newAccount,
})
}

return <Box>
{process.env.REACT_APP_ORACLE_ADDRESS && process.env.REACT_APP_OPERATOR_ADDRESS ? (
<>
<Web3ConnectButton account={account} setProviderData={setProviderData} />
</>
) : (
<div>Configuration error</div>
)}
</Box>
}
49 changes: 16 additions & 33 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
import React, { useState } from 'react'
import Web3 from 'web3'
import Web3ConnectButton from 'src/components/Web3Connect'
import Market from 'src/components/Market'
import { getWeb3Account } from 'src/utils/web3'
import styles from './style.module.css'
import React from 'react'
import { Box, Grommet, Text } from 'grommet'
import { darkTheme } from '../theme/grommet'
import {ConfigProvider} from "antd";
import { Header } from './Header'
import { OneMarketDataProvider } from '../provider/DataProvider'
import { MainContent } from '../pages/mainContent'
import { antdTheme } from '../theme/antd'

const App: React.FC = () => {
const [web3, setWeb3] = useState<any>(undefined)
const [account, setAccount] = useState<string>('')

const setProviderData = async (provider: any) => {
let newWeb3, newAccount
if (provider) {
newWeb3 = new Web3(provider)
newAccount = await getWeb3Account(newWeb3)
} else {
newWeb3 = null
newAccount = null
}
setWeb3(newWeb3)
setAccount(newAccount)
}

return (
<div className={styles.container}>
<h1>Conditional Tokens Tutorial: Categorical Market Example</h1>
{process.env.REACT_APP_ORACLE_ADDRESS && process.env.REACT_APP_OPERATOR_ADDRESS ? (
<>
<Web3ConnectButton account={account} setProviderData={setProviderData} />
{web3 && account && <Market web3={web3} account={account} />}
</>
) : (
<div>Configuration error</div>
)}
</div>
<ConfigProvider theme={antdTheme}>
<Grommet theme={darkTheme} themeMode={'dark'} full>
<OneMarketDataProvider>
<Header />
<MainContent />
</OneMarketDataProvider>
</Grommet>
</ConfigProvider>
)
}

Expand Down
14 changes: 14 additions & 0 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react'
import { Box, Text } from 'grommet'
import { Account } from '../Account'

export const Header = () => {
return <Box justify={'between'} direction={'row'} pad={'16px'}>
<Box>
<Text size={'28px'} color={'accentWhite'}>1Market Demo</Text>
</Box>
<Box>
<Account />
</Box>
</Box>
}
Loading