-
Notifications
You must be signed in to change notification settings - Fork 471
feat(ui): confirm Web3 wallet removal from its row #9754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fdb4c00
feat(ui): confirm Web3 wallet removal from its row
austincalvelage d8b144e
refactor(ui): align Web3 wallet views with account row patterns
austincalvelage 41132a7
docs(swingset): demonstrate Web3 wallet states and actions
austincalvelage 8957629
test(ui): trim duplicate Web3 callback forwarding checks
austincalvelage 7ea6b6f
docs(swingset): simplify Web3 wallet examples
austincalvelage 2d715f3
fix(ui): address Web3 wallet view feedback
austincalvelage a17e448
Merge branch 'main' into austin/web-3-actions
austincalvelage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
packages/swingset/src/stories/fixtures/user-profile-web3-wallets.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import type { | ||
| UserProfileWeb3Provider, | ||
| UserProfileWeb3Wallet, | ||
| } from '@clerk/ui/mosaic/features/user-profile/user-profile-web3-wallets-section.view'; | ||
| import { useState } from 'react'; | ||
|
|
||
| interface DemoWallet extends UserProfileWeb3Wallet { | ||
| providerId?: string; | ||
| } | ||
|
|
||
| const providers: UserProfileWeb3Provider[] = [ | ||
| { id: 'metamask', provider: 'MetaMask', iconUrl: 'https://img.clerk.com/static/metamask.svg' }, | ||
| { id: 'coinbase-wallet', provider: 'Coinbase Wallet', iconUrl: 'https://img.clerk.com/static/coinbase_wallet.svg' }, | ||
| ]; | ||
|
|
||
| export const primaryWallet: DemoWallet = { | ||
| id: 'wallet_1', | ||
| providerId: 'metamask', | ||
| provider: 'MetaMask', | ||
| iconUrl: 'https://img.clerk.com/static/metamask.svg', | ||
| address: '0x71C7656EC7ab88b098defB751B7401B5f6d8976F', | ||
| isPrimary: true, | ||
| isVerified: true, | ||
| }; | ||
|
|
||
| export const secondaryWallet: DemoWallet = { | ||
| id: 'wallet_2', | ||
| providerId: 'coinbase-wallet', | ||
| provider: 'Coinbase Wallet', | ||
| iconUrl: 'https://img.clerk.com/static/coinbase_wallet.svg', | ||
| address: '0x1234567890abcdef1234567890abcdef12345678', | ||
| isVerified: true, | ||
| }; | ||
|
|
||
| export function useWeb3WalletsFixture({ | ||
| initialWallets = [primaryWallet], | ||
| availableProviders = providers, | ||
| primaryError = false, | ||
| removalState, | ||
| }: { | ||
| initialWallets?: DemoWallet[]; | ||
| availableProviders?: UserProfileWeb3Provider[]; | ||
| primaryError?: boolean; | ||
| removalState?: 'pending' | 'error'; | ||
| } = {}) { | ||
| const [wallets, setWallets] = useState(initialWallets); | ||
| const [connectionProviders, setConnectionProviders] = useState(availableProviders); | ||
| const [primaryFailed, setPrimaryFailed] = useState(false); | ||
|
|
||
| return { | ||
| wallets, | ||
| availableProviders: connectionProviders.filter( | ||
| provider => !wallets.some(wallet => wallet.providerId === provider.id && wallet.isVerified), | ||
| ), | ||
| onConnect: (id: string) => { | ||
| const provider = connectionProviders.find(item => item.id === id); | ||
| if (!provider) { | ||
| return; | ||
| } | ||
| setConnectionProviders(current => | ||
| current.map(item => (item.id === id ? { ...item, connectError: undefined } : item)), | ||
| ); | ||
| setWallets(current => { | ||
| if (current.some(wallet => wallet.providerId === id && !wallet.isVerified)) { | ||
| return current.map(wallet => (wallet.providerId === id ? { ...wallet, isVerified: true } : wallet)); | ||
| } | ||
| return [ | ||
| ...current, | ||
| { | ||
| provider: provider.provider, | ||
| iconUrl: provider.iconUrl, | ||
| id: `wallet_${id}`, | ||
| providerId: id, | ||
| address: '0x1234567890abcdef1234567890abcdef12345678', | ||
| isVerified: true, | ||
| isPrimary: !current.some(wallet => wallet.isPrimary), | ||
| }, | ||
| ]; | ||
| }); | ||
| }, | ||
| onSetPrimary: (id: string) => { | ||
| if (primaryError && !primaryFailed) { | ||
| setPrimaryFailed(true); | ||
| setWallets(current => | ||
| current.map(wallet => | ||
| wallet.id === id | ||
| ? { ...wallet, primaryError: 'Unable to set this wallet as primary. Please try again.' } | ||
| : wallet, | ||
| ), | ||
| ); | ||
| return; | ||
| } | ||
| setWallets(current => | ||
| current.map(wallet => ({ ...wallet, isPrimary: wallet.id === id, primaryError: undefined })), | ||
| ); | ||
| }, | ||
| onRemove: (id: string) => { | ||
| if (removalState === 'pending') { | ||
| setWallets(current => current.map(wallet => (wallet.id === id ? { ...wallet, isRemoving: true } : wallet))); | ||
| setTimeout(() => { | ||
| setWallets(current => current.filter(wallet => wallet.id !== id)); | ||
| }, 1500); | ||
| return; | ||
| } | ||
| setWallets(current => { | ||
| if (removalState === 'error' && !current.find(wallet => wallet.id === id)?.removalError) { | ||
| return current.map(wallet => | ||
| wallet.id === id ? { ...wallet, removalError: 'Unable to remove wallet. Please try again.' } : wallet, | ||
| ); | ||
| } | ||
| return current.filter(wallet => wallet.id !== id); | ||
| }); | ||
| }, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.