From 0756fc9a31ce2fbae62ad07b76f41977293875e3 Mon Sep 17 00:00:00 2001 From: William Wills Date: Thu, 18 Jul 2024 18:22:26 -0400 Subject: [PATCH 1/2] feat: offer tweaks and RESTful compliance --- src/controllers/offer.controller.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/controllers/offer.controller.js b/src/controllers/offer.controller.js index 3a647cbf..c2449e45 100644 --- a/src/controllers/offer.controller.js +++ b/src/controllers/offer.controller.js @@ -131,17 +131,17 @@ export const commitImportedOfferFile = async (req, res) => { const response = await datalayer.takeOffer(JSON.parse(offerFile.metaValue)); - res.json({ - message: 'Offer Accepted.', - tradeId: response.trade_id, - success: true, - }); - await Meta.destroy({ where: { metaKey: 'activeOffer', }, }); + + res.json({ + message: 'Offer Accepted.', + tradeId: response.trade_id, + success: true, + }); } catch (error) { res.status(400).json({ message: 'Can not commit offer.', @@ -160,6 +160,11 @@ export const cancelImportedOfferFile = async (req, res) => { metaKey: 'activeOffer', }, }); + + res.json({ + message: 'Offer Cancelled', + success: true, + }); } catch (error) { res.status(400).json({ message: 'Can not cancel offer.', @@ -171,7 +176,15 @@ export const cancelImportedOfferFile = async (req, res) => { export const getCurrentOfferInfo = async (req, res) => { try { - await assertActiveOfferFile(); + try { + await assertActiveOfferFile(); + } catch (error) { + res.status(200).json({ + message: 'No offer to accept', + success: true, + }); + return; + } const offerFileJson = await Meta.findOne({ where: { metaKey: 'activeOffer' }, @@ -231,9 +244,9 @@ export const getCurrentOfferInfo = async (req, res) => { maker, taker, }, + success: true, }); } catch (error) { - console.trace(error); res.status(400).json({ message: 'Can not get offer.', error: error.message, From 7a4f632b734068cd1d5f5cdd5668e0fea8088175 Mon Sep 17 00:00:00 2001 From: William Wills Date: Fri, 19 Jul 2024 11:27:51 -0400 Subject: [PATCH 2/2] fix: changes in previous commit that broke old cadt-ui --- src/controllers/offer.controller.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/controllers/offer.controller.js b/src/controllers/offer.controller.js index c2449e45..0c44c356 100644 --- a/src/controllers/offer.controller.js +++ b/src/controllers/offer.controller.js @@ -176,6 +176,7 @@ export const cancelImportedOfferFile = async (req, res) => { export const getCurrentOfferInfo = async (req, res) => { try { + /* fix for when old cadt-ui is no longer supported try { await assertActiveOfferFile(); } catch (error) { @@ -185,6 +186,10 @@ export const getCurrentOfferInfo = async (req, res) => { }); return; } + */ + + // replace with above + await assertActiveOfferFile(); const offerFileJson = await Meta.findOne({ where: { metaKey: 'activeOffer' },