@campnetwork/origin 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.cjs +5 -5
- package/dist/core.esm.js +1 -1
- package/dist/react/index.esm.js +7 -4
- package/package.json +1 -1
package/dist/core.cjs
CHANGED
|
@@ -57,7 +57,7 @@ let y=null,h=null;const m=()=>(h||(h=t.createPublicClient({chain:c,transport:t.h
|
|
|
57
57
|
* @param deadline The deadline for the registration operation.
|
|
58
58
|
* @param fileKey Optional file key for file uploads.
|
|
59
59
|
* @return A promise that resolves with the registration data.
|
|
60
|
-
*/function E(e,t,n,i,r,s){return a(this,void 0,void 0,(function*(){const a={source:e,deadline:Number(t),licenseTerms:{price:n.price.toString(),duration:n.duration,royaltyBps:n.royaltyBps,paymentToken:n.paymentToken},metadata:i,parentId:Number(s)||0};void 0!==r&&(a.fileKey=r);const o=yield fetch(`${w}/auth/origin/register`,{method:"POST",headers:{Authorization:`Bearer ${this.getJwt()}`},body:JSON.stringify(a)});if(!o.ok)throw new Error(`Failed to get signature: ${o.statusText}`);const d=yield o.json();if(d.isError)throw new Error(`Failed to get signature: ${d.message}`);return d.data}))}function M(e,t){return this.callContractMethod(v,k,"updateTerms",[e,t],{waitForReceipt:!0})}function x(e){return this.callContractMethod(v,k,"requestDelete",[e])}function S(e){return this.callContractMethod(v,k,"getTerms",[e])}function $(e){return this.callContractMethod(v,k,"ownerOf",[e])}function O(e){return this.callContractMethod(v,k,"balanceOf",[e])}function F(e){return this.callContractMethod(v,k,"contentHash",[e])}function j(e){return this.callContractMethod(v,k,"tokenURI",[e])}function P(e){return this.callContractMethod(v,k,"dataStatus",[e])}function N(e,t){return a(this,void 0,void 0,(function*(){return this.callContractMethod(v,k,"royaltyInfo",[e,t])}))}function U(e){return this.callContractMethod(v,k,"getApproved",[e])}function D(e,t){return this.callContractMethod(v,k,"isApprovedForAll",[e,t])}function B(e,t,n){return this.callContractMethod(v,k,"transferFrom",[e,t,n])}function _(e,t,n,i){const a=i?[e,t,n,i]:[e,t,n];return this.callContractMethod(v,k,"safeTransferFrom",a)}function W(e,t){return this.callContractMethod(v,k,"approve",[e,t])}function
|
|
60
|
+
*/function E(e,t,n,i,r,s){return a(this,void 0,void 0,(function*(){const a={source:e,deadline:Number(t),licenseTerms:{price:n.price.toString(),duration:n.duration,royaltyBps:n.royaltyBps,paymentToken:n.paymentToken},metadata:i,parentId:Number(s)||0};void 0!==r&&(a.fileKey=r);const o=yield fetch(`${w}/auth/origin/register`,{method:"POST",headers:{Authorization:`Bearer ${this.getJwt()}`},body:JSON.stringify(a)});if(!o.ok)throw new Error(`Failed to get signature: ${o.statusText}`);const d=yield o.json();if(d.isError)throw new Error(`Failed to get signature: ${d.message}`);return d.data}))}function M(e,t){return this.callContractMethod(v,k,"updateTerms",[e,t],{waitForReceipt:!0})}function x(e){return this.callContractMethod(v,k,"requestDelete",[e])}function S(e){return this.callContractMethod(v,k,"getTerms",[e])}function $(e){return this.callContractMethod(v,k,"ownerOf",[e])}function O(e){return this.callContractMethod(v,k,"balanceOf",[e])}function F(e){return this.callContractMethod(v,k,"contentHash",[e])}function j(e){return this.callContractMethod(v,k,"tokenURI",[e])}function P(e){return this.callContractMethod(v,k,"dataStatus",[e])}function N(e,t){return a(this,void 0,void 0,(function*(){return this.callContractMethod(v,k,"royaltyInfo",[e,t])}))}function U(e){return this.callContractMethod(v,k,"getApproved",[e])}function D(e,t){return this.callContractMethod(v,k,"isApprovedForAll",[e,t])}function B(e,t,n){return this.callContractMethod(v,k,"transferFrom",[e,t,n])}function _(e,t,n,i){const a=i?[e,t,n,i]:[e,t,n];return this.callContractMethod(v,k,"safeTransferFrom",a)}function W(e,t){return this.callContractMethod(v,k,"approve",[e,t])}function q(e,t){return this.callContractMethod(v,k,"setApprovalForAll",[e,t])}var R,z,L,K,J,H,G,V,Z,Y,Q,X,ee,te,ne,ie=[{inputs:[{internalType:"address",name:"dataNFT_",type:"address"},{internalType:"uint16",name:"protocolFeeBps_",type:"uint16"},{internalType:"address",name:"treasury_",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"EnforcedPause",type:"error"},{inputs:[],name:"ExpectedPause",type:"error"},{inputs:[{internalType:"uint256",name:"expected",type:"uint256"},{internalType:"uint256",name:"actual",type:"uint256"}],name:"InvalidPayment",type:"error"},{inputs:[{internalType:"uint32",name:"periods",type:"uint32"}],name:"InvalidPeriods",type:"error"},{inputs:[{internalType:"uint16",name:"royaltyBps",type:"uint16"}],name:"InvalidRoyalty",type:"error"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"OwnableInvalidOwner",type:"error"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"OwnableUnauthorizedAccount",type:"error"},{inputs:[],name:"TransferFailed",type:"error"},{inputs:[],name:"Unauthorized",type:"error"},{inputs:[],name:"ZeroAddress",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"},{indexed:!0,internalType:"address",name:"buyer",type:"address"},{indexed:!1,internalType:"uint32",name:"periods",type:"uint32"},{indexed:!1,internalType:"uint256",name:"newExpiry",type:"uint256"},{indexed:!1,internalType:"uint256",name:"amountPaid",type:"uint256"}],name:"AccessPurchased",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"},{indexed:!0,internalType:"address",name:"creator",type:"address"}],name:"DataDeleted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"},{indexed:!0,internalType:"address",name:"creator",type:"address"},{indexed:!1,internalType:"bytes32",name:"contentHash",type:"bytes32"}],name:"DataMinted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"},{indexed:!1,internalType:"uint256",name:"royaltyAmount",type:"uint256"},{indexed:!1,internalType:"address",name:"creator",type:"address"},{indexed:!1,internalType:"uint256",name:"protocolAmount",type:"uint256"}],name:"RoyaltyPaid",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"},{indexed:!1,internalType:"uint128",name:"newPrice",type:"uint128"},{indexed:!1,internalType:"uint32",name:"newDuration",type:"uint32"},{indexed:!1,internalType:"uint16",name:"newRoyaltyBps",type:"uint16"},{indexed:!1,internalType:"address",name:"paymentToken",type:"address"}],name:"TermsUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{inputs:[{internalType:"address",name:"feeManager",type:"address"}],name:"addFeeManager",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"buyer",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"},{internalType:"uint32",name:"periods",type:"uint32"}],name:"buyAccess",outputs:[],stateMutability:"payable",type:"function"},{inputs:[],name:"dataNFT",outputs:[{internalType:"contract IpNFT",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"feeManagers",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"hasAccess",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"protocolFeeBps",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"feeManager",type:"address"}],name:"removeFeeManager",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"",type:"uint256"},{internalType:"address",name:"",type:"address"}],name:"subscriptionExpiry",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"treasury",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint16",name:"newFeeBps",type:"uint16"}],name:"updateProtocolFee",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newTreasury",type:"address"}],name:"updateTreasury",outputs:[],stateMutability:"nonpayable",type:"function"},{stateMutability:"payable",type:"receive"}];function ae(e,t,n,i){return this.callContractMethod(b,ie,"buyAccess",[e,t,n],{waitForReceipt:!0,value:i})}function re(e,t,n,i){return this.callContractMethod(b,ie,"renewAccess",[e,t,n],void 0!==i?{value:i}:void 0)}function se(e,t){return this.callContractMethod(b,ie,"hasAccess",[e,t])}function oe(e,t){return this.callContractMethod(b,ie,"subscriptionExpiry",[e,t])}
|
|
61
61
|
/**
|
|
62
62
|
* Approves a spender to spend a specified amount of tokens on behalf of the owner.
|
|
63
63
|
* If the current allowance is less than the specified amount, it will perform the approval.
|
|
@@ -67,12 +67,12 @@ let y=null,h=null;const m=()=>(h||(h=t.createPublicClient({chain:c,transport:t.h
|
|
|
67
67
|
* The Origin class
|
|
68
68
|
* Handles the upload of files to Origin, as well as querying the user's stats
|
|
69
69
|
*/
|
|
70
|
-
class de{constructor(t,n){
|
|
70
|
+
class de{constructor(t,n){R.add(this),z.set(this,(e=>a(this,void 0,void 0,(function*(){const t=yield fetch(`${w}/auth/origin/upload-url`,{method:"POST",body:JSON.stringify({name:e.name,type:e.type}),headers:{Authorization:`Bearer ${this.jwt}`}}),n=yield t.json();return n.isError?n.message:n.data})))),L.set(this,((e,t)=>a(this,void 0,void 0,(function*(){(yield fetch(`${w}/auth/origin/update-status`,{method:"PATCH",body:JSON.stringify({status:t,fileKey:e}),headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}})).ok||console.error("Failed to update origin status")})))),this.uploadFile=(t,n)=>a(this,void 0,void 0,(function*(){const i=yield r(this,z,"f").call(this,t);if(i){try{yield((t,n,i)=>new Promise(((a,r)=>{e.put(n,t,Object.assign({headers:{"Content-Type":t.type}},"undefined"!=typeof window&&"function"==typeof i?{onUploadProgress:e=>{if(e.total){const t=e.loaded/e.total*100;i(t)}}}:{})).then((e=>{a(e.data)})).catch((e=>{var t;const n=(null===(t=null==e?void 0:e.response)||void 0===t?void 0:t.data)||(null==e?void 0:e.message)||"Upload failed";r(n)}))})))(t,i.url,(null==n?void 0:n.progressCallback)||(()=>{}))}catch(e){throw yield r(this,L,"f").call(this,i.key,"failed"),new Error("Failed to upload file: "+e)}return yield r(this,L,"f").call(this,i.key,"success"),i}console.error("Failed to generate upload URL")})),this.mintFile=(e,t,n,i,r)=>a(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const a=yield this.uploadFile(e,r);if(!a||!a.key)throw new Error("Failed to upload file or get upload info.");const s=BigInt(Math.floor(Date.now()/1e3)+600),o=yield this.registerIpNFT("file",s,n,t,a.key,i),{tokenId:d,signerAddress:u,creatorContentHash:l,signature:p,uri:c}=o;// 10 minutes from now
|
|
71
71
|
if(!(d&&u&&l&&void 0!==p&&c))throw new Error("Failed to register IpNFT: Missing required fields in registration response.");const[y]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]}),h=yield this.mintWithSignature(y,d,i||BigInt(0),l,c,n,s,p);if("0x1"!==h.status)throw new Error(`Minting failed with status: ${h.status}`);return d.toString()})),this.mintSocial=(e,t)=>a(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const n=BigInt(Math.floor(Date.now()/1e3)+600),i={name:`${e} IpNFT`,description:`This is a ${e} IpNFT`},a=yield this.registerIpNFT(e,n,t,i),{tokenId:r,signerAddress:s,creatorContentHash:o,signature:d,uri:u}=a;// 10 minutes from now
|
|
72
72
|
if(!(r&&s&&o&&void 0!==d&&u))throw new Error("Failed to register Social IpNFT: Missing required fields in registration response.");const[l]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]}),p=yield this.mintWithSignature(l,r,BigInt(0),// parentId is not applicable for social IpNFTs
|
|
73
73
|
o,u,t,n,d);if("0x1"!==p.status)throw new Error(`Minting Social IpNFT failed with status: ${p.status}`);return r.toString()})),this.getOriginUploads=()=>a(this,void 0,void 0,(function*(){const e=yield fetch(`${w}/auth/origin/files`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`}});if(!e.ok)return console.error("Failed to get origin uploads"),null;return(yield e.json()).data})),this.jwt=t,this.viemClient=n,
|
|
74
74
|
// DataNFT methods
|
|
75
|
-
this.mintWithSignature=C.bind(this),this.registerIpNFT=E.bind(this),this.updateTerms=M.bind(this),this.requestDelete=x.bind(this),this.getTerms=S.bind(this),this.ownerOf=$.bind(this),this.balanceOf=O.bind(this),this.contentHash=F.bind(this),this.tokenURI=j.bind(this),this.dataStatus=P.bind(this),this.royaltyInfo=N.bind(this),this.getApproved=U.bind(this),this.isApprovedForAll=D.bind(this),this.transferFrom=B.bind(this),this.safeTransferFrom=_.bind(this),this.approve=W.bind(this),this.setApprovalForAll=
|
|
75
|
+
this.mintWithSignature=C.bind(this),this.registerIpNFT=E.bind(this),this.updateTerms=M.bind(this),this.requestDelete=x.bind(this),this.getTerms=S.bind(this),this.ownerOf=$.bind(this),this.balanceOf=O.bind(this),this.contentHash=F.bind(this),this.tokenURI=j.bind(this),this.dataStatus=P.bind(this),this.royaltyInfo=N.bind(this),this.getApproved=U.bind(this),this.isApprovedForAll=D.bind(this),this.transferFrom=B.bind(this),this.safeTransferFrom=_.bind(this),this.approve=W.bind(this),this.setApprovalForAll=q.bind(this),
|
|
76
76
|
// Marketplace methods
|
|
77
77
|
this.buyAccess=ae.bind(this),this.renewAccess=re.bind(this),this.hasAccess=se.bind(this),this.subscriptionExpiry=oe.bind(this)}getJwt(){return this.jwt}setViemClient(e){this.viemClient=e}
|
|
78
78
|
/**
|
|
@@ -106,13 +106,13 @@ this.buyAccess=ae.bind(this),this.renewAccess=re.bind(this),this.hasAccess=se.bi
|
|
|
106
106
|
* @param {CallOptions} [options] The call options.
|
|
107
107
|
* @returns {Promise<any>} A promise that resolves with the result of the contract call or transaction hash.
|
|
108
108
|
* @throws {Error} - Throws an error if the wallet client is not connected and the method is not a view function.
|
|
109
|
-
*/callContractMethod(e,n,i,s){return a(this,arguments,void 0,(function*(e,n,i,a,s={}){const o=t.getAbiItem({abi:n,name:i}),d=o&&"stateMutability"in o&&("view"===o.stateMutability||"pure"===o.stateMutability);if(!d&&!this.viemClient)throw new Error("WalletClient not connected.");if(d){const t=m();return(yield t.readContract({address:e,abi:n,functionName:i,args:a}))||null}{const[o]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]}),d=t.encodeFunctionData({abi:n,functionName:i,args:a});yield r(this,
|
|
109
|
+
*/callContractMethod(e,n,i,s){return a(this,arguments,void 0,(function*(e,n,i,a,s={}){const o=t.getAbiItem({abi:n,name:i}),d=o&&"stateMutability"in o&&("view"===o.stateMutability||"pure"===o.stateMutability);if(!d&&!this.viemClient)throw new Error("WalletClient not connected.");if(d){const t=m();return(yield t.readContract({address:e,abi:n,functionName:i,args:a}))||null}{const[o]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]}),d=t.encodeFunctionData({abi:n,functionName:i,args:a});yield r(this,R,"m",J).call(this,c);try{const t=yield this.viemClient.sendTransaction({to:e,data:d,account:o,value:s.value,gas:s.gas});if("string"!=typeof t)throw new Error("Transaction failed to send.");if(!s.waitForReceipt)return t;return yield r(this,R,"m",K).call(this,t)}catch(e){throw console.error("Transaction failed:",e),new Error("Transaction failed: "+e)}}}))}
|
|
110
110
|
/**
|
|
111
111
|
* Buy access to an asset by first checking its price via getTerms, then calling buyAccess.
|
|
112
112
|
* @param {bigint} tokenId The token ID of the asset.
|
|
113
113
|
* @param {number} periods The number of periods to buy access for.
|
|
114
114
|
* @returns {Promise<any>} The result of the buyAccess call.
|
|
115
|
-
*/buyAccessSmart(e,n){return a(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const i=yield this.getTerms(e);if(!i)throw new Error("Failed to fetch terms for asset");const{price:r,paymentToken:s}=i;if(void 0===r||void 0===s)throw new Error("Terms missing price or paymentToken");const
|
|
115
|
+
*/buyAccessSmart(e,n){return a(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const i=yield this.getTerms(e);if(!i)throw new Error("Failed to fetch terms for asset");const{price:r,paymentToken:s}=i;if(void 0===r||void 0===s)throw new Error("Terms missing price or paymentToken");const[o]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]}),d=r*BigInt(n);return s===t.zeroAddress?this.buyAccess(o,e,n,d):(yield function(e){return a(this,arguments,void 0,(function*({walletClient:e,publicClient:n,tokenAddress:i,owner:a,spender:r,amount:s}){(yield n.readContract({address:i,abi:t.erc20Abi,functionName:"allowance",args:[a,r]}))<s&&(yield e.writeContract({address:i,account:a,abi:t.erc20Abi,functionName:"approve",args:[r,s],chain:c}))}))}({walletClient:this.viemClient,publicClient:m(),tokenAddress:s,owner:o,spender:b,amount:d}),this.buyAccess(o,e,n))}))}getData(e){return a(this,void 0,void 0,(function*(){const t=yield fetch(`${w}/auth/origin/data/${e}`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!t.ok)throw new Error("Failed to fetch data");return t.json()}))}}z=new WeakMap,L=new WeakMap,R=new WeakSet,K=function(e){return a(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");for(;;){const t=yield this.viemClient.request({method:"eth_getTransactionReceipt",params:[e]});if(t&&t.blockNumber)return t;yield new Promise((e=>setTimeout(e,1e3)))}}))},J=function(e){return a(this,void 0,void 0,(function*(){
|
|
116
116
|
// return;
|
|
117
117
|
if(!this.viemClient)throw new Error("WalletClient not connected.");let t=yield this.viemClient.request({method:"eth_chainId",params:[]});if("string"==typeof t&&(t=parseInt(t,16)),t!==e.id)try{yield this.viemClient.request({method:"wallet_switchEthereumChain",params:[{chainId:"0x"+BigInt(e.id).toString(16)}]})}catch(t){
|
|
118
118
|
// Unrecognized chain
|
package/dist/core.esm.js
CHANGED
|
@@ -275,7 +275,7 @@ this.buyAccess=he.bind(this),this.renewAccess=me.bind(this),this.hasAccess=fe.bi
|
|
|
275
275
|
* @param {bigint} tokenId The token ID of the asset.
|
|
276
276
|
* @param {number} periods The number of periods to buy access for.
|
|
277
277
|
* @returns {Promise<any>} The result of the buyAccess call.
|
|
278
|
-
*/buyAccessSmart(e,t){return c(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const n=yield this.getTerms(e);if(!n)throw new Error("Failed to fetch terms for asset");const{price:i,paymentToken:a}=n;if(void 0===i||void 0===a)throw new Error("Terms missing price or paymentToken");const
|
|
278
|
+
*/buyAccessSmart(e,t){return c(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const n=yield this.getTerms(e);if(!n)throw new Error("Failed to fetch terms for asset");const{price:i,paymentToken:a}=n;if(void 0===i||void 0===a)throw new Error("Terms missing price or paymentToken");const[s]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]}),o=i*BigInt(t);return a===d?this.buyAccess(s,e,t,o):(yield function(e){return c(this,arguments,void 0,(function*({walletClient:e,publicClient:t,tokenAddress:n,owner:i,spender:a,amount:s}){(yield t.readContract({address:n,abi:r,functionName:"allowance",args:[i,a]}))<s&&(yield e.writeContract({address:n,account:i,abi:r,functionName:"approve",args:[a,s],chain:I}))}))}({walletClient:this.viemClient,publicClient:C(),tokenAddress:a,owner:s,spender:$,amount:o}),this.buyAccess(s,e,t))}))}getData(e){return c(this,void 0,void 0,(function*(){const t=yield fetch(`${M}/auth/origin/data/${e}`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!t.ok)throw new Error("Failed to fetch data");return t.json()}))}}X=new WeakMap,ee=new WeakMap,Q=new WeakSet,te=function(e){return c(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");for(;;){const t=yield this.viemClient.request({method:"eth_getTransactionReceipt",params:[e]});if(t&&t.blockNumber)return t;yield new Promise((e=>setTimeout(e,1e3)))}}))},ne=function(e){return c(this,void 0,void 0,(function*(){
|
|
279
279
|
// return;
|
|
280
280
|
if(!this.viemClient)throw new Error("WalletClient not connected.");let t=yield this.viemClient.request({method:"eth_chainId",params:[]});if("string"==typeof t&&(t=parseInt(t,16)),t!==e.id)try{yield this.viemClient.request({method:"wallet_switchEthereumChain",params:[{chainId:"0x"+BigInt(e.id).toString(16)}]})}catch(t){
|
|
281
281
|
// Unrecognized chain
|
package/dist/react/index.esm.js
CHANGED
|
@@ -2540,21 +2540,24 @@ class Origin {
|
|
|
2540
2540
|
if (price === undefined || paymentToken === undefined) {
|
|
2541
2541
|
throw new Error("Terms missing price or paymentToken");
|
|
2542
2542
|
}
|
|
2543
|
-
const
|
|
2543
|
+
const [account] = yield this.viemClient.request({
|
|
2544
|
+
method: "eth_requestAccounts",
|
|
2545
|
+
params: [],
|
|
2546
|
+
});
|
|
2544
2547
|
const totalCost = price * BigInt(periods);
|
|
2545
2548
|
const isNative = paymentToken === zeroAddress;
|
|
2546
2549
|
if (isNative) {
|
|
2547
|
-
return this.buyAccess(
|
|
2550
|
+
return this.buyAccess(account, tokenId, periods, totalCost);
|
|
2548
2551
|
}
|
|
2549
2552
|
yield approveIfNeeded({
|
|
2550
2553
|
walletClient: this.viemClient,
|
|
2551
2554
|
publicClient: getPublicClient(),
|
|
2552
2555
|
tokenAddress: paymentToken,
|
|
2553
|
-
owner:
|
|
2556
|
+
owner: account,
|
|
2554
2557
|
spender: constants.MARKETPLACE_CONTRACT_ADDRESS,
|
|
2555
2558
|
amount: totalCost,
|
|
2556
2559
|
});
|
|
2557
|
-
return this.buyAccess(
|
|
2560
|
+
return this.buyAccess(account, tokenId, periods);
|
|
2558
2561
|
});
|
|
2559
2562
|
}
|
|
2560
2563
|
getData(tokenId) {
|