Skip to content

Commit

Permalink
Merge pull request #45 from NexusMutual/features/add-isDeprecated-check
Browse files Browse the repository at this point in the history
Add isDeprecated check before sending the quote
  • Loading branch information
roxdanila authored Jul 26, 2023
2 parents 89a0cc5 + 575835b commit e0a89f5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib/chainApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const createChainApi = async contracts => {
};

const fetchProduct = async id => {
const { productType, capacityReductionRatio, useFixedPrice } = await cover.products(id);
const { productType, capacityReductionRatio, useFixedPrice, isDeprecated } = await cover.products(id);
const { gracePeriod } = await cover.productTypes(productType);
return { productType, capacityReductionRatio, useFixedPrice, gracePeriod };
return { productType, capacityReductionRatio, useFixedPrice, gracePeriod, isDeprecated };
};

const fetchProducts = async () => {
Expand All @@ -45,9 +45,9 @@ const createChainApi = async contracts => {
}

return products.map((product, id) => {
const { productType, capacityReductionRatio, useFixedPrice } = product;
const { productType, capacityReductionRatio, useFixedPrice, isDeprecated } = product;
const gracePeriod = productTypes[product.productType].gracePeriod;
return { productType, capacityReductionRatio, useFixedPrice, gracePeriod };
return { productType, capacityReductionRatio, useFixedPrice, gracePeriod, isDeprecated };
});
};

Expand Down
9 changes: 9 additions & 0 deletions src/lib/quoteEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ const quoteEngine = (store, productId, amount, period, coverAsset) => {
if (!product) {
return null;
}

if (product.isDeprecated) {
return {
error: {
isDeprecated: true,
},
};
}

const productPools = selectProductPools(store, productId);
const assetRate = selectAssetRate(store, coverAsset);
const assetRates = store.getState().assetRates;
Expand Down
4 changes: 4 additions & 0 deletions src/routes/quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ router.get(
return res.status(400).send({ error: 'Not enough capacity for the cover amount', response: null });
}

if (route.error === 'isDeprecated') {
return res.status(400).send({ error: 'Product is deprecated', response: null });
}

const initialQuote = {
premiumInNXM: Zero,
premiumInAsset: Zero,
Expand Down

0 comments on commit e0a89f5

Please sign in to comment.