@mojito-inc/secondary-market
Version:
Mojito secondary market is the platform to purchase NFT.
2 lines (1 loc) • 1.74 kB
JavaScript
;var e=require("react"),t=require("@mojito-inc/core-service");exports.useTokenDetails=(r,n,o)=>{const{getNFTDetails:a}=t.useNFT(),{getConversionRate:u}=t.useConversion(),{getSupportedNetworks:c}=t.useConnectWallet(),[s,l]=e.useState(),[i,d]=e.useState([]),[v,y]=e.useState(),[g,C]=e.useState(!1),[S,k]=e.useState(!1),[D,f]=e.useState(!1),[I,h]=e.useState(!1),[p,w]=e.useState(!1),N=e.useCallback((()=>{w(!1),C(!0),k(!0)}),[]),T=e.useCallback((async()=>{var e;if(o&&!n)return C(!1),l(o),o;try{w(!1);const t=await a({orgId:r.orgId,onChainTokenID:r.onChainTokenID,contractAddress:r.contractAddress,currency:(null==r?void 0:r.currency)||"USD"},{fetchPolicy:"no-cache"}),n=null===(e=null==t?void 0:t.data)||void 0===e?void 0:e.getNFTDetails;return l(n),C(!1),n}catch(e){return C(!1),l(null),w(!0),null}}),[r,o,n,a]);return e.useEffect((()=>{S&&(k(!1),T())}),[S,T]),e.useEffect((()=>{(async()=>{var e;try{w(!1),f(!0);const t=null===(e=(await c({includeTestnets:!0,orgId:r.orgId})).data)||void 0===e?void 0:e.getSupportedNetworks;return d(t),f(!1),t}catch(e){return f(!1),d(null),w(!0),[]}})()}),[r.orgId,c]),e.useEffect((()=>{(async()=>{var e,t,n,o;try{w(!1),h(!0);const a=await u({fromCurrecny:r.cryptoCurrencyCode||"VIN",toCurrency:r.currency||"USD"}),c=null===(e=null==a?void 0:a.data)||void 0===e?void 0:e.getConversionRate;return y({amount:(null!==(t=null==c?void 0:c.rate)&&void 0!==t?t:0).toString(),base:null!==(n=null==c?void 0:c.base)&&void 0!==n?n:"",currency:null!==(o=null==c?void 0:c.currency)&&void 0!==o?o:""}),h(!1),c}catch(e){return h(!1),y(null),w(!0),null}})()}),[r.cryptoCurrencyCode,r.currency,u]),{tokenData:s,networkData:i,usdData:v,detailsLoading:g,isNetworkLoading:D,isPriceLoading:I,isError:p,reFetchAPI:N}};