Skip to content

Commit 4bcc8b6

Browse files
authored
fix(clerk-js): Update error handling and adjust Web3WalletMenu logic with verification status (#7489)
Signed-off-by: Kenton Duprey <[email protected]>
1 parent 4f90ce0 commit 4bcc8b6

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
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/clerk-js/src/ui/components/UserProfile/Web3Form.tsx

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { Action } from '@/ui/elements/Action';
66
import { useActionContext } from '@/ui/elements/Action/ActionRoot';
77
import { useCardState } from '@/ui/elements/contexts';
88
import { ProfileSection } from '@/ui/elements/Section';
9-
import { getFieldError, handleError } from '@/ui/utils/errorHandler';
9+
import { web3CallbackErrorHandler } from '@/ui/utils/web3CallbackErrorHandler';
1010

1111
import { generateWeb3Signature, getWeb3Identifier } from '../../../utils/web3';
12-
import { descriptors, Image, localizationKeys, Text } from '../../customizables';
12+
import { descriptors, Image, localizationKeys } from '../../customizables';
1313
import { useEnabledThirdPartyProviders } from '../../hooks';
1414

1515
export const AddWeb3WalletActionMenu = () => {
@@ -60,12 +60,7 @@ export const AddWeb3WalletActionMenu = () => {
6060
card.setIdle();
6161
} catch (err) {
6262
card.setIdle();
63-
const fieldError = getFieldError(err);
64-
if (fieldError) {
65-
card.setError(fieldError.longMessage);
66-
} else {
67-
handleError(err, [], card.setError);
68-
}
63+
web3CallbackErrorHandler(err, card.setError);
6964
}
7065
};
7166

@@ -110,18 +105,6 @@ export const AddWeb3WalletActionMenu = () => {
110105
<Web3SelectSolanaWalletScreen onConnect={connect} />
111106
</Action.Card>
112107
</Action.Open>
113-
114-
{card.error && (
115-
<Text
116-
colorScheme='danger'
117-
sx={t => ({
118-
padding: t.sizes.$1x5,
119-
paddingLeft: t.sizes.$8x5,
120-
})}
121-
>
122-
{card.error}
123-
</Text>
124-
)}
125108
</>
126109
);
127110
};

packages/clerk-js/src/ui/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/clerk-js/src/ui/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)