From 185c502ee4ebb190f5d7a996aa429647dcf75ad8 Mon Sep 17 00:00:00 2001 From: Adam Chambers Date: Wed, 29 Nov 2023 21:54:47 -0500 Subject: [PATCH] chore: refactor imports --- .../src/store/jupiterStore.ts | 10 +++++++--- .../src/store/mrgnlendStore.ts | 20 +++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/marginfi-v2-ui-state/src/store/jupiterStore.ts b/packages/marginfi-v2-ui-state/src/store/jupiterStore.ts index 083fccc200..c9284c08b5 100644 --- a/packages/marginfi-v2-ui-state/src/store/jupiterStore.ts +++ b/packages/marginfi-v2-ui-state/src/store/jupiterStore.ts @@ -1,9 +1,9 @@ -import { Wallet, nativeToUi, TOKEN_PROGRAM_ID } from "@mrgnlabs/mrgn-common"; -import { TokenInfo, TokenListContainer } from "@solana/spl-token-registry"; +import { Wallet, TOKEN_PROGRAM_ID } from "@mrgnlabs/mrgn-common"; import { Connection, PublicKey } from "@solana/web3.js"; import { TokenAccountMap, TokenAccount } from "../lib"; import { create, StateCreator } from "zustand"; -import { BN } from "@coral-xyz/anchor"; + +import type { TokenInfo } from "@solana/spl-token-registry"; interface JupiterState { // State @@ -42,6 +42,10 @@ const stateCreator: StateCreator = (set, get) => ({ ? await fetch("https://token.jup.ag/strict") : await fetch("https://token.jup.ag/all") ).json(); + + // Dynamically import TokenListContainer when needed + const { TokenListContainer } = await import("@solana/spl-token-registry"); + const res = new TokenListContainer(tokens); const list = res.filterByChainId(101).getList(); tokenMap = list.reduce((acc, item) => { diff --git a/packages/marginfi-v2-ui-state/src/store/mrgnlendStore.ts b/packages/marginfi-v2-ui-state/src/store/mrgnlendStore.ts index 868e48e5ab..c78efb32dd 100644 --- a/packages/marginfi-v2-ui-state/src/store/mrgnlendStore.ts +++ b/packages/marginfi-v2-ui-state/src/store/mrgnlendStore.ts @@ -1,14 +1,4 @@ -import { MarginfiAccountWrapper, MarginfiClient, MarginfiConfig } from "@mrgnlabs/marginfi-client-v2"; -import { - Wallet, - getValueInsensitive, - loadBankMetadatas, - loadTokenMetadatas, - BankMetadataMap, - TokenMetadataMap, - TokenMetadata, -} from "@mrgnlabs/mrgn-common"; -import { Bank, OraclePrice } from "@mrgnlabs/marginfi-client-v2"; +import { getValueInsensitive } from "@mrgnlabs/mrgn-common"; import { Connection, PublicKey } from "@solana/web3.js"; import { DEFAULT_ACCOUNT_SUMMARY, @@ -28,6 +18,11 @@ import { getPointsSummary } from "../lib/points"; import { create, StateCreator } from "zustand"; import { persist } from "zustand/middleware"; +import type { Bank, OraclePrice } from "@mrgnlabs/marginfi-client-v2"; +import type { Wallet, BankMetadataMap, TokenMetadataMap, TokenMetadata } from "@mrgnlabs/mrgn-common"; +import type { MarginfiAccountWrapper } from "@mrgnlabs/marginfi-client-v2"; +import type { MarginfiClient, MarginfiConfig } from "@mrgnlabs/marginfi-client-v2"; + interface ProtocolStats { deposits: number; borrows: number; @@ -116,6 +111,9 @@ const stateCreator: StateCreator = (set, get) => ({ birdEyeApiKey?: string; }) => { try { + const { MarginfiClient } = await import("@mrgnlabs/marginfi-client-v2"); + const { loadBankMetadatas, loadTokenMetadatas } = await import("@mrgnlabs/mrgn-common"); + let userDataFetched = false; const connection = args?.connection ?? get().marginfiClient?.provider.connection;