Initial commit

This commit is contained in:
Julien Eluard 2019-07-09 15:17:40 +02:00
commit 42eb11fa7a
14 changed files with 22720 additions and 0 deletions

25
.gitignore vendored Normal file
View File

@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
/dist
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.cache/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

22
Makefile Normal file
View File

@ -0,0 +1,22 @@
.PHONY: build, dev
init: clean install
echo "Ready"
install:
yarn
build:
yarn run build
dev:
# requires export NODE_OPTIONS=--max_old_space_size=4096
yarn run dev
deploy-website: install compile
$(eval VERSION = $(shell git rev-parse --short HEAD))
$(eval MESSAGE = 'Deploying \#$(VERSION)')
./node_modules/gh-pages/bin/gh-pages.js --dotfiles --message ${MESSAGE} --dist resources/public
clean:
rm -rf node_modules/ dist/ yarn.lock

11
README.md Normal file
View File

@ -0,0 +1,11 @@
A simplistic UI to publish sticker packs.
# Setup
yarn
## Local dev env
```
make dev
```

15268
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

30
package.json Normal file
View File

@ -0,0 +1,30 @@
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "4.1.2",
"@material-ui/icons": "4.2.1",
"@types/react": "16.8.14",
"@types/react-dom": "16.8.4",
"content-hash": "2.3.2",
"react": "16.8.0",
"react-dom": "16.8.0",
"typeface-roboto": "0.0.54",
"typescript": "3.5.2",
"web3": "1.0.0-beta.55"
},
"devDependencies": {
"parcel-bundler": "1.12.3"
},
"scripts": {
"dev": "parcel public/index.html --host 127.0.0.1.xip.io --https",
"build": "parcel build public/index.html"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
"last 2 Chrome versions"
]
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

41
public/index.html Normal file
View File

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="favicon.ico" />
<meta
name="viewport"
content="minimum-scale=1, width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
<script src="../src/index.tsx"></script>
</html>

15
public/manifest.json Normal file
View File

@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

230
src/App.tsx Normal file
View File

@ -0,0 +1,230 @@
import React, { Fragment, useState, useEffect} from 'react';
import Button from '@material-ui/core/Button';
import Input from '@material-ui/core/Input';
import CloudDone from '@material-ui/icons/CloudDone';
import 'typeface-roboto';
import contentHash from 'content-hash';
import Web3 from 'web3';
// https://cloudflare-ipfs.com/ipfs/QmQRmKoVi5a1CCWDNUFPRdEixMQfsZ2ECC5e2nQF1Gwi86/
/*
https://content-hash.surge.sh
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1577.md
*/
function createDescription(name: String, author: String, thumbnail: String, preview: String, ids: String[]): string {
const stickers = ids.map(id => `{:hash "${id}"}`).join('" "');
// TODO add :hash
return `{meta {:name "${name}"
:author "${author}"
:thumbnail "${thumbnail}"
:preview "${preview}"
:stickers [${stickers}]}}`;
}
async function ipfsAdd(content: string | Blob) {
const formData = new FormData();
formData.append("", content);
const response = await fetch("https://ipfs.infura.io:5001/api/v0/add", {
method: 'post',
body: formData
});
if (response.status === 200) {
return response.json();
}
return null;
}
async function uploadFile(name: string, author: string, thumbnail: string, preview: string, stickers: string[]) {
const description = createDescription(name, author, contentHash.fromIpfs(thumbnail),
contentHash.fromIpfs(preview),
stickers.map(contentHash.fromIpfs));
return ipfsAdd(description);
}
var divStyle = {
display: 'flex',
flexDirection: 'column',
width: '40vw',
alignItems: "center"
};
const ABI = [{"constant":false,
"inputs":[{"name":"_packId",
"type":"uint256"},
{"name":"_limit",
"type":"uint256"}],
"name":"purgePack","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"interfaceId","type":"bytes4"}],
"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},
{"constant":true,"inputs":[],"name":"snt","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},
{"constant":true,"inputs":[{"name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"name":"","type":"address"}],
"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},
{"name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},
{"constant":false,"inputs":[{"name":"_price","type":"uint256"},{"name":"_donate","type":"uint256"},{"name":"_category","type":"bytes4[]"},
{"name":"_owner","type":"address"},{"name":"_contenthash","type":"bytes"}],"name":"registerPack","outputs":[{"name":"packId","type":"uint256"}],
"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_owner","type":"address"},
{"name":"_packId","type":"uint256"}],"name":"generateToken","outputs":[{"name":"tokenId","type":"uint256"}],"payable":false,"stateMutability":"nonpayable",
"type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"setBurnRate","outputs":[],"payable":false,"stateMutability":"nonpayable",
"type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"tokenId","type":"uint256"}],
"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},
{"name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},
{"constant":false,"inputs":[{"name":"_newController","type":"address"}],"name":"changeController","outputs":[],"payable":false,"stateMutability":"nonpayable",
"type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"tokenId","type":"uint256"}],
"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_state","type":"uint8"}],
"name":"setMarketState","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],
"name":"packCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},
{"constant":true,"inputs":[{"name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view",
"type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,
"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_packId","type":"uint256"},{"name":"_to","type":"address"}],"name":"setPackOwner",
"outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},
{"name":"","type":"uint256"},{"name":"_token","type":"address"},{"name":"_data","type":"bytes"}],"name":"receiveApproval","outputs":[],"payable":false,
"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_packId","type":"uint256"},{"name":"_destination","type":"address"}],
"name":"buyToken","outputs":[{"name":"tokenId","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},
{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"setRegisterFee","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},
{"constant":false,"inputs":[{"name":"_packId","type":"uint256"},{"name":"_price","type":"uint256"},{"name":"_donate","type":"uint256"}],
"name":"setPackPrice","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"tokenCount",
"outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_category","type":"bytes4"}],
"name":"getCategoryLength","outputs":[{"name":"size","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,
"inputs":[{"name":"to","type":"address"},{"name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"payable":false,
"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"tokenPackId",
"outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_packId","type":"uint256"},
{"name":"_category","type":"bytes4"}],"name":"addPackCategory","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},
{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getTokenData","outputs":[{"name":"category","type":"bytes4[]"},
{"name":"timestamp","type":"uint256"},{"name":"contenthash","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},
{"constant":true,"inputs":[{"name":"_category","type":"bytes4"}],"name":"getAvailablePacks","outputs":[{"name":"availableIds","type":"uint256[]"}],
"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_category","type":"bytes4"},{"name":"_index","type":"uint256"}],
"name":"getCategoryPack","outputs":[{"name":"packId","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_packId","type":"uint256"},
{"name":"_mintable","type":"bool"}],"name":"setPackState","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],
"name":"packs","outputs":[{"name":"owner","type":"address"},{"name":"mintable","type":"bool"},{"name":"timestamp","type":"uint256"},{"name":"price","type":"uint256"},{"name":"donate","type":"uint256"},
{"name":"contenthash","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},
{"name":"tokenId","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},
{"constant":true,"inputs":[],"name":"state","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_packId",
"type":"uint256"}],"name":"getPackData","outputs":[{"name":"category","type":"bytes4[]"},{"name":"owner","type":"address"},{"name":"mintable","type":"bool"},{"name":"timestamp","type":"uint256"},
{"name":"price","type":"uint256"},{"name":"contenthash","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],
"name":"claimTokens","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_packId","type":"uint256"},{"name":"_category","type":"bytes4"}],
"name":"removePackCategory","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},
{"name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},
{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"tokensOwnedBy","outputs":[{"name":"tokenList","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},
{"constant":true,"inputs":[],"name":"controller","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_snt","type":"address"}],
"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"packId","type":"uint256"},{"indexed":false,"name":"dataPrice","type":"uint256"},
{"indexed":false,"name":"_contenthash","type":"bytes"}],"name":"Register","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"category","type":"bytes4"},{"indexed":true,"name":"packId",
"type":"uint256"}],"name":"Categorized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"category","type":"bytes4"},{"indexed":true,"name":"packId","type":"uint256"}],
"name":"Uncategorized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"packId","type":"uint256"}],"name":"Unregister","type":"event"},{"anonymous":false,
"inputs":[{"indexed":true,"name":"_token","type":"address"},{"indexed":true,"name":"_controller","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"ClaimedTokens",
"type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"state","type":"uint8"}],"name":"MarketState","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"value",
"type":"uint256"}],"name":"RegisterFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"value","type":"uint256"}],"name":"BurnRate","type":"event"},{"anonymous":false,
"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":true,"name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},
{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"approved","type":"address"},{"indexed":true,"name":"tokenId","type":"uint256"}],
"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"operator","type":"address"},{"indexed":false,
"name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"}];
const Home = (props: any) => {
const [name, setName] = useState("");
const [author, setAuthor] = useState("");
const [price, setPrice] = useState("");
const [thumbnail, setThumbnail] = useState("");
const [stickers, setStickers] = useState([]);
const [hash, setHash] = useState("");
const uploadDescription = async (_: any) => {
const res = await uploadFile(name, author, thumbnail, thumbnail, stickers);
setHash(res.Hash);
};
const register = async (_: any) => {
const addresses = await window.ethereum.enable();
const web3 = new Web3(window.ethereum);
web3.eth.Contract(ABI, "0x39d16CdB56b5a6a89e1A397A13Fe48034694316E").methods
.registerPack("0", "0", ["0x00000000", "0x00000001"], addresses[0], "0x"+contentHash.fromIpfs(hash).replace('e30101', 'e301')).send({"from": addresses[0]} );
};
const handleThumbnail = async (e: any) => {
setThumbnail("");
ipfsAdd(e.target.files[0]).then(res => setThumbnail(res.Hash));
};
const handleStickers = async (e: any) => {
setStickers([]);
const files = Array.from(e.target.files);
Promise.all(files.map(ipfsAdd)).then(all => {
setStickers(all.map(a => a.Hash));
})
};
const complete = name.length != 0 && author.length != 0 && thumbnail.length != 0 && stickers.length != 0;
return (
<div id="form" style={divStyle}>
<Input value={name}
onChange={e => setName(e.target.value)}
placeholder="Name" required/>
<Input value={author}
onChange={e => setAuthor(e.target.value)}
placeholder="Author" required/>
<Input value={price}
onChange={e => setPrice(e.target.value)}
placeholder="Price" required/>
<input
accept="image/*"
style={{ display: 'none' }}
id="raised-button-file"
onChange={handleThumbnail}
type="file"
/>
<label htmlFor="raised-button-file">
<Button variant="contained" component="span">
{thumbnail.length != 0 &&
<CloudDone />
}
Upload thumbnail
</Button>
</label>
<input
accept="image/*"
style={{ display: 'none' }}
id="raised-button-stickers"
multiple
onChange={handleStickers}
type="file"
/>
<label htmlFor="raised-button-stickers">
<Button variant="contained" component="span">
{stickers.length != 0 &&
<CloudDone />
}
Upload stickers
</Button>
</label>
<Button variant="contained" color="primary" onClick={uploadDescription} disabled={!complete}>
Deploy
</Button>
{hash && hash.length != 0 &&
<Fragment>
<div>IPFS Hash: {hash}</div>
<a href={'https://ipfs.infura.io/ipfs/'+hash}>link</a>
<Button variant="contained" color="primary" onClick={register}>
Publish
</Button>
</Fragment>
}
</div>);
};
var containerStyle = {
display: 'flex',
justifyContent: "center",
alignItems: "center",
height: "100vh"
};
function App() {
return (
<div style={containerStyle}>
<Home />
</div>
);
}
export default App;

18
src/index.css Normal file
View File

@ -0,0 +1,18 @@
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
#form > * {
margin: 10px;
}

6
src/index.tsx Normal file
View File

@ -0,0 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));

2
src/react-app-env.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
/// <reference types="react-scripts" />
declare module 'content-hash';

25
tsconfig.json Normal file
View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}

7027
yarn.lock Normal file

File diff suppressed because it is too large Load Diff