@onepercentio/one-ui 0.28.7 → 0.28.9
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/package.json +8 -5
- package/src/assets/img/svg/checkbox.svg +3 -0
- package/src/assets/styles/index.scss +2 -0
- package/src/assets/styles/mixins.scss +12 -0
- package/src/assets/styles/variables.scss +49 -0
- package/src/components/AdaptiveButton/AdaptiveButton.module.scss +7 -0
- package/src/components/AdaptiveButton/AdaptiveButton.tsx +26 -0
- package/src/components/AdaptiveButton/index.tsx +1 -0
- package/src/components/AdaptiveContainer/AdaptiveContainer.module.scss +53 -0
- package/src/components/AdaptiveContainer/AdaptiveContainer.tsx +200 -0
- package/src/components/AdaptiveContainer/index.tsx +1 -0
- package/src/components/AdaptiveDialog/AdaptiveDialog.module.scss +147 -0
- package/src/components/AdaptiveDialog/AdaptiveDialog.tsx +97 -0
- package/src/components/AdaptiveDialog/index.tsx +1 -0
- package/src/components/AdaptiveSidebar/AdaptiveSidebar.module.scss +49 -0
- package/src/components/AdaptiveSidebar/AdaptiveSidebar.sample.tsx +10 -0
- package/src/components/AdaptiveSidebar/AdaptiveSidebar.tsx +123 -0
- package/src/components/AdaptiveSidebar/index.tsx +1 -0
- package/src/components/AnchoredTooltip/AnchoredTooltip.module.scss +64 -0
- package/src/components/AnchoredTooltip/AnchoredTooltip.tsx +250 -0
- package/src/components/AnchoredTooltip/index.tsx +1 -0
- package/src/components/AnimatedEntrance/AnimatedEntrance.module.scss +108 -0
- package/src/components/AnimatedEntrance/AnimatedEntrance.tsx +227 -0
- package/src/components/AnimatedEntrance/index.tsx +5 -0
- package/src/components/AsyncWrapper/AsyncWrapper.tsx +38 -0
- package/src/components/AsyncWrapper/index.tsx +1 -0
- package/src/components/Avatar/Avatar.module.scss +22 -0
- package/src/components/Avatar/Avatar.tsx +31 -0
- package/src/components/Avatar/index.tsx +1 -0
- package/src/components/BucketFill/BucketFill.module.scss +36 -0
- package/src/components/BucketFill/BucketFill.tsx +65 -0
- package/src/components/BucketFill/index.tsx +1 -0
- package/src/components/Button/Button.module.scss +45 -0
- package/src/components/Button/Button.tsx +40 -0
- package/src/components/Button/index.tsx +1 -0
- package/src/components/Card/Card.module.scss +12 -0
- package/src/components/Card/Card.tsx +9 -0
- package/src/components/Card/index.tsx +1 -0
- package/src/components/Chart/Chart.e2e.ts +4 -0
- package/src/components/Chart/Chart.logic.tsx +8 -0
- package/src/components/Chart/Chart.module.scss +58 -0
- package/src/components/Chart/Chart.types.ts +35 -0
- package/src/components/Chart/Chart.view.tsx +240 -0
- package/src/components/Chart/index.tsx +1 -0
- package/src/components/CheckBox/CheckBox.module.scss +36 -0
- package/src/components/CheckBox/CheckBox.tsx +63 -0
- package/src/components/CheckBox/index.tsx +1 -0
- package/src/components/CodeInput/CodeInput.module.scss +5 -0
- package/src/components/CodeInput/CodeInput.tsx +84 -0
- package/src/components/CodeInput/index.tsx +1 -0
- package/src/components/Collapsable/Collapsable.module.scss +42 -0
- package/src/components/Collapsable/Collapsable.tsx +253 -0
- package/src/components/Collapsable/index.tsx +1 -0
- package/src/components/Countdown/Countdown.tsx +130 -0
- package/src/components/Countdown/index.tsx +1 -0
- package/src/components/CurrencyInput/CurrencyInput.hook.ts +37 -0
- package/src/components/CurrencyInput/CurrencyInput.tsx +25 -0
- package/src/components/CurrencyInput/index.tsx +1 -0
- package/src/components/Divider/Divider.module.scss +7 -0
- package/src/components/Divider/Divider.tsx +13 -0
- package/src/components/Divider/index.tsx +1 -0
- package/src/components/EmailInput/EmailInput.module.scss +0 -0
- package/src/components/EmailInput/EmailInput.tsx +51 -0
- package/src/components/EmailInput/index.tsx +1 -0
- package/src/components/FadeIn/FadeIn.module.scss +9 -0
- package/src/components/FadeIn/FadeIn.tsx +77 -0
- package/src/components/FadeIn/index.tsx +1 -0
- package/src/components/FileInput/FileInput.module.scss +6 -0
- package/src/components/FileInput/FileInput.tsx +75 -0
- package/src/components/FileInput/View/BigFactory/BigFactory.module.scss +20 -0
- package/src/components/FileInput/View/BigFactory/BigFactory.tsx +48 -0
- package/src/components/FileInput/View/BigFactory/index.tsx +1 -0
- package/src/components/FileInput/View/Compact/Compact.module.scss +68 -0
- package/src/components/FileInput/View/Compact/Compact.tsx +151 -0
- package/src/components/FileInput/View/Compact/index.tsx +1 -0
- package/src/components/FileInput/View/View.types.ts +12 -0
- package/src/components/FileInput/index.tsx +1 -0
- package/src/components/FlowController/FlowController.module.scss +47 -0
- package/src/components/FlowController/FlowController.tsx +93 -0
- package/src/components/FlowController/index.tsx +1 -0
- package/src/components/Form/Form.tsx +243 -0
- package/src/components/Form/index.ts +1 -0
- package/src/components/Form/v2/Form.hook.ts +341 -0
- package/src/components/Form/v2/Form.module.scss +0 -0
- package/src/components/Form/v2/Form.tsx +78 -0
- package/src/components/Form/v2/Form.types.ts +118 -0
- package/src/components/Form/v2/FormField/Extensions/DateField/DateField.module.scss +0 -0
- package/src/components/Form/v2/FormField/Extensions/DateField/DateField.tsx +73 -0
- package/src/components/Form/v2/FormField/Extensions/DateField/index.tsx +1 -0
- package/src/components/Form/v2/FormField/Extensions/PhoneField/PhoneField.module.scss +0 -0
- package/src/components/Form/v2/FormField/Extensions/PhoneField/PhoneField.tsx +91 -0
- package/src/components/Form/v2/FormField/Extensions/PhoneField/index.tsx +1 -0
- package/src/components/Form/v2/FormField/FormField.module.scss +0 -0
- package/src/components/Form/v2/FormField/FormField.tsx +378 -0
- package/src/components/Form/v2/FormField/FormField.types.ts +129 -0
- package/src/components/Form/v2/FormField/index.tsx +1 -0
- package/src/components/Form/v2/index.tsx +1 -0
- package/src/components/Freeze/Freeze.tsx +9 -0
- package/src/components/Freeze/index.tsx +1 -0
- package/src/components/HSForms/HSForms.tsx +57 -0
- package/src/components/HSForms/index.tsx +1 -0
- package/src/components/Header/Header.module.scss +119 -0
- package/src/components/Header/Header.tsx +138 -0
- package/src/components/Header/index.tsx +1 -0
- package/src/components/HeaderCloseBtn/HeaderCloseBtn.module.scss +44 -0
- package/src/components/HeaderCloseBtn/HeaderCloseBtn.tsx +28 -0
- package/src/components/HeaderCloseBtn/index.tsx +1 -0
- package/src/components/InfinityScroll/InfinityScroll.module.scss +30 -0
- package/src/components/InfinityScroll/InfinityScroll.tsx +187 -0
- package/src/components/InfinityScroll/index.tsx +1 -0
- package/src/components/Input/Input.module.scss +71 -0
- package/src/components/Input/Input.tsx +134 -0
- package/src/components/Input/index.tsx +1 -0
- package/src/components/InstantCounter/InstantCounter.tsx +77 -0
- package/src/components/InstantCounter/index.tsx +1 -0
- package/src/components/LavaLamp/LavaLamp.data.tsx +114 -0
- package/src/components/LavaLamp/LavaLamp.module.scss +26 -0
- package/src/components/LavaLamp/LavaLamp.tsx +131 -0
- package/src/components/LavaLamp/index.tsx +1 -0
- package/src/components/LavaLamp/v2/LavaLamp.module.scss +23 -0
- package/src/components/LavaLamp/v2/LavaLamp.tsx +197 -0
- package/src/components/LinkToId/LinkToId.module.scss +4 -0
- package/src/components/LinkToId/LinkToId.tsx +51 -0
- package/src/components/LinkToId/index.tsx +1 -0
- package/src/components/Loader/Loader.module.scss +40 -0
- package/src/components/Loader/Loader.tsx +18 -0
- package/src/components/Loader/index.tsx +1 -0
- package/src/components/LoaderDotsIndicator/LoaderDotsIndicator.tsx +34 -0
- package/src/components/LoaderDotsIndicator/index.tsx +1 -0
- package/src/components/LoopableVideo/LoopableVideo.tsx +37 -0
- package/src/components/LoopableVideo/index.tsx +1 -0
- package/src/components/MainGrid/MainGrid.module.scss +28 -0
- package/src/components/MainGrid/MainGrid.tsx +68 -0
- package/src/components/MainGrid/index.tsx +1 -0
- package/src/components/MutableHamburgerButton/MutableHamburgerButton.module.scss +220 -0
- package/src/components/MutableHamburgerButton/MutableHamburgerButton.tsx +38 -0
- package/src/components/MutableHamburgerButton/index.tsx +1 -0
- package/src/components/Notification/Notification.module.scss +25 -0
- package/src/components/Notification/Notification.tsx +13 -0
- package/src/components/Notification/index.tsx +1 -0
- package/src/components/OrderableList/OrderableList.module.scss +98 -0
- package/src/components/OrderableList/OrderableList.tsx +564 -0
- package/src/components/OrderableList/index.tsx +1 -0
- package/src/components/PaginationIndicator/PaginationIndicator.tsx +365 -0
- package/src/components/PaginationIndicator/index.tsx +1 -0
- package/src/components/Parallax/Parallax.module.scss +28 -0
- package/src/components/Parallax/Parallax.tsx +248 -0
- package/src/components/Parallax/index.tsx +1 -0
- package/src/components/Parallax/math/helpers.ts +289 -0
- package/src/components/PasswordInput/PasswordInput.module.scss +17 -0
- package/src/components/PasswordInput/PasswordInput.tsx +154 -0
- package/src/components/PasswordInput/index.tsx +1 -0
- package/src/components/PingPongText/PingPongText.module.scss +4 -0
- package/src/components/PingPongText/PingPongText.tsx +83 -0
- package/src/components/PingPongText/index.tsx +1 -0
- package/src/components/PixelatedScan/PixelatedScan.module.scss +86 -0
- package/src/components/PixelatedScan/PixelatedScan.tsx +175 -0
- package/src/components/PixelatedScan/index.tsx +1 -0
- package/src/components/Portal/Portal.module.scss +3 -0
- package/src/components/Portal/Portal.tsx +68 -0
- package/src/components/Portal/index.tsx +1 -0
- package/src/components/ProgressBar/ProgressBar.module.scss +44 -0
- package/src/components/ProgressBar/ProgressBar.tsx +124 -0
- package/src/components/ProgressBar/index.tsx +1 -0
- package/src/components/ProgressTexts/ProgressTexts.module.scss +37 -0
- package/src/components/ProgressTexts/ProgressTexts.tsx +85 -0
- package/src/components/ProgressTexts/index.tsx +1 -0
- package/src/components/Radio/Radio.module.scss +36 -0
- package/src/components/Radio/Radio.tsx +53 -0
- package/src/components/Radio/index.tsx +1 -0
- package/src/components/SectionContainer/SectionContainer.module.scss +30 -0
- package/src/components/SectionContainer/SectionContainer.tsx +49 -0
- package/src/components/SectionContainer/index.tsx +1 -0
- package/src/components/Select/Select.module.scss +58 -0
- package/src/components/Select/Select.tsx +192 -0
- package/src/components/Select/index.tsx +1 -0
- package/src/components/Skeleton/Skeleton.module.scss +21 -0
- package/src/components/Skeleton/Skeleton.tsx +29 -0
- package/src/components/Skeleton/index.tsx +1 -0
- package/src/components/Spacing/Spacing.module.scss +13 -0
- package/src/components/Spacing/Spacing.tsx +24 -0
- package/src/components/Spacing/index.tsx +1 -0
- package/src/components/StaticScroller/StaticScroller.module.scss +14 -0
- package/src/components/StaticScroller/StaticScroller.tsx +83 -0
- package/src/components/StaticScroller/index.tsx +1 -0
- package/src/components/Switch/Switch.module.scss +43 -0
- package/src/components/Switch/Switch.tsx +41 -0
- package/src/components/Switch/index.tsx +1 -0
- package/src/components/Table/Table.module.scss +76 -0
- package/src/components/Table/Table.tsx +152 -0
- package/src/components/Table/index.tsx +1 -0
- package/src/components/Tabs/Tabs.module.scss +40 -0
- package/src/components/Tabs/Tabs.tsx +104 -0
- package/src/components/Tabs/index.tsx +1 -0
- package/src/components/Text/Text.module.scss +81 -0
- package/src/components/Text/Text.tsx +42 -0
- package/src/components/Text/index.tsx +1 -0
- package/src/components/Transition/MasksFactory/DiagonalReveal.tsx +47 -0
- package/src/components/Transition/MasksFactory/DiagonalSquareToBalls.tsx +78 -0
- package/src/components/Transition/MasksFactory/PhysicsSquares.tsx +106 -0
- package/src/components/Transition/MasksFactory/SquareToBalls.tsx +66 -0
- package/src/components/Transition/MasksFactory/utils.ts +35 -0
- package/src/components/Transition/Transition.module.scss +211 -0
- package/src/components/Transition/Transition.tsx +495 -0
- package/src/components/Transition/index.tsx +1 -0
- package/src/components/UncontrolledTransition/UncontrolledTransition.ai.md +9 -0
- package/src/components/UncontrolledTransition/UncontrolledTransition.sample.tsx +34 -0
- package/src/components/UncontrolledTransition/UncontrolledTransition.tsx +143 -0
- package/src/components/UncontrolledTransition/index.tsx +2 -0
- package/src/components/WalletConnectionWrapper/WalletConnectionWrapper.tsx +212 -0
- package/src/components/WalletConnectionWrapper/index.tsx +1 -0
- package/src/components/utilitary/ScrollAndFocusLock/ScrollAndFocusLock.module.scss +5 -0
- package/src/components/utilitary/ScrollAndFocusLock/ScrollAndFocusLock.tsx +52 -0
- package/src/components/utilitary/ScrollAndFocusLock/index.tsx +1 -0
- package/src/context/AsyncProcess.tsx +107 -0
- package/src/context/ContextAsyncControl.tsx +89 -0
- package/src/context/CustomBrowserRouter.tsx +55 -0
- package/src/context/OneUIProvider.tsx +308 -0
- package/src/hooks/logs/useDependencyChangeDetection.ts +25 -0
- package/src/hooks/logs/useIsMounting.ts +7 -0
- package/src/hooks/persistence/useLocalStorage.ts +45 -0
- package/src/hooks/shims/ObjectWatchShim.ts +56 -0
- package/src/hooks/ui/useAdaptiveImage.tsx +36 -0
- package/src/hooks/ui/useAlternating.tsx +22 -0
- package/src/hooks/ui/useBreakpoint.tsx +21 -0
- package/src/hooks/ui/useCustomScrollbar.module.scss +20 -0
- package/src/hooks/ui/useCustomScrollbar.tsx +22 -0
- package/src/hooks/ui/useEffectIf.ts +11 -0
- package/src/hooks/ui/useMouseHover.tsx +26 -0
- package/src/hooks/ui/usePaginationControls.module.scss +16 -0
- package/src/hooks/ui/usePaginationControls.tsx +176 -0
- package/src/hooks/ui/useSnapToViewport.module.scss +6 -0
- package/src/hooks/ui/useSnapToViewport.ts +28 -0
- package/src/hooks/ui/useTilt.tsx +219 -0
- package/src/hooks/ui/useZoomable.module.scss +34 -0
- package/src/hooks/ui/useZoomable.tsx +144 -0
- package/src/hooks/useAsyncControl.ai.md +25 -0
- package/src/hooks/useAsyncControl.ts +101 -0
- package/src/hooks/useContainedRepositioning.ts +110 -0
- package/src/hooks/useCustomHistory.ts +14 -0
- package/src/hooks/useElementFit.ts +82 -0
- package/src/hooks/useFirestoreWatch.ts +54 -0
- package/src/hooks/useForm.ts +49 -0
- package/src/hooks/useFreeze.ts +12 -0
- package/src/hooks/useHero.module.scss +41 -0
- package/src/hooks/useHero.ts +512 -0
- package/src/hooks/useIntersection.ts +32 -0
- package/src/hooks/useMergeRefs.ts +29 -0
- package/src/hooks/useObserve.ts +24 -0
- package/src/hooks/usePagination.ts +228 -0
- package/src/hooks/usePooledOperation.ts +54 -0
- package/src/hooks/usePooling.ts +46 -0
- package/src/hooks/useRebound.ts +23 -0
- package/src/hooks/useShortIntl.ai.md +5 -0
- package/src/hooks/useShortIntl.ts +97 -0
- package/src/hooks/utility/useAsyncMemo.ts +43 -0
- package/src/hooks/utility/useDepChange.ts +11 -0
- package/src/hooks/utility/useEvents.ts +33 -0
- package/src/hooks/utility/useImmediate.ts +8 -0
- package/src/hooks/utility/useManualInit.ts +24 -0
- package/src/hooks/utility/useModule.ts +15 -0
- package/src/hooks/utility/useQuery.ts +15 -0
- package/src/hooks/utility/useUniqueEffect.ts +22 -0
- package/src/index.ts +3 -0
- package/src/models/DebugLogger.ts +7 -0
- package/src/models/GenericContract.ts +169 -0
- package/src/models/Orbs.ts +97 -0
- package/src/reac-app-env.d.ts +6 -0
- package/src/storybook/assets/video/txt-reversed.mp4 +0 -0
- package/src/storybookUtils/index.tsx +53 -0
- package/src/type-utils.ts +49 -0
- package/src/utility.d.ts +70 -0
- package/src/utils/blockchain.ts +43 -0
- package/src/utils/flatten.ts +17 -0
- package/src/utils/formatters.ts +36 -0
- package/src/utils/html.utils.ts +3 -0
- package/src/utils/ownEvent.ts +8 -0
- package/src/utils/test.ts +19 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
createRef,
|
|
3
|
+
ForwardedRef,
|
|
4
|
+
forwardRef,
|
|
5
|
+
PropsWithChildren,
|
|
6
|
+
ReactElement,
|
|
7
|
+
ReactNode,
|
|
8
|
+
useEffect,
|
|
9
|
+
useImperativeHandle,
|
|
10
|
+
useMemo,
|
|
11
|
+
useState,
|
|
12
|
+
} from "react";
|
|
13
|
+
import { useWallet, UseWalletProvider } from "use-wallet";
|
|
14
|
+
import useAsyncControl from "../../hooks/useAsyncControl";
|
|
15
|
+
|
|
16
|
+
export type WalletConnectionProps = PropsWithChildren<
|
|
17
|
+
Omit<ReturnType<typeof useAsyncControl>, "process"> & {
|
|
18
|
+
chainId?: number;
|
|
19
|
+
isChainIdValid: boolean | undefined;
|
|
20
|
+
isProviderAvailable: boolean;
|
|
21
|
+
isConnectedAndValidChain: boolean;
|
|
22
|
+
isConnected: boolean;
|
|
23
|
+
wallet?: string;
|
|
24
|
+
|
|
25
|
+
connect: () => Promise<void>;
|
|
26
|
+
disconnect: () => void;
|
|
27
|
+
changeChainId: () => Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
>;
|
|
30
|
+
|
|
31
|
+
type Props = {
|
|
32
|
+
/**
|
|
33
|
+
* The chain id that the user is expected to connect to
|
|
34
|
+
*/
|
|
35
|
+
chain?: {
|
|
36
|
+
id: number;
|
|
37
|
+
rpcUrl: string;
|
|
38
|
+
explorerUrl: string;
|
|
39
|
+
name: string;
|
|
40
|
+
currency: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* When the user doesn't have a provider like metamask available
|
|
45
|
+
*/
|
|
46
|
+
ProviderUnavailable?: React.FunctionComponent;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* This is invoked when the chain ID is not available
|
|
50
|
+
*/
|
|
51
|
+
ChainIdInvalid?: React.FunctionComponent<{
|
|
52
|
+
changeChainId: () => void;
|
|
53
|
+
}>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* This renders the content that is shown inside the wallet content
|
|
57
|
+
*/
|
|
58
|
+
Content: (props: WalletConnectionProps) => ReactElement;
|
|
59
|
+
};
|
|
60
|
+
function _WalletConnectionWrapper(
|
|
61
|
+
props: PropsWithChildren<Props>,
|
|
62
|
+
ref: ForwardedRef<{
|
|
63
|
+
connect: () => Promise<void>;
|
|
64
|
+
disconnect: () => void;
|
|
65
|
+
}>
|
|
66
|
+
) {
|
|
67
|
+
return (
|
|
68
|
+
<UseWalletProvider>
|
|
69
|
+
<Content compRef={ref || createRef()} {...props} />
|
|
70
|
+
</UseWalletProvider>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* This component handles a lot of cenarios when dealing with the wallet connection to different providers (ex: Metamask)
|
|
75
|
+
**/
|
|
76
|
+
function _BaseWalletConnectionWrapper(
|
|
77
|
+
props: Props & {
|
|
78
|
+
children?: any;
|
|
79
|
+
},
|
|
80
|
+
ref: ForwardedRef<{
|
|
81
|
+
connect: () => Promise<void>;
|
|
82
|
+
disconnect: () => void;
|
|
83
|
+
}>
|
|
84
|
+
) {
|
|
85
|
+
return <Content compRef={ref || createRef()} {...props} />;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function Content({
|
|
89
|
+
ProviderUnavailable,
|
|
90
|
+
ChainIdInvalid,
|
|
91
|
+
chain,
|
|
92
|
+
Content: ProvidedContentWrapper,
|
|
93
|
+
compRef,
|
|
94
|
+
children,
|
|
95
|
+
}: PropsWithChildren<
|
|
96
|
+
Props & {
|
|
97
|
+
compRef: ForwardedRef<{
|
|
98
|
+
connect: () => Promise<void>;
|
|
99
|
+
disconnect: () => void;
|
|
100
|
+
}>;
|
|
101
|
+
}
|
|
102
|
+
>) {
|
|
103
|
+
const wallet = useWallet();
|
|
104
|
+
const connectionAsyncWrapper = useAsyncControl();
|
|
105
|
+
const connect = async () => {
|
|
106
|
+
await connectionAsyncWrapper.process(async () => {
|
|
107
|
+
await wallet.connect("injected");
|
|
108
|
+
localStorage.setItem("auto_connect", "true");
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
const disconnect = () => {
|
|
112
|
+
wallet.reset();
|
|
113
|
+
localStorage.removeItem("auto_connect");
|
|
114
|
+
};
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
const autoConnect = !!localStorage.getItem("auto_connect");
|
|
117
|
+
if (autoConnect && !wallet.account) connect();
|
|
118
|
+
}, []);
|
|
119
|
+
useImperativeHandle(
|
|
120
|
+
compRef,
|
|
121
|
+
() => ({
|
|
122
|
+
connect,
|
|
123
|
+
disconnect,
|
|
124
|
+
}),
|
|
125
|
+
[wallet]
|
|
126
|
+
);
|
|
127
|
+
const [isProviderAvailable] = useState(() => !!window.ethereum);
|
|
128
|
+
/**
|
|
129
|
+
* true - Mostrar o conteudo (ex: form de transferencia)
|
|
130
|
+
* false - Mostrar o botão de trocar a chain
|
|
131
|
+
*
|
|
132
|
+
* undefined ???
|
|
133
|
+
*/
|
|
134
|
+
const isChainIdValid = useMemo(
|
|
135
|
+
() =>
|
|
136
|
+
chain
|
|
137
|
+
? wallet.isConnected()
|
|
138
|
+
? wallet.chainId === chain.id
|
|
139
|
+
: true
|
|
140
|
+
: undefined,
|
|
141
|
+
[wallet, chain?.id]
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
async function changeChainId() {
|
|
145
|
+
try {
|
|
146
|
+
await window.ethereum!.request({
|
|
147
|
+
method: "wallet_switchEthereumChain",
|
|
148
|
+
params: [
|
|
149
|
+
{
|
|
150
|
+
chainId: `0x${chain!.id.toString(16).padStart(2, "0")}`,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
} catch (e: any) {
|
|
155
|
+
switch (e.code) {
|
|
156
|
+
case 4902:
|
|
157
|
+
await window.ethereum!.request({
|
|
158
|
+
method: "wallet_addEthereumChain",
|
|
159
|
+
params: [
|
|
160
|
+
{
|
|
161
|
+
chainId: `0x${chain!.id.toString(16).padStart(2, "0")}`,
|
|
162
|
+
chainName: chain!.name,
|
|
163
|
+
rpcUrls: [chain!.rpcUrl],
|
|
164
|
+
blockExplorerUrls: [chain!.explorerUrl],
|
|
165
|
+
nativeCurrency: {
|
|
166
|
+
symbol: chain!.currency,
|
|
167
|
+
decimals: 18,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
});
|
|
172
|
+
default:
|
|
173
|
+
throw e;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const ContentWrapper = ProvidedContentWrapper as any;
|
|
178
|
+
return (
|
|
179
|
+
<>
|
|
180
|
+
{ProviderUnavailable && !isProviderAvailable && <ProviderUnavailable />}
|
|
181
|
+
{ChainIdInvalid && !isChainIdValid && (
|
|
182
|
+
<ChainIdInvalid changeChainId={changeChainId} />
|
|
183
|
+
)}
|
|
184
|
+
{
|
|
185
|
+
<ContentWrapper
|
|
186
|
+
{...connectionAsyncWrapper}
|
|
187
|
+
isChainIdValid={isChainIdValid}
|
|
188
|
+
isProviderAvailable={isProviderAvailable}
|
|
189
|
+
isConnectedAndValidChain={isChainIdValid && wallet.isConnected()}
|
|
190
|
+
connect={connect}
|
|
191
|
+
disconnect={disconnect}
|
|
192
|
+
changeChainId={changeChainId}
|
|
193
|
+
chainId={wallet.chainId}
|
|
194
|
+
isConnected={wallet.isConnected()}
|
|
195
|
+
wallet={wallet.account}
|
|
196
|
+
>
|
|
197
|
+
{children}
|
|
198
|
+
</ContentWrapper>
|
|
199
|
+
}
|
|
200
|
+
</>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* This component handles some cenarios when dealing with the wallet connection to different providers (ex: Metamask)
|
|
206
|
+
**/
|
|
207
|
+
const WalletConnectionWrapper = forwardRef(_WalletConnectionWrapper);
|
|
208
|
+
export default WalletConnectionWrapper;
|
|
209
|
+
|
|
210
|
+
export const BaseWalletConnectionWrapper = forwardRef(
|
|
211
|
+
_BaseWalletConnectionWrapper
|
|
212
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, BaseWalletConnectionWrapper } from './WalletConnectionWrapper';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { PropsWithChildren, useEffect, useRef } from "react";
|
|
2
|
+
import Styles from "./ScrollAndFocusLock.module.scss";
|
|
3
|
+
/**
|
|
4
|
+
* This utilitary component shall be used to lock the focus and disable scroll over the wrapped component
|
|
5
|
+
**/
|
|
6
|
+
export default function ScrollAndFocusLock({
|
|
7
|
+
open,
|
|
8
|
+
children,
|
|
9
|
+
}: PropsWithChildren<{
|
|
10
|
+
open: boolean;
|
|
11
|
+
}>) {
|
|
12
|
+
const firstAnchor = useRef<HTMLDivElement>(null);
|
|
13
|
+
const lastAnchor = useRef<HTMLDivElement>(null);
|
|
14
|
+
const startOfModal = useRef<HTMLDivElement>(null);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (open) startOfModal.current!.focus();
|
|
17
|
+
}, []);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (open) {
|
|
20
|
+
startOfModal.current!.focus();
|
|
21
|
+
document.body.classList.add(Styles.lockClass)
|
|
22
|
+
|
|
23
|
+
return () => {
|
|
24
|
+
document.body.classList.remove(Styles.lockClass)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}, [open]);
|
|
28
|
+
|
|
29
|
+
function onFocusAnchors(e: React.FocusEvent<HTMLDivElement>) {
|
|
30
|
+
const focusOnStartOfModal = () => {
|
|
31
|
+
const nextSibling = firstAnchor.current!.nextElementSibling;
|
|
32
|
+
if (nextSibling instanceof HTMLDivElement) nextSibling.focus();
|
|
33
|
+
};
|
|
34
|
+
if (e.target === firstAnchor.current) {
|
|
35
|
+
if (e.relatedTarget === startOfModal.current) lastAnchor.current!.focus();
|
|
36
|
+
else focusOnStartOfModal();
|
|
37
|
+
} else if (
|
|
38
|
+
e.target === lastAnchor.current &&
|
|
39
|
+
e.relatedTarget !== firstAnchor.current
|
|
40
|
+
) {
|
|
41
|
+
focusOnStartOfModal();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return (
|
|
45
|
+
<>
|
|
46
|
+
<div ref={firstAnchor} tabIndex={0} onFocus={onFocusAnchors} />
|
|
47
|
+
<div ref={startOfModal} tabIndex={0} />
|
|
48
|
+
{children}
|
|
49
|
+
<div ref={lastAnchor} tabIndex={0} onFocus={onFocusAnchors} />
|
|
50
|
+
</>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './ScrollAndFocusLock';
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import React, { useMemo } from "react";
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
PropsWithChildren,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
} from "react";
|
|
9
|
+
import useEvents from "../hooks/utility/useEvents";
|
|
10
|
+
|
|
11
|
+
const AsyncProcessContext = createContext<{
|
|
12
|
+
_subscriber: ReturnType<typeof useEvents>["subscriber"];
|
|
13
|
+
_wrappedFunctions: {
|
|
14
|
+
[k in keyof OnepercentUtility.AsyncQueue.Processes]: (
|
|
15
|
+
...args: OnepercentUtility.AsyncQueue.Processes[k]
|
|
16
|
+
) => Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
}>(null as any);
|
|
19
|
+
|
|
20
|
+
type PersistedIdentifier = string;
|
|
21
|
+
|
|
22
|
+
export default function AsyncProcessProvider({
|
|
23
|
+
children,
|
|
24
|
+
triggers,
|
|
25
|
+
persistence,
|
|
26
|
+
}: PropsWithChildren<{
|
|
27
|
+
/** Functions that will be provided to those that use the async process */
|
|
28
|
+
triggers: {
|
|
29
|
+
[k in keyof OnepercentUtility.AsyncQueue.Processes]: (
|
|
30
|
+
...args: OnepercentUtility.AsyncQueue.Processes[k]
|
|
31
|
+
) => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
/** This will persist the data required for restoring the async processes when required */
|
|
34
|
+
persistence: {
|
|
35
|
+
write: <K extends keyof OnepercentUtility.AsyncQueue.Processes>(
|
|
36
|
+
k: K,
|
|
37
|
+
...args: OnepercentUtility.AsyncQueue.Processes[K]
|
|
38
|
+
) => PersistedIdentifier;
|
|
39
|
+
remove: (id: PersistedIdentifier) => void;
|
|
40
|
+
recover: () => [PersistedIdentifier, Promise<void>][];
|
|
41
|
+
};
|
|
42
|
+
}>) {
|
|
43
|
+
const { subscriber, dispatcher } = useEvents();
|
|
44
|
+
|
|
45
|
+
const wrappedFunctions = useMemo(() => {
|
|
46
|
+
return Object.keys(triggers).reduce(
|
|
47
|
+
(r, k) => ({
|
|
48
|
+
...r,
|
|
49
|
+
[k]: (
|
|
50
|
+
...args: OnepercentUtility.AsyncQueue.Processes[keyof OnepercentUtility.AsyncQueue.Processes]
|
|
51
|
+
) => {
|
|
52
|
+
let persisted = persistence.write(k as any, ...args);
|
|
53
|
+
return (triggers as any)[k as any](...args).finally(() => {
|
|
54
|
+
persistence.remove(persisted);
|
|
55
|
+
dispatcher(k as any);
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
{} as typeof triggers
|
|
60
|
+
);
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
const recoveries = persistence.recover();
|
|
65
|
+
for (let [recoveryId, recoveryProcess] of recoveries)
|
|
66
|
+
recoveryProcess.finally(() => {
|
|
67
|
+
persistence.remove(recoveryId);
|
|
68
|
+
});
|
|
69
|
+
}, []);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<AsyncProcessContext.Provider
|
|
73
|
+
value={{ _subscriber: subscriber, _wrappedFunctions: wrappedFunctions }}
|
|
74
|
+
>
|
|
75
|
+
{children}
|
|
76
|
+
</AsyncProcessContext.Provider>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function useAsyncProcess(): {
|
|
81
|
+
[k in keyof OnepercentUtility.AsyncQueue.Processes]: (
|
|
82
|
+
...args: OnepercentUtility.AsyncQueue.Processes[k]
|
|
83
|
+
) => Promise<void>;
|
|
84
|
+
} & {
|
|
85
|
+
on: (
|
|
86
|
+
k: keyof OnepercentUtility.AsyncQueue.Processes,
|
|
87
|
+
whatToDo: () => void
|
|
88
|
+
) => void;
|
|
89
|
+
} {
|
|
90
|
+
const { _subscriber: subscriber, _wrappedFunctions } =
|
|
91
|
+
useContext(AsyncProcessContext);
|
|
92
|
+
const subscriptions = useRef<Function[]>([]);
|
|
93
|
+
|
|
94
|
+
useEffect(
|
|
95
|
+
() => () => {
|
|
96
|
+
for (let unsubscribe of subscriptions.current) unsubscribe();
|
|
97
|
+
},
|
|
98
|
+
[]
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
on: (k, whatToDo) => {
|
|
103
|
+
subscriptions.current.push(subscriber(k, whatToDo));
|
|
104
|
+
},
|
|
105
|
+
..._wrappedFunctions,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
PropsWithChildren,
|
|
5
|
+
useInsertionEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useEffect,
|
|
8
|
+
useState,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { FunctionMap, useRawAsynControl } from "../hooks/useAsyncControl";
|
|
11
|
+
|
|
12
|
+
type CB = (...args: any[]) => void;
|
|
13
|
+
class Subscriber {
|
|
14
|
+
private sharedCbs: { [id: string]: Function[] } = {};
|
|
15
|
+
private latest: {
|
|
16
|
+
[id: string]: any;
|
|
17
|
+
} = {};
|
|
18
|
+
|
|
19
|
+
register<C extends CB>(cbId: string, cb: C) {
|
|
20
|
+
if (!this.sharedCbs[cbId]) this.sharedCbs[cbId] = [];
|
|
21
|
+
this.sharedCbs[cbId].push(cb);
|
|
22
|
+
return (...args: Parameters<C>) => {
|
|
23
|
+
this.latest[cbId] = args;
|
|
24
|
+
for (let cb of this.sharedCbs[cbId]) cb(...args);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
unregister<C extends CB>(cbId: string, cb: C) {
|
|
28
|
+
const cbIdx = this.sharedCbs[cbId].indexOf(cb);
|
|
29
|
+
this.sharedCbs[cbId].splice(cbIdx, 1);
|
|
30
|
+
}
|
|
31
|
+
current(cbId: string) {
|
|
32
|
+
return this.latest[cbId];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type ContextAsyncControlContextShape = {
|
|
37
|
+
[controlId: string]: Subscriber;
|
|
38
|
+
};
|
|
39
|
+
export const ContextAsyncControlContext =
|
|
40
|
+
createContext<ContextAsyncControlContextShape>(null as any);
|
|
41
|
+
|
|
42
|
+
export default function ContextAsyncControlProvider({
|
|
43
|
+
children,
|
|
44
|
+
}: PropsWithChildren<{}>) {
|
|
45
|
+
return (
|
|
46
|
+
<ContextAsyncControlContext.Provider value={{}}>
|
|
47
|
+
{children}
|
|
48
|
+
</ContextAsyncControlContext.Provider>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function useShareState<E>(controlId: string, stateId: string) {
|
|
53
|
+
const ctx = useContext(ContextAsyncControlContext);
|
|
54
|
+
const [state, setLocalState] = useState<E>(() => {
|
|
55
|
+
if (!ctx[controlId]) ctx[controlId] = new Subscriber();
|
|
56
|
+
const initAs = ctx[controlId].current(stateId)?.[0] as E;
|
|
57
|
+
return initAs;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const wrappedSetState = useMemo(() => {
|
|
61
|
+
return ctx[controlId].register(stateId, setLocalState);
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
useInsertionEffect(
|
|
65
|
+
() => () => {
|
|
66
|
+
ctx[controlId].unregister(stateId, setLocalState);
|
|
67
|
+
},
|
|
68
|
+
[]
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return [state, wrappedSetState] as const;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function useContextControl<E, F extends FunctionMap>(
|
|
75
|
+
controlId: string,
|
|
76
|
+
functionsToWrap: F
|
|
77
|
+
) {
|
|
78
|
+
const [error, setError] = useShareState<E | Error | undefined>(
|
|
79
|
+
controlId,
|
|
80
|
+
"error"
|
|
81
|
+
);
|
|
82
|
+
const [loading, setLoading] = useShareState<boolean>(controlId, "loading");
|
|
83
|
+
|
|
84
|
+
return useRawAsynControl(
|
|
85
|
+
functionsToWrap,
|
|
86
|
+
[error, setError],
|
|
87
|
+
[loading, setLoading]
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Router, useHistory } from "react-router-dom";
|
|
2
|
+
import { createBrowserHistory } from "history";
|
|
3
|
+
import React, {
|
|
4
|
+
PropsWithChildren,
|
|
5
|
+
useEffect,
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
} from "react";
|
|
9
|
+
|
|
10
|
+
export type CustomState = {
|
|
11
|
+
internalNavigation?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default function CustomBrowserRouter({
|
|
15
|
+
children,
|
|
16
|
+
beforeRouteChange = (s) => s,
|
|
17
|
+
}: PropsWithChildren<{
|
|
18
|
+
/**
|
|
19
|
+
* Allows the dev to modify the route before commiting the route change
|
|
20
|
+
*
|
|
21
|
+
* @returns The new route
|
|
22
|
+
*/
|
|
23
|
+
beforeRouteChange?: (
|
|
24
|
+
newRoute: string,
|
|
25
|
+
history: ReturnType<typeof createBrowserHistory>
|
|
26
|
+
) => string;
|
|
27
|
+
}>) {
|
|
28
|
+
const { current: historyCustom } = useRef(createBrowserHistory<any>());
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
function overrideFunction(name: keyof typeof historyCustom) {
|
|
31
|
+
const orig = historyCustom[name] as any;
|
|
32
|
+
(historyCustom as any)[name] = (
|
|
33
|
+
route: string,
|
|
34
|
+
state: CustomState | null,
|
|
35
|
+
...args: any[]
|
|
36
|
+
) => {
|
|
37
|
+
const isReplacingAnInternalNavigation =
|
|
38
|
+
name === "replace" && history.state?.state?.internalNavigation;
|
|
39
|
+
const isARouteChange = name !== "replace";
|
|
40
|
+
if ((isARouteChange || isReplacingAnInternalNavigation) && !state)
|
|
41
|
+
state = {};
|
|
42
|
+
if (state)
|
|
43
|
+
state.internalNavigation =
|
|
44
|
+
name === "replace"
|
|
45
|
+
? history.state?.state?.internalNavigation
|
|
46
|
+
: true;
|
|
47
|
+
const modifiedRoute = beforeRouteChange(route, historyCustom);
|
|
48
|
+
return orig(modifiedRoute, state, ...args);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
overrideFunction("push");
|
|
52
|
+
overrideFunction("replace");
|
|
53
|
+
}, [historyCustom]);
|
|
54
|
+
return <Router history={historyCustom}>{children as any}</Router>;
|
|
55
|
+
}
|