PageSourceSearch

https://www.mousai.stream/assets/ClaimEarnings-CitNUNZI.js

js mousai.stream collected 2026-10-02 20:25:48 UTC 8,018 bytes, 1 lines download raw bytes

1import{z as L,s as N,j as e,ak as E,C as h,d as g,B as o,J as m,a as S,b as F,ae as J,k as O,c as W,M as G}from"./index-TijhCKtc.js";import{k as U,u as V,r as i}from"./react-vendor-C7Tss8ZZ.js";import{H as $}from"./Helmet-D4UNvvPt.js";import{C as q}from"./circle-alert-Q-jdrVSs.js";import{C as K}from"./circle-check-big-BL7u-8lR.js";import{D as Q}from"./dollar-sign-CyhZ0QzJ.js";import"./supabase-BFrdiX0J.js";import"./index-C0Wt4Dfg.js";const ne=()=>{var _;const{token:l}=U(),{user:b,loading:Y}=L(),d=V(),[I,x]=i.useState(!0),[y,C]=i.useState(!1),[t,M]=i.useState(null),[j,A]=i.useState([]),[p,B]=i.useState(0),[u,D]=i.useState(0),[c,R]=i.useState(null),[v,f]=i.useState(null),[T,w]=i.useState(!1);i.useEffect(()=>{if(!l){f("Invalid claim link"),x(!1);return}z()},[l]);const z=async()=>{try{const{data:s,error:r}=await N.rpc("get_claimable_earnings",{p_claim_token:l});if(r||!s){f("Invalid or expired claim link"),x(!1);return}const a=s;if(M({id:a.recipient_id,name:a.recipient_name,recipient_type:a.recipient_type,claim_status:a.claim_status}),a.already_claimed){w(!0),x(!1);return}A((a.earnings||[]).map(n=>({amount:Number(n.amount),track_title:n.track_title,artist_name:n.artist_name}))),B(Number(a.payable)||0),D(Number(a.accruing)||0),x(!1)}catch(s){console.error("Error fetching claim data:",s),f("Failed to load claim data"),x(!1)}},k=async()=>{if(!b){sessionStorage.setItem("pendingClaimToken",l||""),d("/auth?redirect=/claim/"+l);return}C(!0);try{const{data:s,error:r}=await N.rpc("claim_split_earnings",{p_claim_token:l});if(r)throw r;const a=s,n=Number(a==null?void 0:a.paid)||0,P=Number(a==null?void 0:a.accruing)||0;R({paid:n,accruing:P}),m.success(n>0?`$${n.toFixed(2)} added to your wallet!`:"Earnings claimed!"),w(!0)}catch(s){console.error("Error claiming earnings:",s);const r=String((s==null?void 0:s.message)||"");r.includes("already_claimed_by_other")?m.error("These earnings have already been claimed by another account."):r.includes("invalid_token")?m.error("This claim link is no longer valid."):m.error("Failed to claim earnings. Please try again.")}finally{C(!1)}},H=j.reduce((s,r)=>s+r.amount,0);return I||Y?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx(E,{className:"h-8 w-8 animate-spin text-primary"})}):v?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsx(h,{className:"max-w-md w-full",children:e.jsxs(g,{className:"pt-6 text-center",children:[e.jsx(q,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Claim Error"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:v}),e.jsx(o,{onClick:()=>d("/"),children:"Go Home"})]})})}):T?e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:[e.jsx($,{children:e.jsx("title",{children:"Earnings Claimed | Mousai.Stream"})}),e.jsx(h,{className:"max-w-md w-full",children:e.jsxs(g,{className:"pt-6 text-center",children:[e.jsx(K,{className:"h-12 w-12 text-green-500 mx-auto mb-4"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Earnings Claimed!"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:c&&c.paid>0?`$${c.paid.toFixed(2)} has been added to your wallet.`:"Your royalty earnings have been claimed."}),c&&c.accruing>0&&e.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["$",c.accruing.toFixed(4)," is still accruing and will be paid once it reaches one cent."]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(o,{onClick:()=>d("/wallet"),children:"View Wallet"}),e.jsx(o,{variant:"outline",onClick:()=>d("/"),children:"Explore Music"}),e.jsxs("div",{className:"border-t pt-4 mt-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Want to upload your own music?"}),e.jsx(o,{variant:"secondary",className:"w-full",onClick:async()=>{try{const{data:s}=await N.functions.invoke("upgrade-to-artist",{body:{recipientId:t==null?void 0:t.id,artistName:t==null?void 0:t.name}});s!=null&&s.success&&(m.success("You are now an artist! Redirecting..."),setTimeout(()=>d("/artist-dashboard"),1500))}catch{m.error("Failed to upgrade. You may already be an artist.")}},children:"Become an Artist"})]})]})]})})]}):e.jsxs("div",{className:"min-h-screen bg-background p-4",children:[e.jsxs($,{children:[e.jsx("title",{children:"Claim Your Earnings | Mous
1ai.Stream"}),e.jsx("meta",{name:"description",content:"Claim your royalty earnings from music streams on Mousai.Stream"})]}),e.jsxs("div",{className:"max-w-2xl mx-auto py-8",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h1",{className:"text-3xl font-bold mb-2",children:"Claim Your Earnings"}),e.jsx("p",{className:"text-muted-foreground",children:"You have royalty earnings waiting for you"})]}),e.jsxs(h,{className:"mb-6",children:[e.jsx(S,{children:e.jsxs(F,{className:"flex items-center gap-2",children:[e.jsx(J,{className:"h-5 w-5"}),"Recipient Details"]})}),e.jsx(g,{children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-muted-foreground",children:"Name"}),e.jsx("span",{className:"font-medium",children:t==null?void 0:t.name})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-muted-foreground",children:"Role"}),e.jsx(O,{variant:"secondary",className:"capitalize",children:(_=t==null?void 0:t.recipient_type)==null?void 0:_.replace("_"," ")})]})]})})]}),e.jsxs(h,{className:"mb-6",children:[e.jsxs(S,{children:[e.jsxs(F,{className:"flex items-center gap-2",children:[e.jsx(Q,{className:"h-5 w-5"}),"Pending Earnings"]}),e.jsx(W,{children:"Earnings from tracks you've contributed to"})]}),e.jsxs(g,{children:[j.length===0?e.jsx("p",{className:"text-muted-foreground text-center py-4",children:"No pending earnings at this time."}):e.jsx("div",{className:"space-y-3",children:j.map((s,r)=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-muted/50 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(G,{className:"h-8 w-8 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s.track_title||"a track"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["by ",s.artist_name||"an artist"]})]})]}),e.jsxs("span",{className:"font-bold text-green-600",children:["$",s.amount.toFixed(2)]})]},r))}),H>0&&e.jsxs("div",{className:"mt-4 pt-4 border-t space-y-1",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"font-semibold",children:"Claimable now"}),e.jsxs("span",{className:"text-2xl font-bold text-green-600",children:["$",p.toFixed(2)]})]}),u>0&&e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:["$",u.toFixed(4)," still accruing (paid once it reaches one cent)"]})]})]})]}),e.jsx(h,{children:e.jsx(g,{className:"pt-6",children:b?p<.01?e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-muted-foreground",children:j.length===0?"No earnings to claim right now.":`You have $${u.toFixed(4)} accruing. It will be payable once it reaches one cent.`})}):e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"Claim your earnings to add them to your wallet"}),e.jsx(o,{size:"lg",className:"w-full",onClick:k,disabled:y,children:y?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"mr-2 h-4 w-4 animate-spin"}),"Claiming..."]}):`Claim $${p.toFixed(2)}`}),u>0&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["$",u.toFixed(4)," more is still accruing."]})]}):e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"Sign in or create an account to claim your earnings"}),e.jsx(o,{size:"lg",className:"w-full",onClick:k,children:"Sign In to Claim"})]})})})]})]})};export{ne as default};

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.