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

Fix to infinite loading on approve screen #14756

Merged
merged 6 commits into from
Jun 11, 2022
Merged

Conversation

adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented May 20, 2022

Fixes issue where screen for confirming approve() method calls gets stuck in infinite loading (#14459 & #14589 & #14518). This is set to be partially addressed when the commit associated with this PR is merged into the extension. It will be further addressed something like this WIP PR (the exact form of which is still being discussed). Even with these fixes however, there are still contracts for which the issue will not be resolved. The ENS ERC721 contract for example does not implement either a symbol() or name() method the result of which the approve screen currently relies upon. This PR simply adds a fallback value of "" for the symbol so that once we're done loading contract data the symbol will not be undefined no matter what, allowing us to move past the loading screen.

This fixes a regression introduced in this PR: #13788

@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot
Copy link
Collaborator

Builds ready [d1f8da5]
Page Load Metrics (1631 ± 30 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint7614494178
domContentLoaded1559173716215727
load1560175316316330
domInteractive1559173716215727

@adonesky1 adonesky1 changed the title [WIP] - quick fix to infinite loading on approve screen Quick fix to infinite loading on approve screen May 20, 2022
@adonesky1 adonesky1 changed the title Quick fix to infinite loading on approve screen Fix to infinite loading on approve screen May 20, 2022
@adonesky1 adonesky1 marked this pull request as ready for review May 20, 2022 22:06
@adonesky1 adonesky1 requested a review from a team as a code owner May 20, 2022 22:06
@adonesky1 adonesky1 requested review from PeterYinusa and danjm May 20, 2022 22:06
@adonesky1 adonesky1 force-pushed the fix-approve-infinite-spin branch from c6ee02e to 99e6fb6 Compare May 20, 2022 22:40
darkwing
darkwing previously approved these changes May 23, 2022
@metamaskbot
Copy link
Collaborator

Builds ready [99e6fb6]
Page Load Metrics (1736 ± 51 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint76151102178
domContentLoaded1583188317109445
load15841960173610651
domInteractive1583188317109445

@adonesky1
Copy link
Contributor Author

While this is definitely better than infinite loading we should probably do a bit of UX improvement for the cases where someone is calling approve on a token contract that does not match one of the three supported contract types (ERC20, ERC721, ERC1155)

Screen Shot 2022-05-23 at 11 17 27 AM

I know we're going to redesign these screens pretty soon so probably not worth a ton of effort but something small to help us cross the bridge for now? Maybe just a copy change saying something like: "Unable to determine token standard, name or symbol. Approving will grant allowance for this unidentifiable token to the following address." ?

@rachelcope @holantonela

@rachelcope
Copy link

How about Give permission to access your token?

ryanml
ryanml previously approved these changes May 24, 2022
@adonesky1
Copy link
Contributor Author

@adonesky1
Copy link
Contributor Author

adonesky1 commented May 25, 2022

Updated this fix to include additional context - a link to the contract on the blockexplorer - for the user to be sure they know what they are approving in cases where we don't have complete information:

Decentraland (LAND):
Doesn't fully implement the metadata interface currently preventing us from fetching the name/symbol correctly. Once MetaMask/core#834 is pulled into the extension, we will see the name of the asset too, but until then:
https://user-images.githubusercontent.com/34557516/170384627-d8df6e74-61bd-4cdd-b6c1-75378c5aad18.mov

CryptoKitties (CK)
Doesn't fully implement the ERC721 interface, so don't show the name of the token or the tokenId correctly. This will be partially resolved by MetaMask/core#834 -> we will show the asset name.
https://user-images.githubusercontent.com/34557516/170384950-c6e0a231-b5d1-476e-9ba3-78e517f38374.mov

ENS
Doesn't implement the ERC721 metadata interface at all (so no name() or symbol()) so this won't change once MetaMask/core#834 is merged.
https://user-images.githubusercontent.com/34557516/170385792-412f8b64-9be9-4de3-9a94-ccf664af1008.mov

In my opinion this adds critical context with the link to allow users to verify the contract via the block-explorer as a backstop when we don't have name or symbol for the context on this screen. We should be adding the contract (both a link and legible address) but this is an improvement for now. I understand that @SayaGT has an improved approve screen in the works.

@adonesky1 adonesky1 dismissed stale reviews from ryanml and darkwing via 9a983f1 May 25, 2022 23:36
@adonesky1 adonesky1 force-pushed the fix-approve-infinite-spin branch from 9a983f1 to 6f2860a Compare May 25, 2022 23:36
@adonesky1 adonesky1 requested review from darkwing and ryanml May 25, 2022 23:36
@metamaskbot
Copy link
Collaborator

Builds ready [6f2860a]
Page Load Metrics (2081 ± 168 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint871866294515247
domContentLoaded166028752053356171
load166028752081350168
domInteractive165928752053356171

highlights:

storybook

@adonesky1 adonesky1 force-pushed the fix-approve-infinite-spin branch from 6f2860a to aa19c32 Compare May 26, 2022 14:52
@metamaskbot
Copy link
Collaborator

Builds ready [aa19c32]
Page Load Metrics (1852 ± 66 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint91146106136
domContentLoaded16552242184213565
load16552242185213866
domInteractive16552242184213565

highlights:

storybook

@adonesky1 adonesky1 force-pushed the fix-approve-infinite-spin branch from aa19c32 to b4b70c0 Compare May 26, 2022 18:27
@metamaskbot
Copy link
Collaborator

Builds ready [b4b70c0]
Page Load Metrics (1747 ± 55 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint822731103919
domContentLoaded15332008171811053
load15952029174711555
domInteractive15332008171811053

highlights:

storybook

@darkwing
Copy link
Contributor

Code looks good and works, but I"m wondering if there's a test we can add to prevent regressions, since the ERC logic is and symbol asset stuff presents many cases.

@adonesky1
Copy link
Contributor Author

@darkwing I believe @SayaGT has a new design for the approve screen in the works. I'm happy to add tests, just have been a bit hesitant to pour too much effort into this since we're going to rebuild it pretty soon as I understand it.

@hashwarp
Copy link

Pour please 🍷 🙏

More than a few projects halted due to this issue and even if you rebuild it, I assume you'll want a stable/LTS legacy just incase because with changes like this it's breaking support for who knows how many projects.

@darkwing
Copy link
Contributor

darkwing commented Jun 1, 2022

I think a test would be helpful -- do we know when that redesign is scheduled for? Even still, I think it could take months for that new UI to hit.

@adonesky1
Copy link
Contributor Author

adonesky1 commented Jun 2, 2022

I think additionally we should add e2e tests for this flow that include non-standard tokens

@adonesky1
Copy link
Contributor Author

@darkwing I actually don't think we should extract getTitleTokenDescription as a helper function. Won't realistically be used anywhere else. I'm turning my efforts to adding a non-standard token flow in the test-dapp instead, which will add coverage for this functionality much better anyways

@adonesky1
Copy link
Contributor Author

adonesky1 commented Jun 3, 2022

Added test coverage to partially cover us against regressions for this: useAssetDetails test

but I am also working on adding non-standard tokens e2e tests, with some additions to test-dapp

These tests I just added are throwing the Warning: An update to TestHook inside a test was not wrapped in act(...).... Trying to figure out the right way to handle this. Have tried a few different things so far including using waitForNextUpdate, but not finding the right solution yet. Have you encountered this before @darkwing, @brad-decker @mcmire?

@adonesky1 adonesky1 force-pushed the fix-approve-infinite-spin branch from 025f32a to 90b32ff Compare June 3, 2022 22:47
@mcmire
Copy link
Contributor

mcmire commented Jun 3, 2022

@adonesky1 It looks like you're awaiting renderUseAssetDetails in your test. I think if you take this off it should allow you to await waitForNextUpdate() right after that.

@adonesky1
Copy link
Contributor Author

It looks like you're awaiting renderUseAssetDetails in your test. I think if you take this off it should allow you to await waitForNextUpdate() right after that

Unfortunately I'm still getting the warning (Warning: An update to TestHook inside a test was not wrapped in act(...)) when using this pattern

@metamaskbot
Copy link
Collaborator

Builds ready [974ba83]
Page Load Metrics (1688 ± 35 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint7812898157
domContentLoaded1574189216656832
load1574191216887435
domInteractive1573189216656832

highlights:

storybook

@mcmire
Copy link
Contributor

mcmire commented Jun 6, 2022

@adonesky1 waitForNextUpdate is a function. So you need to say await waitForNextUpdate().

@mcmire
Copy link
Contributor

mcmire commented Jun 6, 2022

I changed the first test to this and it seemed to work:

  it('should return object with tokenSymbol set to and empty string, when getAssetDetails returns and empty object', async () => {
    const toAddress = '000000000000000000000000000000000000dead';
    const tokenAddress = '0x1';

    const transactionData = `0xa9059cbb000000000000000000000000${toAddress}000000000000000000000000000000000000000000000000016345785d8a0000`;

    const { result, waitForNextUpdate } = renderUseAssetDetails({
      tokenAddress,
      userAddress: '0x111',
      transactionData,
    });

    await waitForNextUpdate();

    expect(result.current).toStrictEqual({
      assetAddress: tokenAddress,
      assetName: undefined,
      assetStandard: undefined,
      decimals: undefined,
      toAddress: `0x${toAddress}`,
      tokenAmount: undefined,
      tokenId: undefined,
      tokenImage: undefined,
      tokenSymbol: '',
      tokenValue: undefined,
      userBalance: undefined,
    });
  });

@adonesky1
Copy link
Contributor Author

@adonesky1 waitForNextUpdate is a function. So you need to say await waitForNextUpdate().

😜 I meant to do that... whoops! Thanks for the call out!

@adonesky1 adonesky1 force-pushed the fix-approve-infinite-spin branch from acf957d to d8e17ef Compare June 6, 2022 16:59
@adonesky1
Copy link
Contributor Author

@adonesky1 waitForNextUpdate is a function. So you need to say await waitForNextUpdate().

@mcmire fixed here: d8e17ef

@adonesky1 adonesky1 requested a review from darkwing June 6, 2022 17:00
@mcmire
Copy link
Contributor

mcmire commented Jun 6, 2022

@adonesky1 Nice! That matches what I was able to do locally :)

@metamaskbot
Copy link
Collaborator

Builds ready [d8e17ef]
Page Load Metrics (1843 ± 37 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint90155106147
domContentLoaded1655198918077335
load1674201318437837
domInteractive1654198918077335

highlights:

storybook

const collectibles = useSelector(getCollectibles);
const tokenList = useSelector(getTokenList);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

tokens and tokenList were never used by this hook, they had been at one point while developing it initially, but can be safely removed.

const tokenData = parseStandardTokenTransactionData(transactionData);
assetStandard = standard;
assetAddress = tokenAddress;
tokenSymbol = symbol;
tokenSymbol = 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 the basic fix to the regression I introduced here some months back. With this tokenSymbol will never be undefined allowing the confirmApprove screen to load.

Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

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

LGTM, nice work

@adonesky1 adonesky1 merged commit b170211 into develop Jun 11, 2022
@adonesky1 adonesky1 deleted the fix-approve-infinite-spin branch June 11, 2022 17:55
@github-actions github-actions bot locked and limited conversation to collaborators Jun 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants