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: nft view page cta module and responsive style updates #55

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

domw30
Copy link
Collaborator

@domw30 domw30 commented Nov 25, 2022

Associated Notion Card


1. Pull request checklist

  • Notion card has been moved to the Code Review column
  • Notion card has a link to this PR
  • A reviewer has been assigned to the Notion card

2. PR type

  • feature
  • refactor

Updates to the CTA Module to help improve the NFT View page.

Some examples:

Screenshot 2022-12-06 at 16 15 40

Screenshot 2022-12-06 at 16 09 28

Screenshot 2022-12-06 at 15 59 08

Screenshot 2022-12-06 at 15 54 15

Screenshot 2022-12-06 at 16 18 59

Screenshot 2022-12-06 at 16 19 34

@netlify
Copy link

netlify bot commented Nov 28, 2022

Deploy Preview for zapp-nft ready!

Name Link
🔨 Latest commit 0089d3b
🔍 Latest deploy log https://app.netlify.com/sites/zapp-nft/deploys/63988851a22973000899a25d
😎 Deploy Preview https://deploy-preview-55--zapp-nft.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@domw30 domw30 self-assigned this Dec 6, 2022
@domw30 domw30 added the enhancement New feature or request label Dec 6, 2022
@domw30 domw30 marked this pull request as ready for review December 6, 2022 15:48
@domw30 domw30 requested a review from colbr December 6, 2022 16:17
@domw30
Copy link
Collaborator Author

domw30 commented Dec 6, 2022

Hey @colbr. I decided to separate all of the actions for this CTA Module. It does feel a little clunky doing it this way but hopefully it means the variations logic is easier to follow. There are still some further UI changes to make, but it would be good to do these when updating the components in zUI. Let me know your thoughts on it :) Thanks!

Copy link
Member

@colbr colbr left a comment

Choose a reason for hiding this comment

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

Few changes, but looking very solid. Nice work!

Comment on lines 23 to 27
const { isDomainBiddable, isBuyNow, isUserBid, isOwnedByUser } =
useActionsData(zna);

const isSingleAction =
(!isBuyNow && isDomainBiddable) || (isBuyNow && !isDomainBiddable);
Copy link
Member

Choose a reason for hiding this comment

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

All the different variations makes this one pretty tricky huh! Perhaps could be nice if, instead of returning booleans from useActionsData, we rename the hook useActions and return the component to render? It would move a bit of the complex logic into the hook, which would make this component a bit more straight forward. This may end up less tidy, but I think it's worth giving a go as sometimes variations get really hard to manage in JSX.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah nice suggestion thanks mate, like the idea of returning the component to render. I'll give this a go !

@@ -0,0 +1,63 @@
import { FC } from 'react';
Copy link
Member

Choose a reason for hiding this comment

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

Noticed that for each of these components there's a OwnerX and a UserX - would it be possible to instead add isOwner is a property and have one component? That would cut down code repetition.

@@ -13,6 +13,8 @@ import {
useDomainMetadata,
usePaymentToken,
} from '../../../lib/hooks';
import { ethers } from 'ethers';
import { bigNumberToLocaleString } from '@zero-tech/zapp-utils/formatting/big-number';

export const useActionsData = (zna: string) => {
Copy link
Member

Choose a reason for hiding this comment

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

This hook is getting a bit tough to read, perhaps we could split the react-query hooks into a sub hook, like

const useActions = (zna) => {
    const { data, isLoading } = useActionsData(zna)

    ...
}

const useActionsData = () => {
    // get all the data from react-query

    return {
        // data: add all the data to an object
        // isLoading: isLoading from all the react-query hooks
    }
}

@@ -34,13 +36,34 @@ export const useActionsData = (zna: string) => {
const { sortedBids, highestBid } = sortBidsByAmount(allBids);
Copy link
Member

Choose a reason for hiding this comment

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

I think it's going to be quite a common pattern to get bids and then sort them - it could be handy to have a hook which returns all of this together, so you could call

const { data, isLoading } = useBids(domainId, {  account: account, sortBy: 'amount' })

Where the options parameter is optional (useBids(domainId: string, options?: Options)).

Comment on lines 54 to 60
const buyNowPriceUsdConversionString =
paymentToken && buyNowPrice
? `$${formatNumber(
Number(ethers.utils.formatEther(buyNowPriceString)) *
Number(paymentToken?.priceInUsd),
)}`
: '-';
Copy link
Member

Choose a reason for hiding this comment

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

I've seen this pattern a bit too, wonder if we could make a nice wrapper function for this like

const getTextFallback = (generator: () => string, fallback: string) => {
    try {
        return generator();
    } catch(e) {
        return fallback;
    }
}

getTextFallback(
    () => $${formatNumber(
	    Number(ethers.utils.formatEther(buyNowPriceString)) *
		Number(paymentToken?.priceInUsd),
	)}, 
    '-'
)

My suggestion might be a little bit convoluted, but I'm sure there's a way to wrap this to make it easier!

@colbr colbr self-requested a review March 16, 2023 01:42
Copy link
Member

@colbr colbr left a comment

Choose a reason for hiding this comment

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

Looking good! Can you add some tests for the action-option stuff? Just need tests for the different variations, e.g. is owner, no bids, no buy now. That will make it much easier to validate that this works as intended 🚀

Good stuff!

Comment on lines +14 to +18
@media only screen and (min-width: 485px) {
max-width: unset;
}

@media only screen and (min-width: 878px) {
Copy link
Member

Choose a reason for hiding this comment

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

These viewport-based queries will break when zOS team adds the right-sidekick. Should make a note of this and take them out later.

Comment on lines +22 to +55
export const ActionContainer: FC<ActionContainerProps> = ({ zna }) => {
const { isDomainBiddable, isBuyNow, isUserBid, isOwnedByUser } =
useActions(zna);

const isSingleAction =
(!isBuyNow && isDomainBiddable) || (isBuyNow && !isDomainBiddable);

return (
<div
className={cx(styles.ActionContainer, {
isSingleAction: isSingleAction,
})}
>
{/* Make offer */}
{(isDomainBiddable || !isBuyNow || isUserBid) && (
<UserOfferAction zna={zna} />
)}

{/* Buy now */}
{isBuyNow && <UserBuyNowAction zna={zna} />}

{/* View bids / Enable bids now && Set buy now / Edit buy now */}
{isOwnedByUser && (
<>
<OwnerOfferAction zna={zna} />
<OwnerSetBuyNowAction zna={zna} />
</>
)}

{/* TODO: add styling to handle cancel offer with multiple actions */}
{/* {!isSingleAction && !isUserBid && <UserCancelOffer zna={zna} />} */}
</div>
);
};
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

Comment on lines +12 to +25
export const TextValue = ({
tokenValue,
fiatValue,
isSingleAction,
}: TextValueProps) => (
<div
className={cx(styles.Values, {
isSingleAction: isSingleAction,
})}
>
<span className={styles.TokenValue}>{tokenValue}</span>
<span className={styles.FiatValue}>{fiatValue}</span>
</div>
);
Copy link
Member

Choose a reason for hiding this comment

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

Should be able to use TextDetail from zUI now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants