Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Boldizsar Mezei committed Nov 8, 2023
1 parent cc18578 commit 429894f
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 68 deletions.
10 changes: 5 additions & 5 deletions src/app/@api/base.api.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { HttpClient } from '@angular/common/http';
import { environment } from '@env/environment';
import {
EthAddress,
NetworkAddress,
PublicCollections,
BUILD5_PROD_ADDRESS_API,
BUILD5_TEST_ADDRESS_API,
WEN_FUNC,
WenRequest,
} from '@build-5/interfaces';
import { Build5Env } from '@build-5/lib';
import { CrudRepository } from '@build-5/lib/lib/repositories/CrudRepository';
import { Build5Env, CrudRepository } from '@build-5/lib';
import { Observable, map, of } from 'rxjs';

export const DEFAULT_LIST_SIZE = 50;
Expand All @@ -29,12 +29,12 @@ export class BaseApi<T> {

public listen = (id: string) => this.repo.getByIdLive(id);

public listenMultiple = (ids: EthAddress[]) =>
public listenMultiple = (ids: NetworkAddress[]) =>
ids.length ? this.repo.getManyByIdLive(ids) : of([]);

public top = (lastValue?: string, limit?: number) => this.repo.getTopLive(lastValue, limit);

protected request<T>(func: WEN_FUNC, req: any): Observable<T | undefined> {
protected request<T>(func: WEN_FUNC, req: WenRequest): Observable<T | undefined> {
const origin = environment.production ? BUILD5_PROD_ADDRESS_API : BUILD5_TEST_ADDRESS_API;
return this.httpClient.post(origin + func, { data: req }).pipe(map((b: any) => b.data));

Check warning on line 39 in src/app/@api/base.api.ts

View workflow job for this annotation

GitHub Actions / front_end_es_lint

Unexpected any. Specify a different type
}
Expand Down
31 changes: 19 additions & 12 deletions src/app/@api/member.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '@env/environment';
import {
EthAddress,
NetworkAddress,
Member,
Proposal,
PublicCollections,
Expand Down Expand Up @@ -74,7 +74,7 @@ export class MemberApi extends BaseApi<Member> {
super(PublicCollections.MEMBER, httpClient);
}

public soonDistributionStats = (id: EthAddress) => {
public soonDistributionStats = (id: NetworkAddress) => {
const tokenId = environment.production ? SOON_TOKEN : SOON_TOKEN_TEST;
return this.tokenDistRepo.getByIdLive(tokenId, id.toLowerCase()).pipe(
switchMap(async (distribution) => {
Expand All @@ -90,7 +90,7 @@ export class MemberApi extends BaseApi<Member> {
) as Observable<TokenDistributionWithAirdrops | undefined>;
};

public listenMultiple = (ids: EthAddress[]) =>
public listenMultiple = (ids: NetworkAddress[]) =>
ids.length
? this.memberRepo
.getByFieldLive(
Expand All @@ -105,7 +105,10 @@ export class MemberApi extends BaseApi<Member> {
)
: of([]);

public topStakes = (memberId: EthAddress, lastValue?: string): Observable<StakeWithTokenRec[]> =>
public topStakes = (
memberId: NetworkAddress,
lastValue?: string,
): Observable<StakeWithTokenRec[]> =>
this.stakeRepo.getByMemberLive(memberId, lastValue).pipe(
switchMap(async (stakes: Stake[]) => {
const tokenIds = Array.from(new Set(stakes.map((s) => s.token)));
Expand All @@ -119,7 +122,7 @@ export class MemberApi extends BaseApi<Member> {
}),
);

public topTokens = (memberId: EthAddress): Observable<TokenWithMemberDistribution[]> =>
public topTokens = (memberId: NetworkAddress): Observable<TokenWithMemberDistribution[]> =>
this.tokenDistRepo.getTopBySubColIdLive(memberId, [], []).pipe(
switchMap(async (distributions) => {
const promises = distributions.map(async (distribution) => {
Expand All @@ -138,28 +141,28 @@ export class MemberApi extends BaseApi<Member> {
);

public topSpaces = (
memberId: EthAddress,
memberId: NetworkAddress,
orderBy = ['createdOn'],
orderByDir = ['desc'],
lastValue?: string,
limit?: number,
) => this.spaceRepo.getTopByMember(memberId, orderBy, orderByDir, lastValue, limit);

public pendingSpaces = (
memberId: EthAddress,
memberId: NetworkAddress,
orderBy = ['createdOn'],
orderByDir = ['desc'],
lastValue?: string,
) => this.spaceRepo.getPendingSpacesByMemberLive(memberId, orderBy, orderByDir, lastValue);

public topAwardsPending = (memberId: EthAddress, lastValue?: string) =>
public topAwardsPending = (memberId: NetworkAddress, lastValue?: string) =>
this.awardRepo.getTopByMemberLive(memberId, false, lastValue);

public topAwardsCompleted = (memberId: EthAddress, lastValue?: string) =>
public topAwardsCompleted = (memberId: NetworkAddress, lastValue?: string) =>
this.awardRepo.getTopByMemberLive(memberId, true, lastValue);

public topProposals = (
memberId: EthAddress,
memberId: NetworkAddress,
orderBy = ['createdOn'],
orderByDir = ['desc'],
lastValue?: string,
Expand Down Expand Up @@ -211,7 +214,7 @@ export class MemberApi extends BaseApi<Member> {
);
}

public allSpacesAsMember = (memberId: EthAddress, lastValue?: string) =>
public allSpacesAsMember = (memberId: NetworkAddress, lastValue?: string) =>
this.spaceMemberRepo.getTopBySubColIdLive(memberId, [], [], lastValue).pipe(
switchMap(async (spaceMembers) => {
const spacePromises = spaceMembers.map(
Expand All @@ -222,7 +225,11 @@ export class MemberApi extends BaseApi<Member> {
);

public createIfNotExists = (address: string): Observable<Member | undefined> =>
this.request(WEN_FUNC.createMember, address);
this.request(WEN_FUNC.createMember, {
address: '',
projectApiKey: environment.build5Token,
body: address,
});

public updateMember = (req: WenRequest): Observable<Member | undefined> =>
this.request(WEN_FUNC.updateMember, req);
Expand Down
4 changes: 2 additions & 2 deletions src/app/@api/order.api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import {
EthAddress,
NetworkAddress,
PublicCollections,
Transaction,
WEN_FUNC,
Expand Down Expand Up @@ -33,7 +33,7 @@ export class OrderApi extends BaseApi<Transaction> {
public openBid = (req: WenRequest): Observable<Transaction | undefined> =>
this.request(WEN_FUNC.openBid, req);

public listenMultiple = (ids: EthAddress[]) =>
public listenMultiple = (ids: NetworkAddress[]) =>
ids.length
? this.transactionRepo.getByFieldLive(
ids.map(() => 'uid'),
Expand Down
4 changes: 2 additions & 2 deletions src/app/@api/proposal.api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import {
EthAddress,
NetworkAddress,
Member,
Proposal,
PublicCollections,
Expand Down Expand Up @@ -53,7 +53,7 @@ export class ProposalApi extends BaseApi<Proposal> {
super(PublicCollections.PROPOSAL, httpClient);
}

public listen = (id: EthAddress) => this.proposalRepo.getByIdLive(id);
public listen = (id: NetworkAddress) => this.proposalRepo.getByIdLive(id);

public lastActive = (lastValue?: string) => this.proposalRepo.getActiveLive(lastValue);

Expand Down
21 changes: 10 additions & 11 deletions src/app/components/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { undefinedToEmpty } from '@core/utils/manipulations.utils';
import { ROUTER_UTILS } from '@core/utils/router.utils';
import detectEthereumProvider from '@metamask/detect-provider';
import {
EthAddress,
NetworkAddress,
Member,
Network,
StakeType,
tiers,
// tiers,
TOKEN_EXPIRY_HOURS,
WenRequest,
} from '@build-5/interfaces';
Expand Down Expand Up @@ -144,14 +144,13 @@ export class AuthService {

this.memberSoonDistribution$.subscribe((v) => {
if (v && (v?.stakes?.[StakeType.DYNAMIC]?.value || 0) > 0) {
let l = -1;
tiers.forEach((a) => {
if ((v?.stakes?.[StakeType.DYNAMIC]?.value || 0) >= a) {
l++;
}
});

this.memberLevel$.next(l);
// let l = -1;
// tiers.forEach((a) => {
// if ((v?.stakes?.[StakeType.DYNAMIC]?.value || 0) >= a) {
// l++;
// }
// });
// this.memberLevel$.next(l);
} else {
this.memberLevel$.next(0);
}
Expand Down Expand Up @@ -418,7 +417,7 @@ export class AuthService {
}
}

public monitorMember(address: EthAddress): void {
public monitorMember(address: NetworkAddress): void {
this.memberSubscription$ = this.memberApi.listen(address).subscribe((v) => {
this.member$.next(v);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class TokenInfoDescriptionComponent {
const distributions = await this.tokenApi.getAllDistributions(this.token?.uid);
const fields = [
'',
'ethAddress',
'NetworkAddress',
'tokenOwned',
'unclaimedTokens',
'tokenClaimed',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
TransactionType,
calcStakedMultiplier,
getDefDecimalIfNotSet,
tiers,
// tiers,
} from '@build-5/interfaces';
import dayjs from 'dayjs';
import { BehaviorSubject, Subscription, interval, merge } from 'rxjs';
Expand Down Expand Up @@ -153,21 +153,21 @@ export class TokenStakeComponent implements OnInit, OnDestroy {
const val =
calcStakedMultiplier(this.weekControl.value) * (this.amountControl.value || 0);
this.stakeControl.setValue(val.toFixed(2));
const newTotal =
(this.auth.memberSoonDistribution$.value?.stakes?.[StakeType.DYNAMIC]?.value || 0) +
Math.pow(10, getDefDecimalIfNotSet(this.token?.decimals)) * val;
let l = 0;
tiers.forEach((a) => {
if (newTotal >= a) {
l++;
}
});

if (l > tiers.length - 1) {
l = tiers.length - 1;
}

this.levelControl.setValue(l);
// const newTotal =
// (this.auth.memberSoonDistribution$.value?.stakes?.[StakeType.DYNAMIC]?.value || 0) +
// Math.pow(10, getDefDecimalIfNotSet(this.token?.decimals)) * val;
// let l = 0;
// tiers.forEach((a) => {
// if (newTotal >= a) {
// l++;
// }
// });

// if (l > tiers.length - 1) {
// l = tiers.length - 1;
// }

// this.levelControl.setValue(l);
this.multiplierControl.setValue(calcStakedMultiplier(this.weekControl.value));
if (this.tokenStats && this.rewards) {
this.earnControl.setValue(
Expand Down
38 changes: 19 additions & 19 deletions src/app/pages/soon-staking/pages/staking/staking.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
TokenStats,
calcStakedMultiplier,
getDefDecimalIfNotSet,
tiers,
// tiers,
} from '@build-5/interfaces';
import { BehaviorSubject, Observable, Subscription, map, merge, of } from 'rxjs';

Expand Down Expand Up @@ -119,21 +119,21 @@ export class StakingPage implements OnInit, OnDestroy {
if ((this.amountControl.value || 0) > 0 && (this.weekControl.value || 0) > 0) {
const val = calcStakedMultiplier(this.weekControl.value) * (this.amountControl.value || 0);
this.stakeControl.setValue(val.toFixed(2));
const newTotal =
(this.auth.memberSoonDistribution$.value?.stakes?.[StakeType.DYNAMIC]?.value || 0) +
Math.pow(10, getDefDecimalIfNotSet(this.token$.value?.decimals)) * val;
let l = -1;
tiers.forEach((a) => {
if (newTotal >= a) {
l++;
}
});
// const newTotal =
// (this.auth.memberSoonDistribution$.value?.stakes?.[StakeType.DYNAMIC]?.value || 0) +
// Math.pow(10, getDefDecimalIfNotSet(this.token$.value?.decimals)) * val;
// let l = -1;
// tiers.forEach((a) => {
// if (newTotal >= a) {
// l++;
// }
// });

if (l > tiers.length) {
l = tiers.length;
}
// if (l > tiers.length) {
// l = tiers.length;
// }

this.levelControl.setValue(l);
// this.levelControl.setValue(l);
this.multiplierControl.setValue(calcStakedMultiplier(this.weekControl.value));
if (this.tokenStats$.value && this.stakeRewards$.value) {
this.earnControl.setValue(
Expand Down Expand Up @@ -206,11 +206,11 @@ export class StakingPage implements OnInit, OnDestroy {
key: '1',
category: 'Requirements',
category_extra: 'Staked value', // auth.memberLevel$ | async
level0: tiers[0].toString(),
level1: tiers[1].toString(),
level2: tiers[2].toString(),
level3: tiers[3].toString(),
level4: tiers[4].toString(),
level0: '0', // tiers[0].toString(),
level1: '0', // tiers[1].toString(),
level2: '0', // tiers[2].toString(),
level3: '0', // tiers[3].toString(),
level4: '0', // tiers[4].toString(),
},
{
key: '2',
Expand Down

0 comments on commit 429894f

Please sign in to comment.