Skip to content

Commit 136a160

Browse files
authored
Merge pull request #2021 from RoboSats/fix-orders-ids
Fix orders ids
2 parents 9407c57 + f4209de commit 136a160

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

frontend/src/utils/nostr.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Geohash from 'latlon-geohash';
66
import thirdParties from '../../static/thirdparties.json';
77
import currencyDict from '../../static/assets/currencies.json';
88
import defaultFederation from '../../static/federation.json';
9+
import hashStringToInteger from './stringToInteger';
910

1011
const eventToPublicOrder = (
1112
event: Event,
@@ -48,7 +49,6 @@ const eventToPublicOrder = (
4849

4950
publicOrder.coordinatorShortAlias = coordinator?.shortAlias;
5051
publicOrder.federated = coordinator?.federated ?? false;
51-
publicOrder.id = parseInt(dTag[1], 16);
5252

5353
event.tags.forEach((tag) => {
5454
switch (tag[0]) {
@@ -99,6 +99,8 @@ const eventToPublicOrder = (
9999
if (platform[1] === 'robosats') {
100100
const orderUrl = tag[1].split('/');
101101
publicOrder.id = parseInt(orderUrl[orderUrl.length - 1] ?? '0');
102+
} else {
103+
publicOrder.id = hashStringToInteger(tag[1] + dTag[1]);
102104
}
103105

104106
if (tag[1] !== '') publicOrder.link = tag[1];
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function hashStringToInteger(input: string): number {
2+
let hash = 0;
3+
4+
for (let i = 0; i < input.length; i++) {
5+
hash = (hash << 5) - hash + input.charCodeAt(i); // Hashing algorithm
6+
hash |= 0; // Convert to 32-bit integer
7+
}
8+
9+
return Math.abs(hash); // Return a positive integer
10+
}

0 commit comments

Comments
 (0)