add configs

This commit is contained in:
0xtsukino
2021-08-20 13:24:34 +08:00
parent ddc580390d
commit 22d7c2a15d
15 changed files with 93 additions and 70 deletions

1
.gitignore vendored
View File

@@ -2,6 +2,7 @@
node_modules
build*
config.dev.json
config.prod.json
config.json
.DS_Store
.env

View File

@@ -5,10 +5,6 @@ WORKDIR /app
COPY package*.json ./
COPY tsconfig.json ./
COPY config.json ./
COPY csr.pem ./
COPY privatekey.pem ./
COPY server.crt ./
COPY serve.js ./
COPY src /app/src
COPY static /app/static
COPY webpack.ui.config.js /app/webpack.ui.config.js
@@ -20,6 +16,5 @@ RUN npm install -g serve
RUN npm run build
EXPOSE 80
EXPOSE 443
CMD [ "node", "serve.js" ]
CMD [ "serve", "./build", "-l", "80" ]

View File

@@ -9,8 +9,7 @@
"predev": "cp ./static/bn128.js ./node_modules/websnark/src/bn128.js",
"prebuild": "cp ./static/bn128.js ./node_modules/websnark/src/bn128.js",
"dev": "NODE_ENV=development concurrently --kill-others-on-fail npm:dev-ui",
"build": "NODE_ENV=production npm run build-ui",
"serve": "serve ./build -l 80 & serve ./build -l 443"
"build": "NODE_ENV=production npm run build-ui"
},
"dependencies": {
"@ensdomains/ensjs": "^2.0.1",
@@ -21,7 +20,6 @@
"draft-js-table": "^0.3.0",
"elliptic": "^6.5.4",
"ethereum-blockies-base64": "^1.0.2",
"express": "^4.17.1",
"fast-deep-equal": "^3.1.3",
"gun": "^0.2020.1232",
"isomorphic-fetch": "^3.0.0",
@@ -68,6 +66,6 @@
"webpack-dev-server": "^3.9.0",
"webpack-node-externals": "^1.7.2"
},
"author": "",
"author": "0xTsukino",
"license": "ISC"
}

View File

@@ -1,18 +0,0 @@
var express = require('express');
var https = require('https');
var fs = require('fs');
var app = express();
var app2 = express();
app.use(express.static('/build'));
app2.use(express.static('/build'));
var options = {
key: fs.readFileSync('./privatekey.pem'),
cert: fs.readFileSync('./server.crt')
};
const server = https.createServer(options, app);
server.listen(443);
app2.listen(80);

View File

@@ -29,7 +29,7 @@ export default function Button(props: Props): ReactElement {
{
'button--primary': btnType === 'primary',
'button--secondary': btnType === 'secondary',
'cursor-default': disabled,
'cursor-default': disabled || loading,
},
className,
)}

View File

@@ -32,7 +32,7 @@ export default function DiscoverUserPanel(): ReactElement {
<div className="px-4 py-2 font-bold text-lg border-b border-gray-100">Discover Users</div>
<div className="flex flex-col flex-nowrap py-1">
{ loading && <Icon className="self-center my-4" url={SpinnerGIF} size={3} /> }
{users.map(ens => <UserRow name={ens} />)}
{users.map(ens => <UserRow key={ens} name={ens} />)}
</div>
</div>
)

View File

@@ -42,6 +42,16 @@ export default function Thread(props: Props): ReactElement {
await fetchMore();
}, [fetchMore, messageId]);
const gotoPost = useCallback(() => {
const [creator, hash] = messageId.split('/')
if (!hash) {
history.push(`/post/${creator}`)
} else {
history.push(`/${creator}/status/${hash}`)
}
}, [messageId]);
useEffect(() => {
(async function onThreadMount() {
if (!messageId || level >= 3) return;
@@ -79,7 +89,7 @@ export default function Thread(props: Props): ReactElement {
"border-l-4 bg-gray-50 mr-1 hover:border-gray-400",
)}
messageId={messageId}
onClick={() => history.push(`/${creator}/status/${hash}`)}
onClick={gotoPost}
clearObserver={props.clearObserver}
/>
</div>

View File

@@ -85,7 +85,11 @@ export const submitSemaphorePost = (post: Post) => async (dispatch: Dispatch, ge
return null;
}
const hash = post.hash();
const {
messageId,
hash,
...json
} = post.toJSON();
const signalStr = hash;
const externalNullifierStr = signalStr;
const externalNullifier = genExternalNullifier(externalNullifierStr);
@@ -118,27 +122,27 @@ export const submitSemaphorePost = (post: Post) => async (dispatch: Dispatch, ge
const proof = await genProof(witness, provingKey);
const publicSignals = genPublicSignals(witness, circuit);
const json = post.toJSON();
try {
// @ts-ignore
await fetch(`${config.indexerAPI}/dev/semaphore/post`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
post: json,
proof: JSON.stringify(snarkjs.stringifyBigInts(proof)),
publicSignals: JSON.stringify(snarkjs.stringifyBigInts(publicSignals)),
}),
});
const semaphorePost: any = {
...json,
proof: JSON.stringify(snarkjs.stringifyBigInts(proof)),
publicSignals: JSON.stringify(snarkjs.stringifyBigInts(publicSignals)),
};
// @ts-ignore
await gun.get('message')
.get(messageId)
// @ts-ignore
.put(semaphorePost);
dispatch({
type: ActionTypes.SET_SUBMITTING,
payload: false,
});
dispatch(setDraft(EditorState.createEmpty(), `${post.creator}/${hash}`));
dispatch(setDraft(EditorState.createEmpty(), post.payload.reference || ''));
} catch (e) {
dispatch({
type: ActionTypes.SET_SUBMITTING,

View File

@@ -88,23 +88,27 @@ export const fetchPost = (messageId: string) =>
const [username, hash] = messageId.split('/');
const user: any = await dispatch(getUser(username));
if (!hash) {
return null;
let message;
if (username && !hash) {
message = await fetchMessage(`message/${messageId}`);
} else if (username && hash) {
message = await fetchMessage(`~${user.pubkey}/message/${messageId}`);
}
const message = await fetchMessage(`~${user.pubkey}/message/${messageId}`);
if (!message) return null;
dispatch({
type: ActionTypes.SET_POST,
payload: new Post({
...message,
creator: username,
creator: hash ? username : '',
}),
});
return {
...message,
creator: username,
creator: hash ? username : '',
};
}
@@ -144,15 +148,15 @@ export const fetchPosts = (creator?: string, limit = 10, offset = 0) =>
},
});
if (!hash) {
dispatch({
type: ActionTypes.SET_POST,
payload: new Post({
...post,
createdAt: new Date(post.createdAt),
}),
});
}
// if (!hash) {
// dispatch({
// type: ActionTypes.SET_POST,
// payload: new Post({
// ...post,
// createdAt: new Date(post.createdAt),
// }),
// });
// }
}
return json.payload.map((post: any) => post.messageId);
@@ -239,15 +243,15 @@ export const fetchReplies = (reference: string, limit = 10, offset = 0) =>
},
});
if (!hash) {
dispatch({
type: ActionTypes.SET_POST,
payload: new Post({
...post,
createdAt: new Date(post.createdAt),
}),
});
}
// if (!hash) {
// dispatch({
// type: ActionTypes.SET_POST,
// payload: new Post({
// ...post,
// createdAt: new Date(post.createdAt),
// }),
// });
// }
}
return json.payload.map((post: any) => post.messageId);

View File

@@ -182,6 +182,11 @@ export const setNetwork = (network: string) => ({
payload: network,
});
export const setGunPublicKey = (publicKey: string) => ({
type: ActionTypes.SET_SOCIAL_KEY,
payload: publicKey,
});
export const setGunPrivateKey = (privateKey: string) => ({
type: ActionTypes.SET_GUN_PRIVATE_KEY,
payload: privateKey,
@@ -241,6 +246,17 @@ export const setWeb3 = (web3: Web3 | null, account: string) => async (
// @ts-ignore
web3.currentProvider.on('accountsChanged', async ([account]) => {
dispatch(setGunPublicKey(''));
dispatch(setGunPrivateKey(''));
dispatch(setSemaphoreID({
keypair: {
pubKey: '',
privKey: null,
},
identityNullifier: '',
identityTrapdoor: '',
commitment: '',
}));
dispatch(setWeb3Loading(true));
const gunUser = gun.user();
// @ts-ignore
@@ -249,6 +265,7 @@ export const setWeb3 = (web3: Web3 | null, account: string) => async (
}
dispatch(setAccount(account));
await dispatch(lookupENS());
dispatch(setWeb3Loading(false));
});

View File

@@ -6,7 +6,9 @@ let json: {
} = {};
try {
json = require('../../config.json');
json = require(process.env.NODE_ENV === 'development'
? '../../config.dev.json'
: '../../config.prod.json');
} catch (e) {}
const web3HttpProvider = json.web3HttpProvider || process.env.WEB3_HTTP_PROVIDER;

View File

@@ -1,4 +1,5 @@
import { genCircuit } from "libsemaphore";
import {local} from "web3modal";
let circuit: any, provingKey: Uint8Array;
@@ -7,6 +8,7 @@ export const getCircuit = async () => {
const response = await fetch('https://dl.dropboxusercontent.com/s/3gzxjibqgb6ke13/circuit.json?dl=1');
const result = await response.json()
circuit = genCircuit(result);
return circuit;
}
@@ -15,6 +17,7 @@ export const getProvingKey = async () => {
const response = await fetch('https://dl.dropboxusercontent.com/s/qjlu6v125g7jkcq/proving_key.bin?dl=1');
const result = await response.arrayBuffer()
provingKey = new Uint8Array(result);
return provingKey;
}

BIN
static/icons/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -7,7 +7,7 @@
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700&family=Roboto+Mono:wght@300;400;600;700&family=Inter:wght@300;400;600;700&display=swap" rel="stylesheet">
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
<link rel="icon" type="image/svg+xml" href="/favicon.png">
<title>0xSocial UI</title>
</head>
<body>

View File

@@ -1,5 +1,6 @@
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require("copy-webpack-plugin");
const path = require('path');
const isProd = process.env.NODE_ENV === 'production';
@@ -91,6 +92,12 @@ module.exports = [
},
plugins: [
envPlugin,
new CopyPlugin([
{
from: "./static/icons/favicon.png",
to: __dirname + '/build/favicon.png',
},
]),
new HtmlWebpackPlugin({
template: `./static/index.html`,
filename: `index.html`,