diff --git a/frontend/src/utils/nostr.ts b/frontend/src/utils/nostr.ts index f3916c93..0b0d6c7e 100644 --- a/frontend/src/utils/nostr.ts +++ b/frontend/src/utils/nostr.ts @@ -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]; diff --git a/frontend/src/utils/stringToInteger.ts b/frontend/src/utils/stringToInteger.ts new file mode 100644 index 00000000..6f363dc9 --- /dev/null +++ b/frontend/src/utils/stringToInteger.ts @@ -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 +}