@mojito-inc/secondary-market
Version:
Mojito secondary market is the platform to purchase NFT.
2 lines (1 loc) • 2.56 kB
JavaScript
import{ethers as s}from"ethers";import e from"../constant/contractABI/ListitemERC115.js";import i from"../constant/contractABI/ListitemERC721.js";import{ErrorsType as a}from"../constant/index.js";async function n({tokenId:n,tokenType:d,contractAddress:o,toAddress:t,signer:l,walletAddress:r,maxFeePerGas:u,maxPriorityFeePerGas:v}){var m,c,g,E,h,R,f,F,I,N,P,S,p,x,y,C,T,U;try{if(d.includes("ERC-721")){const e=new s.Contract(o,i.abi,l),a=await e["safeTransferFrom(address,address,uint256)"](r,t,n,{maxFeePerGas:u,maxPriorityFeePerGas:v});return a.hash?{status:!0,message:a.hash}:{status:!1,message:a.hash}}const a=new s.Contract(o,e.abi,l),m="0x000000000000000000000000",c="1",g=await a["safeTransferFrom(address,address,uint256,uint256,bytes)"](r,t,n,c,m,{maxFeePerGas:u,maxPriorityFeePerGas:v});return g.hash?{status:!0,message:g.hash}:{status:!1,message:g.hash}}catch(s){return(null===(c=null===(m=null==s?void 0:s.data)||void 0===m?void 0:m.message)||void 0===c?void 0:c.includes(a.USER_REJECTED))||(null===(g=null==s?void 0:s.message)||void 0===g?void 0:g.includes(a.USER_REJECTED))||(null===(h=null===(E=null==s?void 0:s.data)||void 0===E?void 0:E.message)||void 0===h?void 0:h.includes(a.USER_DENIED))||(null===(R=null==s?void 0:s.message)||void 0===R?void 0:R.includes(a.USER_DENIED))?{status:!1,message:"Reject"}:(null===(F=null===(f=null==s?void 0:s.data)||void 0===f?void 0:f.message)||void 0===F?void 0:F.includes(a.INSUFFICIENT_FUNDS))||(null===(I=null==s?void 0:s.message)||void 0===I?void 0:I.includes(a.INSUFFICIENT_FUNDS))?{status:!1,message:"There is no sufficient balance in your wallet for this transaction"}:(null===(P=null===(N=null==s?void 0:s.data)||void 0===N?void 0:N.message)||void 0===P?void 0:P.includes(a.SIGNER_ERROR))||(null===(S=null==s?void 0:s.message)||void 0===S?void 0:S.includes(a.SIGNER_ERROR))?{status:!1,message:"Please provide a valid signer for this transaction"}:(null===(p=null==s?void 0:s.message)||void 0===p?void 0:p.includes("Invalid ENS name"))||(null===(y=null===(x=s.data)||void 0===x?void 0:x.message)||void 0===y?void 0:y.includes("Invalid ENS name"))?{status:!1,message:"The ENS name is invalid or not configured"}:(null===(C=null==s?void 0:s.message)||void 0===C?void 0:C.includes("Provider initialization failed"))||(null===(U=null===(T=null==s?void 0:s.data)||void 0===T?void 0:T.message)||void 0===U?void 0:U.includes("Provider initialization failed"))?{status:!1,message:"Failed to initialize provider"}:{status:!1,message:"Unable to process the request. Please try again."}}}export{n as transferToken};