Skip to content

Commit

Permalink
Merge pull request #89 from althea-net/reboot-on-key-import
Browse files Browse the repository at this point in the history
Handle router reboot after private key import
  • Loading branch information
asoltys authored Jul 26, 2019
2 parents b6ab6ad + 4a593a2 commit d1130c4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 34 deletions.
4 changes: 1 addition & 3 deletions src/Frontpage/NodeInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const NodeInformation = () => {
const { meshIp } = await get("/mesh_ip");
dispatch({ type: "meshIp", meshIp });

const {
network: { wgPublicKey }
} = await get("/settings");
const wgPublicKey = await get("/wg_public_key");
dispatch({ type: "wgPublicKey", wgPublicKey });
} catch (e) {
console.log(e);
Expand Down
55 changes: 34 additions & 21 deletions src/Payments/PrivateKeys.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import useInterval from "hooks/useInterval";
import {
Alert,
Button,
Expand All @@ -10,9 +11,8 @@ import {
Input,
Label
} from "reactstrap";
import { post, useStore } from "store";
import { get, post, useStore } from "store";
import { Confirm, toEth } from "utils";
import useInterval from "hooks/useInterval";

import Export from "./Export";

Expand All @@ -21,30 +21,38 @@ const PrivateKeys = () => {
const [privateKey, setPrivateKey] = useState("");
const [exporting, setExporting] = useState(false);
const [confirming, setConfirming] = useState(false);
const [saving, setSaving] = useState(false);
const [success, setSuccess] = useState(false);
const [warning, setWarning] = useState(false);
const [oldKey, setOldKey] = useState();

const valid = parseInt(privateKey, 16) > 0;

const [{ balance, symbol, waiting }, dispatch] = useStore();
const [{ balance, symbol, wgPublicKey }, dispatch] = useStore();

useInterval(() => {
if (saving) dispatch({ type: "keepWaiting" });
}, waiting > 0 ? 1000 : null);
useInterval(async () => {
try {
const wgPublicKey = await get("/wg_public_key");
if (!(wgPublicKey instanceof Error))
dispatch({ type: "wgPublicKey", wgPublicKey });
} catch (e) {
console.log(e);
}
}, 5000);

useEffect(
() =>
(async () => {
const wgPublicKey = await get("/wg_public_key");
if (!(wgPublicKey instanceof Error)) setOldKey(wgPublicKey);
})(),
[]
);

const save = async e => {
e.preventDefault();

const eth_private_key = privateKey;
setConfirming(false);
setSaving(true);

dispatch({ type: "meshIp", meshIp: null });
dispatch({ type: "wgPublicKey", wgPublicKey: null });
dispatch({ type: "startKeyChange" });
dispatch({ type: "startWaiting", waiting: 120 });

post("/eth_private_key", { eth_private_key });
setSuccess(true);
post("/eth_private_key", { eth_private_key: privateKey });
setWarning(true);
};

const confirm = e => {
Expand All @@ -66,8 +74,13 @@ const PrivateKeys = () => {
<h3>{t("privateKeys")}</h3>
<p>{t("importKey", { balance: toEth(balance), symbol })}</p>
<h4>{t("import")}</h4>
{!waiting &&
success && <Alert color="success">{t("privateKeyImported")}</Alert>}
{oldKey === wgPublicKey ? (
warning && (
<Alert color="warning">{t("privateKeyImportInitiated")}</Alert>
)
) : (
<Alert color="success">{t("privateKeySuccess")}</Alert>
)}
<FormGroup>
<Label for="price">{t("privateKeyString")}</Label>
<div className="d-flex">
Expand Down
5 changes: 3 additions & 2 deletions src/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"problemSubmittingForm": "There was a problem submitting the form",
"exitWarning": "You need to register with an exit node on the Network Connection page",
"keyChange": "The connection to the router is being reset as your new private key is being imported. Please wait for the router to come back online.",
"privateKeyImportWarning": "After importing your new private key, the router connection will be reset and you'll be required to re-register with your exit server.",
"privateKeyImportWarning": "After importing your private key, your router will be rebooted and will be assigned a new Wireguard VPN key and IP address. You'll need to re-register with any exit servers you wish to use. If you are connected via Wifi, you may need to reconnect once the router comes back online in case your device roams to another network.",
"lessThanAWeek": "Based on your average usage of {{perMonthUsage}} GB per month, your balance will provide you with less than a week of service.",
"loginError": "Password entry failed",
"login": "Router Password Required",
Expand Down Expand Up @@ -175,9 +175,10 @@
"priceSaved": "Price was set successfully",
"priceSetError": "An error occured, the price could not be updated",
"privateKeyError": "There was a problem importing the private key",
"privateKeyImported": "Private key imported successfully",
"privateKeyImportInitiated": "Private key import has been initiated. The router will be rebooted.",
"privateKeyString": "Private Key String",
"privateKeys": "Private Keys",
"privateKeySuccess": "Private key imported successfully.",
"proceed": "Do you wish to proceed?",
"putAddress": "Put subnet DAO eth address here...",
"reassignPorts": "Re-assign the modes of your router ports. They are visually displayed in the same order as on your router.",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/es/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"problemSubmittingForm": "Hubo un problema enviando el formulario",
"exitWarning": "No tiene un servidor de salida seleccionado o no está registrado correctamente, visite la página de Conexión de red.",
"keyChange": "La conexión al enrutador se restablece a medida que se importa su nueva clave privada. Espere a que el enrutador vuelva a estar en línea.",
"privateKeyImportWarning": "Después de importar su nueva clave privada, la conexión del enrutador se restablecerá y se le solicitará que vuelva a registrarse con su servidor de salida.",
"privateKeyImportWarning": "Después de importar su clave privada, su enrutador se reiniciará y se le asignará una nueva clave y dirección IP de Wireguard VPN. Deberá volver a registrarse con cualquier servidor de salida que desee utilizar. Si está conectado a través de Wifi, es posible que deba volver a conectarse una vez que el enrutador vuelva a estar en línea en caso de que su dispositivo pase a otra red.",
"lessThanAWeek": "Según su uso promedio de {{perMonthUsage}} GB por mes, su saldo le proporcionará menos de una semana de servicio.",
"loginError": "La entrada de contraseña falló",
"login": "Se requiere contraseña de enrutador",
Expand Down Expand Up @@ -177,6 +177,7 @@
"privateKeyError": "Hubo un problema en importar la llave privada",
"privateKeyImported": "Llave privada fue importada exitosamente",
"privateKeyString": "Texto de la llave privada",
"privateKeySuccess": "Private key imported successfully.",
"privateKeys": "Llaves privadas",
"proceed": "Desea continuar?",
"putAddress": "Pon la dirección de Ethereum de la subred DAO aquí ...",
Expand Down
7 changes: 1 addition & 6 deletions src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,10 @@ export default (state, action) => {
lowBalance,
ritaVersion,
version,
waiting:
(state.keyChange && state.waiting > 110) || state.portChange
? state.waiting
: 0
waiting: state.portChange ? state.waiting : 0
}),
meshIp: ({ meshIp }) => ({ meshIp }),
keepWaiting: () => ({
keyChange: state.keyChange && state.waiting >= 1,
portChange: state.portChange && state.waiting >= 1,
wifiChange: state.wifiChange && state.waiting >= 1,
waiting: Math.max(state.waiting - 1, 0)
Expand Down Expand Up @@ -106,7 +102,6 @@ export default (state, action) => {
reset: ({ nickname }) => ({
resetting: [...state.resetting, nickname]
}),
startKeyChange: () => ({ keyChange: true }),
startPortChange: () => ({ portChange: true }),
startWaiting: ({ waiting }) => ({ waiting }),
usage: ({ usage }) => ({ usage }),
Expand Down
1 change: 0 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const state = {
exits: [],
factor: 0,
interfaces: null,
keyChange: false,
localFee: null,
lowBalance: false,
meshIp: null,
Expand Down

0 comments on commit d1130c4

Please sign in to comment.