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 send page state management #10965

Merged
merged 4 commits into from
Jun 23, 2021
Merged

Refactor send page state management #10965

merged 4 commits into from
Jun 23, 2021

Conversation

brad-decker
Copy link
Contributor

@brad-decker brad-decker commented Apr 30, 2021

Refactor Send Page State Management

Problem Statements

  1. The "state" of the send page is not centralized making it near impossible to understand the logic because each component owns it's own impact on the state. The result was the same overall effect being applied in multiple places (ex: updating the max amount when the max button is clicked, AND anytime the gas field is modified AND anytime the asset was changed, each implementation in it's respective component's componentDidUpdate/lifecycle methods)
  2. The Components that make up the UI are too complex due to being the sole managers of state, making it near impossible to refactor or update.
  3. Changes required for future logic updates would need to be carried through many different places

Design goals of refactor

  1. No functional change to the UX.
  2. Centralize all state update logic as it pertains to the send page into a send slice using redux-toolkit.
  3. keep metamask/background state and send page state clearly separated.
  4. capture the intent of the send page, which is to create a draft transaction.
  5. eliminate any dead code found or created by way of this refactor
  6. adhere to the redux-toolkit design guide as much as possible

jsconfig.json Outdated Show resolved Hide resolved
@brad-decker brad-decker force-pushed the improve-send-slice branch 3 times, most recently from 07015e4 to d9d759a Compare May 3, 2021 15:36
app/scripts/controllers/transactions/index.js Outdated Show resolved Hide resolved
ui/ducks/app/app.js Outdated Show resolved Hide resolved
ui/ducks/app/app.js Outdated Show resolved Hide resolved
ui/ducks/app/app.test.js Outdated Show resolved Hide resolved
ui/ducks/metamask/metamask.js Outdated Show resolved Hide resolved
ui/pages/send/send.container.js Outdated Show resolved Hide resolved
ui/pages/send/send.utils.js Show resolved Hide resolved
ui/selectors/send.js Show resolved Hide resolved
ui/store/actions.js Outdated Show resolved Hide resolved
@metamaskbot
Copy link
Collaborator

Builds ready [d9d759a]
Page Load Metrics (776 ± 51 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint6010773115
domContentLoaded48789777410651
load48889877610651
domInteractive48689677410651

@brad-decker brad-decker marked this pull request as ready for review May 3, 2021 16:45
@brad-decker brad-decker requested a review from a team as a code owner May 3, 2021 16:45
ui/ducks/send/send.js Outdated Show resolved Hide resolved
ui/ducks/send/send.js Outdated Show resolved Hide resolved
@brad-decker brad-decker force-pushed the improve-send-slice branch from 0aac00b to e19e5d9 Compare May 12, 2021 19:40
@brad-decker brad-decker changed the title unravel send slice from metamask Refactor send page state management May 12, 2021
@brad-decker brad-decker force-pushed the improve-send-slice branch 4 times, most recently from b284d46 to 294b8c6 Compare May 12, 2021 22:05
ui/ducks/send/send.js Outdated Show resolved Hide resolved
ui/ducks/send/send.js Outdated Show resolved Hide resolved
ui/ducks/send/send.js Outdated Show resolved Hide resolved
ui/ducks/send/send.js Outdated Show resolved Hide resolved
ui/ducks/send/send.js Outdated Show resolved Hide resolved
ui/store/store.js Outdated Show resolved Hide resolved
ui/ducks/ens.js Show resolved Hide resolved
ui/pages/send/send.component.js Show resolved Hide resolved
ui/pages/send/send.js Outdated Show resolved Hide resolved
ui/pages/send/send.test.js Outdated Show resolved Hide resolved
ui/ducks/send/send.js Outdated Show resolved Hide resolved
ui/helpers/utils/token-util.js Outdated Show resolved Hide resolved
ui/ducks/send/send.js Outdated Show resolved Hide resolved
ui/ducks/send/send.js Show resolved Hide resolved
ui/ducks/send/send.js Outdated Show resolved Hide resolved
ui/ducks/send/send.js Show resolved Hide resolved
ui/ducks/send/send.js Outdated Show resolved Hide resolved
ui/ducks/send/send.js Outdated Show resolved Hide resolved
@metamaskbot
Copy link
Collaborator

Builds ready [8ef1d5e]
Page Load Metrics (601 ± 42 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint46726094
domContentLoaded3987175998842
load3997186018842
domInteractive3987175998842

ui/ducks/send/send.js Outdated Show resolved Hide resolved
@metamaskbot
Copy link
Collaborator

Builds ready [7209ec6]
Page Load Metrics (613 ± 52 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint52766373
domContentLoaded41073661210952
load41173761310952
domInteractive40973561210952

@Gudahtt
Copy link
Member

Gudahtt commented Jun 22, 2021

Everything looks good to me! I can re-review after the rebase

@brad-decker brad-decker requested a review from Gudahtt June 22, 2021 21:49
@metamaskbot
Copy link
Collaborator

Builds ready [849ca6a]
Page Load Metrics (673 ± 56 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint52856594
domContentLoaded41981967211756
load42182167311756
domInteractive41981967111756

Gudahtt
Gudahtt previously approved these changes Jun 23, 2021
@@ -2738,6 +2723,16 @@ export function estimateGas(params) {
return promisifiedBackground.estimateGas(params);
}

export async function updateTokenType(tokenAddress) {
let token = {};
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Guess you felt loading indicator wasn't required here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its handled at the callsite now, the loading indicator is shown anytime we updateAsset to a token asset.

@metamaskbot
Copy link
Collaborator

Builds ready [f7bb6c3]
Page Load Metrics (569 ± 46 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint44675884
domContentLoaded3806475689646
load3826495699646
domInteractive3806475679646

@@ -44,6 +44,7 @@ import {
hideLoadingIndication,
showConfTxPage,
showLoadingIndication,
updateTokenType,
Copy link
Contributor

Choose a reason for hiding this comment

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

So while trying to test this I re-found an issue similar to one I had been having while trying to tack a PR on top of the broad send-slice refactor.
Here it is, so entering the send flow the form status is immediately set to valid:
Screen Shot 2021-06-23 at 12 05 52 PM

once, however, I click the dropdown to select another token, the form becomes invalid:
Screen Shot 2021-06-23 at 12 06 22 PM

That is expected, but then I cannot get the form status to be valid again:
Screen Shot 2021-06-23 at 12 06 29 PM

even if I go back and select Eth as the send asset:
Screen Shot 2021-06-23 at 12 11 24 PM

I believe it has something to do with sequencing of actions and the gas loading thunk. The last call to validateSendState sets us to invalid here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you try 3d8ca2d out for a spin? see if the issue persists?

Copy link
Contributor

Choose a reason for hiding this comment

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

@brad-decker That commit seems to have fixed the issue, 🚀

@@ -843,6 +845,10 @@ const slice = createSlice({
):
state.status = SEND_STATUSES.INVALID;
break;
case state.asset.type === ASSET_TYPES.TOKEN &&
Copy link
Contributor

Choose a reason for hiding this comment

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

not req but wondering if it makes sense to separate this out so that asset has an error field, as we do with amount and gas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i was thinking that when I was working through erc721 updates, i think its a definite candidate for an improvement but not to be handled here.

@metamaskbot
Copy link
Collaborator

Builds ready [3d8ca2d]
Page Load Metrics (614 ± 52 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint459363115
domContentLoaded36575861210852
load36675961410852
domInteractive36575861210852

@PeterYinusa
Copy link
Contributor

LGTM!

@metamaskbot
Copy link
Collaborator

Builds ready [0320dff]
Page Load Metrics (560 ± 33 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint46696163
domContentLoaded3776345586933
load3796365606933
domInteractive3776345586933

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -1,7 +1,7 @@
import { connect } from 'react-redux';
Copy link
Contributor

@adonesky1 adonesky1 Jun 23, 2021

Choose a reason for hiding this comment

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

At some point - not in this PR - we should consider renaming some of these files/components/containers that refer to ether towards more chain-agnostic language, like you do throughout this PR

Copy link
Contributor

@darkwing darkwing left a comment

Choose a reason for hiding this comment

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

Tested this a bunch and the code looks good! Let's gooooooo!

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

Amazing work Brad! LGTM

@brad-decker brad-decker merged commit c30cb7d into develop Jun 23, 2021
@brad-decker brad-decker deleted the improve-send-slice branch June 23, 2021 21:35
@github-actions github-actions bot locked and limited conversation to collaborators Jun 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants