-
Notifications
You must be signed in to change notification settings - Fork 26
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
refactor: revamp snap onHomePage
handler
#345
base: main
Are you sure you want to change the base?
Conversation
…-on-homepage-handle
Quality Gate passed for 'consensys_starknet-snap-wallet-ui'Issues Measures |
Quality Gate passed for 'consensys_starknet-snap-starknet-snap'Issues Measures |
!currentNetwork || | ||
currentNetwork.chainId !== STARKNET_MAINNET_NETWORK.chainId |
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.
!currentNetwork || | |
currentNetwork.chainId !== STARKNET_MAINNET_NETWORK.chainId | |
!currentNetwork || ( | |
currentNetwork.chainId !== STARKNET_MAINNET_NETWORK.chainId && | |
currentNetwork.chainId !== STARKNET_SEPOLIA_TESTNET_NETWORK.chainId | |
) |
!currentNetwork || | ||
currentNetwork.chainId !== STARKNET_MAINNET_NETWORK.chainId | ||
) { | ||
return STARKNET_SEPOLIA_TESTNET_NETWORK; |
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.
return STARKNET_SEPOLIA_TESTNET_NETWORK; | |
return STARKNET_MAINNET_NETWORK; |
async getCurrentNetwork(state?: SnapState): Promise<Network> { | ||
const { currentNetwork } = state ?? (await this.get()); | ||
|
||
// Make sure the current network is either Sepolia testnet or Mainnet. By default it will be Sepolia testnet. |
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.
// Make sure the current network is either Sepolia testnet or Mainnet. By default it will be Sepolia testnet. | |
// Make sure the current network is either Sepolia testnet or Mainnet. By default it will be Mainnet. |
@@ -173,15 +174,27 @@ describe('NetworkStateManager', () => { | |||
expect(result).toStrictEqual(STARKNET_MAINNET_NETWORK); | |||
}); | |||
|
|||
it('returns null if the current network is null or undefined', async () => { | |||
it('returns sepolia testnet if the current network is null or undefined', async () => { |
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.
it('returns sepolia testnet if the current network is null or undefined', async () => { | |
it('returns mainnet if the current network is null or undefined', async () => { |
await mockState({ | ||
networks: [STARKNET_MAINNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK], | ||
}); | ||
|
||
const stateManager = new NetworkStateManager(); | ||
const result = await stateManager.getCurrentNetwork(); | ||
|
||
expect(result).toBeNull(); | ||
expect(result).toStrictEqual(STARKNET_SEPOLIA_TESTNET_NETWORK); |
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.
expect(result).toStrictEqual(STARKNET_SEPOLIA_TESTNET_NETWORK); | |
expect(result).toStrictEqual(STARKNET_MAINNET_NETWORK); |
expect(result).toStrictEqual(STARKNET_SEPOLIA_TESTNET_NETWORK); | ||
}); | ||
|
||
it('returns sepolia testnet if the current network is neither mainnet or sepolia testnet', async () => { |
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.
it('returns sepolia testnet if the current network is neither mainnet or sepolia testnet', async () => { | |
it('returns mainnet if the current network is neither mainnet or sepolia testnet', async () => { |
const stateManager = new NetworkStateManager(); | ||
const result = await stateManager.getCurrentNetwork(); | ||
|
||
expect(result).toStrictEqual(STARKNET_SEPOLIA_TESTNET_NETWORK); |
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.
expect(result).toStrictEqual(STARKNET_SEPOLIA_TESTNET_NETWORK); | |
expect(result).toStrictEqual(STARKNET_MAINNET_NETWORK); |
This PR is adding a controller to handle the request in onHomePage
This PR also update the network state manager to return an default network if the current network is undefined
Requirement:
Requires this PR to be merged first:
snapUtils
function -dappUrl
#344