Skip to content

Commit

Permalink
Merge pull request #77 from cansulting/release/0.4.2
Browse files Browse the repository at this point in the history
Release/0.4.2
  • Loading branch information
jhoe123 authored Feb 24, 2022
2 parents d501b47 + 1affc1b commit 59d5454
Show file tree
Hide file tree
Showing 44 changed files with 19,383 additions and 17,701 deletions.
14 changes: 10 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
"version": "0.2.0",
"configurations": [
{
"command": "npm start",
"name": "Run npm server",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"name": "Server",
"program": "${workspaceFolder}/src_server/index.js",
"request": "launch",
"type": "node-terminal",
"cwd": "${workspaceFolder}/src_server"
"restart": true,
"runtimeExecutable": "nodemon",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
},
{
"command": "npm start",
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src_client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "companion",
"homepage": "/",
"homepage": "/ela.companion",
"version": "0.1.0",
"private": true,
"dependencies": {
Expand Down
11 changes: 5 additions & 6 deletions src_client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import {
import backend from "./api/backend";
import RootStore from "./store";
import Socket from "./Socket";
const loading = () => (
<div className="animated fadeIn pt-3 text-center">Loading...</div>
);
import Landing from "./views/components/Landing"
const Auth = React.lazy(() => import("./views/Auth"));
const Config = React.lazy(() => import("./views/Config"));
const Download = React.lazy(() => import("./views/Download"));
const loading = () => <Landing/>;
class App extends React.Component {
constructor(props) {
super(props);
Expand All @@ -23,7 +22,7 @@ class App extends React.Component {
RootStore.blockchain.eid.fetchData();
RootStore.blockchain.esc.fetchData();
RootStore.blockchain.carrier.fetchData();
RootStore.blockchain.feeds.fetchData();
RootStore.blockchain.feeds.fetchData();
backend.checkInstallation().then((responseJson) => {
localStorage.setItem("isconfiged", responseJson.configed.trim());
this.setState({ loading: false });
Expand All @@ -40,7 +39,7 @@ class App extends React.Component {
render() {
if (this.state.loading) {
return (
<Router>
<Router basename={process.env.PUBLIC_URL}>
<div>
<React.Suspense fallback={loading()}>
<Switch>
Expand All @@ -59,7 +58,7 @@ class App extends React.Component {
);
} else {
return (
<Router>
<Router basename={process.env.PUBLIC_URL}>
<Socket>
<div>
<React.Suspense fallback={loading()}>
Expand Down
61 changes: 53 additions & 8 deletions src_client/src/api/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ class API {
body: JSON.stringify({
pwd,
}),
}).then((response) => response.json());
});
};

getRateLimitWaitTime= () => {
return fetch(`http://${PUBLIC_URI}/rateLimitWaitTime`,{
method: "get",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
}
}).then(response=>response.json())
}
fetchEla = async () => {
const response = await this.axios.get("/ela");
return response.data;
Expand Down Expand Up @@ -241,12 +249,49 @@ class API {
});
return data;
};
downloadWallet = () => {
const response = {
file: `http://${PUBLIC_URI}/downloadWallet`,
};
// now, let's download:
window.location.href = response.file;
restart = async () => {
await axios.post(`http://${PUBLIC_URI}/restart`);
};
shutdown = async () => {
await axios.post(`http://${PUBLIC_URI}/shutdown`);
setTimeout(()=>{
window.location.reload()
},5000)
}
checkElaboxStatus = async () =>{
const { data } = await axios.get(`http://${PUBLIC_URI}/check_elabox_status`);
return data
};
downloadWallet = (pass) => {
return new Promise((resolve, reject) => {
axios({
url: `http://${PUBLIC_URI}/downloadWallet?pass=${pass}`, //your url
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
//console.log(response)
try {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'keystore.dat'); //or any other extension
document.body.appendChild(link);
link.click();
resolve("")
}
catch (e) {
reject(e)
}
})
.catch((error) => reject(error));
})
};
uploadKeyStore= async (values) =>{
const {oldPass,newPass,keystore}=values
const {data} = await axios.post(`http://${PUBLIC_URI}/uploadWallet`,{
wallet : keystore, oldpass : oldPass, newpass : newPass
})
return data
};
}

Expand Down
77 changes: 77 additions & 0 deletions src_client/src/hooks/UseAuth.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { useState, useEffect,useRef } from "react"
import backend from "../api/backend"
import {validCharacters} from "../utils/auth"
export default function UseAuth(clearWindowAddress=false) {
const [seconds,setTimer]=useState(0)
const [isProcessing, setProcessing] = useState(false)
useEffect(()=>{
if(clearWindowAddress){
window.localStorage.removeItem('address');
}

backend.getRateLimitWaitTime().then(responseJson => {
setTimer(responseJson.rateLimitRemaining)
})
},[])
useEffect(()=>{
let interval=null
if(seconds>0){
interval=setInterval(()=>{
setTimer(seconds=>seconds-1)
},1000)
}
else{
backend.getRateLimitWaitTime().then(responseJson => {
setTimer(responseJson.rateLimitRemaining)
})
clearInterval(interval)
}
return ()=>{
clearInterval(interval)
}
},[seconds])
const handleLogin= async pwd => {
return new Promise((resolve,reject)=>{
setProcessing(true)
if(!validCharacters(pwd)){
reject("Password shouldnt contain special characters and space with atleast 6 characters.")
setProcessing(false)
return;
}
backend
.login(pwd)
.then(async (response) => {
const responseJson=await response.json()
if (responseJson.ok) {
localStorage.setItem('logedin', true);
localStorage.setItem('address', responseJson.address);
resolve("")
} else {
if(responseJson.err!=="Too many auth request from this IP"){
reject("Wrong password")
}
else{
backend.getRateLimitWaitTime().then(responseJson => {
setTimer(responseJson.rateLimitRemaining)
})
reject(`Too many auth request from this IP, please try again.`)
}
}
})
.catch((error) => {
console.error(error)
reject(error)
})
.finally(()=>{
setProcessing(false)
})
})
}
const isBlocked= seconds>0
return {
seconds,
isBlocked,
isProcessing,
handleLogin,
}
}
8 changes: 8 additions & 0 deletions src_client/src/hooks/UseHook.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from "react"
import useAuth from "./UseAuth"
export const withAuth = (Component) => {
return (props)=> {
const auth = useAuth();
return <Component {...props} auth={auth} />;
}
}
36 changes: 24 additions & 12 deletions src_client/src/index.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


body {
margin: 0;
/* font-family: -apple-system, BlinkMacSystemFont, 'MuliExtraLight', 'Segoe UI', 'Roboto', 'Oxygen',
Expand All @@ -17,10 +15,10 @@ body {
monospace;
} */

.sidebar{
.sidebar {
width: 130px;
height: calc(100vh - 90px);
background-color: 'blue';
background-color: "blue";
position: fixed;
top: 0;
left: 0;
Expand Down Expand Up @@ -48,18 +46,32 @@ body {

.sidebarMenu {
height: 70px;
width:100%;
width: 100%;
justify-content: center;
display: flex;
flex-direction:column;
padding-left: 30px
flex-direction: column;
padding-left: 30px;
}
.modal .modal-content{
.modal .modal-content {
background-color: rgb(39, 42, 61) !important;
color:white;
border:none;
color: white;
border: none;
}
a:hover {
text-decoration: none !important;
color: white !important;
}
a:hover{
.dropdown-item {
color: white !important;
}
.nar-dropdown > .dropdown-item:hover {
text-decoration: none !important;
color:white !important;
color: white !important;
}
.nar-dropdown > .dropdown-item:hover {
background-color: red;
}

.modal-header button.close{
color: white !important;
}
2 changes: 2 additions & 0 deletions src_client/src/store/BlockchainStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export const eid = types

export const esc = types
.model({
port:types.optional(types.number,0),
chainId:types.optional(types.number,0),
servicesRunning: types.optional(types.boolean, false),
restarting: types.optional(types.boolean, false),
isRunning: types.maybeNull(types.boolean),
Expand Down
4 changes: 2 additions & 2 deletions src_client/src/tests/Wallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe("Wallet", () => {
fireEvent.change(amountInput, { target: { value: "1" } })
const sendBtn = screen.getByTestId("send")
fireEvent.click(sendBtn)
const sendingElaModal = await screen.findByText("Error ELA address")
const sendingElaModal = await screen.findByText("Incorrect ELA Address")
expect(sendingElaModal).toBeInTheDocument()


Expand Down Expand Up @@ -220,7 +220,7 @@ test("Send ELA doesnt accept amount with comma(e.g 1,000)", async () => {
const sendBtn = screen.getByTestId("send")
fireEvent.click(sendBtn)

const sendingElaModal = await screen.findByText("Error amount")
const sendingElaModal = await screen.findByText("Incorrect Amount")
expect(sendingElaModal).toBeInTheDocument()

})
Expand Down
7 changes: 7 additions & 0 deletions src_client/src/utils/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const validCharacters = (str = "") => {
if (!str || str.length <= 5) return false
if (str.search(' ') >= 0) return false;

const specialChars = /[`^$&()\'\"\[\]{};:\\|,.<>\/]/;
return !specialChars.test(str);
}
5 changes: 5 additions & 0 deletions src_client/src/utils/string.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export const shortifyHash = (hash) => {
return hash.substring(0, 9) + "..." + hash.substring(54, 64);
};

export const capitalize = (s) => {
if (typeof s !== 'string') return ''
return s.charAt(0).toUpperCase() + s.slice(1)
}
7 changes: 3 additions & 4 deletions src_client/src/views/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import {
Redirect,
} from "react-router-dom"
import Ota from "./components/Ota"
const loading = () => (
<div className="animated fadeIn pt-3 text-center">Loading...</div>
)
import Landing from "./components/Landing"
const loading = () => <Landing/>
const Companion = React.lazy(() => import("./Companion"))
const Login = React.lazy(() => import("./Login"))

function Auth({ ota }) {
return (
<Router>
<Router basename={process.env.PUBLIC_URL}>
<div>
<React.Suspense fallback={loading()}>
<Switch>
Expand Down
2 changes: 1 addition & 1 deletion src_client/src/views/Companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Companion({ ota, elaStatus }) {

return (
<>
<Router>
<Router basename={process.env.PUBLIC_URL}>
<div
style={{
height: "100vh",
Expand Down
Loading

0 comments on commit 59d5454

Please sign in to comment.