@arthur2079/internal-profile 4.1.2-next.5 → 5.1.2
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/api/errors.d.ts +3 -0
- package/dist/api/errors.js +9 -0
- package/dist/api/mod.d.ts +4 -0
- package/dist/api/mod.js +2 -0
- package/dist/api/request.d.ts +19 -0
- package/dist/api/request.js +96 -0
- package/dist/api/types.d.ts +190 -0
- package/dist/api/types.js +1 -0
- package/dist/components/ConnectWalletModal/ConnectWalletFooter.d.ts +5 -0
- package/dist/components/ConnectWalletModal/ConnectWalletFooter.js +9 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.constants.d.ts +5 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.constants.js +8 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.d.ts +3 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.helpers.d.ts +2 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.helpers.js +9 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.js +194 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.styles.d.ts +19 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.styles.js +101 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.types.d.ts +44 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.types.js +1 -0
- package/dist/components/ConnectWalletModal/EmptyWalletList.d.ts +2 -0
- package/dist/components/ConnectWalletModal/EmptyWalletList.js +9 -0
- package/dist/components/ConnectWalletModal/StatefulConnectContainer.d.ts +3 -0
- package/dist/components/ConnectWalletModal/StatefulConnectContainer.js +37 -0
- package/dist/components/ConnectWalletModal/StatefulConnectContainer.styles.d.ts +1 -0
- package/dist/components/ConnectWalletModal/StatefulConnectContainer.styles.js +51 -0
- package/dist/components/ConnectWalletModal/StatefulConnectContainer.types.d.ts +12 -0
- package/dist/components/ConnectWalletModal/StatefulConnectContainer.types.js +1 -0
- package/dist/components/ConnectWalletModal/WalletsChainSelect.d.ts +3 -0
- package/dist/components/ConnectWalletModal/WalletsChainSelect.js +86 -0
- package/dist/components/ConnectWalletModal/WalletsChainSelect.styles.d.ts +21 -0
- package/dist/components/ConnectWalletModal/WalletsChainSelect.styles.js +83 -0
- package/dist/components/ConnectWalletModal/WalletsChainSelect.types.d.ts +12 -0
- package/dist/components/ConnectWalletModal/WalletsChainSelect.types.js +1 -0
- package/dist/components/ConnectWalletModal/index.d.ts +3 -0
- package/dist/components/ConnectWalletModal/index.js +2 -0
- package/dist/components/ProfileWallet/ProfileWallet.d.ts +3 -0
- package/dist/components/ProfileWallet/ProfileWallet.js +54 -0
- package/dist/components/ProfileWallet/ProfileWallet.styles.d.ts +6 -0
- package/dist/components/ProfileWallet/ProfileWallet.styles.js +54 -0
- package/dist/components/ProfileWallet/ProfileWallet.types.d.ts +11 -0
- package/dist/components/ProfileWallet/ProfileWallet.types.js +1 -0
- package/dist/components/ProfileWallet/index.d.ts +1 -0
- package/dist/components/ProfileWallet/index.js +1 -0
- package/dist/components/ProfileWallets/ConnectedWallets.d.ts +2 -0
- package/dist/components/ProfileWallets/ConnectedWallets.js +25 -0
- package/dist/components/ProfileWallets/ConnectedWallets.styles.d.ts +4 -0
- package/dist/components/ProfileWallets/ConnectedWallets.styles.js +30 -0
- package/dist/components/ProfileWallets/ConnectedWalletsEmptyState.d.ts +5 -0
- package/dist/components/ProfileWallets/ConnectedWalletsEmptyState.js +9 -0
- package/dist/components/ProfileWallets/ConnectedWalletsEmptyState.styles.d.ts +1 -0
- package/dist/components/ProfileWallets/ConnectedWalletsEmptyState.styles.js +8 -0
- package/dist/components/ProfileWallets/ProfileWallets.d.ts +4 -0
- package/dist/components/ProfileWallets/ProfileWallets.js +37 -0
- package/dist/components/ProfileWallets/ProfileWallets.styles.d.ts +5 -0
- package/dist/components/ProfileWallets/ProfileWallets.styles.js +17 -0
- package/dist/components/ProfileWallets/ProfileWallets.types.d.ts +14 -0
- package/dist/components/ProfileWallets/ProfileWallets.types.js +1 -0
- package/dist/components/ProfileWallets/index.d.ts +1 -0
- package/dist/components/ProfileWallets/index.js +1 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.constants.d.ts +3 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.constants.js +2 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.d.ts +3 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.js +23 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.styles.d.ts +4 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.styles.js +23 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.types.d.ts +23 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.types.js +1 -0
- package/dist/components/ProfileWalletsModal/index.d.ts +2 -0
- package/dist/components/ProfileWalletsModal/index.js +1 -0
- package/dist/components/SocialWalletIntroModal/SocialWalletIntroModal.d.ts +2 -0
- package/dist/components/SocialWalletIntroModal/SocialWalletIntroModal.js +21 -0
- package/dist/components/SocialWalletIntroModal/SocialWalletIntroModal.styles.d.ts +4 -0
- package/dist/components/SocialWalletIntroModal/SocialWalletIntroModal.styles.js +49 -0
- package/dist/components/SocialWalletIntroModal/SocialWalletIntroModal.types.d.ts +7 -0
- package/dist/components/SocialWalletIntroModal/SocialWalletIntroModal.types.js +1 -0
- package/dist/components/SocialWalletIntroModal/index.d.ts +1 -0
- package/dist/components/SocialWalletIntroModal/index.js +1 -0
- package/dist/components/StackModal/ModalContainer.d.ts +4 -0
- package/dist/components/StackModal/ModalContainer.js +33 -0
- package/dist/components/StackModal/ModalContainer.types.d.ts +6 -0
- package/dist/components/StackModal/ModalContainer.types.js +1 -0
- package/dist/components/StackModal/StackModal.d.ts +3 -0
- package/dist/components/StackModal/StackModal.js +90 -0
- package/dist/components/StackModal/StackModal.styles.d.ts +2 -0
- package/dist/components/StackModal/StackModal.styles.js +77 -0
- package/dist/components/StackModal/StackModal.types.d.ts +3 -0
- package/dist/components/StackModal/StackModal.types.js +1 -0
- package/dist/components/StackModal/index.d.ts +1 -0
- package/dist/components/StackModal/index.js +1 -0
- package/dist/components/WalletItem/WalletItem.d.ts +3 -0
- package/dist/components/WalletItem/WalletItem.js +60 -0
- package/dist/components/WalletItem/WalletItem.styles.d.ts +9 -0
- package/dist/components/WalletItem/WalletItem.styles.js +71 -0
- package/dist/components/WalletItem/WalletItem.types.d.ts +8 -0
- package/dist/components/WalletItem/WalletItem.types.js +1 -0
- package/dist/components/WalletItem/index.d.ts +1 -0
- package/dist/components/WalletItem/index.js +1 -0
- package/dist/components/mod.d.ts +5 -0
- package/dist/components/mod.js +3 -0
- package/dist/constants/errors.d.ts +1 -0
- package/dist/constants/errors.js +1 -0
- package/dist/constants/events.d.ts +3 -0
- package/dist/constants/events.js +3 -0
- package/dist/constants/links.d.ts +2 -0
- package/dist/constants/links.js +2 -0
- package/dist/constants/mod.d.ts +3 -0
- package/dist/constants/mod.js +3 -0
- package/dist/constants/modals.d.ts +3 -0
- package/dist/constants/modals.js +3 -0
- package/dist/fetcher.d.ts +3 -0
- package/dist/fetcher.js +10 -0
- package/dist/hooks/mod.d.ts +4 -0
- package/dist/hooks/mod.js +3 -0
- package/dist/hooks/useLocalStorage/index.d.ts +1 -0
- package/dist/hooks/useLocalStorage/index.js +1 -0
- package/dist/hooks/useLocalStorage/useLocalStorage.d.ts +1 -0
- package/dist/hooks/useLocalStorage/useLocalStorage.js +24 -0
- package/dist/hooks/useProfile/index.d.ts +1 -0
- package/dist/hooks/useProfile/index.js +1 -0
- package/dist/hooks/useProfile/useProfile.constants.d.ts +2 -0
- package/dist/hooks/useProfile/useProfile.constants.js +3 -0
- package/dist/hooks/useProfile/useProfile.d.ts +2 -0
- package/dist/hooks/useProfile/useProfile.helpers.d.ts +4 -0
- package/dist/hooks/useProfile/useProfile.helpers.js +3 -0
- package/dist/hooks/useProfile/useProfile.js +20 -0
- package/dist/hooks/useProfile/useProfile.types.d.ts +11 -0
- package/dist/hooks/useProfile/useProfile.types.js +1 -0
- package/dist/hooks/useStackModal.d.ts +38 -0
- package/dist/hooks/useStackModal.js +61 -0
- package/dist/hooks/useStatefulConnect.d.ts +7 -0
- package/dist/hooks/useStatefulConnect.js +15 -0
- package/dist/mod.d.ts +1 -0
- package/dist/mod.js +1 -0
- package/dist/store/helpers.d.ts +5 -0
- package/dist/store/helpers.js +42 -0
- package/dist/store/middlewares.d.ts +6 -0
- package/dist/store/middlewares.js +40 -0
- package/dist/store/mod.d.ts +4 -0
- package/dist/store/mod.js +3 -0
- package/dist/store/selectors.d.ts +47 -0
- package/dist/store/selectors.js +21 -0
- package/dist/store/slice.d.ts +134 -0
- package/dist/store/slice.js +230 -0
- package/dist/store/thunks.d.ts +153 -0
- package/dist/store/thunks.js +219 -0
- package/dist/store/types.d.ts +67 -0
- package/dist/store/types.js +1 -0
- package/dist/store/utils.d.ts +1 -0
- package/dist/store/utils.js +11 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +1 -0
- package/dist/utils/mod.d.ts +1 -0
- package/dist/utils/mod.js +1 -0
- package/dist/utils/wallets.d.ts +16 -0
- package/dist/utils/wallets.js +34 -0
- package/package.json +8 -5
- package/CHANGELOG.md +0 -32
- package/tsconfig.json +0 -21
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { StackModal } from './StackModal';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { SOCIAL_WALLET_TYPE } from '@arthur2079/internal-social-wallet';
|
|
3
|
+
import { Image, Typography, WalletState } from '@rango-dev/ui';
|
|
4
|
+
import { detectInstallLink } from '@rango-dev/wallets-shared';
|
|
5
|
+
import { useWallets } from '@rango-dev/widget-embedded';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { ImageContainer, LogoContainer, logoContainerStyles, Spinner, WalletItemContainer, } from './WalletItem.styles';
|
|
8
|
+
export const WalletItem = ({ wallet, handleClick, disabled, disablePartialState, }) => {
|
|
9
|
+
const { title, image, link } = wallet;
|
|
10
|
+
const { t } = useTranslation();
|
|
11
|
+
const { state } = useWallets();
|
|
12
|
+
const connecting = wallet.state === WalletState.CONNECTING;
|
|
13
|
+
const notInstalled = wallet.state === WalletState.NOT_INSTALLED;
|
|
14
|
+
const ParentComp = (props) => {
|
|
15
|
+
const containerStyles = {
|
|
16
|
+
display: 'flex',
|
|
17
|
+
justifyContent: 'flex-start',
|
|
18
|
+
textAlign: 'center',
|
|
19
|
+
position: 'relative',
|
|
20
|
+
// TODO: As this component always receives disabled prop as false, we can remove this
|
|
21
|
+
...(disabled && {
|
|
22
|
+
filter: 'grayscale(1)',
|
|
23
|
+
pointerEvents: 'none',
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
return notInstalled ? (_jsx("a", { href: detectInstallLink(link), target: "_blank", rel: "noreferrer", style: containerStyles, children: props.children })) : (_jsx("div", { onClick: () => handleClick(wallet), style: containerStyles, children: props.children }));
|
|
27
|
+
};
|
|
28
|
+
function renderConnectingState() {
|
|
29
|
+
return (_jsx(Typography, { variant: "body", size: "xsmall", color: "info500", children: _jsx("b", { children: t('Connecting...') }) }));
|
|
30
|
+
}
|
|
31
|
+
function renderConnectedState() {
|
|
32
|
+
return (_jsx(Typography, { variant: "body", size: "xsmall", color: "success500", children: _jsx("b", { children: t('Connected') }) }));
|
|
33
|
+
}
|
|
34
|
+
function renderPartiallyConnectedState() {
|
|
35
|
+
if (!disablePartialState) {
|
|
36
|
+
return (_jsx(Typography, { variant: "body", size: "xsmall", color: "warning500", children: _jsx("b", { children: t('Connected Partially') }) }));
|
|
37
|
+
}
|
|
38
|
+
const namespacesState = state(wallet.type)?.namespaces;
|
|
39
|
+
if (!namespacesState ||
|
|
40
|
+
!Array.from(namespacesState.values()).some((namespace) => namespace.connecting)) {
|
|
41
|
+
return renderConnectedState();
|
|
42
|
+
}
|
|
43
|
+
return renderConnectingState();
|
|
44
|
+
}
|
|
45
|
+
const renderWalletState = () => {
|
|
46
|
+
switch (wallet.state) {
|
|
47
|
+
case WalletState.NOT_INSTALLED:
|
|
48
|
+
return (_jsx(Typography, { variant: "body", size: "xsmall", color: "info500", children: _jsx("b", { children: t('Install') }) }));
|
|
49
|
+
case WalletState.DISCONNECTED:
|
|
50
|
+
return (_jsx(Typography, { variant: "body", size: "xsmall", color: "neutral600", children: t('Disconnected') }));
|
|
51
|
+
case WalletState.CONNECTING:
|
|
52
|
+
return renderConnectingState();
|
|
53
|
+
case WalletState.PARTIALLY_CONNECTED:
|
|
54
|
+
return renderPartiallyConnectedState();
|
|
55
|
+
case WalletState.CONNECTED:
|
|
56
|
+
return renderConnectedState();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return (_jsx(ParentComp, { children: _jsxs(WalletItemContainer, { bordered: connecting, children: [_jsxs(LogoContainer, { style: logoContainerStyles, children: [_jsx(ImageContainer, { rounded: wallet.type !== SOCIAL_WALLET_TYPE, children: _jsx(Image, { alt: title, src: image, size: 35 }) }), connecting && _jsx(Spinner, {})] }), _jsx(Typography, { variant: "label", size: "medium", children: title }), renderWalletState()] }) }));
|
|
60
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const WalletItemContainer: any;
|
|
2
|
+
export declare const LogoContainer: any;
|
|
3
|
+
export declare const ImageContainer: any;
|
|
4
|
+
export declare const Spinner: any;
|
|
5
|
+
export declare const logoContainerStyles: {
|
|
6
|
+
margin: string;
|
|
7
|
+
marginBottom: string;
|
|
8
|
+
borderRadius: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { darkTheme, keyframes, styled } from '@rango-dev/ui';
|
|
2
|
+
export const WalletItemContainer = styled('div', {
|
|
3
|
+
width: '100%',
|
|
4
|
+
position: 'relative',
|
|
5
|
+
borderRadius: '$sm',
|
|
6
|
+
cursor: 'pointer',
|
|
7
|
+
backgroundColor: '$neutral100',
|
|
8
|
+
padding: '$10',
|
|
9
|
+
display: 'flex',
|
|
10
|
+
flexDirection: 'column',
|
|
11
|
+
borderWidth: '1px',
|
|
12
|
+
borderColor: 'transparent',
|
|
13
|
+
[`.${darkTheme} &`]: {
|
|
14
|
+
backgroundColor: '$neutral300',
|
|
15
|
+
},
|
|
16
|
+
variants: {
|
|
17
|
+
bordered: {
|
|
18
|
+
true: {
|
|
19
|
+
borderColor: '$info500',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
'&:hover': {
|
|
24
|
+
backgroundColor: '$info100',
|
|
25
|
+
[`.${darkTheme} &`]: {
|
|
26
|
+
backgroundColor: '$neutral100',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
export const LogoContainer = styled('div', {
|
|
31
|
+
position: 'relative',
|
|
32
|
+
});
|
|
33
|
+
export const ImageContainer = styled('div', {
|
|
34
|
+
borderRadius: '100%',
|
|
35
|
+
border: '1.5px transparent solid',
|
|
36
|
+
variants: {
|
|
37
|
+
rounded: {
|
|
38
|
+
true: {
|
|
39
|
+
img: {
|
|
40
|
+
borderRadius: '100%',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
const spin = keyframes({
|
|
47
|
+
'0%': {
|
|
48
|
+
transform: 'rotate(0deg)',
|
|
49
|
+
},
|
|
50
|
+
'100%': {
|
|
51
|
+
transform: 'rotate(360deg)',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
export const Spinner = styled('div', {
|
|
55
|
+
position: 'absolute',
|
|
56
|
+
border: '2px solid rgba(0, 0, 0, 0.1)',
|
|
57
|
+
borderTop: '2px solid $info500',
|
|
58
|
+
borderRadius: '$lg',
|
|
59
|
+
width: '$35',
|
|
60
|
+
height: '$35',
|
|
61
|
+
animation: `${spin} 1s linear infinite`,
|
|
62
|
+
top: 0,
|
|
63
|
+
bottom: 0,
|
|
64
|
+
right: 0,
|
|
65
|
+
left: 0,
|
|
66
|
+
});
|
|
67
|
+
export const logoContainerStyles = {
|
|
68
|
+
margin: '0 auto',
|
|
69
|
+
marginBottom: '8px',
|
|
70
|
+
borderRadius: '50%',
|
|
71
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ExtendedModalWalletInfo } from '../../utils/wallets';
|
|
2
|
+
export interface WalletItemProps {
|
|
3
|
+
wallet: ExtendedModalWalletInfo;
|
|
4
|
+
handleClick: (wallet: ExtendedModalWalletInfo) => void;
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
/** Reserved for the forcedNamespaces flow; avoid enabling partial state elsewhere. */
|
|
7
|
+
disablePartialState?: boolean;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WalletItem } from './WalletItem';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WalletItem } from './WalletItem';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ConnectWalletModal } from './ConnectWalletModal';
|
|
2
|
+
export type { ConnectWalletModalProps } from './ConnectWalletModal';
|
|
3
|
+
export { ProfileWalletsModal } from './ProfileWalletsModal';
|
|
4
|
+
export type { ProfileWalletsModalProps } from './ProfileWalletsModal';
|
|
5
|
+
export { StackModal } from './StackModal';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEFAULT_WALLET_INJECTION_ERROR = "Failed to connect to wallet";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_WALLET_INJECTION_ERROR = 'Failed to connect to wallet';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { STATEFUL_CONNECT_MODAL_ID, CONNECT_WALLETS_MODAL_ID, PROFILE_WALLETS_MODAL_ID, } from './modals';
|
|
2
|
+
export { DEFAULT_WALLET_INJECTION_ERROR } from './errors';
|
|
3
|
+
export { BLOCKCHAINS_THAT_SUPPORT_PROFILE, WALLETS_WITHOUT_SIGN_MESSAGE_METHOD, } from '../hooks/useProfile/useProfile.constants';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { STATEFUL_CONNECT_MODAL_ID, CONNECT_WALLETS_MODAL_ID, PROFILE_WALLETS_MODAL_ID, } from './modals';
|
|
2
|
+
export { DEFAULT_WALLET_INJECTION_ERROR } from './errors';
|
|
3
|
+
export { BLOCKCHAINS_THAT_SUPPORT_PROFILE, WALLETS_WITHOUT_SIGN_MESSAGE_METHOD, } from '../hooks/useProfile/useProfile.constants';
|
package/dist/fetcher.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
let fetcherInstance = null;
|
|
2
|
+
export function initializeFetcher(instance) {
|
|
3
|
+
fetcherInstance = instance;
|
|
4
|
+
}
|
|
5
|
+
export function fetcher() {
|
|
6
|
+
if (!fetcherInstance) {
|
|
7
|
+
throw new Error('You are trying to fetch profile data before the fetch instance has been intialized.');
|
|
8
|
+
}
|
|
9
|
+
return fetcherInstance;
|
|
10
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { useStackModal, MAX_STACK_SIZE, StackModalContextProvider, StackModalContext, } from './useStackModal';
|
|
2
|
+
export type { StackItem } from './useStackModal';
|
|
3
|
+
export { useStatefulConnect, StatefulConnectContextProvider, StatefulConnectContext, } from './useStatefulConnect';
|
|
4
|
+
export { useProfile } from './useProfile';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useLocalStorage } from './useLocalStorage';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useLocalStorage } from './useLocalStorage';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useLocalStorage<T>(key: string, initialValue: T): readonly [T, (value: T | ((val: T) => T)) => void];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
export function useLocalStorage(key, initialValue) {
|
|
3
|
+
const [storedValue, setStoredValue] = useState(() => {
|
|
4
|
+
try {
|
|
5
|
+
const item = window.localStorage.getItem(key);
|
|
6
|
+
return item ? JSON.parse(item) : initialValue;
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
console.warn(`Error reading localStorage key "${key}":`, error);
|
|
10
|
+
return initialValue;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const setValue = (value) => {
|
|
14
|
+
try {
|
|
15
|
+
const valueToStore = value instanceof Function ? value(storedValue) : value;
|
|
16
|
+
setStoredValue(valueToStore);
|
|
17
|
+
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.warn(`Error setting localStorage key "${key}":`, error);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
return [storedValue, setValue];
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useProfile } from './useProfile';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useProfile } from './useProfile';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useWidget } from '@rango-dev/widget-embedded';
|
|
2
|
+
import { BLOCKCHAINS_THAT_SUPPORT_PROFILE, WALLETS_WITHOUT_SIGN_MESSAGE_METHOD, } from './useProfile.constants';
|
|
3
|
+
import { hashAccount } from './useProfile.helpers';
|
|
4
|
+
export function useProfile(params) {
|
|
5
|
+
const { wallets: { details: walletsDetails }, } = useWidget();
|
|
6
|
+
const hashedAddedAccounts = new Set(params?.addedAccounts?.map(hashAccount));
|
|
7
|
+
const compatibleAccounts = walletsDetails
|
|
8
|
+
.filter((walletDetail) => BLOCKCHAINS_THAT_SUPPORT_PROFILE.includes(walletDetail.chain) &&
|
|
9
|
+
!WALLETS_WITHOUT_SIGN_MESSAGE_METHOD.includes(walletDetail.walletType) &&
|
|
10
|
+
!hashedAddedAccounts.has(hashAccount({ blockchain: walletDetail.chain, address: walletDetail.address })))
|
|
11
|
+
.map((walletDetail) => ({
|
|
12
|
+
address: walletDetail.address,
|
|
13
|
+
blockchain: walletDetail.chain,
|
|
14
|
+
walletType: walletDetail.walletType,
|
|
15
|
+
}));
|
|
16
|
+
return {
|
|
17
|
+
compatibleAccounts: compatibleAccounts ?? [],
|
|
18
|
+
readyToSign: !!compatibleAccounts?.length,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type StackItem = {
|
|
3
|
+
id: string;
|
|
4
|
+
renderContent: (index: number) => React.ReactNode;
|
|
5
|
+
onExit?: () => void;
|
|
6
|
+
};
|
|
7
|
+
type StackModalContextType = {
|
|
8
|
+
stack: StackItem[];
|
|
9
|
+
setStack: (items: StackItem[] | ((prev: StackItem[]) => StackItem[])) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare const MAX_STACK_SIZE = 10;
|
|
12
|
+
export declare const StackModalContext: React.Context<StackModalContextType>;
|
|
13
|
+
export declare const StackModalContextProvider: ({ children }: {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
/**
|
|
17
|
+
* Hook for managing a stack of modals
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const { push, pop, stack } = useStackModal();
|
|
22
|
+
*
|
|
23
|
+
* const openModal = () => {
|
|
24
|
+
* push({
|
|
25
|
+
* id: 'my-modal',
|
|
26
|
+
* renderContent: (index) => <MyModal index={index} />,
|
|
27
|
+
* onExit: () => console.log('Modal closed')
|
|
28
|
+
* });
|
|
29
|
+
* };
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function useStackModal(): {
|
|
33
|
+
stack: StackItem[];
|
|
34
|
+
push: (item: StackItem) => void;
|
|
35
|
+
pop: (count?: number) => void;
|
|
36
|
+
clear: () => void;
|
|
37
|
+
};
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useMemo, useState } from 'react';
|
|
3
|
+
export const MAX_STACK_SIZE = 10;
|
|
4
|
+
export const StackModalContext = createContext({
|
|
5
|
+
stack: [],
|
|
6
|
+
setStack: () => { },
|
|
7
|
+
});
|
|
8
|
+
export const StackModalContextProvider = ({ children }) => {
|
|
9
|
+
const [stack, setStack] = useState([]);
|
|
10
|
+
const contextValue = useMemo(() => ({
|
|
11
|
+
stack,
|
|
12
|
+
setStack,
|
|
13
|
+
}), [stack]);
|
|
14
|
+
return _jsx(StackModalContext.Provider, { value: contextValue, children: children });
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Hook for managing a stack of modals
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const { push, pop, stack } = useStackModal();
|
|
22
|
+
*
|
|
23
|
+
* const openModal = () => {
|
|
24
|
+
* push({
|
|
25
|
+
* id: 'my-modal',
|
|
26
|
+
* renderContent: (index) => <MyModal index={index} />,
|
|
27
|
+
* onExit: () => console.log('Modal closed')
|
|
28
|
+
* });
|
|
29
|
+
* };
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function useStackModal() {
|
|
33
|
+
const context = useContext(StackModalContext);
|
|
34
|
+
if (!context) {
|
|
35
|
+
throw new Error('useStackModal must be used within a StackModalContextProvider');
|
|
36
|
+
}
|
|
37
|
+
const { stack, setStack } = context;
|
|
38
|
+
const push = useCallback((item) => {
|
|
39
|
+
if (stack.length >= MAX_STACK_SIZE) {
|
|
40
|
+
throw new Error('Stack size exceeded');
|
|
41
|
+
}
|
|
42
|
+
setStack((prevStack) => prevStack.concat(item));
|
|
43
|
+
}, [setStack]);
|
|
44
|
+
const pop = useCallback((count = 1) => {
|
|
45
|
+
setStack((prevStack) => {
|
|
46
|
+
if (prevStack.length === 0) {
|
|
47
|
+
return prevStack;
|
|
48
|
+
}
|
|
49
|
+
return prevStack.slice(0, Math.max(prevStack.length - count));
|
|
50
|
+
});
|
|
51
|
+
}, [setStack]);
|
|
52
|
+
const clear = useCallback(() => {
|
|
53
|
+
setStack([]);
|
|
54
|
+
}, [setStack]);
|
|
55
|
+
return {
|
|
56
|
+
stack,
|
|
57
|
+
push,
|
|
58
|
+
pop,
|
|
59
|
+
clear,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UseStatefulConnect } from '@rango-dev/widget-embedded';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export declare const StatefulConnectContext: React.Context<UseStatefulConnect | null>;
|
|
4
|
+
export declare const StatefulConnectContextProvider: ({ children }: {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare const useStatefulConnect: () => UseStatefulConnect;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useStatefulConnect as widgetUseStatefulConnect } from '@rango-dev/widget-embedded';
|
|
3
|
+
import { createContext, useContext } from 'react';
|
|
4
|
+
export const StatefulConnectContext = createContext(null);
|
|
5
|
+
export const StatefulConnectContextProvider = ({ children }) => {
|
|
6
|
+
const statefulConnect = widgetUseStatefulConnect();
|
|
7
|
+
return (_jsx(StatefulConnectContext.Provider, { value: statefulConnect, children: children }));
|
|
8
|
+
};
|
|
9
|
+
export const useStatefulConnect = () => {
|
|
10
|
+
const context = useContext(StatefulConnectContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('useStatefulConnect must be used within a StatefulConnectContextProvider');
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
};
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { initializeFetcher } from './fetcher';
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { initializeFetcher } from './fetcher';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function getProfileType(isPublic: boolean): 'public' | 'private';
|
|
2
|
+
export declare function throwIfAborted(signal: AbortSignal): void;
|
|
3
|
+
export declare function getErrorMessage(error: unknown): string;
|
|
4
|
+
export declare function loadState<T>(key: string): T | undefined;
|
|
5
|
+
export declare function saveState(key: string, state: unknown): void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function getProfileType(isPublic) {
|
|
2
|
+
return isPublic ? 'public' : 'private';
|
|
3
|
+
}
|
|
4
|
+
// These functions have been copy/pasted from `apps/rango/utils/Errors.ts` to avoid creating a third package to share these logic.
|
|
5
|
+
export function throwIfAborted(signal) {
|
|
6
|
+
if (signal.aborted) {
|
|
7
|
+
throw new Error('Operation canceled');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function getErrorMessage(error) {
|
|
11
|
+
return error instanceof Error ? error.message : 'Something went wrong. Please try again.';
|
|
12
|
+
}
|
|
13
|
+
export function loadState(key) {
|
|
14
|
+
// For avoiding run in SSR
|
|
15
|
+
if (typeof window === 'undefined') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const serializedState = localStorage.getItem(key);
|
|
20
|
+
if (serializedState === null) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return JSON.parse(serializedState);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
console.error('Could not load state', err);
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function saveState(key, state) {
|
|
31
|
+
// For avoiding run in SSR
|
|
32
|
+
if (typeof window === 'undefined') {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const serializedState = JSON.stringify(state);
|
|
37
|
+
localStorage.setItem(key, serializedState);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
console.error('Could not save state', err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RootStateLike } from './slice';
|
|
2
|
+
import type { Middleware } from '@reduxjs/toolkit';
|
|
3
|
+
export declare const AUTH_PERSIST_KEY = "isLoggedIn";
|
|
4
|
+
export declare const PROFILE_PERSIST_KEY = "profile";
|
|
5
|
+
export declare const loadPersistedState: () => Partial<RootStateLike>;
|
|
6
|
+
export declare const persistProfileState: Middleware<object, RootStateLike>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { loadState, saveState } from './helpers';
|
|
2
|
+
import { profileSliceInitialState } from './slice';
|
|
3
|
+
import { createFetchProfileSummary, createRequestLogOutUser, createSignMessage } from './thunks';
|
|
4
|
+
const signMessage = createSignMessage();
|
|
5
|
+
const fetchProfileSummary = createFetchProfileSummary();
|
|
6
|
+
const requestLogOutUser = createRequestLogOutUser();
|
|
7
|
+
export const AUTH_PERSIST_KEY = 'isLoggedIn';
|
|
8
|
+
export const PROFILE_PERSIST_KEY = 'profile';
|
|
9
|
+
export const loadPersistedState = () => {
|
|
10
|
+
const initialState = { ...profileSliceInitialState };
|
|
11
|
+
const authState = loadState(AUTH_PERSIST_KEY);
|
|
12
|
+
const profileDataState = loadState(PROFILE_PERSIST_KEY);
|
|
13
|
+
if (authState) {
|
|
14
|
+
initialState.isLoggedIn = authState;
|
|
15
|
+
}
|
|
16
|
+
if (profileDataState?.username) {
|
|
17
|
+
initialState.username = profileDataState.username;
|
|
18
|
+
}
|
|
19
|
+
return { profile: initialState };
|
|
20
|
+
};
|
|
21
|
+
export const persistProfileState = (store) => (next) => (action) => {
|
|
22
|
+
const prevState = store.getState();
|
|
23
|
+
const returnValue = next(action);
|
|
24
|
+
const nextState = store.getState();
|
|
25
|
+
const shouldPersistAuthState = prevState.profile.isLoggedIn !== nextState.profile.isLoggedIn;
|
|
26
|
+
const shouldPersistProfileData =
|
|
27
|
+
// @ts-expect-error to have correct type for action.meta, instead of `action: ProfileSliceActions` we need to have access full store's actions. specificly meta slice.
|
|
28
|
+
(fetchProfileSummary.fulfilled.match(action) && !action.meta.arg.public) ||
|
|
29
|
+
signMessage.fulfilled.match(action) ||
|
|
30
|
+
requestLogOutUser.fulfilled.match(action);
|
|
31
|
+
if (shouldPersistAuthState) {
|
|
32
|
+
const state = store.getState().profile.isLoggedIn;
|
|
33
|
+
saveState(AUTH_PERSIST_KEY, state);
|
|
34
|
+
}
|
|
35
|
+
if (shouldPersistProfileData) {
|
|
36
|
+
const username = store.getState().profile.profileSummary.private.data?.username;
|
|
37
|
+
saveState(PROFILE_PERSIST_KEY, { username });
|
|
38
|
+
}
|
|
39
|
+
return returnValue;
|
|
40
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { profileSliceInitialState, createProfileState } from './slice';
|
|
2
|
+
export { showPrivateProfileSelector, profileSummarySelector, authenticatedProfileSelector, privateProfileSummarySelector, isLoggedInProfileSelector, usernameProfileSelector, } from './selectors';
|
|
3
|
+
export type { SignMessageParams, ProfileState } from './types';
|
|
4
|
+
export { persistProfileState, loadPersistedState, AUTH_PERSIST_KEY, PROFILE_PERSIST_KEY, } from './middlewares';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { profileSliceInitialState, createProfileState } from './slice';
|
|
2
|
+
export { showPrivateProfileSelector, profileSummarySelector, authenticatedProfileSelector, privateProfileSummarySelector, isLoggedInProfileSelector, usernameProfileSelector, } from './selectors';
|
|
3
|
+
export { persistProfileState, loadPersistedState, AUTH_PERSIST_KEY, PROFILE_PERSIST_KEY, } from './middlewares';
|