Skip to content

Commit

Permalink
check whitelist status hook (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamueleA authored Jun 11, 2024
1 parent 57a0239 commit f21bb86
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/checkout/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './useAddFundsModal'
export * from './useCheckoutModal'
export * from './useNavigation'
export * from './useModalTheme'
export * from './useCheckoutWhitelistStatus'
20 changes: 20 additions & 0 deletions packages/checkout/src/hooks/useCheckoutWhitelistStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useProjectAccessKey } from '@0xsequence/kit'
import { useQuery } from '@tanstack/react-query'

import { checkSardineWhitelistStatus, CheckSardineWhitelistStatusArgs } from '../utils'


export const useCheckoutWhitelistStatus = (args: CheckSardineWhitelistStatusArgs) => {
const projectAccessKey = useProjectAccessKey()

return useQuery({
queryKey: ['useCheckoutWhitelistStatus', args],
queryFn: async () => {
const res = await checkSardineWhitelistStatus(args, projectAccessKey)

return res
},
retry: false,
staleTime: 1800 * 1000,
})
}
1 change: 1 addition & 0 deletions packages/checkout/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { KitCheckoutProvider } from './shared/components/KitCheckoutProvider'
// Hooks
export { useCheckoutModal } from './hooks/useCheckoutModal'
export { useAddFundsModal } from './hooks/useAddFundsModal'
export { useCheckoutWhitelistStatus } from './hooks/useCheckoutWhitelistStatus'

export { type CheckoutSettings } from './contexts/CheckoutModal'
export { type AddFundsSettings } from './contexts/AddFundsModal'
Expand Down
1 change: 1 addition & 0 deletions packages/checkout/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './helpers'
export * from './networks'
export * from './sardine'
67 changes: 67 additions & 0 deletions packages/checkout/src/utils/sardine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { ChainId, networks } from '@0xsequence/network'
import { constants } from 'ethers'

export interface CheckSardineWhitelistStatusArgs {
isDev: boolean
chainId: number
marketplaceAddress: string
}

export const checkSardineWhitelistStatus = async ({
isDev,
chainId,
marketplaceAddress,
}: CheckSardineWhitelistStatusArgs,
projectAccessKey: string) => {
const referenceId = `sequence-kit-sardine-whitelist-check`

const accessKey = isDev ? '17xhjK4yjRf1fr0am8kgKfICAAAAAAAAA' : projectAccessKey

const url = isDev
? 'https://dev-api.sequence.app/rpc/API/GetSardineNFTCheckoutToken'
: 'https://api.sequence.app/rpc/API/GetSardineNFTCheckoutToken'

const res = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Access-Key': `${accessKey || ''}`
},
body: JSON.stringify({
params: {
referenceId,
expiresIn: 3600,
paymentMethodTypeConfig: {
enabled: ['us_debit', 'us_credit', 'international_debit', 'international_credit', 'ach'],
default: 'us_debit'
},
name: 'whitelist-check',
imageUrl: 'https://www.sequence.market/images/placeholder.png',
network: networks[chainId as ChainId].name,
recipientAddress: constants.AddressZero,
contractAddress: marketplaceAddress,
platform: "calldata_execution",
executionType: 'smart_contract',
blockchainNftId: '42',
quantity: 1,
decimals: 0,
tokenAmount: '1000000',
tokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
tokenSymbol: 'USDC',
tokenDecimals: 6,
callData: '0x1',
}
})
})

const resJson = await res.json()

if (
typeof resJson?.cause === 'string' &&
resJson.cause.includes('It must me allow listed')
) {
return false
}

return true
}

0 comments on commit f21bb86

Please sign in to comment.