mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-17 16:23:13 +00:00
Fix orders ids
This commit is contained in:
@ -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];
|
||||
|
10
frontend/src/utils/stringToInteger.ts
Normal file
10
frontend/src/utils/stringToInteger.ts
Normal 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
|
||||
}
|
Reference in New Issue
Block a user