Skip to content

Commit

Permalink
feat: pass event and data to the onClick
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Mar 12, 2024
1 parent eb9c3e5 commit 1606b7a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import { Props } from './BuyWithCryptoButton.types'
export const BuyWithCryptoButton = (props: Props) => {
const { asset, onClick, ...rest } = props

const handleOnClick = useCallback(() => {
const isClaimingName = isNFT(asset) && asset.category === NFTCategory.ENS && !asset.tokenId
const isMint = !!asset.itemId || isClaimingName
getAnalytics().track(events.BUY_WITH_CRYPTO, {
transaction_type: isMint ? 'mint' : 'secondary',
contract_address: isClaimingName ? undefined : asset.contractAddress,
token_id: isClaimingName ? undefined : isNFT(asset) ? asset.tokenId : asset.itemId,
category: asset.category
})
onClick()
}, [props.asset, onClick])
const handleOnClick = useCallback(
(e, data) => {
const isClaimingName = isNFT(asset) && asset.category === NFTCategory.ENS && !asset.tokenId
const isMint = !!asset.itemId || isClaimingName
getAnalytics().track(events.BUY_WITH_CRYPTO, {
transaction_type: isMint ? 'mint' : 'secondary',
contract_address: isClaimingName ? undefined : asset.contractAddress,
token_id: isClaimingName ? undefined : isNFT(asset) ? asset.tokenId : asset.itemId,
category: asset.category
})
onClick?.(e, data)
},
[props.asset, onClick]
)

return (
<Button primary fluid {...rest} onClick={handleOnClick}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ import { Asset } from '../../../../../modules/asset/types'

export type Props = ButtonProps & {
asset: Asset

Check failure on line 5 in webapp/src/components/AssetPage/SaleActionBox/BuyNFTButtons/BuyWithCryptoButton/BuyWithCryptoButton.types.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

Check failure on line 5 in webapp/src/components/AssetPage/SaleActionBox/BuyNFTButtons/BuyWithCryptoButton/BuyWithCryptoButton.types.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
onClick: () => void
}
1 change: 1 addition & 0 deletions webapp/src/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const PURCHASED_FAILED = 'Purchase Failed'
export const PURCHASED_STARTED = 'Purchase Started'
export const BUY = 'Buy'
export const BUY_WITH_CARD = 'Buy With Card'
export const BUY_WITH_CRYPTO = 'Click on buy with crypto'
export const PUBLISH = 'Publish'
export const CANCEL_SALE = 'Cancel Sale'
export const TRANSFER_NFT = 'Transfer NFT'
Expand Down

0 comments on commit 1606b7a

Please sign in to comment.