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(wallet): fix wallet module relations with app #3108

Merged
merged 12 commits into from
Sep 21, 2023

Conversation

shoom3301
Copy link
Collaborator

@shoom3301 shoom3301 commented Sep 5, 2023

Summary

This PR is a preparation before moving modules/wallet into a lib (PR). The goal is to fix modules/wallet imports and dependencies.

  1. Imports to files inside of the module changed from absolute to relative (commit)
  2. Utility functions (isChainAllowed, getWeb3ReactConnection, getIsHardWareWallet) have been moved from index into separate files (commit)
  3. All imports modules/wallet/* were replaced by modules/wallet (commit)
  4. Got rid of external styling of Web3StatusWrapper (commit)
  5. Fixed AddToMetamask component styling and removed unused styles in pages/Account/styled.tsx (commit)
  6. Duplicated safe-logo.svg to get rid of importing it from wallet module. From one side it's not a good idea, but it also is not a big problem :) (commit)

#3109

To Test

Test in #3109

@vercel
Copy link

vercel bot commented Sep 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
swap-dev ✅ Ready (Inspect) Visit Preview Sep 21, 2023 2:54pm

🌃 Cosmos ↗︎

@shoom3301 shoom3301 changed the title [1] Refactor/separate wallet module refactor(wallet): fix wallet module relations with app Sep 6, 2023
@shoom3301 shoom3301 requested a review from a team September 6, 2023 05:25
@shoom3301 shoom3301 self-assigned this Sep 6, 2023
@shoom3301 shoom3301 marked this pull request as ready for review September 6, 2023 05:26
… refactor/separate-wallet-module

# Conflicts:
#	apps/cowswap-frontend/src/cosmos.decorator.tsx
#	apps/cowswap-frontend/src/modules/wallet/api/pure/AddToMetamask/index.tsx
#	apps/cowswap-frontend/src/pages/Account/styled.tsx
@@ -92,7 +92,7 @@ export const Wrapper = styled.div`
${({ theme }) => theme.mediaWidth.upToMedium`
width: auto;
height: 100%;
margin: 0 0 0 auto;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this equivalent? before we had the margin define always, now is upToMedium ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great question!
Actually, the value of margin was overridden here:
07f4c8d

I've checked all places where the component is used and it's displayed well there

@@ -8,7 +8,7 @@ import { ApplicationModal } from 'legacy/state/application/reducer'
import { updateConnectionError } from 'legacy/state/connection/reducer'
import { useAppDispatch } from 'legacy/state/hooks'

import { getWeb3ReactConnection } from 'modules/wallet/web3-react/connection'
Copy link
Contributor

Choose a reason for hiding this comment

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

Because im only starting the review, and i don't know where this is ending, my comment might get outdated soon, but one thought here is that long term we shouldn't export something Web3React related (if we can avoid it).

Ideally the module would abstract that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

100% agree. In this PR I only moved all imports from modules/wallet/* to modules/wallet to replace it by import from a in in the future

import { BlockNumberProvider } from 'lib/hooks/useBlockNumber'

import { WalletUpdater } from './modules/wallet'
import { WalletUpdater, injectedConnection } from './modules/wallet'
Copy link
Contributor

Choose a reason for hiding this comment

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

why cosmos don't use absolute imports?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There was a circular dependency that broke cosmos build :( Probably after this changes it won't be relevant


export default function useIsAmbireWallet(): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

this hook uses only stuff from the wallet module, so I wonder if this is where it belongs.

Some additional idea, I think this is only used for detecting if the wallet is a smart contract wallwet. I think this should also be part of the wallet module. This way, we don't need to see any "ambire" use outside of the module

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've moved the hook into useIsSmartContractWallet here:
#3109

{(ENSName || account) && (
<Copy toCopy={ENSName ? ENSName : account ? account : ''} />
)}
{(ENSName || account) && <Copy toCopy={ENSName ? ENSName : account ? account : ''} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

is this expression sth that could be expressed simpler?

would it be equivalent to: ENSName || account || ''

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It might, will change it after this PR. I try to keep this PR as simple as possible, just imports replacements

Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

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

Great prep work!

the thing i felt more unsure was the change to relative. Once this is in a lib, it might be convenient to use absolute imports within the library.

But anyways, i don't want to get too ahead. Looking fw to read the big fat follow up of this PR. Nice work!

@socket-security
Copy link

Updated dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
vite-plugin-node-polyfills 0.11.1...0.12.0 None +0/-0 193 kB voraciousdev

@shoom3301 shoom3301 merged commit 1cdfa24 into develop Sep 21, 2023
7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 21, 2023
@alfetopito alfetopito deleted the refactor/separate-wallet-module branch September 22, 2023 09:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants