@mojito-inc/secondary-market
Version:
Mojito secondary market is the platform to purchase NFT.
2 lines (1 loc) • 3.33 kB
JavaScript
import{jsx as e}from"react/jsx-runtime";import{useState as l,useCallback as o,useEffect as n}from"react";import{ProviderType as i}from"../interface/index.js";import a from"../layout/TransferNFTLayout.js";import{transferToken as t}from"../utils/transferNFT.utils.js";import{validateWalletAddress as r}from"../utils/validateWalletAddress.utils.js";const d=({open:d,tokenDetails:s,walletDetails:u,configChainId:v,networksData:c,mediaCardAttributes:m,onCloseTransferNFTModal:p,onOpenSuccessModal:T,onOpenLoadingModal:g})=>{var h;const[f,k]=l(""),[w,y]=l(!1),[A,b]=l(""),[D,I]=l(""),C=o((async()=>{const e=await navigator.clipboard.readText();k(e)}),[]),F=o((e=>{navigator.clipboard.writeText(e).then((()=>{b(e),setTimeout((()=>{b("close")}),1e3)})).catch((()=>{b("close")}))}),[]),P=o((e=>{k(e.target.value)}),[]),x=o((()=>{I(""),p(),k(""),y(!1)}),[p]),j=o((async()=>{var e,l,o,n,a,r,d;try{if(v!==(null===(e=null==u?void 0:u.networkDetails)||void 0===e?void 0:e.chainID)){const e=null===(n=null===(o=null===(l=null==c?void 0:c.filter)||void 0===l?void 0:l.call(c,(e=>e.chainID===v)))||void 0===o?void 0:o[0])||void 0===n?void 0:n.name;return void I(`Please switch to ${e} in the wallet to proceed.`)}I("");const m=(null==u?void 0:u.providerType)===i.EMAIL?null===(a=null==u?void 0:u.provider)||void 0===a?void 0:a.provider:null==u?void 0:u.provider,p=(null==u?void 0:u.providerType)===i.EMAIL?null==u?void 0:u.provider:null===(r=null==u?void 0:u.provider)||void 0===r?void 0:r.getSigner(),{maxFeePerGas:h,maxPriorityFeePerGas:k}=await m.getFeeData();if(s&&f){const e=await t({tokenId:String(null==s?void 0:s.onChainTokenID),tokenType:String(null==s?void 0:s.tokenType),toAddress:f,contractAddress:String(null==s?void 0:s.contractAddress),signer:p,walletAddress:null==u?void 0:u.walletAddress,maxFeePerGas:h,maxPriorityFeePerGas:k});if((null==e?void 0:e.message)&&(null==e?void 0:e.status)){g(null==e?void 0:e.message),x();const l=await m.waitForTransaction(null==e?void 0:e.message,1);0!==(null==l?void 0:l.status)&&T(null==e?void 0:e.message)}else"Reject"===(null==e?void 0:e.message)?I("Transaction has been cancelled by user"):I(null!==(d=null==e?void 0:e.message)&&void 0!==d?d:"")}}catch(e){I(null==e?void 0:e.message)}}),[s,null==u?void 0:u.provider,null==u?void 0:u.providerType,null==u?void 0:u.walletAddress,f,v,c,null===(h=null==u?void 0:u.networkDetails)||void 0===h?void 0:h.chainID,x,T,g]),N=o((async()=>{""===f?I("Please enter the wallet address"):r(f)?y(!0):I("Please enter valid wallet address")}),[f]),S=o((async()=>{I(""),y(!1)}),[]);return n((()=>{r(f)||""===f?I(""):I("Please enter valid wallet address")}),[f]),e(a,{open:d,copied:A,error:D,tokenDetails:{itemId:null==s?void 0:s.onChainTokenID,contractAddress:null==s?void 0:s.contractAddress,onChainTokenID:null==s?void 0:s.onChainTokenID,tokenImage:null==s?void 0:s.tokenImage,tokenName:null==s?void 0:s.tokenName,tokenSubTitle:null==s?void 0:s.tokenSubTitle,thumbnail:null==s?void 0:s.thumbnail},mediaCardAttributes:Object.assign(Object.assign({},m),{customThumbnail:(null==m?void 0:m.customThumbnail)||(null==s?void 0:s.thumbnail)}),walletDetails:u,transferWalletAddress:f,maxLength:42,confirmTransfer:w,onClickCopy:F,handlePaste:C,onCloseModal:x,onChangeWalletAddress:P,onTransferNFT:N,onConfirmTransferNFT:j,onEditWalletAddress:S})};export{d as default};