Skip to content

Commit

Permalink
Merge branch 'master' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
LautaroPetaccio committed Sep 23, 2021
2 parents f66d73a + f1ccf55 commit 823cbd3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/lib/api/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,14 @@ export class BuilderAPI extends BaseAPI {
}
}

async fetchAssetPacks() {
const remotePacks: RemoteAssetPack[] = await this.request('get', `/assetPacks`)
return remotePacks.map(fromRemoteAssetPack)
async fetchAssetPacks(address?: string): Promise<FullAssetPack[]> {
const promisesOfRemoteAssetPacks: Array<Promise<RemoteAssetPack[]>> = [this.request('get', '/assetPacks?owner=default')]
if (address) {
promisesOfRemoteAssetPacks.push(this.request('get', `/assetPacks?owner=${address}`))
}

const assetPacks: RemoteAssetPack[][] = await Promise.all(promisesOfRemoteAssetPacks)
return assetPacks.reduce((acc, curr) => acc.concat(curr), []).map(fromRemoteAssetPack)
}

async deleteAssetPack(assetPack: FullAssetPack) {
Expand Down
4 changes: 3 additions & 1 deletion src/modules/assetPack/sagas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { call, put, takeLatest, all, select } from 'redux-saga/effects'

import { getData as getWallet } from 'decentraland-dapps/dist/modules/wallet/selectors'
import {
LOAD_ASSET_PACKS_REQUEST,
loadAssetPacksSuccess,
Expand Down Expand Up @@ -44,7 +45,8 @@ export function* assetPackSaga(builder: BuilderAPI) {

function* handleLoadAssetPacks(_: LoadAssetPacksRequestAction) {
try {
const assetPacks: FullAssetPack[] = yield call(() => builder.fetchAssetPacks())
const wallet: ReturnType<typeof getWallet> = yield select(getWallet)
const assetPacks: FullAssetPack[] = yield call([builder, 'fetchAssetPacks'], wallet?.address)
yield put(loadAssetPacksSuccess(assetPacks))
} catch (error) {
yield put(loadAssetPacksFailure(error.message))
Expand Down

0 comments on commit 823cbd3

Please sign in to comment.