@mysten/kiosk 1.0.0 → 1.1.0

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/src/utils.ts CHANGED
@@ -5,12 +5,9 @@ import { bcs } from '@mysten/sui/bcs';
5
5
  import { PaginationArguments } from '@mysten/sui/jsonRpc';
6
6
  import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
7
7
  import { normalizeStructTag, normalizeSuiAddress, parseStructTag } from '@mysten/sui/utils';
8
- import { chunk } from '@mysten/utils';
9
8
 
10
- import { Listing, Lock, Kiosk as KioskStruct } from './contracts/0x2/kiosk.js';
11
- import type { Kiosk, KioskData, KioskListing } from './types/index.js';
12
-
13
- const DEFAULT_QUERY_LIMIT = 50;
9
+ import { Item, Listing, Lock, Kiosk as KioskStruct } from './contracts/0x2/kiosk.js';
10
+ import type { Kiosk, KioskData, KioskListing, ObjectWithDisplay } from './types/index.js';
14
11
 
15
12
  export type DynamicFieldInfo = SuiClientTypes.ListDynamicFieldsResponse['dynamicFields'][number];
16
13
 
@@ -53,9 +50,10 @@ export function extractKioskData(
53
50
  baseType ===
54
51
  '0x0000000000000000000000000000000000000000000000000000000000000002::kiosk::Item'
55
52
  ) {
56
- acc.itemIds.push(val.fieldId);
53
+ const parsed = Item.parse(val.name.bcs);
54
+ acc.itemIds.push(parsed.id);
57
55
  acc.items.push({
58
- objectId: val.fieldId,
56
+ objectId: parsed.id,
59
57
  type: val.valueType,
60
58
  isLocked: false,
61
59
  kioskId,
@@ -137,9 +135,9 @@ export function attachListingsAndPrices(
137
135
  * A helper that attaches object data to kiosk items.
138
136
  * Works with core API objects that contain BCS content.
139
137
  */
140
- export function attachObjects(kioskData: KioskData, objects: SuiClientTypes.Object[]) {
141
- const mapping = objects.reduce<Record<string, SuiClientTypes.Object>>(
142
- (acc: Record<string, SuiClientTypes.Object>, obj) => {
138
+ export function attachObjects(kioskData: KioskData, objects: ObjectWithDisplay[]) {
139
+ const mapping = objects.reduce<Record<string, ObjectWithDisplay>>(
140
+ (acc: Record<string, ObjectWithDisplay>, obj) => {
143
141
  acc[obj.objectId] = obj;
144
142
  return acc;
145
143
  },
@@ -200,34 +198,6 @@ export async function getAllDynamicFields(
200
198
  return data;
201
199
  }
202
200
 
203
- /**
204
- * A helper to fetch all objects that works with pagination.
205
- * It will fetch all objects in the array, and limit it to 50/request.
206
- * Requests are sent using `Promise.all`.
207
- */
208
- export async function getAllObjects(
209
- client: ClientWithCoreApi,
210
- ids: string[],
211
- ): Promise<SuiClientTypes.Object[]> {
212
- const chunks = chunk(ids, DEFAULT_QUERY_LIMIT);
213
-
214
- const results = await Promise.all(
215
- chunks.map(async (objectIds) => {
216
- const { objects } = await client.core.getObjects({
217
- objectIds,
218
- include: {
219
- content: true,
220
- previousTransaction: true,
221
- },
222
- });
223
-
224
- return objects.filter((obj): obj is SuiClientTypes.Object => !(obj instanceof Error));
225
- }),
226
- );
227
-
228
- return results.flat();
229
- }
230
-
231
201
  /**
232
202
  * Converts a number to basis points.
233
203
  * Supports up to 2 decimal points.