Skip to content

Commit

Permalink
fix: ignore banks with missing oracle / meta data
Browse files Browse the repository at this point in the history
  • Loading branch information
chambaz committed Nov 21, 2023
1 parent ee7010d commit 51faa68
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/marginfi-v2-ui-state/src/store/mrgnlendStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
loadTokenMetadatas,
BankMetadataMap,
TokenMetadataMap,
TokenMetadata,
} from "@mrgnlabs/mrgn-common";
import { Bank, OraclePrice } from "@mrgnlabs/marginfi-client-v2";
import { Connection, PublicKey } from "@solana/web3.js";
import {
DEFAULT_ACCOUNT_SUMMARY,
Expand Down Expand Up @@ -151,17 +153,29 @@ const stateCreator: StateCreator<MrgnlendState, [], []> = (set, get) => ({
userDataFetched = true;
}

const banksWithPriceAndToken = banks.map((bank) => {
const banksWithPriceAndToken: {
bank: Bank;
oraclePrice: OraclePrice;
tokenMetadata: TokenMetadata;
}[] = [];

banks.forEach((bank) => {
const oraclePrice = marginfiClient.getOraclePriceByBank(bank.address);
if (!oraclePrice) throw new Error(`Price info not found for bank ${bank.address.toBase58()}`);
if (!oraclePrice) {
return;
}

const bankMetadata = bankMetadataMap[bank.address.toBase58()];
if (bankMetadata === undefined) throw new Error(`Bank metadata not found for ${bank.address.toBase58()}`);
if (bankMetadata === undefined) {
return;
}

const tokenMetadata = getValueInsensitive(tokenMetadataMap, bankMetadata.tokenSymbol);

This comment has been minimized.

Copy link
@thedonmon

thedonmon Nov 21, 2023

This method throws the error but never handled so probably need a try catch in here or remove throwing the error to get the undefined result. UI just hangs on loading otherwise
image

if (!tokenMetadata) throw new Error(`Token metadata not found for ${bankMetadata.tokenSymbol}`);
if (!tokenMetadata) {
return;
}

return { bank, oraclePrice, tokenMetadata };
banksWithPriceAndToken.push({ bank, oraclePrice, tokenMetadata });
});

const [extendedBankInfos, extendedBankMetadatas] = banksWithPriceAndToken.reduce(
Expand Down

2 comments on commit 51faa68

@vercel
Copy link

@vercel vercel bot commented on 51faa68 Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

omni – ./apps/omni

omni-git-production-mrgn.vercel.app
omni-mrgn.vercel.app
omni-one.vercel.app
omni.marginfi.com

@vercel
Copy link

@vercel vercel bot commented on 51faa68 Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.