Skip to content

Commit

Permalink
Merge pull request #256 from logion-network/fix/items-order
Browse files Browse the repository at this point in the history
fix: order of collection items is determined by backend.
  • Loading branch information
gdethier authored May 2, 2024
2 parents 7d142ce + 48eb060 commit a98eb02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@logion/client",
"version": "0.43.1-1",
"version": "0.43.1-2",
"description": "logion SDK for client applications",
"main": "dist/index.js",
"packageManager": "yarn@3.2.0",
Expand Down
18 changes: 12 additions & 6 deletions packages/client/src/LocClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,15 +612,21 @@ export abstract class LocClient {
const { locId } = parameters;
const onchainItems = await this.nodeApi.queries.getCollectionItems(locId);

const onchainItemsMap: Record<string, CollectionItem> = {};
for(const item of onchainItems) {
onchainItemsMap[item.id.toHex()] = item;
}

try {
const result: UploadableCollectionItem[] = [];
const offchainItems = await this.getOffchainItems({ locId });

const offchainItemsMap: Record<string, OffchainCollectionItem> = {};
for(const item of offchainItems) {
offchainItemsMap[item.itemId] = item;
for(const offchainItem of offchainItems) {
const onchainItem = onchainItemsMap[offchainItem.itemId];
if (onchainItem) {
result.push(this.mergeItems(onchainItem, offchainItem))
}
}

return onchainItems.map(item => this.mergeItems(item, offchainItemsMap[item.id.toHex()]));
return result;
} catch(e) {
throw newBackendError(e);
}
Expand Down

0 comments on commit a98eb02

Please sign in to comment.