@keplr-wallet/stores-eth 0.13.32 → 0.13.34
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/build/queries/erc20-balance-batch.d.ts +26 -0
- package/build/queries/erc20-balance-batch.js +262 -0
- package/build/queries/erc20-balance-batch.js.map +1 -0
- package/build/queries/erc20-balance-batch.spec.d.ts +1 -0
- package/build/queries/erc20-balance-batch.spec.js +157 -0
- package/build/queries/erc20-balance-batch.spec.js.map +1 -0
- package/build/queries/erc20-balance.d.ts +21 -6
- package/build/queries/erc20-balance.js +118 -27
- package/build/queries/erc20-balance.js.map +1 -1
- package/build/queries/erc20-balance.spec.d.ts +1 -0
- package/build/queries/erc20-balance.spec.js +90 -0
- package/build/queries/erc20-balance.spec.js.map +1 -0
- package/build/queries/erc20-balances.d.ts +18 -4
- package/build/queries/erc20-balances.js +200 -25
- package/build/queries/erc20-balances.js.map +1 -1
- package/build/queries/erc20-balances.spec.d.ts +1 -0
- package/build/queries/erc20-balances.spec.js +150 -0
- package/build/queries/erc20-balances.spec.js.map +1 -0
- package/build/queries/erc20-batch-parent-store.d.ts +8 -0
- package/build/queries/erc20-batch-parent-store.js +21 -0
- package/build/queries/erc20-batch-parent-store.js.map +1 -0
- package/build/queries/index.d.ts +1 -3
- package/build/queries/index.js +6 -5
- package/build/queries/index.js.map +1 -1
- package/jest.config.js +8 -1
- package/package.json +8 -8
- package/src/queries/erc20-balance-batch.spec.ts +192 -0
- package/src/queries/erc20-balance-batch.ts +273 -0
- package/src/queries/erc20-balance.spec.ts +129 -0
- package/src/queries/erc20-balance.ts +122 -36
- package/src/queries/erc20-balances.spec.ts +194 -0
- package/src/queries/erc20-balances.ts +220 -37
- package/src/queries/erc20-batch-parent-store.ts +28 -0
- package/src/queries/index.ts +8 -15
|
@@ -5,6 +5,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
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
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
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
|
+
};
|
|
8
17
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
19
|
};
|
|
@@ -13,56 +22,137 @@ exports.ObservableQueryEthereumERC20BalanceRegistry = exports.ObservableQueryEth
|
|
|
13
22
|
const unit_1 = require("@keplr-wallet/unit");
|
|
14
23
|
const mobx_1 = require("mobx");
|
|
15
24
|
const big_integer_1 = __importDefault(require("big-integer"));
|
|
16
|
-
const constants_1 = require("../constants");
|
|
17
25
|
const common_1 = require("@keplr-wallet/common");
|
|
18
26
|
const account_1 = require("../account");
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
to: contractAddress,
|
|
25
|
-
data: constants_1.erc20ContractInterface.encodeFunctionData("balanceOf", [
|
|
26
|
-
ethereumHexAddress,
|
|
27
|
-
]),
|
|
28
|
-
},
|
|
29
|
-
"latest",
|
|
30
|
-
]);
|
|
27
|
+
class ObservableQueryEthereumERC20BalanceImpl {
|
|
28
|
+
constructor(parent, chainId, chainGetter, denomHelper, contractAddress) {
|
|
29
|
+
this.parent = parent;
|
|
30
|
+
this.chainId = chainId;
|
|
31
|
+
this.chainGetter = chainGetter;
|
|
31
32
|
this.denomHelper = denomHelper;
|
|
32
|
-
this.ethereumHexAddress = ethereumHexAddress;
|
|
33
33
|
this.contractAddress = contractAddress;
|
|
34
|
+
this._observedProps = 0;
|
|
34
35
|
(0, mobx_1.makeObservable)(this);
|
|
36
|
+
// Readiness gates (hooks-evm) can early-return on `response` before
|
|
37
|
+
// reading `balance`, so either property being observed must register
|
|
38
|
+
// the contract into the shared batch parent.
|
|
39
|
+
const attach = (prop) => {
|
|
40
|
+
(0, mobx_1.onBecomeObserved)(this, prop, () => {
|
|
41
|
+
(0, mobx_1.runInAction)(() => {
|
|
42
|
+
this._observedProps += 1;
|
|
43
|
+
});
|
|
44
|
+
if (this._observedProps === 1) {
|
|
45
|
+
this.parent.addContract(contractAddress);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
(0, mobx_1.onBecomeUnobserved)(this, prop, () => {
|
|
49
|
+
(0, mobx_1.runInAction)(() => {
|
|
50
|
+
this._observedProps -= 1;
|
|
51
|
+
});
|
|
52
|
+
if (this._observedProps === 0) {
|
|
53
|
+
this.parent.removeContract(contractAddress);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
attach("balance");
|
|
58
|
+
attach("response");
|
|
59
|
+
attach("error");
|
|
35
60
|
}
|
|
36
61
|
get balance() {
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
.findCurrency(denom);
|
|
41
|
-
if (!currency) {
|
|
42
|
-
throw new Error(`Unknown currency: ${this.contractAddress}`);
|
|
43
|
-
}
|
|
44
|
-
if (!this.response || !this.response.data) {
|
|
62
|
+
const currency = this.currency;
|
|
63
|
+
const raw = this.parent.getBalance(this.contractAddress);
|
|
64
|
+
if (raw === undefined) {
|
|
45
65
|
return new unit_1.CoinPretty(currency, new unit_1.Int(0)).ready(false);
|
|
46
66
|
}
|
|
47
|
-
return new unit_1.CoinPretty(currency, new unit_1.Int((0, big_integer_1.default)(
|
|
67
|
+
return new unit_1.CoinPretty(currency, new unit_1.Int((0, big_integer_1.default)(raw.replace("0x", ""), 16).toString()));
|
|
48
68
|
}
|
|
49
69
|
get currency() {
|
|
50
|
-
const denom = this.denomHelper.denom;
|
|
51
70
|
return this.chainGetter
|
|
52
71
|
.getModularChain(this.chainId)
|
|
53
|
-
.forceFindCurrency(denom);
|
|
72
|
+
.forceFindCurrency(this.denomHelper.denom);
|
|
73
|
+
}
|
|
74
|
+
get isFetching() {
|
|
75
|
+
return this.parent.isFetching;
|
|
76
|
+
}
|
|
77
|
+
get isObserved() {
|
|
78
|
+
return this._observedProps > 0;
|
|
79
|
+
}
|
|
80
|
+
get isStarted() {
|
|
81
|
+
return this._observedProps > 0;
|
|
82
|
+
}
|
|
83
|
+
get error() {
|
|
84
|
+
return this.parent.getError(this.contractAddress);
|
|
85
|
+
}
|
|
86
|
+
get response() {
|
|
87
|
+
// hooks-evm tx flow gates readiness on truthy `bal.response`. Synthesize
|
|
88
|
+
// from the shared batch parent so the Child advertises fetch completion.
|
|
89
|
+
const raw = this.parent.getBalance(this.contractAddress);
|
|
90
|
+
if (raw === undefined)
|
|
91
|
+
return undefined;
|
|
92
|
+
return {
|
|
93
|
+
data: raw,
|
|
94
|
+
staled: false,
|
|
95
|
+
local: false,
|
|
96
|
+
timestamp: 0,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
ensureFetched() {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
// balanceImplMap doesn't evict on currency removal.
|
|
102
|
+
if (!this.isCurrencyRegistered())
|
|
103
|
+
return;
|
|
104
|
+
// Force temporary registration so imperative callers (outside a reactive
|
|
105
|
+
// observer) still trigger an actual eth_call.
|
|
106
|
+
this.parent.addContract(this.contractAddress);
|
|
107
|
+
try {
|
|
108
|
+
yield this.parent.waitFreshResponse();
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
this.parent.removeContract(this.contractAddress);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
isCurrencyRegistered() {
|
|
116
|
+
const target = common_1.DenomHelper.normalizeDenom(this.denomHelper.denom);
|
|
117
|
+
return this.chainGetter
|
|
118
|
+
.getModularChain(this.chainId)
|
|
119
|
+
.currencies.some((c) => common_1.DenomHelper.normalizeDenom(c.coinMinimalDenom) === target);
|
|
120
|
+
}
|
|
121
|
+
fetch() {
|
|
122
|
+
return this.ensureFetched();
|
|
123
|
+
}
|
|
124
|
+
waitFreshResponse() {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
yield this.ensureFetched();
|
|
127
|
+
return this.response;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
waitResponse() {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
return yield this.waitFreshResponse();
|
|
133
|
+
});
|
|
54
134
|
}
|
|
55
135
|
}
|
|
136
|
+
__decorate([
|
|
137
|
+
mobx_1.observable
|
|
138
|
+
], ObservableQueryEthereumERC20BalanceImpl.prototype, "_observedProps", void 0);
|
|
56
139
|
__decorate([
|
|
57
140
|
mobx_1.computed
|
|
58
141
|
], ObservableQueryEthereumERC20BalanceImpl.prototype, "balance", null);
|
|
59
142
|
__decorate([
|
|
60
143
|
mobx_1.computed
|
|
61
144
|
], ObservableQueryEthereumERC20BalanceImpl.prototype, "currency", null);
|
|
145
|
+
__decorate([
|
|
146
|
+
mobx_1.computed
|
|
147
|
+
], ObservableQueryEthereumERC20BalanceImpl.prototype, "error", null);
|
|
148
|
+
__decorate([
|
|
149
|
+
mobx_1.computed
|
|
150
|
+
], ObservableQueryEthereumERC20BalanceImpl.prototype, "response", null);
|
|
62
151
|
exports.ObservableQueryEthereumERC20BalanceImpl = ObservableQueryEthereumERC20BalanceImpl;
|
|
63
152
|
class ObservableQueryEthereumERC20BalanceRegistry {
|
|
64
|
-
constructor(sharedContext) {
|
|
153
|
+
constructor(sharedContext, batchParentStore) {
|
|
65
154
|
this.sharedContext = sharedContext;
|
|
155
|
+
this.batchParentStore = batchParentStore;
|
|
66
156
|
}
|
|
67
157
|
getBalanceImpl(chainId, chainGetter, address, minimalDenom) {
|
|
68
158
|
const denomHelper = new common_1.DenomHelper(minimalDenom);
|
|
@@ -73,7 +163,8 @@ class ObservableQueryEthereumERC20BalanceRegistry {
|
|
|
73
163
|
(mcInfo.type !== "evm" && mcInfo.type !== "ethermint")) {
|
|
74
164
|
return;
|
|
75
165
|
}
|
|
76
|
-
|
|
166
|
+
const parent = this.batchParentStore.getOrCreate(chainId, chainGetter, address);
|
|
167
|
+
return new ObservableQueryEthereumERC20BalanceImpl(parent, chainId, chainGetter, denomHelper, denomHelper.contractAddress);
|
|
77
168
|
}
|
|
78
169
|
}
|
|
79
170
|
exports.ObservableQueryEthereumERC20BalanceRegistry = ObservableQueryEthereumERC20BalanceRegistry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"erc20-balance.js","sourceRoot":"","sources":["../../src/queries/erc20-balance.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"erc20-balance.js","sourceRoot":"","sources":["../../src/queries/erc20-balance.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AASA,6CAAqD;AACrD,+BAOc;AACd,8DAAqC;AACrC,iDAAmD;AACnD,wCAAiD;AAIjD,MAAa,uCAAuC;IAMlD,YACqB,MAAuD,EACvD,OAAe,EACf,WAAwB,EACxB,WAAwB,EACxB,eAAuB;QAJvB,WAAM,GAAN,MAAM,CAAiD;QACvD,YAAO,GAAP,OAAO,CAAQ;QACf,gBAAW,GAAX,WAAW,CAAa;QACxB,gBAAW,GAAX,WAAW,CAAa;QACxB,oBAAe,GAAf,eAAe,CAAQ;QAPlC,mBAAc,GAAG,CAAC,CAAC;QAS3B,IAAA,qBAAc,EAAC,IAAI,CAAC,CAAC;QAErB,oEAAoE;QACpE,qEAAqE;QACr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O;YAC5B,CAAC,YAAY;YACb,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,CAAC,EACtD;YACA,OAAO;SACR;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAC9C,OAAO,EACP,WAAW,EACX,OAAO,CACR,CAAC;QAEF,OAAO,IAAI,uCAAuC,CAChD,MAAM,EACN,OAAO,EACP,WAAW,EACX,WAAW,EACX,WAAW,CAAC,eAAe,CAC5B,CAAC;IACJ,CAAC;CACF;AAxCD,kGAwCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_1 = require("@keplr-wallet/common");
|
|
4
|
+
const stores_1 = require("@keplr-wallet/stores");
|
|
5
|
+
const erc20_balance_1 = require("./erc20-balance");
|
|
6
|
+
jest.mock("../account", () => ({
|
|
7
|
+
EthereumAccountBase: {
|
|
8
|
+
isEthereumHexAddressWithChecksum: jest.fn(() => true),
|
|
9
|
+
},
|
|
10
|
+
}));
|
|
11
|
+
jest.mock("@keplr-wallet/stores", () => {
|
|
12
|
+
const context = jest.requireActual("../../../stores/src/common/query/context");
|
|
13
|
+
const jsonRpc = jest.requireActual("../../../stores/src/common/query/json-rpc");
|
|
14
|
+
const map = jest.requireActual("../../../stores/src/common/map");
|
|
15
|
+
return {
|
|
16
|
+
QuerySharedContext: context.QuerySharedContext,
|
|
17
|
+
ObservableJsonRPCQuery: jsonRpc.ObservableJsonRPCQuery,
|
|
18
|
+
HasMapStore: map.HasMapStore,
|
|
19
|
+
getKeplrFromWindow: jest.fn(),
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
const ADDRESS = "0x0000000000000000000000000000000000000001";
|
|
23
|
+
const CONTRACT = "0x0000000000000000000000000000000000000002";
|
|
24
|
+
const DENOM = `erc20:${CONTRACT}`;
|
|
25
|
+
const CURRENCY = {
|
|
26
|
+
coinMinimalDenom: DENOM,
|
|
27
|
+
coinDenom: "TEST",
|
|
28
|
+
coinDecimals: 18,
|
|
29
|
+
};
|
|
30
|
+
describe("ObservableQueryEthereumERC20BalanceRegistry", () => {
|
|
31
|
+
it("keeps ethermint ERC20 balances on the shared batch query for hex senders", () => {
|
|
32
|
+
const batchParentStore = mockBatchParentStore();
|
|
33
|
+
const chainGetter = mockChainGetter("ethermint");
|
|
34
|
+
const registry = createRegistry(batchParentStore);
|
|
35
|
+
const impl = registry.getBalanceImpl("injective-1", chainGetter, ADDRESS, DENOM);
|
|
36
|
+
expect(impl).toBeInstanceOf(erc20_balance_1.ObservableQueryEthereumERC20BalanceImpl);
|
|
37
|
+
expect(batchParentStore.getOrCreate).toHaveBeenCalledWith("injective-1", chainGetter, ADDRESS);
|
|
38
|
+
});
|
|
39
|
+
it("keeps pure EVM ERC20 balances on the shared batch query", () => {
|
|
40
|
+
const batchParentStore = mockBatchParentStore();
|
|
41
|
+
const chainGetter = mockChainGetter("evm");
|
|
42
|
+
const registry = createRegistry(batchParentStore);
|
|
43
|
+
const impl = registry.getBalanceImpl("eip155:1", chainGetter, ADDRESS, DENOM);
|
|
44
|
+
expect(impl).toBeInstanceOf(erc20_balance_1.ObservableQueryEthereumERC20BalanceImpl);
|
|
45
|
+
expect(batchParentStore.getOrCreate).toHaveBeenCalledWith("eip155:1", chainGetter, ADDRESS);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
function createRegistry(batchParentStore) {
|
|
49
|
+
return new erc20_balance_1.ObservableQueryEthereumERC20BalanceRegistry(new stores_1.QuerySharedContext(new common_1.MemoryKVStore("erc20-balance-registry-test"), {
|
|
50
|
+
responseDebounceMs: 0,
|
|
51
|
+
}), batchParentStore);
|
|
52
|
+
}
|
|
53
|
+
function mockBatchParentStore() {
|
|
54
|
+
return {
|
|
55
|
+
getOrCreate: jest.fn(() => ({
|
|
56
|
+
addContract: jest.fn(),
|
|
57
|
+
removeContract: jest.fn(),
|
|
58
|
+
waitFreshResponse: jest.fn(),
|
|
59
|
+
getBalance: jest.fn(),
|
|
60
|
+
getError: jest.fn(),
|
|
61
|
+
isFetching: false,
|
|
62
|
+
})),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function mockChainGetter(type) {
|
|
66
|
+
return {
|
|
67
|
+
getModularChain() {
|
|
68
|
+
return {
|
|
69
|
+
type,
|
|
70
|
+
unwrapped: {
|
|
71
|
+
type,
|
|
72
|
+
evm: {
|
|
73
|
+
rpc: "https://rpc.example",
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
currencies: [CURRENCY],
|
|
77
|
+
forceFindCurrency(denom) {
|
|
78
|
+
if (denom === DENOM) {
|
|
79
|
+
return CURRENCY;
|
|
80
|
+
}
|
|
81
|
+
throw new Error(`Unknown currency: ${denom}`);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
hasModularChain() {
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=erc20-balance.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"erc20-balance.spec.js","sourceRoot":"","sources":["../../src/queries/erc20-balance.spec.ts"],"names":[],"mappings":";;AAAA,iDAAqD;AACrD,iDAAuE;AACvE,mDAGyB;AAEzB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7B,mBAAmB,EAAE;QACnB,gCAAgC,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;KACtD;CACF,CAAC,CAAC,CAAC;AAEJ,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACrC,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAChC,0CAA0C,CAC3C,CAAC;IACF,MAAM,OAAO,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AAI,KAAK,KAAK,KAAK,EAAE;wBACnB,OAAO,QAAQ,CAAC;qBACjB;oBACD,MAAM,IAAI,KAAK,CAAC,qBAAqB,KAAK,EAAE,CAAC,CAAC;gBAChD,CAAC;aAC4C,CAAC;QAClD,CAAC;QACD,eAAe;YACb,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { DenomHelper } from "@keplr-wallet/common";
|
|
2
|
+
import { IReactionDisposer } from "mobx";
|
|
2
3
|
import { CoinPretty } from "@keplr-wallet/unit";
|
|
3
4
|
import { AppCurrency } from "@keplr-wallet/types";
|
|
4
5
|
import { BalanceRegistry, ChainGetter, IObservableQueryBalanceImpl, ObservableJsonRPCQuery, QueryError, QueryResponse, QuerySharedContext } from "@keplr-wallet/stores";
|
|
6
|
+
import { ObservableQueryEthereumERC20BalancesBatchParent } from "./erc20-balance-batch";
|
|
7
|
+
import { ERC20BalanceBatchParentStore } from "./erc20-batch-parent-store";
|
|
5
8
|
interface ThirdpartyERC20TokenBalance {
|
|
6
9
|
address: string;
|
|
7
10
|
tokenBalances: {
|
|
@@ -12,39 +15,50 @@ interface ThirdpartyERC20TokenBalance {
|
|
|
12
15
|
message: string;
|
|
13
16
|
} | null;
|
|
14
17
|
}[];
|
|
15
|
-
pageKey
|
|
18
|
+
pageKey?: string;
|
|
16
19
|
}
|
|
17
20
|
export declare class ObservableQueryThirdpartyERC20BalancesImplParent extends ObservableJsonRPCQuery<ThirdpartyERC20TokenBalance> {
|
|
18
21
|
protected readonly chainId: string;
|
|
19
22
|
protected readonly chainGetter: ChainGetter;
|
|
20
23
|
protected readonly ethereumHexAddress: string;
|
|
24
|
+
readonly batchParent: ObservableQueryEthereumERC20BalancesBatchParent;
|
|
21
25
|
duplicatedFetchResolver?: Promise<void>;
|
|
22
|
-
|
|
26
|
+
protected alchemyContractSet: Set<string>;
|
|
27
|
+
constructor(sharedContext: QuerySharedContext, chainId: string, chainGetter: ChainGetter, ethereumHexAddress: string, batchParent: ObservableQueryEthereumERC20BalancesBatchParent);
|
|
23
28
|
protected canFetch(): boolean;
|
|
24
29
|
protected onReceiveResponse(response: Readonly<QueryResponse<ThirdpartyERC20TokenBalance>>): void;
|
|
30
|
+
hasAlchemyBalance(contract: string): boolean;
|
|
31
|
+
getAlchemyTokenBalance(contract: string): ThirdpartyERC20TokenBalance["tokenBalances"][number] | undefined;
|
|
32
|
+
resolvesAlchemyBalance(contract: string): boolean;
|
|
25
33
|
}
|
|
26
34
|
export declare class ObservableQueryThirdpartyERC20BalancesImpl implements IObservableQueryBalanceImpl {
|
|
27
35
|
protected readonly parent: ObservableQueryThirdpartyERC20BalancesImplParent;
|
|
28
36
|
protected readonly chainId: string;
|
|
29
37
|
protected readonly chainGetter: ChainGetter;
|
|
30
38
|
protected readonly denomHelper: DenomHelper;
|
|
39
|
+
protected batchReactionDisposer?: IReactionDisposer;
|
|
40
|
+
protected isInBatch: boolean;
|
|
41
|
+
protected observedProps: number;
|
|
31
42
|
constructor(parent: ObservableQueryThirdpartyERC20BalancesImplParent, chainId: string, chainGetter: ChainGetter, denomHelper: DenomHelper);
|
|
32
43
|
get balance(): CoinPretty;
|
|
33
44
|
get currency(): AppCurrency;
|
|
45
|
+
protected get alchemyResolvesBalance(): boolean;
|
|
34
46
|
get error(): Readonly<QueryError<unknown>> | undefined;
|
|
35
47
|
get isFetching(): boolean;
|
|
36
48
|
get isObserved(): boolean;
|
|
37
49
|
get isStarted(): boolean;
|
|
38
50
|
get response(): Readonly<QueryResponse<ThirdpartyERC20TokenBalance>> | undefined;
|
|
39
51
|
fetch(): Promise<void>;
|
|
52
|
+
protected awaitFallbackIfMissing(): Promise<void>;
|
|
53
|
+
protected isCurrencyRegistered(): boolean;
|
|
40
54
|
waitFreshResponse(): Promise<Readonly<QueryResponse<unknown>> | undefined>;
|
|
41
55
|
waitResponse(): Promise<Readonly<QueryResponse<unknown>> | undefined>;
|
|
42
56
|
}
|
|
43
57
|
export declare class ObservableQueryThirdpartyERC20BalanceRegistry implements BalanceRegistry {
|
|
44
58
|
protected readonly sharedContext: QuerySharedContext;
|
|
45
|
-
protected readonly
|
|
59
|
+
protected readonly batchParentStore: ERC20BalanceBatchParentStore;
|
|
46
60
|
protected parentMap: Map<string, ObservableQueryThirdpartyERC20BalancesImplParent>;
|
|
47
|
-
constructor(sharedContext: QuerySharedContext,
|
|
61
|
+
constructor(sharedContext: QuerySharedContext, batchParentStore: ERC20BalanceBatchParentStore);
|
|
48
62
|
getBalanceImpl(chainId: string, chainGetter: ChainGetter, address: string, minimalDenom: string): ObservableQueryThirdpartyERC20BalancesImpl | undefined;
|
|
49
63
|
}
|
|
50
64
|
export {};
|