├── .gitignore
├── LICENSE
├── README.md
├── assets
├── aviondb-authereum.gif
├── aviondb-blocknative.gif
├── aviondb-dapper.gif
├── aviondb-fortmatic.gif
├── aviondb-portis.gif
├── aviondb-squarelink.gif
├── aviondb-torus.gif
├── aviondb-trust.gif
└── aviondb-walletconnect.gif
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── index.html
├── logo.png
├── manifest.json
└── robots.txt
├── src
├── AccessController
│ └── BlocknativeAccessController.js
├── App.css
├── App.js
├── App.test.js
├── assets
│ ├── aviondb.png
│ └── blocknative.png
├── components
│ ├── Footer
│ │ └── index.js
│ ├── Login
│ │ └── index.js
│ └── TodoList
│ │ ├── index.js
│ │ └── todoItem.js
├── index.css
├── index.js
├── logo.svg
├── redux
│ ├── actions
│ │ ├── login.js
│ │ ├── signup.js
│ │ └── todolist.js
│ ├── constants.js
│ ├── reducers
│ │ ├── app.js
│ │ └── index.js
│ └── store
│ │ └── index.js
├── serviceWorker.js
├── setupTests.js
└── utils
│ └── index.js
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2 | Version 2, December 2004
3 |
4 | Copyright (C) 2020 Dappkit
5 |
6 | Everyone is permitted to copy and distribute verbatim or modified
7 | copies of this license document, and changing it is allowed as long
8 | as the name is changed.
9 |
10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12 |
13 | 0. You just DO WHAT THE FUCK YOU WANT TO.
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## aviondb-onboard-js
2 |
3 | > A Blocknaive's OnBoard.js Auth based Access Controller for AvionDB & OrbitDB
4 |
5 | This allows you to integrate [AvionDB](https://github.com/dappkit/aviondb) with [@metamask_io](https://twitter.com/metamask_io), [@TorusLabs](https://twitter.com/TorusLabs), [@authereum](https://twitter.com/authereum), [@dapper_labs](https://twitter.com/dapper_labs), [@coinbase](https://twitter.com/coinbase), [@TrustWalletApp](https://twitter.com/TrustWalletApp), [@Trezor](https://twitter.com/Trezor), [@Ledger](https://twitter.com/Ledger), [@fortmatic](https://twitter.com/fortmatic), [@portis_io](https://twitter.com/portis_io), [@Squarelink_Inc](https://twitter.com/Squarelink_Inc), [@WalletConnect](https://twitter.com/WalletConnect), [@opera](https://twitter.com/opera), [@ethstatus](https://twitter.com/ethstatus), [@unilogin](https://twitter.com/unilogin), [@imTokenOfficial](https://twitter.com/imTokenOfficial)
6 |
7 | Checkout [AvionDB here](https://github.com/dappkit/aviondb).
8 |
9 | ### Demo
10 |
11 | #### Metamask Auth
12 |
13 | 
14 |
15 | #### Authereum Auth
16 |
17 | 
18 |
19 | #### Dapper Auth
20 |
21 | 
22 |
23 | #### Fortmatic Auth
24 |
25 | 
26 |
27 | #### Portis Auth
28 |
29 | 
30 |
31 | #### SquareLink Auth
32 |
33 | 
34 |
35 | #### Tor.us Auth
36 |
37 | 
38 |
39 | #### TrustWallet Auth
40 |
41 | 
42 |
43 | #### Wallet Connect Auth
44 |
45 | 
46 |
47 | You can find other demos in the [assets folder](./assets)
48 |
49 | ### Try it out
50 |
51 | Check out the [Todolist in Action](https://bit.ly/aviondb-blocknative).
52 |
53 | ### Requirements
54 |
55 | The minimum required version of Node.js is now 8.6.0 due to the usage of `...` spread syntax. LTS versions (even numbered versions 8, 10, etc) are preferred.
56 |
57 | ### How to Use?
58 |
59 | Run the following command to install dependencies & Open the console to see logs
60 |
61 | ```
62 | npm i
63 | npm start
64 | ```
65 |
66 | ### How it Works?
67 |
68 | TODO: Add How it Works
69 |
--------------------------------------------------------------------------------
/assets/aviondb-authereum.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/assets/aviondb-authereum.gif
--------------------------------------------------------------------------------
/assets/aviondb-blocknative.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/assets/aviondb-blocknative.gif
--------------------------------------------------------------------------------
/assets/aviondb-dapper.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/assets/aviondb-dapper.gif
--------------------------------------------------------------------------------
/assets/aviondb-fortmatic.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/assets/aviondb-fortmatic.gif
--------------------------------------------------------------------------------
/assets/aviondb-portis.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/assets/aviondb-portis.gif
--------------------------------------------------------------------------------
/assets/aviondb-squarelink.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/assets/aviondb-squarelink.gif
--------------------------------------------------------------------------------
/assets/aviondb-torus.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/assets/aviondb-torus.gif
--------------------------------------------------------------------------------
/assets/aviondb-trust.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/assets/aviondb-trust.gif
--------------------------------------------------------------------------------
/assets/aviondb-walletconnect.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/assets/aviondb-walletconnect.gif
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "aviondb-onboardjs",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^4.2.4",
7 | "@testing-library/react": "^9.3.2",
8 | "@testing-library/user-event": "^7.1.2",
9 | "aviondb": "^0.2.3-rc.12",
10 | "bnc-onboard": "^1.8.0",
11 | "orbit-db-access-controllers": "^0.2.4",
12 | "orbit-db-io": "^0.2.0",
13 | "react": "^16.13.1",
14 | "react-dom": "^16.13.1",
15 | "react-github-btn": "^1.2.0",
16 | "react-redux": "^7.2.0",
17 | "react-router-dom": "^5.1.2",
18 | "react-scripts": "3.4.1",
19 | "redux": "^4.0.5",
20 | "redux-thunk": "^2.3.0",
21 | "web3": "^1.2.7"
22 | },
23 | "scripts": {
24 | "start": "react-scripts start",
25 | "build": "react-scripts build",
26 | "test": "react-scripts test",
27 | "eject": "react-scripts eject"
28 | },
29 | "eslintConfig": {
30 | "extends": "react-app"
31 | },
32 | "browserslist": {
33 | "production": [
34 | ">0.2%",
35 | "not dead",
36 | "not op_mini all"
37 | ],
38 | "development": [
39 | "last 1 chrome version",
40 | "last 1 firefox version",
41 | "last 1 safari version"
42 | ]
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
23 |
24 |
25 |
31 |
32 |
33 |
34 |
43 | Blocknative Auth with AvionDB
44 |
45 |
46 |
47 |
48 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/public/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/public/logo.png
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/src/AccessController/BlocknativeAccessController.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | const EventEmitter = require("events").EventEmitter;
4 | const io = require("orbit-db-io");
5 | /**
6 | * Interface for OrbitDB Access Controllers
7 | *
8 | * Any OrbitDB access controller needs to define and implement
9 | * the methods defined by the interface here.
10 | */
11 | class BlocknativeAccessController extends EventEmitter {
12 | constructor(ipfs, options) {
13 | super();
14 | this.onboard = options.onboard;
15 | this._ipfs = ipfs;
16 | }
17 |
18 | /*
19 | Every AC needs to have a 'Factory' method
20 | that creates an instance of the AccessController
21 | */
22 | static async create(orbitdb, options) {
23 | if (!options.onboard) {
24 | throw new Error("you need to pass a onboard Object");
25 | }
26 | return new BlocknativeAccessController(orbitdb._ipfs, options);
27 | }
28 |
29 | /* Return the type for this controller */
30 | static get type() {
31 | return "blocknative-access-controller";
32 | }
33 |
34 | /*
35 | Return the type for this controller
36 | NOTE! This is the only property of the interface that
37 | shouldn't be overridden in the inherited Access Controller
38 | */
39 | get type() {
40 | return this.constructor.type;
41 | }
42 |
43 | /* Each Access Controller has some address to anchor to */
44 | //get address() {}
45 |
46 | /*
47 | Called by the databases (the log) to see if entry should
48 | be allowed in the database. Return true if the entry is allowed,
49 | false is not allowed
50 | */
51 | async canAppend(entry, identityProvider) {
52 | if (this.onboard.getState().address) {
53 | const verifiedIdentity = await identityProvider.verifyIdentity(
54 | entry.identity
55 | );
56 | // Allow access if identity verifies
57 | return Promise.resolve(verifiedIdentity);
58 | } else {
59 | // No user is signed in.
60 | return Promise.resolve(false);
61 | }
62 | }
63 |
64 | /* Add and remove access */
65 | async grant(access, identity) {}
66 | async revoke(access, identity) {}
67 |
68 | /* AC creation and loading */
69 | async load(address) {
70 | if (address) {
71 | try {
72 | if (address.indexOf("/ipfs") === 0) {
73 | address = address.split("/")[2];
74 | }
75 | // const access = await io.read(this._ipfs, address);
76 | // this.firebaseConfig = access.firebaseConfig;
77 | } catch (e) {
78 | console.log("BlocknativeAccessController.load ERROR:", e);
79 | }
80 | }
81 | }
82 | /* Returns AC manifest parameters object */
83 | async save() {
84 | let cid;
85 | try {
86 | cid = await io.write(this._ipfs, "dag-cbor", {});
87 | } catch (e) {
88 | console.log("BlocknativeAccessController.save ERROR:", e);
89 | }
90 | // return the manifest data
91 | return { address: cid };
92 | }
93 | /* Called when the database for this AC gets closed */
94 | //async close() {}
95 | }
96 |
97 | export default BlocknativeAccessController;
98 |
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | }
4 |
5 | .App-logo {
6 | height: 40vmin;
7 | pointer-events: none;
8 | }
9 |
10 | @media (prefers-reduced-motion: no-preference) {
11 | .App-logo {
12 | animation: App-logo-spin infinite 20s linear;
13 | }
14 | }
15 |
16 | .App-header {
17 | background-color: #282c34;
18 | min-height: 100vh;
19 | display: flex;
20 | flex-direction: column;
21 | align-items: center;
22 | justify-content: center;
23 | font-size: calc(10px + 2vmin);
24 | color: white;
25 | }
26 |
27 | .App-link {
28 | color: #61dafb;
29 | }
30 |
31 | @keyframes App-logo-spin {
32 | from {
33 | transform: rotate(0deg);
34 | }
35 | to {
36 | transform: rotate(360deg);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import "./App.css";
3 | import { Provider } from "react-redux";
4 | import Store from "./redux/store";
5 | import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
6 | import TodoList from "./components/TodoList";
7 | import Login from "./components/Login";
8 | import Footer from "./components/Footer";
9 |
10 | function App() {
11 | return (
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | );
33 | }
34 |
35 | export default App;
36 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { render } from '@testing-library/react';
3 | import App from './App';
4 |
5 | test('renders learn react link', () => {
6 | const { getByText } = render();
7 | const linkElement = getByText(/learn react/i);
8 | expect(linkElement).toBeInTheDocument();
9 | });
10 |
--------------------------------------------------------------------------------
/src/assets/aviondb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/src/assets/aviondb.png
--------------------------------------------------------------------------------
/src/assets/blocknative.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aviondb/aviondb-onboard/413ecc39c0d3f82bef117638acc00e85344e5383/src/assets/blocknative.png
--------------------------------------------------------------------------------
/src/components/Footer/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import Blocknative from "../../assets/blocknative.png";
3 | import AvionDB from "../../assets/aviondb.png";
4 | import GitHubButton from "react-github-btn";
5 | //require("react-github-button/assets/style.css");
6 |
7 | export default function Footer() {
8 | return (
9 |
10 |
Built Using
11 |

12 |

13 |
14 |
15 |
21 | Star
22 |
23 |
24 | );
25 | }
26 |
--------------------------------------------------------------------------------
/src/components/Login/index.js:
--------------------------------------------------------------------------------
1 | import React, { Fragment } from "react";
2 | import { connect } from "react-redux";
3 | import { login } from "../../redux/actions/login";
4 | import { useHistory } from "react-router-dom";
5 | import { onboard } from "../../utils";
6 |
7 | function Login(props) {
8 | const { user, login } = props;
9 | const history = useHistory();
10 |
11 | if (user.address) {
12 | history.push("/todolist");
13 | } else {
14 | startLogin(login);
15 | }
16 |
17 | return (
18 |
19 |
20 | Login
21 |
22 |
23 | );
24 | }
25 |
26 | const startLogin = async (login) => {
27 | await onboard.walletSelect();
28 | await onboard.walletCheck();
29 | login({ ...onboard.getState() });
30 | };
31 |
32 | const mapStateToProps = (state) => ({
33 | user: state.app.user,
34 | });
35 |
36 | const mapDispatchToProps = (dispatch) => ({
37 | login: (payload) => dispatch(login(payload)),
38 | });
39 |
40 | export default connect(mapStateToProps, mapDispatchToProps)(Login);
41 |
--------------------------------------------------------------------------------
/src/components/TodoList/index.js:
--------------------------------------------------------------------------------
1 | import React, { Fragment } from "react";
2 | import {
3 | addTodoItem,
4 | getTodoList,
5 | updateTodoItem,
6 | } from "../../redux/actions/todolist";
7 | import { connect } from "react-redux";
8 | import { useHistory } from "react-router-dom";
9 | import TodoItem from "./todoItem";
10 |
11 | function TodoList(props) {
12 | const {
13 | addTodoItem,
14 | getTodoList,
15 | updateTodoItem,
16 | user,
17 | todoList,
18 | loaded,
19 | } = props;
20 | const history = useHistory();
21 |
22 | if (!user.address) {
23 | history.push("/login");
24 | }
25 |
26 | if (!loaded) {
27 | getTodoList();
28 | }
29 | return (
30 |
31 |
32 |
33 |
34 |
40 |
41 |
42 |
55 |
56 |
57 |
58 |
59 |
60 |
65 |
66 |
67 | );
68 | }
69 |
70 | const mapStateToProps = (state) => ({
71 | user: state.app.user,
72 | todoList: state.app.todoList,
73 | loaded: state.app.loaded,
74 | });
75 |
76 | const mapDispatchToProps = (dispatch) => ({
77 | addTodoItem: (payload) => dispatch(addTodoItem(payload)),
78 | updateTodoItem: (payload) => dispatch(updateTodoItem(payload)),
79 | getTodoList: () => dispatch(getTodoList()),
80 | });
81 |
82 | export default connect(mapStateToProps, mapDispatchToProps)(TodoList);
83 |
--------------------------------------------------------------------------------
/src/components/TodoList/todoItem.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | export default function todoItem(props) {
4 | const { todos, updateTodoItem } = props;
5 |
6 | return todos.map((todo) => {
7 | return (
8 | {
12 | updateTodoItem({
13 | id: todo.id,
14 | isDone: document.getElementById(todo.id).checked,
15 | });
16 | }}
17 | >
18 | {todo.isDone ? (
19 |
20 | ) : (
21 |
22 | )}
23 |
24 |
25 | );
26 | });
27 | }
28 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12 | monospace;
13 | }
14 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 |
7 | ReactDOM.render(
8 |
9 |
10 | ,
11 | document.getElementById('root')
12 | );
13 |
14 | // If you want your app to work offline and load faster, you can change
15 | // unregister() to register() below. Note this comes with some pitfalls.
16 | // Learn more about service workers: https://bit.ly/CRA-PWA
17 | serviceWorker.unregister();
18 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/src/redux/actions/login.js:
--------------------------------------------------------------------------------
1 | import types from "../constants";
2 | //import { firebase } from "../../utils";
3 |
4 | export const login = (payload) => (dispatch) => {
5 | dispatch({
6 | type: types.LOGIN,
7 | payload: payload,
8 | });
9 | };
10 |
--------------------------------------------------------------------------------
/src/redux/actions/signup.js:
--------------------------------------------------------------------------------
1 | import types from "../constants";
2 | //import { firebase } from "../../utils";
3 |
4 | export const signup = (payload) => (dispatch) => {
5 | const { email, password } = payload;
6 | /* firebase
7 | .auth()
8 | .createUserWithEmailAndPassword(email, password)
9 | .then((data) => {
10 | dispatch({
11 | type: types.SIGNUP,
12 | payload: {
13 | email: data.user.email,
14 | uid: data.user.uid,
15 | },
16 | });
17 | })
18 | .catch(function (error) {
19 | // Handle Errors here.
20 | console.error(error);
21 | alert(error.message);
22 | }); */
23 | };
24 |
--------------------------------------------------------------------------------
/src/redux/actions/todolist.js:
--------------------------------------------------------------------------------
1 | import types from "../constants";
2 | import { getAvionDBCollection } from "../../utils";
3 |
4 | export const addTodoItem = (payload) => async (dispatch) => {
5 | const collection = await getAvionDBCollection();
6 | await collection.insert([payload]);
7 | dispatch({
8 | type: types.ADD_TODO,
9 | payload: payload,
10 | });
11 | };
12 |
13 | export const getTodoList = () => async (dispatch) => {
14 | const collection = await getAvionDBCollection();
15 | const todos = await collection.find({});
16 | dispatch({
17 | type: types.GET_TODOS,
18 | payload: todos,
19 | });
20 | };
21 |
22 | export const updateTodoItem = (payload) => async (dispatch) => {
23 | const collection = await getAvionDBCollection();
24 | await collection.findOneAndUpdate(
25 | {
26 | id: payload.id,
27 | },
28 | {
29 | $set: { isDone: payload.isDone },
30 | }
31 | );
32 | const todos = await collection.find({});
33 | dispatch({
34 | type: types.UPDATE_TODOS,
35 | payload: todos,
36 | });
37 | };
38 |
--------------------------------------------------------------------------------
/src/redux/constants.js:
--------------------------------------------------------------------------------
1 | export default {
2 | LOGIN: "LOGIN",
3 | ADD_TODO: "ADD_TODO",
4 | GET_TODOS: "GET_TODOS",
5 | UPDATE_TODOS: "UPDATE_TODOS",
6 | };
7 |
--------------------------------------------------------------------------------
/src/redux/reducers/app.js:
--------------------------------------------------------------------------------
1 | import types from "../constants";
2 |
3 | const initialState = {
4 | user: {},
5 | todoList: [],
6 | loaded: false,
7 | };
8 |
9 | export default (state = initialState, action) => {
10 | switch (action.type) {
11 | case types.LOGIN:
12 | return { ...state, user: action.payload };
13 | case types.ADD_TODO:
14 | return { ...state, todoList: [...state.todoList, action.payload] };
15 | case types.GET_TODOS:
16 | return {
17 | ...state,
18 | todoList: [...state.todoList, ...action.payload],
19 | loaded: true,
20 | };
21 | case types.UPDATE_TODOS:
22 | return {
23 | ...state,
24 | todoList: action.payload,
25 | };
26 | default:
27 | return state;
28 | }
29 | };
30 |
--------------------------------------------------------------------------------
/src/redux/reducers/index.js:
--------------------------------------------------------------------------------
1 | import { combineReducers } from "redux";
2 | import app from "./app";
3 |
4 | export default combineReducers({
5 | app: app,
6 | });
7 |
--------------------------------------------------------------------------------
/src/redux/store/index.js:
--------------------------------------------------------------------------------
1 | import { createStore, applyMiddleware } from "redux";
2 | import thunk from "redux-thunk";
3 | import RootReducer from "../reducers";
4 |
5 | const middlewares = [thunk];
6 |
7 | const intialState = {};
8 |
9 | const Store = createStore(
10 | RootReducer,
11 | intialState,
12 | applyMiddleware(...middlewares)
13 | );
14 | window.store = Store;
15 | export default Store;
16 |
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.0/8 are considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl, {
104 | headers: { 'Service-Worker': 'script' },
105 | })
106 | .then(response => {
107 | // Ensure service worker exists, and that we really are getting a JS file.
108 | const contentType = response.headers.get('content-type');
109 | if (
110 | response.status === 404 ||
111 | (contentType != null && contentType.indexOf('javascript') === -1)
112 | ) {
113 | // No service worker found. Probably a different app. Reload the page.
114 | navigator.serviceWorker.ready.then(registration => {
115 | registration.unregister().then(() => {
116 | window.location.reload();
117 | });
118 | });
119 | } else {
120 | // Service worker found. Proceed as normal.
121 | registerValidSW(swUrl, config);
122 | }
123 | })
124 | .catch(() => {
125 | console.log(
126 | 'No internet connection found. App is running in offline mode.'
127 | );
128 | });
129 | }
130 |
131 | export function unregister() {
132 | if ('serviceWorker' in navigator) {
133 | navigator.serviceWorker.ready
134 | .then(registration => {
135 | registration.unregister();
136 | })
137 | .catch(error => {
138 | console.error(error.message);
139 | });
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom/extend-expect';
6 |
--------------------------------------------------------------------------------
/src/utils/index.js:
--------------------------------------------------------------------------------
1 | import AvionDB from "aviondb";
2 | import AccessControllers from "orbit-db-access-controllers";
3 | import BlocknativeAccessController from "../AccessController/BlocknativeAccessController";
4 | import Onboard from "bnc-onboard";
5 | import Web3 from "web3";
6 | var collection, web3;
7 |
8 | export const onboard = Onboard({
9 | dappId: "32dedbdd-255e-4e93-a66f-7e558c24893a", // [String] The API key created by step one above
10 | networkId: 1, // [Integer] The Ethereum network ID your Dapp uses.
11 | subscriptions: {
12 | wallet: (wallet) => {
13 | web3 = new Web3(wallet.provider);
14 | },
15 | },
16 | walletSelect: {
17 | wallets: [
18 | { walletName: "coinbase", preferred: true },
19 | { walletName: "trust" },
20 | { walletName: "metamask", preferred: true },
21 | { walletName: "dapper", preferred: true },
22 | /* {
23 | walletName: "trezor",
24 | appUrl: APP_URL,
25 | email: CONTACT_EMAIL,
26 | rpcUrl: "https://mainnet.infura.io/v3/2cf3ec9bd42d4099b8620c2a6ee8c51a",
27 | }, */
28 | {
29 | walletName: "ledger",
30 | rpcUrl: "https://mainnet.infura.io/v3/2cf3ec9bd42d4099b8620c2a6ee8c51a",
31 | },
32 | {
33 | walletName: "fortmatic",
34 | apiKey: "pk_test_27DFAEDF186A9394",
35 | preferred: true,
36 | },
37 | {
38 | walletName: "portis",
39 | apiKey: "110f4f7b-6c23-43e9-afc8-07f3dd8edd2e",
40 | preferred: true,
41 | label: "Portis",
42 | },
43 | {
44 | walletName: "squarelink",
45 | apiKey: "0d839d14070173707470",
46 | },
47 | { walletName: "authereum" },
48 | {
49 | walletName: "walletConnect",
50 | infuraKey: "2cf3ec9bd42d4099b8620c2a6ee8c51a",
51 | },
52 | { walletName: "opera" },
53 | { walletName: "operaTouch" },
54 | { walletName: "torus" },
55 | { walletName: "status" },
56 | /* { walletName: "unilogin" }, */
57 | {
58 | walletName: "imToken",
59 | rpcUrl: "https://tokenlon-core-market.tokenlon.im/rpc",
60 | },
61 | ],
62 | },
63 | });
64 |
65 | AccessControllers.addAccessController({
66 | AccessController: BlocknativeAccessController,
67 | });
68 |
69 | export const getAvionDBCollection = async () => {
70 | if (!collection) {
71 | const ipfs = await window.Ipfs.create();
72 | const aviondb = await AvionDB.init(
73 | "database-test-23",
74 | ipfs,
75 | {
76 | accessController: {
77 | type: "blocknative-access-controller",
78 | onboard: onboard,
79 | },
80 | },
81 | { AccessControllers: AccessControllers }
82 | );
83 | collection = await aviondb.initCollection(
84 | "collection-test-23" /* ,
85 | {},
86 | {
87 | accessController: {
88 | type: "blocknative-access-controller",
89 | onboard: onboard,
90 | },
91 | AccessControllers: AccessControllers,
92 | } */
93 | );
94 | return collection;
95 | } else {
96 | return collection;
97 | }
98 | };
99 |
--------------------------------------------------------------------------------