Skip to content

Commit

Permalink
[Explore Page] Hide tokens & pools with zero tvl (#941)
Browse files Browse the repository at this point in the history
* change tokens page data handling

* update explore pools

* remove console

* tokens min liquidity 1

---------

Co-authored-by: Stefan Popov <stefanpopov@list.ru>
  • Loading branch information
Nikita-Polyakov and stefashkaa authored Feb 9, 2023
1 parent 58f835d commit 1e8ff36
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/views/Explore/Container.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class ExploreContainer extends Mixins(mixins.LoadingMixin, Transl
@getter.wallet.account.isLoggedIn private isLoggedIn!: boolean;
exploreQuery = '';
isAccountItems = Boolean(storage.get(storageKey as any));
isAccountItems = JSON.parse(storage.get(storageKey as any) ?? false);
get isAccountItemsOnly(): boolean {
return this.isAccountItems;
Expand Down
5 changes: 4 additions & 1 deletion src/views/Explore/Pools.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ import PoolApyMixin from '@/components/mixins/PoolApyMixin';
import { state, getter } from '@/store/decorators';
import { lazyComponent } from '@/router';
import { Components } from '@/consts';
import { formatAmountWithSuffix, formatDecimalPlaces } from '@/utils';
import { formatAmountWithSuffix, formatDecimalPlaces, asZeroValue } from '@/utils';
import type { Asset, Whitelist } from '@sora-substrate/util/build/assets/types';
import type { AccountLiquidity } from '@sora-substrate/util/build/poolXyk/types';
Expand Down Expand Up @@ -157,6 +157,9 @@ export default class ExplorePools extends Mixins(ExplorePageMixin, TranslationMi
get items(): TableItem[] {
return Object.entries(this.poolReserves).reduce<any>((buffer, [key, reserves]) => {
// dont show empty pools
if (reserves.some((reserve) => asZeroValue(reserve))) return buffer;
const matches = key.match(/0x\w{64}/g);
if (!matches || !matches[0] || !matches[1] || !this.whitelist[matches[0]] || !this.whitelist[matches[1]])
Expand Down
29 changes: 17 additions & 12 deletions src/views/Explore/Tokens.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ type TableItem = {
const AssetsQuery = gql<EntitiesQueryResponse<AssetData>>`
query AssetsQuery($after: Cursor, $ids: [String!], $dayTimestamp: Int, $weekTimestamp: Int) {
entities: assets(after: $after, filter: { id: { in: $ids } }) {
entities: assets(after: $after, filter: { and: [{ id: { in: $ids } }, { liquidity: { greaterThan: "1" } }] }) {
pageInfo {
hasNextPage
endCursor
Expand Down Expand Up @@ -273,20 +273,23 @@ export default class Tokens extends Mixins(ExplorePageMixin, TranslationMixin) {
}
get preparedItems(): TableItem[] {
return this.items.map((item) => {
const fpPrice = FPNumber.fromCodecValue(this.getAssetFiatPrice(item) ?? 0);
const fpPriceDay = this.tokensData[item.address]?.startPriceDay ?? FPNumber.ZERO;
const fpPriceWeek = this.tokensData[item.address]?.startPriceWeek ?? FPNumber.ZERO;
const fpVolumeWeek = this.tokensData[item.address]?.volume ?? FPNumber.ZERO;
return Object.entries(this.tokensData).reduce<TableItem[]>((buffer, [address, tokenData]) => {
const asset = this.getAsset(address);
if (!asset) return buffer;
const fpPrice = FPNumber.fromCodecValue(this.getAssetFiatPrice(asset) ?? 0);
const fpPriceDay = tokenData?.startPriceDay ?? FPNumber.ZERO;
const fpPriceWeek = tokenData?.startPriceWeek ?? FPNumber.ZERO;
const fpVolumeWeek = tokenData?.volume ?? FPNumber.ZERO;
const fpPriceChangeDay = calcPriceChange(fpPrice, fpPriceDay);
const fpPriceChangeWeek = calcPriceChange(fpPrice, fpPriceWeek);
const reserves = this.tokensData[item.address]?.reserves ?? FPNumber.ZERO;
const reserves = tokenData?.reserves ?? FPNumber.ZERO;
const tvl = reserves.mul(fpPrice);
return {
...item,
buffer.push({
...asset,
price: fpPrice.toNumber(),
priceFormatted: new FPNumber(fpPrice.toFixed(7)).toLocaleString(),
priceChangeDay: fpPriceChangeDay.toNumber(),
Expand All @@ -297,8 +300,10 @@ export default class Tokens extends Mixins(ExplorePageMixin, TranslationMixin) {
volumeWeekFormatted: formatAmountWithSuffix(fpVolumeWeek),
tvl: tvl.toNumber(),
tvlFormatted: formatAmountWithSuffix(tvl),
};
});
});
return buffer;
}, []);
}
// ExplorePageMixin method implementation
Expand All @@ -314,7 +319,7 @@ export default class Tokens extends Mixins(ExplorePageMixin, TranslationMixin) {
const now = Math.floor(Date.now() / (5 * 60 * 1000)) * (5 * 60); // rounded to latest 5min snapshot (unix)
const dayTimestamp = now - 60 * 60 * 24; // latest day snapshot (unix)
const weekTimestamp = now - 60 * 60 * 24 * 7; // latest week snapshot (unix)
const ids = this.items.map((item) => item.address);
const ids = this.items.map((item) => item.address); // only whitelisted assets
const variables = { ids, dayTimestamp, weekTimestamp };
const items = await SubqueryExplorerService.fetchAndParseEntities(parse, AssetsQuery, variables);
Expand Down

0 comments on commit 1e8ff36

Please sign in to comment.