Skip to content

Commit

Permalink
feat: replace get_assets_paged to get_assets_paged_detailed
Browse files Browse the repository at this point in the history
  • Loading branch information
naturexie committed Jan 29, 2025
1 parent b474a92 commit 2c0eadd
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 48 deletions.
4 changes: 2 additions & 2 deletions api/get-account-meme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getAssetsMEMEDetailed } from "../store";
import { getAssetsMEMEDetail } from "../store";

import getBalance from "./get-balance";
import getPortfolioMEME from "./get-portfolio-meme";
Expand All @@ -9,7 +9,7 @@ const getAccountMEME = async () => {
const account = await getAccountWallet();
const { accountId } = account;
if (accountId) {
const assets = await getAssetsMEMEDetailed();
const assets = await getAssetsMEMEDetail();
const tokenIds = assets.map((asset) => asset.token_id);
const shadowRecords = await getShadowRecords();
const accountBalance = (await account.getAccountBalance()).available;
Expand Down
4 changes: 2 additions & 2 deletions api/get-account.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getAssetsDetailed } from "../store";
import { getAssetsDetail } from "../store";

import getBalance from "./get-balance";
import getPortfolio from "./get-portfolio";
Expand All @@ -10,7 +10,7 @@ const getAccount = async () => {
const account = await getAccountWallet();
const { accountId } = account;
if (accountId) {
const assets = await getAssetsDetailed();
const assets = await getAssetsDetail();
const tokenIds = assets.map((asset) => asset.token_id);
const shadowRecords = await getShadowRecords();
const accountBalance = (await account.getAccountBalance()).available;
Expand Down
4 changes: 2 additions & 2 deletions api/get-assets-meme.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Decimal from "decimal.js";
import { getAllMetadata, getAssetsMEMEDetailed, getPrices, getUnitLptAssets } from "../store";
import { getAllMetadata, getAssetsMEMEDetail, getPrices, getUnitLptAssets } from "../store";
import { shrinkToken } from "../store/helper";
import { lpTokenPrefix } from "../utils/config";
import { IToken, IUnitLptAssetDetail, IMetadata } from "../interfaces/asset";
Expand Down Expand Up @@ -40,7 +40,7 @@ const getLptMetadata = (lp_token_details: IUnitLptAssetDetail, priceMap, metadat
};

const getAssetsMEME = async () => {
const assets = await getAssetsMEMEDetailed();
const assets = await getAssetsMEMEDetail();
const token_ids_from_regular = assets
.filter((asset) => asset.token_id.indexOf(lpTokenPrefix) === -1)
.map((asset) => asset.token_id);
Expand Down
4 changes: 2 additions & 2 deletions api/get-assets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Decimal from "decimal.js";
import { getAllMetadata, getAssetsDetailed, getPrices, getUnitLptAssets } from "../store";
import { getAllMetadata, getAssetsDetail, getPrices, getUnitLptAssets } from "../store";
import { shrinkToken } from "../store/helper";
import { lpTokenPrefix, blackAssets } from "../utils/config";
import { IToken, IUnitLptAssetDetail, IMetadata } from "../interfaces/asset";
Expand Down Expand Up @@ -40,7 +40,7 @@ const getLptMetadata = (lp_token_details: IUnitLptAssetDetail, priceMap, metadat
};

const getAssets = async () => {
const assets_pending = await getAssetsDetailed();
const assets_pending = await getAssetsDetail();
const assets = assets_pending.filter((asset) => !blackAssets.includes(asset.token_id));
const token_ids_from_regular = assets
.filter((asset) => asset.token_id.indexOf(lpTokenPrefix) === -1)
Expand Down
3 changes: 2 additions & 1 deletion interfaces/burrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export type IViewReturnType =
| IMarginConfig
| IMarginAccountDetailedView
| IPoolDcl[]
| IQuoteResult;
| IQuoteResult
| IAssetDetailed[];

export interface IBurrow {
selector: WalletSelector;
Expand Down
1 change: 1 addition & 0 deletions interfaces/contract-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum ViewMethodsLogic {
get_asset,
get_assets,
get_assets_paged,
get_assets_paged_detailed,
// config
get_config,
get_margin_config,
Expand Down
4 changes: 2 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
trailingSlash: true,
reactStrictMode: false,
trailingSlash: false,
eslint: {
ignoreDuringBuilds: true,
},
Expand Down
48 changes: 11 additions & 37 deletions store/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export const getAssets = async (): Promise<IAssetEntry[]> => {
token_id,
}));
};
export const getAssetsDetail = async (): Promise<IAssetDetailed[]> => {
const { view, logicContract } = await getBurrow();
return (await view(
logicContract,
ViewMethodsLogic[ViewMethodsLogic.get_assets_paged_detailed],
)) as IAssetDetailed[];
};

export const getAssetsMEME = async (): Promise<IAssetEntry[]> => {
const { view, logicMEMEContract, pythContract } = await getBurrow();
Expand All @@ -35,45 +42,12 @@ export const getAssetsMEME = async (): Promise<IAssetEntry[]> => {
token_id,
}));
};

export const getAssetDetailed = async (token_id: string): Promise<IAssetDetailed> => {
const { view, logicContract } = await getBurrow();
const assetDetails: IAssetDetailed = (await view(
logicContract,
ViewMethodsLogic[ViewMethodsLogic.get_asset],
{
token_id,
},
)) as IAssetDetailed;

return assetDetails;
};

export const getAssetMEMEDetailed = async (token_id: string): Promise<IAssetDetailed> => {
export const getAssetsMEMEDetail = async (): Promise<IAssetDetailed[]> => {
const { view, logicMEMEContract } = await getBurrow();
const assetDetails: IAssetDetailed = (await view(
return (await view(
logicMEMEContract,
ViewMethodsLogic[ViewMethodsLogic.get_asset],
{
token_id,
},
)) as IAssetDetailed;

return assetDetails;
};

export const getAssetsDetailed = async (): Promise<IAssetDetailed[]> => {
const assets: IAssetEntry[] = await getAssets();
const detailedAssets = await Promise.all(assets.map((asset) => getAssetDetailed(asset.token_id)));
return detailedAssets;
};

export const getAssetsMEMEDetailed = async (): Promise<IAssetDetailed[]> => {
const assets: IAssetEntry[] = await getAssetsMEME();
const detailedAssets = await Promise.all(
assets.map((asset) => getAssetMEMEDetailed(asset.token_id)),
);
return detailedAssets;
ViewMethodsLogic[ViewMethodsLogic.get_assets_paged_detailed],
)) as IAssetDetailed[];
};

export const getUnitLptAssets = async (pool_ids: number[]): Promise<IUnitLptAsset> => {
Expand Down

0 comments on commit 2c0eadd

Please sign in to comment.