-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
:fix
allowUnsupportedChain
param to work correctly (#3447)
- Loading branch information
1 parent
c1a641f
commit 85c858f
Showing
10 changed files
with
321 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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,22 @@ | ||
--- | ||
'@reown/appkit-scaffold-ui': patch | ||
'@reown/appkit': patch | ||
'@reown/appkit-core': patch | ||
'@reown/appkit-adapter-ethers': patch | ||
'@reown/appkit-adapter-ethers5': patch | ||
'@reown/appkit-adapter-solana': patch | ||
'@reown/appkit-adapter-wagmi': patch | ||
'@reown/appkit-utils': patch | ||
'@reown/appkit-cdn': patch | ||
'@reown/appkit-cli': patch | ||
'@reown/appkit-common': patch | ||
'@reown/appkit-experimental': patch | ||
'@reown/appkit-polyfills': patch | ||
'@reown/appkit-siwe': patch | ||
'@reown/appkit-siwx': patch | ||
'@reown/appkit-ui': patch | ||
'@reown/appkit-wallet': patch | ||
'@reown/appkit-wallet-button': patch | ||
--- | ||
|
||
Fix allowUnsupportedChain param to work correctly |
This file contains 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 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 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 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 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 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 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
124 changes: 124 additions & 0 deletions
124
packages/scaffold-ui/test/modal/w3m-account-button.test.ts
This file contains 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,124 @@ | ||
import { expect, html, fixture } from '@open-wc/testing' | ||
|
||
import { | ||
AccountController, | ||
ChainController, | ||
OptionsController, | ||
ModalController, | ||
RouterController | ||
} from '@reown/appkit-core' | ||
import { W3mAccountButton } from '../../src/modal/w3m-account-button' | ||
import { describe, it, afterEach, vi } from 'vitest' | ||
import type { CaipNetwork } from '@reown/appkit-common' | ||
|
||
const mockCaipNetwork: CaipNetwork = { | ||
chainNamespace: 'eip155', | ||
caipNetworkId: 'eip155:1', | ||
id: 1, | ||
name: '', | ||
nativeCurrency: { name: '', symbol: '', decimals: 0 }, | ||
rpcUrls: { default: { http: [], webSocket: undefined } } | ||
} | ||
|
||
const mockCaipAddress = 'eip155:1:0x0000000000000000000000000000000000000000' | ||
describe('W3mAccountButton', () => { | ||
afterEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
it('should set isUnsupportedChain to false when allowUnsupportedChain is true', async () => { | ||
vi.spyOn(ChainController.state, 'activeChain', 'get').mockReturnValue('eip155') | ||
vi.spyOn(ChainController, 'checkIfSupportedNetwork').mockReturnValue(true) | ||
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({ | ||
...OptionsController.state, | ||
allowUnsupportedChain: true | ||
}) | ||
|
||
vi.spyOn(AccountController, 'state', 'get').mockReturnValue({ | ||
...AccountController.state, | ||
profileName: 'test' | ||
}) | ||
|
||
const button = (await fixture( | ||
html`<w3m-account-button></w3m-account-button>` | ||
)) as W3mAccountButton | ||
|
||
const accountButton = button.shadowRoot?.querySelector('wui-account-button') | ||
expect(accountButton).to.exist | ||
|
||
expect(accountButton?.isUnsupportedChain).to.equal(false) | ||
}) | ||
|
||
it('should set isUnsupportedChain to true when allowUnsupportedChain is false and chain is unsupported', async () => { | ||
vi.spyOn(ChainController.state, 'activeChain', 'get').mockReturnValue('eip155') | ||
vi.spyOn(ChainController.state, 'activeCaipNetwork', 'get').mockReturnValue(mockCaipNetwork) | ||
vi.spyOn(ChainController, 'checkIfSupportedNetwork').mockReturnValue(false) | ||
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({ | ||
...OptionsController.state, | ||
allowUnsupportedChain: false | ||
}) | ||
|
||
const button = (await fixture( | ||
html`<w3m-account-button></w3m-account-button>` | ||
)) as W3mAccountButton | ||
|
||
const accountButton = button.shadowRoot?.querySelector('wui-account-button') | ||
expect(accountButton).to.exist | ||
expect(accountButton?.isUnsupportedChain).to.equal(true) | ||
}) | ||
|
||
describe('onClick behavior', () => { | ||
it('should open modal normally when chain is supported', async () => { | ||
vi.spyOn(ChainController.state, 'activeChain', 'get').mockReturnValue('eip155') | ||
vi.spyOn(ChainController, 'checkIfSupportedNetwork').mockReturnValue(true) | ||
vi.spyOn(ChainController.state, 'activeCaipAddress', 'get').mockReturnValue(mockCaipAddress) | ||
|
||
vi.spyOn(ModalController, 'open') | ||
|
||
const button = await fixture(html`<w3m-account-button></w3m-account-button>`) | ||
const accountButton = button.shadowRoot?.querySelector('wui-account-button') | ||
|
||
await accountButton?.click() | ||
|
||
expect(RouterController.state.view).to.equal('Account') | ||
}) | ||
|
||
it('should open modal normally when chain is not supported and allowUnsupportedChain is true', async () => { | ||
vi.spyOn(ChainController.state, 'activeChain', 'get').mockReturnValue('eip155') | ||
vi.spyOn(ChainController, 'checkIfSupportedNetwork').mockReturnValue(false) | ||
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({ | ||
...OptionsController.state, | ||
allowUnsupportedChain: true | ||
}) | ||
vi.spyOn(ChainController.state, 'activeCaipAddress', 'get').mockReturnValue(mockCaipAddress) | ||
|
||
vi.spyOn(ModalController, 'open') | ||
|
||
const button = await fixture(html`<w3m-account-button></w3m-account-button>`) | ||
const accountButton = button.shadowRoot?.querySelector('wui-account-button') | ||
|
||
await accountButton?.click() | ||
|
||
expect(RouterController.state.view).to.equal('Account') | ||
}) | ||
|
||
it('should open modal in UnsupportedChain view when chain is not supported and allowUnsupportedChain is false', async () => { | ||
vi.spyOn(ChainController.state, 'activeChain', 'get').mockReturnValue('eip155') | ||
vi.spyOn(ChainController, 'checkIfSupportedNetwork').mockReturnValue(false) | ||
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({ | ||
...OptionsController.state, | ||
allowUnsupportedChain: false | ||
}) | ||
vi.spyOn(ChainController.state, 'activeCaipAddress', 'get').mockReturnValue(mockCaipAddress) | ||
|
||
vi.spyOn(ModalController, 'open') | ||
|
||
const button = await fixture(html`<w3m-account-button></w3m-account-button>`) | ||
const accountButton = button.shadowRoot?.querySelector('wui-account-button') | ||
|
||
await accountButton?.click() | ||
|
||
expect(RouterController.state.view).to.equal('UnsupportedChain') | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.