privacycash 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/getUtxos.js +17 -0
- package/package.json +1 -1
- package/src/getUtxos.ts +17 -0
package/dist/getUtxos.js
CHANGED
|
@@ -32,6 +32,7 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
32
32
|
getMyUtxosPromise = (async () => {
|
|
33
33
|
let valid_utxos = [];
|
|
34
34
|
let valid_strings = [];
|
|
35
|
+
let history_indexes = [];
|
|
35
36
|
try {
|
|
36
37
|
let offsetStr = storage.getItem(LSK_FETCH_OFFSET + localstorageKey(publicKey));
|
|
37
38
|
if (offsetStr) {
|
|
@@ -51,6 +52,7 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
51
52
|
const nonZeroUtxos = [];
|
|
52
53
|
const nonZeroEncrypted = [];
|
|
53
54
|
for (let [k, utxo] of fetched.utxos.entries()) {
|
|
55
|
+
history_indexes.push(utxo.index);
|
|
54
56
|
if (utxo.amount.toNumber() > 0) {
|
|
55
57
|
nonZeroUtxos.push(utxo);
|
|
56
58
|
nonZeroEncrypted.push(fetched.encryptedOutputs[k]);
|
|
@@ -80,6 +82,21 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
80
82
|
finally {
|
|
81
83
|
getMyUtxosPromise = null;
|
|
82
84
|
}
|
|
85
|
+
// get history index
|
|
86
|
+
let historyKey = 'tradeHistory' + localstorageKey(publicKey);
|
|
87
|
+
let rec = storage.getItem(historyKey);
|
|
88
|
+
let recIndexes = [];
|
|
89
|
+
if (rec?.length) {
|
|
90
|
+
recIndexes = rec.split(',').map(n => Number(n));
|
|
91
|
+
}
|
|
92
|
+
if (recIndexes.length) {
|
|
93
|
+
history_indexes = [...history_indexes, ...recIndexes];
|
|
94
|
+
}
|
|
95
|
+
let unique_history_indexes = Array.from(new Set(history_indexes));
|
|
96
|
+
let top20 = unique_history_indexes.sort((a, b) => b - a).slice(0, 20);
|
|
97
|
+
if (top20.length) {
|
|
98
|
+
storage.setItem(historyKey, top20.join(','));
|
|
99
|
+
}
|
|
83
100
|
// store valid strings
|
|
84
101
|
logger.debug(`valid_strings len before set: ${valid_strings.length}`);
|
|
85
102
|
valid_strings = [...new Set(valid_strings)];
|
package/package.json
CHANGED
package/src/getUtxos.ts
CHANGED
|
@@ -62,6 +62,7 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
62
62
|
getMyUtxosPromise = (async () => {
|
|
63
63
|
let valid_utxos: Utxo[] = []
|
|
64
64
|
let valid_strings: string[] = []
|
|
65
|
+
let history_indexes: number[] = []
|
|
65
66
|
try {
|
|
66
67
|
let offsetStr = storage.getItem(LSK_FETCH_OFFSET + localstorageKey(publicKey))
|
|
67
68
|
if (offsetStr) {
|
|
@@ -81,6 +82,7 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
81
82
|
const nonZeroUtxos: Utxo[] = [];
|
|
82
83
|
const nonZeroEncrypted: any[] = [];
|
|
83
84
|
for (let [k, utxo] of fetched.utxos.entries()) {
|
|
85
|
+
history_indexes.push(utxo.index)
|
|
84
86
|
if (utxo.amount.toNumber() > 0) {
|
|
85
87
|
nonZeroUtxos.push(utxo);
|
|
86
88
|
nonZeroEncrypted.push(fetched.encryptedOutputs[k]);
|
|
@@ -108,6 +110,21 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
108
110
|
} finally {
|
|
109
111
|
getMyUtxosPromise = null
|
|
110
112
|
}
|
|
113
|
+
// get history index
|
|
114
|
+
let historyKey = 'tradeHistory' + localstorageKey(publicKey)
|
|
115
|
+
let rec = storage.getItem(historyKey)
|
|
116
|
+
let recIndexes: number[] = []
|
|
117
|
+
if (rec?.length) {
|
|
118
|
+
recIndexes = rec.split(',').map(n => Number(n))
|
|
119
|
+
}
|
|
120
|
+
if (recIndexes.length) {
|
|
121
|
+
history_indexes = [...history_indexes, ...recIndexes]
|
|
122
|
+
}
|
|
123
|
+
let unique_history_indexes = Array.from(new Set(history_indexes));
|
|
124
|
+
let top20 = unique_history_indexes.sort((a, b) => b - a).slice(0, 20);
|
|
125
|
+
if (top20.length) {
|
|
126
|
+
storage.setItem(historyKey, top20.join(','))
|
|
127
|
+
}
|
|
111
128
|
// store valid strings
|
|
112
129
|
logger.debug(`valid_strings len before set: ${valid_strings.length}`)
|
|
113
130
|
valid_strings = [...new Set(valid_strings)];
|