1- import { useUser } from '@clerk/shared/react' ;
1+ import { useReverification , useUser } from '@clerk/shared/react' ;
22import { Fragment , useState } from 'react' ;
33
44import { Badge , Box , Flex , Image , localizationKeys , Text } from '../../customizables' ;
@@ -7,7 +7,9 @@ import { Action } from '../../elements/Action';
77import { useActionContext } from '../../elements/Action/ActionRoot' ;
88import { useEnabledThirdPartyProviders } from '../../hooks' ;
99import type { PropsOfComponent } from '../../styledSystem' ;
10+ import { handleError } from '../../utils' ;
1011import { RemoveWeb3WalletForm } from './RemoveResourceForm' ;
12+ import { sortIdentificationBasedOnVerification } from './utils' ;
1113import { AddWeb3WalletActionMenu } from './Web3Form' ;
1214
1315type 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
111114const 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 ) [ ]
0 commit comments