@ocap/indexdb 1.30.14 → 1.30.16

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.
@@ -1,4 +1,36 @@
1
+ import { fromUnitToToken } from "@ocap/util";
2
+
1
3
  //#region src/search-result.ts
4
+ const parseObject = (value) => {
5
+ if (value && typeof value === "object" && !Array.isArray(value)) return value;
6
+ if (typeof value === "string" && value.length > 0) try {
7
+ const parsed = JSON.parse(value);
8
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
9
+ } catch {
10
+ return null;
11
+ }
12
+ return null;
13
+ };
14
+ const parseArray = (value) => {
15
+ if (Array.isArray(value)) return value;
16
+ if (typeof value === "string" && value.length > 0) try {
17
+ const parsed = JSON.parse(value);
18
+ return Array.isArray(parsed) ? parsed : [];
19
+ } catch {
20
+ return [];
21
+ }
22
+ return [];
23
+ };
24
+ const formatBNAmount = (value, decimal, symbol) => {
25
+ if (!value) return "";
26
+ let display = value;
27
+ if (typeof decimal === "number" && decimal > 0) try {
28
+ display = fromUnitToToken(value, decimal, { commify: true });
29
+ } catch {
30
+ display = value;
31
+ }
32
+ return symbol ? `${display} ${symbol}` : display;
33
+ };
2
34
  const ENTITY_LABELS = {
3
35
  tx: "Transaction",
4
36
  rollupBlock: "Rollup Block",
@@ -109,14 +141,20 @@ const formatSearchDescription = (type, row) => {
109
141
  case "account": {
110
142
  const numTxs = getNumber(row, "numTxs");
111
143
  const numAssets = getNumber(row, "numAssets");
144
+ const balances = parseArray(row.tokens).filter((t) => t && typeof t.balance === "string" && t.balance.length > 0 && t.balance !== "0").slice(0, 2).map((t) => formatBNAmount(t.balance, t.decimal, t.symbol)).filter(Boolean);
112
145
  return compactParts([
113
146
  numTxs !== null ? `${numTxs} txs` : "",
114
147
  numAssets !== null ? `${numAssets} assets` : "",
115
- getString(row, "balance") ? `Balance ${getString(row, "balance")}` : ""
148
+ balances.length ? `Balance ${balances.join(", ")}` : ""
116
149
  ]);
117
150
  }
118
151
  case "asset": return compactParts([getString(row, "owner") ? `Owner ${getString(row, "owner")}` : "", getString(row, "parent") ? `Factory ${getString(row, "parent")}` : ""]);
119
- case "token": return compactParts([getString(row, "totalSupply") ? `Supply ${getString(row, "totalSupply")}` : "", getString(row, "issuer") ? `Issuer ${getString(row, "issuer")}` : ""]);
152
+ case "token": {
153
+ const totalSupply = getString(row, "totalSupply");
154
+ const decimal = getNumber(row, "decimal");
155
+ const symbol = getString(row, "symbol");
156
+ return compactParts([totalSupply ? `Supply ${formatBNAmount(totalSupply, decimal ?? void 0, symbol)}` : "", getString(row, "issuer") ? `Issuer ${getString(row, "issuer")}` : ""]);
157
+ }
120
158
  case "factory": {
121
159
  const minted = getNumber(row, "numMinted");
122
160
  const limit = getNumber(row, "limit", "limit_");
@@ -126,11 +164,17 @@ const formatSearchDescription = (type, row) => {
126
164
  limit !== null ? `Limit ${limit}` : ""
127
165
  ]);
128
166
  }
129
- case "tokenFactory": return compactParts([
130
- getString(row, "status") ? `Status ${getString(row, "status")}` : "",
131
- getString(row, "currentSupply") ? `Supply ${getString(row, "currentSupply")}` : "",
132
- getString(row, "reserveBalance") ? `Reserve ${getString(row, "reserveBalance")}` : ""
133
- ]);
167
+ case "tokenFactory": {
168
+ const tokenInfo = parseObject(row.token) ?? {};
169
+ const reserveInfo = parseObject(row.reserveToken) ?? {};
170
+ const currentSupply = getString(row, "currentSupply");
171
+ const reserveBalance = getString(row, "reserveBalance");
172
+ return compactParts([
173
+ getString(row, "status") ? `Status ${getString(row, "status")}` : "",
174
+ currentSupply ? `Supply ${formatBNAmount(currentSupply, tokenInfo.decimal, tokenInfo.symbol)}` : "",
175
+ reserveBalance ? `Reserve ${formatBNAmount(reserveBalance, reserveInfo.decimal, reserveInfo.symbol)}` : ""
176
+ ]);
177
+ }
134
178
  case "stake": {
135
179
  const sender = getString(row, "sender");
136
180
  const receiver = getString(row, "receiver");
@@ -142,11 +186,16 @@ const formatSearchDescription = (type, row) => {
142
186
  const to = getString(row, "to", "to_");
143
187
  return compactParts([from && to ? `${from} -> ${to}` : "", getString(row, "validUntil") ? `Valid until ${getString(row, "validUntil")}` : ""]);
144
188
  }
145
- case "rollup": return compactParts([
146
- getString(row, "tokenAddress") ? `Token ${getString(row, "tokenAddress")}` : "",
147
- getString(row, "totalDepositAmount") ? `Deposits ${getString(row, "totalDepositAmount")}` : "",
148
- getString(row, "totalWithdrawAmount") ? `Withdrawals ${getString(row, "totalWithdrawAmount")}` : ""
149
- ]);
189
+ case "rollup": {
190
+ const tokenInfo = parseObject(row.tokenInfo) ?? {};
191
+ const deposit = getString(row, "totalDepositAmount");
192
+ const withdraw = getString(row, "totalWithdrawAmount");
193
+ return compactParts([
194
+ getString(row, "tokenAddress") ? `Token ${getString(row, "tokenAddress")}` : "",
195
+ deposit ? `Deposits ${formatBNAmount(deposit, tokenInfo.decimal, tokenInfo.symbol)}` : "",
196
+ withdraw ? `Withdrawals ${formatBNAmount(withdraw, tokenInfo.decimal, tokenInfo.symbol)}` : ""
197
+ ]);
198
+ }
150
199
  default: return getString(row, "description");
151
200
  }
152
201
  };
@@ -1,5 +1,37 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let _ocap_util = require("@ocap/util");
1
3
 
2
4
  //#region src/search-result.ts
5
+ const parseObject = (value) => {
6
+ if (value && typeof value === "object" && !Array.isArray(value)) return value;
7
+ if (typeof value === "string" && value.length > 0) try {
8
+ const parsed = JSON.parse(value);
9
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
10
+ } catch {
11
+ return null;
12
+ }
13
+ return null;
14
+ };
15
+ const parseArray = (value) => {
16
+ if (Array.isArray(value)) return value;
17
+ if (typeof value === "string" && value.length > 0) try {
18
+ const parsed = JSON.parse(value);
19
+ return Array.isArray(parsed) ? parsed : [];
20
+ } catch {
21
+ return [];
22
+ }
23
+ return [];
24
+ };
25
+ const formatBNAmount = (value, decimal, symbol) => {
26
+ if (!value) return "";
27
+ let display = value;
28
+ if (typeof decimal === "number" && decimal > 0) try {
29
+ display = (0, _ocap_util.fromUnitToToken)(value, decimal, { commify: true });
30
+ } catch {
31
+ display = value;
32
+ }
33
+ return symbol ? `${display} ${symbol}` : display;
34
+ };
3
35
  const ENTITY_LABELS = {
4
36
  tx: "Transaction",
5
37
  rollupBlock: "Rollup Block",
@@ -110,14 +142,20 @@ const formatSearchDescription = (type, row) => {
110
142
  case "account": {
111
143
  const numTxs = getNumber(row, "numTxs");
112
144
  const numAssets = getNumber(row, "numAssets");
145
+ const balances = parseArray(row.tokens).filter((t) => t && typeof t.balance === "string" && t.balance.length > 0 && t.balance !== "0").slice(0, 2).map((t) => formatBNAmount(t.balance, t.decimal, t.symbol)).filter(Boolean);
113
146
  return compactParts([
114
147
  numTxs !== null ? `${numTxs} txs` : "",
115
148
  numAssets !== null ? `${numAssets} assets` : "",
116
- getString(row, "balance") ? `Balance ${getString(row, "balance")}` : ""
149
+ balances.length ? `Balance ${balances.join(", ")}` : ""
117
150
  ]);
118
151
  }
119
152
  case "asset": return compactParts([getString(row, "owner") ? `Owner ${getString(row, "owner")}` : "", getString(row, "parent") ? `Factory ${getString(row, "parent")}` : ""]);
120
- case "token": return compactParts([getString(row, "totalSupply") ? `Supply ${getString(row, "totalSupply")}` : "", getString(row, "issuer") ? `Issuer ${getString(row, "issuer")}` : ""]);
153
+ case "token": {
154
+ const totalSupply = getString(row, "totalSupply");
155
+ const decimal = getNumber(row, "decimal");
156
+ const symbol = getString(row, "symbol");
157
+ return compactParts([totalSupply ? `Supply ${formatBNAmount(totalSupply, decimal ?? void 0, symbol)}` : "", getString(row, "issuer") ? `Issuer ${getString(row, "issuer")}` : ""]);
158
+ }
121
159
  case "factory": {
122
160
  const minted = getNumber(row, "numMinted");
123
161
  const limit = getNumber(row, "limit", "limit_");
@@ -127,11 +165,17 @@ const formatSearchDescription = (type, row) => {
127
165
  limit !== null ? `Limit ${limit}` : ""
128
166
  ]);
129
167
  }
130
- case "tokenFactory": return compactParts([
131
- getString(row, "status") ? `Status ${getString(row, "status")}` : "",
132
- getString(row, "currentSupply") ? `Supply ${getString(row, "currentSupply")}` : "",
133
- getString(row, "reserveBalance") ? `Reserve ${getString(row, "reserveBalance")}` : ""
134
- ]);
168
+ case "tokenFactory": {
169
+ const tokenInfo = parseObject(row.token) ?? {};
170
+ const reserveInfo = parseObject(row.reserveToken) ?? {};
171
+ const currentSupply = getString(row, "currentSupply");
172
+ const reserveBalance = getString(row, "reserveBalance");
173
+ return compactParts([
174
+ getString(row, "status") ? `Status ${getString(row, "status")}` : "",
175
+ currentSupply ? `Supply ${formatBNAmount(currentSupply, tokenInfo.decimal, tokenInfo.symbol)}` : "",
176
+ reserveBalance ? `Reserve ${formatBNAmount(reserveBalance, reserveInfo.decimal, reserveInfo.symbol)}` : ""
177
+ ]);
178
+ }
135
179
  case "stake": {
136
180
  const sender = getString(row, "sender");
137
181
  const receiver = getString(row, "receiver");
@@ -143,11 +187,16 @@ const formatSearchDescription = (type, row) => {
143
187
  const to = getString(row, "to", "to_");
144
188
  return compactParts([from && to ? `${from} -> ${to}` : "", getString(row, "validUntil") ? `Valid until ${getString(row, "validUntil")}` : ""]);
145
189
  }
146
- case "rollup": return compactParts([
147
- getString(row, "tokenAddress") ? `Token ${getString(row, "tokenAddress")}` : "",
148
- getString(row, "totalDepositAmount") ? `Deposits ${getString(row, "totalDepositAmount")}` : "",
149
- getString(row, "totalWithdrawAmount") ? `Withdrawals ${getString(row, "totalWithdrawAmount")}` : ""
150
- ]);
190
+ case "rollup": {
191
+ const tokenInfo = parseObject(row.tokenInfo) ?? {};
192
+ const deposit = getString(row, "totalDepositAmount");
193
+ const withdraw = getString(row, "totalWithdrawAmount");
194
+ return compactParts([
195
+ getString(row, "tokenAddress") ? `Token ${getString(row, "tokenAddress")}` : "",
196
+ deposit ? `Deposits ${formatBNAmount(deposit, tokenInfo.decimal, tokenInfo.symbol)}` : "",
197
+ withdraw ? `Withdrawals ${formatBNAmount(withdraw, tokenInfo.decimal, tokenInfo.symbol)}` : ""
198
+ ]);
199
+ }
151
200
  default: return getString(row, "description");
152
201
  }
153
202
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.30.14",
6
+ "version": "1.30.16",
7
7
  "type": "module",
8
8
  "description": "Defines the basic interface for OCAP IndexDB",
9
9
  "main": "./lib/main.cjs",
@@ -52,9 +52,9 @@
52
52
  "tsdown": "^0.18.4"
53
53
  },
54
54
  "dependencies": {
55
- "@ocap/state": "1.30.14",
56
- "@ocap/types": "1.30.14",
57
- "@ocap/util": "1.30.14",
55
+ "@ocap/state": "1.30.16",
56
+ "@ocap/types": "1.30.16",
57
+ "@ocap/util": "1.30.16",
58
58
  "kareem": "^2.4.1",
59
59
  "lodash": "^4.17.23"
60
60
  }