UNPKG

@mojito-inc/secondary-market

Version:

Mojito secondary market is the platform to purchase NFT.

2 lines (1 loc) 1.47 kB
import{useState as e,useCallback as o,useEffect as t}from"react";import{useFee as l}from"@mojito-inc/core-service";const i=(i,n,a,r,c="USD")=>{const{estimateTaxAndRoyaltyFee:d}=l(),[v,u]=e({platformFee:0,royaltyFee:0,taxPercentage:0,commissionFee:0,taxResponse:{cryptoTaxPrice:0,cryptoTotalPrice:0,USDUnitprice:0,taxPercentage:0}}),[s,p]=e(!1),x=o((async()=>{var e,o,t,l,r,v,s,x,y,m,P,F,T;try{p(!0);const g=await d({orgId:i,estimateType:n,nftTokenId:a,price:1,currency:c}),R=null===(e=null==g?void 0:g.data)||void 0===e?void 0:e.estimateTaxAndRoyaltyFee;return u({platformFee:null!==(o=null==R?void 0:R.platformFee)&&void 0!==o?o:0,royaltyFee:null!==(t=null==R?void 0:R.royaltyFee)&&void 0!==t?t:0,taxPercentage:null!==(l=null==R?void 0:R.taxPercentage)&&void 0!==l?l:0,commissionFee:null!==(r=null==R?void 0:R.commissionFee)&&void 0!==r?r:0,taxResponse:{cryptoTaxPrice:null!==(s=null===(v=null==R?void 0:R.taxResponse)||void 0===v?void 0:v.cryptoTaxPrice)&&void 0!==s?s:0,cryptoTotalPrice:null!==(y=null===(x=null==R?void 0:R.taxResponse)||void 0===x?void 0:x.cryptoTotalPrice)&&void 0!==y?y:0,taxPercentage:null!==(P=null===(m=null==R?void 0:R.taxResponse)||void 0===m?void 0:m.taxPercentage)&&void 0!==P?P:0,USDUnitprice:null!==(T=null===(F=null==R?void 0:R.taxResponse)||void 0===F?void 0:F.USDUnitprice)&&void 0!==T?T:0}}),p(!1),R}catch(e){return p(!1),u(null),null}}),[d,i,n,a,c]);return t((()=>{r&&x()}),[r,x]),{taxData:v,taxLoading:s}};export{i as useTax};