Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Vaibhav Saini <[email protected]>
  • Loading branch information
vasa-develop committed May 11, 2020
1 parent 8edb3eb commit 05a5cad
Show file tree
Hide file tree
Showing 22 changed files with 19,811 additions and 23 deletions.
19,308 changes: 19,308 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"bnc-onboard": "^1.8.0",
"orbit-db-access-controllers": "^0.2.4",
"orbit-db-io": "^0.2.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
"react-github-btn": "^1.2.0",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.1",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"web3": "^1.2.7"
},
"scripts": {
"start": "react-scripts start",
Expand Down
22 changes: 19 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,34 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="icon" href="%PUBLIC_URL%/logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo.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="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous"
/>

<!-- Optional theme -->
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous"
/>
<script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"></script>
<script src="https://unpkg.com/aviondb/dist/aviondb.min.js"></script>
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
Expand All @@ -24,7 +40,7 @@
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>
<title>Blocknative Auth with AvionDB</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
Binary file added public/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/logo192.png
Binary file not shown.
Binary file removed public/logo512.png
Binary file not shown.
97 changes: 97 additions & 0 deletions src/AccessController/BlocknativeAccessController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"use strict";

const EventEmitter = require("events").EventEmitter;
const io = require("orbit-db-io");
/**
* Interface for OrbitDB Access Controllers
*
* Any OrbitDB access controller needs to define and implement
* the methods defined by the interface here.
*/
class BlocknativeAccessController extends EventEmitter {
constructor(ipfs, options) {
super();
this.onboard = options.onboard;
this._ipfs = ipfs;
}

/*
Every AC needs to have a 'Factory' method
that creates an instance of the AccessController
*/
static async create(orbitdb, options) {
if (!options.onboard) {
throw new Error("you need to pass a onboard Object");
}
return new BlocknativeAccessController(orbitdb._ipfs, options);
}

/* Return the type for this controller */
static get type() {
return "blocknative-access-controller";
}

/*
Return the type for this controller
NOTE! This is the only property of the interface that
shouldn't be overridden in the inherited Access Controller
*/
get type() {
return this.constructor.type;
}

/* Each Access Controller has some address to anchor to */
//get address() {}

/*
Called by the databases (the log) to see if entry should
be allowed in the database. Return true if the entry is allowed,
false is not allowed
*/
async canAppend(entry, identityProvider) {
if (this.onboard.getState().address) {
const verifiedIdentity = await identityProvider.verifyIdentity(
entry.identity
);
// Allow access if identity verifies
return Promise.resolve(verifiedIdentity);
} else {
// No user is signed in.
return Promise.resolve(false);
}
}

/* Add and remove access */
async grant(access, identity) {}
async revoke(access, identity) {}

/* AC creation and loading */
async load(address) {
if (address) {
try {
if (address.indexOf("/ipfs") === 0) {
address = address.split("/")[2];
}
// const access = await io.read(this._ipfs, address);
// this.firebaseConfig = access.firebaseConfig;
} catch (e) {
console.log("BlocknativeAccessController.load ERROR:", e);
}
}
}
/* Returns AC manifest parameters object */
async save() {
let cid;
try {
cid = await io.write(this._ipfs, "dag-cbor", {});
} catch (e) {
console.log("BlocknativeAccessController.save ERROR:", e);
}
// return the manifest data
return { address: cid };
}
/* Called when the database for this AC gets closed */
//async close() {}
}

export default BlocknativeAccessController;
47 changes: 28 additions & 19 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
import React from "react";
import "./App.css";
import { Provider } from "react-redux";
import Store from "./redux/store";
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
import TodoList from "./components/TodoList";
import Login from "./components/Login";
import Footer from "./components/Footer";

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
<center>
<Provider store={Store}>
<Router>
<Switch>
<Route path="/login">
<Login />
</Route>
<Route path="/todolist">
<TodoList />
</Route>
<Route path="">
<Login />
</Route>
</Switch>
</Router>
<div style={{ position: "absolute", bottom: "30px", width: "100%" }}>
<Footer />
</div>
</Provider>
</center>
);
}

Expand Down
Binary file added src/assets/aviondb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/blocknative.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/components/Footer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from "react";
import Blocknative from "../../assets/blocknative.png";
import AvionDB from "../../assets/aviondb.png";
import GitHubButton from "react-github-btn";
//require("react-github-button/assets/style.css");

export default function Footer() {
return (
<div>
<h3>Built Using</h3>
<img src={Blocknative} width="100" />
<img src={AvionDB} width="100" />
<br />
<br />
<GitHubButton
href="https://github.com/dappkit/aviondb"
data-size="large"
data-show-count="true"
aria-label="Star dappkit/aviondb on GitHub"
>
Star
</GitHubButton>
</div>
);
}
40 changes: 40 additions & 0 deletions src/components/Login/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { Fragment } from "react";
import { connect } from "react-redux";
import { login } from "../../redux/actions/login";
import { useHistory } from "react-router-dom";
import { onboard } from "../../utils";

function Login(props) {
const { user, login } = props;
const history = useHistory();

if (user.address) {
history.push("/todolist");
} else {
startLogin(login);
}

return (
<Fragment>
<center>
<h1>Login</h1>
</center>
</Fragment>
);
}

const startLogin = async (login) => {
await onboard.walletSelect();
await onboard.walletCheck();
login({ ...onboard.getState() });
};

const mapStateToProps = (state) => ({
user: state.app.user,
});

const mapDispatchToProps = (dispatch) => ({
login: (payload) => dispatch(login(payload)),
});

export default connect(mapStateToProps, mapDispatchToProps)(Login);
82 changes: 82 additions & 0 deletions src/components/TodoList/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { Fragment } from "react";
import {
addTodoItem,
getTodoList,
updateTodoItem,
} from "../../redux/actions/todolist";
import { connect } from "react-redux";
import { useHistory } from "react-router-dom";
import TodoItem from "./todoItem";

function TodoList(props) {
const {
addTodoItem,
getTodoList,
updateTodoItem,
user,
todoList,
loaded,
} = props;
const history = useHistory();

if (!user.address) {
history.push("/login");
}

if (!loaded) {
getTodoList();
}
return (
<Fragment>
<center>
<div className="form-inline" style={{ marginTop: "2rem" }}>
<div className="form-group mx-sm-3 mb-2">
<input
type="text"
className="form-control"
id="todo"
placeholder="Enter Todo"
/>
<br />
<br />
<button
className="btn btn-primary mb-2"
onClick={() => {
addTodoItem({
id: Math.random().toString().substr(2, 4),
todo: document.getElementById("todo").value,
isDone: false,
});
document.getElementById("todo").value = "";
}}
>
Add Todo
</button>
</div>
</div>
<br />
<br />
<br />
<div className="card" style={{ width: "18rem" }}>
<ul className="list-group list-group-flush">
<TodoItem todos={todoList} updateTodoItem={updateTodoItem} />
</ul>
</div>
</center>
</Fragment>
);
}

const mapStateToProps = (state) => ({
user: state.app.user,
todoList: state.app.todoList,
loaded: state.app.loaded,
});

const mapDispatchToProps = (dispatch) => ({
addTodoItem: (payload) => dispatch(addTodoItem(payload)),
updateTodoItem: (payload) => dispatch(updateTodoItem(payload)),
getTodoList: () => dispatch(getTodoList()),
});

export default connect(mapStateToProps, mapDispatchToProps)(TodoList);
27 changes: 27 additions & 0 deletions src/components/TodoList/todoItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";

export default function todoItem(props) {
const { todos, updateTodoItem } = props;

return todos.map((todo) => {
return (
<li
key={todo.id}
className="list-group-item"
onClick={() => {
updateTodoItem({
id: todo.id,
isDone: document.getElementById(todo.id).checked,
});
}}
>
{todo.isDone ? (
<input type="checkbox" id={todo.id} checked />
) : (
<input type="checkbox" id={todo.id} />
)}
<label htmlFor={todo.id}>{todo.todo}</label>
</li>
);
});
}
Loading

0 comments on commit 05a5cad

Please sign in to comment.