From f99e7e1f322c2ed925d234bac69844c205ecee14 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 26 Jul 2019 10:21:29 -0700 Subject: [PATCH 1/2] use /wg_public_key endpoint instead of /settings --- src/Frontpage/NodeInformation.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Frontpage/NodeInformation.js b/src/Frontpage/NodeInformation.js index 3f2fafe5..0b3eb4ca 100644 --- a/src/Frontpage/NodeInformation.js +++ b/src/Frontpage/NodeInformation.js @@ -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); From 4a593a2e49b3b0a3de60bff72d3436a4ccb2f7cd Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 26 Jul 2019 13:51:55 -0700 Subject: [PATCH 2/2] handle router reboot after private key import --- src/Payments/PrivateKeys.js | 55 ++++++++++++++++++++------------ src/locales/en/translations.json | 5 +-- src/locales/es/translations.json | 3 +- src/store/actions.js | 7 +--- src/store/index.js | 1 - 5 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/Payments/PrivateKeys.js b/src/Payments/PrivateKeys.js index 9e6d3a30..70a6b930 100644 --- a/src/Payments/PrivateKeys.js +++ b/src/Payments/PrivateKeys.js @@ -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, @@ -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"; @@ -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 => { @@ -66,8 +74,13 @@ const PrivateKeys = () => {

{t("privateKeys")}

{t("importKey", { balance: toEth(balance), symbol })}

{t("import")}

- {!waiting && - success && {t("privateKeyImported")}} + {oldKey === wgPublicKey ? ( + warning && ( + {t("privateKeyImportInitiated")} + ) + ) : ( + {t("privateKeySuccess")} + )}
diff --git a/src/locales/en/translations.json b/src/locales/en/translations.json index f2396722..155c0d84 100644 --- a/src/locales/en/translations.json +++ b/src/locales/en/translations.json @@ -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", @@ -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.", diff --git a/src/locales/es/translations.json b/src/locales/es/translations.json index a2a77a4a..d707b70c 100644 --- a/src/locales/es/translations.json +++ b/src/locales/es/translations.json @@ -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", @@ -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í ...", diff --git a/src/store/actions.js b/src/store/actions.js index a436e31b..f267ab97 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -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) @@ -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 }), diff --git a/src/store/index.js b/src/store/index.js index d3944a30..625d11d7 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -26,7 +26,6 @@ const state = { exits: [], factor: 0, interfaces: null, - keyChange: false, localFee: null, lowBalance: false, meshIp: null,