Skip to content

Commit 0b18bb1

Browse files
authored
fix(clerk-js,types,localizations): Allow user set primary web3 wallet in <UserProfile /> (#5353)
1 parent f8829c9 commit 0b18bb1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+319
-14
lines changed

.changeset/strong-chefs-travel.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clerk/localizations': minor
3+
'@clerk/clerk-js': minor
4+
'@clerk/types': minor
5+
---
6+
7+
Allow user set primary web3 wallet in `<UserProfile />` when more than one web3 wallets presented

packages/clerk-js/src/ui/components/UserProfile/Web3Section.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useUser } from '@clerk/shared/react';
1+
import { useReverification, useUser } from '@clerk/shared/react';
22
import { Fragment, useState } from 'react';
33

44
import { Badge, Box, Flex, Image, localizationKeys, Text } from '../../customizables';
@@ -7,7 +7,9 @@ import { Action } from '../../elements/Action';
77
import { useActionContext } from '../../elements/Action/ActionRoot';
88
import { useEnabledThirdPartyProviders } from '../../hooks';
99
import type { PropsOfComponent } from '../../styledSystem';
10+
import { handleError } from '../../utils';
1011
import { RemoveWeb3WalletForm } from './RemoveResourceForm';
12+
import { sortIdentificationBasedOnVerification } from './utils';
1113
import { AddWeb3WalletActionMenu } from './Web3Form';
1214

1315
type RemoveWeb3WalletScreenProps = { walletId: string };
@@ -44,6 +46,7 @@ export const Web3Section = withCardStateProvider(
4446
return (
4547
<ProfileSection.Root
4648
title={localizationKeys('userProfile.start.web3WalletsSection.title')}
49+
centered={false}
4750
id='web3Wallets'
4851
>
4952
<Card.Alert>{card.error}</Card.Alert>
@@ -52,7 +55,7 @@ export const Web3Section = withCardStateProvider(
5255
onChange={setActionValue}
5356
>
5457
<ProfileSection.ItemList id='web3Wallets'>
55-
{user?.web3Wallets.map(wallet => {
58+
{sortIdentificationBasedOnVerification(user?.web3Wallets, user?.primaryWeb3WalletId).map(wallet => {
5659
const strategy = wallet.verification.strategy as keyof typeof strategyToDisplayData;
5760
const walletId = wallet.id;
5861
return (
@@ -109,12 +112,27 @@ export const Web3Section = withCardStateProvider(
109112
);
110113

111114
const Web3WalletMenu = ({ walletId }: { walletId: string }) => {
115+
const card = useCardState();
112116
const { open } = useActionContext();
117+
const { user } = useUser();
118+
const isPrimary = user?.primaryWeb3WalletId === walletId;
119+
const [setPrimary] = useReverification(() => {
120+
return user?.update({ primaryWeb3WalletId: walletId });
121+
});
113122

114123
const actions = (
115124
[
125+
!isPrimary
126+
? {
127+
label: localizationKeys('userProfile.start.web3WalletsSection.detailsAction__nonPrimary'),
128+
onClick: () => {
129+
setPrimary().catch(e => handleError(e, [], card.setError));
130+
},
131+
}
132+
: null,
116133
{
117134
label: localizationKeys('userProfile.start.web3WalletsSection.destructiveAction'),
135+
isDestructive: true,
118136
onClick: () => open(`remove-${walletId}`),
119137
},
120138
] satisfies (PropsOfComponent<typeof ThreeDotsMenu>['actions'][0] | null)[]

packages/clerk-js/src/ui/components/UserProfile/utils.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import type { Attributes, EmailAddressResource, PhoneNumberResource, UserResource } from '@clerk/types';
1+
import type {
2+
Attributes,
3+
EmailAddressResource,
4+
PhoneNumberResource,
5+
UserResource,
6+
Web3WalletResource,
7+
} from '@clerk/types';
28

39
type IDable = { id: string };
410

@@ -38,10 +44,9 @@ export function getSecondFactorsAvailableToAdd(attributes: Attributes, user: Use
3844
return sfs;
3945
}
4046

41-
export function sortIdentificationBasedOnVerification<T extends Array<EmailAddressResource | PhoneNumberResource>>(
42-
array: T | null | undefined,
43-
primaryId: string | null | undefined,
44-
): T {
47+
export function sortIdentificationBasedOnVerification<
48+
T extends Array<EmailAddressResource | PhoneNumberResource | Web3WalletResource>,
49+
>(array: T | null | undefined, primaryId: string | null | undefined): T {
4550
if (!array) {
4651
return [] as unknown as T;
4752
}

packages/localizations/src/ar-SA.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ export const arSA: LocalizationResource = {
285285
actionText: undefined,
286286
blockButton__backupCode: undefined,
287287
blockButton__emailCode: undefined,
288+
blockButton__passkey: undefined,
288289
blockButton__password: undefined,
289290
blockButton__phoneCode: undefined,
290291
blockButton__totp: undefined,
@@ -311,6 +312,11 @@ export const arSA: LocalizationResource = {
311312
subtitle: undefined,
312313
title: undefined,
313314
},
315+
passkey: {
316+
blockButton__passkey: undefined,
317+
subtitle: undefined,
318+
title: undefined,
319+
},
314320
password: {
315321
actionLink: undefined,
316322
subtitle: undefined,
@@ -908,6 +914,7 @@ export const arSA: LocalizationResource = {
908914
},
909915
web3WalletsSection: {
910916
destructiveAction: 'حذف المحفظة',
917+
detailsAction__nonPrimary: undefined,
911918
primaryButton: 'محافظ Web3',
912919
title: 'محافظ Web3',
913920
},

packages/localizations/src/be-BY.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ export const beBY: LocalizationResource = {
291291
actionText: 'Паспрабуйце іншы метад для верыфікацыі.',
292292
blockButton__backupCode: 'Увядзіце код з рэзервовага кода',
293293
blockButton__emailCode: 'Увядзіце код, адправлены на электронную пошту',
294+
blockButton__passkey: undefined,
294295
blockButton__password: 'Увядзіце пароль',
295296
blockButton__phoneCode: 'Увядзіце код, адправлены на тэлефон',
296297
blockButton__totp: 'Выкарыстайце TOTP',
@@ -317,6 +318,11 @@ export const beBY: LocalizationResource = {
317318
subtitle: 'Калі ласка, выберыце іншы метад або звярніцеся ў службу падтрымкі.',
318319
title: 'Няма даступных метадаў верыфікацыі',
319320
},
321+
passkey: {
322+
blockButton__passkey: undefined,
323+
subtitle: undefined,
324+
title: undefined,
325+
},
320326
password: {
321327
actionLink: 'Вярнуцца да ўводу пароля',
322328
subtitle: 'Калі вы памятаеце свой пароль, вы можаце ўвесці яго для завершэння верыфікацыі.',
@@ -923,6 +929,7 @@ export const beBY: LocalizationResource = {
923929
},
924930
web3WalletsSection: {
925931
destructiveAction: 'Выдаліць кашалёк',
932+
detailsAction__nonPrimary: undefined,
926933
primaryButton: 'Web3 кашалькі',
927934
title: 'Web3 кашалькі',
928935
},

packages/localizations/src/bg-BG.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ export const bgBG: LocalizationResource = {
287287
actionText: "Don't have one of these?",
288288
blockButton__backupCode: 'Use backup code',
289289
blockButton__emailCode: 'Send code to email',
290+
blockButton__passkey: undefined,
290291
blockButton__password: 'Login with password',
291292
blockButton__phoneCode: 'Send code to phone',
292293
blockButton__totp: 'Use authenticator app',
@@ -313,6 +314,11 @@ export const bgBG: LocalizationResource = {
313314
subtitle: 'Something went wrong.',
314315
title: 'Authentication failed',
315316
},
317+
passkey: {
318+
blockButton__passkey: undefined,
319+
subtitle: undefined,
320+
title: undefined,
321+
},
316322
password: {
317323
actionLink: 'Use another method',
318324
subtitle: 'Enter your password to continue using "{{applicationName}}"',
@@ -913,6 +919,7 @@ export const bgBG: LocalizationResource = {
913919
},
914920
web3WalletsSection: {
915921
destructiveAction: 'Премахни портфейл',
922+
detailsAction__nonPrimary: undefined,
916923
primaryButton: 'Web3 портфейли',
917924
title: 'Web3 портфейли',
918925
},

packages/localizations/src/ca-ES.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ export const caES: LocalizationResource = {
287287
actionText: undefined,
288288
blockButton__backupCode: undefined,
289289
blockButton__emailCode: undefined,
290+
blockButton__passkey: undefined,
290291
blockButton__password: undefined,
291292
blockButton__phoneCode: undefined,
292293
blockButton__totp: undefined,
@@ -313,6 +314,11 @@ export const caES: LocalizationResource = {
313314
subtitle: undefined,
314315
title: undefined,
315316
},
317+
passkey: {
318+
blockButton__passkey: undefined,
319+
subtitle: undefined,
320+
title: undefined,
321+
},
316322
password: {
317323
actionLink: undefined,
318324
subtitle: undefined,
@@ -920,6 +926,7 @@ export const caES: LocalizationResource = {
920926
},
921927
web3WalletsSection: {
922928
destructiveAction: 'Elimina cartera',
929+
detailsAction__nonPrimary: undefined,
923930
primaryButton: 'Carteres Web3',
924931
title: 'Carteres Web3',
925932
},

packages/localizations/src/cs-CZ.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ export const csCZ: LocalizationResource = {
286286
actionText: undefined,
287287
blockButton__backupCode: undefined,
288288
blockButton__emailCode: undefined,
289+
blockButton__passkey: undefined,
289290
blockButton__password: undefined,
290291
blockButton__phoneCode: undefined,
291292
blockButton__totp: undefined,
@@ -312,6 +313,11 @@ export const csCZ: LocalizationResource = {
312313
subtitle: undefined,
313314
title: undefined,
314315
},
316+
passkey: {
317+
blockButton__passkey: undefined,
318+
subtitle: undefined,
319+
title: undefined,
320+
},
315321
password: {
316322
actionLink: undefined,
317323
subtitle: undefined,
@@ -911,6 +917,7 @@ export const csCZ: LocalizationResource = {
911917
},
912918
web3WalletsSection: {
913919
destructiveAction: 'Odstranit peněženku',
920+
detailsAction__nonPrimary: undefined,
914921
primaryButton: 'Web3 peněženky',
915922
title: 'Web3 peněženky',
916923
},

packages/localizations/src/da-DK.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ export const daDK: LocalizationResource = {
287287
actionText: undefined,
288288
blockButton__backupCode: undefined,
289289
blockButton__emailCode: undefined,
290+
blockButton__passkey: undefined,
290291
blockButton__password: undefined,
291292
blockButton__phoneCode: undefined,
292293
blockButton__totp: undefined,
@@ -313,6 +314,11 @@ export const daDK: LocalizationResource = {
313314
subtitle: undefined,
314315
title: undefined,
315316
},
317+
passkey: {
318+
blockButton__passkey: undefined,
319+
subtitle: undefined,
320+
title: undefined,
321+
},
316322
password: {
317323
actionLink: undefined,
318324
subtitle: undefined,
@@ -913,6 +919,7 @@ export const daDK: LocalizationResource = {
913919
},
914920
web3WalletsSection: {
915921
destructiveAction: 'Fjern tegnebog',
922+
detailsAction__nonPrimary: undefined,
916923
primaryButton: 'Tilføj Web3 tegnebøger',
917924
title: 'Web3 tegnebøger',
918925
},

packages/localizations/src/de-DE.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ export const deDE: LocalizationResource = {
290290
actionText: 'Verwenden Sie eine alternative Verifizierungsmethode',
291291
blockButton__backupCode: 'Mit Backup-Code verifizieren',
292292
blockButton__emailCode: 'Mit E-Mail-Code verifizieren',
293+
blockButton__passkey: undefined,
293294
blockButton__password: 'Mit Passwort verifizieren',
294295
blockButton__phoneCode: 'Mit SMS-Code verifizieren',
295296
blockButton__totp: 'Mit TOTP verifizieren',
@@ -316,6 +317,11 @@ export const deDE: LocalizationResource = {
316317
subtitle: 'Bitte kontaktieren Sie den Support, um Hilfe zu erhalten.',
317318
title: 'Keine verfügbaren Methoden',
318319
},
320+
passkey: {
321+
blockButton__passkey: undefined,
322+
subtitle: undefined,
323+
title: undefined,
324+
},
319325
password: {
320326
actionLink: 'Passwort zurücksetzen',
321327
subtitle: 'Geben Sie Ihr Passwort ein, um fortzufahren.',
@@ -928,6 +934,7 @@ export const deDE: LocalizationResource = {
928934
},
929935
web3WalletsSection: {
930936
destructiveAction: 'Wallet entfernen',
937+
detailsAction__nonPrimary: undefined,
931938
primaryButton: 'Web3-Wallets',
932939
title: 'Web3-Wallets',
933940
},

0 commit comments

Comments
 (0)