Skip to content

Commit 323e66d

Browse files
authored
fix(clerk-js): Update error handling, Web3WalletMenu checks verification status, port from core 2 (#7511)
Signed-off-by: Kenton Duprey <[email protected]>
1 parent 2c4ce1a commit 323e66d

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

.changeset/busy-frogs-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Fix Web3 connection error handling in `<UserProfile />`

packages/ui/src/components/UserProfile/Web3Form.tsx

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ import { createWeb3 } from '@clerk/shared/internal/clerk-js/web3';
22
import { useReverification, useUser } from '@clerk/shared/react';
33
import type { Web3Provider, Web3Strategy } from '@clerk/shared/types';
44

5+
import { useModuleManager } from '@/contexts';
6+
import { descriptors, Image, localizationKeys } from '@/customizables';
7+
import { useEnabledThirdPartyProviders } from '@/hooks';
58
import { Web3SelectSolanaWalletScreen } from '@/ui/components/UserProfile/Web3SelectSolanaWalletScreen';
69
import { Action } from '@/ui/elements/Action';
710
import { useActionContext } from '@/ui/elements/Action/ActionRoot';
811
import { useCardState } from '@/ui/elements/contexts';
912
import { ProfileSection } from '@/ui/elements/Section';
10-
import { getFieldError, handleError } from '@/ui/utils/errorHandler';
11-
12-
import { useModuleManager } from '../../contexts';
13-
import { descriptors, Image, localizationKeys, Text } from '../../customizables';
14-
import { useEnabledThirdPartyProviders } from '../../hooks';
13+
import { web3CallbackErrorHandler } from '@/ui/utils/web3CallbackErrorHandler';
1514

1615
export const AddWeb3WalletActionMenu = () => {
1716
const card = useCardState();
@@ -64,12 +63,7 @@ export const AddWeb3WalletActionMenu = () => {
6463
card.setIdle();
6564
} catch (err: any) {
6665
card.setIdle();
67-
const fieldError = getFieldError(err);
68-
if (fieldError) {
69-
card.setError(fieldError.longMessage);
70-
} else {
71-
handleError(err, [], card.setError);
72-
}
66+
web3CallbackErrorHandler(err, card.setError);
7367
}
7468
};
7569

@@ -116,18 +110,6 @@ export const AddWeb3WalletActionMenu = () => {
116110
<Web3SelectSolanaWalletScreen onConnect={connect} />
117111
</Action.Card>
118112
</Action.Open>
119-
120-
{card.error && (
121-
<Text
122-
colorScheme='danger'
123-
sx={t => ({
124-
padding: t.sizes.$1x5,
125-
paddingLeft: t.sizes.$8x5,
126-
})}
127-
>
128-
{card.error}
129-
</Text>
130-
)}
131113
</>
132114
);
133115
};

packages/ui/src/components/UserProfile/Web3Section.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ export const Web3Section = withCardStateProvider(
9595
</Flex>
9696
</Box>
9797
</Flex>
98-
<Web3WalletMenu walletId={walletId} />
98+
<Web3WalletMenu
99+
walletId={walletId}
100+
isVerified={wallet.verification.status === 'verified'}
101+
/>
99102
</ProfileSection.Item>
100103

101104
<Action.Open value={`remove-${walletId}`}>
@@ -115,7 +118,7 @@ export const Web3Section = withCardStateProvider(
115118
},
116119
);
117120

118-
const Web3WalletMenu = ({ walletId }: { walletId: string }) => {
121+
const Web3WalletMenu = ({ walletId, isVerified }: { walletId: string; isVerified: boolean }) => {
119122
const card = useCardState();
120123
const { open } = useActionContext();
121124
const { user } = useUser();
@@ -126,7 +129,8 @@ const Web3WalletMenu = ({ walletId }: { walletId: string }) => {
126129

127130
const actions = (
128131
[
129-
!isPrimary
132+
// Only allow setting as primary if the wallet is verified and not already primary
133+
!isPrimary && isVerified
130134
? {
131135
label: localizationKeys('userProfile.start.web3WalletsSection.detailsAction__nonPrimary'),
132136
onClick: () => {

packages/ui/src/components/UserProfile/__tests__/PasswordSection.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ describe('PasswordSection', () => {
139139
updated_at: 123,
140140
logo_public_url: null,
141141
protocol: 'saml',
142+
enterprise_connection_id: 'ent_123',
142143
},
143144
verification: {
144145
status: 'verified',
@@ -155,6 +156,8 @@ describe('PasswordSection', () => {
155156
object: 'verification',
156157
},
157158
id: 'eac_123',
159+
last_authenticated_at: 123,
160+
enterprise_connection_id: 'ent_123',
158161
},
159162
],
160163
});
@@ -212,6 +215,7 @@ describe('PasswordSection', () => {
212215
updated_at: 123,
213216
logo_public_url: null,
214217
protocol: 'saml',
218+
enterprise_connection_id: null,
215219
},
216220
verification: {
217221
status: 'verified',
@@ -228,6 +232,8 @@ describe('PasswordSection', () => {
228232
object: 'verification',
229233
},
230234
id: 'eac_123',
235+
last_authenticated_at: null,
236+
enterprise_connection_id: null,
231237
},
232238
],
233239
});
@@ -378,6 +384,7 @@ describe('PasswordSection', () => {
378384
updated_at: 123,
379385
logo_public_url: null,
380386
protocol: 'saml',
387+
enterprise_connection_id: null,
381388
},
382389
verification: {
383390
status: 'verified',
@@ -394,6 +401,8 @@ describe('PasswordSection', () => {
394401
object: 'verification',
395402
},
396403
id: 'eac_123',
404+
last_authenticated_at: null,
405+
enterprise_connection_id: null,
397406
},
398407
],
399408
});
@@ -452,6 +461,7 @@ describe('PasswordSection', () => {
452461
updated_at: 123,
453462
logo_public_url: null,
454463
protocol: 'saml',
464+
enterprise_connection_id: null,
455465
},
456466
verification: {
457467
status: 'verified',
@@ -468,6 +478,8 @@ describe('PasswordSection', () => {
468478
object: 'verification',
469479
},
470480
id: 'eac_123',
481+
last_authenticated_at: null,
482+
enterprise_connection_id: null,
471483
},
472484
],
473485
});

0 commit comments

Comments
 (0)