Skip to content

Commit

Permalink
Merge pull request #1138 from Chia-Network/offer-tweaks
Browse files Browse the repository at this point in the history
feat: offer bug fix and RESTful compliance
  • Loading branch information
TheLastCicada authored Jul 30, 2024
2 parents eb14436 + 0379b84 commit 173e560
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/controllers/offer.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand All @@ -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.',
Expand All @@ -171,6 +176,19 @@ 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) {
res.status(200).json({
message: 'No offer to accept',
success: true,
});
return;
}
*/

// replace with above
await assertActiveOfferFile();

const offerFileJson = await Meta.findOne({
Expand Down Expand Up @@ -231,9 +249,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,
Expand Down

0 comments on commit 173e560

Please sign in to comment.