From 09027deffcaca0ca554cbf1d4c8087a91e1eb248 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Fri, 3 Mar 2023 11:00:08 -0800 Subject: [PATCH] Fix order click on matches. Fix existing PGP on deleted robot rebuild. --- api/logics.py | 56 ++++++++++++++------------ frontend/src/basic/MakerPage/index.tsx | 24 ++++++++++- frontend/src/basic/RobotPage/index.tsx | 2 +- 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/api/logics.py b/api/logics.py index 694cf50e..0763eda5 100644 --- a/api/logics.py +++ b/api/logics.py @@ -97,38 +97,42 @@ class Logics: # Try to import the public key import_pub_result = gpg.import_keys(pub_key) if not import_pub_result.imported == 1: - return ( - False, - { - "bad_request": "Your PGP public key does not seem valid.\n" - + f"Stderr: {str(import_pub_result.stderr)}\n" - + f"ReturnCode: {str(import_pub_result.returncode)}\n" - + f"Summary: {str(import_pub_result.summary)}\n" - + f"Results: {str(import_pub_result.results)}\n" - + f"Imported: {str(import_pub_result.imported)}\n" - }, - None, - None, - ) + # If a robot is deleted and it is rebuilt with the same pubKey, the key will not be imported again + # so we assert that the import error is "Not actually changed" + if "Not actually changed" not in import_pub_result.results[0]["text"]: + return ( + False, + { + "bad_request": "Your PGP public key does not seem valid.\n" + + f"Stderr: {str(import_pub_result.stderr)}\n" + + f"ReturnCode: {str(import_pub_result.returncode)}\n" + + f"Summary: {str(import_pub_result.summary)}\n" + + f"Results: {str(import_pub_result.results)}\n" + + f"Imported: {str(import_pub_result.imported)}\n" + }, + None, + None, + ) # Exports the public key again for uniform formatting. pub_key = gpg.export_keys(import_pub_result.fingerprints[0]) # Try to import the encrypted private key (without passphrase) import_priv_result = gpg.import_keys(enc_priv_key) if not import_priv_result.sec_imported == 1: - return ( - False, - { - "bad_request": "Your PGP encrypted private key does not seem valid.\n" - + f"Stderr: {str(import_priv_result.stderr)}\n" - + f"ReturnCode: {str(import_priv_result.returncode)}\n" - + f"Summary: {str(import_priv_result.summary)}\n" - + f"Results: {str(import_priv_result.results)}\n" - + f"Sec Imported: {str(import_priv_result.sec_imported)}\n" - }, - None, - None, - ) + if "Not actually changed" not in import_priv_result.results[0]["text"]: + return ( + False, + { + "bad_request": "Your PGP encrypted private key does not seem valid.\n" + + f"Stderr: {str(import_priv_result.stderr)}\n" + + f"ReturnCode: {str(import_priv_result.returncode)}\n" + + f"Summary: {str(import_priv_result.summary)}\n" + + f"Results: {str(import_priv_result.results)}\n" + + f"Sec Imported: {str(import_priv_result.sec_imported)}\n" + }, + None, + None, + ) return True, None, pub_key, enc_priv_key diff --git a/frontend/src/basic/MakerPage/index.tsx b/frontend/src/basic/MakerPage/index.tsx index 19567514..2cf5c3d0 100644 --- a/frontend/src/basic/MakerPage/index.tsx +++ b/frontend/src/basic/MakerPage/index.tsx @@ -9,6 +9,7 @@ import MakerForm from '../../components/MakerForm'; import BookTable from '../../components/BookTable'; import { AppContext, AppContextProps } from '../../contexts/AppContext'; +import { NoRobotDialog } from '../../components/Dialogs'; const MakerPage = (): JSX.Element => { const { @@ -21,16 +22,19 @@ const MakerPage = (): JSX.Element => { setCurrentOrder, navbarHeight, setPage, + setOrder, + setDelay, } = useContext(AppContext); const { t } = useTranslation(); const history = useHistory(); const maxHeight = (windowSize.height - navbarHeight) * 0.85 - 3; const [showMatches, setShowMatches] = useState(false); + const [openNoRobot, setOpenNoRobot] = useState(false); const matches = filterOrders({ orders: book.orders, - baseFilter: { currency: fav.currency === 0 ? 1 : fav.currency, type: fav.type }, + baseFilter: { currency: fav.currency === 0 ? 1 : fav.currency, type: fav.type, mode: fav.mode }, paymentMethods: maker.paymentMethods, amountFilter: { amount: maker.amount, @@ -40,8 +44,25 @@ const MakerPage = (): JSX.Element => { }, }); + const onViewOrder = function () { + setOrder(undefined); + setDelay(10000); + }; + + const onOrderClicked = function (id: number) { + if (robot.avatarLoaded) { + history.push('/order/' + id); + setPage('order'); + setCurrentOrder(id); + onViewOrder(); + } else { + setOpenNoRobot(true); + } + }; + return ( + setOpenNoRobot(false)} setPage={setPage} /> 0 && showMatches}> @@ -57,6 +78,7 @@ const MakerPage = (): JSX.Element => { showControls={false} showFooter={false} showNoResults={false} + onOrderClicked={onOrderClicked} /> diff --git a/frontend/src/basic/RobotPage/index.tsx b/frontend/src/basic/RobotPage/index.tsx index ebe55f03..4eb32535 100644 --- a/frontend/src/basic/RobotPage/index.tsx +++ b/frontend/src/basic/RobotPage/index.tsx @@ -43,7 +43,7 @@ const RobotPage = (): JSX.Element => { setInputToken(robot.token); } if (robot.nickname == null && robot.token) { - fetchRobot({ action: 'generate' }); + fetchRobot({ action: 'generate', setBadRequest }); } }, []);