-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Fixed navigation through multiple unapproved transactions for ERC20 tokens #16822
Fixed navigation through multiple unapproved transactions for ERC20 tokens #16822
Conversation
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. |
Verified by QA |
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.
Look good 👍
991f5d8
to
b8553f9
Compare
Builds ready [b8553f9]
Page Load Metrics (2233 ± 140 ms)
Bundle size diffs
highlights: |
const network = hexToDecimal(fullTxData.chainId); | ||
|
||
const currentNetworkUnapprovedTxs = Object.keys(unapprovedTxs) | ||
.filter((key) => | ||
transactionMatchesNetwork( | ||
unapprovedTxs[key], | ||
fullTxData.chainId, | ||
network, | ||
), | ||
) | ||
.reduce((acc, key) => ({ ...acc, [key]: unapprovedTxs[key] }), {}); | ||
|
||
const enumUnapprovedTxs = Object.keys(currentNetworkUnapprovedTxs); | ||
const currentPosition = enumUnapprovedTxs.indexOf( | ||
fullTxData.id ? fullTxData.id.toString() : '', | ||
); | ||
|
||
const totalTx = enumUnapprovedTxs.length; | ||
const positionOfCurrentTx = currentPosition + 1; | ||
const nextTxId = enumUnapprovedTxs[currentPosition + 1]; | ||
const prevTxId = enumUnapprovedTxs[currentPosition - 1]; | ||
const showNavigation = enumUnapprovedTxs.length > 1; | ||
const firstTx = enumUnapprovedTxs[0]; | ||
const lastTx = enumUnapprovedTxs[enumUnapprovedTxs.length - 1]; | ||
|
||
const handleNextTx = (txId) => { | ||
if (txId) { | ||
dispatch(clearConfirmTransaction()); | ||
history.push(`${CONFIRM_TRANSACTION_ROUTE}/${txId}`); | ||
} | ||
}; |
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 don't think this is problematic but what I'm wondering is if there's an opportunity to improve the readability of our code by relocating and consolidating this logic and the 'confirm-transaction-base.container.js' files logic and move it into the <ConfirmPageContainerNavigation>
component which appears to already be a functional component. Doing this would make that specific part of our code much more understandable and perhaps prevent needing to do this selector logic in multiple places.
Could you take a look into this and see how much effort it'll be to consolidate? Thanks @filipsekulic
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.
Hey @brad-decker! Good suggestion!
I refactored the code and you can see the changes here: f4b0938
However, there is a problem and you can see it in the attached screenshot, which is the reason why the pipeline is failing (e2e test
).
This happens when there are multiple token approvals and when a user confirms one of them, the navigation disappears for some reason and throws the error (screenshot attached). I think the problem is in the confirm-page-container.component.js
within the async componentDidMount
, which the error message is also suggesting (...cancel all subscriptions and asynchronous tasks...
).
I would appreciate if you could take a look and give your opinion on this one.
4309ec0
to
f4b0938
Compare
const txData = useSelector(getTxData); | ||
|
||
const network = hexToDecimal(txData.chainId); | ||
|
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.
The "Navigate transactions - should confirm and remove an unapproved transaction" e2e test is failing because: TimeoutError: Waiting for element to be located By(xpath, .//*[contains(concat(' ', normalize-space(./@class), ' '), ' confirm-page-container-navigation ')][(contains(string(.), '1 of 3') or contains(string(.), '1of3'))])
This probably means that during the e2e test run showNavigation
is false, which probably means that enumUnapprovedTxs
is an empty array. Looking at this new code for getting currentNetworkUnapprovedTxs
compared to the old code in confirm-transaction-base.container.js
, I notice that the chainId
and network
are here derived from the transaction but in confirm-transaction-base.container.js
they are taken directly from state.metamask
.
If this feature is working when running it manually in the browser, for both custom approvals and erc-20 token transfers, then the problem is likely in e2e test fixtures (unless there is something wrong with getting the chainId and network from the transaction?... I don't think so, but worth a double check)
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 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.
why did you have to change it so that txData
is being passed in, instead of being selected? what problem did that solve?
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.
When a user tries to confirm one of the transactions, it now shows the navigation, but doesn't get updated as it should - txData
object being selected becomes empty, next tx
cannot be seen on the next page and currentPosition
is -1
as the currentTx
cannot be found from enumUnapprovedTxs
, because there is no txId
from txData
object which is empty at that moment.
Screencast:
Screen.Recording.2022-12-20.at.16.05.36.mov
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.
txData is derived from state in confirm-transaction-base.container.js which means we can get it here without drilling the prop down the line
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 get it, but the problem with it is that somehow the txData
gets empty when one of the transactions is confirmed.
You can see it in the above attached video where txDataFromSelector
is actually the transaction data derived from state. I console.log
-ged it in order to show this problem...
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 was the code for getting txDataFromSelector
? was it derived from state in the exact same way as it is in confirm-transaction-base.container.js
?
344d0df
to
1d005ae
Compare
Builds ready [1d005ae]
Page Load Metrics (2115 ± 86 ms)
Bundle size diffs
highlights: |
const txData = useSelector(getTxData); | ||
|
||
const network = hexToDecimal(txData.chainId); | ||
|
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.
txData is derived from state in confirm-transaction-base.container.js which means we can get it here without drilling the prop down the line
1d005ae
to
094315d
Compare
Builds ready [094315d]
Page Load Metrics (1455 ± 93 ms)
Bundle size diffs
highlights: |
094315d
to
8220055
Compare
Builds ready [453de3c]
Page Load Metrics (1627 ± 157 ms)
Bundle size diffs
highlights: |
@brad-decker |
Explanation
Fixed navigation through multiple unapproved transactions for ERC20 tokens.
approve
transactions #16768Screenshots/Screencaps
Before
Before.mov
After
After.mov
Manual Testing Steps
ERC20
tokenAPPROVE TOKENS
multiple times