Skip to content

Commit

Permalink
fix: implemented feedback from review
Browse files Browse the repository at this point in the history
  • Loading branch information
k0beLeenders committed Oct 31, 2024
1 parent a86272e commit 977ab08
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 331 deletions.
31 changes: 27 additions & 4 deletions apps/marginfi-v2-trading/src/components/common/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ import React from "react";
import Link from "next/link";
import { useRouter } from "next/router";
import { motion, useAnimate } from "framer-motion";
import { IconPlus, IconCopy, IconCheck } from "@tabler/icons-react";
import { IconPlus, IconCopy, IconCheck, IconSettings } from "@tabler/icons-react";
import { CopyToClipboard } from "react-copy-to-clipboard";
import { cn } from "@mrgnlabs/mrgn-utils";
import { USDC_MINT } from "@mrgnlabs/mrgn-common";
import { Settings } from "@mrgnlabs/mrgn-ui";

import { useTradeStore } from "~/store";
import { useTradeStore, useUiStore } from "~/store";
import { useWallet } from "~/components/wallet-v2/hooks/use-wallet.hook";
import { useIsMobile } from "~/hooks/use-is-mobile";
import { useConnection } from "~/hooks/use-connection";

import { Wallet } from "~/components/wallet-v2";
import { Button } from "~/components/ui/button";
import { IconArena } from "~/components/ui/icons";
import { Popover, PopoverContent, PopoverTrigger } from "~/components/ui/popover";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "~/components/ui/tooltip";

import { CreatePoolScriptDialog } from "../Pool/CreatePoolScript";
import { CreatePoolSoon } from "../Pool/CreatePoolSoon";
import { SettingsPopover } from "../settings";

const navItems = [
{ label: "Discover", href: "/" },
Expand All @@ -42,6 +43,13 @@ export const Header = () => {
state.referralCode,
]
);
const { priorityType, broadcastType, maxCap, maxCapType, setTransactionSettings } = useUiStore((state) => ({
priorityType: state.priorityType,
broadcastType: state.broadcastType,
maxCap: state.maxCap,
maxCapType: state.maxCapType,
setTransactionSettings: state.setTransactionSettings,
}));
const { wallet } = useWallet();
const { asPath } = useRouter();
const isMobile = useIsMobile();
Expand Down Expand Up @@ -141,7 +149,22 @@ export const Header = () => {
/> */}
</div>
)}
<SettingsPopover />
<Popover>
<PopoverTrigger asChild>
<Button variant="ghost" size="icon" className="h-10 w-10 shrink-0">
<IconSettings size={20} />
</Button>
</PopoverTrigger>
<PopoverContent className="w-80">
<Settings
onChange={setTransactionSettings}
broadcastType={broadcastType}
priorityType={priorityType}
maxCap={maxCap}
maxCapType={maxCapType}
/>
</PopoverContent>
</Popover>
<Wallet
connection={connection}
initialized={initialized}
Expand Down

This file was deleted.

This file was deleted.

19 changes: 6 additions & 13 deletions apps/marginfi-v2-trading/src/store/uiStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { persist } from "zustand/middleware";
import { ActionType } from "@mrgnlabs/marginfi-v2-ui-state";

import { LendingModes, PreviousTxn } from "~/types";
import { MaxCapType, TransactionBroadcastType, TransactionPriorityType } from "@mrgnlabs/mrgn-common";
import {
MaxCapType,
TransactionBroadcastType,
TransactionPriorityType,
TransactionSettings,
} from "@mrgnlabs/mrgn-common";
import { DEFAULT_PRIORITY_SETTINGS } from "@mrgnlabs/mrgn-utils";

export enum WalletState {
Expand All @@ -17,13 +22,6 @@ export enum WalletState {
BUY = "buy",
}

type TransactionSettings = {
broadcastType: TransactionBroadcastType;
priorityType: TransactionPriorityType;
maxCapType: MaxCapType;
maxCap: number;
};

interface UiState {
// State
isWalletAuthDialogOpen: boolean;
Expand Down Expand Up @@ -59,11 +57,6 @@ function createUiStore() {
persist(stateCreator, {
name: "uiStore",
onRehydrateStorage: () => (state) => {
// overwrite priority fee
// if (process.env.NEXT_PUBLIC_INIT_PRIO_FEE && process.env.NEXT_PUBLIC_INIT_PRIO_FEE !== "0") {
// state?.setPriorityFee(Number(process.env.NEXT_PUBLIC_INIT_PRIO_FEE));
// }

// overwrite wallet on mobile
// covers private key export modal when open
if (window.innerWidth < 768) {
Expand Down
32 changes: 27 additions & 5 deletions apps/marginfi-v2-ui/src/components/common/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import Image from "next/image";
import { useRouter } from "next/router";

import { PublicKey } from "@solana/web3.js";
// import LipAccount from "@mrgnlabs/lip-client/src/account";
import { IconBell, IconBrandTelegram, IconSettings } from "@tabler/icons-react";

import { collectRewardsBatch, capture, cn } from "@mrgnlabs/mrgn-utils";
import { Wallet } from "@mrgnlabs/mrgn-ui";
import { Settings, Wallet } from "@mrgnlabs/mrgn-ui";

import { useMrgnlendStore, useUiStore, useUserProfileStore } from "~/store";
import { useFirebaseAccount } from "~/hooks/useFirebaseAccount";
Expand All @@ -21,7 +20,6 @@ import { EMISSION_MINT_INFO_MAP } from "~/components/desktop/AssetList/component
import { Popover, PopoverContent, PopoverTrigger } from "~/components/ui/popover";
import { Button } from "~/components/ui/button";
import { IconMrgn } from "~/components/ui/icons";
import { SettingsPopover } from "~/components/common/settings";

// @todo implement second pretty navbar row
export const Navbar: FC = () => {
Expand Down Expand Up @@ -53,7 +51,16 @@ export const Navbar: FC = () => {
state.fetchMrgnlendState,
]);

const [isOraclesStale] = useUiStore((state) => [state.isOraclesStale]);
const { isOraclesStale, priorityType, broadcastType, maxCap, maxCapType, setTransactionSettings } = useUiStore(
(state) => ({
isOraclesStale: state.isOraclesStale,
priorityType: state.priorityType,
broadcastType: state.broadcastType,
maxCap: state.maxCap,
maxCapType: state.maxCapType,
setTransactionSettings: state.setTransactionSettings,
})
);

const [userPointsData] = useUserProfileStore((state) => [state.userPointsData]);

Expand Down Expand Up @@ -205,7 +212,22 @@ export const Navbar: FC = () => {
</PopoverContent>
</Popover>

<SettingsPopover />
<Popover>
<PopoverTrigger asChild>
<Button variant="ghost" size="icon" className="h-10 w-10 shrink-0">
<IconSettings size={20} />
</Button>
</PopoverTrigger>
<PopoverContent className="w-80">
<Settings
onChange={setTransactionSettings}
broadcastType={broadcastType}
priorityType={priorityType}
maxCap={maxCap}
maxCapType={maxCapType}
/>
</PopoverContent>
</Popover>

<Wallet
connection={connection}
Expand Down

This file was deleted.

This file was deleted.

24 changes: 8 additions & 16 deletions apps/marginfi-v2-ui/src/store/uiStore.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { create, StateCreator } from "zustand";
import { persist } from "zustand/middleware";

import { ActionType } from "@mrgnlabs/marginfi-v2-ui-state";
import { MaxCapType, TransactionBroadcastType, TransactionPriorityType } from "@mrgnlabs/mrgn-common";
import {
MaxCapType,
TransactionBroadcastType,
TransactionPriorityType,
TransactionSettings,
} from "@mrgnlabs/mrgn-common";
import { LendingModes, PoolTypes, DEFAULT_PRIORITY_SETTINGS } from "@mrgnlabs/mrgn-utils";

import { SortType, sortDirection, SortAssetOption, PreviousTxn } from "~/types";
import { SortType, sortDirection, SortAssetOption } from "~/types";

const SORT_OPTIONS_MAP: { [key in SortType]: SortAssetOption } = {
APY_DESC: {
Expand Down Expand Up @@ -36,13 +40,6 @@ const SORT_OPTIONS_MAP: { [key in SortType]: SortAssetOption } = {
},
};

type TransactionSettings = {
broadcastType: TransactionBroadcastType;
priorityType: TransactionPriorityType;
maxCap: number;
maxCapType: MaxCapType;
};

interface UiState {
// State
isMenuDrawerOpen: boolean;
Expand Down Expand Up @@ -74,12 +71,7 @@ function createUiStore() {
return create<UiState>()(
persist(stateCreator, {
name: "uiStore",
onRehydrateStorage: () => (state) => {
// overwrite priority fee
// if (process.env.NEXT_PUBLIC_INIT_PRIO_FEE && process.env.NEXT_PUBLIC_INIT_PRIO_FEE !== "0") {
// state?.setPriorityFee(Number(process.env.NEXT_PUBLIC_INIT_PRIO_FEE));
// }
},
onRehydrateStorage: () => (state) => {},
})
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/marginfi-client-v2/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ class MarginfiClient {
return signature;
}

await sleep(1000); // Wait before retrying
await sleep(500); // Wait before retrying
}
} catch (error) {
console.error(error);
Expand Down
7 changes: 7 additions & 0 deletions packages/mrgn-common/src/priority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ export type TransactionPriorityType = "NORMAL" | "HIGH" | "MAMAS";

export type MaxCapType = "DYNAMIC" | "MANUAL";

export type TransactionSettings = {
broadcastType: TransactionBroadcastType;
priorityType: TransactionPriorityType;
maxCapType: MaxCapType;
maxCap: number;
};

// easy to use values for user convenience
export const enum PriotitizationFeeLevels {
LOW = 2500,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,20 @@ interface ActionSettingsProps {
returnLabel?: string;
}

enum SettingsState {
Slippage = "slippage",
PriorityFee = "priority-fee",
}

export const ActionSettings = ({
slippage,
changeSlippage,

toggleSettings,
returnLabel = "Back",
}: ActionSettingsProps) => {
const [settingsMode, setSettingsMode] = React.useState<SettingsState>(SettingsState.PriorityFee);

return (
<div className="space-y-6">
<div className="space-y-3">
<button className="flex items-center gap-1.5 text-sm" onClick={() => toggleSettings(false)}>
<IconArrowLeft size={18} /> {returnLabel}
</button>
{/* Navigator logic if we have more settings */}
{/* {slippage !== undefined && (
<ToggleGroup
value={settingsMode}
Expand All @@ -44,10 +38,10 @@ export const ActionSettings = ({
</ToggleGroupItem>
<ToggleGroupItem value="priority-fee" className="w-1/2 text-xs gap-1.5">
Priority Fee
Setting 2
</ToggleGroupItem>
</ToggleGroup>
)} */}
)} */}
</div>
<div>
{slippage !== undefined && (
Expand All @@ -57,10 +51,6 @@ export const ActionSettings = ({
setSlippagePct={(value) => changeSlippage(value * 100)}
/>
)}

{/* {priorityFee !== undefined && settingsMode === SettingsState.PriorityFee && (
<PriorityFees toggleSettings={toggleSettings} priorityFee={priorityFee} setPriorityFee={changePriorityFee} />
)} */}
</div>
</div>
);
Expand Down
Loading

0 comments on commit 977ab08

Please sign in to comment.