Skip to content

Commit

Permalink
messages: CommonJS require to TypeScript import (#525)
Browse files Browse the repository at this point in the history
This commit completes the TypeScript conversion [1] by replacing
the CommonJS `require` syntax with TypeScript's `import` syntax.

[1]: #435
  • Loading branch information
Mersho authored May 16, 2024
1 parent 87318ac commit ee4281c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
14 changes: 7 additions & 7 deletions bot/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { TelegramError } = require('telegraf');
const QR = require('qrcode');
import { TelegramError } from 'telegraf'
import QR from 'qrcode';
const {
getCurrency,
numberFormat,
Expand All @@ -14,7 +14,7 @@ const {
getStars,
} = require('../util');
const OrderEvents = require('./modules/events/orders');
const { logger } = require('../logger');
import { logger } from "../logger";
import { MainContext } from './start';
import { UserDocument } from '../models/user'
import { IOrder } from '../models/order'
Expand Down Expand Up @@ -103,7 +103,7 @@ const invoicePaymentRequestMessage = async (
}
};

const pendingSellMessage = async (ctx: MainContext, user: UserDocument, order: IOrder, channel: string, i18n: I18nContext) => {
const pendingSellMessage = async (ctx: Telegraf<MainContext>, user: UserDocument, order: IOrder, channel: string, i18n: I18nContext) => {
try {
const orderExpirationWindow =
Number(process.env.ORDER_PUBLISHED_EXPIRATION_WINDOW) / 60 / 60;
Expand Down Expand Up @@ -614,7 +614,7 @@ const publishBuyOrderMessage = async (
};

const publishSellOrderMessage = async (
ctx: MainContext,
ctx: Telegraf<MainContext>,
user: UserDocument,
order: IOrder,
i18n: I18nContext,
Expand Down Expand Up @@ -1553,7 +1553,7 @@ const currencyNotSupportedMessage = async (ctx: MainContext, currencies: Array<s
}
};

const notAuthorized = async (ctx: MainContext, tgId: string) => {
const notAuthorized = async (ctx: MainContext, tgId?: string) => {
try {
if (tgId) {
await ctx.telegram.sendMessage(tgId, ctx.i18n.t('not_authorized'));
Expand Down Expand Up @@ -1610,7 +1610,7 @@ const showConfirmationButtons = async (ctx: MainContext, orders: Array<IOrder>,
}
};

module.exports = {
export {
startMessage,
initBotErrorMessage,
invoicePaymentRequestMessage,
Expand Down
2 changes: 1 addition & 1 deletion bot/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const {
validateObjectId,
validateLightningAddress,
} = require('./validations');
const messages = require('./messages');
import * as messages from './messages';
const {
attemptPendingPayments,
cancelOrders,
Expand Down
2 changes: 1 addition & 1 deletion jobs/pending_payments.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { payRequest, isPendingPayment } = require('../ln');
const { PendingPayment, Order, User, Community } = require('../models');
const messages = require('../bot/messages');
import * as messages from '../bot/messages';
const { getUserI18nContext } = require('../util');
const { logger } = require('../logger');
import { Telegraf } from 'telegraf';
Expand Down
14 changes: 12 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
],
"devDependencies": {
"@types/node": "^20.5.0",
"@types/qrcode": "^1.5.2",
"chai": "^4.3.4",
"chokidar": "^3.5.3",
"eslint": "^8.15.0",
Expand Down

0 comments on commit ee4281c

Please # to comment.