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

feat: finish up UI changes and code styling #24429

Merged
merged 97 commits into from
May 24, 2024
Merged

Conversation

BZahory
Copy link
Contributor

@BZahory BZahory commented May 8, 2024

No description provided.

@BZahory BZahory requested a review from a team as a code owner May 8, 2024 10:46
Copy link
Contributor

github-actions bot commented May 8, 2024

CLA Signature Action:

Thank you for your submission, we really appreciate it. We ask that you all read and sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just by adding a comment to this pull request with this exact sentence:

I have read the CLA Document and I hereby sign the CLA

By commenting with the above message you are agreeing to the terms of the CLA. Your account will be recorded as agreeing to our CLA so you don't need to sign it again for future contributions to this repository.

1 out of 2 committers have signed the CLA.
@BZahory
@ejwessel

Base automatically changed from mb843/updates to mb843/swap-and-send May 8, 2024 17:50
@micaelae micaelae requested review from a team as code owners May 8, 2024 17:50
ui/ducks/send/send.js Outdated Show resolved Hide resolved
ui/ducks/send/send.js Outdated Show resolved Hide resolved
@@ -93,6 +98,7 @@ export function SwappableCurrencyInput({
)}
asset={asset?.details}
isSkeleton={isAmountLoading}
isMatchingUpstream={isSetToMax}
Copy link
Member

Choose a reason for hiding this comment

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

Why not just call const isSetToMax = useSelector(getSendMaxModeState); in CurrencyInput?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CurrencyInput should be decoupled from Send logic (see: #23192 (comment))

Copy link
Member

@micaelae micaelae May 15, 2024

Choose a reason for hiding this comment

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

Gotcha, I think the naming could be more descriptive then - maybe shouldSyncValueWithUpstreamState

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't starting with "is" convention?

Copy link
Member

Choose a reason for hiding this comment

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

hmm good point - looks like is/has/can is the convention. I'm good with any prefix as long as the name is more descriptive

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm yeah, it's tricky because it's technically always syncing with the upstream; this explicitly says that it will always match the upstream

// symbol to cover edge case where initial value is literally 'INITIAL_VALUE'
const INITIAL_VALUE = Symbol('INITIAL_VALUE');

export default function useStateWithFirstTouch<T>(
Copy link
Member

Choose a reason for hiding this comment

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

Which bug does this address?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It lets us know if the token amount has been modified by a user input in CurrencyInput so we can know if the amount is being updated upstream after opening the send flow via the "EDIT" flow

Copy link
Member

Choose a reason for hiding this comment

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

gotcha, i feel like there's some way we can use the usePrevious hook within or instead of this hook. no need to look into it if there's other things to fix tho. unless the usage is obvious (i didn't dive too deep)

can this be reused instead of setIsTokenInputChanged in asset-picker-amount or are the behaviors different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a little different since we are able to reset that one, so a normal state will do there. useStateWithFirstTouch should do for now imo – it's the cleanest solution I can think of

@@ -22,7 +22,7 @@ export function NFTInput({ integerValue, onChange, className }: NFTInputProps) {
return;
}

onChange(newValue.toPrefixedHexString());
onChange(newValue.toPrefixedHexString(), String(newValueAsString));
};

return (
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to make the amount input autofocus? That's the behavior for tokens, but doesn't seem to work for NFTs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

autofocus is super inconsistent so I just added logic to focus on key press if that's okay

Copy link
Member

Choose a reason for hiding this comment

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

I see it working when I click Send from the NFTs tab in the overview. But not if I go to the NFTs tab from within Send. Low priority tho, so the latest version lgtm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I see it working for both

ui/ducks/send/send.js Outdated Show resolved Hide resolved
ui/ducks/send/send.js Outdated Show resolved Hide resolved
BZahory added a commit to MetaMask/core that referenced this pull request May 21, 2024
## Explanation

### What is the current state of things and why does it need to change?

With MetaMask/metamask-extension#23703, we will
be implementing a new type of transaction, swap+send – a swap targeting
the recipient. To properly track this transaction, we will need a new
transaction type with new properties.

### What is the solution your changes offer and how does it work?

We add a new `swapAndSend` transaction type with properties that track
the source+destination tokens, as well as the recipient.

### Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?

We include certain swap properties that we may not use initially (e.g.,
`swapTokenValue`, `swapMetaData`) in case we add more parity with the
swaps functionality over time.

### If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?

The `TransactionType` enum was abstracted to this library rather than
the Extension.

### If you had to upgrade a dependency, why did you do so?

N/A

## References

[MB-843](https://consensyssoftware.atlassian.net/browse/METABRIDGE-843)

MetaMask/metamask-extension#23703
(MetaMask/metamask-extension#24429 latest in
merge train targeting that branch)

<!--
Are there any issues that this pull request is tied to? Are there other
links that reviewers should consult to understand these changes better?


For example:

* -->

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/transaction-controller`

- **ADDED**: `swapAndSend` type and respective 
- **ADDED**: `updateSwapAndSendTransaction()`
- **ADDED**: `TransactionMetaBase` properties: `destinationTokenAmount`,
`sourceTokenAddress`, `sourceTokenAmount`, `sourceTokenDecimals`,
`swapAndSendRecipient`

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
@@ -140,6 +140,9 @@ const QUOTE_VALIDATORS = [
type: 'number',
},
];

const SWAP_AND_SEND_SLIPPAGE = '2';
Copy link
Member

Choose a reason for hiding this comment

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

just confirming, does swaps have a default slippage and is it the same as this?

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 couldn't find one. I just found this code in review-quote.js:

const [slippageErrorKey] = useState(() => {
    const slippage = Number(fetchParams?.slippage);
    if (slippage > 0 && slippage <= 1) {
      return SLIPPAGE_LOW_ERROR;
    } else if (slippage >= 5 && slippage <= MAX_ALLOWED_SLIPPAGE) {
      return SLIPPAGE_HIGH_ERROR;
    }
    return '';
  });

This indicates that the range for swaps quotes is 1-5 (both exclusive). I'd imagine we'd want to be on the lower end given the typical use cases for a send, so 2 seems like a clean number to choose.

legobeat

This comment was marked as off-topic.

@legobeat legobeat dismissed their stale review May 23, 2024 02:02

this is not rageting develop

@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label May 23, 2024
Comment on lines +32 to +34
&--size-xs {
--button-icon-size: 20px;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be removed? Started a discussion in slack regarding changes in #24150

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will address both comments in a follow-up PR in the merge train

@@ -58,7 +58,7 @@
text-decoration: none;
}

&--disable-underline:hover:not(&--disabled){
&--disable-underline:hover:not(&--disabled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment above

@@ -2804,7 +2806,8 @@ export function signTransaction(history) {

await dispatch(actions.setPrevSwapAndSend(prevSwapAndSendData));

if (stage === SEND_STAGES.EDIT) {
// you can only edit a basic send transaction
if (stage === SEND_STAGES.EDIT && !isSwapAndSend) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean we can remove the prev swap send state from redux as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory but I’d rather keep it for now since we may be reutilizing it p soon. A bit of a boat anchor that we can clear pending future discussion on confirmations

@BZahory BZahory merged commit 06f2924 into mb843/swap-and-send May 24, 2024
49 of 63 checks passed
@BZahory BZahory deleted the mb843/updates-2 branch May 24, 2024 20:50
@github-actions github-actions bot locked and limited conversation to collaborators May 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
INVALID-PR-TEMPLATE PR's body doesn't match template
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants