Skip to content

Commit

Permalink
WIP1
Browse files Browse the repository at this point in the history
The entire project needs to be converted to typescript due
to a conflict between typescript and nodejs & at the
moment, the project cannot run and work properly.
  • Loading branch information
Mersho committed Sep 6, 2023
1 parent 63b5e54 commit 719e78a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
16 changes: 9 additions & 7 deletions app.js → app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require('dotenv').config();
const { SocksProxyAgent } = require('socks-proxy-agent');
const { start } = require('./bot');
const mongoConnect = require('./db_connect');
import * as dotenv from "dotenv";
dotenv.config()
const SocksProxyAgent = require('socks-proxy-agent')
import { start } from "./bot/start";
import mongoConnect from './db_connect'
const { resubscribeInvoices } = require('./ln');
const logger = require('./logger');
const { delay } = require('./util');
Expand Down Expand Up @@ -30,12 +31,13 @@ const { delay } = require('./util');
telegram: {
agent,
},
};
} as any;
}
const bot = start(process.env.BOT_TOKEN, options);
const bot = start(String(process.env.BOT_TOKEN), options);
// Wait 1 seconds before try to resubscribe hold invoices
await delay(1000);
await resubscribeInvoices(bot);
})
.on('error', error => logger.error(`Error connecting to Mongo: ${error}`));
.on('error', (error: Error) => logger.error(`Error connecting to Mongo: ${error}`));
})();

7 changes: 4 additions & 3 deletions db_connect.js → db_connect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose');
import mongoose from "mongoose";
const logger = require('./logger');

// connect to database
Expand All @@ -12,12 +12,13 @@ if (!MONGO_URI) {
throw new Error('You must provide a MongoDB URI');
}
logger.info(`Connecting to: ${MONGO_URI}`);
// TODO: Update mongoose to latest version
const connect = () => {
mongoose.connect(MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
} as any); // older version of mongoose that does not have the ConnectOptions type defined.
return mongoose;
};

module.exports = connect;
export default connect;
13 changes: 5 additions & 8 deletions lnurl/lnurl-pay.js → lnurl/lnurl-pay.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const axios = require('axios').default;
import axios from 'axios';
const logger = require('../logger');

// {
// pr: String, // bech32-serialized lightning invoice
// routes: [], // an empty array
// }
const resolvLightningAddress = async (address, amountMsat) => {
const resolvLightningAddress = async (address: string, amountMsat: number) => {
const [user, domain] = address.split('@');
const lnAddressQuery = `https://${domain}/.well-known/lnurlp/${user}`;

Expand All @@ -17,7 +17,7 @@ const resolvLightningAddress = async (address, amountMsat) => {
}

if (
(lnAddressRes.minSendable > amountMsat) |
(lnAddressRes.minSendable > amountMsat) ||
(lnAddressRes.maxSendable < amountMsat)
) {
logger.info('lnAddress invalid amount');
Expand All @@ -31,7 +31,7 @@ const resolvLightningAddress = async (address, amountMsat) => {
return res;
};

const existLightningAddress = async address => {
const existLightningAddress = async (address: string) => {
const [user, domain] = address.split('@');
const lnAddressQuery = `https://${domain}/.well-known/lnurlp/${user}`;

Expand All @@ -49,7 +49,4 @@ const existLightningAddress = async address => {
}
};

module.exports = {
resolvLightningAddress,
existLightningAddress,
};
export { resolvLightningAddress, existLightningAddress }
10 changes: 5 additions & 5 deletions logger.js → logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const winston = require('winston');
import * as winston from 'winston';

const level = process.env.LOG_LEVEL || 'notice';

Expand All @@ -9,9 +9,8 @@ const logger = winston.createLogger({
}),
winston.format.colorize(),
winston.format.printf(info => {
return `[${info.timestamp}] ${info.level}: ${info.message} ${
info.stack ? info.stack : ''
}`;
return `[${info.timestamp}] ${info.level}: ${info.message} ${info.stack ? info.stack : ''
}`;
})
),
levels: winston.config.syslog.levels,
Expand All @@ -24,4 +23,5 @@ const logger = winston.createLogger({
exitOnError: false,
});

module.exports = logger;

export default logger;

0 comments on commit 719e78a

Please sign in to comment.