-
Notifications
You must be signed in to change notification settings - Fork 20
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
Prevent "no multisig" from being displayed before we checked #390
Conversation
Deployment is failing because of Cloudflare issues. The reviewing of this PR shouldn't be impacted though. |
…tix into tbaut-no-multisig-flashing
Found a bug, let's not merge. |
The bug was visible when you had a watched account with no multisig, but no extension connection. The spinner would show endlessly. I changed a little my strategy. Making sure the first "Mutlxi is an interface.." would only show when we're sure we've init all the localstorage related elements (connection to the extension and watched accounts). |
@@ -55,7 +55,7 @@ Cypress.Commands.add('initExtension', (accounts: InjectedAccountWitMnemonic[]) = | |||
}) | |||
|
|||
Cypress.Commands.add('getAuthRequests', () => { | |||
return cy.wrap(extension.getAuthRequests()) | |||
return cy.wait(500).then(() => cy.wrap(extension.getAuthRequests())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use waitUntil especially when we show the loader. It's hard to guess how much time you really need, so the test might be unstable.
An example of usage
cy.waitUntil(function() {
return cy.get('loader').should('not.exist');
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a library for that method https://www.npmjs.com/package/cypress-wait-until
It's a missing method in the cypress, but it's inspired by "Testing library" (https://testing-library.com/docs/guide-disappearance/#waiting-for-disappearance).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really dislike waits
, and I'll fight them all as much as I can. But in this case, I don't think we have any other solution, because the actual firing of the request is itself delayed. the loader appears right away (after this PR) but the firing of the request for accounts is done 500ms after, because of a bug, see the comment above the following code:
Multix/packages/ui/src/contexts/AccountsContext.tsx
Lines 135 to 138 in eac29c0
// race condition see https://github.com/polkadot-js/extension/issues/938 | |
setTimeout(() => { | |
getaccountList(chainInfo.isEthereum) | |
}, 500) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check if waitUntil can help here, at least to make things more elegant on the surface. It will have to wait for 500ms at least.
packages/ui/src/pages/Home/Home.tsx
Outdated
) | ||
} | ||
|
||
if (isLoading) { | ||
if (isLoadingMultisigs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about to move the loading and error handling in the separate file:
import React from 'react';
import { CircularProgress } from '@mui/material';
import { LoaderBoxStyled, MessageWrapper, ErrorMessageStyled } from './YourStyledComponents'; // Update with your actual imports
const useLoadingAndError = ({ api, isAccountLoading, isLoadingMultisigs, multisigQueryError, multiProxyList, showNewMultisigAlert, selectedNetworkInfo }) => {
if (!api) {
return (
<LoaderBoxStyled data-cy="loader-rpc-connection">
<CircularProgress />
{`Connecting to the node at ${selectedNetworkInfo?.rpcUrl}`}
</LoaderBoxStyled>
);
}
if (isAccountLoading) {
return (
<LoaderBoxStyled data-cy="loader-accounts-connection">
<CircularProgress />
Loading accounts...
</LoaderBoxStyled>
);
}
if (isLoadingMultisigs) {
return (
<MessageWrapper>
<CircularProgress />
<div>Loading your multisigs...</div>
</MessageWrapper>
);
}
if (multisigQueryError) {
return (
<MessageWrapper>
<ErrorMessageStyled>
<ErrorOutlineIcon size={64} />
<div>An error occurred.</div>
</ErrorMessageStyled>
</MessageWrapper>
);
}
if (multiProxyList.length === 0) {
return (
<MessageWrapper>
{showNewMultisigAlert ? <SuccessCreation /> : <ConnectOrWatch />}
</MessageWrapper>
);
}
return null;
};
export default useLoadingAndError;
Home page
const loadingAndErrorComponent = useLoadingAndError({
api,
isAccountLoading,
isLoadingMultisigs,
multisigQueryError,
multiProxyList,
showNewMultisigAlert,
selectedNetworkInfo,
});
if (loadingAndErrorComponent) {
return loadingAndErrorComponent;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that'd help make the Home easier to read, I may do it in a normal component though, rather than a hook.
edit: a hook allows to remove a lot of code from Home, so doing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed an update separating DisplayError
and DisplayLoader
, and keeping the rest as is for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the refactoring suggestion. Let me know if you want to work on it in the separate issue
All right, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thank you for the updates
closes #381
The flow of things was as follow
There are other flashing things like the "loading multisig" but it's a little more tricky to fix.
Submission checklist:
Layout