1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-sui-y6CUr_B6.js","assets/vendor-react-COL_fmx_.js"])))=>i.map(i=>d[i]); 2import{r as f,j as a}from"./vendor-react-COL_fmx_.js";import{_ as R,aE as z,aF as Q,aG as Z,aH as V,aI as ee,aJ as te,aK as G,aL as ne,aM as Y,aN as se,aO as ae,aP as q}from"./index-Cc-3hq20.js";import{g as re}from"./suiGrpcFailover-BjN35zYs.js";import"./vendor-three-CoHYrz5L.js";class m extends Error{reason;submitted;digest;constructor(t,r,n=!1,s){super(t),this.name="SponsoredTxError",this.reason=r,this.submitted=n,this.digest=s}}function K(e){const t=String(e?.message||e||"").toLowerCase();return t.includes("reject")||t.includes("denied")||t.includes("cancel")||t.includes("dismiss")}const oe={rejected:"Signature request was declined.",gas:"Your wallet needs a small amount of testnet SUI for the network fee (gas sponsorship was unavailable).",onChainFailure:"The transaction failed on-chain (nothing was charged).",noDigest:"Wallet did not return a transaction digest."};let U=null;function ie(){return U||(U=Promise.all([R(()=>import("./vendor-sui-y6CUr_B6.js").then(e=>e.e),__vite__mapDeps([0,1])),R(()=>import("./vendor-sui-y6CUr_B6.js").then(e=>e.i),__vite__mapDeps([0,1]))]).then(([e,t])=>({toBase64:e.toBase64,fromBase64:e.fromBase64,transactionFrom:r=>t.Transaction.from(r)}))),U}function J(e){return Array.isArray(e)?e.map(t=>({eventType:t?.eventType,json:t?.json??null})):[]}async function ce(e){const{tx:t,signer:r,sender:n,sponsorUrl:s,client:i,onStage:u,includeEvents:d=!1,fetchImpl:o=((...c)=>fetch(...c)),extractFailureMessage:x,logLabel:p="sponsored-tx"}=e,h={...oe,...e.messages??{}},y=d?{include:{events:!0}}:{};if(t.setSender(n),s){const c=e.codec??await ie();let k=null,E=null,T=null;try{u("requesting-sponsorship");const l=await t.build({client:i,onlyTransactionKind:!0}),w=await o(`${s.replace(/\/$/,"")}/sponsor`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({txKindB64:c.toBase64(l),sender:n,timestamp:Date.now()})});if(!w.ok)throw new Error(`sponsor ${w.status}`);const v=await w.json();if(!v?.txB64||!v?.sponsorSignature)throw new Error("sponsor response incomplete");u("awaiting-signature");const I=c.transactionFrom(c.fromBase64(v.txB64));try{const N=await r.signTransaction({transaction:I});if(!N?.signature)throw new m("Wallet returned no signature.","error");T=N.signature,k=v.txB64,E=v.sponsorSignature}catch(N){throw K(N)?new m(h.rejected,"rejected"):N}}catch(l){if(l instanceof m&&l.reason==="rejected")throw l;console.warn(`[${p}] sponsorship acquisition failed, falling back to user-paid gas:`,l),u("sponsor-fallback")}if(k&&E&&T){let l;try{u("submitting"),l=await i.core.executeTransaction({transaction:c.fromBase64(k),signatures:[T,E],...y})}catch(I){throw new m(`The transaction was sent but its outcome is unknown (${String(I?.message||I)}).`,"error",!0)}if(l?.$kind==="FailedTransaction")throw new m(x?.(l)??h.onChainFailure,"error",!0,l.FailedTransaction?.digest);const w=l?.Transaction?.digest;if(!w)throw new m(h.noDigest,"error",!0);const v=J(l?.Transaction?.events);try{u("confirming"),await i.core.waitForTransaction({digest:w})}catch{throw new m(`The transaction was submitted (digest ${w}) but confirmation timed out.`,"error",!0,w)}return{digest:w,sponsored:!0,events:v}}}u("awaiting-signature");let b;try{const c=await r.signAndExecuteTransaction({transaction:t});if(c?.$kind==="FailedTransaction")throw new m(x?.(c)??h.onChainFailure,"error",!0,c.FailedTransaction?.digest);b=c?.digest??c?.Transaction?.digest}catch(c){if(c instanceof m)throw c;if(K(c))throw new m(h.rejected,"rejected");const k=String(c?.message||"").toLowerCase();throw k.includes("gas")||k.includes("insufficient")?new m(h.gas,"gas"):new m(String(c?.message||"Transaction failed."),"error",!0)}if(!b)throw new m(h.noDigest,"error",!0);u("confirming");let j;try{j=await i.core.waitForTransaction({digest:b,...y})}catch{throw new m(`The transaction was submitted (digest ${b}) but confirmation timed out.`,"error",!0,b)}if(j?.$kind==="FailedTransaction")throw new m(x?.(j)??h.onChainFailure,"error",!0,b);return{digest:b,sponsored:!1,events:J(j?.Transaction?.events)}}let P=null;function le(){return P||(P=fetch("/api/intel/commerce-config",{credentials:"include"}).then(async e=>{if(!e.ok)throw new Error(`HTTP ${e.status}`);const t=await e.json();return t.configured?t:null}).catch(e=>{throw P=null,e})),P}
2class S extends Error{reason;submitted;digest;constructor(t,r,n=!1,s){super(t),this.name="IntelPurchaseError",this.reason=r,this.submitted=n,this.digest=s}}const ue="0x6",de=20;function X(){return re()}async function fe(e,t,r){const n=r??await X(),{balance:s}=await n.core.getBalance({owner:e,coinType:t});return BigInt(s.balance)}async function he(e,t,r){const n=[];let s=null;do{const i=await e.core.listCoins({owner:t,coinType:r,...s?{cursor:s}:{}});for(const u of i.objects)n.push({objectId:u.objectId,version:u.version,digest:u.digest,balance:BigInt(u.balance)});s=i.hasNextPage?i.cursor:null}while(s);return n}async function me(e,t,r,n,s){const i=await he(t,r,n);i.sort((p,h)=>h.balance>p.balance?1:h.balance<p.balance?-1:0);const u=i.reduce((p,h)=>p+h.balance,0n);if(u<s)throw new S(`Insufficient balance: need ${s}, have ${u}`,"funds");const d=i[0],o=e.objectRef({objectId:d.objectId,version:d.version,digest:d.digest});if(d.balance<s){const p=[];let h=d.balance;for(const y of i.slice(1)){if(h>=s)break;if(p.length>=de)throw new S("Wallet EVE is fragmented across too many coins â consolidate first.","funds");p.push(e.objectRef({objectId:y.objectId,version:y.version,digest:y.digest})),h+=y.balance}e.mergeCoins(o,p)}const[x]=e.splitCoins(o,[e.pure.u64(s)]);return x}async function ge(){const{Transaction:e}=await R(async()=>{const{Transaction:t}=await import("./vendor-sui-y6CUr_B6.js").then(r=>r.i);return{Transaction:t}},__vite__mapDeps([0,1]));return new e}async function pe(e,t,r,n){const s=await n(),i=await me(s,t,r,e.coinType,BigInt(e.priceRaw));return s.moveCall({target:`${e.packageId}::payments::pay`,typeArguments:[e.coinType],arguments:[s.object(e.registryId),s.object(e.merchantId),s.pure.u64(BigInt(e.productId)),s.pure.u64(1n),i,s.pure.address(r),s.pure.option("string","ef-map-intel-unlock"),s.object(ue)]}),s}async function we(e,t,r,n,s={}){n("preparing");const i=s.client??await X(),u=await fe(r,e.coinType,i);if(u<BigInt(e.priceRaw))throw new S(`This wallet holds ${$(u,e.coinDecimals)} ${e.coinSymbol}; the unlock costs ${$(BigInt(e.priceRaw),e.coinDecimals)} ${e.coinSymbol}. In-game, open Wallet â Currency Exchange and convert LUX to ${e.coinSymbol}.`,"funds");let d;try{d=await pe(e,i,r,s.createTransaction??ge)}catch(o){throw o instanceof S?o:new S(String(o?.message||"Could not prepare the payment transaction."),"error",!1)}try{const o=await ce({tx:d,signer:t,sender:r,sponsorUrl:e.sponsorUrl,client:i,onStage:n,codec:s.codec,fetchImpl:s.fetchImpl,logLabel:"intel-purchase",messages:{gas:"Your wallet needs a small amount of testnet SUI to cover the network fee (gas sponsorship was unavailable).",onChainFailure:"The payment transaction failed on-chain.",noDigest:"Wallet did not return a transaction digest."}});return{digest:o.digest,sponsored:o.sponsored}}catch(o){throw o instanceof m?new S(o.message,o.reason,o.submitted,o.digest):o instanceof S?o:new S(String(o?.message||"Payment failed."),"error",!1)}}function $(e,t){const r=10n**BigInt(t),n=e/r,s=e%r;if(s===0n)return n.toString();const i=s.toString().padStart(t,"0").replace(/0+$/,"");return`${n}.${i}`}function ye(){return f.useSyncExternalStore(ae,q,q)}const be={preparing:"Preparing transactionâ¦","requesting-sponsorship":"Requesting gas sponsorshipâ¦","sponsor-fallback":"Sponsor unavailable â your wallet pays the small SUI network fee instead.","awaiting-signature":"Waiting for your wallet signatureâ¦",submitting:"Submitting transactionâ¦",confirming:"Waiting for on-chain confirmationâ¦"},je=()=>{const e=z(),t=Q(),r=ye(),[n,s]=f.useState(void 0),[i,u]=f.useState(!1),[d,o]=f.useState("idle"),[x,p]=f.useState(null),[h,y]=f.useState(!1),[b,j]=f.useState(null),[c,k]=f.useState(null),[E,T]=f.useState(null);f.useEffect(()=>{Z()},[]),f.useEffect(()=>{let C=!1;return le().then(g=>{C||s(g)}).catch(()=>{C||(s(null),u(!0))}),()=>{C=!0}},[]);const l=t.sessionAddress,w=!!(e.isConnected&&e.walletAddress&&l&&e.walletAddress.toLowerCase()!==l.toLowerCase()),v=f.useCallback(()=>{j(null),e.isConnected||V(),Promise.resolve(t.connectAndSign()).then(()=>{})},[t,e.isConnected]),[I,N]=f.useState(!1);f.useEffect(()=>{l&&!I&&(N(!0),ee())},[l,I]);const[L,M]=f.useState(null),_=f.useRef(!1),A=f.useRef(null),F=f.useCallback(async C=>{o("confirming-entitlement");const g=await te();return g==="entitled"?(C&&!_.current&&(_.current=!0,G()),o("unlocked"),!0):(M(g),o(C?"payment-unresolved":"confirm-timeout"),!1)},[]),H=f.useCallback(async()=>
2{if(!n||!e.signer||!l||!e.walletAddress)return;j(null),T(null),k(null),y(!1),M(null),_.current=!1,A.current=null,o("purchasing");const C=!!n.sponsorUrl;ne(C);try{const g=await we(n,e.signer,e.walletAddress,B=>{p(B),B==="sponsor-fallback"&&y(!0)});k(g.digest),G(),await F(!1)}catch(g){const B=g instanceof S?g.reason:"error",W=B==="gas"?"funds":B==="sponsor"?"sponsor":B==="rejected"?"rejected":B==="funds"?"funds":"error",O=g instanceof Error?g.message:"Payment failed.";if(g instanceof S&&g.submitted){p(null),T(O),g.digest&&k(g.digest),A.current=W,await F(!0);return}Y(W),j(O),o("idle"),p(null)}},[n,e.signer,e.walletAddress,l,F]),D=n?$(BigInt(n.priceRaw),n.coinDecimals):null;return r.phase==="checking"?a.jsx("div",{className:"ef-intel-unlock-status",children:"Checking accessâ¦"}):r.entitled||d==="unlocked"?a.jsxs("div",{className:"ef-intel-unlock-status ok",children:["Intelligence is unlocked for this wallet",r.expiresAtMs?` until ${new Date(r.expiresAtMs).toLocaleDateString()}`:"","."]}):n===void 0?a.jsx("div",{className:"ef-intel-unlock-status",children:"Loading unlock detailsâ¦"}):n===null?a.jsx("div",{className:"ef-intel-unlock-status",children:i?"Unlock details are temporarily unavailable. Please try again shortly.":"Unlocking is not available on this deployment yet."}):a.jsxs("div",{className:"ef-intel-unlock-flow",children:[a.jsxs("div",{className:"ef-intel-unlock-offer",children:[a.jsxs("span",{className:"ef-intel-unlock-offer-price",children:[D," ",n.coinSymbol]}),a.jsxs("span",{className:"ef-intel-unlock-offer-duration",children:[n.durationDays," days of access"]}),a.jsxs("span",{className:"ef-intel-unlock-offer-wallet",children:["Uses the ",n.coinSymbol," balance shown in your in-game Wallet."]})]}),d==="purchasing"&&x&&a.jsxs("div",{className:"ef-intel-unlock-status busy",role:"status",children:[be[x],h&&x!=="sponsor-fallback"&&a.jsx("span",{className:"ef-intel-unlock-substatus",children:"Gas sponsor unavailable â your wallet pays the SUI network fee."})]}),d==="confirming-entitlement"&&a.jsx("div",{className:"ef-intel-unlock-status busy",role:"status",children:E?"Payment submitted â confirming with the network. Do not pay again; checking whether your access is already activeâ¦":"Payment confirmed on-chain. Verifying your entitlementâ¦"}),d==="payment-unresolved"&&a.jsxs("div",{className:"ef-intel-unlock-status warn",role:"alert",children:["Your payment was submitted",c?` (tx ${c.slice(0,10)}â¦)`:""," but we could not confirm its outcome, and no entitlement is visible yet. Check your wallet before paying again â if the payment did go through, access unlocks automatically once it is picked up.",E?a.jsx("span",{className:"ef-intel-unlock-substatus",children:E}):null,L==="unknown"&&a.jsx("span",{className:"ef-intel-unlock-substatus",children:"The access check itself is currently unavailable, so we cannot tell yet whether the payment landed. Wait a moment and check again â do not pay again until this resolves."}),a.jsx("button",{type:"button",className:"ef-intel-unlock-btn secondary",onClick:()=>{F(!0)},children:"Check access again"}),L==="not-entitled"&&a.jsx("button",{type:"button",className:"ef-intel-unlock-btn secondary",onClick:()=>{A.current&&(Y(A.current),A.current=null),j(E),T(null),o("idle")},children:"I checked my wallet â pay again"})]}),d==="confirm-timeout"&&a.jsxs("div",{className:"ef-intel-unlock-status warn",role:"status",children:["Your payment succeeded on-chain",c?` (tx ${c.slice(0,10)}â¦)`:"",", but the entitlement check is lagging. Access unlocks automatically once it catches up â or reload in a minute.",a.jsx("button",{type:"button",className:"ef-intel-unlock-btn secondary",onClick:()=>{se({fresh:!0})},children:"Check again"})]}),b&&d==="idle"&&a.jsx("div",{className:"ef-intel-unlock-status error",role:"alert",children:b}),r.degraded&&d==="idle"&&a.jsx("div",{className:"ef-intel-unlock-status warn",children:"The entitlement service is temporarily degraded â status may be stale."}),d==="idle"&&a.jsx("div",{className:"ef-intel-unlock-actions",children:l?w?a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"ef-intel-unlock-status warn",children:"The connected wallet differs from the signed-in session. Sign in with the connected wallet to continue."}),a.jsx("button",{type:"button",className:"ef-intel-unlock-btn",disabled:t.authBusy,onClick:v,children:"Sign in with this wallet"})]}):e.isConnected?a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"ef-intel-unlock-btn",onClick:()=>{H()},children:["Unlock for ",$(BigInt(n.priceRaw),n.coinDecimals)," ",n.coinSymbol]}),a.jsxs("span",{className:"ef-intel-unlock-note",children:["Pays ",D," ",n.coinSymbol," from your connected wallet to EF-Map.",n.sponsorUrl?" The network fee is covered by EF-Map when available.":" Your wallet pays a tiny SUI network fee."]})]}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"ef-intel-unlock-status",children:["Signed in as ",l.slice(0,8),"â¦",l.slice(-4)," â reconnect your wallet to pay."]}),a.jsx("button",{type:"button",className:"ef-intel-unlock-btn",onClick:()=>{V(),e.handleConnect()},children:"Reconnect wallet"})]}):a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"ef-intel-unlock-btn",disabled:t.authBusy,onClick:v,children:t.authBusy?"Waiting for walletâ¦":e.isConnected?"Sign in to verify your wallet":"Connect EVE Vault"}),a.jsxs("span",{className:"ef-intel-unlock-note",children:["Connect to verify your wallet. You will c
2onfirm the ",D," ",n.coinSymbol," payment separately.",t.authError?` (${t.authError})`:""]})]})}),d==="idle"&&a.jsxs("p",{className:"ef-intel-unlock-hint",children:["Need ",n.coinSymbol,"? In-game, open Wallet â Currency Exchange and convert LUX to ",n.coinSymbol,"."]}),a.jsx("p",{className:"ef-intel-unlock-env",children:"This purchase is on the current test server. Pricing may change and does not indicate future Mainnet pricing."})]})};export{je as IntelUnlockFlow};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.