Skip to content

Commit

Permalink
861, remove extra tokensList reassignment
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoElement committed Dec 28, 2024
1 parent 1d46ef8 commit 83bb136
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,15 @@ export class TokensListBuilder {
constructor(
private readonly tokensStoreService: TokensStoreService,
private readonly assetsSelectorService: AssetsSelectorService,
private readonly swapFormService: SwapsFormService,
listType: TokensListType
) {
this.initList(listType);
}
private readonly swapFormService: SwapsFormService
) {}

/**
* Use at the beggining of builder, if you work directly with tokenList
*/
public useCustomList(tokensList: List<TokenAmount>): TokensListBuilder {
this.tempTokensList = this.addAvailableFavoriteFields(tokensList);
return this;
}
public initList(listType: TokensListType, tokensList?: List<TokenAmount>): TokensListBuilder {
if (tokensList) {
this.tempTokensList = this.addAvailableFavoriteFields(tokensList);
return this;
}

private initList(listType: TokensListType): TokensListBuilder {
if (listType === 'favorite') {
this.tempTokensList = this.addAvailableFavoriteFields(this.tokensStoreService.favoriteTokens);
} else if (this.assetsSelectorService.assetType === 'allChains') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,10 @@ export class TokensListStoreService {
const tlb = new TokensListBuilder(
this.tokensStoreService,
this.assetsSelectorService,
this.swapFormService,
this.listType
this.swapFormService
);

return tlb.useCustomList(backendTokens).applySortByComparator().toArray();
return tlb.initList(this.listType, backendTokens).applySortByComparator().toArray();
}
return [];
})
Expand Down Expand Up @@ -282,12 +281,15 @@ export class TokensListStoreService {
const tlb = new TokensListBuilder(
this.tokensStoreService,
this.assetsSelectorService,
this.swapFormService,
this.listType
this.swapFormService
);

if (this.assetsSelectorService.assetType === 'allChains') {
return tlb.applyFilterBySearchQueryOnClient(query).applySortByComparator().toArray();
return tlb
.initList(this.listType)
.applyFilterBySearchQueryOnClient(query)
.applySortByComparator()
.toArray();
}

return tlb
Expand All @@ -304,15 +306,18 @@ export class TokensListStoreService {
const tlb = new TokensListBuilder(
this.tokensStoreService,
this.assetsSelectorService,
this.swapFormService,
this.listType
this.swapFormService
);

if (this.assetsSelectorService.assetType === 'allChains') {
return tlb.applySortByComparator().toArray();
return tlb.initList(this.listType).applySortByComparator().toArray();
}

return tlb.applyFilterByChain(this.blockchain).applySortByComparator().toArray();
return tlb
.initList(this.listType)
.applyFilterByChain(this.blockchain)
.applySortByComparator()
.toArray();
}

private isTokenFavorite(token: BlockchainToken): boolean {
Expand Down

0 comments on commit 83bb136

Please sign in to comment.