diff --git a/src/app/components/ConnectPage/ConnectPage.jsx b/src/app/components/ConnectPage/ConnectPage.jsx index 4b9d1c2..74e3252 100644 --- a/src/app/components/ConnectPage/ConnectPage.jsx +++ b/src/app/components/ConnectPage/ConnectPage.jsx @@ -17,60 +17,65 @@ export default function ConnectPage({ const [keyValue, setKeyValue] = useState(""); - const [receivedPublicKey, setReceivedPublicKey] = useState(""); const [keyIncorrect, setKeyIncorrect] = useState(false); + const [portIncorrect, setPortIncorrect] = useState(false); const [password, setPassword] = useState(""); - const [passwordRepeat, setPasswordRepeat] = useState(""); + const [passwordRepeat, setPasswordRepeat] = useState(""); + const [walletPort, setWalletPort] = useState("12111"); - const [invalidPassword, setInvalidPassword] = useState(false); + const [invalidPassword, setInvalidPassword] = useState(false); - function onPasswordInput(event, repeat) { - const { value } = event.currentTarget; - setIncorrectPassword(false); - setInvalidPassword(false); - if (repeat) { - setPasswordRepeat(value); - } else { - setPassword(value); - } - } - - async function connectClick() { - const response = await fetchBackground({ method: "CREATE_CONNECT_KEY" }); - setReceivedPublicKey(response.publicKey); + function onPasswordInput(event, repeat) { + const { value } = event.currentTarget; + setIncorrectPassword(false); + setInvalidPassword(false); + if (repeat) { + setPasswordRepeat(value); + } else { + setPassword(value); + } } - - useEffect(() => { - connectClick(); - }, []); - async function continueClick() { - + const correctPassword = ( - password === passwordRepeat && + password === passwordRepeat && password ); if (!correctPassword) return setInvalidPassword(true); + if (!parseInt(walletPort, 10)) { + console.log('PORT IS NOT A NUMBER'); + return setPortIncorrect(true); + } - const publicKey = forge.pki.publicKeyFromPem(receivedPublicKey); - const encrypted = publicKey.encrypt(keyValue); - const response = await fetchBackground({ method: "VALIDATE_CONNECT_KEY", key: encrypted }); + await fetchBackground({ method: "SET_API_CREDENTIALS", credentials: { port: walletPort } }); - if (response.success) { - setConnectData(dispatch, { - token: keyValue, - publicKey: receivedPublicKey - }); - - onConfirm && onConfirm(password, keyValue, receivedPublicKey); + const publicKeyResponse = await fetchBackground({ method: "CREATE_CONNECT_KEY" }); + + if (!publicKeyResponse.publicKey) { + console.log('NO PUBLIC KEY RECEIVED'); + return setPortIncorrect(true); + } + + setConnectData(dispatch, { + token: keyValue, + publicKey: publicKeyResponse.publicKey, + port: walletPort // not handled + }); + + if (onConfirm) { + onConfirm( + password, + keyValue, + publicKeyResponse.publicKey + ); } else { - setKeyIncorrect(true); + throw new Error("No onConfirm function provided"); } } @@ -81,40 +86,45 @@ export default function ConnectPage({ return (
- Zano + Zano
- { + setWalletPort(event.currentTarget.value); + setPortIncorrect(false); + }} /> - {false &&

Wallet is not responding

} + {portIncorrect &&

Wallet is not responding

}
- - onPasswordInput(event, false)} + onChange={event => onPasswordInput(event, false)} /> - onPasswordInput(event, true)} + onChange={event => onPasswordInput(event, true)} />
diff --git a/src/app/components/UI/MyInput/MyInput.jsx b/src/app/components/UI/MyInput/MyInput.jsx index 0e14eb2..bd1453d 100644 --- a/src/app/components/UI/MyInput/MyInput.jsx +++ b/src/app/components/UI/MyInput/MyInput.jsx @@ -12,13 +12,14 @@ const MyInput = memo((props) => { noActiveBorder, type, isError, + noValidation, ...otherProps } = props; const { value, onChange, onInput, inputValid, onBlur, isDirty, isFilled } = inputData; const onInputHandler = (e) => { - if (type === "number") { + if (type === "number" && !noValidation) { const newValue = e.target.value .replace(/[^0-9.]/g, "") .replace(/(\..*?)\..*/g, "$1") diff --git a/src/background/background.js b/src/background/background.js index 3ff89df..164b293 100644 --- a/src/background/background.js +++ b/src/background/background.js @@ -34,7 +34,11 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { switch (request.method) { case "SET_API_CREDENTIALS": - apiCredentials = request.credentials; + apiCredentials = { + ...(apiCredentials || {}), + ...request.credentials + }; + console.log("API credentials set to", apiCredentials); break; case "PING_WALLET":