Skip to content

Commit f88c5f8

Browse files
committed
Skeleton loader added to Unlock Profile
1 parent d078568 commit f88c5f8

File tree

2 files changed

+144
-48
lines changed

2 files changed

+144
-48
lines changed

src/components/chat/unlockProfile/UnlockProfile.tsx

Lines changed: 117 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { useContext, useEffect, useState } from 'react';
55
import styled, { useTheme } from 'styled-components';
66

77
// Internal Compoonents
8-
import { ButtonV2, ImageV2, ItemHV2, ItemVV2, SpanV2 } from 'components/reusables/SharedStylingV2';
8+
import { ButtonV2, ImageV2, ItemHV2, ItemVV2, Skeleton, SkeletonLine, SpanV2 } from 'components/reusables/SharedStylingV2';
99
import { AppContext } from 'contexts/AppContext';
1010
import { useAccount, useDeviceWidthCheck } from 'hooks';
11+
import { retrieveUserPGPKeyFromStorage } from 'helpers/connectWalletHelper';
1112

1213
// Internal Configs
1314
import { device, size } from 'config/Globals';
@@ -74,6 +75,19 @@ const UnlockProfile = ({ InnerComponentProps, onClose }: UnlockProfileModalProps
7475

7576
const isMobile = useDeviceWidthCheck(parseInt(size.tablet));
7677

78+
const [isLoading, setIsLoading] = useState(false);
79+
80+
useEffect(() => {
81+
if (wallet?.accounts?.length > 0) {
82+
const decryptedPGPKeys = retrieveUserPGPKeyFromStorage(account);
83+
console.log("decryptedPGPKeys", decryptedPGPKeys);
84+
if (decryptedPGPKeys) {
85+
setIsLoading(true);
86+
}
87+
}
88+
89+
}, [account])
90+
7791
return (
7892
<Container type={type}>
7993
<SubContainer type={type}>
@@ -92,22 +106,45 @@ const UnlockProfile = ({ InnerComponentProps, onClose }: UnlockProfileModalProps
92106
/>
93107

94108
<ItemVV2 alignItems={type === UNLOCK_PROFILE_TYPE.MODAL || isMobile ? 'center' : 'baseline'}>
95-
<SpanV2
96-
fontSize="24px"
97-
fontWeight="500"
98-
lineHeight="28.8px"
99-
color={theme.default.color}
100-
>
101-
{activeStatus.title}
102-
</SpanV2>
103-
<SpanV2
104-
fontSize={type === UNLOCK_PROFILE_TYPE.MODAL || isMobile ? '16px' : '18px'}
105-
fontWeight="400"
106-
lineHeight="22.4px"
107-
color={theme.default.secondaryColor}
108-
>
109-
{activeStatus.body}
110-
</SpanV2>
109+
110+
{!isLoading ? (
111+
<>
112+
<SpanV2
113+
fontSize="24px"
114+
fontWeight="500"
115+
lineHeight="28.8px"
116+
color={theme.default.color}
117+
>
118+
{activeStatus.title}
119+
</SpanV2>
120+
<SpanV2
121+
fontSize={type === UNLOCK_PROFILE_TYPE.MODAL || isMobile ? '16px' : '18px'}
122+
fontWeight="400"
123+
lineHeight="22.4px"
124+
color={theme.default.secondaryColor}
125+
>
126+
{activeStatus.body}
127+
</SpanV2>
128+
</>
129+
) : (
130+
<SkeletonWrapper>
131+
<SkeletonLine
132+
height="24px"
133+
width='100%'
134+
margin="0 0 8px 0"
135+
borderRadius='4px'
136+
></SkeletonLine>
137+
138+
<SkeletonLine
139+
height="16px"
140+
width='100%'
141+
margin="0 0 8px 0"
142+
borderRadius='4px'
143+
></SkeletonLine>
144+
145+
</SkeletonWrapper>
146+
)}
147+
111148
</ItemVV2>
112149
</ItemHV2>
113150

@@ -150,23 +187,43 @@ const UnlockProfile = ({ InnerComponentProps, onClose }: UnlockProfileModalProps
150187
alignItems="baseline"
151188
flexDirection={type === UNLOCK_PROFILE_TYPE.MODAL || isMobile ? 'column' : 'row'}
152189
>
153-
<DefaultButton
154-
activeStatus={activeStatus.status}
155-
status={PROFILESTATE.CONNECT_WALLET}
156-
disabled={activeStatus.status !== PROFILESTATE.CONNECT_WALLET && true}
157-
onClick={() => connectWallet()}
158-
>
159-
Connect Wallet
160-
</DefaultButton>
161-
162-
<DefaultButton
163-
activeStatus={activeStatus.status}
164-
status={PROFILESTATE.UNLOCK_PROFILE}
165-
disabled={activeStatus.status === PROFILESTATE.CONNECT_WALLET && true}
166-
onClick={handleChatprofileUnlock}
167-
>
168-
Unlock Profile
169-
</DefaultButton>
190+
191+
{!isLoading ? (
192+
<>
193+
<DefaultButton
194+
activeStatus={activeStatus.status}
195+
status={PROFILESTATE.CONNECT_WALLET}
196+
disabled={activeStatus.status !== PROFILESTATE.CONNECT_WALLET && true}
197+
onClick={() => connectWallet()}
198+
>
199+
Connect Wallet
200+
</DefaultButton>
201+
202+
<DefaultButton
203+
activeStatus={activeStatus.status}
204+
status={PROFILESTATE.UNLOCK_PROFILE}
205+
disabled={activeStatus.status === PROFILESTATE.CONNECT_WALLET && true}
206+
onClick={handleChatprofileUnlock}
207+
>
208+
Unlock Profile
209+
</DefaultButton>
210+
</>
211+
) : (
212+
<SkeletonContainer
213+
width="100%"
214+
flexDirection={type === UNLOCK_PROFILE_TYPE.MODAL || isMobile ? 'column' : 'row'}
215+
>
216+
<SkeletonLine
217+
height="40px"
218+
width="150px"
219+
></SkeletonLine>
220+
<SkeletonLine
221+
height="40px"
222+
width="150px"
223+
></SkeletonLine>
224+
</SkeletonContainer>
225+
226+
)}
170227
</ItemHV2>
171228
</ItemVV2>
172229
</SubContainer>
@@ -209,21 +266,21 @@ const RenderToolTip = ({ children, type }) => {
209266
placementProps={
210267
type === UNLOCK_PROFILE_TYPE.MODAL
211268
? {
212-
background: 'black',
213-
width: '220px',
214-
padding: '8px 12px',
215-
top: '10px',
216-
left: '60px',
217-
borderRadius: '4px 12px 12px 12px',
218-
}
269+
background: 'black',
270+
width: '220px',
271+
padding: '8px 12px',
272+
top: '10px',
273+
left: '60px',
274+
borderRadius: '4px 12px 12px 12px',
275+
}
219276
: {
220-
background: 'black',
221-
width: '120px',
222-
padding: '8px 12px',
223-
bottom: '0px',
224-
right: '-30px',
225-
borderRadius: '12px 12px 12px 4px',
226-
}
277+
background: 'black',
278+
width: '120px',
279+
padding: '8px 12px',
280+
bottom: '0px',
281+
right: '-30px',
282+
borderRadius: '12px 12px 12px 4px',
283+
}
227284
}
228285
tooltipContent={
229286
<SpanV2
@@ -318,4 +375,16 @@ const DefaultButton = styled(ButtonV2)`
318375
cursor: ${(props) => (props.activeStatus !== props.status ? 'not-allowed' : 'pointer')};
319376
`;
320377

378+
const SkeletonWrapper = styled.div`
379+
overflow: hidden;
380+
min-width:220px;
381+
`;
382+
383+
const SkeletonContainer = styled(Skeleton)`
384+
max-width: -webkit-fill-available;
385+
border-radius: 5px;
386+
gap: 16px;
387+
display: flex;
388+
`;
389+
321390
export default UnlockProfile;

src/helpers/connectWalletHelper.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as w2wHelper from 'helpers/w2w';
2+
3+
export const retrieveUserPGPKeyFromStorage = (account: string) => {
4+
const key = getUniquePGPKey(account);
5+
const value = localStorage.getItem(key);
6+
7+
if (isPGPKey(value)) {
8+
return value;
9+
}
10+
11+
return null;
12+
};
13+
14+
const isPGPKey = (str: string | null) => {
15+
if (!str) return false;
16+
17+
const pgpPublicKeyRegex = /-----BEGIN PGP PUBLIC KEY BLOCK-----[\s\S]*-----END PGP PUBLIC KEY BLOCK-----/;
18+
const pgpPrivateKeyRegex = /-----BEGIN PGP PRIVATE KEY BLOCK-----[\s\S]*-----END PGP PRIVATE KEY BLOCK-----/;
19+
20+
return pgpPublicKeyRegex.test(str) || pgpPrivateKeyRegex.test(str);
21+
};
22+
23+
const getUniquePGPKey = (account: string) => {
24+
let address = w2wHelper.walletToCAIP10({ account });
25+
const uniqueKey = `push-user-${address}-pgp`;
26+
return uniqueKey;
27+
};

0 commit comments

Comments
 (0)