Skip to content

Commit 3790ecd

Browse files
author
Evgeny Kuzyakov
committed
Initial template based on wiki
0 parents  commit 3790ecd

19 files changed

+14009
-0
lines changed

.gitignore

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
#IDE
26+
.idea
27+
28+
target
29+
neardev
30+
31+
# OS X
32+
.DS_Store

LICENSE

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org>

package.json

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "frontend",
3+
"version": "0.1.0",
4+
"homepage": "/",
5+
"private": true,
6+
"dependencies": {
7+
"@testing-library/jest-dom": "^4.2.4",
8+
"@testing-library/react": "^9.3.2",
9+
"@testing-library/user-event": "^7.1.2",
10+
"big.js": "^6.1.1",
11+
"bn.js": "^5.1.1",
12+
"bootstrap": "^5.0.1",
13+
"bootstrap-icons": "^1.5.0",
14+
"chart.js": "^3.3.2",
15+
"chartjs-adapter-moment": "^1.0.0",
16+
"collections": "^5.1.12",
17+
"error-polyfill": "^0.1.2",
18+
"local-storage": "^2.0.0",
19+
"moment": "^2.29.1",
20+
"near-api-js": "^0.45.1",
21+
"node-sass": "^4.0.0",
22+
"react": "^16.13.1",
23+
"react-chartjs-2": "^3.0.3",
24+
"react-compound-timer": "^1.2.0",
25+
"react-datepicker": "^4.1.1",
26+
"react-diff-viewer": "^3.1.1",
27+
"react-dom": "^16.13.1",
28+
"react-infinite-scroller": "^1.2.4",
29+
"react-markdown": "^7.1.0",
30+
"react-markdown-editor-lite": "^1.3.1",
31+
"react-router-dom": "^5.2.0",
32+
"react-scripts": "3.4.0",
33+
"react-select": "^4.3.1",
34+
"react-singleton-hook": "^3.1.1",
35+
"react-tooltip": "^4.2.13",
36+
"react-uuid": "^1.0.2",
37+
"remark-gfm": "^3.0.1",
38+
"swr": "^0.5.6",
39+
"timeago-react": "^3.0.3"
40+
},
41+
"scripts": {
42+
"start": "react-scripts start",
43+
"build": "react-scripts build",
44+
"test": "react-scripts test",
45+
"eject": "react-scripts eject",
46+
"deploy": "yarn build"
47+
},
48+
"eslintConfig": {
49+
"extends": "react-app"
50+
},
51+
"browserslist": {
52+
"production": [
53+
">0.2%",
54+
"not dead",
55+
"not op_mini all"
56+
],
57+
"development": [
58+
"last 1 chrome version",
59+
"last 1 firefox version",
60+
"last 1 safari version"
61+
]
62+
},
63+
"devDependencies": {
64+
"prettier": "^2.2.1"
65+
}
66+
}

public/.nojekyll

Whitespace-only changes.

public/CNAME

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
viewer

public/_redirects

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* /index.html 200

public/favicon.png

306 KB
Loading

public/index.html

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.png" />
6+
7+
<meta name="viewport" content="width=device-width, initial-scale=1" />
8+
<meta name="theme-color" content="#123123" />
9+
<meta
10+
name="description"
11+
content="viewer"
12+
/>
13+
<meta name="twitter:card" content="summary" />
14+
<!-- <meta property="og:image" content="https://viewer.io/favicon.png">-->
15+
<meta property="og:type" content="website">
16+
<meta property="og:title" content="viewer" />
17+
<meta property="og:description" content="viewer" />
18+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/favicon.png" />
19+
<!--
20+
manifest.json provides metadata used when your web app is installed on a
21+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
22+
-->
23+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
24+
<!--
25+
Notice the use of %PUBLIC_URL% in the tags above.
26+
It will be replaced with the URL of the `public` folder during the build.
27+
Only files inside the `public` folder can be referenced from the HTML.
28+
29+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
30+
work correctly both with client-side routing and a non-root public URL.
31+
Learn how to configure a non-root public URL by running `npm run build`.
32+
-->
33+
<title>viewer</title>
34+
</head>
35+
<body>
36+
<noscript>You need to enable JavaScript to run this app.</noscript>
37+
<div id="root"></div>
38+
<!--
39+
This HTML file is a template.
40+
If you open it directly in the browser, you will see an empty page.
41+
42+
You can add webfonts, meta tags, or analytics to this file.
43+
The build step will place the bundled scripts into the <body> tag.
44+
45+
To begin the development, run `npm start` or `yarn start`.
46+
To create a production bundle, use `npm run build` or `yarn build`.
47+
-->
48+
</body>
49+
</html>

public/manifest.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "viewer",
3+
"name": "viewer",
4+
"icons": [
5+
{
6+
"src": "favicon.png",
7+
"sizes": "256x256",
8+
"type": "image/png"
9+
}
10+
],
11+
"start_url": ".",
12+
"display": "standalone",
13+
"theme_color": "#333333",
14+
"background_color": "#ffffff"
15+
}

public/robots.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:

src/App.js

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
import React, { useCallback, useEffect, useState } from "react";
2+
import "error-polyfill";
3+
import "bootstrap-icons/font/bootstrap-icons.css";
4+
import "bootstrap/dist/js/bootstrap.bundle";
5+
import "./App.scss";
6+
import { BrowserRouter as Router, Link, Route, Switch } from "react-router-dom";
7+
import { NearConfig, TGas, useNearPromise } from "./data/near";
8+
import MainPage from "./pages/MainPage";
9+
import { OneNear } from "./data/utils";
10+
import { useAccount } from "./data/account";
11+
12+
export const refreshAllowanceObj = {};
13+
14+
function App(props) {
15+
const [connected, setConnected] = useState(false);
16+
const [signedIn, setSignedIn] = useState(false);
17+
const [signedAccountId, setSignedAccountId] = useState(null);
18+
19+
const _near = useNearPromise();
20+
const account = useAccount();
21+
22+
const requestSignIn = useCallback(
23+
async (e) => {
24+
e && e.preventDefault();
25+
const appTitle = "viewer";
26+
const near = await _near;
27+
28+
await near.walletConnection.requestSignIn(
29+
NearConfig.contractName,
30+
appTitle
31+
);
32+
return false;
33+
},
34+
[_near]
35+
);
36+
37+
const logOut = useCallback(async () => {
38+
const near = await _near;
39+
near.walletConnection.signOut();
40+
near.accountId = null;
41+
setSignedIn(false);
42+
setSignedAccountId(null);
43+
}, [_near]);
44+
45+
const donate = async (e) => {
46+
e.preventDefault();
47+
await account.near.contract.donate(
48+
{},
49+
TGas.mul(10).toFixed(),
50+
OneNear.toFixed()
51+
);
52+
};
53+
54+
const refreshAllowance = useCallback(async () => {
55+
alert(
56+
"You're out of access key allowance. Need sign in again to refresh it"
57+
);
58+
await logOut();
59+
await requestSignIn();
60+
}, [logOut, requestSignIn]);
61+
refreshAllowanceObj.refreshAllowance = refreshAllowance;
62+
63+
useEffect(() => {
64+
_near.then((near) => {
65+
setSignedIn(!!near.accountId);
66+
setSignedAccountId(near.accountId);
67+
setConnected(true);
68+
});
69+
}, [_near]);
70+
71+
const passProps = {
72+
refreshAllowance: () => refreshAllowance(),
73+
signedAccountId,
74+
signedIn,
75+
connected,
76+
};
77+
78+
const header = !connected ? (
79+
<div>
80+
Connecting...{" "}
81+
<span
82+
className="spinner-grow spinner-grow-sm"
83+
role="status"
84+
aria-hidden="true"
85+
/>
86+
</div>
87+
) : signedIn ? (
88+
<div>
89+
<button className="btn btn-outline-light me-2" onClick={donate}>
90+
Donate 1 NEAR for storage
91+
</button>
92+
93+
<button className="btn btn-outline-light" onClick={() => logOut()}>
94+
Sign out {signedAccountId}
95+
</button>
96+
</div>
97+
) : (
98+
<div>
99+
<button
100+
className="btn btn-outline-light"
101+
onClick={(e) => requestSignIn(e)}
102+
>
103+
Sign in with NEAR Wallet
104+
</button>
105+
</div>
106+
);
107+
108+
return (
109+
<div className="App">
110+
<Router basename={process.env.PUBLIC_URL}>
111+
<nav className="navbar navbar-expand-lg navbar-dark bg-primary mb-3">
112+
<div className="container-fluid">
113+
<a className="navbar-brand" href="/" title="viewer">
114+
<img
115+
src="/favicon.png"
116+
alt="viewer logo"
117+
height="24"
118+
className="d-inline-block align-text-top me-2"
119+
/>
120+
viewer
121+
</a>
122+
<button
123+
className="navbar-toggler"
124+
type="button"
125+
data-bs-toggle="collapse"
126+
data-bs-target="#navbarSupportedContent"
127+
aria-controls="navbarSupportedContent"
128+
aria-expanded="false"
129+
aria-label="Toggle navigation"
130+
>
131+
<span className="navbar-toggler-icon" />
132+
</button>
133+
<div
134+
className="collapse navbar-collapse"
135+
id="navbarSupportedContent"
136+
>
137+
<ul className="navbar-nav me-auto mb-2 mb-lg-0">
138+
<li className="nav-item">
139+
<Link className="nav-link" aria-current="page" to="/">
140+
Main
141+
</Link>
142+
</li>
143+
</ul>
144+
<form className="d-flex">{header}</form>
145+
</div>
146+
</div>
147+
</nav>
148+
149+
<Switch>
150+
<Route exact path={"/"}>
151+
<MainPage {...passProps} />
152+
</Route>
153+
</Switch>
154+
</Router>
155+
</div>
156+
);
157+
}
158+
159+
export default App;

src/App.scss

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
$primary: #333;
2+
3+
@import "node_modules/bootstrap/scss/bootstrap";
4+
5+
body, html {
6+
background: #fbfbfb;
7+
-webkit-font-smoothing: antialiased;
8+
}
9+
10+
.pointer {
11+
cursor: pointer;
12+
}
13+
14+
.flex-buttons {
15+
display: flex;
16+
flex-flow: row wrap;
17+
18+
.btn {
19+
flex: 1 1;
20+
}
21+
}
22+
23+
.btn-success {
24+
.text-secondary {
25+
color: #fff !important;
26+
};
27+
}

0 commit comments

Comments
 (0)