@crossmint/client-sdk-base
Advanced tools
Comparing version 0.2.5-alpha.0 to 0.2.6-alpha.0
declare function generateClientId(): string; | ||
declare const EVM_CHAINS: readonly ["ethereum", "polygon", "bsc"]; | ||
type EVMChain = (typeof EVM_CHAINS)[number]; | ||
declare enum clientNames { | ||
@@ -8,4 +10,4 @@ reactUi = "client-sdk-react-ui", | ||
declare enum baseUrls { | ||
prod = "https://www.crossmint.io", | ||
staging = "https://staging.crossmint.io/", | ||
prod = "https://www.crossmint.com", | ||
staging = "https://staging.crossmint.com", | ||
dev = "http://localhost:3001" | ||
@@ -17,2 +19,10 @@ } | ||
} | ||
declare enum ChainLocators { | ||
solana = "sol", | ||
ethereum = "eth", | ||
polygon = "poly", | ||
cardano = "ada", | ||
bsc = "bsc" | ||
} | ||
type EVMChainLocators = ChainLocators.bsc | ChainLocators.ethereum | ChainLocators.polygon; | ||
type theme = "light" | "dark"; | ||
@@ -78,3 +88,50 @@ type paymentMethods = "fiat" | "ETH" | "SOL"; | ||
}; | ||
interface Wallet { | ||
chain: string; | ||
publicKey: string; | ||
} | ||
interface Colors { | ||
textPrimary?: string; | ||
textSecondary?: string; | ||
accent?: string; | ||
background?: string; | ||
backgroundSecondary?: string; | ||
border?: string; | ||
} | ||
interface UIConfig { | ||
colors?: Colors; | ||
} | ||
interface CommonProps { | ||
uiConfig?: UIConfig; | ||
environment?: string; | ||
} | ||
interface NFTCollectionViewProps extends CommonProps { | ||
wallets: Wallet[]; | ||
} | ||
interface CardanoNFT { | ||
chain: "cardano"; | ||
assetId: string; | ||
} | ||
interface EVMNFT { | ||
chain: EVMChain; | ||
contractAddress: string; | ||
tokenId: string; | ||
} | ||
interface SolanaNFT { | ||
mintHash: string; | ||
chain: "solana"; | ||
} | ||
type NFTLocator<T extends ChainLocators> = `${T}:${string}${T extends EVMChainLocators ? `:${string}` : ""}`; | ||
type NFT = CardanoNFT | EVMNFT | SolanaNFT | NFTLocator<ChainLocators.solana> | NFTLocator<ChainLocators.ethereum> | NFTLocator<ChainLocators.polygon> | NFTLocator<ChainLocators.bsc> | NFTLocator<ChainLocators.cardano>; | ||
interface NFTDetailProps extends CommonProps { | ||
nft: NFT; | ||
} | ||
declare function assertValidNFTCollectionViewProps({ wallets }: NFTCollectionViewProps): void; | ||
declare function assertValidValidateNFTDetailProps({ nft }: NFTDetailProps): void; | ||
declare const getEnvironmentBaseUrl: (environment?: string) => string; | ||
declare function getNFTCollectionViewSrc(props: NFTCollectionViewProps, clientVersion: string): string; | ||
declare function getNFTDetailSrc(props: NFTDetailProps, clientVersion: string): string; | ||
interface CrossmintModalServiceParams { | ||
@@ -135,2 +192,2 @@ clientId: string; | ||
export { BaseButtonProps, CrossmintModalServiceReturn, CrossmintPayButtonProps, Currency, Locale, OnboardingQueryParams, PayButtonConfig, SigninMethods, baseUrls, clientNames, crossmintModalService, crossmintPayButtonService, crossmintStatusButtonService, crossmintStatusService, customHeaders, generateClientId, mintingContractTypes, onboardingRequestStatusResponse, paymentMethodIsEth, paymentMethodIsSol, paymentMethods }; | ||
export { BaseButtonProps, CardanoNFT, ChainLocators, CrossmintModalServiceReturn, CrossmintPayButtonProps, Currency, EVMChain, EVMChainLocators, EVMNFT, EVM_CHAINS, Locale, NFT, NFTCollectionViewProps, NFTDetailProps, NFTLocator, OnboardingQueryParams, PayButtonConfig, SigninMethods, SolanaNFT, Wallet, assertValidNFTCollectionViewProps, assertValidValidateNFTDetailProps, baseUrls, clientNames, crossmintModalService, crossmintPayButtonService, crossmintStatusButtonService, crossmintStatusService, customHeaders, generateClientId, getEnvironmentBaseUrl, getNFTCollectionViewSrc, getNFTDetailSrc, mintingContractTypes, onboardingRequestStatusResponse, paymentMethodIsEth, paymentMethodIsSol, paymentMethods }; |
@@ -1,1 +0,1 @@ | ||
import{v4 as x}from"uuid";function Z(){return x()}var D=(o=>(o.reactUi="client-sdk-react-ui",o.vanillaUi="client-sdk-vanilla-ui",o))(D||{}),X=(n=>(n.prod="https://www.crossmint.io",n.staging="https://staging.crossmint.io/",n.dev="http://localhost:3001",n))(X||{}),A=(o=>(o.clientVersion="X-Client-Version",o.clientName="X-Client-Name",o))(A||{}),et=t=>t==="ETH",nt=t=>t==="SOL",R=(n=>(n.CANDY_MACHINE="candy-machine",n.SOLANA_AUCTION="solana-auction",n.ERC_721="erc-721",n))(R||{}),k=(r=>(r.WAITING_SUBMISSION="waiting-submission",r.PENDING="pending",r.REJECTED="rejected",r.ACCEPTED="accepted",r.INVALID="invalid",r))(k||{});var y=(t="")=>{let e=["prod","production"];return t==="staging"?"https://staging.crossmint.io/":e.includes(t)||!t?"https://www.crossmint.io":t};var L="__crossmint-overlay__",H=400,W=750,G=()=>{let t=navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);return t?parseInt(t[2]):null};function V(t,e){function o(){return(window==null?void 0:window.top)!=null?window.top.outerWidth/2+window.top.screenX-t/2:window.outerWidth/2+window.screenX-t/2}function n(){return(window==null?void 0:window.top)!=null?window.top.outerHeight/2+window.top.screenY-e/2:window.outerHeight/2+window.screenY-e/2}let i=G();return`${i&&i>99?"popup=true,":""}height=${e},width=${t},left=${o()},top=${n()},resizable=yes,scrollbars=yes,toolbar=yes,menubar=true,location=no,directories=no, status=yes`}var Y=t=>{let e=document.createElement("div");e.setAttribute("id",L);let o={width:"100vw",height:"100vh","background-color":"rgba(0, 0, 0, 0.5)",position:"fixed","z-index":"99999999",top:"0",left:"0"};Object.assign(e.style,o),document.body.appendChild(e),t&&e.addEventListener("click",()=>{O()})},O=()=>{let t=document.getElementById(L);t&&t.remove()};function st({clientId:t,libVersion:e,showOverlay:o,dismissOverlayOnClick:n,setConnecting:i,environment:r,clientName:m,locale:s,currency:p,successCallbackURL:S,failureCallbackURL:I}){let c=(f,g,h,v,E,P,B,N)=>{let w=y(r),_=encodeURIComponent(`${w}/checkout/mint?${(()=>{let u={clientId:t,clientName:m,clientVersion:e,mintConfig:JSON.stringify(f),locale:s,currency:p};return g&&(u.mintTo=g),h&&(u.emailTo=h),v&&(u.listingId=v),E&&(u.whPassThroughArgs=JSON.stringify(E)),P&&(u.paymentMethod=P.toLowerCase()),B&&(u.preferredSigninMethod=B),N&&(u.prepay="true"),S&&(u.successCallbackURL=S),I&&(u.failureCallbackURL=I),new URLSearchParams(u).toString()})()}`),M=`${w}/signin?callbackUrl=${_}&locale=${s}¤cy=${p}`,U=window.open(M,"popUpWindow",V(H,W));if(U){T(U),o&&Y(n);return}i(!1),window.open(M,"_blank")||console.error("Failed to open popup window and new tab")},C=(f,g,h,v,E,P,B,N)=>{i(!0),c(f,g,h,v,E,P,B,N)};function T(f){let g=setInterval(function(){f.closed&&(clearInterval(g),i(!1),o&&O())},500)}return{connect:C}}var $={crossmintPayButtonService:{CONNECTING:"Connecting...",BUY_WITH_ETH:"Buy with ETH",BUY_WITH_SOL:"Buy with SOL",BUY_WITH_CREDIT_CARD:"Buy with credit card"},crossmintStatusButtonService:{INVALID:"Invalid clientId",WAITING_SUBMISSION:"Click here to setup Crossmint",PENDING:"Your application is under review",ACCEPTED:"You're good to go!",REJECTED:"Your application was rejected"}},Q={crossmintPayButtonService:{CONNECTING:"Conectando...",BUY_WITH_ETH:"Comprar con ETH",BUY_WITH_SOL:"Comprar con SOL",BUY_WITH_CREDIT_CARD:"Comprar con tarjeta de cr\xE9dito"},crossmintStatusButtonService:{INVALID:"clientId inv\xE1lido",WAITING_SUBMISSION:"Haga clic aqu\xED para configurar Crossmint",PENDING:"Su solicitud est\xE1 en revisi\xF3n",ACCEPTED:"\xA1Est\xE1 listo para usar Crossmint!",REJECTED:"Su solicitud fue rechazada"}},J={"en-US":$,"es-ES":Q};function a(t,e){let o=J[e];return t.split(".").reduce((n,i)=>n[i],o)}function lt({onClick:t,connecting:e,paymentMethod:o,locale:n}){return{getButtonText:s=>{if(s)return a("crossmintPayButtonService.CONNECTING",n);switch(o){case"ETH":return a("crossmintPayButtonService.BUY_WITH_ETH",n);case"SOL":return a("crossmintPayButtonService.BUY_WITH_SOL",n);default:return a("crossmintPayButtonService.BUY_WITH_CREDIT_CARD",n)}},shouldHideButton:({hideMintOnInactiveClient:s,status:p})=>s&&p!=="accepted",handleClick:(s,p)=>{t&&t(s),!e&&(s.defaultPrevented||p())}}}var j=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function b(t){return typeof t=="string"&&j.test(t)}var q=t=>{try{return b(t)}catch(e){return console.error(e),!1}};function ft({libVersion:t,clientId:e,platformId:o,auctionId:n,mintConfig:i,setStatus:r,environment:m,clientName:s}){async function p(){if(!e||e===""||e==="<YOUR_CLIENT_ID>"){console.error("You must enter your own Crossmint client ID in <CrossmintPayButton clientId=XXX>");return}if(!q(e)){console.error("The clientId passed to is invalid. Make sure to pass the clientId obtained from the crossmint team, with format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX");return}let c=y(m),C=await fetch(`${c}/api/crossmint/onboardingRequests/${e}/status`,{headers:{["X-Client-Version"]:t,["X-Client-Name"]:s}});if(C.status===200){let T=await C.json();r(T.status)}else r("invalid")}let S=()=>{let c=y(m);window.open(`${c}/developers/onboarding?${I()}`,"_blank")},I=()=>{let c={clientId:e};return o&&(c.platformId=o),n&&(c.auctionId=n),i&&(c.mintConfig=JSON.stringify(i)),new URLSearchParams(c).toString()};return{fetchClientIntegration:p,goToOnboarding:S}}function It({onClick:t,locale:e}){return{getButtonText:r=>{switch(r){case"invalid":return a("crossmintStatusButtonService.INVALID",e);case"waiting-submission":return a("crossmintStatusButtonService.WAITING_SUBMISSION",e);case"pending":return a("crossmintStatusButtonService.PENDING",e);case"accepted":return a("crossmintStatusButtonService.ACCEPTED",e);case"rejected":return a("crossmintStatusButtonService.REJECTED",e)}},isButtonDisabled:r=>r!=="waiting-submission",handleClick:(r,m,s)=>{t&&t(r),m==="waiting-submission"&&s()}}}export{X as baseUrls,D as clientNames,st as crossmintModalService,lt as crossmintPayButtonService,It as crossmintStatusButtonService,ft as crossmintStatusService,A as customHeaders,Z as generateClientId,R as mintingContractTypes,k as onboardingRequestStatusResponse,et as paymentMethodIsEth,nt as paymentMethodIsSol}; | ||
import{v4 as A}from"uuid";function et(){return A()}function ot({wallets:t}){if(t.length===0)throw new Error("wallets prop is empty. Please provide at least one wallet.")}function rt({nft:t}){if(t==null)throw new Error("nft prop is empty. Please provide a valid nft.")}var st=["ethereum","polygon","bsc"],V=(r=>(r.reactUi="client-sdk-react-ui",r.vanillaUi="client-sdk-vanilla-ui",r))(V||{}),U=(n=>(n.prod="https://www.crossmint.com",n.staging="https://staging.crossmint.com",n.dev="http://localhost:3001",n))(U||{}),X=(r=>(r.clientVersion="X-Client-Version",r.clientName="X-Client-Name",r))(X||{}),v=(o=>(o.solana="sol",o.ethereum="eth",o.polygon="poly",o.cardano="ada",o.bsc="bsc",o))(v||{}),at=t=>t==="ETH",ct=t=>t==="SOL",F=(n=>(n.CANDY_MACHINE="candy-machine",n.SOLANA_AUCTION="solana-auction",n.ERC_721="erc-721",n))(F||{}),k=(o=>(o.WAITING_SUBMISSION="waiting-submission",o.PENDING="pending",o.REJECTED="rejected",o.ACCEPTED="accepted",o.INVALID="invalid",o))(k||{});var g=(t="")=>{let e=["prod","production"];return t==="staging"?"https://staging.crossmint.com":e.includes(t)||!t?"https://www.crossmint.com":t};function R(t){if(typeof t=="string")return t;switch(t.chain){case"solana":return`${"sol"}:${t.mintHash}`;case"polygon":case"ethereum":case"bsc":return`${v[t.chain]}:${t.contractAddress}:${t.tokenId}`;case"cardano":return`${v[t.chain]}:${t.assetId}`;default:throw new Error(`Invalid chain type ${JSON.stringify(t)}`)}}function gt(t,e){let r=g(t.environment),{wallets:n}=t,i=JSON.stringify(n),o=new URLSearchParams({wallets:i,clientVersion:e,...t.uiConfig!=null?{uiConfig:JSON.stringify(t.uiConfig)}:{}});return`${r}/sdk/wallets/collection?${o.toString()}`}function ft(t,e){let r=g(t.environment),n=new URLSearchParams({clientVersion:e,...t.uiConfig!=null?{uiConfig:JSON.stringify(t.uiConfig)}:{}}),i=R(t.nft);return`${r}/sdk/wallets/tokens/${i}?${n.toString()}`}var D="__crossmint-overlay__",$=400,H=750,W=()=>{let t=navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);return t?parseInt(t[2]):null};function G(t,e){function r(){return(window==null?void 0:window.top)!=null?window.top.outerWidth/2+window.top.screenX-t/2:window.outerWidth/2+window.screenX-t/2}function n(){return(window==null?void 0:window.top)!=null?window.top.outerHeight/2+window.top.screenY-e/2:window.outerHeight/2+window.screenY-e/2}let i=W();return`${i&&i>99?"popup=true,":""}height=${e},width=${t},left=${r()},top=${n()},resizable=yes,scrollbars=yes,toolbar=yes,menubar=true,location=no,directories=no, status=yes`}var Y=t=>{let e=document.createElement("div");e.setAttribute("id",D);let r={width:"100vw",height:"100vh","background-color":"rgba(0, 0, 0, 0.5)",position:"fixed","z-index":"99999999",top:"0",left:"0"};Object.assign(e.style,r),document.body.appendChild(e),t&&e.addEventListener("click",()=>{O()})},O=()=>{let t=document.getElementById(D);t&&t.remove()};function ht({clientId:t,libVersion:e,showOverlay:r,dismissOverlayOnClick:n,setConnecting:i,environment:o,clientName:p,locale:s,currency:m,successCallbackURL:C,failureCallbackURL:h}){let c=(y,f,I,T,N,P,w,b)=>{let x=g(o),_=encodeURIComponent(`${x}/checkout/mint?${(()=>{let l={clientId:t,clientName:p,clientVersion:e,mintConfig:JSON.stringify(y),locale:s,currency:m};return f&&(l.mintTo=f),I&&(l.emailTo=I),T&&(l.listingId=T),N&&(l.whPassThroughArgs=JSON.stringify(N)),P&&(l.paymentMethod=P.toLowerCase()),w&&(l.preferredSigninMethod=w),b&&(l.prepay="true"),C&&(l.successCallbackURL=C),h&&(l.failureCallbackURL=h),new URLSearchParams(l).toString()})()}`),L=`${x}/signin?callbackUrl=${_}&locale=${s}¤cy=${m}`,M=window.open(L,"popUpWindow",G($,H));if(M){E(M),r&&Y(n);return}i(!1),window.open(L,"_blank")||console.error("Failed to open popup window and new tab")},S=(y,f,I,T,N,P,w,b)=>{i(!0),c(y,f,I,T,N,P,w,b)};function E(y){let f=setInterval(function(){y.closed&&(clearInterval(f),i(!1),r&&O())},500)}return{connect:S}}var J={crossmintPayButtonService:{CONNECTING:"Connecting...",BUY_WITH_ETH:"Buy with ETH",BUY_WITH_SOL:"Buy with SOL",BUY_WITH_CREDIT_CARD:"Buy with credit card"},crossmintStatusButtonService:{INVALID:"Invalid clientId",WAITING_SUBMISSION:"Click here to setup Crossmint",PENDING:"Your application is under review",ACCEPTED:"You're good to go!",REJECTED:"Your application was rejected"}},Q={crossmintPayButtonService:{CONNECTING:"Conectando...",BUY_WITH_ETH:"Comprar con ETH",BUY_WITH_SOL:"Comprar con SOL",BUY_WITH_CREDIT_CARD:"Comprar con tarjeta de cr\xE9dito"},crossmintStatusButtonService:{INVALID:"clientId inv\xE1lido",WAITING_SUBMISSION:"Haga clic aqu\xED para configurar Crossmint",PENDING:"Su solicitud est\xE1 en revisi\xF3n",ACCEPTED:"\xA1Est\xE1 listo para usar Crossmint!",REJECTED:"Su solicitud fue rechazada"}},q={"en-US":J,"es-ES":Q};function a(t,e){let r=q[e];return t.split(".").reduce((n,i)=>n[i],r)}function Nt({onClick:t,connecting:e,paymentMethod:r,locale:n}){return{getButtonText:s=>{if(s)return a("crossmintPayButtonService.CONNECTING",n);switch(r){case"ETH":return a("crossmintPayButtonService.BUY_WITH_ETH",n);case"SOL":return a("crossmintPayButtonService.BUY_WITH_SOL",n);default:return a("crossmintPayButtonService.BUY_WITH_CREDIT_CARD",n)}},shouldHideButton:({hideMintOnInactiveClient:s,status:m})=>s&&m!=="accepted",handleClick:(s,m)=>{t&&t(s),!e&&(s.defaultPrevented||m())}}}var j=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function B(t){return typeof t=="string"&&j.test(t)}var K=t=>{try{return B(t)}catch(e){return console.error(e),!1}};function bt({libVersion:t,clientId:e,platformId:r,auctionId:n,mintConfig:i,setStatus:o,environment:p,clientName:s}){async function m(){if(!e||e===""||e==="<YOUR_CLIENT_ID>"){console.error("You must enter your own Crossmint client ID in <CrossmintPayButton clientId=XXX>");return}if(!K(e)){console.error("The clientId passed to is invalid. Make sure to pass the clientId obtained from the crossmint team, with format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX");return}let c=g(p),S=await fetch(`${c}/api/crossmint/onboardingRequests/${e}/status`,{headers:{["X-Client-Version"]:t,["X-Client-Name"]:s}});if(S.status===200){let E=await S.json();o(E.status)}else o("invalid")}let C=()=>{let c=g(p);window.open(`${c}/developers/onboarding?${h()}`,"_blank")},h=()=>{let c={clientId:e};return r&&(c.platformId=r),n&&(c.auctionId=n),i&&(c.mintConfig=JSON.stringify(i)),new URLSearchParams(c).toString()};return{fetchClientIntegration:m,goToOnboarding:C}}function Lt({onClick:t,locale:e}){return{getButtonText:o=>{switch(o){case"invalid":return a("crossmintStatusButtonService.INVALID",e);case"waiting-submission":return a("crossmintStatusButtonService.WAITING_SUBMISSION",e);case"pending":return a("crossmintStatusButtonService.PENDING",e);case"accepted":return a("crossmintStatusButtonService.ACCEPTED",e);case"rejected":return a("crossmintStatusButtonService.REJECTED",e)}},isButtonDisabled:o=>o!=="waiting-submission",handleClick:(o,p,s)=>{t&&t(o),p==="waiting-submission"&&s()}}}export{v as ChainLocators,st as EVM_CHAINS,ot as assertValidNFTCollectionViewProps,rt as assertValidValidateNFTDetailProps,U as baseUrls,V as clientNames,ht as crossmintModalService,Nt as crossmintPayButtonService,Lt as crossmintStatusButtonService,bt as crossmintStatusService,X as customHeaders,et as generateClientId,g as getEnvironmentBaseUrl,gt as getNFTCollectionViewSrc,ft as getNFTDetailSrc,F as mintingContractTypes,k as onboardingRequestStatusResponse,at as paymentMethodIsEth,ct as paymentMethodIsSol}; |
{ | ||
"name": "@crossmint/client-sdk-base", | ||
"version": "0.2.5-alpha.0", | ||
"version": "0.2.6-alpha.0", | ||
"author": "Paella Labs Inc", | ||
@@ -34,3 +34,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "15fb24687e4c49b5b5e062de5b791ced2e25714e" | ||
"gitHead": "44d625ae5edfaff7c54df47d17c8f807d05bd94d" | ||
} |
@@ -0,1 +1,4 @@ | ||
export const EVM_CHAINS = ["ethereum", "polygon", "bsc"] as const; | ||
export type EVMChain = (typeof EVM_CHAINS)[number]; | ||
export enum clientNames { | ||
@@ -7,4 +10,4 @@ reactUi = "client-sdk-react-ui", | ||
export enum baseUrls { | ||
prod = "https://www.crossmint.io", | ||
staging = "https://staging.crossmint.io/", | ||
prod = "https://www.crossmint.com", | ||
staging = "https://staging.crossmint.com", | ||
dev = "http://localhost:3001", | ||
@@ -18,2 +21,11 @@ } | ||
export enum ChainLocators { | ||
solana = "sol", | ||
ethereum = "eth", | ||
polygon = "poly", | ||
cardano = "ada", | ||
bsc = "bsc", | ||
} | ||
export type EVMChainLocators = ChainLocators.bsc | ChainLocators.ethereum | ChainLocators.polygon; | ||
type theme = "light" | "dark"; | ||
@@ -41,3 +53,2 @@ | ||
export interface PayButtonConfig { | ||
@@ -92,1 +103,60 @@ type: string; | ||
}; | ||
export interface Wallet { | ||
chain: string; | ||
publicKey: string; | ||
} | ||
interface Colors { | ||
textPrimary?: string; | ||
textSecondary?: string; | ||
accent?: string; | ||
background?: string; | ||
backgroundSecondary?: string; | ||
border?: string; | ||
} | ||
interface UIConfig { | ||
colors?: Colors; | ||
} | ||
interface CommonProps { | ||
uiConfig?: UIConfig; | ||
environment?: string; | ||
} | ||
export interface NFTCollectionViewProps extends CommonProps { | ||
wallets: Wallet[]; | ||
} | ||
export interface CardanoNFT { | ||
chain: "cardano"; | ||
assetId: string; | ||
} | ||
export interface EVMNFT { | ||
chain: EVMChain; | ||
contractAddress: string; | ||
tokenId: string; | ||
} | ||
export interface SolanaNFT { | ||
mintHash: string; | ||
chain: "solana"; | ||
} | ||
export type NFTLocator<T extends ChainLocators> = `${T}:${string}${T extends EVMChainLocators ? `:${string}` : ""}`; | ||
export type NFT = | ||
| CardanoNFT | ||
| EVMNFT | ||
| SolanaNFT | ||
| NFTLocator<ChainLocators.solana> | ||
| NFTLocator<ChainLocators.ethereum> | ||
| NFTLocator<ChainLocators.polygon> | ||
| NFTLocator<ChainLocators.bsc> | ||
| NFTLocator<ChainLocators.cardano>; | ||
export interface NFTDetailProps extends CommonProps { | ||
nft: NFT; | ||
} |
export * from "./generateClientId"; | ||
export * from "./validate"; | ||
export * from "./ui"; |
@@ -1,2 +0,2 @@ | ||
import { baseUrls } from "../models/types"; | ||
import { ChainLocators, NFT, NFTCollectionViewProps, NFTDetailProps, baseUrls } from "../models/types"; | ||
@@ -9,1 +9,43 @@ export const getEnvironmentBaseUrl = (environment = ""): string => { | ||
}; | ||
function getNFTLocator(nft: NFT) { | ||
if (typeof nft === "string") { | ||
return nft; | ||
} | ||
switch (nft.chain) { | ||
case "solana": | ||
return `${ChainLocators.solana}:${nft.mintHash}`; | ||
case "polygon": | ||
case "ethereum": | ||
case "bsc": | ||
return `${ChainLocators[nft.chain]}:${nft.contractAddress}:${nft.tokenId}`; | ||
case "cardano": | ||
return `${ChainLocators[nft.chain]}:${nft.assetId}`; | ||
default: | ||
throw new Error(`Invalid chain type ${JSON.stringify(nft)}`); | ||
} | ||
} | ||
export function getNFTCollectionViewSrc(props: NFTCollectionViewProps, clientVersion: string) { | ||
const baseUrl = getEnvironmentBaseUrl(props.environment); | ||
const { wallets } = props; | ||
const walletsStringify = JSON.stringify(wallets); | ||
const queryParams = new URLSearchParams({ | ||
wallets: walletsStringify, | ||
clientVersion, | ||
...(props.uiConfig != null ? { uiConfig: JSON.stringify(props.uiConfig) } : {}), | ||
}); | ||
return `${baseUrl}/sdk/wallets/collection?${queryParams.toString()}`; | ||
} | ||
export function getNFTDetailSrc(props: NFTDetailProps, clientVersion: string) { | ||
const baseUrl = getEnvironmentBaseUrl(props.environment); | ||
const queryParams = new URLSearchParams({ | ||
clientVersion, | ||
...(props.uiConfig != null ? { uiConfig: JSON.stringify(props.uiConfig) } : {}), | ||
}); | ||
const tokenLocator = getNFTLocator(props.nft); | ||
return `${baseUrl}/sdk/wallets/tokens/${tokenLocator}?${queryParams.toString()}`; | ||
} |
Sorry, the diff of this file is not supported yet
57472
18
881