Skip to content
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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

stanleyyconsensys
Copy link
Collaborator

@stanleyyconsensys stanleyyconsensys commented Sep 4, 2024

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:

@stanleyyconsensys stanleyyconsensys requested a review from a team as a code owner September 4, 2024 05:53
@stanleyyconsensys stanleyyconsensys requested review from Julink-eth and wantedsystem and removed request for a team September 4, 2024 05:53
Copy link

sonarcloud bot commented Sep 4, 2024

Quality Gate Passed Quality Gate passed for 'consensys_starknet-snap-wallet-ui'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

sonarcloud bot commented Sep 4, 2024

Quality Gate Passed Quality Gate passed for 'consensys_starknet-snap-starknet-snap'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Comment on lines +123 to +124
!currentNetwork ||
currentNetwork.chainId !== STARKNET_MAINNET_NETWORK.chainId
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
!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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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 () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(result).toStrictEqual(STARKNET_SEPOLIA_TESTNET_NETWORK);
expect(result).toStrictEqual(STARKNET_MAINNET_NETWORK);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants