Skip to content

Commit

Permalink
Merge pull request #6 from decentraland/fix/check-inventory-against-w…
Browse files Browse the repository at this point in the history
…earables-api

fix: check inventory against wearable api
  • Loading branch information
HPrivakos authored Feb 16, 2021
2 parents 7f7f103 + 84d6818 commit 7ad3082
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/avatar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ export async function getUserInfo(address?: eth.Address) {
*/
export async function getUserInventory(address?: eth.Address) {
if (!address) address = await getUserAccount()
const profile = await getUserInfo(address)
return profile.metadata.avatars[0].inventory
const response = await fetch(`https://wearable-api.decentraland.org/v2/addresses/${address}/wearables?fields=id`)
const inventory: { id: string }[] = await response.json()
return inventory.map((wearable) => wearable.id)
}

/**
Expand All @@ -44,7 +45,8 @@ export async function itemInInventory(wearable: string, equiped: boolean = false
if (item == wearable) return true
}
} else {
for (const item of profile.metadata.avatars[0].inventory) {
const inventory = await getUserInventory()
for (const item of inventory) {
if (item == wearable) return true
}
}
Expand All @@ -64,7 +66,8 @@ export async function itemsInInventory(wearables: string[], equiped: boolean = f
if (wearables.indexOf(item) != -1) return true
}
} else {
for (const item of profile.metadata.avatars[0]?.inventory) {
const inventory = await getUserInventory()
for (const item of inventory) {
if (wearables.indexOf(item) != -1) return true
}
}
Expand Down

0 comments on commit 7ad3082

Please sign in to comment.