polkamarkets-js 3.1.0 → 3.1.1
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/package.json
CHANGED
|
@@ -168,7 +168,26 @@ class PredictionMarketV3Contract extends PredictionMarketV2Contract {
|
|
|
168
168
|
// should be non-blocking
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
const
|
|
171
|
+
const chunkSize = 250;
|
|
172
|
+
let userMarketsData;
|
|
173
|
+
|
|
174
|
+
// chunking data to avoid out of gas errors
|
|
175
|
+
const marketIndex = await this.getMarketIndex();
|
|
176
|
+
|
|
177
|
+
if (marketIndex > chunkSize) {
|
|
178
|
+
const chunks = Math.ceil(marketIndex / chunkSize);
|
|
179
|
+
const promises = Array.from({ length: chunks }, async (_, i) => {
|
|
180
|
+
const marketIds = Array.from({ length: chunkSize }, (_, j) => i * chunkSize + j).filter(id => id < marketIndex);
|
|
181
|
+
const chunkMarketData = await this.querier.getUserMarketsData({ user, marketIds });
|
|
182
|
+
return chunkMarketData;
|
|
183
|
+
});
|
|
184
|
+
const chunksData = await Promise.all(promises);
|
|
185
|
+
// concatenating all arrays into a single one
|
|
186
|
+
userMarketsData = chunksData.reduce((obj, chunk) => [...obj, ...chunk], []);
|
|
187
|
+
} else {
|
|
188
|
+
userMarketsData = await this.querier.getUserAllMarketsData({ user });
|
|
189
|
+
}
|
|
190
|
+
|
|
172
191
|
const marketIds = Object.keys(userMarketsData).map(Number);
|
|
173
192
|
// fetching all markets decimals asynchrounously
|
|
174
193
|
const marketDecimals = await Promise.all(marketIds.map(marketId => this.getMarketDecimals({ marketId })));
|
|
@@ -228,6 +247,10 @@ class PredictionMarketV3Contract extends PredictionMarketV2Contract {
|
|
|
228
247
|
false,
|
|
229
248
|
);
|
|
230
249
|
}
|
|
250
|
+
|
|
251
|
+
async getMarketIndex() {
|
|
252
|
+
return parseInt(await this.getContract().methods.marketIndex().call());
|
|
253
|
+
}
|
|
231
254
|
}
|
|
232
255
|
|
|
233
256
|
module.exports = PredictionMarketV3Contract;
|
|
@@ -8,12 +8,12 @@ class PredictionMarketV3QuerierContract extends IContract {
|
|
|
8
8
|
this.contractName = 'PredictionMarketV3Querier';
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
async
|
|
12
|
-
return await this.params.contract.getContract().methods.getUserMarketData(
|
|
11
|
+
async getUserMarketData({ user, marketId }) {
|
|
12
|
+
return await this.params.contract.getContract().methods.getUserMarketData(marketId, user).call();
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async getUserMarketsData({ user, marketIds }) {
|
|
16
|
-
return await this.params.contract.getContract().methods.getUserMarketsData(
|
|
16
|
+
return await this.params.contract.getContract().methods.getUserMarketsData(marketIds, user).call();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
async getUserAllMarketsData({ user }) {
|