@keplr-wallet/stores-eth 0.13.33 → 0.13.35

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.
Files changed (34) hide show
  1. package/build/queries/erc20-balance-batch.d.ts +26 -0
  2. package/build/queries/erc20-balance-batch.js +262 -0
  3. package/build/queries/erc20-balance-batch.js.map +1 -0
  4. package/build/queries/erc20-balance-batch.spec.d.ts +1 -0
  5. package/build/queries/erc20-balance-batch.spec.js +157 -0
  6. package/build/queries/erc20-balance-batch.spec.js.map +1 -0
  7. package/build/queries/erc20-balance.d.ts +21 -6
  8. package/build/queries/erc20-balance.js +118 -27
  9. package/build/queries/erc20-balance.js.map +1 -1
  10. package/build/queries/erc20-balance.spec.d.ts +1 -0
  11. package/build/queries/erc20-balance.spec.js +90 -0
  12. package/build/queries/erc20-balance.spec.js.map +1 -0
  13. package/build/queries/erc20-balances.d.ts +18 -4
  14. package/build/queries/erc20-balances.js +200 -25
  15. package/build/queries/erc20-balances.js.map +1 -1
  16. package/build/queries/erc20-balances.spec.d.ts +1 -0
  17. package/build/queries/erc20-balances.spec.js +150 -0
  18. package/build/queries/erc20-balances.spec.js.map +1 -0
  19. package/build/queries/erc20-batch-parent-store.d.ts +8 -0
  20. package/build/queries/erc20-batch-parent-store.js +21 -0
  21. package/build/queries/erc20-batch-parent-store.js.map +1 -0
  22. package/build/queries/index.d.ts +1 -3
  23. package/build/queries/index.js +6 -5
  24. package/build/queries/index.js.map +1 -1
  25. package/jest.config.js +8 -1
  26. package/package.json +8 -8
  27. package/src/queries/erc20-balance-batch.spec.ts +192 -0
  28. package/src/queries/erc20-balance-batch.ts +273 -0
  29. package/src/queries/erc20-balance.spec.ts +129 -0
  30. package/src/queries/erc20-balance.ts +122 -36
  31. package/src/queries/erc20-balances.spec.ts +194 -0
  32. package/src/queries/erc20-balances.ts +220 -37
  33. package/src/queries/erc20-batch-parent-store.ts +28 -0
  34. package/src/queries/index.ts +8 -15
@@ -0,0 +1,26 @@
1
+ import { ChainGetter, ObservableJsonRpcBatchQuery, QueryError, QuerySharedContext } from "@keplr-wallet/stores";
2
+ export declare class ObservableQueryEthereumERC20BalancesBatchParent {
3
+ protected readonly sharedContext: QuerySharedContext;
4
+ protected readonly chainId: string;
5
+ protected readonly chainGetter: ChainGetter;
6
+ protected readonly ethereumHexAddress: string;
7
+ protected refcount: Map<string, number>;
8
+ protected batchQueries: ObservableJsonRpcBatchQuery<string>[];
9
+ protected batchQueryKeys: string[];
10
+ protected lastKnownBalances: Map<string, string>;
11
+ protected lastBuiltKey: string;
12
+ protected chunkIndex: Map<string, number>;
13
+ constructor(sharedContext: QuerySharedContext, chainId: string, chainGetter: ChainGetter, ethereumHexAddress: string);
14
+ addContract(contract: string): void;
15
+ removeContract(contract: string): void;
16
+ getBalance(contract: string): string | undefined;
17
+ getLastKnownBalance(contract: string): string | undefined;
18
+ get isFetching(): boolean;
19
+ isFetchingContract(contract: string): boolean;
20
+ getError(contract: string): QueryError<unknown> | undefined;
21
+ protected currentKey(): string;
22
+ waitFreshResponse(): Promise<void>;
23
+ protected rebuildBatchQueries(key: string): void;
24
+ protected rememberCurrentBatchBalances(): void;
25
+ protected getRpcUrl(): string;
26
+ }
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ObservableQueryEthereumERC20BalancesBatchParent = void 0;
19
+ const stores_1 = require("@keplr-wallet/stores");
20
+ const mobx_1 = require("mobx");
21
+ const constants_1 = require("../constants");
22
+ const BATCH_CHUNK_SIZE = 10;
23
+ const REBUILD_DEBOUNCE_MS = 200;
24
+ class ObservableQueryEthereumERC20BalancesBatchParent {
25
+ constructor(sharedContext, chainId, chainGetter, ethereumHexAddress) {
26
+ this.sharedContext = sharedContext;
27
+ this.chainId = chainId;
28
+ this.chainGetter = chainGetter;
29
+ this.ethereumHexAddress = ethereumHexAddress;
30
+ this.refcount = new Map();
31
+ this.batchQueries = [];
32
+ this.batchQueryKeys = [];
33
+ this.lastKnownBalances = new Map();
34
+ this.lastBuiltKey = "";
35
+ // Snapshot of contract → batchQueries index at rebuild time, so getError
36
+ // doesn't misattribute chunk ownership during debounce transitions when
37
+ // the live refcount no longer matches the current batchQueries layout.
38
+ this.chunkIndex = new Map();
39
+ (0, mobx_1.makeObservable)(this);
40
+ (0, mobx_1.reaction)(() => {
41
+ const keys = Array.from(this.refcount.keys()).sort().join(",");
42
+ // Include the RPC URL so a runtime endpoint change (user-configured
43
+ // custom RPC) triggers a rebuild against the new endpoint.
44
+ return `${this.getRpcUrl()}::${keys}`;
45
+ }, (key) => this.rebuildBatchQueries(key), { fireImmediately: true, delay: REBUILD_DEBOUNCE_MS });
46
+ }
47
+ addContract(contract) {
48
+ const key = contract.toLowerCase();
49
+ (0, mobx_1.runInAction)(() => {
50
+ var _a;
51
+ this.refcount.set(key, ((_a = this.refcount.get(key)) !== null && _a !== void 0 ? _a : 0) + 1);
52
+ });
53
+ }
54
+ removeContract(contract) {
55
+ const key = contract.toLowerCase();
56
+ const n = this.refcount.get(key);
57
+ if (n === undefined)
58
+ return;
59
+ (0, mobx_1.runInAction)(() => {
60
+ if (n <= 1) {
61
+ this.refcount.delete(key);
62
+ }
63
+ else {
64
+ this.refcount.set(key, n - 1);
65
+ }
66
+ });
67
+ }
68
+ getBalance(contract) {
69
+ var _a, _b;
70
+ const key = contract.toLowerCase();
71
+ const lastKnown = this.lastKnownBalances.get(key);
72
+ for (const q of this.batchQueries) {
73
+ trackQueryFetching(q);
74
+ if (!q.isStarted && lastKnown !== undefined) {
75
+ continue;
76
+ }
77
+ const data = (_b = (_a = q.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b[key];
78
+ if (data !== undefined)
79
+ return data;
80
+ }
81
+ return lastKnown;
82
+ }
83
+ getLastKnownBalance(contract) {
84
+ return this.lastKnownBalances.get(contract.toLowerCase());
85
+ }
86
+ get isFetching() {
87
+ return this.batchQueries.some((q) => q.isFetching);
88
+ }
89
+ isFetchingContract(contract) {
90
+ const key = contract.toLowerCase();
91
+ const chunkIdx = this.chunkIndex.get(key);
92
+ if (chunkIdx === undefined)
93
+ return false;
94
+ const q = this.batchQueries[chunkIdx];
95
+ if (!q)
96
+ return false;
97
+ const isFetching = trackQueryFetching(q);
98
+ if (!q.isStarted && this.lastKnownBalances.has(key))
99
+ return false;
100
+ return isFetching;
101
+ }
102
+ // Per-contract error: surface only the error of the chunk that owns this
103
+ // contract (plus its per-request error if any). Looks up chunk ownership
104
+ // from the snapshot taken at rebuild time to avoid misattribution during
105
+ // debounced refcount transitions.
106
+ getError(contract) {
107
+ const key = contract.toLowerCase();
108
+ const chunkIdx = this.chunkIndex.get(key);
109
+ if (chunkIdx === undefined)
110
+ return undefined;
111
+ const q = this.batchQueries[chunkIdx];
112
+ if (!q)
113
+ return undefined;
114
+ trackQueryFetching(q);
115
+ if (!q.isStarted && this.lastKnownBalances.has(key))
116
+ return undefined;
117
+ if (q.error)
118
+ return q.error;
119
+ const perReq = q.perRequestErrors[key];
120
+ if (perReq) {
121
+ return {
122
+ status: 0,
123
+ statusText: "batch-request-error",
124
+ message: perReq.message,
125
+ data: perReq,
126
+ };
127
+ }
128
+ return undefined;
129
+ }
130
+ currentKey() {
131
+ const keys = Array.from(this.refcount.keys()).sort().join(",");
132
+ return `${this.getRpcUrl()}::${keys}`;
133
+ }
134
+ waitFreshResponse() {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ // The reaction that rebuilds batchQueries is debounced, so refcount can
137
+ // change without batchQueries catching up. Wait until the built key
138
+ // matches the current (refcount + rpc) snapshot.
139
+ yield (0, mobx_1.when)(() => this.currentKey() === this.lastBuiltKey);
140
+ yield Promise.all(this.batchQueries.map((q) => q.waitFreshResponse()));
141
+ this.rememberCurrentBatchBalances();
142
+ });
143
+ }
144
+ rebuildBatchQueries(key) {
145
+ this.rememberCurrentBatchBalances();
146
+ if (this.refcount.size === 0) {
147
+ (0, mobx_1.runInAction)(() => {
148
+ this.batchQueries = [];
149
+ this.batchQueryKeys = [];
150
+ this.lastBuiltKey = key;
151
+ this.chunkIndex = new Map();
152
+ });
153
+ return;
154
+ }
155
+ const rpcUrl = this.getRpcUrl();
156
+ if (!rpcUrl) {
157
+ (0, mobx_1.runInAction)(() => {
158
+ this.batchQueries = [];
159
+ this.batchQueryKeys = [];
160
+ this.lastBuiltKey = key;
161
+ this.chunkIndex = new Map();
162
+ });
163
+ return;
164
+ }
165
+ const contracts = Array.from(this.refcount.keys()).sort();
166
+ const chunks = chunkArray(contracts, BATCH_CHUNK_SIZE);
167
+ const calldata = (to) => ({
168
+ to,
169
+ data: constants_1.erc20ContractInterface.encodeFunctionData("balanceOf", [
170
+ this.ethereumHexAddress,
171
+ ]),
172
+ });
173
+ const nextChunkIndex = new Map();
174
+ chunks.forEach((chunk, idx) => {
175
+ for (const c of chunk)
176
+ nextChunkIndex.set(c, idx);
177
+ });
178
+ const previousQueries = new Map();
179
+ this.batchQueries.forEach((q, idx) => {
180
+ const queryKey = this.batchQueryKeys[idx];
181
+ if (queryKey) {
182
+ previousQueries.set(queryKey, q);
183
+ }
184
+ });
185
+ const nextBatchQueryKeys = chunks.map((chunk) => `${rpcUrl}::${chunk.join(",")}`);
186
+ (0, mobx_1.runInAction)(() => {
187
+ this.batchQueries = chunks.map((chunk, idx) => {
188
+ const queryKey = nextBatchQueryKeys[idx];
189
+ const previous = previousQueries.get(queryKey);
190
+ if (previous) {
191
+ return previous;
192
+ }
193
+ const requests = chunk.map((c) => ({
194
+ method: "eth_call",
195
+ params: [calldata(c), "latest"],
196
+ id: c,
197
+ }));
198
+ return new stores_1.ObservableJsonRpcBatchQuery(this.sharedContext, rpcUrl, "", requests);
199
+ });
200
+ this.batchQueryKeys = nextBatchQueryKeys;
201
+ this.lastBuiltKey = key;
202
+ this.chunkIndex = nextChunkIndex;
203
+ });
204
+ }
205
+ rememberCurrentBatchBalances() {
206
+ var _a;
207
+ const entries = [];
208
+ for (const q of this.batchQueries) {
209
+ const data = (_a = q.response) === null || _a === void 0 ? void 0 : _a.data;
210
+ if (!data) {
211
+ continue;
212
+ }
213
+ for (const [contract, balance] of Object.entries(data)) {
214
+ entries.push([contract.toLowerCase(), balance]);
215
+ }
216
+ }
217
+ if (entries.length === 0) {
218
+ return;
219
+ }
220
+ (0, mobx_1.runInAction)(() => {
221
+ for (const [contract, balance] of entries) {
222
+ this.lastKnownBalances.set(contract, balance);
223
+ }
224
+ });
225
+ }
226
+ getRpcUrl() {
227
+ const u = this.chainGetter.getModularChain(this.chainId).unwrapped;
228
+ return u.type === "evm" || u.type === "ethermint" ? u.evm.rpc : "";
229
+ }
230
+ }
231
+ __decorate([
232
+ mobx_1.observable.shallow
233
+ ], ObservableQueryEthereumERC20BalancesBatchParent.prototype, "refcount", void 0);
234
+ __decorate([
235
+ mobx_1.observable.ref
236
+ ], ObservableQueryEthereumERC20BalancesBatchParent.prototype, "batchQueries", void 0);
237
+ __decorate([
238
+ mobx_1.observable.ref
239
+ ], ObservableQueryEthereumERC20BalancesBatchParent.prototype, "batchQueryKeys", void 0);
240
+ __decorate([
241
+ mobx_1.observable.shallow
242
+ ], ObservableQueryEthereumERC20BalancesBatchParent.prototype, "lastKnownBalances", void 0);
243
+ __decorate([
244
+ mobx_1.observable.ref
245
+ ], ObservableQueryEthereumERC20BalancesBatchParent.prototype, "lastBuiltKey", void 0);
246
+ __decorate([
247
+ mobx_1.observable.ref
248
+ ], ObservableQueryEthereumERC20BalancesBatchParent.prototype, "chunkIndex", void 0);
249
+ exports.ObservableQueryEthereumERC20BalancesBatchParent = ObservableQueryEthereumERC20BalancesBatchParent;
250
+ function chunkArray(array, size) {
251
+ const chunks = [];
252
+ for (let i = 0; i < array.length; i += size) {
253
+ chunks.push(array.slice(i, i + size));
254
+ }
255
+ return chunks;
256
+ }
257
+ function trackQueryFetching(query) {
258
+ // Reading `isFetching` starts ObservableQuery when a caller observes the
259
+ // parent state, while still letting getters return cached last-known data.
260
+ return query.isFetching;
261
+ }
262
+ //# sourceMappingURL=erc20-balance-batch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erc20-balance-batch.js","sourceRoot":"","sources":["../../src/queries/erc20-balance-batch.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,iDAM8B;AAC9B,+BAA+E;AAC/E,4CAAsD;AAEtD,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,MAAa,+CAA+C;IAsB1D,YACqB,aAAiC,EACjC,OAAe,EACf,WAAwB,EACxB,kBAA0B;QAH1B,kBAAa,GAAb,aAAa,CAAoB;QACjC,YAAO,GAAP,OAAO,CAAQ;QACf,gBAAW,GAAX,WAAW,CAAa;QACxB,uBAAkB,GAAlB,kBAAkB,CAAQ;QAxBrC,aAAQ,GAAwB,IAAI,GAAG,EAAE,CAAC;QAG1C,iBAAY,GAA0C,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UAAU,CAAC;AAC1B,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const common_1 = require("@keplr-wallet/common");
13
+ const simple_fetch_1 = require("@keplr-wallet/simple-fetch");
14
+ const stores_1 = require("@keplr-wallet/stores");
15
+ const mobx_1 = require("mobx");
16
+ const erc20_balance_batch_1 = require("./erc20-balance-batch");
17
+ jest.mock("@keplr-wallet/stores", () => {
18
+ const context = jest.requireActual("../../../stores/src/common/query/context");
19
+ const batch = jest.requireActual("../../../stores/src/common/query/json-rpc-batch");
20
+ return {
21
+ QuerySharedContext: context.QuerySharedContext,
22
+ ObservableJsonRpcBatchQuery: batch.ObservableJsonRpcBatchQuery,
23
+ };
24
+ });
25
+ jest.mock("@keplr-wallet/simple-fetch", () => {
26
+ const actual = jest.requireActual("@keplr-wallet/simple-fetch");
27
+ return Object.assign(Object.assign({}, actual), { simpleFetch: jest.fn() });
28
+ });
29
+ const ADDRESS = "0x0000000000000000000000000000000000000001";
30
+ const CONTRACT_A = "0x0000000000000000000000000000000000000002";
31
+ const CONTRACT_B = "0x0000000000000000000000000000000000000003";
32
+ describe("ObservableQueryEthereumERC20BalancesBatchParent", () => {
33
+ let pendingFetches;
34
+ beforeEach(() => {
35
+ pendingFetches = [];
36
+ simple_fetch_1.simpleFetch.mockImplementation((_baseURL, _url, options) => {
37
+ return new Promise((resolve) => {
38
+ pendingFetches.push({
39
+ body: JSON.parse(options.body),
40
+ resolve: resolve,
41
+ });
42
+ });
43
+ });
44
+ });
45
+ afterEach(() => {
46
+ jest.clearAllMocks();
47
+ });
48
+ it("keeps the last known contract balance while the batch layout is rebuilt", () => __awaiter(void 0, void 0, void 0, function* () {
49
+ const parent = new erc20_balance_batch_1.ObservableQueryEthereumERC20BalancesBatchParent(new stores_1.QuerySharedContext(new common_1.MemoryKVStore("erc20-balance-batch-test"), {
50
+ responseDebounceMs: 0,
51
+ }), "eip155:1", mockChainGetter(), ADDRESS);
52
+ parent.addContract(CONTRACT_A);
53
+ const firstWait = parent.waitFreshResponse();
54
+ yield waitForPendingFetches(pendingFetches, 1);
55
+ resolveFetch(pendingFetches[0], {
56
+ [CONTRACT_A]: "0x1",
57
+ });
58
+ yield firstWait;
59
+ expect(parent.getBalance(CONTRACT_A)).toBe("0x1");
60
+ parent.addContract(CONTRACT_B);
61
+ const secondWait = parent.waitFreshResponse();
62
+ yield waitForPendingFetches(pendingFetches, 2);
63
+ expect(parent.getBalance(CONTRACT_A)).toBe("0x1");
64
+ resolveFetch(pendingFetches[1], {
65
+ [CONTRACT_A]: "0x2",
66
+ [CONTRACT_B]: "0x3",
67
+ });
68
+ yield secondWait;
69
+ expect(parent.getBalance(CONTRACT_A)).toBe("0x2");
70
+ expect(parent.getBalance(CONTRACT_B)).toBe("0x3");
71
+ }));
72
+ it("starts a rebuilt query while serving a last known balance", () => __awaiter(void 0, void 0, void 0, function* () {
73
+ const parent = new erc20_balance_batch_1.ObservableQueryEthereumERC20BalancesBatchParent(new stores_1.QuerySharedContext(new common_1.MemoryKVStore("erc20-balance-batch-test"), {
74
+ responseDebounceMs: 0,
75
+ }), "eip155:1", mockChainGetter(), ADDRESS);
76
+ parent.addContract(CONTRACT_A);
77
+ const firstWait = parent.waitFreshResponse();
78
+ yield waitForPendingFetches(pendingFetches, 1);
79
+ resolveFetch(pendingFetches[0], {
80
+ [CONTRACT_A]: "0x1",
81
+ });
82
+ yield firstWait;
83
+ parent.removeContract(CONTRACT_A);
84
+ yield wait(250);
85
+ parent.addContract(CONTRACT_A);
86
+ yield wait(250);
87
+ const disposers = [
88
+ (0, mobx_1.autorun)(() => parent.getBalance(CONTRACT_A)),
89
+ (0, mobx_1.autorun)(() => parent.getError(CONTRACT_A)),
90
+ (0, mobx_1.autorun)(() => parent.isFetchingContract(CONTRACT_A)),
91
+ ];
92
+ yield waitForPendingFetches(pendingFetches, 2);
93
+ expect(parent.getBalance(CONTRACT_A)).toBe("0x1");
94
+ resolveFetch(pendingFetches[1], {
95
+ [CONTRACT_A]: "0x2",
96
+ });
97
+ yield waitForCondition(() => parent.getBalance(CONTRACT_A) === "0x2");
98
+ expect(parent.getBalance(CONTRACT_A)).toBe("0x2");
99
+ disposers.forEach((dispose) => dispose());
100
+ }));
101
+ });
102
+ function mockChainGetter() {
103
+ return {
104
+ getModularChain() {
105
+ return {
106
+ unwrapped: {
107
+ type: "evm",
108
+ evm: {
109
+ rpc: "https://rpc.example",
110
+ },
111
+ },
112
+ };
113
+ },
114
+ hasModularChain() {
115
+ return true;
116
+ },
117
+ };
118
+ }
119
+ function resolveFetch(fetch, results) {
120
+ fetch.resolve({
121
+ headers: {},
122
+ data: fetch.body.map((req) => {
123
+ var _a;
124
+ return ({
125
+ jsonrpc: "2.0",
126
+ id: req.id,
127
+ result: (_a = results[req.id]) !== null && _a !== void 0 ? _a : "0x0",
128
+ });
129
+ }),
130
+ });
131
+ }
132
+ function waitForPendingFetches(pendingFetches, count) {
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ const startedAt = Date.now();
135
+ while (pendingFetches.length < count) {
136
+ if (Date.now() - startedAt > 2000) {
137
+ throw new Error(`Timed out waiting for ${count} fetches`);
138
+ }
139
+ yield new Promise((resolve) => setTimeout(resolve, 10));
140
+ }
141
+ });
142
+ }
143
+ function wait(ms) {
144
+ return new Promise((resolve) => setTimeout(resolve, ms));
145
+ }
146
+ function waitForCondition(fn) {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ const startedAt = Date.now();
149
+ while (!fn()) {
150
+ if (Date.now() - startedAt > 2000) {
151
+ throw new Error("Timed out waiting for condition");
152
+ }
153
+ yield wait(10);
154
+ }
155
+ });
156
+ }
157
+ //# sourceMappingURL=erc20-balance-batch.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erc20-balance-batch.spec.js","sourceRoot":"","sources":["../../src/queries/erc20-balance-batch.spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iDAAqD;AACrD,6DAAyD;AACzD,iDAAuE;AACvE,+BAA+B;AAC/B,+DAAwF;AAExF,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACrC,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAChC,0CAA0C,CAC3C,CAAC;IACF,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAC9B,iDAAiD,CAClD,CAAC;IACF,OAAO;QACL,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;QAC9C,2BAA2B,EAAE,KAAK,CAAC,2BAA2B;KAC/D,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,IAAI,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,4BAA4B,CAAC,CAAC;IAChE,uCACK,MAAM,KACT,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE,IACtB;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,OAAO,GAAG,4CAA4C,CAAC;AAC7D,MAAM,UAAU,GAAG,4CAA4C,CAAC;AAChE,MAAM,UAAU,GAAG,4CAA4C,CAAC;AAOhE,QAAQ,CAAC,iDAAiD,EAAE,GAAG,EAAE;IAC/D,IAAI,cAA8B,CAAC;IAEnC,UAAU,CAAC,GAAG,EAAE;QACd,cAAc,GAAG,EAAE,CAAC;QACnB,0BAAyB,CAAC,kBAAkB,CAC3C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AG,EAAE,EAAE;;YAAC,OAAA,CAAC;gBAC7B,OAAO,EAAE,KAAK;gBACd,EAAE,EAAE,GAAG,CAAC,EAAE;gBACV,MAAM,EAAE,MAAA,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,mCAAI,KAAK;aACjC,CAAC,CAAA;SAAA,CAAC;KACJ,CAAC,CAAC;AACL,CAAC;AAED,SAAe,qBAAqB,CAClC,cAA8B,EAC9B,KAAa;;QAEb,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,OAAO,cAAc,CAAC,MAAM,GAAG,KAAK,EAAE;YACpC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,IAAI,EAAE;gBACjC,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,UAAU,CAAC,CAAC;aAC3D;YACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;SACzD;IACH,CAAC;CAAA;AAED,SAAS,IAAI,CAAC,EAAU;IACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,SAAe,gBAAgB,CAAC,EAAiB;;QAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,OAAO,CAAC,EAAE,EAAE,EAAE;YACZ,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,IAAI,EAAE;gBACjC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;aACpD;YACD,MAAM,IAAI,CAAC,EAAE,CAAC,CAAC;SAChB;IACH,CAAC;CAAA"}
@@ -1,18 +1,33 @@
1
- import { BalanceRegistry, ChainGetter, IObservableQueryBalanceImpl, QuerySharedContext } from "@keplr-wallet/stores";
1
+ import { BalanceRegistry, ChainGetter, IObservableQueryBalanceImpl, QueryError, QueryResponse, QuerySharedContext } from "@keplr-wallet/stores";
2
2
  import { AppCurrency } from "@keplr-wallet/types";
3
3
  import { CoinPretty } from "@keplr-wallet/unit";
4
4
  import { DenomHelper } from "@keplr-wallet/common";
5
- import { ObservableEvmChainJsonRpcQuery } from "./evm-chain-json-rpc";
6
- export declare class ObservableQueryEthereumERC20BalanceImpl extends ObservableEvmChainJsonRpcQuery<string> implements IObservableQueryBalanceImpl {
5
+ import { ObservableQueryEthereumERC20BalancesBatchParent } from "./erc20-balance-batch";
6
+ import { ERC20BalanceBatchParentStore } from "./erc20-batch-parent-store";
7
+ export declare class ObservableQueryEthereumERC20BalanceImpl implements IObservableQueryBalanceImpl {
8
+ protected readonly parent: ObservableQueryEthereumERC20BalancesBatchParent;
9
+ protected readonly chainId: string;
10
+ protected readonly chainGetter: ChainGetter;
7
11
  protected readonly denomHelper: DenomHelper;
8
- protected readonly ethereumHexAddress: string;
9
12
  protected readonly contractAddress: string;
10
- constructor(sharedContext: QuerySharedContext, chainId: string, chainGetter: ChainGetter, denomHelper: DenomHelper, ethereumHexAddress: string, contractAddress: string);
13
+ protected _observedProps: number;
14
+ constructor(parent: ObservableQueryEthereumERC20BalancesBatchParent, chainId: string, chainGetter: ChainGetter, denomHelper: DenomHelper, contractAddress: string);
11
15
  get balance(): CoinPretty;
12
16
  get currency(): AppCurrency;
17
+ get isFetching(): boolean;
18
+ get isObserved(): boolean;
19
+ get isStarted(): boolean;
20
+ get error(): QueryError<unknown> | undefined;
21
+ get response(): Readonly<QueryResponse<unknown>> | undefined;
22
+ protected ensureFetched(): Promise<void>;
23
+ protected isCurrencyRegistered(): boolean;
24
+ fetch(): Promise<void>;
25
+ waitFreshResponse(): Promise<Readonly<QueryResponse<unknown>> | undefined>;
26
+ waitResponse(): Promise<Readonly<QueryResponse<unknown>> | undefined>;
13
27
  }
14
28
  export declare class ObservableQueryEthereumERC20BalanceRegistry implements BalanceRegistry {
15
29
  protected readonly sharedContext: QuerySharedContext;
16
- constructor(sharedContext: QuerySharedContext);
30
+ protected readonly batchParentStore: ERC20BalanceBatchParentStore;
31
+ constructor(sharedContext: QuerySharedContext, batchParentStore: ERC20BalanceBatchParentStore);
17
32
  getBalanceImpl(chainId: string, chainGetter: ChainGetter, address: string, minimalDenom: string): IObservableQueryBalanceImpl | undefined;
18
33
  }