Consensys / starknet-snap

The MetaMask Snap for Starknet
https://snaps.consensys.net/starknet
Apache License 2.0
72 stars 25 forks source link

fix: non zero balance on non deployed cairo 0 account #276

Closed khanti42 closed 1 week ago

khanti42 commented 2 weeks ago

Description: This PR closes #281. It introduces several enhancements and fixes to the StarkNet Snap package. Key changes include:

  1. Support for Cairo Legacy Versions:

    • Introduced support for Cairo legacy versions by adding CAIRO_VERSION_LEGACY and related utilities.
    • Updated createAccount function to handle both current and legacy Cairo versions, using the cairoVersion parameter.
  2. Account Deployment Enhancements:

    • Added new functions to estimate fees and deploy accounts for both Cairo versions.
    • Updated the getCorrectContractAddress function to include logic for detecting and handling non-deployed accounts with a non-zero balance.
    • Added a new state variable deployRequired to the AccContract type to track whether account deployment is needed.
  3. UI Updates:

    • Introduced a new DeployModal component to guide users through deploying their accounts.
    • Updated App.tsx to handle the display logic for the new DeployModal.
    • Added Storybook stories for the DeployModal component for better UI development and testing.
  4. Redux State Management:

    • Updated the modal slice to include deployModalVisible state for managing the visibility of the deployment modal.
    • Updated the useStarkNetSnap hook to handle the deployment flow and manage modal visibility accordingly.
  5. Test Coverage:

    • Added and updated tests to cover the new deployment logic and ensure backward compatibility with existing functionalities.

Files Changed:

  1. createAccount.ts: Updated to support Cairo legacy versions and added conditional logic for account creation.
  2. index.ts: Added a new case for starkNet_createAccountLegacy.
  3. recoverAccounts.ts: Added logic to determine if an account requires deployment.
  4. snapState.ts: Updated AccContract interface to include deployRequired.
  5. constants.ts: Added constants for Cairo versions and hashes.
  6. starknetUtils.ts: Added utility functions for deployment and fee estimation.
  7. constants.test.ts: Added new test constants.
  8. recoverAccounts.test.ts, upgradeAccContract.test.ts, starknetUtils.test.ts: Updated and added tests for new functionalities.
  9. App.tsx, DeployModal.stories.tsx, DeployModal.style.ts, DeployModal.view.tsx, DeployModal/index.ts: UI updates for deployment modal. Created new DeployModal.
  10. useStarkNetSnap.ts: Updated to manage deployment flow.
  11. modalSlice.ts: Added deployModalVisible state.
  12. index.ts: Updated Account type to include deployRequired.

PR Checklist:

Note: Ensure to review the new deployment flow and the UI changes introduced by the DeployModal component.

sonarcloud[bot] commented 1 week ago

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

Issues
6 New issues
0 Accepted issues

Measures
0 Security Hotspots
71.0% Coverage on New Code
1.3% Duplication on New Code

See analysis details on SonarCloud

sonarcloud[bot] commented 1 week ago

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

Issues
1 New issue
0 Accepted issues

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

See analysis details on SonarCloud