Skip to content

Commit

Permalink
fix merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
losman0s committed Sep 4, 2023
1 parent e979bcd commit c60adaf
Show file tree
Hide file tree
Showing 21 changed files with 282 additions and 161 deletions.
10 changes: 5 additions & 5 deletions apps/marginfi-v2-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"@next/bundle-analyzer": "^13.4.19",
"@next/font": "13.1.1",
"@socialgouv/matomo-next": "^1.4.0",
"@solana/wallet-adapter-base": "^0.9.23",
"@solana/wallet-adapter-react": "^0.15.34",
"@solana/wallet-adapter-react-ui": "^0.9.33",
"@solana/wallet-adapter-wallets": "^0.19.20",
"@solana/web3.js": "^1.78.4",
"@solana/wallet-adapter-base": "^0.9.20",
"@solana/wallet-adapter-react": "^0.15.28",
"@solana/wallet-adapter-react-ui": "^0.9.27",
"@solana/wallet-adapter-wallets": "^0.19.10",
"@solana/web3.js": "^1.73.0",
"@vercel/analytics": "^1.0.0",
"bignumber.js": "^9.1.1",
"bn.js": "^5.2.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useWallet } from "@solana/wallet-adapter-react";
import React, { FC } from "react";
import { UserStats } from "./UserStats";
import { useMrgnlendStore } from "~/store";
import dynamic from "next/dynamic";
import { useWalletContext } from "../useWalletContext";

const GlobalStats = dynamic(async () => (await import("./GlobalStats")).GlobalStats, { ssr: false });

Expand All @@ -13,7 +13,7 @@ const AccountSummary: FC = () => {
state.protocolStats,
state.selectedAccount,
]);
const wallet = useWallet();
const { connected } = useWalletContext();

return (
<div className="flex flex-col lg:flex-row w-full justify-between items-center">
Expand All @@ -27,7 +27,7 @@ const AccountSummary: FC = () => {
</div>

<div className="w-full">
{wallet.connected && (
{connected && (
<UserStats
accountSummary={isStoreInitialized && selectedAccount ? accountSummary : null}
healthFactor={accountSummary.healthFactor}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ExtendedBankMetadata,
} from "@mrgnlabs/marginfi-v2-ui-state";
import { MarginfiAccountWrapper, PriceBias } from "@mrgnlabs/marginfi-client-v2";
import { useWalletContext } from "~/components/useWalletContext";

const CLOSE_BALANCE_TOAST_ID = "close-balance";
const BORROW_OR_LEND_TOAST_ID = "borrow-or-lend";
Expand Down Expand Up @@ -64,6 +65,7 @@ const AssetRow: FC<{
showHotkeyBadges,
badgeContent,
}) => {
const { connected, openWalletSelector } = useWalletContext();
const [lendZoomLevel, denominationUSD] = useUserProfileStore((state) => [state.lendZoomLevel, state.denominationUSD]);
const setIsRefreshingStore = useMrgnlendStore((state) => state.setIsRefreshingStore);
const [mfiClient, fetchMrgnlendState] = useMrgnlendStore((state) => [state.marginfiClient, state.fetchMrgnlendState]);
Expand All @@ -74,9 +76,14 @@ const AssetRow: FC<{
() => bank.isActive && uiToNative(bank.position.amount, bank.info.state.mintDecimals).isZero(),
[bank]
);
const currentAction = useMemo(() => getCurrentAction(isInLendingMode, bank), [isInLendingMode, bank]);
const currentAction: ActionType | "Connect" = useMemo(
() => (connected ? getCurrentAction(isInLendingMode, bank) : "Connect"),
[connected, isInLendingMode, bank]
);
const maxAmount = useMemo(() => {
switch (currentAction) {
case "Connect":
return 0;
case ActionType.Deposit:
return bank.userInfo.maxDeposit;
case ActionType.Withdraw:
Expand Down Expand Up @@ -303,7 +310,16 @@ const AssetRow: FC<{
console.log("Error while reloading state");
console.log(error);
}
}, [bank, borrowOrLendAmount, currentAction, marginfiAccount, mfiClient, nativeSolBalance, fetchMrgnlendState, setIsRefreshingStore]);
}, [
bank,
borrowOrLendAmount,
currentAction,
marginfiAccount,
mfiClient,
nativeSolBalance,
fetchMrgnlendState,
setIsRefreshingStore,
]);

return (
<TableRow className="h-[54px] w-full bg-[#171C1F] border border-[#1E2122]">
Expand Down Expand Up @@ -641,7 +657,7 @@ const AssetRow: FC<{
maxValue={maxAmount}
maxDecimals={bank.info.state.mintDecimals}
inputRefs={inputRefs}
disabled={isDust}
disabled={isDust || currentAction === "Connect"}
/>
</Badge>
</TableCell>
Expand All @@ -654,11 +670,15 @@ const AssetRow: FC<{
<div className="h-full w-full flex justify-end items-center ml-2 xl:ml-0 pl-2 sm:px-2">
<AssetRowAction
bgColor={
currentAction === ActionType.Deposit || currentAction === ActionType.Borrow
currentAction === "Connect" ||
currentAction === ActionType.Deposit ||
currentAction === ActionType.Borrow
? "rgb(227, 227, 227)"
: "rgba(0,0,0,0)"
}
onClick={isDust ? closeBalance : borrowOrLend}
onClick={
currentAction === "Connect" ? openWalletSelector : isDust ? closeBalance : borrowOrLend
}
>
{isDust ? "Close" : currentAction}
</AssetRowAction>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
import { Button, ButtonProps } from "@mui/material";
import { useWallet } from "@solana/wallet-adapter-react";
import { FC, ReactNode } from "react";
import dynamic from "next/dynamic";

const WalletMultiButtonDynamic = dynamic(
async () => (await import("@solana/wallet-adapter-react-ui")).WalletMultiButton,
{ ssr: false }
);

interface AssetRowActionProps extends ButtonProps {
children?: ReactNode;
bgColor?: string;
}

const AssetRowAction: FC<AssetRowActionProps> = ({ children, disabled, bgColor, ...otherProps }) => {
const wallet = useWallet();

return <Button
className="normal-case text-[10px] sm:text-sm mx-2 sm:mx-0 w-14 sm:w-32 h-11 max-w-1 rounded-md"
style={{
backgroundColor: disabled || !wallet.connected ? "gray" : bgColor ? bgColor : "rgb(227, 227, 227)",
border: bgColor ? "solid 1px rgb(227, 227, 227)" : "none",
color: bgColor === "rgba(0,0,0,0)" ? "rgb(227, 227, 227)" : "black",
fontWeight: 400,
fontFamily: "Aeonik Pro",
zIndex: 10,
}}
{...otherProps}
disabled={disabled || !wallet.connected}
onClick={wallet.connected ? otherProps.onClick : () => wallet.connect()}
>
{children}
</Button>;
};
const AssetRowAction: FC<AssetRowActionProps> = ({ children, disabled, bgColor, ...otherProps }) => (
<Button
className="normal-case text-[10px] sm:text-sm mx-2 sm:mx-0 w-14 sm:w-32 h-11 max-w-1 rounded-md"
style={{
backgroundColor: disabled ? "gray" : bgColor ? bgColor : "rgb(227, 227, 227)",
border: disabled ? "gray" : bgColor ? "solid 1px rgb(227, 227, 227)" : "solid 1px transparent",
color: bgColor === "rgba(0,0,0,0)" ? "rgb(227, 227, 227)" : "black",
fontWeight: 400,
fontFamily: "Aeonik Pro",
zIndex: 10,
}}
{...otherProps}
disabled={disabled}
>
{children}
</Button>
);

export { AssetRowAction };
8 changes: 4 additions & 4 deletions apps/marginfi-v2-ui/src/components/AssetsList/AssetsList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Image from "next/image";
import React, { FC, useEffect, useRef, useState } from "react";
import { useWallet } from "@solana/wallet-adapter-react";
import { Card, Table, TableHead, TableBody, TableContainer, TableCell } from "@mui/material";
import { styled } from "@mui/material/styles";
import Tooltip, { TooltipProps, tooltipClasses } from "@mui/material/Tooltip";
Expand All @@ -10,6 +9,7 @@ import AssetRow from "./AssetRow";
import { useMrgnlendStore, useUserProfileStore } from "~/store";
import { useHotkeys } from "react-hotkeys-hook";
import { LoadingAsset } from "./AssetRow/AssetRow";
import { useWalletContext } from "../useWalletContext";

const HtmlTooltip = styled(({ className, ...props }: TooltipProps) => (
<Tooltip {...props} classes={{ popper: className }} />
Expand All @@ -25,7 +25,7 @@ const HtmlTooltip = styled(({ className, ...props }: TooltipProps) => (

const AssetsList: FC = () => {
// const { selectedAccount, nativeSolBalance } = useStore();
const wallet = useWallet();
const { connected } = useWalletContext();
const [isStoreInitialized, sortedBanks, nativeSolBalance, selectedAccount] = useMrgnlendStore((state) => [
state.initialized,
state.extendedBankInfos,
Expand Down Expand Up @@ -305,7 +305,7 @@ const AssetsList: FC = () => {
nativeSolBalance={nativeSolBalance}
bank={bank}
isInLendingMode={isInLendingMode}
isConnected={wallet.connected}
isConnected={connected}
marginfiAccount={selectedAccount}
inputRefs={inputRefs}
hasHotkey={true}
Expand Down Expand Up @@ -351,7 +351,7 @@ const AssetsList: FC = () => {
nativeSolBalance={nativeSolBalance}
bank={bank}
isInLendingMode={isInLendingMode}
isConnected={wallet.connected}
isConnected={connected}
marginfiAccount={selectedAccount}
inputRefs={inputRefs}
hasHotkey={false}
Expand Down
10 changes: 5 additions & 5 deletions apps/marginfi-v2-ui/src/components/CampaignWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
getAssociatedTokenAddressSync,
} from "@mrgnlabs/mrgn-common";
import { useLipClient } from "~/context";
import { useWallet } from "@solana/wallet-adapter-react";
import { MenuItem, Select, TextField } from "@mui/material";
import { Bank } from "@mrgnlabs/marginfi-client-v2";
import Image from "next/image";
import { NumberFormatValues, NumericFormat } from "react-number-format";
import { useMrgnlendStore } from "~/store";
import { computeGuaranteedApy } from "@mrgnlabs/lip-client";
import { EarnAction } from "./Earn";
import { useWalletContext } from "./useWalletContext";

interface CampaignWizardInputBox {
value: number;
Expand Down Expand Up @@ -87,7 +87,7 @@ const CampaignWizard: FC<CampaignWizardProps> = () => {
const [depositCapacity, setDepositCapacity] = useState(0);
const [campaignBank, setCampaignBank] = useState<Bank | null>(null);

const wallet = useWallet();
const walletContext = useWalletContext();
const [mfiClient] = useMrgnlendStore((state) => [state.marginfiClient]);
const { lipClient, reload: reloadLipClient } = useLipClient();

Expand Down Expand Up @@ -273,7 +273,7 @@ const CampaignWizard: FC<CampaignWizardProps> = () => {
setValue={(value) => setGuaranteedApy(value / 100)}
loadingSafetyCheck={() => {}}
maxDecimals={2}
disabled={!wallet.connected}
disabled={!walletContext.connected}
/>
</div>
<div className="flex justify-between text-[rgb(227, 227, 227)]">
Expand All @@ -284,7 +284,7 @@ const CampaignWizard: FC<CampaignWizardProps> = () => {
setValue={setLockupPeriodInDays}
loadingSafetyCheck={() => {}}
maxDecimals={4}
disabled={!wallet.connected}
disabled={!walletContext.connected}
/>
</div>
</div>
Expand All @@ -295,7 +295,7 @@ const CampaignWizard: FC<CampaignWizardProps> = () => {
setValue={setDepositCapacity}
loadingSafetyCheck={() => {}}
maxDecimals={3}
disabled={!wallet.connected}
disabled={!walletContext.connected}
/>
</div>
<div></div>
Expand Down
31 changes: 15 additions & 16 deletions apps/marginfi-v2-ui/src/components/Earn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ import { Bank, PriceBias } from "@mrgnlabs/marginfi-client-v2";
import { Countdown } from "~/components/Countdown";
import { toast } from "react-toastify";
import BigNumber from "bignumber.js";
import { useWalletWithOverride } from "~/components/useWalletWithOverride";
import { useWalletContext } from "~/components/useWalletContext";
import { useMrgnlendStore } from "~/store";

const Earn = () => {
const walletContext = useWallet();
const { wallet, isOverride } = useWalletWithOverride();
const { wallet, isOverride, connected, walletAddress } = useWalletContext();
const { connection } = useConnection();
const { lipClient } = useLipClient();

Expand Down Expand Up @@ -128,31 +127,31 @@ const Earn = () => {
useEffect(() => {
(async function () {
setInitialFetchDone(true);
if (!mfiClient || !lipClient || !walletContext.publicKey) return;
const lipAccount = await LipAccount.fetch(walletContext.publicKey, lipClient, mfiClient);
if (!mfiClient || !lipClient || !walletAddress) return;
const lipAccount = await LipAccount.fetch(walletAddress, lipClient, mfiClient);
setLipAccount(lipAccount);
})();
}, [lipClient, mfiClient, walletContext.publicKey]);
}, [lipClient, mfiClient, walletAddress]);

useEffect(() => {
if (walletContext.connected) {
if (connected) {
setProgressPercent(50);
} else {
setProgressPercent(0);
}
}, [walletContext.connected]);
}, [connected]);

useEffect(() => {
if (amount > 0) {
setProgressPercent(100);
} else {
if (walletContext.connected) {
if (connected) {
setProgressPercent(50);
} else {
setProgressPercent(0);
}
}
}, [amount, walletContext.connected]);
}, [amount, connected]);

const depositAction = useCallback(async () => {
if (!lipAccount || !lipClient || !selectedCampaign || amount === 0 || whitelistedCampaignsWithMeta.length === 0)
Expand Down Expand Up @@ -216,7 +215,7 @@ const Earn = () => {
<div className="w-[360px] flex flex-col items-center gap-6">
<div className="w-[300px] h-[100px] flex flex-col gap-5 justify-center">
<div className="flex flex-col gap-1 w-full justify-center">
{walletContext.connected && (
{connected && (
<div className="text-2xl flex justify-center gap-2" style={{ fontWeight: 400 }}>
Your total deposits:
<span style={{ color: "#51B56A" }}>
Expand Down Expand Up @@ -275,7 +274,7 @@ const Earn = () => {
maxValue={maxDepositAmount}
loadingSafetyCheck={loadingSafetyCheck}
maxDecimals={2}
disabled={!walletContext.connected}
disabled={!connected}
/>
</div>

Expand Down Expand Up @@ -625,21 +624,21 @@ interface EarnActionProps extends ButtonProps {
}

export const EarnAction: FC<EarnActionProps> = ({ children, spinning, disabled, ...otherProps }) => {
const walletContext = useWallet();
const { connected } = useWalletContext();

return walletContext.connected ? (
return connected ? (
<Button
className={`bg-white text-black normal-case text-sm min-w-[360px] w-[360px] h-12 rounded-[100px] ${
disabled && "cursor-not-allowed"
}`}
style={{
backgroundColor: disabled || !walletContext.connected ? "gray" : "rgb(227, 227, 227)",
backgroundColor: disabled || !connected ? "gray" : "rgb(227, 227, 227)",
color: "black",
fontFamily: "Aeonik Pro",
zIndex: 10,
}}
{...otherProps}
disabled={disabled || !walletContext.connected}
disabled={disabled || !connected}
>
{spinning ? <CircularProgress style={{ color: "#3CAB5F", width: "20px", height: "20px" }} /> : children}
</Button>
Expand Down
Loading

0 comments on commit c60adaf

Please sign in to comment.