@ocap/indexdb 1.18.17 → 1.18.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/lib/util.js +16 -7
  2. package/package.json +4 -4
package/lib/util.js CHANGED
@@ -6,15 +6,19 @@ const uniqBy = require('lodash/uniqBy');
6
6
  const { createSortedList } = require('@ocap/util/lib/create-sorted-list');
7
7
  const { BN } = require('@ocap/util');
8
8
 
9
- const formatTokenMeta = (token, tokenStates) => {
9
+ const formatTokenMeta = (token, tokenStates, ...rest) => {
10
10
  if (!tokenStates) {
11
11
  return token;
12
12
  }
13
13
 
14
- const tokenState = tokenStates.find((x) => x.address === token.address);
15
- token.decimal = tokenState.decimal;
16
- token.unit = tokenState.unit;
17
- token.symbol = tokenState.symbol;
14
+ const tokenState = tokenStates.filter(Boolean).find((x) => x.address === token.address);
15
+ if (tokenState) {
16
+ token.decimal = tokenState.decimal;
17
+ token.unit = tokenState.unit;
18
+ token.symbol = tokenState.symbol;
19
+ } else {
20
+ console.warn('Invalid token state on formatting', token, tokenStates, ...rest);
21
+ }
18
22
 
19
23
  return token;
20
24
  };
@@ -235,13 +239,18 @@ const createIndexedTransaction = async (tx, ctx, indexdb) => {
235
239
 
236
240
  const createIndexedStake = async (x, ctx, indexdb) => {
237
241
  const tokens = uniq(Object.keys(x.tokens || {}).concat(Object.keys(x.revokedTokens || {})));
238
- const tokenStates = await Promise.all(tokens.map((t) => indexdb.token.get(t)));
242
+ const existTokenStates = ctx.tokenStates || [];
243
+ const missingTokenStates = await Promise.all(
244
+ tokens.filter((a) => !existTokenStates.find((t) => t.address === a)).map((t) => indexdb.token.get(t))
245
+ );
246
+ const tokenStates = [...existTokenStates, ...missingTokenStates];
239
247
  return {
240
248
  ...pick(x, [
241
249
  'address',
242
250
  'sender',
243
251
  'receiver',
244
252
  'assets',
253
+ 'slashers',
245
254
  'revocable',
246
255
  'data',
247
256
  'message',
@@ -249,7 +258,7 @@ const createIndexedStake = async (x, ctx, indexdb) => {
249
258
  'revokedAssets',
250
259
  ]),
251
260
  tokens: Object.keys(x.tokens || {}).map((address) =>
252
- formatTokenMeta({ address, balance: x.tokens[address] }, tokenStates)
261
+ formatTokenMeta({ address, balance: x.tokens[address] }, tokenStates, x)
253
262
  ),
254
263
  revokedTokens: Object.keys(x.revokedTokens || {}).map((address) =>
255
264
  formatTokenMeta({ address, balance: x.revokedTokens[address] }, tokenStates)
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.17",
6
+ "version": "1.18.19",
7
7
  "description": "Defines the basic interface for OCAP IndexDB",
8
8
  "main": "lib/main.js",
9
9
  "files": [
@@ -25,10 +25,10 @@
25
25
  "jest": "^27.5.1"
26
26
  },
27
27
  "dependencies": {
28
- "@ocap/state": "1.18.17",
29
- "@ocap/util": "1.18.17",
28
+ "@ocap/state": "1.18.19",
29
+ "@ocap/util": "1.18.19",
30
30
  "kareem": "^2.4.1",
31
31
  "lodash": "^4.17.21"
32
32
  },
33
- "gitHead": "be4f07d40599521e3b5364dd7d0ace22ad5f58d6"
33
+ "gitHead": "d13bcea225809e0c0a926cfc246c7a46bd4185f3"
34
34
  }