diff --git a/apps/hub/src/app/pools/[poolId]/deposit/AddLiquidityContent.tsx b/apps/hub/src/app/pools/[poolId]/deposit/AddLiquidityContent.tsx
index c8eead559..d52628025 100755
--- a/apps/hub/src/app/pools/[poolId]/deposit/AddLiquidityContent.tsx
+++ b/apps/hub/src/app/pools/[poolId]/deposit/AddLiquidityContent.tsx
@@ -28,6 +28,7 @@ import {
} from "@bera/shared-ui";
import { cn } from "@bera/ui";
import { Button } from "@bera/ui/button";
+import { Switch } from "@bera/ui/switch";
import { Card, CardContent, CardHeader, CardTitle } from "@bera/ui/card";
import { Icons } from "@bera/ui/icons";
import { Address, formatEther } from "viem";
@@ -48,6 +49,7 @@ import { beraToken, wBeraToken } from "@bera/wagmi";
import { useAddLiquidity } from "./useAddLiquidity";
import { Alert, AlertDescription, AlertTitle } from "@bera/ui/alert";
import { Checkbox } from "@bera/ui/checkbox";
+import AddLiquidityError from "./AddLiquidityError";
interface IAddLiquidityContent {
poolId: Address;
@@ -298,39 +300,34 @@ export default function AddLiquidityContent({ poolId }: IAddLiquidityContent) {
);
})}
- {process.env.NODE_ENV === "development" && (
-
-
- setType((t) =>
- t === AddLiquidityKind.Proportional
- ? AddLiquidityKind.Unbalanced
- : AddLiquidityKind.Proportional,
- )
- }
- />
-
-
- )}
+
+
+
+ setType((t) =>
+ t === AddLiquidityKind.Proportional
+ ? AddLiquidityKind.Unbalanced
+ : AddLiquidityKind.Proportional,
+ )
+ }
+ id="balance-amounts"
+ />
+
+
+
- {error && (
-
-
- Error
-
-
- {error.balanceError
- ? `Balancer error ${error.balanceError}`
- : error.message}
-
-
- )}
+
{/* {error && (
Error
diff --git a/apps/hub/src/app/pools/[poolId]/deposit/AddLiquidityError.tsx b/apps/hub/src/app/pools/[poolId]/deposit/AddLiquidityError.tsx
new file mode 100644
index 000000000..4d45f961a
--- /dev/null
+++ b/apps/hub/src/app/pools/[poolId]/deposit/AddLiquidityError.tsx
@@ -0,0 +1,42 @@
+import { Alert, AlertDescription, AlertTitle } from "@bera/ui/alert";
+import { Icons } from "@bera/ui/icons";
+import { AddLiquidityError as AddLiquidityErrorType } from "./useAddLiquidity";
+import { AddLiquidityKind } from "@berachain-foundation/berancer-sdk";
+
+export default function AddLiquidityError({
+ error,
+ transactionType,
+}: {
+ error: AddLiquidityErrorType | undefined;
+ transactionType: AddLiquidityKind;
+}) {
+ if (!error) {
+ return null;
+ }
+
+ const isUnbalanced = transactionType === AddLiquidityKind.Unbalanced;
+
+ const isUnbalanceAndTooMuch =
+ isUnbalanced && error.balanceError === "BAL#001";
+
+ return (
+
+
+ Error
+
+
+ {isUnbalanceAndTooMuch ? (
+
+ Balancer error: {error.balanceError} SUB_OVERFLOW.
+
+ Try to reduce the amount of tokens or use balanced mode.
+
+ ) : error.balanceError ? (
+ `Balancer error ${error.balanceError}`
+ ) : (
+ error.message
+ )}
+
+
+ );
+}
diff --git a/apps/hub/src/app/pools/[poolId]/deposit/useAddLiquidity.ts b/apps/hub/src/app/pools/[poolId]/deposit/useAddLiquidity.ts
index 025732922..0887f0ab4 100644
--- a/apps/hub/src/app/pools/[poolId]/deposit/useAddLiquidity.ts
+++ b/apps/hub/src/app/pools/[poolId]/deposit/useAddLiquidity.ts
@@ -17,6 +17,12 @@ export interface UseAddLiquidityArgs {
wethIsEth: boolean;
}
+export type AddLiquidityError = {
+ error?: unknown;
+ balanceError?: `BAL#${string}`;
+ message?: string;
+};
+
export const useAddLiquidity = ({ pool, wethIsEth }: UseAddLiquidityArgs) => {
const [type, setType] = useState(
AddLiquidityKind.Unbalanced,
@@ -30,11 +36,7 @@ export const useAddLiquidity = ({ pool, wethIsEth }: UseAddLiquidityArgs) => {
>([]);
const [isLoading, setIsLoading] = useState(false);
- const [error, setError] = useState<{
- error?: unknown;
- balanceError?: string;
- message?: string;
- }>();
+ const [error, setError] = useState();
const [priceImpact, setPriceImpact] = useState();
@@ -131,7 +133,7 @@ export const useAddLiquidity = ({ pool, wethIsEth }: UseAddLiquidityArgs) => {
const e = error as ContractFunctionExecutionError;
setError({
error: e,
- balanceError: e?.shortMessage?.split("\n").at(1),
+ balanceError: e?.shortMessage?.split("\n").at(1) as `BAL#${string}`,
message: e.shortMessage,
});
} else {
diff --git a/packages/ui/src/switch.tsx b/packages/ui/src/switch.tsx
index 178070c43..9dea5e18b 100755
--- a/packages/ui/src/switch.tsx
+++ b/packages/ui/src/switch.tsx
@@ -4,24 +4,57 @@ import * as React from "react";
import * as SwitchPrimitives from "@radix-ui/react-switch";
import { cn } from "./utils/cn";
+import { VariantProps, cva } from "class-variance-authority";
+
+const rootVariants = cva(
+ [
+ "peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors",
+ "disabled:cursor-not-allowed disabled:opacity-50",
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
+ "data-[state=checked]:bg-positive data-[state=unchecked]:bg-secondary-foreground",
+ ],
+ {
+ variants: {
+ size: {
+ md: "h-[24px] w-[44px]",
+ sm: "h-[16px] w-[28px]",
+ },
+ },
+ defaultVariants: {
+ size: "md",
+ },
+ },
+);
+
+const thumbVariants = cva(
+ [
+ "pointer-events-none block rounded-full bg-background shadow-lg ring-0 transition-transform",
+ "data-[state=unchecked]:translate-x-0",
+ ],
+ {
+ variants: {
+ size: {
+ md: "h-5 w-5 data-[state=checked]:translate-x-5",
+ sm: "h-3 w-3 data-[state=checked]:translate-x-3",
+ },
+ },
+ defaultVariants: {
+ size: "md",
+ },
+ },
+);
const Switch = React.forwardRef<
React.ElementRef,
- React.ComponentPropsWithoutRef
->(({ className, ...props }, ref) => (
+ React.ComponentPropsWithoutRef &
+ VariantProps
+>(({ className, size, ...props }, ref) => (
-
+
));
Switch.displayName = SwitchPrimitives.Root.displayName;