-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: filter wallets without wc support from useAppKitWallets search results on mobile #5616
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tomiir
wants to merge
3
commits into
main
Choose a base branch
from
tomiir/wallet-filter-analysis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { | ||
| ConnectionController, | ||
| ConnectorController, | ||
| OptionsController | ||
| } from '../../exports/index.js' | ||
| import { AssetUtil } from '../../src/utils/AssetUtil.js' | ||
| import { ConnectUtil } from '../../src/utils/ConnectUtil.js' | ||
| import { CoreHelperUtil } from '../../src/utils/CoreHelperUtil.js' | ||
| import type { WcWallet } from '../../src/utils/TypeUtil.js' | ||
|
|
||
| // -- Helpers ------------------------------------------------------------------ | ||
| function createMockWcWallet(overrides: Partial<WcWallet> = {}): WcWallet { | ||
| return { | ||
| id: 'wallet-id', | ||
| name: 'Test Wallet', | ||
| supports_wc: true, | ||
| mobile_link: 'testwalletapp://', | ||
| ...overrides | ||
| } | ||
| } | ||
|
|
||
| // -- Tests -------------------------------------------------------------------- | ||
| describe('ConnectUtil', () => { | ||
| describe('getWalletConnectWallets', () => { | ||
| beforeEach(() => { | ||
| vi.restoreAllMocks() | ||
| ConnectorController.state.connectors = [] | ||
| OptionsController.state.featuredWalletIds = undefined | ||
| ConnectionController.state.wcBasic = false | ||
| vi.spyOn(AssetUtil, 'getWalletImageUrl').mockReturnValue('') | ||
| }) | ||
|
|
||
| it('should filter out wallets without wc support from search results on mobile', () => { | ||
| vi.spyOn(CoreHelperUtil, 'isMobile').mockReturnValue(true) | ||
|
|
||
| const walletWithWc = createMockWcWallet({ | ||
| id: 'wc-wallet', | ||
| name: 'WC Wallet', | ||
| supports_wc: true | ||
| }) | ||
| const walletWithoutWc = createMockWcWallet({ | ||
| id: 'no-wc-wallet', | ||
| name: 'No WC Wallet', | ||
| supports_wc: false, | ||
| mobile_link: 'noWcWalletapp://' | ||
| }) | ||
|
|
||
| const result = ConnectUtil.getWalletConnectWallets([], [walletWithWc, walletWithoutWc]) | ||
|
|
||
| expect(result.map(w => w.id)).toEqual(['wc-wallet']) | ||
| }) | ||
|
|
||
| it('should include all search results on desktop when wcBasic is false', () => { | ||
| vi.spyOn(CoreHelperUtil, 'isMobile').mockReturnValue(false) | ||
| ConnectionController.state.wcBasic = false | ||
|
|
||
| const walletWithWc = createMockWcWallet({ | ||
| id: 'wc-wallet', | ||
| name: 'WC Wallet', | ||
| supports_wc: true | ||
| }) | ||
| const walletWithoutWc = createMockWcWallet({ | ||
| id: 'no-wc-wallet', | ||
| name: 'No WC Wallet', | ||
| supports_wc: false | ||
| }) | ||
|
|
||
| const result = ConnectUtil.getWalletConnectWallets([], [walletWithWc, walletWithoutWc]) | ||
|
|
||
| expect(result.map(w => w.id)).toEqual(['wc-wallet', 'no-wc-wallet']) | ||
| }) | ||
|
|
||
| it('should filter out wallets without wc support on desktop when wcBasic is true', () => { | ||
| vi.spyOn(CoreHelperUtil, 'isMobile').mockReturnValue(false) | ||
| ConnectionController.state.wcBasic = true | ||
|
|
||
| const walletWithWc = createMockWcWallet({ | ||
| id: 'wc-wallet', | ||
| name: 'WC Wallet', | ||
| supports_wc: true | ||
| }) | ||
| const walletWithoutWc = createMockWcWallet({ | ||
| id: 'no-wc-wallet', | ||
| name: 'No WC Wallet', | ||
| supports_wc: false | ||
| }) | ||
|
|
||
| const result = ConnectUtil.getWalletConnectWallets([], [walletWithWc, walletWithoutWc]) | ||
|
|
||
| expect(result.map(w => w.id)).toEqual(['wc-wallet']) | ||
| }) | ||
|
|
||
| it('should preserve order of search results when no installed or featured wallets', () => { | ||
| vi.spyOn(CoreHelperUtil, 'isMobile').mockReturnValue(false) | ||
|
|
||
| const wallets = [ | ||
| createMockWcWallet({ id: 'wallet-0', name: 'Wallet 0' }), | ||
| createMockWcWallet({ id: 'wallet-1', name: 'Wallet 1' }), | ||
| createMockWcWallet({ id: 'wallet-2', name: 'Wallet 2' }) | ||
| ] | ||
|
|
||
| const result = ConnectUtil.getWalletConnectWallets([], wallets) | ||
|
|
||
| expect(result).toHaveLength(3) | ||
| expect(result[0]?.id).toBe('wallet-0') | ||
| expect(result[1]?.id).toBe('wallet-1') | ||
| expect(result[2]?.id).toBe('wallet-2') | ||
| }) | ||
|
|
||
| it('should sort installed wallets first in search results', () => { | ||
| vi.spyOn(CoreHelperUtil, 'isMobile').mockReturnValue(false) | ||
| ConnectorController.state.connectors = [ | ||
| { | ||
| id: 'wallet-2-connector', | ||
| name: 'Wallet 2', | ||
| type: 'ANNOUNCED', | ||
| chain: 'eip155', | ||
| info: { rdns: 'com.wallet2' } | ||
| } | ||
| ] as any | ||
|
|
||
| const wallets = [ | ||
| createMockWcWallet({ id: 'wallet-0', name: 'Wallet 0' }), | ||
| createMockWcWallet({ id: 'wallet-1', name: 'Wallet 1' }), | ||
| createMockWcWallet({ id: 'wallet-2', name: 'Wallet 2', rdns: 'com.wallet2' }) | ||
| ] | ||
|
|
||
| const result = ConnectUtil.getWalletConnectWallets([], wallets) | ||
|
|
||
| expect(result[0]?.id).toBe('wallet-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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { | ||
| ConnectionController, | ||
| ConnectorController, | ||
| OptionsController | ||
| } from '../../exports/index.js' | ||
| import { CoreHelperUtil } from '../../src/utils/CoreHelperUtil.js' | ||
| import type { WcWallet } from '../../src/utils/TypeUtil.js' | ||
| import { WalletUtil } from '../../src/utils/WalletUtil.js' | ||
|
|
||
| // -- Helpers ------------------------------------------------------------------ | ||
| function createMockWcWallet(overrides: Partial<WcWallet> = {}): WcWallet { | ||
| return { | ||
| id: 'wallet-id', | ||
| name: 'Test Wallet', | ||
| supports_wc: true, | ||
| mobile_link: 'testwalletapp://', | ||
| ...overrides | ||
| } | ||
| } | ||
|
|
||
| // -- Tests -------------------------------------------------------------------- | ||
| describe('WalletUtil', () => { | ||
| describe('filterAndFlagWallets', () => { | ||
| beforeEach(() => { | ||
| vi.restoreAllMocks() | ||
| ConnectorController.state.connectors = [] | ||
| OptionsController.state.featuredWalletIds = undefined | ||
| ConnectionController.state.wcBasic = false | ||
| }) | ||
|
|
||
| it('should filter out wallets without wc support on mobile', () => { | ||
| vi.spyOn(CoreHelperUtil, 'isMobile').mockReturnValue(true) | ||
|
|
||
| const wallets = [ | ||
| createMockWcWallet({ id: 'wc-wallet', supports_wc: true }), | ||
| createMockWcWallet({ id: 'no-wc-wallet', supports_wc: false }) | ||
| ] | ||
|
|
||
| const result = WalletUtil.filterAndFlagWallets(wallets) | ||
|
|
||
| expect(result.map(w => w.id)).toEqual(['wc-wallet']) | ||
| }) | ||
|
|
||
| it('should pass through all wallets on desktop', () => { | ||
| vi.spyOn(CoreHelperUtil, 'isMobile').mockReturnValue(false) | ||
|
|
||
| const wallets = [ | ||
| createMockWcWallet({ id: 'wc-wallet', supports_wc: true }), | ||
| createMockWcWallet({ id: 'no-wc-wallet', supports_wc: false }) | ||
| ] | ||
|
|
||
| const result = WalletUtil.filterAndFlagWallets(wallets) | ||
|
|
||
| expect(result.map(w => w.id)).toEqual(['wc-wallet', 'no-wc-wallet']) | ||
| }) | ||
|
|
||
| it('should assign display_index to each wallet', () => { | ||
| vi.spyOn(CoreHelperUtil, 'isMobile').mockReturnValue(false) | ||
|
|
||
| const wallets = [ | ||
| createMockWcWallet({ id: 'wallet-0' }), | ||
| createMockWcWallet({ id: 'wallet-1' }), | ||
| createMockWcWallet({ id: 'wallet-2' }) | ||
| ] | ||
|
|
||
| const result = WalletUtil.filterAndFlagWallets(wallets) | ||
|
|
||
| expect(result[0]?.display_index).toBe(0) | ||
| expect(result[1]?.display_index).toBe(1) | ||
| expect(result[2]?.display_index).toBe(2) | ||
| }) | ||
| }) | ||
| }) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On desktop let's filter out the wallets which
webapp_linkis not valid? When they don't support WC and no webapp_link don't make sense to render them at allThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm but on desktop we can have injected wallets on those spots, and clicking on them should trigger those no?