Skip to content

Commit

Permalink
fixed issues with itemType
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed Feb 22, 2023
1 parent 9fe38b1 commit eaa3a83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
20 changes: 11 additions & 9 deletions src/mappings/diamond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export function handleUseConsumables(event: UseConsumables): void {
let itemTypes = event.params._itemIds;
let quantities = event.params._quantities;
for (let i = 0; i < event.params._itemIds.length; i++) {
let itemType = getOrCreateItemType(itemTypes[i].toString());
let itemType = getOrCreateItemType(itemTypes[i].toString())!;
itemType.consumed = itemType.consumed.plus(quantities[i]);
itemType.save();
}
Expand Down Expand Up @@ -766,7 +766,9 @@ export function handleERC1155ListingRemoved(
//ERC1155 Item Types

export function handleAddItemType(event: AddItemType): void {
let itemType = getOrCreateItemType(event.params._itemType.svgId.toString());
let itemType = getOrCreateItemType(
event.params._itemType.svgId.toString()
)!;

let itemInfo = event.params._itemType;

Expand Down Expand Up @@ -800,7 +802,7 @@ export function handleItemTypeMaxQuantity(event: ItemTypeMaxQuantity): void {
let itemId = itemIds[index];
let maxQuantity = quantities[index];

let itemType = getOrCreateItemType(itemId.toString());
let itemType = getOrCreateItemType(itemId.toString())!;
itemType.maxQuantity = maxQuantity;
itemType.save();
}
Expand All @@ -816,7 +818,7 @@ export function handlePurchaseItemsWithGhst(
let itemId = itemIds[index];
let quantity = quantities[index];

let itemType = getOrCreateItemType(itemId.toString());
let itemType = getOrCreateItemType(itemId.toString())!;
itemType.totalQuantity = itemType.totalQuantity.plus(quantity);
itemType.save();
}
Expand All @@ -832,7 +834,7 @@ export function handlePurchaseItemsWithVouchers(
let itemId = itemIds[index];
let quantity = quantities[index];

let itemType = getOrCreateItemType(itemId.toString());
let itemType = getOrCreateItemType(itemId.toString())!;
itemType.totalQuantity = itemType.totalQuantity.plus(quantity);
itemType.save();
}
Expand All @@ -846,7 +848,7 @@ export function handleMigrateVouchers(event: MigrateVouchers): void {
let itemId = itemIds[index];
let quantity = quantities[index];

let itemType = getOrCreateItemType(itemId.toString());
let itemType = getOrCreateItemType(itemId.toString())!;
itemType.totalQuantity = itemType.totalQuantity.plus(quantity);
itemType.save();
}
Expand Down Expand Up @@ -877,7 +879,7 @@ export function handleUpdateWearableSet(event: UpdateWearableSet): void {
}

export function handleItemModifiersSet(event: ItemModifiersSet): void {
let itemType = getOrCreateItemType(event.params._wearableId.toString());
let itemType = getOrCreateItemType(event.params._wearableId.toString())!;
itemType.traitModifiers = event.params._traitModifiers;
itemType.rarityScoreModifier = event.params._rarityScoreModifier;
itemType.save();
Expand All @@ -886,7 +888,7 @@ export function handleItemModifiersSet(event: ItemModifiersSet): void {
export function handleWearableSlotPositionsSet(
event: WearableSlotPositionsSet
): void {
let itemType = getOrCreateItemType(event.params._wearableId.toString());
let itemType = getOrCreateItemType(event.params._wearableId.toString())!;
itemType.slotPositions = event.params._slotPositions;
itemType.save();
}
Expand Down Expand Up @@ -928,7 +930,7 @@ export function handleERC1155ListingUpdated(event: UpdateERC1155Listing): void {
}

export function handleUpdateItemPrice(event: UpdateItemPrice): void {
let item = getOrCreateItemType(event.params._itemId.toString());
let item = getOrCreateItemType(event.params._itemId.toString())!;
item.ghstPrice = event.params._priceInWei;
item.save();
}
Expand Down
11 changes: 5 additions & 6 deletions src/utils/helpers/diamond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ export function getOrCreateERC1155Purchase(
export function getOrCreateItemType(
id: string,
createIfNotFound: boolean = true
): ItemType {
): ItemType | null {
let itemType = ItemType.load(id);

if (itemType == null && createIfNotFound) {
itemType = new ItemType(id);
itemType.consumed = BIGINT_ZERO;
}

return itemType as ItemType;
return itemType;
}

export function getOrCreateWearableSet(
Expand Down Expand Up @@ -300,12 +300,11 @@ export function updateERC1155ListingInfo(
false
);

if (itemType) {
listing.rarityLevel = itemMaxQuantityToRarity(
itemType.maxQuantity
);
if (!itemType) {
return listing;
}

listing.rarityLevel = itemMaxQuantityToRarity(itemType.maxQuantity);
// brs modifier
listing.rarityScoreModifier = BigInt.fromI32(
itemType.rarityScoreModifier
Expand Down

0 comments on commit eaa3a83

Please sign in to comment.