Fix orders ids

This commit is contained in:
koalasat
2025-06-24 22:18:12 +02:00
parent 9407c570c6
commit f4209de810
2 changed files with 13 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import Geohash from 'latlon-geohash';
import thirdParties from '../../static/thirdparties.json';
import currencyDict from '../../static/assets/currencies.json';
import defaultFederation from '../../static/federation.json';
import hashStringToInteger from './stringToInteger';
const eventToPublicOrder = (
event: Event,
@ -48,7 +49,6 @@ const eventToPublicOrder = (
publicOrder.coordinatorShortAlias = coordinator?.shortAlias;
publicOrder.federated = coordinator?.federated ?? false;
publicOrder.id = parseInt(dTag[1], 16);
event.tags.forEach((tag) => {
switch (tag[0]) {
@ -99,6 +99,8 @@ const eventToPublicOrder = (
if (platform[1] === 'robosats') {
const orderUrl = tag[1].split('/');
publicOrder.id = parseInt(orderUrl[orderUrl.length - 1] ?? '0');
} else {
publicOrder.id = hashStringToInteger(tag[1] + dTag[1]);
}
if (tag[1] !== '') publicOrder.link = tag[1];

View File

@ -0,0 +1,10 @@
export default function hashStringToInteger(input: string): number {
let hash = 0;
for (let i = 0; i < input.length; i++) {
hash = (hash << 5) - hash + input.charCodeAt(i); // Hashing algorithm
hash |= 0; // Convert to 32-bit integer
}
return Math.abs(hash); // Return a positive integer
}