Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mfi-v2-ui): token account issue #422

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions packages/marginfi-v2-ui-state/src/lib/mrgnlend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
TokenMetadata,
} from "@mrgnlabs/mrgn-common";
import BigNumber from "bignumber.js";
import { Connection, PublicKey } from "@solana/web3.js";
import { Connection, PublicKey, SystemProgram } from "@solana/web3.js";
import BN from "bn.js";

const FEE_MARGIN = 0.01;
Expand Down Expand Up @@ -448,21 +448,24 @@ async function fetchTokenAccounts(
const [walletAi, ...ataAiList] = accountsAiList;
const nativeSolBalance = walletAi?.lamports ? walletAi.lamports / 1e9 : 0;

const ataList: TokenAccount[] = ataAiList.map((ai, index) => {
if (!ai) {
const ataList: TokenAccount[] = ataAiList
.filter((ai) => !ai?.owner?.equals(SystemProgram.programId))
.map((ai, index) => {
if (!ai) {
return {
created: false,
mint: mintList[index].address,
balance: 0,
};
}

const decoded = unpackAccount(ataAddresses[index], ai);
return {
created: false,
mint: mintList[index].address,
balance: 0,
created: true,
mint: decoded.mint,
balance: nativeToUi(new BN(decoded.amount.toString()), mintList[index].decimals),
};
}
const decoded = unpackAccount(ataAddresses[index], ai);
return {
created: true,
mint: decoded.mint,
balance: nativeToUi(new BN(decoded.amount.toString()), mintList[index].decimals),
};
});
});

return { nativeSolBalance, tokenAccountMap: new Map(ataList.map((ata) => [ata.mint.toString(), ata])) };
}
Expand Down