diff --git a/apps/marginfi-v2-trading/src/components/common/ActionBox/ActionBox.tsx b/apps/marginfi-v2-trading/src/components/common/ActionBox/ActionBox.tsx
index 0af2480272..6ce0edcfd8 100644
--- a/apps/marginfi-v2-trading/src/components/common/ActionBox/ActionBox.tsx
+++ b/apps/marginfi-v2-trading/src/components/common/ActionBox/ActionBox.tsx
@@ -61,16 +61,16 @@ export const ActionBox = ({
isTokenSelectable,
handleCloseDialog,
}: ActionBoxProps) => {
- const [isInitialized, setIsRefreshingStore, activeGroupPk, groupMap, mfiClient, nativeSolBalance, refreshGroup] =
- useTradeStore((state) => [
+ const [isInitialized, setIsRefreshingStore, activeGroupPk, groupMap, nativeSolBalance, refreshGroup] = useTradeStore(
+ (state) => [
state.initialized,
state.setIsRefreshingStore,
state.activeGroup,
state.groupMap,
- state.marginfiClient,
state.nativeSolBalance,
state.refreshGroup,
- ]);
+ ]
+ );
const activeGroup = React.useMemo(() => {
const group = activeGroupPk ? groupMap.get(activeGroupPk.toBase58()) || null : null;
@@ -363,6 +363,7 @@ export const ActionBox = ({
setIsActionComplete,
setPreviousTxn,
setIsRefreshingStore,
+ refreshGroup,
connection,
wallet,
activeGroup?.groupPk,
@@ -443,7 +444,7 @@ export const ActionBox = ({
};
const handleLstAction = React.useCallback(async () => {
- if ((!selectedBank && !selectedStakingAccount) || !mfiClient || !lstData) {
+ if ((!selectedBank && !selectedStakingAccount) || !activeGroup?.client || !lstData) {
return;
}
@@ -473,7 +474,7 @@ export const ActionBox = ({
const txnSig = await executeLstAction({
actionMode,
- marginfiClient: mfiClient,
+ marginfiClient: activeGroup.client,
amount,
connection,
wallet,
@@ -538,7 +539,8 @@ export const ActionBox = ({
}, [
selectedBank,
selectedStakingAccount,
- mfiClient,
+ activeGroup?.client,
+ activeGroup?.groupPk,
lstData,
lstQuoteMeta,
setIsLoading,
@@ -553,17 +555,18 @@ export const ActionBox = ({
setIsActionComplete,
setPreviousTxn,
setIsRefreshingStore,
- activeGroup?.groupPk,
+ refreshGroup,
]);
const handleLendingAction = React.useCallback(async () => {
- if (!actionMode || !selectedBank || (!amount && !repayAmount)) {
+ console.log({ activeGroup });
+ if (!actionMode || !activeGroup?.client || !selectedBank || (!amount && !repayAmount)) {
return;
}
const action = async () => {
const params = {
- mfiClient,
+ mfiClient: activeGroup.client,
actionType: actionMode,
bank: selectedBank,
amount,
@@ -589,10 +592,10 @@ export const ActionBox = ({
await action();
}, [
actionMode,
+ activeGroup?.client,
selectedBank,
amount,
repayAmount,
- mfiClient,
nativeSolBalance,
selectedAccount,
walletContextState,
diff --git a/apps/marginfi-v2-trading/src/components/common/ActionBox/components/ActionBoxPreview/Components/LendingPreview/LendingPreview.tsx b/apps/marginfi-v2-trading/src/components/common/ActionBox/components/ActionBoxPreview/Components/LendingPreview/LendingPreview.tsx
index 3c52ef4e85..7d91c06002 100644
--- a/apps/marginfi-v2-trading/src/components/common/ActionBox/components/ActionBoxPreview/Components/LendingPreview/LendingPreview.tsx
+++ b/apps/marginfi-v2-trading/src/components/common/ActionBox/components/ActionBoxPreview/Components/LendingPreview/LendingPreview.tsx
@@ -30,10 +30,8 @@ export const LendingPreview = ({
addAdditionalsPopup,
children,
}: ActionBoxPreviewProps) => {
- const [marginfiClient] = useTradeStore((state) => [state.marginfiClient]);
-
const { preview, previewStats, isLoading, actionMethod } = useLendingPreview({
- marginfiClient: activeGroup?.client ?? marginfiClient,
+ marginfiClient: activeGroup?.client ?? null,
accountSummary: activeGroup?.accountSummary ?? DEFAULT_ACCOUNT_SUMMARY,
actionMode,
account: activeGroup?.selectedAccount ?? null,
diff --git a/apps/marginfi-v2-trading/src/components/common/ActiveGroup/ActiveGroup.tsx b/apps/marginfi-v2-trading/src/components/common/ActiveGroup/ActiveGroup.tsx
index cae6431c9b..54c5b5bd97 100644
--- a/apps/marginfi-v2-trading/src/components/common/ActiveGroup/ActiveGroup.tsx
+++ b/apps/marginfi-v2-trading/src/components/common/ActiveGroup/ActiveGroup.tsx
@@ -9,11 +9,7 @@ import { useTradeStore } from "~/store";
import { Button } from "~/components/ui/button";
export const ActiveGroup = () => {
- const [activeGroupPk, groupMap, marginfiClient] = useTradeStore((state) => [
- state.activeGroup,
- state.groupMap,
- state.marginfiClient,
- ]);
+ const [activeGroupPk, groupMap] = useTradeStore((state) => [state.activeGroup, state.groupMap]);
const activeGroup = React.useMemo(() => {
return (activeGroupPk ? groupMap.get(activeGroupPk.toBase58()) : null) ?? null;
@@ -31,8 +27,8 @@ export const ActiveGroup = () => {
return (
- {(!activeGroup || !activeGroup.pool.token || !marginfiClient) &&
No active group
}
- {activeGroup && activeGroup.pool.token && marginfiClient && isOpen && (
+ {(!activeGroup || !activeGroup.pool.token || !activeGroup.client) &&
No active group
}
+ {activeGroup && activeGroup.pool.token && activeGroup.client && isOpen && (
<>
diff --git a/apps/marginfi-v2-trading/src/pages/trade/[symbol].tsx b/apps/marginfi-v2-trading/src/pages/trade/[symbol].tsx
index 938a0ce3a1..daf52eac3c 100644
--- a/apps/marginfi-v2-trading/src/pages/trade/[symbol].tsx
+++ b/apps/marginfi-v2-trading/src/pages/trade/[symbol].tsx
@@ -355,7 +355,7 @@ export default function TradeSymbolPage() {
diff --git a/apps/marginfi-v2-trading/src/pages/yield.tsx b/apps/marginfi-v2-trading/src/pages/yield.tsx
index 23196ecd4d..90c3e701f3 100644
--- a/apps/marginfi-v2-trading/src/pages/yield.tsx
+++ b/apps/marginfi-v2-trading/src/pages/yield.tsx
@@ -280,6 +280,7 @@ export default function PortfolioPage() {
group.pool.token.position.isLending &&
group.selectedAccount && (
)}
Supply
@@ -354,6 +356,7 @@ export default function PortfolioPage() {
{collateralBank.isActive && collateralBank.position.isLending && group.selectedAccount && (
)}
Supply
@@ -492,13 +496,21 @@ export default function PortfolioPage() {
)}
{group.pool.token.isActive && group.pool.token.position.isLending && (
-
+
Withdraw
)}
-
+
Supply
@@ -560,13 +572,21 @@ export default function PortfolioPage() {
)}
{collateralBank.isActive && collateralBank.position.isLending && (
-
+
Withdraw
)}
-
+
Supply
diff --git a/apps/marginfi-v2-trading/src/store/tradeStore.ts b/apps/marginfi-v2-trading/src/store/tradeStore.ts
index 9ebd36e41e..de73b0ecc4 100644
--- a/apps/marginfi-v2-trading/src/store/tradeStore.ts
+++ b/apps/marginfi-v2-trading/src/store/tradeStore.ts
@@ -120,9 +120,6 @@ type TradeStoreState = {
sortBy: TradePoolFilterStates;
- // marginfi client, initialized when viewing an active group
- marginfiClient: MarginfiClient | null;
-
// active group, currently being viewed / traded
activeGroup: PublicKey | null;
// user native sol balance
@@ -190,7 +187,6 @@ const stateCreator: StateCreator = (set, get) => ({
currentPage: 1,
totalPages: 0,
sortBy: TradePoolFilterStates.TIMESTAMP,
- marginfiClient: null,
activeGroup: null,
nativeSolBalance: 0,
tokenAccountMap: null,
@@ -441,7 +437,6 @@ const stateCreator: StateCreator = (set, get) => ({
}
set({
- marginfiClient,
portfolio,
groupMap,
wallet: wallet,
@@ -475,7 +470,6 @@ const stateCreator: StateCreator = (set, get) => ({
set({
activeGroup: args.groupPk,
- marginfiClient,
});
},
@@ -483,7 +477,6 @@ const stateCreator: StateCreator = (set, get) => ({
set((state) => {
return {
...state,
- marginfiClient: null,
selectedAccount: null,
activeGroup: null,
};
diff --git a/apps/marginfi-v2-trading/src/utils/mrgnActions.ts b/apps/marginfi-v2-trading/src/utils/mrgnActions.ts
index e1d82a2cb1..aa700d0947 100644
--- a/apps/marginfi-v2-trading/src/utils/mrgnActions.ts
+++ b/apps/marginfi-v2-trading/src/utils/mrgnActions.ts
@@ -101,7 +101,6 @@ export async function executeLendingAction({
if (actionType === ActionType.Repay) {
if (repayWithCollatOptions) {
- console.log({ amount, repay: repayWithCollatOptions.repayAmount });
txnSig = await repayWithCollat({
marginfiClient: mfiClient,
marginfiAccount,