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

Chore: finish networks refactoring #14398

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

Lemonexe
Copy link
Contributor

@Lemonexe Lemonexe commented Sep 17, 2024

Finish refactoring of old networksCompatible to networks 🎉

🚧 Depends on #14281, #14374, so if you want to CR this in advance, then only last 3 commits.

Description

  • 1st commit the heavy lifting 💪 These changes had to be done together, as they are tightly interlinked:
    • refactor selectedAccount state
    • refactor discovery (a lot of logic changed!)
    • refactor the easy stuff related to discovery or selected account
  • 2nd commit nuke legacy code 🧹 🪣 ☢️
  • 3rd commit: incidental fix of pre-existing discovery bug: with tada, discovery would seemingly never finish

Related Issue

Resolve #13839 , finally ☺️ 🎉

Screenshots:

I tested in app that the discovery works as before: all accounts are discovered & unfinished/in progress is indicated correctly. But to be really sure, I console logged loaded and total at calculateProgress#L147

  • I activated btc, ltc, eth, sol, test, regtest on T2T1 w/ academic seed, and this is how the discovery progressed on this branch vs. develop: discovery test.txt
  • with all coins activated, it converged on 65 / 65 both this branch & develop
  • with another wallet with even more accounts, it converged on 92 / 92 both this branch & develop
  • before TADA bug was solved, it would end up on for example 16 / 36

TADA 🎉 bug: wrongly indicated as unfinished even when actually finished:
tada bug


// increment the appropriate counter based on the network symbol
const incrementAccumulator = () => {
if (symbol === 'ada' || symbol === 'tada') acc.numberOfCardano += 1;
Copy link
Contributor Author

@Lemonexe Lemonexe Sep 18, 2024

Choose a reason for hiding this comment

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

Note: at first I thought just including 'tada' here would solve the 🎉 🐛,
but I also had to do the "1 or 2 thing" with numberOfCardanoCoins instead of always 1.

Otherwise, with ada & tada at the same time, discovery was wrongly indicated as finished, with debug showing 16 / 6 as loaded / total 😱
I would have to activate some more coins to start the discovery of ada or tada..

@@ -560,8 +560,7 @@ const intlMock = {
formatMessage: (s: any) => s.defaultMessage,
};

const mockedBlockchainNetworks = networksCompatibility.reduce((result, network) => {
if (network.accountType) return result;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this line means that when using networksCompatibility, only 'normal' accounts were processed, which makes the refactoring really easy ☺️ Analogical diff in several other files below.

...networkOverride,
})),
],
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

farewell 👋

@@ -33,7 +33,7 @@ export const disableAccountsThunk = createThunk(
const accounts = selectAccounts(getState());
const enabledNetworks = selectEnabledNetworks(getState());
// find disabled networks
const disabledNetworks = networksCompatibility
const disabledNetworks = networksCollection
.filter(n => !enabledNetworks.includes(n.symbol) || n.isHidden)
.map(n => n.symbol);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ this is different! With networksCompatibility, the array of symbols is not unique, so e.g. 'btc' is duplicated foreach account. Now with networksCollection it is unique.
BUt in this case it's ok, see L41, disabledNetworks is only used to test .includes

@@ -61,7 +61,7 @@ export const preloadFeeInfoThunk = createThunk(
`${BLOCKCHAIN_MODULE_PREFIX}/preloadFeeInfoThunk`,
async (_, { dispatch }) => {
// Fetch default fee levels
const networks = networksCompatibility.filter(n => !n.isHidden && !n.accountType);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

filters only 'normal' accounts, so it's the same ✔️


if (!account || !networkFeeInfo || !device || !network) return null;
const network = networks[account.symbol];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

when !!account, network is now guaranteed ✔️

} else {
acc.numberOfNonCardano += 1;
}
const device = selectDevice(getState());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

what's going on here? See L741, L748 where it's first called.

Previously, networksSymbols from filterUnavailableNetworksCompatible was non-unique, like in comment above, except here it actually mattered, and imho the previous implementation was kinda occult.
In calculateProgress, we need the number of loaded accounts, so the number of duplicated discovery.networks symbols was counted.

Now, discovery.networks is unique, and it is responsibility of calculateProgress to iterate through accounts.

💡 Note how filterUnavailableNetworksCompatible is split between filterUnavailableNetworks and filterUnavailableAccountTypes.

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.

Refactor and type network config
1 participant