@rockerone/xprnkit 0.3.0

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.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1100 -0
  3. package/build/components/identity/index.d.ts +4 -0
  4. package/build/components/identity/index.js +4 -0
  5. package/build/components/identity/xprn-avatar.d.ts +8 -0
  6. package/build/components/identity/xprn-avatar.js +23 -0
  7. package/build/components/identity/xprn-identity.d.ts +9 -0
  8. package/build/components/identity/xprn-identity.js +30 -0
  9. package/build/components/identity/xprn-session-actor.d.ts +4 -0
  10. package/build/components/identity/xprn-session-actor.js +13 -0
  11. package/build/components/identity/xprn-session-name.d.ts +4 -0
  12. package/build/components/identity/xprn-session-name.js +14 -0
  13. package/build/components/index.d.ts +5 -0
  14. package/build/components/index.js +5 -0
  15. package/build/components/swap/index.d.ts +46 -0
  16. package/build/components/swap/index.js +9 -0
  17. package/build/components/swap/xprn-swap-button.d.ts +5 -0
  18. package/build/components/swap/xprn-swap-button.js +21 -0
  19. package/build/components/swap/xprn-swap-field.d.ts +6 -0
  20. package/build/components/swap/xprn-swap-field.js +69 -0
  21. package/build/components/swap/xprn-swap-fields-group.d.ts +6 -0
  22. package/build/components/swap/xprn-swap-fields-group.js +16 -0
  23. package/build/components/swap/xprn-swap-fields.d.ts +4 -0
  24. package/build/components/swap/xprn-swap-fields.js +10 -0
  25. package/build/components/swap/xprn-swap-layout.d.ts +7 -0
  26. package/build/components/swap/xprn-swap-layout.js +21 -0
  27. package/build/components/swap/xprn-swap-markets-selector.d.ts +4 -0
  28. package/build/components/swap/xprn-swap-markets-selector.js +31 -0
  29. package/build/components/swap/xprn-swap-markets.d.ts +8 -0
  30. package/build/components/swap/xprn-swap-markets.js +93 -0
  31. package/build/components/swap/xprn-swap-pair-selector.d.ts +7 -0
  32. package/build/components/swap/xprn-swap-pair-selector.js +37 -0
  33. package/build/components/swap/xprn-swap-provider.d.ts +35 -0
  34. package/build/components/swap/xprn-swap-provider.js +187 -0
  35. package/build/components/swap/xprn-swap-side-button.d.ts +6 -0
  36. package/build/components/swap/xprn-swap-side-button.js +22 -0
  37. package/build/components/swap/xprn-swap.d.ts +9 -0
  38. package/build/components/swap/xprn-swap.js +12 -0
  39. package/build/components/ui/dropdown.d.ts +27 -0
  40. package/build/components/ui/dropdown.js +36 -0
  41. package/build/components/ui/input.d.ts +5 -0
  42. package/build/components/ui/input.js +8 -0
  43. package/build/components/ui/select.d.ts +13 -0
  44. package/build/components/ui/select.js +27 -0
  45. package/build/components/xprn-container.d.ts +9 -0
  46. package/build/components/xprn-container.js +15 -0
  47. package/build/components/xprn-session.d.ts +11 -0
  48. package/build/components/xprn-session.js +21 -0
  49. package/build/components/xprn-transaction.d.ts +23 -0
  50. package/build/components/xprn-transaction.js +58 -0
  51. package/build/global.css +1138 -0
  52. package/build/index.d.ts +5 -0
  53. package/build/index.js +3 -0
  54. package/build/interfaces/proton_wrap.d.ts +141 -0
  55. package/build/interfaces/proton_wrap.js +81 -0
  56. package/build/interfaces/service-status.d.ts +1 -0
  57. package/build/interfaces/service-status.js +1 -0
  58. package/build/interfaces/transaction-error-message.d.ts +5 -0
  59. package/build/interfaces/transaction-error-message.js +1 -0
  60. package/build/lib/utils.d.ts +2 -0
  61. package/build/lib/utils.js +5 -0
  62. package/build/providers/XPRNProvider.d.ts +59 -0
  63. package/build/providers/XPRNProvider.js +336 -0
  64. package/build/utils/index.d.ts +2 -0
  65. package/build/utils/index.js +2 -0
  66. package/build/utils/token-precision.d.ts +1 -0
  67. package/build/utils/token-precision.js +22 -0
  68. package/build/utils/transaction-errors.d.ts +2 -0
  69. package/build/utils/transaction-errors.js +15 -0
  70. package/package.json +49 -0
@@ -0,0 +1,187 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import React, { useCallback, useContext, useEffect, useMemo, useState, } from "react";
4
+ import { getSwapMarkets } from "./xprn-swap-markets";
5
+ import { useXPRN } from "../../providers/XPRNProvider";
6
+ const XPRNSwapContext = React.createContext({
7
+ marketProviders: [],
8
+ currentMarketProvider: null,
9
+ setCurrentMarketProvider: (marketProvider) => { },
10
+ refreshMarketPairs: () => { },
11
+ currentMarketPairs: [],
12
+ refreshStatus: "idle",
13
+ setCurrentSwapPair: pair => { },
14
+ currentSwapPair: null,
15
+ currentSwapValues: null,
16
+ setCurrentSwapValues: (value) => { },
17
+ swapTransaction: [],
18
+ swapVolume: 0,
19
+ setSwapSide: (value) => { },
20
+ swapSide: "buy",
21
+ setSwapVolume: (value) => { },
22
+ swapValues: { base: 0, quote: 0, volume: 0, lastMutated: "base" },
23
+ updateSwapValues: (base, quote, lastMutated) => { },
24
+ });
25
+ export const XPRNSwapProvider = ({ children, config, }) => {
26
+ const [services, setServices] = useState();
27
+ const [currentMarketProvider, setCurrentMarketProvider] = useState();
28
+ const [currentMarketPairs, setCurrentMarketPairs] = useState();
29
+ const [refreshStatus, setRefreshStatus] = useState();
30
+ const [currentSwapPair, setCurrentSwapPair] = useState();
31
+ const [swapTransaction, setSwapTransaction] = useState();
32
+ const [swapSide, setSwapSide] = useState();
33
+ const [swapVolume, setSwapVolume] = useState();
34
+ const [swapValues, setSwapValues] = useState();
35
+ const { session } = useXPRN();
36
+ const refreshMarketPairs = useCallback(() => {
37
+ if (!currentMarketProvider)
38
+ return;
39
+ setRefreshStatus("pending");
40
+ fetch(currentMarketProvider.endpoint)
41
+ .then(async (res) => {
42
+ return await res.json();
43
+ })
44
+ .then(res => {
45
+ let parsedPairs = currentMarketProvider.parse(res);
46
+ if (config && config.filters) {
47
+ if (config.filters.baseSymbol)
48
+ parsedPairs = parsedPairs.filter(pair => {
49
+ if (!config.filters)
50
+ return false;
51
+ return pair.baseToken == config.filters.baseSymbol;
52
+ });
53
+ if (config.filters.quoteSymbol)
54
+ parsedPairs = parsedPairs.filter(pair => {
55
+ if (!config.filters)
56
+ return false;
57
+ return pair.quoteToken == config.filters.quoteSymbol;
58
+ });
59
+ }
60
+ setCurrentMarketPairs(parsedPairs);
61
+ setRefreshStatus("idle");
62
+ })
63
+ .catch(() => {
64
+ setRefreshStatus("fail");
65
+ });
66
+ }, [currentMarketProvider, setRefreshStatus, setCurrentMarketPairs, config]);
67
+ const defaultServices = useMemo(() => {
68
+ const marketFilters = config ? config.marketFilters : undefined;
69
+ return getSwapMarkets(marketFilters);
70
+ }, []);
71
+ const defaultService = useMemo(() => {
72
+ let foundService = defaultServices.findLast(service => {
73
+ return service.default;
74
+ });
75
+ if (foundService)
76
+ return foundService;
77
+ return defaultServices[0];
78
+ }, [services, defaultServices]);
79
+ const updateSwapValues = useCallback((base, quote, lastMutated) => {
80
+ if (!currentSwapPair)
81
+ return;
82
+ const validatedBase = base ?? 0;
83
+ const validatedQuote = quote ?? 0;
84
+ const validatedLastMutated = lastMutated ?? "base"; // Default to "base" or your desired default
85
+ setSwapValues((prev) => {
86
+ return {
87
+ ...prev,
88
+ base: validatedLastMutated === "quote"
89
+ ? validatedQuote * currentSwapPair.lastPrice
90
+ : validatedBase,
91
+ quote: validatedLastMutated === "base"
92
+ ? validatedBase / currentSwapPair.lastPrice
93
+ : validatedQuote,
94
+ volume: 0,
95
+ lastMutated: validatedLastMutated,
96
+ };
97
+ });
98
+ }, [setSwapValues, currentSwapPair]);
99
+ useEffect(() => {
100
+ setRefreshStatus("idle");
101
+ setSwapSide("buy");
102
+ setCurrentMarketProvider(defaultService);
103
+ }, [defaultService]);
104
+ useEffect(() => {
105
+ if (currentMarketProvider)
106
+ refreshMarketPairs();
107
+ }, [currentMarketProvider]);
108
+ useEffect(() => {
109
+ if (!swapVolume) {
110
+ return;
111
+ }
112
+ if (!currentSwapPair) {
113
+ return;
114
+ }
115
+ if (!currentMarketProvider) {
116
+ return;
117
+ }
118
+ if (!swapSide) {
119
+ return;
120
+ }
121
+ setSwapTransaction(currentMarketProvider.getTransaction(currentSwapPair, swapVolume, 0, swapSide, session ? session : undefined));
122
+ }, [currentSwapPair, swapVolume, swapSide, currentMarketProvider, session]);
123
+ React.useEffect(() => {
124
+ if (!currentMarketPairs || currentMarketPairs.length == 0)
125
+ return;
126
+ setCurrentSwapPair(currentMarketPairs[0]);
127
+ }, [currentMarketPairs]);
128
+ React.useEffect(() => {
129
+ if (config && config.sides && config.sides.length == 0) {
130
+ throw new Error("XPRNProvider config sides could not be empty");
131
+ }
132
+ if (!config || !config.sides) {
133
+ setSwapSide("buy");
134
+ }
135
+ if (config && config.sides) {
136
+ setSwapSide(config.sides[0]);
137
+ }
138
+ updateSwapValues(0, 0, "base");
139
+ }, [config, updateSwapValues]);
140
+ React.useEffect(() => {
141
+ if (!swapSide)
142
+ setSwapVolume(0);
143
+ if (!currentSwapPair)
144
+ setSwapVolume(0);
145
+ }, [swapValues, swapSide, currentSwapPair, setSwapVolume]);
146
+ const providerValue = useMemo(() => {
147
+ return {
148
+ marketProviders: defaultServices,
149
+ currentMarketProvider,
150
+ setCurrentMarketProvider,
151
+ refreshMarketPairs,
152
+ currentMarketPairs: currentMarketPairs || [],
153
+ refreshStatus,
154
+ setCurrentSwapPair,
155
+ currentSwapPair,
156
+ swapTransaction,
157
+ swapSide,
158
+ setSwapSide,
159
+ swapVolume,
160
+ setSwapVolume,
161
+ config,
162
+ swapValues,
163
+ updateSwapValues,
164
+ };
165
+ }, [
166
+ defaultServices,
167
+ currentMarketProvider,
168
+ setCurrentMarketProvider,
169
+ refreshMarketPairs,
170
+ currentMarketPairs,
171
+ refreshStatus,
172
+ setCurrentSwapPair,
173
+ currentSwapPair,
174
+ swapTransaction,
175
+ swapSide,
176
+ setSwapSide,
177
+ swapVolume,
178
+ setSwapVolume,
179
+ config,
180
+ swapValues,
181
+ updateSwapValues,
182
+ ]);
183
+ return (_jsx(XPRNSwapContext.Provider, { value: providerValue, children: children }));
184
+ };
185
+ export function useXPRNSwap() {
186
+ return useContext(XPRNSwapContext);
187
+ }
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ type XPRNSwapSideButtonProps = React.HTMLAttributes<HTMLDivElement> & {
3
+ horizontal?: boolean;
4
+ };
5
+ export declare const XPRNSwapSideButton: React.FunctionComponent<XPRNSwapSideButtonProps>;
6
+ export {};
@@ -0,0 +1,22 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import classNames from "classnames";
4
+ import { useXPRNSwap } from "./xprn-swap-provider";
5
+ import React from "react";
6
+ export const XPRNSwapSideButton = ({ children, className, horizontal }) => {
7
+ const { config, swapSide, setSwapSide } = useXPRNSwap();
8
+ const rootClasses = classNames({
9
+ "transition-transform ": true,
10
+ "hover:rotate-180": true,
11
+ [`${className}`]: className,
12
+ });
13
+ const onSideSwitch = React.useCallback(() => {
14
+ swapSide == "sell" ? setSwapSide("buy") : setSwapSide("sell");
15
+ }, [swapSide, setSwapSide]);
16
+ const defaultIcon = React.useMemo(() => {
17
+ if (horizontal)
18
+ return (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", strokeLinecap: "round", strokeLinejoin: "round", className: "lucide lucide-arrow-left-right", children: [_jsx("path", { d: "M8 3 4 7l4 4" }), _jsx("path", { d: "M4 7h16" }), _jsx("path", { d: "m16 21 4-4-4-4" }), _jsx("path", { d: "M20 17H4" })] }));
19
+ return (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", className: "lucide lucide-arrow-down-up ", children: [_jsx("path", { d: "m3 16 4 4 4-4" }), _jsx("path", { d: "M7 20V4" }), _jsx("path", { d: "m21 8-4-4-4 4" }), _jsx("path", { d: "M17 4v16" })] }));
20
+ }, [horizontal]);
21
+ return (_jsx("button", { className: rootClasses, onClick: () => onSideSwitch(), children: _jsx(_Fragment, { children: config && config.sides && config.sides.length == 1 ? null : (_jsx(_Fragment, { children: children ? (children) : (_jsx(_Fragment, { children: defaultIcon })) })) }) }));
22
+ };
@@ -0,0 +1,9 @@
1
+ import * as React from "react";
2
+ import { type XPRNMarketProviderQuoteFilter, type XPRNSwapSide } from ".";
3
+ type XPRNSwapProps = React.HTMLAttributes<HTMLDivElement> & {
4
+ filters?: XPRNMarketProviderQuoteFilter;
5
+ sides?: XPRNSwapSide[];
6
+ markets?: string[];
7
+ };
8
+ export declare const XPRNSwap: React.FunctionComponent<XPRNSwapProps>;
9
+ export {};
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import classNames from "classnames";
4
+ import { XPRNSwapProvider } from "./xprn-swap-provider";
5
+ import { XPRNSwapLayout } from ".";
6
+ export const XPRNSwap = ({ children, className, filters, sides, markets }) => {
7
+ const rootClasses = classNames({
8
+ "grid grid-col-1 gap-4 rounded-md border border-white p-4": true,
9
+ [`${className}`]: className,
10
+ });
11
+ return (_jsx(XPRNSwapProvider, { config: { filters, sides, marketFilters: markets }, children: _jsx(XPRNSwapLayout, {}) }));
12
+ };
@@ -0,0 +1,27 @@
1
+ import * as React from "react";
2
+ import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
3
+ declare const DropdownMenu: React.FC<DropdownMenuPrimitive.DropdownMenuProps>;
4
+ declare const DropdownMenuTrigger: React.ForwardRefExoticComponent<DropdownMenuPrimitive.DropdownMenuTriggerProps & React.RefAttributes<HTMLButtonElement>>;
5
+ declare const DropdownMenuGroup: React.ForwardRefExoticComponent<DropdownMenuPrimitive.DropdownMenuGroupProps & React.RefAttributes<HTMLDivElement>>;
6
+ declare const DropdownMenuPortal: React.FC<DropdownMenuPrimitive.DropdownMenuPortalProps>;
7
+ declare const DropdownMenuSub: React.FC<DropdownMenuPrimitive.DropdownMenuSubProps>;
8
+ declare const DropdownMenuRadioGroup: React.ForwardRefExoticComponent<DropdownMenuPrimitive.DropdownMenuRadioGroupProps & React.RefAttributes<HTMLDivElement>>;
9
+ declare const DropdownMenuSubTrigger: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuSubTriggerProps & React.RefAttributes<HTMLDivElement>, "ref"> & {
10
+ inset?: boolean;
11
+ } & React.RefAttributes<HTMLDivElement>>;
12
+ declare const DropdownMenuSubContent: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuSubContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
13
+ declare const DropdownMenuContent: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
14
+ declare const DropdownMenuItem: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuItemProps & React.RefAttributes<HTMLDivElement>, "ref"> & {
15
+ inset?: boolean;
16
+ } & React.RefAttributes<HTMLDivElement>>;
17
+ declare const DropdownMenuCheckboxItem: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuCheckboxItemProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
18
+ declare const DropdownMenuRadioItem: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuRadioItemProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
19
+ declare const DropdownMenuLabel: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuLabelProps & React.RefAttributes<HTMLDivElement>, "ref"> & {
20
+ inset?: boolean;
21
+ } & React.RefAttributes<HTMLDivElement>>;
22
+ declare const DropdownMenuSeparator: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuSeparatorProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
23
+ declare const DropdownMenuShortcut: {
24
+ ({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>): import("react/jsx-runtime").JSX.Element;
25
+ displayName: string;
26
+ };
27
+ export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuRadioItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuGroup, DropdownMenuPortal, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuRadioGroup, };
@@ -0,0 +1,36 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
5
+ import { CheckIcon, ChevronRightIcon, DotFilledIcon, } from "@radix-ui/react-icons";
6
+ import { cn } from "../../lib/utils";
7
+ const DropdownMenu = DropdownMenuPrimitive.Root;
8
+ const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
9
+ const DropdownMenuGroup = DropdownMenuPrimitive.Group;
10
+ const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
11
+ const DropdownMenuSub = DropdownMenuPrimitive.Sub;
12
+ const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
13
+ const DropdownMenuSubTrigger = React.forwardRef(({ className, inset, children, ...props }, ref) => (_jsxs(DropdownMenuPrimitive.SubTrigger, { ref: ref, className: cn("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent", inset && "pl-8", className), ...props, children: [children, _jsx(ChevronRightIcon, { className: "ml-auto h-4 w-4" })] })));
14
+ DropdownMenuSubTrigger.displayName =
15
+ DropdownMenuPrimitive.SubTrigger.displayName;
16
+ const DropdownMenuSubContent = React.forwardRef(({ className, ...props }, ref) => (_jsx(DropdownMenuPrimitive.SubContent, { ref: ref, className: cn("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className), ...props })));
17
+ DropdownMenuSubContent.displayName =
18
+ DropdownMenuPrimitive.SubContent.displayName;
19
+ const DropdownMenuContent = React.forwardRef(({ className, sideOffset = 4, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Portal, { children: _jsx(DropdownMenuPrimitive.Content, { ref: ref, sideOffset: sideOffset, className: cn("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md", "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className), ...props }) })));
20
+ DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
21
+ const DropdownMenuItem = React.forwardRef(({ className, inset, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Item, { ref: ref, className: cn("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", inset && "pl-8", className), ...props })));
22
+ DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
23
+ const DropdownMenuCheckboxItem = React.forwardRef(({ className, children, checked, ...props }, ref) => (_jsxs(DropdownMenuPrimitive.CheckboxItem, { ref: ref, className: cn("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className), checked: checked, ...props, children: [_jsx("span", { className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center", children: _jsx(DropdownMenuPrimitive.ItemIndicator, { children: _jsx(CheckIcon, { className: "h-4 w-4" }) }) }), children] })));
24
+ DropdownMenuCheckboxItem.displayName =
25
+ DropdownMenuPrimitive.CheckboxItem.displayName;
26
+ const DropdownMenuRadioItem = React.forwardRef(({ className, children, ...props }, ref) => (_jsxs(DropdownMenuPrimitive.RadioItem, { ref: ref, className: cn("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className), ...props, children: [_jsx("span", { className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center", children: _jsx(DropdownMenuPrimitive.ItemIndicator, { children: _jsx(DotFilledIcon, { className: "h-4 w-4 fill-current" }) }) }), children] })));
27
+ DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;
28
+ const DropdownMenuLabel = React.forwardRef(({ className, inset, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Label, { ref: ref, className: cn("px-2 py-1.5 text-sm font-semibold", inset && "pl-8", className), ...props })));
29
+ DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;
30
+ const DropdownMenuSeparator = React.forwardRef(({ className, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Separator, { ref: ref, className: cn("-mx-1 my-1 h-px bg-muted", className), ...props })));
31
+ DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;
32
+ const DropdownMenuShortcut = ({ className, ...props }) => {
33
+ return (_jsx("span", { className: cn("ml-auto text-xs tracking-widest opacity-60", className), ...props }));
34
+ };
35
+ DropdownMenuShortcut.displayName = "DropdownMenuShortcut";
36
+ export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuRadioItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuGroup, DropdownMenuPortal, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuRadioGroup, };
@@ -0,0 +1,5 @@
1
+ import * as React from "react";
2
+ export interface BaseInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
3
+ }
4
+ declare const Input: React.ForwardRefExoticComponent<BaseInputProps & React.RefAttributes<HTMLInputElement>>;
5
+ export { Input };
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { cn } from "./../../lib/utils";
4
+ const Input = React.forwardRef(({ className, type, ...props }, ref) => {
5
+ return (_jsx("div", { children: _jsx("input", { type: type, className: cn("border border-input bg-transparent h-9 w-full rounded-md px-3 py-1 text-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50", className), ref: ref, ...props }) }));
6
+ });
7
+ Input.displayName = "Input";
8
+ export { Input };
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+ import * as SelectPrimitive from "@radix-ui/react-select";
3
+ declare const Select: React.FC<SelectPrimitive.SelectProps>;
4
+ declare const SelectGroup: React.ForwardRefExoticComponent<SelectPrimitive.SelectGroupProps & React.RefAttributes<HTMLDivElement>>;
5
+ declare const SelectValue: React.ForwardRefExoticComponent<SelectPrimitive.SelectValueProps & React.RefAttributes<HTMLSpanElement>>;
6
+ declare const SelectTrigger: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectTriggerProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
7
+ declare const SelectScrollUpButton: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectScrollUpButtonProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
8
+ declare const SelectScrollDownButton: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectScrollDownButtonProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
9
+ declare const SelectContent: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
10
+ declare const SelectLabel: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectLabelProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
11
+ declare const SelectItem: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectItemProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
12
+ declare const SelectSeparator: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectSeparatorProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
13
+ export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectLabel, SelectItem, SelectSeparator, SelectScrollUpButton, SelectScrollDownButton, };
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { CaretSortIcon, CheckIcon, ChevronDownIcon, ChevronUpIcon, } from "@radix-ui/react-icons";
5
+ import * as SelectPrimitive from "@radix-ui/react-select";
6
+ import { cn } from "./../../lib/utils";
7
+ const Select = SelectPrimitive.Root;
8
+ const SelectGroup = SelectPrimitive.Group;
9
+ const SelectValue = SelectPrimitive.Value;
10
+ const SelectTrigger = React.forwardRef(({ className, children, ...props }, ref) => (_jsxs(SelectPrimitive.Trigger, { ref: ref, className: cn("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1", className), ...props, children: [children, _jsx(SelectPrimitive.Icon, { asChild: true, children: _jsx(CaretSortIcon, { className: "h-4 w-4 opacity-50" }) })] })));
11
+ SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
12
+ const SelectScrollUpButton = React.forwardRef(({ className, ...props }, ref) => (_jsx(SelectPrimitive.ScrollUpButton, { ref: ref, className: cn("flex cursor-default items-center justify-center py-1", className), ...props, children: _jsx(ChevronUpIcon, {}) })));
13
+ SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
14
+ const SelectScrollDownButton = React.forwardRef(({ className, ...props }, ref) => (_jsx(SelectPrimitive.ScrollDownButton, { ref: ref, className: cn("flex cursor-default items-center justify-center py-1", className), ...props, children: _jsx(ChevronDownIcon, {}) })));
15
+ SelectScrollDownButton.displayName =
16
+ SelectPrimitive.ScrollDownButton.displayName;
17
+ const SelectContent = React.forwardRef(({ className, children, position = "popper", ...props }, ref) => (_jsx(SelectPrimitive.Portal, { children: _jsxs(SelectPrimitive.Content, { ref: ref, className: cn("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", position === "popper" &&
18
+ "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", className), position: position, ...props, children: [_jsx(SelectScrollUpButton, {}), _jsx(SelectPrimitive.Viewport, { className: cn("p-1", position === "popper" &&
19
+ "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"), children: children }), _jsx(SelectScrollDownButton, {})] }) })));
20
+ SelectContent.displayName = SelectPrimitive.Content.displayName;
21
+ const SelectLabel = React.forwardRef(({ className, ...props }, ref) => (_jsx(SelectPrimitive.Label, { ref: ref, className: cn("px-2 py-1.5 text-sm font-semibold", className), ...props })));
22
+ SelectLabel.displayName = SelectPrimitive.Label.displayName;
23
+ const SelectItem = React.forwardRef(({ className, children, ...props }, ref) => (_jsxs(SelectPrimitive.Item, { ref: ref, className: cn("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className), ...props, children: [_jsx("span", { className: "absolute right-2 flex h-3.5 w-3.5 items-center justify-center", children: _jsx(SelectPrimitive.ItemIndicator, { children: _jsx(CheckIcon, { className: "h-4 w-4" }) }) }), _jsx(SelectPrimitive.ItemText, { children: children })] })));
24
+ SelectItem.displayName = SelectPrimitive.Item.displayName;
25
+ const SelectSeparator = React.forwardRef(({ className, ...props }, ref) => (_jsx(SelectPrimitive.Separator, { ref: ref, className: cn("-mx-1 my-1 h-px bg-muted", className), ...props })));
26
+ SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
27
+ export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectLabel, SelectItem, SelectSeparator, SelectScrollUpButton, SelectScrollDownButton, };
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import type { ReactNode } from "react";
3
+ type XRPNContainerProps = React.HTMLAttributes<HTMLDivElement> & {
4
+ noSessionState?: ReactNode | ReactNode[];
5
+ };
6
+ export declare const XRPNContainer: React.FunctionComponent<XRPNContainerProps>;
7
+ export declare const XPRNUnlogged: React.FunctionComponent<XRPNContainerProps>;
8
+ export declare const XPRNLogged: React.FunctionComponent<XRPNContainerProps>;
9
+ export {};
@@ -0,0 +1,15 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
+ import { useXPRN } from "../providers/XPRNProvider";
4
+ export const XRPNContainer = ({ children, className, noSessionState, }) => {
5
+ const { session } = useXPRN();
6
+ return _jsx(_Fragment, { children: session ? _jsx(_Fragment, { children: children }) : _jsx(_Fragment, { children: noSessionState }) });
7
+ };
8
+ export const XPRNUnlogged = ({ children, className, noSessionState, }) => {
9
+ const { session } = useXPRN();
10
+ return _jsx(_Fragment, { children: !session ? children : null });
11
+ };
12
+ export const XPRNLogged = ({ children, className, noSessionState, }) => {
13
+ const { session } = useXPRN();
14
+ return _jsx(_Fragment, { children: session ? children : null });
15
+ };
@@ -0,0 +1,11 @@
1
+ import * as React from "react";
2
+ import { type VariantProps } from "class-variance-authority";
3
+ declare const XPRNConnectButtonVariants: (props?: ({
4
+ variant?: null | undefined;
5
+ size?: null | undefined;
6
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
7
+ export interface XPRNConnectButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof XPRNConnectButtonVariants> {
8
+ asChild?: boolean;
9
+ }
10
+ declare const XPRNConnectButton: React.ForwardRefExoticComponent<XPRNConnectButtonProps & React.RefAttributes<HTMLButtonElement>>;
11
+ export { XPRNConnectButton, XPRNConnectButtonVariants };
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useXPRN } from "../providers/XPRNProvider";
4
+ import * as React from "react";
5
+ import { Slot } from "@radix-ui/react-slot";
6
+ import { cva } from "class-variance-authority";
7
+ import { cn } from "../lib/utils";
8
+ const XPRNConnectButtonVariants = cva("inline-flex items-center justify-center whitespace-nowrap ", {
9
+ variants: {
10
+ variant: {},
11
+ size: {},
12
+ },
13
+ defaultVariants: {},
14
+ });
15
+ const XPRNConnectButton = React.forwardRef(({ className, variant, size, asChild = false, onClick, children, ...props }, ref) => {
16
+ const Comp = asChild ? Slot : "button";
17
+ const { session, connect, disconnect } = useXPRN();
18
+ return (_jsxs(_Fragment, { children: [!session && (_jsx(Comp, { onClick: () => connect(), className: cn(XPRNConnectButtonVariants({ variant, size, className })), ref: ref, children: children, ...props })), session && (_jsx(Comp, { onClick: () => disconnect(), className: cn(XPRNConnectButtonVariants({ variant, size, className })), ref: ref, children: `Log out (${session.auth.actor.toString()})`, ...props }))] }));
19
+ });
20
+ XPRNConnectButton.displayName = "XPRNConnectButton";
21
+ export { XPRNConnectButton, XPRNConnectButtonVariants };
@@ -0,0 +1,23 @@
1
+ import * as React from "react";
2
+ import { type VariantProps } from "class-variance-authority";
3
+ import type { TransactResult } from "@proton/web-sdk";
4
+ declare const XPRNTransactionVariants: (props?: ({
5
+ variant?: null | undefined;
6
+ size?: null | undefined;
7
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
8
+ export interface XPRNTransactionButtonBaseProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof XPRNTransactionVariants> {
9
+ asChild?: boolean;
10
+ }
11
+ export type XPRNTransactionButtonProps = XPRNTransactionButtonBaseProps & {
12
+ onTransactionStart?: () => void;
13
+ onTransactionSuccess?: (res: TransactResult) => void;
14
+ onTransactionFail?: (e: any) => void;
15
+ actions: any[];
16
+ };
17
+ declare const XPRNTransaction: React.ForwardRefExoticComponent<XPRNTransactionButtonBaseProps & {
18
+ onTransactionStart?: () => void;
19
+ onTransactionSuccess?: (res: TransactResult) => void;
20
+ onTransactionFail?: (e: any) => void;
21
+ actions: any[];
22
+ } & React.RefAttributes<HTMLButtonElement>>;
23
+ export { XPRNTransaction, XPRNTransactionVariants };
@@ -0,0 +1,58 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useXPRN } from "../providers/XPRNProvider";
4
+ import * as React from "react";
5
+ import { Slot } from "@radix-ui/react-slot";
6
+ import { cva } from "class-variance-authority";
7
+ import { cn } from "../lib/utils";
8
+ const XPRNTransactionVariants = cva("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50", {
9
+ variants: {
10
+ variant: {},
11
+ size: {},
12
+ },
13
+ defaultVariants: {},
14
+ });
15
+ const XPRNTransaction = React.forwardRef(({ className, variant, size, asChild = false, onClick, children, actions, onTransactionStart, onTransactionSuccess, onTransactionFail, ...props }, ref) => {
16
+ const Comp = asChild ? Slot : "button";
17
+ const { session, connect, addTransactionError, txErrorsStack } = useXPRN();
18
+ const [txStatus, setTxStatus] = React.useState('idle');
19
+ const TxStatusNode = React.useMemo(() => {
20
+ if (txStatus == 'idle')
21
+ return _jsx(_Fragment, { children: children });
22
+ if (txStatus == 'pending')
23
+ return _jsx(_Fragment, { children: _jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", className: "animate-spin", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [_jsx("path", { d: "M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8" }), _jsx("path", { d: "M21 3v5h-5" }), _jsx("path", { d: "M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16" }), _jsx("path", { d: "M8 16H3v5" })] }) });
24
+ if (txStatus == 'success')
25
+ return _jsxs("div", { className: "flex gap-2 justify-center items-center", children: [_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", className: "lucide lucide-circle-check-big", children: [_jsx("path", { d: "M21.801 10A10 10 0 1 1 17 3.335" }), _jsx("path", { d: "m9 11 3 3L22 4" })] }), "Success"] });
26
+ if (txStatus == 'fail')
27
+ return _jsxs("div", { className: "flex gap-2 justify-center items-center", children: [_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [_jsx("circle", { cx: "12", cy: "12", r: "10" }), _jsx("path", { d: "m15 9-6 6" }), _jsx("path", { d: "m9 9 6 6" })] }), "Fail, lease Rety"] });
28
+ }, [session, txStatus]);
29
+ const pushTransaction = React.useCallback(() => {
30
+ if (session) {
31
+ if (onTransactionStart)
32
+ onTransactionStart();
33
+ setTxStatus('pending');
34
+ try {
35
+ session.transact({ actions }, { broadcast: true }).then(res => {
36
+ if (onTransactionSuccess)
37
+ onTransactionSuccess(res);
38
+ setTxStatus('success');
39
+ }).catch((e) => {
40
+ setTxStatus('fail');
41
+ addTransactionError(e);
42
+ });
43
+ }
44
+ catch (e) {
45
+ setTxStatus('fail');
46
+ addTransactionError(e.toString());
47
+ if (onTransactionFail)
48
+ onTransactionFail(e);
49
+ setTimeout(() => {
50
+ setTxStatus('idle');
51
+ }, 3000);
52
+ }
53
+ }
54
+ }, [session, actions, setTxStatus]);
55
+ return (_jsxs(_Fragment, { children: [!session && (_jsx(Comp, { onClick: () => connect(false, false, () => pushTransaction()), className: cn(XPRNTransactionVariants({ variant, size, className })), ref: ref, children: "Connecte Me!", ...props })), session && (_jsx(Comp, { onClick: () => pushTransaction(), className: cn(XPRNTransactionVariants({ variant, size, className })), ref: ref, children: TxStatusNode, ...props }))] }));
56
+ });
57
+ XPRNTransaction.displayName = "XPRNTransaction";
58
+ export { XPRNTransaction, XPRNTransactionVariants };