-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './helpers' | ||
export * from './networks' | ||
export * from './sardine' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |