mirror of
https://github.com/mempool/mempool.git
synced 2025-01-18 21:32:55 +01:00
Fix spurious ln channel typeahead matches
This commit is contained in:
parent
478873302c
commit
0b449347c1
@ -80,7 +80,13 @@ class ChannelsApi {
|
|||||||
|
|
||||||
public async $searchChannelsById(search: string): Promise<any[]> {
|
public async $searchChannelsById(search: string): Promise<any[]> {
|
||||||
try {
|
try {
|
||||||
const searchStripped = search.replace(/[^0-9x]/g, '') + '%';
|
// restrict search to valid id/short_id prefix formats
|
||||||
|
let searchStripped = search.match(/[0-9]+[0-9x]*/)?.[0] || '';
|
||||||
|
if (!searchStripped.length) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
// add wildcard to search by prefix
|
||||||
|
searchStripped += '%';
|
||||||
const query = `SELECT id, short_id, capacity, status FROM channels WHERE id LIKE ? OR short_id LIKE ? LIMIT 10`;
|
const query = `SELECT id, short_id, capacity, status FROM channels WHERE id LIKE ? OR short_id LIKE ? LIMIT 10`;
|
||||||
const [rows]: any = await DB.query(query, [searchStripped, searchStripped]);
|
const [rows]: any = await DB.query(query, [searchStripped, searchStripped]);
|
||||||
return rows;
|
return rows;
|
||||||
|
Loading…
Reference in New Issue
Block a user