Skip to content

Commit

Permalink
Merge pull request #83 from soonaverse/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
adamunchained authored Nov 9, 2023
2 parents cc18578 + f9a4603 commit 9c71ec1
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 52 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));
}
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
8 changes: 3 additions & 5 deletions src/app/components/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ 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,
TOKEN_EXPIRY_HOURS,
WenRequest,
} from '@build-5/interfaces';
Expand Down Expand Up @@ -145,12 +144,11 @@ export class AuthService {
this.memberSoonDistribution$.subscribe((v) => {
if (v && (v?.stakes?.[StakeType.DYNAMIC]?.value || 0) > 0) {
let l = -1;
tiers.forEach((a) => {
environment.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 +416,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 @@ -230,9 +230,9 @@ export class NftCheckoutComponent implements OnInit, OnDestroy {
if (val.payload.nft) {
firstValueFrom(this.nftApi.listen(val.payload.nft)).then((obj) => {
if (obj) {
this.purchasedNft = obj;
this.purchasedNft = <Nft>obj;
this.fileApi
.getMetadata(this.purchasedNft.media)
.getMetadata(this.purchasedNft?.media)
.pipe(take(1), untilDestroyed(this))
.subscribe((o) => {
this.mediaType = o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ export class TokenAllTokenRowComponent implements OnInit, OnDestroy {
this.tokenApi
.listen(this.tokenId)
.pipe(untilDestroyed(this))
.subscribe((token) => {
.subscribe((token: any) => {
if (token) {
this.token = token;
this.listenToStats(this.token.uid);
if (this.token?.uid) {
this.listenToStats(this.token.uid);
}
this.cd.markForCheck();
}
});
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,6 @@ import {
TransactionType,
calcStakedMultiplier,
getDefDecimalIfNotSet,
tiers,
} from '@build-5/interfaces';
import dayjs from 'dayjs';
import { BehaviorSubject, Subscription, interval, merge } from 'rxjs';
Expand Down Expand Up @@ -157,14 +156,14 @@ export class TokenStakeComponent implements OnInit, OnDestroy {
(this.auth.memberSoonDistribution$.value?.stakes?.[StakeType.DYNAMIC]?.value || 0) +
Math.pow(10, getDefDecimalIfNotSet(this.token?.decimals)) * val;
let l = 0;
tiers.forEach((a) => {
environment.tiers.forEach((a) => {
if (newTotal >= a) {
l++;
}
});

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

this.levelControl.setValue(l);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class TokenTradingPairRowComponent implements OnInit, OnDestroy {
@Input() tableMode = false;
@Output() wenOnFavouriteClick = new EventEmitter<void>();
@Output() wenOnClick = new EventEmitter<void>();
public token?: Token;
public token?: any;
public path = ROUTER_UTILS.config.token.root;
public tradePath = ROUTER_UTILS.config.token.trade;
public listenAvgPrice$: BehaviorSubject<number | undefined> = new BehaviorSubject<
Expand Down Expand Up @@ -64,7 +64,7 @@ export class TokenTradingPairRowComponent implements OnInit, OnDestroy {
this.tokenApi
.listen(this.tokenId)
.pipe(untilDestroyed(this))
.subscribe((token) => {
.subscribe((token: any) => {
if (token) {
this.token = token;
this.listenToStats(this.token.uid, [token.status || TokenStatus.PRE_MINTED]);
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/award/pages/new/new.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class NewPage implements OnInit, OnDestroy {
filter((space) => !!space),
untilDestroyed(this),
)
.subscribe((space) => {
.subscribe((space: any) => {
this.spaceControl.setValue(space?.uid);

this.seo.setTags(
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/collection/pages/upsert/upsert.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export class UpsertPage implements OnInit, OnDestroy {

// Load selected options for award/collections
o.accessAwards?.forEach(async (a) => {
const award = await firstValueFrom(this.awardApi.listen(a));
const award: any = await firstValueFrom(this.awardApi.listen(a));
if (award) {
this.filteredAwards$.next([
...(this.filteredAwards$.value || []),
Expand All @@ -274,7 +274,7 @@ export class UpsertPage implements OnInit, OnDestroy {
});

o.accessCollections?.forEach(async (a) => {
const collection = await firstValueFrom(this.collectionApi.listen(a));
const collection: any = await firstValueFrom(this.collectionApi.listen(a));
if (collection) {
this.filteredCollections$.next([
...(this.filteredCollections$.value || []),
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/proposal/pages/new/new.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class NewPage implements OnInit, OnDestroy {
filter((space) => !!space),
untilDestroyed(this),
)
.subscribe((space) => {
.subscribe((space: any) => {
this.spaceControl.setValue(space?.uid);

this.seo.setTags(
Expand Down
17 changes: 8 additions & 9 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,6 @@ import {
TokenStats,
calcStakedMultiplier,
getDefDecimalIfNotSet,
tiers,
} from '@build-5/interfaces';
import { BehaviorSubject, Observable, Subscription, map, merge, of } from 'rxjs';

Expand Down Expand Up @@ -123,14 +122,14 @@ export class StakingPage implements OnInit, OnDestroy {
(this.auth.memberSoonDistribution$.value?.stakes?.[StakeType.DYNAMIC]?.value || 0) +
Math.pow(10, getDefDecimalIfNotSet(this.token$.value?.decimals)) * val;
let l = -1;
tiers.forEach((a) => {
environment.tiers.forEach((a) => {
if (newTotal >= a) {
l++;
}
});

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

this.levelControl.setValue(l);
Expand Down Expand Up @@ -206,11 +205,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: environment.tiers[0].toString(),
level1: environment.tiers[1].toString(),
level2: environment.tiers[2].toString(),
level3: environment.tiers[3].toString(),
level4: environment.tiers[4].toString(),
},
{
key: '2',
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/tokens/pages/tokens/tokens.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class TokensPage implements OnInit {
this.tokenApi
.listenMultiple(HIGHLIGHT_TOKENS)
.pipe(
filter((r) => r.every((token) => token)),
filter((r: any) => r.every((token) => token)),
untilDestroyed(this),
)
.subscribe((r) => {
Expand Down
3 changes: 3 additions & 0 deletions src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MIN_IOTA_AMOUNT } from '@build-5/interfaces';

export const environment = {
production: true,
algolia: {
Expand All @@ -6,4 +8,5 @@ export const environment = {
},
soonaversePlaceholder: 'https://soonaverse.com/favicon.ico',
build5Token: '',
tiers: [0, 10, 4000, 6000, 15000].map((v) => v * MIN_IOTA_AMOUNT),
};
Loading

0 comments on commit 9c71ec1

Please sign in to comment.