Skip to content

Commit

Permalink
Merge pull request #939 from mrgnlabs/chore/latest-bank-as-announcement
Browse files Browse the repository at this point in the history
feat(mfi-v2-ui): adding the latest added bank to the announcements section
  • Loading branch information
k0beLeenders authored Oct 31, 2024
2 parents 4acbe55 + 4bb2143 commit a035534
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions apps/marginfi-v2-ui/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useRouter } from "next/router";

import { shortenAddress } from "@mrgnlabs/mrgn-common";
import { capture, Desktop, LendingModes, Mobile } from "@mrgnlabs/mrgn-utils";
import { ActionType } from "@mrgnlabs/marginfi-v2-ui-state";
import { ActionType, ExtendedBankInfo } from "@mrgnlabs/marginfi-v2-ui-state";
import { ActionBox } from "@mrgnlabs/mrgn-ui";

import { useMrgnlendStore, useUiStore } from "~/store";
Expand Down Expand Up @@ -33,22 +33,35 @@ export default function HomePage() {
const { walletContextState, walletAddress, isOverride, connected } = useWallet();
const [lendingMode] = useUiStore((state) => [state.lendingMode]);

const [isStoreInitialized, isRefreshingStore, selectedAccount, extendedBankInfos, fetchMrgnlendState] =
useMrgnlendStore((state) => [
state.initialized,
state.isRefreshingStore,
state.selectedAccount,
state.extendedBankInfos,
state.fetchMrgnlendState,
]);
const [
isStoreInitialized,
isRefreshingStore,
selectedAccount,
extendedBankInfos,
fetchMrgnlendState,
marginfiClient,
] = useMrgnlendStore((state) => [
state.initialized,
state.isRefreshingStore,
state.selectedAccount,
state.extendedBankInfos,
state.fetchMrgnlendState,
state.marginfiClient,
]);

const annoucements = React.useMemo(() => {
const mother = extendedBankInfos.find((bank) => bank.meta.tokenSymbol === "MOTHER");
const hSOL = extendedBankInfos.find((bank) => bank.meta.tokenSymbol === "hSOL");
let banks: (ExtendedBankInfo | undefined)[] = [];
banks.push(extendedBankInfos.find((bank) => bank.meta.tokenSymbol === "hSOL"));
if (marginfiClient?.banks) {
const latestBankKey = Array.from(marginfiClient.banks.keys())[0];
banks.push(extendedBankInfos.find((bank) => bank.address.toString() === latestBankKey.toString()));
}

banks = banks.filter((bank): bank is ExtendedBankInfo => bank !== undefined);
return [
{ bank: mother },
{ bank: hSOL },
...banks.map((bank) => ({
bank: bank,
})),
{
image: <IconBook size={22} />,
text: "New documentation now available!",
Expand All @@ -60,7 +73,7 @@ export default function HomePage() {
onClick: () => router.push("/points"),
},
] as (AnnouncementBankItem | AnnouncementCustomItem)[];
}, [extendedBankInfos, router]);
}, [extendedBankInfos, router, marginfiClient]);

return (
<>
Expand Down

0 comments on commit a035534

Please sign in to comment.