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: Add utility code for NFT Features #4256

Merged

Conversation

cbachmeier
Copy link
Contributor

@cbachmeier cbachmeier commented Aug 3, 2022

Adds in the utility code for NFT Features including:

  • dependencies
  • styles
  • hooks
  • queries
  • types
  • util functions

@vercel
Copy link

vercel bot commented Aug 3, 2022

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

Name Status Preview Updated
interface ✅ Ready (Inspect) Visit Preview Aug 10, 2022 at 11:25PM (UTC)

@vm
Copy link
Contributor

vm commented Aug 3, 2022

@zzmp will own reviewing this PR

@vm vm removed their request for review August 3, 2022 15:38
Copy link
Contributor

@zzmp zzmp left a comment

Choose a reason for hiding this comment

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

  • The pngs and svgs should be added with the appropriate PR, not as part of utility code, unless they are directly referenced by utility code.
  • The ttfs are redundant - we already include Inter in public/fonts/Inter-roman.var.woff2.
  • privacy.pdf should probably not be included. I don't see anything linking to it.

(these are just initial comments - I'll give this a more thorough review tomorrow AM)

craco.config.cjs Outdated Show resolved Hide resolved
Copy link
Contributor

@zzmp zzmp left a comment

Choose a reason for hiding this comment

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

A lot of the packages that you've added are not yet used, or are already used implicitly and do not need to be explicitly added. They should not be added until they are actually used, even if it makes the subsequent PRs a little more cumbersome. Adding them all at once risks adding no-longer used packages, and makes it harder to review and ensure that our dependencies are being pinned correctly (and that no malicious dependencies or version skew gets through).

Please remove these packages from the package.json, and then re-checkout the lockfile and re-install the files to regenerate it: git checkout main yarn.lock.

  • @babel/runtime
  • @testing-library/react-hooks
  • @types/react-table
  • tslib
  • @react-spring/web
  • @use-gesture/react
  • color.js
  • deepmerge
  • html2canvas
  • overlayscrollbars
  • overlayscrollbars-react
  • query-string
  • react-country-flag
  • react-error-overlay
  • react-infinite-scroll-component
  • react-merge-refs
  • react-meta-tags
  • react-player
  • react-select
  • react-tilty

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/index.tsx Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@zzmp zzmp left a comment

Choose a reason for hiding this comment

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

I've still got to go through src/nft/utils/ and the yarn.lock.

src/lib/hooks/useCurrencyBalance.ts Outdated Show resolved Hide resolved
@@ -141,3 +141,6 @@ export default function useCurrencyBalance(
useMemo(() => [currency], [currency])
)[0]
}

export const useCurrencyBalanceString = (account: string): string =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Following other naming conventions in this file, this should be useNativeCurrencyBalance(account: string): CurrencyAmount<Currency> | undefined.

You should defer converting it to a string until it is used, so that it is passed around as a more usable CurrencyAmount.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This utility function was named and recommended by Connor in this PR https://github.com/Uniswap/interface-nft/pull/4#discussion_r907469235

craco.config.cjs Outdated Show resolved Hide resolved
src/connection/index.ts Outdated Show resolved Hide resolved
reset?: keyof JSX.IntrinsicElements
}

export const atoms = ({ reset, ...rest }: Atoms) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Document what reset does.

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 used by the Box component when declaring the component as something other than a div. It's should only be used for that specific purpose https://github.com/Uniswap/interface-nft/blob/main/src/nft/components/Box.ts

src/nft/hooks/useToggle.ts Outdated Show resolved Hide resolved
src/nft/hooks/useWalletBalance.ts Show resolved Hide resolved
src/nft/hooks/useWindowDimensions.ts Outdated Show resolved Hide resolved
src/nft/hooks/useWrongNetwork.ts Outdated Show resolved Hide resolved
src/nft/types/index.ts Show resolved Hide resolved
Copy link
Contributor

@zzmp zzmp left a comment

Choose a reason for hiding this comment

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

A lot of the utils use hard-coded english strings. What is the plan for i18n/l10n?
Will nft features use lingui? Have they been using something else?

src/nft/utils/address.ts Outdated Show resolved Hide resolved
src/nft/utils/address.ts Outdated Show resolved Hide resolved
src/nft/utils/calcPoolPrice.ts Outdated Show resolved Hide resolved
src/nft/utils/chains.ts Outdated Show resolved Hide resolved
return isNaN(d) ? false : true
}

export const getTimeDifference = (eventTimestamp: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not internationalized. Why not use a library for 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.

We have no yet started the work for internationalization for NFT components. For procedurally generated text such as getting time difference in either days, hours, or minutes is there a standard practice? When it is tackled which I believe is outside of the scope of this PR, should we return a Trans component in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Either return a trans component, or use a library which deals with internationalizing date/time strings. I believe we already use such a library in places like governance.


export const fetchPrice = async (currency: Currency = Currency.ETH): Promise<number | undefined> => {
try {
const response = await fetch(`https://api.coinbase.com/v2/exchange-rates?currency=${currency}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine, but it seems strange to go to coinbase for this price when the global app checks it from uniswap.

Copy link
Contributor Author

@cbachmeier cbachmeier Aug 9, 2022

Choose a reason for hiding this comment

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

This is how we retrieved current price on Genie. For the sake of V0 and the scope of this ticket would it be fine if we keep this and add it as tech debt to replace and refactor where it is used?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes - you should make a low-priority jira ticket to document the tech debt (same with i18n work).

src/nft/utils/gtag.tsx Outdated Show resolved Hide resolved
src/nft/utils/listNfts.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,5 @@
export const roundAndPluralize = (i: number, word: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't work with internationalization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll be tackling internationalization in a later sprint. When we do, will we not be able to have any kind of generalized behaviour helper function here or will we just need to use a conditional for the full word?

Copy link
Contributor

Choose a reason for hiding this comment

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

you will not be able to use a helper function, you'll need to use the i18n libraries (lingui) to deal with pluralization.

@@ -0,0 +1,24 @@
import { roundAndPluralize } from './roundAndPluralize'
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't work with i10n.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll be tackling internationalization in a later sprint.

@zzmp
Copy link
Contributor

zzmp commented Aug 5, 2022

The lockfile changes were too large to comment on, so I updated them locally and pushed the changes to this branch.

@cbachmeier cbachmeier force-pushed the WEB-687-merge-utility-code-in-the-main-interface-repository branch from 7db6fed to d5c9f21 Compare August 10, 2022 00:21
@cbachmeier cbachmeier closed this Aug 10, 2022
@cbachmeier cbachmeier reopened this Aug 10, 2022
Charles Bachmeier added 2 commits August 9, 2022 17:36
src/connection/index.ts Outdated Show resolved Hide resolved
src/hooks/useImperativeDisableScroll.ts Outdated Show resolved Hide resolved
src/nft/hooks/useIsMobile.ts Outdated Show resolved Hide resolved
src/nft/hooks/useSellAsset.ts Outdated Show resolved Hide resolved
src/nft/queries/genie/CollectionStatsFetcher.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,16 @@
export const buildSellObject = (amount: string) => {
return {
address: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
Copy link
Contributor

Choose a reason for hiding this comment

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

What is 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's effectively the same as the null address and it's what the genieswap contract uses for buying with ETH. @azflin might be able to discuss this further if you have more questions on it.

src/nft/utils/chains.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@zzmp zzmp left a comment

Choose a reason for hiding this comment

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

Can you fix the issues the linter brought up before merging?

  • src/nft/queries/genie/RouteFetcher.ts#L15 (!== instead of !=)
  • src/nft/queries/openSea/OSCollectionsFetcher.ts#L7 (=== instead of ==)

@cbachmeier cbachmeier merged commit 8dbc91e into main Aug 10, 2022
@cbachmeier cbachmeier deleted the WEB-687-merge-utility-code-in-the-main-interface-repository branch August 10, 2022 23:38
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