PageSourceSearch

https://a2zworkhub.com/assets/js/WalletPage-VkMaWa-D.js

js a2zworkhub.com collected 2026-10-02 00:46:01 UTC 5,834 bytes, 1 lines download raw bytes

1import{b as v,c as _,a as d,s as x,j as e,L as j,o as C,ab as w,p as m}from"./index-WXqAjLLd.js";import{H as W}from"./history-B-M1FYLt.js";import{A as E,a as A}from"./arrow-up-circle-s9att6SW.js";function R(){const{user:l}=v(),{formatPrice:o}=_(),[h,N]=d.useState(null),[g,k]=d.useState([]),[r,b]=d.useState(!0),[u,n]=d.useState(null);d.useEffect(()=>{window.scrollTo({top:0,behavior:"smooth"}),l&&c()},[l]);const c=async()=>{if(l){n(null),b(!0);try{const{data:a,error:f}=await x.from("wallets").select("*").eq("user_id",l.id).maybeSingle();if(f){console.error("Wallet fetch error:",f),n("Failed to fetch wallet. Please try again.");return}let s=null;if(a)s=a;else{const{data:i,error:t}=await x.from("wallets").insert({user_id:l.id,balance:0}).select().single();if(t){console.error("Wallet creation error:",t),n("Failed to create wallet. Please try again.");return}i&&(s=i)}if(s){const i=typeof s.balance=="string"?parseFloat(s.balance):Number(s.balance);N({...s,balance:i})}const{data:y,error:p}=await x.from("wallet_transactions").select("*").eq("user_id",l.id).order("created_at",{ascending:!1}).limit(20);if(p)console.error("Transactions fetch error:",p),n("Failed to fetch transactions. Please try again.");else if(y){const i=y.map(t=>({...t,amount:typeof t.amount=="string"?parseFloat(t.amount):Number(t.amount),balance_after:typeof t.balance_after=="string"?parseFloat(t.balance_after):Number(t.balance_after)}));k(i)}}catch(a){console.error("Error fetching wallet data:",a),n("An unexpected error occurred. Please try again.")}finally{b(!1)}}};return r?e.jsx("div",{className:"flex items-center justify-center min-h-screen bg-gray-50 dark:bg-gray-900",children:e.jsx(j,{className:"w-8 h-8 animate-spin text-green-600 dark:text-green-500"})}):u?e.jsx("div",{className:"px-4 py-6 pb-24 animate-fadeIn min-h-screen bg-gray-50 dark:bg-gray-900",children:e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-2xl p-6 text-center mb-6",children:[e.jsx(C,{className:"w-12 h-12 text-red-500 dark:text-red-400 mx-auto mb-4"}),e.jsx("p",{className:"text-red-700 dark:text-red-300 mb-4",children:u}),e.jsx("button",{onClick:()=>{n(null),c()},className:"bg-red-600 text-white px-6 py-2 rounded-lg font-semibold hover:bg-red-700 transition-colors",children:"Retry"})]})}):e.jsxs("div",{className:"px-4 py-6 animate-fadeIn pb-24 min-h-screen bg-gray-50 dark:bg-gray-900",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900 dark:text-white mb-2",children:"My Wallet"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Manage your wallet balance"})]}),e.jsx("div",{className:"bg-gradient-to-br from-green-600 to-emerald-600 rounded-3xl p-6 shadow-xl mb-6 text-white relative",children:e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-white/80 text-sm mb-1",children:"Available Balance"}),e.jsx("h2",{className:"text-4xl font-bold",children:h?.balance?o(h.balance):o(0)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"bg-blue-50 dark:bg-blue-900/30 p-3 rounded-full",children:e.jsx(w,{className:"w-6 h-6 text-blue-600 dark:text-blue-400"})}),e.jsx("button",{onClick:c,disabled:r,className:"p-2 text-white/70 hover:text-white transition-colors disabled:opacity-50",title:"Refresh wallet data",children:e.jsx(m,{className:`w-5 h-5 ${r?"animate-spin":""}`})})]})]})}),e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white",children:"Transaction History"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(W,{className:"w-5 h-5 text-gray-400"}),e.jsx("button",{onClick:c,disabled:r,className:"p-1 text-gray-400 hover:text-gray-600 transition-colors disabled:opacity-50",title:"Refresh transactions",children:e.jsx(m,{className:`w-4 h-4 ${r?"animate-spin":""}`})})]})]}),g.length===0?e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl p-8 text-center",children:[e.jsx(w,{className:"w-16 h-16 text-gray-300 dark:text-gray-600 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"No transactions yet"}),e.jsxs("button",{onClick:c,disabled:r,className:"mt-4 text-green-600 hover:text-green-700 font-semibold flex items-center justify-center gap-1 mx-auto disabled:opacity-50",children:[r?e.jsx(j,{className:"w-4 h-4 animate-spin"}):e.jsx(m,{className:"w-4 h-4"}),"Refresh"]})]}):e.jsx("div",{className:"space-y-3",children:g.map(a=>e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-xl p-4 shadow-md hover:shadow-lg transition-all",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`w-12 h-12 rounded-full flex items-center justify-center ${a.type==="credit"?"bg-green-100 dark:bg-green-900/30":"bg-red-100 dark:bg-red-900/30"}`,children:a.type==="credit"?e.jsx(E,{className:"w-6 h-6 text-green-600 dark:text-green-500"}):e.jsx(A,{className:"w-6 h-6 text-red-600 dark:text-red-500"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-semibold text-gray-900 dark:text-white",children:a.description}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:new Date(a.created_at).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:`text-lg font-bold ${a.type==="credit"?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"}`,children:[a.type==="credit"?"+":"-",o(a.amount)]}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Balance: ",o(a.balance_after)]})]})]})},a.id))})]})}export{R as WalletPage};

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.