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: Removes HathorWallet from Redux store #580

Merged
merged 10 commits into from
Apr 19, 2024

Conversation

tuliomir
Copy link
Collaborator

@tuliomir tuliomir commented Apr 9, 2024

The next version of Redux throws an error by default whenever there are non-serializable objects in its Store ( more about this on this article ). This PR is one in a series of PRs that aim to refactor all of those instances before the upgrade.

The wallet Redux property stored is currently used for many operations throughout the whole application. The proposed solution is to:

  • Create a wallet singleton javascript module, apart from the Redux store
  • Refactor all the calls from this store property to use the singleton directly

It is worth noting that we plan on implementing multiple simultaneous wallets in the future ( see #210 ). This refactor also aims to facilitate this feature, while not directly implementing it.

Acceptance Criteria

  • The routerHistory should not be present on the Redux Store

Rationale and Alternatives

Many different approaches were considered for this refactor, the most important ones were using useRef and useContext. The idea is to keep this wallet instance in a way that does not cause:

  • Additional cognitive overhead due to abstractions
  • Bugs with future iterations of React
  • Compatibility with the React conventions

Since useContext is meant to deal with serializable data that will affect rendering, it was not an option for this solution. Creating a new component and applying useRef would be a possibility, but this would not offer any benefit over a common javascript singleton.

So, the decided solution was to implement a singleton for the application HathorWallet instance.

Security Checklist

  • Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.

@tuliomir tuliomir self-assigned this Apr 9, 2024
@tuliomir tuliomir requested a review from pedroferreira1 as a code owner April 9, 2024 21:28
@tuliomir tuliomir force-pushed the refactor/redux-hathorwallet branch from b8307c3 to 49c41d6 Compare April 9, 2024 21:53
@tuliomir tuliomir requested review from andreabadesso and r4mmer and removed request for pedroferreira1 April 11, 2024 17:08
Copy link
Member

@r4mmer r4mmer left a comment

Choose a reason for hiding this comment

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

As stated in the review, I think we should remove the wallet from all mapStateToProps since the objective of this PR is to remove the wallet from redux state.

src/components/ModalAddManyTokens.js Outdated Show resolved Hide resolved
src/screens/TransactionDetail.js Outdated Show resolved Hide resolved
src/services/wallet.singleton.js Outdated Show resolved Hide resolved
@tuliomir tuliomir force-pushed the refactor/redux-hathorwallet branch from 91d18c4 to 0fe2c6d Compare April 16, 2024 23:53
@tuliomir tuliomir requested a review from r4mmer April 16, 2024 23:55
src/components/ModalAddToken.js Outdated Show resolved Hide resolved
src/components/ModalBackupWords.js Outdated Show resolved Hide resolved
src/components/ModalResetAllData.js Show resolved Hide resolved
src/components/ModalSendTx.js Show resolved Hide resolved
src/components/ModalUnregisteredTokenInfo.js Show resolved Hide resolved
src/modules/wallet.js Show resolved Hide resolved
src/screens/AddressList.js Outdated Show resolved Hide resolved
src/screens/CreateNFT.js Outdated Show resolved Hide resolved
src/utils/tokens.js Outdated Show resolved Hide resolved
src/screens/atomic-swap/NewSwap.js Outdated Show resolved Hide resolved
@tuliomir tuliomir requested a review from andreabadesso April 17, 2024 16:40
@tuliomir tuliomir merged commit 42b0d60 into master Apr 19, 2024
1 check passed
@tuliomir tuliomir deleted the refactor/redux-hathorwallet branch April 19, 2024 16:53
@tuliomir tuliomir mentioned this pull request May 3, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants