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

Adds token approval, debounces quote calls, fixes other bugs #60

Merged
merged 3 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { useEffect, useState } from "react";
import { CloseIcon } from "@repo/ui/icons";
import { ActionButton } from "@repo/ui/components";
import { TXN_STATUS } from "../../constants";
import { TXN_STATUS } from "@repo/flame-types";

interface ConfirmationModalProps {
onSubmitCallback: () => void;
Expand All @@ -27,15 +27,15 @@ interface ConfirmationModalProps {

export default function ConfirmationModal({
onSubmitCallback,
setTxnStatus,
txnStatus,
handleResetInputs,
buttonText,
children,
title,
actionButtonText,
handleResetInputs,
isCloseModalAction,
setTxnStatus,
skipIdleTxnStatus,
title,
txnStatus,
actionButtonText,
}: ConfirmationModalProps): React.ReactElement {
const [open, setOpen] = useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import { GearIcon } from "@repo/ui/icons";
import { InfoTooltip } from "@repo/ui/components";
import { useState } from "react";
import { getFromLocalStorage, setInLocalStorage } from "utils/utils";
import { defaultSlippageTolerance } from "../../constants";
import { useConfig } from "config";

export const SettingsPopover = () => {
const { SwapDefaultSlippageTolerance } = useConfig();
const currentSettings = getFromLocalStorage("settings") || {};
const [customSlippage, setCustomSlippage] = useState<string>(
currentSettings?.slippageTolerance?.toString() ||
defaultSlippageTolerance.toString(),
SwapDefaultSlippageTolerance.toString(),
);
const [expertMode, setExpertMode] = useState(
currentSettings?.expertMode || false,
Expand Down
39 changes: 39 additions & 0 deletions apps/flame-defi/app/config/contexts/ConfigContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,42 @@ export const ConfigContextProvider: React.FC<ConfigContextProps> = ({
const poolURL = getEnvVariable("NEXT_PUBLIC_POOL_URL");
const earnAPIURL = getEnvVariable("NEXT_PUBLIC_EARN_API_URL");

const TokenDefaultApprovalAmount =
"115792089237316195423570985008687907853269984665640564039457";

const SwapDefaultSlippageTolerance = 0.1;

const feeData = [
{
id: 0,
feePercent: "0.3%",
text: "Best for most pairs.",
tvl: "100M",
selectPercent: "0.3%",
},
{
id: 1,
feePercent: "0.5%",
text: "Best for stable pairs.",
tvl: "100M",
selectPercent: "0.5%",
},
{
id: 2,
feePercent: "1%",
text: "Best for high-volatility pairs.",
tvl: "100M",
selectPercent: "1%",
},
{
id: 3,
feePercent: "1%",
text: "Best for high-volatility pairs.",
tvl: "100M",
selectPercent: "1%",
},
];

let feedbackFormURL: string | null;
try {
feedbackFormURL = getEnvVariable("NEXT_PUBLIC_FEEDBACK_FORM_URL");
Expand Down Expand Up @@ -68,6 +104,9 @@ export const ConfigContextProvider: React.FC<ConfigContextProps> = ({
earnAPIURL,
feedbackFormURL,
networksList,
TokenDefaultApprovalAmount,
SwapDefaultSlippageTolerance,
feeData,
}}
>
{children}
Expand Down
1 change: 0 additions & 1 deletion apps/flame-defi/app/config/hooks/useConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client";

import { useContext } from "react";

import { ConfigContext } from "../contexts/ConfigContext";
import { EvmChainInfo } from "@repo/flame-types";

Expand Down
12 changes: 12 additions & 0 deletions apps/flame-defi/app/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ export interface AppConfig {
feedbackFormURL: string | null;
// List of networks to display in the network selector.
networksList: FlameNetwork[];
// The default approval amount for tokens.
TokenDefaultApprovalAmount: string;
// The default slippage tolerance for swaps.
SwapDefaultSlippageTolerance: number;
// The data for the fee options.
feeData: {
id: number;
feePercent: string;
text: string;
tvl: string;
selectPercent: string;
}[];
}

export {
Expand Down
49 changes: 0 additions & 49 deletions apps/flame-defi/app/constants.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
AccordionItem,
AccordionTrigger,
} from "@repo/ui/shadcn-primitives";
import { useEvmChainData } from "config";

interface ConnectEvmWalletButtonProps {
// Label to show before the user is connected to a wallet.
Expand All @@ -24,6 +25,7 @@ interface ConnectEvmWalletButtonProps {
export default function ConnectEvmWalletButton({
labelBeforeConnected,
}: ConnectEvmWalletButtonProps) {
const { selectedChain } = useEvmChainData();
const {
connectEvmWallet,
disconnectEvmWallet,
Expand Down Expand Up @@ -61,10 +63,16 @@ export default function ConnectEvmWalletButton({
</AccordionTrigger>
<div className="flex items-center gap-3">
<CopyToClipboardButton textToCopy={userAccount.address} />
<UpRightSquareIcon
className="cursor-pointer hover:text-white transition"
size={21}
/>
<a
href={`${selectedChain.blockExplorerUrl}/address/${userAccount.address}`}
target="_blank"
rel="noreferrer"
>
<UpRightSquareIcon
className="cursor-pointer hover:text-white transition"
size={21}
/>
</a>
<button type="button" onClick={() => disconnectEvmWallet()}>
<PowerIcon
className="cursor-pointer hover:text-white transition"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
PopoverContent,
PopoverTrigger,
} from "@repo/ui/shadcn-primitives";

import { useEvmChainData } from "config";
export function SingleWalletContent({
address,
handleClose,
Expand All @@ -18,6 +18,7 @@ export function SingleWalletContent({
handleClose?: () => void;
}) {
// const [showTransactions, setShowTransactions] = useState(false);
const { selectedChain } = useEvmChainData();
const {
disconnectEvmWallet,
evmNativeTokenBalance,
Expand All @@ -32,7 +33,7 @@ export function SingleWalletContent({
};

return (
<div className="">
<div>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<FlameIcon />
Expand All @@ -43,10 +44,16 @@ export function SingleWalletContent({
</div>
<div className="flex items-center gap-3 text-grey-light">
<CopyToClipboardButton textToCopy={address} />
<UpRightSquareIcon
className="cursor-pointer hover:text-white transition"
size={21}
/>
<a
href={`${selectedChain.blockExplorerUrl}/address/${address}`}
target="_blank"
rel="noreferrer"
>
<UpRightSquareIcon
className="cursor-pointer hover:text-white transition"
size={21}
/>
</a>
<button type="button" onClick={() => handleDisconnect()}>
<PowerIcon
className="cursor-pointer hover:text-white transition"
Expand Down Expand Up @@ -109,7 +116,7 @@ export default function SingleWalletConnect() {
</PopoverTrigger>
<PopoverContent
side="bottom"
className="flex flex-col mr-12 gap-3 p-5 bg-radial-dark"
className="flex flex-col mr-12 gap-3 p-5 bg-radial-dark w-full md:w-[300px]"
>
<SingleWalletContent address={userAccount.address} />
</PopoverContent>
Expand Down
Loading