Skip to content

Commit

Permalink
Initial template based on wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Kuzyakov committed Aug 23, 2022
0 parents commit 3790ecd
Show file tree
Hide file tree
Showing 19 changed files with 14,009 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

#IDE
.idea

target
neardev

# OS X
.DS_Store
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>
66 changes: 66 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "frontend",
"version": "0.1.0",
"homepage": "/",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"big.js": "^6.1.1",
"bn.js": "^5.1.1",
"bootstrap": "^5.0.1",
"bootstrap-icons": "^1.5.0",
"chart.js": "^3.3.2",
"chartjs-adapter-moment": "^1.0.0",
"collections": "^5.1.12",
"error-polyfill": "^0.1.2",
"local-storage": "^2.0.0",
"moment": "^2.29.1",
"near-api-js": "^0.45.1",
"node-sass": "^4.0.0",
"react": "^16.13.1",
"react-chartjs-2": "^3.0.3",
"react-compound-timer": "^1.2.0",
"react-datepicker": "^4.1.1",
"react-diff-viewer": "^3.1.1",
"react-dom": "^16.13.1",
"react-infinite-scroller": "^1.2.4",
"react-markdown": "^7.1.0",
"react-markdown-editor-lite": "^1.3.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.0",
"react-select": "^4.3.1",
"react-singleton-hook": "^3.1.1",
"react-tooltip": "^4.2.13",
"react-uuid": "^1.0.2",
"remark-gfm": "^3.0.1",
"swr": "^0.5.6",
"timeago-react": "^3.0.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"deploy": "yarn build"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"prettier": "^2.2.1"
}
}
Empty file added public/.nojekyll
Empty file.
1 change: 1 addition & 0 deletions public/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
viewer
1 change: 1 addition & 0 deletions public/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* /index.html 200
Binary file added public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.png" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#123123" />
<meta
name="description"
content="viewer"
/>
<meta name="twitter:card" content="summary" />
<!-- <meta property="og:image" content="https://viewer.io/favicon.png">-->
<meta property="og:type" content="website">
<meta property="og:title" content="viewer" />
<meta property="og:description" content="viewer" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/favicon.png" />
<!--
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/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
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>viewer</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>
</html>
15 changes: 15 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "viewer",
"name": "viewer",
"icons": [
{
"src": "favicon.png",
"sizes": "256x256",
"type": "image/png"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#333333",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
159 changes: 159 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import React, { useCallback, useEffect, useState } from "react";
import "error-polyfill";
import "bootstrap-icons/font/bootstrap-icons.css";
import "bootstrap/dist/js/bootstrap.bundle";
import "./App.scss";
import { BrowserRouter as Router, Link, Route, Switch } from "react-router-dom";
import { NearConfig, TGas, useNearPromise } from "./data/near";
import MainPage from "./pages/MainPage";
import { OneNear } from "./data/utils";
import { useAccount } from "./data/account";

export const refreshAllowanceObj = {};

function App(props) {
const [connected, setConnected] = useState(false);
const [signedIn, setSignedIn] = useState(false);
const [signedAccountId, setSignedAccountId] = useState(null);

const _near = useNearPromise();
const account = useAccount();

const requestSignIn = useCallback(
async (e) => {
e && e.preventDefault();
const appTitle = "viewer";
const near = await _near;

await near.walletConnection.requestSignIn(
NearConfig.contractName,
appTitle
);
return false;
},
[_near]
);

const logOut = useCallback(async () => {
const near = await _near;
near.walletConnection.signOut();
near.accountId = null;
setSignedIn(false);
setSignedAccountId(null);
}, [_near]);

const donate = async (e) => {
e.preventDefault();
await account.near.contract.donate(
{},
TGas.mul(10).toFixed(),
OneNear.toFixed()
);
};

const refreshAllowance = useCallback(async () => {
alert(
"You're out of access key allowance. Need sign in again to refresh it"
);
await logOut();
await requestSignIn();
}, [logOut, requestSignIn]);
refreshAllowanceObj.refreshAllowance = refreshAllowance;

useEffect(() => {
_near.then((near) => {
setSignedIn(!!near.accountId);
setSignedAccountId(near.accountId);
setConnected(true);
});
}, [_near]);

const passProps = {
refreshAllowance: () => refreshAllowance(),
signedAccountId,
signedIn,
connected,
};

const header = !connected ? (
<div>
Connecting...{" "}
<span
className="spinner-grow spinner-grow-sm"
role="status"
aria-hidden="true"
/>
</div>
) : signedIn ? (
<div>
<button className="btn btn-outline-light me-2" onClick={donate}>
Donate 1 NEAR for storage
</button>

<button className="btn btn-outline-light" onClick={() => logOut()}>
Sign out {signedAccountId}
</button>
</div>
) : (
<div>
<button
className="btn btn-outline-light"
onClick={(e) => requestSignIn(e)}
>
Sign in with NEAR Wallet
</button>
</div>
);

return (
<div className="App">
<Router basename={process.env.PUBLIC_URL}>
<nav className="navbar navbar-expand-lg navbar-dark bg-primary mb-3">
<div className="container-fluid">
<a className="navbar-brand" href="/" title="viewer">
<img
src="/favicon.png"
alt="viewer logo"
height="24"
className="d-inline-block align-text-top me-2"
/>
viewer
</a>
<button
className="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span className="navbar-toggler-icon" />
</button>
<div
className="collapse navbar-collapse"
id="navbarSupportedContent"
>
<ul className="navbar-nav me-auto mb-2 mb-lg-0">
<li className="nav-item">
<Link className="nav-link" aria-current="page" to="/">
Main
</Link>
</li>
</ul>
<form className="d-flex">{header}</form>
</div>
</div>
</nav>

<Switch>
<Route exact path={"/"}>
<MainPage {...passProps} />
</Route>
</Switch>
</Router>
</div>
);
}

export default App;
27 changes: 27 additions & 0 deletions src/App.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$primary: #333;

@import "node_modules/bootstrap/scss/bootstrap";

body, html {
background: #fbfbfb;
-webkit-font-smoothing: antialiased;
}

.pointer {
cursor: pointer;
}

.flex-buttons {
display: flex;
flex-flow: row wrap;

.btn {
flex: 1 1;
}
}

.btn-success {
.text-secondary {
color: #fff !important;
};
}
Loading

0 comments on commit 3790ecd

Please sign in to comment.