|
1 | 1 | import { useReverification, useUser } from '@clerk/shared/react'; |
2 | 2 | import type { Web3Provider, Web3Strategy } from '@clerk/shared/types'; |
3 | 3 |
|
4 | | -import { useWizard, Wizard } from '@/ui/common'; |
5 | 4 | import { Web3SelectWalletScreen } from '@/ui/components/UserProfile/Web3SelectWalletScreen'; |
6 | | -import { useCardState, withCardStateProvider } from '@/ui/elements/contexts'; |
| 5 | +import { Action } from '@/ui/elements/Action'; |
| 6 | +import { useActionContext } from '@/ui/elements/Action/ActionRoot'; |
| 7 | +import { useCardState } from '@/ui/elements/contexts'; |
7 | 8 | import { ProfileSection } from '@/ui/elements/Section'; |
8 | 9 | import { getFieldError, handleError } from '@/ui/utils/errorHandler'; |
9 | 10 |
|
10 | 11 | import { generateWeb3Signature, getWeb3Identifier } from '../../../utils/web3'; |
11 | 12 | import { descriptors, Image, localizationKeys, Text } from '../../customizables'; |
12 | 13 | import { useEnabledThirdPartyProviders } from '../../hooks'; |
13 | 14 |
|
14 | | -export const AddWeb3WalletActionMenu = withCardStateProvider(() => { |
| 15 | +export const AddWeb3WalletActionMenu = () => { |
15 | 16 | const card = useCardState(); |
| 17 | + const { open } = useActionContext(); |
16 | 18 | const { user } = useUser(); |
| 19 | + const { strategies, strategyToDisplayData } = useEnabledThirdPartyProviders(); |
| 20 | + const enabledStrategies = strategies.filter(s => s.startsWith('web3')) as Web3Strategy[]; |
| 21 | + const connectedStrategies = user?.verifiedWeb3Wallets?.map(w => w.verification.strategy) ?? ([] as Web3Strategy[]); |
| 22 | + const unconnectedStrategies = enabledStrategies.filter(strategy => { |
| 23 | + return !connectedStrategies.includes(strategy) && strategyToDisplayData[strategy]; |
| 24 | + }); |
17 | 25 |
|
18 | | - const wizard = useWizard(); |
| 26 | + if (unconnectedStrategies.length === 0) { |
| 27 | + return null; |
| 28 | + } |
19 | 29 |
|
20 | 30 | const createWeb3Wallet = useReverification((identifier: string) => |
21 | 31 | user?.createWeb3Wallet({ web3Wallet: identifier }), |
22 | 32 | ); |
23 | 33 |
|
| 34 | + // If the user selects `web3_solana_signature` as their strategy, |
| 35 | + // we need to obtain the wallet name to use when connecting and signing the message during the auth flow |
| 36 | + // |
| 37 | + // Otherwise, our current Web3 providers are all based on the wallet provider name, |
| 38 | + // which is sufficient for our current use case when connecting to a wallet. |
24 | 39 | const connect = async ({ strategy, walletName }: { strategy: Web3Strategy; walletName?: string }) => { |
25 | 40 | if (strategy === 'web3_solana_signature' && !walletName) { |
26 | | - wizard.nextStep(); |
| 41 | + open('web3Wallets'); |
27 | 42 | return; |
28 | 43 | } |
29 | 44 | const provider = strategy.replace('web3_', '').replace('_signature', '') as Web3Provider; |
@@ -54,67 +69,48 @@ export const AddWeb3WalletActionMenu = withCardStateProvider(() => { |
54 | 69 | } |
55 | 70 | }; |
56 | 71 |
|
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 | | - |
80 | | - if (unconnectedStrategies.length === 0) { |
81 | | - return null; |
82 | | - } |
83 | | - |
84 | 72 | return ( |
85 | 73 | <> |
86 | | - <ProfileSection.ActionMenu |
87 | | - id='web3Wallets' |
88 | | - triggerLocalizationKey={localizationKeys('userProfile.start.web3WalletsSection.primaryButton')} |
89 | | - > |
90 | | - {unconnectedStrategies.map(strategy => ( |
91 | | - <ProfileSection.ActionMenuItem |
92 | | - key={strategy} |
93 | | - id={strategyToDisplayData[strategy].id} |
94 | | - onClick={() => onConnect({ strategy })} |
95 | | - isLoading={card.loadingMetadata === strategy} |
96 | | - isDisabled={card.isLoading} |
97 | | - localizationKey={localizationKeys('userProfile.web3WalletPage.web3WalletButtonsBlockButton', { |
98 | | - provider: strategyToDisplayData[strategy].name, |
99 | | - })} |
100 | | - sx={t => ({ |
101 | | - justifyContent: 'start', |
102 | | - gap: t.space.$2, |
103 | | - })} |
104 | | - leftIcon={ |
105 | | - <Image |
106 | | - elementDescriptor={descriptors.providerIcon} |
107 | | - elementId={descriptors.providerIcon.setId(strategyToDisplayData[strategy].id)} |
108 | | - isLoading={card.loadingMetadata === strategy} |
109 | | - isDisabled={card.isLoading} |
110 | | - src={strategyToDisplayData[strategy].iconUrl} |
111 | | - alt={`Connect ${strategyToDisplayData[strategy].name}`} |
112 | | - sx={theme => ({ width: theme.sizes.$5 })} |
113 | | - /> |
114 | | - } |
115 | | - /> |
116 | | - ))} |
117 | | - </ProfileSection.ActionMenu> |
| 74 | + <Action.Closed value='web3Wallets'> |
| 75 | + <ProfileSection.ActionMenu |
| 76 | + id='web3Wallets' |
| 77 | + triggerLocalizationKey={localizationKeys('userProfile.start.web3WalletsSection.primaryButton')} |
| 78 | + > |
| 79 | + {unconnectedStrategies.map(strategy => ( |
| 80 | + <ProfileSection.ActionMenuItem |
| 81 | + key={strategy} |
| 82 | + id={strategyToDisplayData[strategy].id} |
| 83 | + onClick={() => connect({ strategy })} |
| 84 | + isLoading={card.loadingMetadata === strategy} |
| 85 | + isDisabled={card.isLoading} |
| 86 | + localizationKey={localizationKeys('userProfile.web3WalletPage.web3WalletButtonsBlockButton', { |
| 87 | + provider: strategyToDisplayData[strategy].name, |
| 88 | + })} |
| 89 | + sx={t => ({ |
| 90 | + justifyContent: 'start', |
| 91 | + gap: t.space.$2, |
| 92 | + })} |
| 93 | + leftIcon={ |
| 94 | + <Image |
| 95 | + elementDescriptor={descriptors.providerIcon} |
| 96 | + elementId={descriptors.providerIcon.setId(strategyToDisplayData[strategy].id)} |
| 97 | + isLoading={card.loadingMetadata === strategy} |
| 98 | + isDisabled={card.isLoading} |
| 99 | + src={strategyToDisplayData[strategy].iconUrl} |
| 100 | + alt={`Connect ${strategyToDisplayData[strategy].name}`} |
| 101 | + sx={theme => ({ width: theme.sizes.$5 })} |
| 102 | + /> |
| 103 | + } |
| 104 | + /> |
| 105 | + ))} |
| 106 | + </ProfileSection.ActionMenu> |
| 107 | + </Action.Closed> |
| 108 | + <Action.Open value='web3Wallets'> |
| 109 | + <Action.Card> |
| 110 | + <Web3SelectWalletScreen onConnect={connect} /> |
| 111 | + </Action.Card> |
| 112 | + </Action.Open> |
| 113 | + |
118 | 114 | {card.error && ( |
119 | 115 | <Text |
120 | 116 | colorScheme='danger' |
|
0 commit comments