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: [DetailsV2] instant buy #6599

Merged
merged 17 commits into from
May 22, 2023
Merged

feat: [DetailsV2] instant buy #6599

merged 17 commits into from
May 22, 2023

Conversation

JackShort
Copy link
Contributor

@JackShort JackShort commented May 18, 2023

Implementing single purchase asset for nft details. Design has not figured out the way to handle price changes yet or assets that happen to be unavailable so right now we just return and don't execute a metamask transaction.

Automated testing

  • Unit test

@vercel
Copy link

vercel bot commented May 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
interface ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2023 6:34pm

@codecov
Copy link

codecov bot commented May 18, 2023

Codecov Report

Patch coverage: 59.09% and project coverage change: -0.26 ⚠️

Comparison is base (f3a80c6) 60.18% compared to head (84371a9) 59.92%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6599      +/-   ##
==========================================
- Coverage   60.18%   59.92%   -0.26%     
==========================================
  Files         719      721       +2     
  Lines       21143    21176      +33     
  Branches     6974     6981       +7     
==========================================
- Hits        12724    12689      -35     
- Misses       8342     8408      +66     
- Partials       77       79       +2     
Flag Coverage Δ
e2e-tests 60.43% <20.45%> (-0.21%) ⬇️
unit-tests 21.18% <59.09%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ft/components/details/detailsV2/DataPageHeader.tsx 100.00% <ø> (ø)
...c/nft/components/details/detailsV2/LandingPage.tsx 80.00% <ø> (ø)
src/nft/hooks/usePurchaseAssets.ts 46.66% <ø> (ø)
src/nft/hooks/useFetchAssets.ts 30.90% <31.81%> (+0.60%) ⬆️
src/nft/components/details/detailsV2/BuyButton.tsx 78.57% <78.57%> (ø)
...c/nft/components/details/detailsV2/OfferButton.tsx 100.00% <100.00%> (ø)
src/nft/components/details/detailsV2/shared.ts 60.00% <100.00%> (+4.44%) ⬆️
src/nft/utils/buildSellObject.ts 27.27% <100.00%> (ø)

... and 21 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@JackShort JackShort requested review from cbachmeier, a team and cmcewen May 18, 2023 19:50
@JackShort JackShort marked this pull request as ready for review May 18, 2023 19:51
src/nft/components/details/detailsV2/BuyButton.tsx Outdated Show resolved Hide resolved
src/nft/components/details/detailsV2/BuyButton.tsx Outdated Show resolved Hide resolved
src/nft/hooks/useFetchAssets.ts Outdated Show resolved Hide resolved
@@ -100,3 +106,48 @@ export function useFetchAssets(): () => Promise<void> {
tokenTradeInput,
])
}

export const useFetchSingleAsset = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of this code is duplicated from useFetchAssets. Have you tried when a users hits the buy button to add it to the bag, keep the bag hidden, and then just call useFetchAssets()? This would pair well with the updated designs for handling price changes as then you'd just have to reveal the bag.

Copy link
Contributor

Choose a reason for hiding this comment

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

The follow up would be if a user already has items in their bag. In that case you could add an optional asset? param to useFetchAsset which would override using the assets currently in the bag.

Copy link
Contributor Author

@JackShort JackShort May 19, 2023

Choose a reason for hiding this comment

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

I think the surface area between those two functions are actually very low there are only a few lines of code that they share in similiarity and the useFetchAssets function deals a lot with the bagstate which this should not touch. Also this has different outputs, design has decided that if the item is unavailable or if there is a price change to send it over to the bag. This would result in a flag being added to the fetch query and you would basically have two different functions running in one, so I really think it would be best just to separate it out. Also if the useFetchAssets query changed this doesn't need to change I don't see any reason they need to be coupled other than calling the same functions both are calling

Copy link
Contributor

Choose a reason for hiding this comment

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

This function would still need to touch bag state in the case of a price change since we'll need to display that change in the bag to the user to review. If we leverage useFetchAssets that logic is already handled for us. The only substantial change for the fetch query would be a conditional on nftTrades: singleAsset ? buildNftTradeInput([singleAsset]) : buildNftTradeInputFromBagItems(itemsInBag), the rest of the logic should be able to be left untouched.

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 am currently working on handling updated price in bag with a prompt - when that pr comes in I will be in a better place to see if we can merge the two functions until then I propose separate and if it looks like they can be combined I will

Copy link
Contributor

Choose a reason for hiding this comment

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

this seems like it is returning a callback to purchase the asset (and fetch related data). so it seems like useBuyAssetCallback might be a better name? otherwise i would think this function just gives me the data for the asset

@cypress
Copy link

cypress bot commented May 19, 2023

1 flaky tests on run #11173 ↗︎

0 69 8 0 Flakiness 1

Details:

feat: [DetailsV2] instant buy
Project: Uniswap Interface Commit: 84371a989a
Status: Passed Duration: 04:33 💡
Started: May 22, 2023 6:33 PM Ended: May 22, 2023 6:37 PM
Flakiness  cypress/e2e/swap/swap.test.ts • 1 flaky test • e2e

View Output Video

Test Artifacts
Swap > Swap on main page > swaps ETH for USDC Output Screenshots Video

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

Copy link
Contributor

@cbachmeier cbachmeier left a comment

Choose a reason for hiding this comment

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

unable to 1 click buy pooled assets with no price change, see #6599 (comment)

@JackShort JackShort temporarily deployed to false May 22, 2023 16:41 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 16:41 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 16:41 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 16:46 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 16:46 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 16:46 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 16:46 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 16:52 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 16:52 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 16:52 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 16:52 — with GitHub Actions Inactive

return (
<>
<StyledBuyButton disabled={isLoadingRoute} onClick={() => fetchAndPurchaseSingleAsset(asset)}>
Copy link
Contributor

Choose a reason for hiding this comment

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

could go either way here but you could useCallback

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 am a little confused by this comment it is using a callback - wondering if you could explain more as to what you would like me to do here

Copy link
Contributor

Choose a reason for hiding this comment

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

the onClick function takes a function, which you create new every render. you could use useCallback to keep the function referentially equal if you want, but since this is a simple component and unlikely to change, it's a bit of a wash

@@ -100,3 +106,48 @@ export function useFetchAssets(): () => Promise<void> {
tokenTradeInput,
])
}

export const useFetchSingleAsset = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems like it is returning a callback to purchase the asset (and fetch related data). so it seems like useBuyAssetCallback might be a better name? otherwise i would think this function just gives me the data for the asset

Copy link
Contributor

@cbachmeier cbachmeier left a comment

Choose a reason for hiding this comment

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

LGTM. Successfully 1 click purchased pooled asset

@JackShort JackShort temporarily deployed to false May 22, 2023 18:24 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 18:24 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 18:24 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 18:24 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 18:31 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 18:31 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 18:31 — with GitHub Actions Inactive
@JackShort JackShort temporarily deployed to false May 22, 2023 18:31 — with GitHub Actions Inactive
@JackShort JackShort requested a review from cmcewen May 22, 2023 19:23
@JackShort JackShort merged commit caa2524 into main May 22, 2023
20 of 25 checks passed
@JackShort JackShort deleted the jack/singleAssetBuy branch May 22, 2023 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants