Skip to content

Commit

Permalink
feat: Fetch default & created by the user asset packs (#1579)
Browse files Browse the repository at this point in the history
  • Loading branch information
LautaroPetaccio committed Sep 23, 2021
1 parent a013996 commit f1ccf55
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

1 comment on commit f1ccf55

@vercel
Copy link

@vercel vercel bot commented on f1ccf55 Sep 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.