11import { useReverification , useUser } from '@clerk/shared/react' ;
22import type { Web3Provider , Web3Strategy } from '@clerk/shared/types' ;
33
4+ import { useWizard , Wizard } from '@/ui/common' ;
5+ import { Web3SelectWalletScreen } from '@/ui/components/UserProfile/Web3SelectWalletScreen' ;
46import { useCardState , withCardStateProvider } from '@/ui/elements/contexts' ;
57import { ProfileSection } from '@/ui/elements/Section' ;
68import { getFieldError , handleError } from '@/ui/utils/errorHandler' ;
@@ -9,27 +11,27 @@ import { generateWeb3Signature, getWeb3Identifier } from '../../../utils/web3';
911import { descriptors , Image , localizationKeys , Text } from '../../customizables' ;
1012import { useEnabledThirdPartyProviders } from '../../hooks' ;
1113
12- export const AddWeb3WalletActionMenu = withCardStateProvider ( ( { onClick } : { onClick ?: ( ) => void } ) => {
14+ export const AddWeb3WalletActionMenu = withCardStateProvider ( ( ) => {
1315 const card = useCardState ( ) ;
1416 const { user } = useUser ( ) ;
15- const { strategies, strategyToDisplayData } = useEnabledThirdPartyProviders ( ) ;
1617
17- const enabledStrategies = strategies . filter ( s => s . startsWith ( 'web3' ) ) as Web3Strategy [ ] ;
18- const connectedStrategies = user ?. verifiedWeb3Wallets . map ( w => w . verification . strategy ) as Web3Strategy [ ] ;
19- const unconnectedStrategies = enabledStrategies . filter ( strategy => {
20- return ! connectedStrategies . includes ( strategy ) ;
21- } ) ;
18+ const wizard = useWizard ( ) ;
19+
2220 const createWeb3Wallet = useReverification ( ( identifier : string ) =>
2321 user ?. createWeb3Wallet ( { web3Wallet : identifier } ) ,
2422 ) ;
2523
26- const connect = async ( strategy : Web3Strategy ) => {
24+ const connect = async ( { strategy, walletName } : { strategy : Web3Strategy ; walletName ?: string } ) => {
25+ if ( strategy === 'web3_solana_signature' && ! walletName ) {
26+ wizard . nextStep ( ) ;
27+ return ;
28+ }
2729 const provider = strategy . replace ( 'web3_' , '' ) . replace ( '_signature' , '' ) as Web3Provider ;
2830 card . setError ( undefined ) ;
2931
3032 try {
3133 card . setLoading ( strategy ) ;
32- const identifier = await getWeb3Identifier ( { provider } ) ;
34+ const identifier = await getWeb3Identifier ( { provider, walletName } ) ;
3335
3436 if ( ! user ) {
3537 throw new Error ( 'user is not defined' ) ;
@@ -38,7 +40,7 @@ export const AddWeb3WalletActionMenu = withCardStateProvider(({ onClick }: { onC
3840 let web3Wallet = await createWeb3Wallet ( identifier ) ;
3941 web3Wallet = await web3Wallet ?. prepareVerification ( { strategy } ) ;
4042 const message = web3Wallet ?. verification . message as string ;
41- const signature = await generateWeb3Signature ( { identifier, nonce : message , provider } ) ;
43+ const signature = await generateWeb3Signature ( { identifier, nonce : message , provider, walletName } ) ;
4244 await web3Wallet ?. attemptVerification ( { signature } ) ;
4345 card . setIdle ( ) ;
4446 } catch ( err ) {
@@ -52,6 +54,29 @@ export const AddWeb3WalletActionMenu = withCardStateProvider(({ onClick }: { onC
5254 }
5355 } ;
5456
57+ return (
58+ < Wizard { ...wizard . props } >
59+ < Web3SelectStrategyScreen onConnect = { connect } />
60+
61+ < Web3SelectWalletScreen onConnect = { connect } />
62+ </ Wizard >
63+ ) ;
64+ } ) ;
65+
66+ const Web3SelectStrategyScreen = ( {
67+ onConnect,
68+ } : {
69+ onConnect : ( params : { strategy : Web3Strategy ; walletName ?: string } ) => Promise < void > ;
70+ } ) => {
71+ const card = useCardState ( ) ;
72+ const { user } = useUser ( ) ;
73+ const { strategies, strategyToDisplayData } = useEnabledThirdPartyProviders ( ) ;
74+ const enabledStrategies = strategies . filter ( s => s . startsWith ( 'web3' ) ) as Web3Strategy [ ] ;
75+ const connectedStrategies = user ?. verifiedWeb3Wallets ?. map ( w => w . verification . strategy ) ?? ( [ ] as Web3Strategy [ ] ) ;
76+ const unconnectedStrategies = enabledStrategies . filter ( strategy => {
77+ return ! connectedStrategies . includes ( strategy ) && strategyToDisplayData [ strategy ] ;
78+ } ) ;
79+
5580 if ( unconnectedStrategies . length === 0 ) {
5681 return null ;
5782 }
@@ -61,13 +86,12 @@ export const AddWeb3WalletActionMenu = withCardStateProvider(({ onClick }: { onC
6186 < ProfileSection . ActionMenu
6287 id = 'web3Wallets'
6388 triggerLocalizationKey = { localizationKeys ( 'userProfile.start.web3WalletsSection.primaryButton' ) }
64- onClick = { onClick }
6589 >
6690 { unconnectedStrategies . map ( strategy => (
6791 < ProfileSection . ActionMenuItem
6892 key = { strategy }
6993 id = { strategyToDisplayData [ strategy ] . id }
70- onClick = { ( ) => connect ( strategy ) }
94+ onClick = { ( ) => onConnect ( { strategy } ) }
7195 isLoading = { card . loadingMetadata === strategy }
7296 isDisabled = { card . isLoading }
7397 localizationKey = { localizationKeys ( 'userProfile.web3WalletPage.web3WalletButtonsBlockButton' , {
@@ -104,4 +128,4 @@ export const AddWeb3WalletActionMenu = withCardStateProvider(({ onClick }: { onC
104128 ) }
105129 </ >
106130 ) ;
107- } ) ;
131+ } ;
0 commit comments