@b3dotfun/sdk 0.0.42-alpha.2 → 0.0.42-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/global-account/react/components/index.d.ts +8 -7
- package/dist/cjs/global-account/react/components/index.js +29 -23
- package/dist/cjs/global-account/react/components/ui/dropdown-menu.d.ts +27 -0
- package/dist/cjs/global-account/react/components/ui/dropdown-menu.js +100 -0
- package/dist/cjs/shared/constants/currency.d.ts +1 -0
- package/dist/cjs/shared/constants/currency.js +5 -0
- package/dist/cjs/shared/constants/index.d.ts +1 -0
- package/dist/cjs/shared/constants/index.js +15 -0
- package/dist/cjs/shared/react/components/CurrencySelector.d.ts +7 -0
- package/dist/cjs/shared/react/components/CurrencySelector.js +14 -0
- package/dist/cjs/shared/react/components/FormattedCurrency.d.ts +12 -0
- package/dist/cjs/shared/react/components/FormattedCurrency.js +60 -0
- package/dist/cjs/shared/react/components/index.d.ts +2 -0
- package/dist/cjs/shared/react/components/index.js +18 -0
- package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
- package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +245 -0
- package/dist/cjs/shared/react/hooks/index.d.ts +1 -0
- package/dist/cjs/shared/react/hooks/index.js +1 -0
- package/dist/cjs/shared/react/hooks/useCurrencyConversion.d.ts +35 -0
- package/dist/cjs/shared/react/hooks/useCurrencyConversion.js +200 -0
- package/dist/cjs/shared/react/index.d.ts +2 -0
- package/dist/cjs/shared/react/index.js +2 -0
- package/dist/cjs/shared/react/stores/currencyModalStore.d.ts +7 -0
- package/dist/cjs/shared/react/stores/currencyModalStore.js +9 -0
- package/dist/cjs/shared/react/stores/currencyStore.d.ts +51 -0
- package/dist/cjs/shared/react/stores/currencyStore.js +57 -0
- package/dist/cjs/shared/react/stores/index.d.ts +2 -0
- package/dist/cjs/shared/react/stores/index.js +18 -0
- package/dist/esm/global-account/react/components/index.d.ts +8 -7
- package/dist/esm/global-account/react/components/index.js +8 -7
- package/dist/esm/global-account/react/components/ui/dropdown-menu.d.ts +27 -0
- package/dist/esm/global-account/react/components/ui/dropdown-menu.js +60 -0
- package/dist/esm/shared/constants/currency.d.ts +1 -0
- package/dist/esm/shared/constants/currency.js +2 -0
- package/dist/esm/shared/constants/index.d.ts +1 -0
- package/dist/esm/shared/constants/index.js +1 -0
- package/dist/esm/shared/react/components/CurrencySelector.d.ts +7 -0
- package/dist/esm/shared/react/components/CurrencySelector.js +11 -0
- package/dist/esm/shared/react/components/FormattedCurrency.d.ts +12 -0
- package/dist/esm/shared/react/components/FormattedCurrency.js +57 -0
- package/dist/esm/shared/react/components/index.d.ts +2 -0
- package/dist/esm/shared/react/components/index.js +2 -0
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +243 -0
- package/dist/esm/shared/react/hooks/index.d.ts +1 -0
- package/dist/esm/shared/react/hooks/index.js +1 -0
- package/dist/esm/shared/react/hooks/useCurrencyConversion.d.ts +35 -0
- package/dist/esm/shared/react/hooks/useCurrencyConversion.js +197 -0
- package/dist/esm/shared/react/index.d.ts +2 -0
- package/dist/esm/shared/react/index.js +2 -0
- package/dist/esm/shared/react/stores/currencyModalStore.d.ts +7 -0
- package/dist/esm/shared/react/stores/currencyModalStore.js +6 -0
- package/dist/esm/shared/react/stores/currencyStore.d.ts +51 -0
- package/dist/esm/shared/react/stores/currencyStore.js +54 -0
- package/dist/esm/shared/react/stores/index.d.ts +2 -0
- package/dist/esm/shared/react/stores/index.js +2 -0
- package/dist/styles/index.css +1 -1
- package/dist/types/global-account/react/components/index.d.ts +8 -7
- package/dist/types/global-account/react/components/ui/dropdown-menu.d.ts +27 -0
- package/dist/types/shared/constants/currency.d.ts +1 -0
- package/dist/types/shared/constants/index.d.ts +1 -0
- package/dist/types/shared/react/components/CurrencySelector.d.ts +7 -0
- package/dist/types/shared/react/components/FormattedCurrency.d.ts +12 -0
- package/dist/types/shared/react/components/index.d.ts +2 -0
- package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
- package/dist/types/shared/react/hooks/index.d.ts +1 -0
- package/dist/types/shared/react/hooks/useCurrencyConversion.d.ts +35 -0
- package/dist/types/shared/react/index.d.ts +2 -0
- package/dist/types/shared/react/stores/currencyModalStore.d.ts +7 -0
- package/dist/types/shared/react/stores/currencyStore.d.ts +51 -0
- package/dist/types/shared/react/stores/index.d.ts +2 -0
- package/package.json +29 -3
- package/src/global-account/react/components/index.ts +19 -12
- package/src/global-account/react/components/ui/dropdown-menu.tsx +132 -0
- package/src/shared/constants/currency.ts +2 -0
- package/src/shared/constants/index.ts +2 -0
- package/src/shared/react/components/CurrencySelector.tsx +71 -0
- package/src/shared/react/components/FormattedCurrency.tsx +106 -0
- package/src/shared/react/components/index.ts +2 -0
- package/src/shared/react/hooks/__tests__/useCurrencyConversion.test.ts +308 -0
- package/src/shared/react/hooks/index.ts +1 -0
- package/src/shared/react/hooks/useCurrencyConversion.ts +211 -0
- package/src/shared/react/index.ts +2 -0
- package/src/shared/react/stores/currencyModalStore.ts +13 -0
- package/src/shared/react/stores/currencyStore.ts +82 -0
- package/src/shared/react/stores/index.ts +2 -0
|
@@ -4,12 +4,12 @@ export { RelayKitProviderWrapper } from "./B3Provider/RelayKitProviderWrapper";
|
|
|
4
4
|
export { B3Context, type B3ContextType } from "./B3Provider/types";
|
|
5
5
|
export { useB3 } from "./B3Provider/useB3";
|
|
6
6
|
export { StyleRoot } from "./StyleRoot";
|
|
7
|
-
export { SignInWithB3 } from "./SignInWithB3/SignInWithB3";
|
|
8
|
-
export { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow";
|
|
9
|
-
export { SignInWithB3Privy } from "./SignInWithB3/SignInWithB3Privy";
|
|
10
7
|
export { AuthButton } from "./SignInWithB3/components/AuthButton";
|
|
11
8
|
export { PermissionItem } from "./SignInWithB3/components/PermissionItem";
|
|
12
9
|
export { WalletRow } from "./SignInWithB3/components/WalletRow";
|
|
10
|
+
export { SignInWithB3 } from "./SignInWithB3/SignInWithB3";
|
|
11
|
+
export { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow";
|
|
12
|
+
export { SignInWithB3Privy } from "./SignInWithB3/SignInWithB3Privy";
|
|
13
13
|
export { LoginStepContainer } from "./SignInWithB3/steps/LoginStep";
|
|
14
14
|
export { getConnectOptionsFromStrategy, isWalletType, type AllowedStrategy } from "./SignInWithB3/utils/signInUtils";
|
|
15
15
|
export { ManageAccount } from "./ManageAccount/ManageAccount";
|
|
@@ -24,21 +24,22 @@ export { ClientOnly } from "./custom/ClientOnly";
|
|
|
24
24
|
export { CopyToClipboard } from "./custom/CopyToClipboard";
|
|
25
25
|
export { StaggeredFadeLoader } from "./custom/StaggeredFadeLoader";
|
|
26
26
|
export { WalletConnectorIcon } from "./custom/WalletConnectorIcon";
|
|
27
|
-
export { Loading } from "./ui/Loading";
|
|
28
|
-
export { ShinyButton } from "./ui/ShinyButton";
|
|
29
|
-
export { TabTrigger, Tabs, TabsContent, TabsList, TabsTransitionWrapper } from "./ui/TabSystem";
|
|
30
|
-
export { TabTrigger as TabTriggerPrimitive, TabsContent as TabsContentPrimitive, TabsList as TabsListPrimitive, Tabs as TabsPrimitive, } from "./ui/Tabs";
|
|
31
27
|
export { Badge, badgeVariants } from "./ui/badge";
|
|
32
28
|
export { Button, buttonVariants } from "./ui/button";
|
|
33
29
|
export { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, } from "./ui/command";
|
|
34
30
|
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, } from "./ui/dialog";
|
|
35
31
|
export { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, } from "./ui/drawer";
|
|
32
|
+
export { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "./ui/dropdown-menu";
|
|
36
33
|
export { GlareCard } from "./ui/glare-card";
|
|
37
34
|
export { GlareCardRounded } from "./ui/glare-card-rounded";
|
|
38
35
|
export { Input } from "./ui/input";
|
|
36
|
+
export { Loading } from "./ui/Loading";
|
|
39
37
|
export { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";
|
|
40
38
|
export { ScrollArea, ScrollBar } from "./ui/scroll-area";
|
|
39
|
+
export { ShinyButton } from "./ui/ShinyButton";
|
|
41
40
|
export { Skeleton } from "./ui/skeleton";
|
|
41
|
+
export { TabTrigger as TabTriggerPrimitive, TabsContent as TabsContentPrimitive, TabsList as TabsListPrimitive, Tabs as TabsPrimitive, } from "./ui/Tabs";
|
|
42
|
+
export { TabTrigger, Tabs, TabsContent, TabsList, TabsTransitionWrapper } from "./ui/TabSystem";
|
|
42
43
|
export { TextLoop } from "./ui/text-loop";
|
|
43
44
|
export { TextShimmer } from "./ui/text-shimmer";
|
|
44
45
|
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip";
|
|
@@ -6,12 +6,12 @@ export { B3Context } from "./B3Provider/types.js";
|
|
|
6
6
|
export { useB3 } from "./B3Provider/useB3.js";
|
|
7
7
|
export { StyleRoot } from "./StyleRoot.js";
|
|
8
8
|
// SignInWithB3 Components
|
|
9
|
-
export { SignInWithB3 } from "./SignInWithB3/SignInWithB3.js";
|
|
10
|
-
export { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow.js";
|
|
11
|
-
export { SignInWithB3Privy } from "./SignInWithB3/SignInWithB3Privy.js";
|
|
12
9
|
export { AuthButton } from "./SignInWithB3/components/AuthButton.js";
|
|
13
10
|
export { PermissionItem } from "./SignInWithB3/components/PermissionItem.js";
|
|
14
11
|
export { WalletRow } from "./SignInWithB3/components/WalletRow.js";
|
|
12
|
+
export { SignInWithB3 } from "./SignInWithB3/SignInWithB3.js";
|
|
13
|
+
export { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow.js";
|
|
14
|
+
export { SignInWithB3Privy } from "./SignInWithB3/SignInWithB3Privy.js";
|
|
15
15
|
export { LoginStepContainer } from "./SignInWithB3/steps/LoginStep.js";
|
|
16
16
|
export { getConnectOptionsFromStrategy, isWalletType } from "./SignInWithB3/utils/signInUtils.js";
|
|
17
17
|
// ManageAccount Components
|
|
@@ -34,21 +34,22 @@ export { CopyToClipboard } from "./custom/CopyToClipboard.js";
|
|
|
34
34
|
export { StaggeredFadeLoader } from "./custom/StaggeredFadeLoader.js";
|
|
35
35
|
export { WalletConnectorIcon } from "./custom/WalletConnectorIcon.js";
|
|
36
36
|
// UI Components
|
|
37
|
-
export { Loading } from "./ui/Loading.js";
|
|
38
|
-
export { ShinyButton } from "./ui/ShinyButton.js";
|
|
39
|
-
export { TabTrigger, Tabs, TabsContent, TabsList, TabsTransitionWrapper } from "./ui/TabSystem.js";
|
|
40
|
-
export { TabTrigger as TabTriggerPrimitive, TabsContent as TabsContentPrimitive, TabsList as TabsListPrimitive, Tabs as TabsPrimitive, } from "./ui/Tabs.js";
|
|
41
37
|
export { Badge, badgeVariants } from "./ui/badge.js";
|
|
42
38
|
export { Button, buttonVariants } from "./ui/button.js";
|
|
43
39
|
export { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, } from "./ui/command.js";
|
|
44
40
|
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, } from "./ui/dialog.js";
|
|
45
41
|
export { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, } from "./ui/drawer.js";
|
|
42
|
+
export { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "./ui/dropdown-menu.js";
|
|
46
43
|
export { GlareCard } from "./ui/glare-card.js";
|
|
47
44
|
export { GlareCardRounded } from "./ui/glare-card-rounded.js";
|
|
48
45
|
export { Input } from "./ui/input.js";
|
|
46
|
+
export { Loading } from "./ui/Loading.js";
|
|
49
47
|
export { Popover, PopoverContent, PopoverTrigger } from "./ui/popover.js";
|
|
50
48
|
export { ScrollArea, ScrollBar } from "./ui/scroll-area.js";
|
|
49
|
+
export { ShinyButton } from "./ui/ShinyButton.js";
|
|
51
50
|
export { Skeleton } from "./ui/skeleton.js";
|
|
51
|
+
export { TabTrigger as TabTriggerPrimitive, TabsContent as TabsContentPrimitive, TabsList as TabsListPrimitive, Tabs as TabsPrimitive, } from "./ui/Tabs.js";
|
|
52
|
+
export { TabTrigger, Tabs, TabsContent, TabsList, TabsTransitionWrapper } from "./ui/TabSystem.js";
|
|
52
53
|
export { TextLoop } from "./ui/text-loop.js";
|
|
53
54
|
export { TextShimmer } from "./ui/text-shimmer.js";
|
|
54
55
|
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
interface DropdownMenuProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
}
|
|
5
|
+
interface DropdownMenuContentProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
align?: "start" | "center" | "end";
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
interface DropdownMenuItemProps {
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
onClick?: () => void;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
interface DropdownMenuSeparatorProps {
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
interface DropdownMenuTriggerProps {
|
|
19
|
+
children: React.ReactNode;
|
|
20
|
+
asChild?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function DropdownMenu({ children }: DropdownMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export declare function DropdownMenuTrigger({ children, asChild }: DropdownMenuTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
export declare function DropdownMenuContent({ children, align, className }: DropdownMenuContentProps): import("react/jsx-runtime").JSX.Element | null;
|
|
25
|
+
export declare function DropdownMenuItem({ children, onClick, className }: DropdownMenuItemProps): import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
export declare function DropdownMenuSeparator({ className }: DropdownMenuSeparatorProps): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { cn } from "../../../../shared/utils/index.js";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
const DropdownMenuContext = React.createContext({
|
|
6
|
+
isOpen: false,
|
|
7
|
+
setIsOpen: () => { },
|
|
8
|
+
});
|
|
9
|
+
export function DropdownMenu({ children }) {
|
|
10
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
11
|
+
React.useEffect(() => {
|
|
12
|
+
const handleClickOutside = (event) => {
|
|
13
|
+
const target = event.target;
|
|
14
|
+
if (!target.closest("[data-dropdown-menu]")) {
|
|
15
|
+
setIsOpen(false);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
if (isOpen) {
|
|
19
|
+
document.addEventListener("click", handleClickOutside);
|
|
20
|
+
return () => document.removeEventListener("click", handleClickOutside);
|
|
21
|
+
}
|
|
22
|
+
}, [isOpen]);
|
|
23
|
+
return (_jsx(DropdownMenuContext.Provider, { value: { isOpen, setIsOpen }, children: _jsx("div", { className: "relative", "data-dropdown-menu": true, children: children }) }));
|
|
24
|
+
}
|
|
25
|
+
export function DropdownMenuTrigger({ children, asChild }) {
|
|
26
|
+
const { isOpen, setIsOpen } = React.useContext(DropdownMenuContext);
|
|
27
|
+
const handleClick = () => {
|
|
28
|
+
setIsOpen(!isOpen);
|
|
29
|
+
};
|
|
30
|
+
if (asChild) {
|
|
31
|
+
if (React.isValidElement(children)) {
|
|
32
|
+
return React.cloneElement(children, {
|
|
33
|
+
onClick: handleClick,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return _jsx("button", { onClick: handleClick, children: children });
|
|
38
|
+
}
|
|
39
|
+
export function DropdownMenuContent({ children, align = "start", className }) {
|
|
40
|
+
const { isOpen } = React.useContext(DropdownMenuContext);
|
|
41
|
+
if (!isOpen)
|
|
42
|
+
return null;
|
|
43
|
+
const alignmentClasses = {
|
|
44
|
+
start: "left-0",
|
|
45
|
+
center: "left-1/2 -translate-x-1/2",
|
|
46
|
+
end: "right-0",
|
|
47
|
+
};
|
|
48
|
+
return (_jsx("div", { className: cn("bg-popover text-popover-foreground absolute top-full z-50 mt-1 min-w-32 overflow-hidden rounded-md border p-1 shadow-md", "border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-800", alignmentClasses[align], className), children: children }));
|
|
49
|
+
}
|
|
50
|
+
export function DropdownMenuItem({ children, onClick, className }) {
|
|
51
|
+
const { setIsOpen } = React.useContext(DropdownMenuContext);
|
|
52
|
+
const handleClick = () => {
|
|
53
|
+
onClick?.();
|
|
54
|
+
setIsOpen(false);
|
|
55
|
+
};
|
|
56
|
+
return (_jsx("div", { className: cn("hover:bg-accent hover:text-accent-foreground relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50", "hover:bg-gray-100 dark:hover:bg-gray-700", className), onClick: handleClick, children: children }));
|
|
57
|
+
}
|
|
58
|
+
export function DropdownMenuSeparator({ className }) {
|
|
59
|
+
return _jsx("div", { className: cn("bg-muted -mx-1 my-1 h-px", "bg-gray-200 dark:bg-gray-600", className) });
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const B3_COIN_IMAGE_URL = "https://cdn.b3.fun/b3-coin-3d.png";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface CurrencySelectorProps {
|
|
2
|
+
labelClassName?: string;
|
|
3
|
+
buttonVariant?: "dark" | "primary" | "ghost" | "gold";
|
|
4
|
+
label?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function CurrencySelector({ labelClassName, buttonVariant, label }: CurrencySelectorProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cn } from "../../../shared/utils/index.js";
|
|
4
|
+
import { Button } from "../../../global-account/react/components/ui/button.js";
|
|
5
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "../../../global-account/react/components/ui/dropdown-menu.js";
|
|
6
|
+
import { CURRENCY_NAMES, CURRENCY_SYMBOLS, useCurrencyStore } from "../stores/currencyStore.js";
|
|
7
|
+
const currencies = ["B3", "ETH", "SOL", "USD", "EUR", "GBP", "KRW", "JPY", "CAD", "AUD"];
|
|
8
|
+
export function CurrencySelector({ labelClassName, buttonVariant = "dark", label }) {
|
|
9
|
+
const { selectedCurrency, setSelectedCurrency } = useCurrencyStore();
|
|
10
|
+
return (_jsx("div", { className: "flex items-center gap-2", children: _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsxs("div", { className: "flex items-center gap-3", children: [label && (_jsx("span", { className: cn("text-foreground text-sm font-medium leading-none tracking-tight sm:text-base", labelClassName), children: label })), _jsxs(Button, { variant: buttonVariant, className: "flex items-center gap-2", children: [_jsx("span", { className: "text-sm font-medium", children: CURRENCY_NAMES[selectedCurrency] }), _jsx("svg", { className: "h-4 w-4", fill: "currentColor", viewBox: "0 0 20 20", children: _jsx("path", { fillRule: "evenodd", d: "M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z", clipRule: "evenodd" }) })] })] }) }), _jsx(DropdownMenuContent, { align: "end", className: "z-[100] min-w-[200px]", children: currencies.map(currency => (_jsxs("div", { children: [_jsxs(DropdownMenuItem, { onClick: () => setSelectedCurrency(currency), className: `flex cursor-pointer items-center justify-between gap-3 px-3 py-2.5 transition-colors ${selectedCurrency === currency ? "bg-accent" : "hover:bg-accent/50"}`, children: [_jsx("span", { className: "text-foreground text-sm font-medium", children: CURRENCY_NAMES[currency] }), _jsx("span", { className: "text-muted-foreground text-xs font-medium", children: CURRENCY_SYMBOLS[currency] })] }), currency === "SOL" && _jsx(DropdownMenuSeparator, { className: "bg-border my-1" }, "separator")] }, currency))) })] }) }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface FormattedCurrencyProps {
|
|
2
|
+
amount: number;
|
|
3
|
+
showChange?: boolean;
|
|
4
|
+
showColor?: boolean;
|
|
5
|
+
className?: string;
|
|
6
|
+
subB3Icon?: boolean;
|
|
7
|
+
clickable?: boolean;
|
|
8
|
+
decimals?: number;
|
|
9
|
+
currency?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function FormattedCurrency({ amount, showChange, showColor, className, subB3Icon, clickable, decimals, currency, }: FormattedCurrencyProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { B3_COIN_IMAGE_URL } from "../../../shared/constants/currency.js";
|
|
4
|
+
import { cn } from "../../../shared/utils/index.js";
|
|
5
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "../../../global-account/react/components/ui/tooltip.js";
|
|
6
|
+
import { useCurrencyConversion } from "../hooks/useCurrencyConversion.js";
|
|
7
|
+
import { useCurrencyModalStore } from "../stores/currencyModalStore.js";
|
|
8
|
+
export function FormattedCurrency({ amount, showChange = false, showColor = false, className, subB3Icon = true, clickable = true, decimals, currency, }) {
|
|
9
|
+
const { formatCurrencyValue, formatTooltipValue, selectedCurrency, baseCurrency } = useCurrencyConversion();
|
|
10
|
+
const { openModal } = useCurrencyModalStore();
|
|
11
|
+
// Use passed currency or fall back to selected currency
|
|
12
|
+
const activeCurrency = currency || selectedCurrency;
|
|
13
|
+
const isPositive = amount >= 0;
|
|
14
|
+
// Get the formatted value (using absolute value for negative numbers when showing change)
|
|
15
|
+
const baseAmount = showChange ? Math.abs(amount) : amount;
|
|
16
|
+
// Use centralized formatting from hook with optional overrides
|
|
17
|
+
const formattedValue = formatCurrencyValue(baseAmount, {
|
|
18
|
+
decimals,
|
|
19
|
+
currency,
|
|
20
|
+
});
|
|
21
|
+
// Generate tooltip using the centralized hook function
|
|
22
|
+
const baseTooltipValue = formatTooltipValue(amount, currency);
|
|
23
|
+
// Add change indicator if needed
|
|
24
|
+
const tooltipValue = showChange ? `${isPositive ? "+" : "-"}${baseTooltipValue}` : baseTooltipValue;
|
|
25
|
+
// Determine color class
|
|
26
|
+
let colorClass = "";
|
|
27
|
+
if (showColor) {
|
|
28
|
+
if (isPositive) {
|
|
29
|
+
colorClass = "text-green-400";
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
colorClass = "text-red-400";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Add change indicator
|
|
36
|
+
let displayValue = formattedValue;
|
|
37
|
+
if (showChange) {
|
|
38
|
+
if (isPositive) {
|
|
39
|
+
displayValue = `+${formattedValue}`;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
displayValue = `-${formattedValue}`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const handleClick = () => {
|
|
46
|
+
if (clickable) {
|
|
47
|
+
openModal();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsxs("span", { onClick: handleClick, className: cn("inline-flex items-center gap-1 whitespace-nowrap", colorClass, className, clickable && "cursor-pointer transition-opacity hover:opacity-80"), children: [subB3Icon &&
|
|
51
|
+
(currency === baseCurrency || (!currency && activeCurrency === baseCurrency)) &&
|
|
52
|
+
baseCurrency === "B3"
|
|
53
|
+
? displayValue.split(" ")[0]
|
|
54
|
+
: displayValue, subB3Icon &&
|
|
55
|
+
(currency === baseCurrency || (!currency && activeCurrency === baseCurrency)) &&
|
|
56
|
+
baseCurrency === "B3" && (_jsx("img", { src: B3_COIN_IMAGE_URL, className: "inline-block h-4 w-4 align-middle", alt: "B3 coin" }))] }) }), _jsx(TooltipContent, { children: tooltipValue })] }));
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { renderHook } from "@testing-library/react";
|
|
3
|
+
import { useCurrencyConversion } from "../useCurrencyConversion.js";
|
|
4
|
+
// Mock the external dependencies
|
|
5
|
+
// Store mock rates for different quote currencies
|
|
6
|
+
const mockRates = {};
|
|
7
|
+
// Mock store state
|
|
8
|
+
const mockStoreState = {
|
|
9
|
+
selectedCurrency: "B3",
|
|
10
|
+
baseCurrency: "B3",
|
|
11
|
+
setSelectedCurrency: vi.fn(),
|
|
12
|
+
setBaseCurrency: vi.fn(),
|
|
13
|
+
};
|
|
14
|
+
vi.mock("@b3dotfun/sdk/global-account/react", () => ({
|
|
15
|
+
useExchangeRate: vi.fn((params) => {
|
|
16
|
+
const rate = mockRates[params?.quoteCurrency];
|
|
17
|
+
return { rate };
|
|
18
|
+
}),
|
|
19
|
+
}));
|
|
20
|
+
vi.mock("@b3dotfun/sdk/shared/utils/number", () => ({
|
|
21
|
+
formatDisplayNumber: vi.fn((value) => {
|
|
22
|
+
const num = Number(value);
|
|
23
|
+
if (isNaN(num))
|
|
24
|
+
return "0";
|
|
25
|
+
return num.toLocaleString("en-US", { maximumFractionDigits: 6 });
|
|
26
|
+
}),
|
|
27
|
+
}));
|
|
28
|
+
vi.mock("../../stores/currencyStore", () => ({
|
|
29
|
+
useCurrencyStore: vi.fn((selector) => {
|
|
30
|
+
if (selector) {
|
|
31
|
+
return selector(mockStoreState);
|
|
32
|
+
}
|
|
33
|
+
return mockStoreState;
|
|
34
|
+
}),
|
|
35
|
+
CURRENCY_SYMBOLS: {
|
|
36
|
+
B3: "B3",
|
|
37
|
+
USD: "$",
|
|
38
|
+
EUR: "€",
|
|
39
|
+
GBP: "£",
|
|
40
|
+
JPY: "¥",
|
|
41
|
+
CAD: "C$",
|
|
42
|
+
AUD: "A$",
|
|
43
|
+
ETH: "ETH",
|
|
44
|
+
SOL: "SOL",
|
|
45
|
+
KRW: "₩",
|
|
46
|
+
},
|
|
47
|
+
}));
|
|
48
|
+
describe("useCurrencyConversion", () => {
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
vi.clearAllMocks();
|
|
51
|
+
// Reset mock rates to default
|
|
52
|
+
Object.keys(mockRates).forEach(key => delete mockRates[key]);
|
|
53
|
+
mockRates.USD = 1.0;
|
|
54
|
+
// Reset store state
|
|
55
|
+
mockStoreState.selectedCurrency = "B3";
|
|
56
|
+
mockStoreState.baseCurrency = "B3";
|
|
57
|
+
});
|
|
58
|
+
describe("formatCurrencyValue", () => {
|
|
59
|
+
it("should format base currency (B3) without conversion", () => {
|
|
60
|
+
mockStoreState.selectedCurrency = "B3";
|
|
61
|
+
mockStoreState.baseCurrency = "B3";
|
|
62
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
63
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
64
|
+
expect(formatted).toContain("B3");
|
|
65
|
+
expect(formatted).toContain("100");
|
|
66
|
+
});
|
|
67
|
+
it("should show base currency when exchange rate is unavailable", () => {
|
|
68
|
+
mockRates.USD = undefined;
|
|
69
|
+
mockStoreState.selectedCurrency = "USD";
|
|
70
|
+
mockStoreState.baseCurrency = "B3";
|
|
71
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
72
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
73
|
+
expect(formatted).toContain("B3");
|
|
74
|
+
expect(formatted).not.toContain("$");
|
|
75
|
+
});
|
|
76
|
+
it("should format USD with prefix symbol", () => {
|
|
77
|
+
mockRates.USD = 2.0;
|
|
78
|
+
mockStoreState.selectedCurrency = "USD";
|
|
79
|
+
mockStoreState.baseCurrency = "B3";
|
|
80
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
81
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
82
|
+
expect(formatted).toMatch(/^\$/);
|
|
83
|
+
expect(formatted).toContain("200");
|
|
84
|
+
});
|
|
85
|
+
it("should format EUR with prefix symbol", () => {
|
|
86
|
+
mockRates.EUR = 1.8;
|
|
87
|
+
mockRates.USD = 2.0;
|
|
88
|
+
mockStoreState.selectedCurrency = "EUR";
|
|
89
|
+
mockStoreState.baseCurrency = "B3";
|
|
90
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
91
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
92
|
+
expect(formatted).toMatch(/^€/);
|
|
93
|
+
});
|
|
94
|
+
it("should format JPY without decimals", () => {
|
|
95
|
+
mockRates.JPY = 150;
|
|
96
|
+
mockRates.USD = 2.0;
|
|
97
|
+
mockStoreState.selectedCurrency = "JPY";
|
|
98
|
+
mockStoreState.baseCurrency = "B3";
|
|
99
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
100
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
101
|
+
expect(formatted).toContain("¥");
|
|
102
|
+
expect(formatted).not.toContain(".");
|
|
103
|
+
});
|
|
104
|
+
it("should format KRW without decimals", () => {
|
|
105
|
+
mockRates.KRW = 1300;
|
|
106
|
+
mockRates.USD = 2.0;
|
|
107
|
+
mockStoreState.selectedCurrency = "KRW";
|
|
108
|
+
mockStoreState.baseCurrency = "B3";
|
|
109
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
110
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
111
|
+
expect(formatted).toContain("₩");
|
|
112
|
+
expect(formatted).not.toContain(".");
|
|
113
|
+
});
|
|
114
|
+
it("should format ETH with suffix symbol", () => {
|
|
115
|
+
mockRates.ETH = 0.0005;
|
|
116
|
+
mockRates.USD = 2.0;
|
|
117
|
+
mockStoreState.selectedCurrency = "ETH";
|
|
118
|
+
mockStoreState.baseCurrency = "B3";
|
|
119
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
120
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
121
|
+
expect(formatted).toContain("ETH");
|
|
122
|
+
expect(formatted).not.toMatch(/^ETH/);
|
|
123
|
+
});
|
|
124
|
+
it("should format SOL with suffix symbol", () => {
|
|
125
|
+
mockRates.SOL = 0.05;
|
|
126
|
+
mockRates.USD = 2.0;
|
|
127
|
+
mockStoreState.selectedCurrency = "SOL";
|
|
128
|
+
mockStoreState.baseCurrency = "B3";
|
|
129
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
130
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
131
|
+
expect(formatted).toContain("SOL");
|
|
132
|
+
expect(formatted).not.toMatch(/^SOL/);
|
|
133
|
+
});
|
|
134
|
+
it("should handle small USD amounts with proper conversion", () => {
|
|
135
|
+
mockRates.USD = 1.5;
|
|
136
|
+
mockStoreState.selectedCurrency = "USD";
|
|
137
|
+
mockStoreState.baseCurrency = "B3";
|
|
138
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
139
|
+
const formatted = result.current.formatCurrencyValue(10);
|
|
140
|
+
// 10 * 1.5 = 15
|
|
141
|
+
expect(formatted).toMatch(/^\$/);
|
|
142
|
+
expect(formatted).toContain("15");
|
|
143
|
+
});
|
|
144
|
+
it("should apply correct exchange rate conversion", () => {
|
|
145
|
+
const testRate = 3.5;
|
|
146
|
+
mockRates.USD = testRate;
|
|
147
|
+
mockStoreState.selectedCurrency = "USD";
|
|
148
|
+
mockStoreState.baseCurrency = "B3";
|
|
149
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
150
|
+
const inputValue = 100;
|
|
151
|
+
const formatted = result.current.formatCurrencyValue(inputValue);
|
|
152
|
+
expect(formatted).toContain("350");
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
describe("return values", () => {
|
|
156
|
+
it("should return selected currency", () => {
|
|
157
|
+
mockStoreState.selectedCurrency = "USD";
|
|
158
|
+
mockStoreState.baseCurrency = "B3";
|
|
159
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
160
|
+
expect(result.current.selectedCurrency).toBe("USD");
|
|
161
|
+
});
|
|
162
|
+
it("should return base currency", () => {
|
|
163
|
+
mockStoreState.selectedCurrency = "USD";
|
|
164
|
+
mockStoreState.baseCurrency = "B3";
|
|
165
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
166
|
+
expect(result.current.baseCurrency).toBe("B3");
|
|
167
|
+
});
|
|
168
|
+
it("should return exchange rate", () => {
|
|
169
|
+
const testRate = 2.5;
|
|
170
|
+
mockRates.USD = testRate;
|
|
171
|
+
mockStoreState.selectedCurrency = "USD";
|
|
172
|
+
mockStoreState.baseCurrency = "B3";
|
|
173
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
174
|
+
expect(result.current.exchangeRate).toBe(testRate);
|
|
175
|
+
});
|
|
176
|
+
it("should return correct currency symbols", () => {
|
|
177
|
+
mockStoreState.selectedCurrency = "EUR";
|
|
178
|
+
mockStoreState.baseCurrency = "B3";
|
|
179
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
180
|
+
expect(result.current.selectedCurrencySymbol).toBe("€");
|
|
181
|
+
expect(result.current.baseCurrencySymbol).toBe("B3");
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
describe("formatTooltipValue", () => {
|
|
185
|
+
it("should show USD equivalent when displaying base currency", () => {
|
|
186
|
+
mockRates.USD = 1.5;
|
|
187
|
+
mockStoreState.selectedCurrency = "B3";
|
|
188
|
+
mockStoreState.baseCurrency = "B3";
|
|
189
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
190
|
+
const tooltip = result.current.formatTooltipValue(100);
|
|
191
|
+
expect(tooltip).toContain("USD");
|
|
192
|
+
expect(tooltip).toContain("150");
|
|
193
|
+
});
|
|
194
|
+
it("should show base currency when displaying other currency", () => {
|
|
195
|
+
mockRates.EUR = 0.9;
|
|
196
|
+
mockRates.USD = 1.2;
|
|
197
|
+
mockStoreState.selectedCurrency = "EUR";
|
|
198
|
+
mockStoreState.baseCurrency = "B3";
|
|
199
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
200
|
+
const tooltip = result.current.formatTooltipValue(100);
|
|
201
|
+
expect(tooltip).toContain("B3");
|
|
202
|
+
expect(tooltip).toContain("100");
|
|
203
|
+
});
|
|
204
|
+
it("should handle custom currency for base currency", () => {
|
|
205
|
+
mockRates.USD = 2.0;
|
|
206
|
+
mockRates.EUR = 1.8;
|
|
207
|
+
mockStoreState.selectedCurrency = "EUR";
|
|
208
|
+
mockStoreState.baseCurrency = "B3";
|
|
209
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
210
|
+
const tooltip = result.current.formatTooltipValue(100, "B3");
|
|
211
|
+
expect(tooltip).toContain("USD");
|
|
212
|
+
expect(tooltip).toContain("200");
|
|
213
|
+
});
|
|
214
|
+
it("should handle custom currency for non-base currency", () => {
|
|
215
|
+
mockRates.USD = 2.0;
|
|
216
|
+
mockStoreState.selectedCurrency = "USD";
|
|
217
|
+
mockStoreState.baseCurrency = "B3";
|
|
218
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
219
|
+
const tooltip = result.current.formatTooltipValue(50, "ETH");
|
|
220
|
+
expect(tooltip).toContain("ETH");
|
|
221
|
+
expect(tooltip).toContain("50");
|
|
222
|
+
});
|
|
223
|
+
it("should handle absolute values for negative amounts", () => {
|
|
224
|
+
mockRates.USD = 1.5;
|
|
225
|
+
mockStoreState.selectedCurrency = "B3";
|
|
226
|
+
mockStoreState.baseCurrency = "B3";
|
|
227
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
228
|
+
const tooltip = result.current.formatTooltipValue(-100);
|
|
229
|
+
expect(tooltip).toContain("USD");
|
|
230
|
+
expect(tooltip).toContain("150");
|
|
231
|
+
expect(tooltip).not.toContain("-");
|
|
232
|
+
});
|
|
233
|
+
it("should handle exchange rate unavailable", () => {
|
|
234
|
+
mockRates.USD = undefined;
|
|
235
|
+
mockStoreState.selectedCurrency = "B3";
|
|
236
|
+
mockStoreState.baseCurrency = "B3";
|
|
237
|
+
const { result } = renderHook(() => useCurrencyConversion());
|
|
238
|
+
const tooltip = result.current.formatTooltipValue(100);
|
|
239
|
+
expect(tooltip).toContain("USD");
|
|
240
|
+
expect(tooltip).toContain("100");
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for currency conversion and formatting with real-time exchange rates.
|
|
3
|
+
*
|
|
4
|
+
* This hook provides currency conversion functionality using live exchange rates
|
|
5
|
+
* and formats values according to currency-specific rules (decimals, symbols, etc.).
|
|
6
|
+
*
|
|
7
|
+
* @returns Currency conversion utilities and state
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* function PriceDisplay({ amount }: { amount: number }) {
|
|
12
|
+
* const { formatCurrencyValue, selectedCurrency } = useCurrencyConversion();
|
|
13
|
+
* return <div>{formatCurrencyValue(amount)}</div>;
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function useCurrencyConversion(): {
|
|
18
|
+
/** Currently selected display currency */
|
|
19
|
+
selectedCurrency: import("../stores/currencyStore").SupportedCurrency;
|
|
20
|
+
/** Base currency used for conversion (typically B3) */
|
|
21
|
+
baseCurrency: import("../stores/currencyStore").SupportedCurrency;
|
|
22
|
+
/** Current exchange rate from base to selected currency (undefined while loading) */
|
|
23
|
+
exchangeRate: number;
|
|
24
|
+
/** Format a value with currency conversion and proper symbol/decimal handling */
|
|
25
|
+
formatCurrencyValue: (value: number, options?: {
|
|
26
|
+
decimals?: number;
|
|
27
|
+
currency?: string;
|
|
28
|
+
}) => string;
|
|
29
|
+
/** Format a tooltip value showing alternate currency representation */
|
|
30
|
+
formatTooltipValue: (value: number, customCurrency?: string) => string;
|
|
31
|
+
/** Symbol for the currently selected currency (e.g., "$", "€", "ETH") */
|
|
32
|
+
selectedCurrencySymbol: string;
|
|
33
|
+
/** Symbol for the base currency */
|
|
34
|
+
baseCurrencySymbol: string;
|
|
35
|
+
};
|