-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
License: MIT Signed-off-by: Vaibhav Saini <[email protected]>
- Loading branch information
1 parent
8edb3eb
commit 05a5cad
Showing
22 changed files
with
19,811 additions
and
23 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}); | ||
} |
Oops, something went wrong.