mirror of
https://github.com/lil-org/wallet.git
synced 2025-01-06 04:13:11 +03:00
37 lines
839 B
JavaScript
37 lines
839 B
JavaScript
// ∅ 2024 lil org
|
|
// Rewrite of id_mapping.js from trust-web3-provider.
|
|
|
|
"use strict";
|
|
|
|
import Utils from "./utils";
|
|
|
|
class IdMapping {
|
|
|
|
constructor() {
|
|
this.intIds = new Map;
|
|
}
|
|
|
|
tryFixId(payload) {
|
|
if (!payload.id) {
|
|
payload.id = Utils.genId();
|
|
this.intIds.set(payload.id, payload.id);
|
|
} else if (typeof payload.id !== "number" || this.intIds.has(payload.id) ) {
|
|
let newId = Utils.genId();
|
|
this.intIds.set(newId, payload.id);
|
|
payload.id = newId;
|
|
} else {
|
|
this.intIds.set(payload.id, payload.id);
|
|
}
|
|
}
|
|
|
|
tryPopId(id) {
|
|
let originId = this.intIds.get(id);
|
|
if (originId) {
|
|
this.intIds.delete(id);
|
|
}
|
|
return originId;
|
|
}
|
|
}
|
|
|
|
module.exports = IdMapping;
|