-
Notifications
You must be signed in to change notification settings - Fork 652
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
fix: Refactor buy with crypto modal #2130
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
…/refactor-buy-with-crypto-modal
Tested both of these and they worked correctly :D |
There is an issue when selecting 0 balance tokens, the estimations are not being updated. This will not affect the user given that with 0 balance they cannot proceed, just as a reminder. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea of separating the PaymentSelector, PurchaseTotal and hooks out of the main component.
I tried some operations and it worked correctly.
Also committed some formatting and import fixes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks awesome, so much organized than before. Left a few comments of how I think we could improve it further
webapp/src/components/Modals/BuyWithCryptoModal/BuyWithCryptoModal.tsx
Outdated
Show resolved
Hide resolved
}) | ||
}, [nft, order, getContract, onAuthorizedAction, onExecuteOrder]) | ||
|
||
const onBuyWithCard = useCallback(() => onExecuteOrderWithCard(nft), [nft]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks a little bit unnecessary IMO, it might be simpler to just use
const onBuyWithCard = useCallback(() => onExecuteOrderWithCard(nft), [nft]) | |
const onBuyWithCard = (nft) => onExecuteOrderWithCard(nft) |
or if you really want to avoid those re-definitions of the fn in each render, maybe like this?
const onBuyWithCard = useCallback(() => onExecuteOrderWithCard(nft), [nft]) | |
const onBuyWithCard = useCallback((nft) => onExecuteOrderWithCard(nft), [onExecuteOrderWithCard]) |
import { Props } from './MintNftWithCryptoModal.types' | ||
import { OnGetCrossChainRoute, OnGetGasCost } from '../BuyWithCryptoModal.types' | ||
|
||
const MintNftWithCryptoModalHOC = (props: Props) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we could turn this to a generic HOC that has a prop like action
that could be MINT/BUY that abstracts most of the logic to avoid having repetead code that has really small differences.
E.g:
onBuyNatively
is almost identical, it just changes the contract and nft <=> item- onGetCrossChainRoute as well is too similar, just changes the nft/tem
- similar case for other props
) | ||
} | ||
|
||
export const useCrossChainMintNftRoute = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar case here, a lot of props and params repetead between the 2, could we think of making this more generic maybe?
export const useCrossChainBuyRoute = (
item?: Item,
order?: Order,
....
) => {
const fn = item ? getMintNFTRoute : getBuyNFTRoute
const payload = item ? { item : { collectionAddress: .... } } : { nft: { ... } }
...
return crossChainProvider.fn({ ...baseParams, ...payload })
This might be a big refactor, so maybe we could leave it for later. WDYT?
…yptoModal.tsx Co-authored-by: Juanma Hidalgo <juanma06@gmail.com> Signed-off-by: Fernando Zavalia <24811313+fzavalia@users.noreply.github.com>
This PR refactors the
BuyWithCryptoModal
by:MintNftWithCryptoModal
andBuyNftWithCryptoModal
). This logic has been moved and refactored into hooks.PaymentSelector
and thePurchaseTotal