From 9001a8cea96b35ec231f5f73c33f22d65bae988c Mon Sep 17 00:00:00 2001 From: jejolare Date: Tue, 12 Mar 2024 22:26:30 +0700 Subject: [PATCH 1/2] dev edits --- .../components/ConnectPage/ConnectPage.jsx | 71 ++++++------------- src/app/components/UI/MyInput/MyInput.jsx | 3 +- src/background/background.js | 5 +- 3 files changed, 27 insertions(+), 52 deletions(-) diff --git a/src/app/components/ConnectPage/ConnectPage.jsx b/src/app/components/ConnectPage/ConnectPage.jsx index 2b984d6..141fde2 100644 --- a/src/app/components/ConnectPage/ConnectPage.jsx +++ b/src/app/components/ConnectPage/ConnectPage.jsx @@ -20,9 +20,11 @@ export default function ConnectPage({ const [receivedPublicKey, setReceivedPublicKey] = useState(""); const [keyIncorrect, setKeyIncorrect] = useState(false); + const [portIncorrect, setPortIncorrect] = useState(false); const [password, setPassword] = useState(""); const [passwordRepeat, setPasswordRepeat] = useState(""); + const [walletPort, setWalletPort] = useState("12111"); const [invalidPassword, setInvalidPassword] = useState(false); @@ -37,16 +39,11 @@ export default function ConnectPage({ } } - async function connectClick() { + async function fetchPublicKey() { const response = await fetchBackground({ method: "CREATE_CONNECT_KEY" }); setReceivedPublicKey(response.publicKey); } - - useEffect(() => { - connectClick(); - }, []); - async function continueClick() { @@ -57,21 +54,18 @@ export default function ConnectPage({ if (!correctPassword) return setInvalidPassword(true); - - const publicKey = forge.pki.publicKeyFromPem(receivedPublicKey); - const encrypted = publicKey.encrypt(keyValue); - const response = await fetchBackground({ method: "VALIDATE_CONNECT_KEY", key: encrypted }); - - if (response.success) { - setConnectData(dispatch, { - token: keyValue, - publicKey: receivedPublicKey - }); - - onConfirm && onConfirm(password, keyValue, receivedPublicKey); - } else { - setKeyIncorrect(true); + if (!parseInt(walletPort, 10)) { + return setPortIncorrect(true); } + + await fetchBackground({ method: "SET_API_CREDENTIALS", credentials: { port: walletPort } }); + + setConnectData(dispatch, { + token: keyValue, + publicKey: receivedPublicKey + }); + + onConfirm && onConfirm(password, keyValue, receivedPublicKey); } function onKeyInput(event) { @@ -86,40 +80,17 @@ export default function ConnectPage({ src={logo} alt="Zano" /> - {/*

{connectState === "start" ? "Connect wallet app to continue" : "Type connect key from app"}

*/} - {/* { - (() => { - switch (connectState) { - case "code": { - return ( -
- - -
- // <> - ) - } - default: { - return ( - <> - - - ) - } - } - })() - } */}
{ + setWalletPort(event.currentTarget.value); + setPortIncorrect(false); + }} /> { 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 a84e60a..428a879 100644 --- a/src/background/background.js +++ b/src/background/background.js @@ -32,7 +32,10 @@ chrome.storage.local.get("pendingTx", (result) => { chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { switch (request.method) { case "SET_API_CREDENTIALS": - apiCredentials = request.credentials; + apiCredentials = { + ...(apiCredentials || {}), + ...request.credentials + }; break; case "PING_WALLET": From 1f98789927e1cd735300ed6e338829245a4c1f56 Mon Sep 17 00:00:00 2001 From: jejolare Date: Tue, 12 Mar 2024 22:35:07 +0700 Subject: [PATCH 2/2] change connect process --- .../components/ConnectPage/ConnectPage.jsx | 95 +++++++++++-------- src/background/background.js | 1 + 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/src/app/components/ConnectPage/ConnectPage.jsx b/src/app/components/ConnectPage/ConnectPage.jsx index ed9be6b..74e3252 100644 --- a/src/app/components/ConnectPage/ConnectPage.jsx +++ b/src/app/components/ConnectPage/ConnectPage.jsx @@ -17,55 +17,66 @@ 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 fetchPublicKey() { - 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); + } } 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); } await fetchBackground({ method: "SET_API_CREDENTIALS", credentials: { port: walletPort } }); + 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: receivedPublicKey + publicKey: publicKeyResponse.publicKey, + port: walletPort // not handled }); - onConfirm && onConfirm(password, keyValue, receivedPublicKey); + if (onConfirm) { + onConfirm( + password, + keyValue, + publicKeyResponse.publicKey + ); + } else { + throw new Error("No onConfirm function provided"); + } } function onKeyInput(event) { @@ -75,45 +86,45 @@ export default function ConnectPage({ return (
- Zano + Zano
- { - setWalletPort(event.currentTarget.value); - setPortIncorrect(false); - }} + noValidation={true} + type={"number"} + onChange={event => { + 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/background/background.js b/src/background/background.js index 428a879..4757a8a 100644 --- a/src/background/background.js +++ b/src/background/background.js @@ -36,6 +36,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { ...(apiCredentials || {}), ...request.credentials }; + console.log("API credentials set to", apiCredentials); break; case "PING_WALLET":