Skip to content

feat: finish swap+send UI and handle transactions#23889

Merged
BZahory merged 60 commits intomb843/swap-and-sendfrom
mb843/ui-2
May 1, 2024
Merged

feat: finish swap+send UI and handle transactions#23889
BZahory merged 60 commits intomb843/swap-and-sendfrom
mb843/ui-2

Conversation

@BZahory
Copy link
Copy Markdown
Contributor

@BZahory BZahory commented Apr 8, 2024

Description

Open in GitHub Codespaces

Related issues

Fixes:

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@BZahory BZahory requested review from a team as code owners April 8, 2024 13:48
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2024

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.

@BZahory BZahory changed the base branch from develop to mb843/data-flows April 8, 2024 13:49
address: PropTypes.string,
symbol: PropTypes.string,
decimals: PropTypes.number,
decimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What causes this to be a string? Can the value be normalized to a number on selection, before it's passed into this component?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's a mistype somewhere. The commit (a5a5417) was made in response to a console error (not thrown) regarding an invalid prop type being passed. Also doesn't hurt to have a bit of extra robustness anyways.

setTokenDecimalValue(newTokenDecimalValue);
setFiatDecimalValue(newFiatDecimalValue);

// timeout intentionally not cleared so this always runs
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you mean by this? Won't a new timeout always be created when the dependencies change anyway, assuming the component is not unmounted?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, why is the timeout needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If the dependencies update but Number(decimalizedHexValue) === Number(tokenDecimalValue) is true, then the timeout won't be ran after the update.

The ref doesn't update on the input state variable's (or any state variable's) cadence, so we need a delay to give the input – and its ref – time to update before checking.


const NATIVE_CURRENCY_DECIMALS = 18;

export default function useGetConversionRate() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you adding unit tests for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah will do in the testing PR

Comment on lines +7 to +8
export default function useTranslatedNetworkName() {
const chainId = useSelector(getCurrentChainId);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you adding unit tests for this?

draftTransactionInitialState.swapQuotesError;
draftTransaction.isSwapQuoteLoading =
draftTransactionInitialState.isSwapQuoteLoading;
draftTransaction.swapQuotesLatestRequestTimestamp =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can the latestFetchTime value be derived from this?

Copy link
Copy Markdown
Contributor Author

@BZahory BZahory Apr 18, 2024

Choose a reason for hiding this comment

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

swapQuotesLatestRequestTimestamp is the time of the request, not the response. It's used for cleaning up multiple ongoing fetches

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is there an abort functionality we can use? similar to the AbortController in portfolio

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried that but the quotes kept coming through anyways sometimes IIRC

Comment on lines +2107 to +2114
const isSwapAndSend =
draftTransaction?.sendAsset?.details?.address !==
draftTransaction?.receiveAsset?.details?.address;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Extract to a selector?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Selectors are created later in the file (i.e., after usage)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good point. Maybe an internal method then? This condition is used multiple times so that would keep them in sync and reusable

Comment on lines 2749 to +2755
const quotesAsArray = Object.values(quotes || {});
if (isSwapQuoteLoading || swapQuotesError || !quotesAsArray.length) {
if (swapQuotesError || !quotesAsArray.length) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are the keys of quotes used? If not, it might make more sense to store the quotes as an array in state

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it fine if I revisit this once the best quote logic is finalized?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sure, can you add it to the TODO list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in the next PR: aff8ab57c46d942cb0278ed7c42c8a59fe073eba

@BZahory BZahory merged commit f0455a3 into mb843/swap-and-send May 1, 2024
@BZahory BZahory deleted the mb843/ui-2 branch May 1, 2024 20:14
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
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.

2 participants