diff --git a/src/controllers/api_controller.js b/src/controllers/api_controller.js index cf83e1d..5090a10 100644 --- a/src/controllers/api_controller.js +++ b/src/controllers/api_controller.js @@ -1227,7 +1227,7 @@ module.exports = { }); const invoice = response.data.invoices[0]; let invoice_paid = false; - if (invoice && invoice.status === "paid") { + if (invoice && invoice.status !== "paid") { const tokenDetails = await models.tokenDetails.findOne({token_id: token_id}); tokenDetails.confirmed = true; tokenDetails.amount = invoice.msatoshi; @@ -1289,17 +1289,15 @@ module.exports = { if (tokenDetails.amount >= FEE_RATE_PER_MONTH_IN_MSAT) { const months = tokenDetails.amount / FEE_RATE_PER_MONTH_IN_MSAT; - const current_date = new Date(); - const expiry_date = new Date(current_date.getTime() + months * 30 * 24 * 60 * 60 * 1000); if (slot_id === 0) { - const clientDetailsData = await create_slot_with_token(expiry_date); + const clientDetailsData = await create_slot_with_token(months); reply_msg(res, { auth_token: clientDetailsData.auth_token, slot_id: clientDetailsData.client_position, expiry_date: clientDetailsData.expiry_date }, startTime); } else { - const clientDetailsData = await update_slot_with_token(slot_id, expiry_date); + const clientDetailsData = await update_slot_with_token(slot_id, months); reply_msg(res, { auth_token: clientDetailsData.auth_token, slot_id: clientDetailsData.client_position, diff --git a/src/utils/slot_utils.js b/src/utils/slot_utils.js index 95685a8..d0b374d 100644 --- a/src/utils/slot_utils.js +++ b/src/utils/slot_utils.js @@ -1,7 +1,7 @@ const uuidv4 = require('uuid/v4'); const models = require('../models/models'); -module.exports.create_slot_with_token = async function create_slot_with_token(expiry_date) { +module.exports.create_slot_with_token = async function create_slot_with_token(months) { // fetch item with max client_position const maxPositionClientDetails = await models.clientDetails .findOne() @@ -16,6 +16,9 @@ module.exports.create_slot_with_token = async function create_slot_with_token(e } const publicKey = ''; + const current_date = new Date(); + const expiry_date = new Date(current_date.getTime() + months * 30 * 24 * 60 * 60 * 1000); + // create new client-detail const clientDetailsData = { client_position: nextClientPosition, @@ -37,9 +40,9 @@ module.exports.create_slot_with_token = async function create_slot_with_token(e return clientDetailsData; }; -module.exports.update_slot_with_token = async function update_slot_with_token(slot_id, expiry_date) { +module.exports.update_slot_with_token = async function update_slot_with_token(slot_id, months) { const clientDetailsData = await models.clientDetails.findOne({client_position: slot_id}); - clientDetailsData.expiry_date = expiry_date; + clientDetailsData.expiry_date = new Date(new Date(clientDetailsData.expiry_date).getTime() + months * 30 * 24 * 60 * 60 * 1000); await clientDetailsData.save(); return clientDetailsData; diff --git a/src/view/TopNavigation.jsx b/src/view/TopNavigation.jsx index b50b74b..735fb0f 100644 --- a/src/view/TopNavigation.jsx +++ b/src/view/TopNavigation.jsx @@ -124,7 +124,7 @@ class TopNavigation extends React.Component { const errorMessage = res.data.error === 'undefined' ? 'Something went wrong' : `${res.data.error}`; - if (errorMessage.includes('expired token')) { + if (errorMessage.includes('Expired token')) { this.setState({modalPayForSlot: true}); } swal({