@cedros/pay-react 1.1.24 → 1.1.26
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/{AISettingsSection-Dw0ZlxMf.mjs → AISettingsSection-BlIv3CzS.mjs} +2 -2
- package/dist/{AISettingsSection-IXS1Wt_1.js → AISettingsSection-DELur7D2.js} +1 -1
- package/dist/{AutosaveIndicator-BJsg_kFZ.mjs → AutosaveIndicator-Bed0-ekg.mjs} +1 -1
- package/dist/{AutosaveIndicator-CY_YHM1D.js → AutosaveIndicator-Dn_qA2hK.js} +1 -1
- package/dist/CedrosContext-C2RjHLaQ.js +6 -0
- package/dist/{CedrosContext-DQUbL8yP.mjs → CedrosContext-CY6zvjvJ.mjs} +768 -617
- package/dist/ChatLogsSection-BH5tLA4T.js +1 -0
- package/dist/ChatLogsSection-v4zwzCTC.mjs +201 -0
- package/dist/ComplianceSection-CemgfDrL.mjs +650 -0
- package/dist/ComplianceSection-DP2a9-S0.js +1 -0
- package/dist/{CryptoButton-D1BCZBk4.mjs → CryptoButton-BV9owVe2.mjs} +2 -2
- package/dist/{CryptoButton-C1AAOOfj.js → CryptoButton-DpiCnyXE.js} +1 -1
- package/dist/CustomersSection-CBwy_waO.js +1 -0
- package/dist/CustomersSection-D_j7OrfS.mjs +207 -0
- package/dist/DisputesSection-BLjIk60n.js +1 -0
- package/dist/DisputesSection-BcAbXp3K.mjs +230 -0
- package/dist/{FAQSection-C78MnK4k.mjs → FAQSection-Dn38OhB_.mjs} +1 -1
- package/dist/{FAQSection-BmgmzDN5.js → FAQSection-wNeH0i6Q.js} +1 -1
- package/dist/ImagesSection-0ZzKlzMJ.js +1 -0
- package/dist/ImagesSection-Ctw9Icym.mjs +216 -0
- package/dist/InventorySection-DmhjUlRZ.mjs +150 -0
- package/dist/InventorySection-zV6lTmue.js +1 -0
- package/dist/{MessagingSection-De3t8bSI.mjs → MessagingSection-B1FaGxkp.mjs} +2 -2
- package/dist/{MessagingSection-CWLZcg11.js → MessagingSection-B_wdFR0j.js} +1 -1
- package/dist/{OrdersSection-_xKVzjSZ.mjs → OrdersSection-Bj8bPdg8.mjs} +6 -6
- package/dist/{OrdersSection-BKOxsZw0.js → OrdersSection-Dw2FX-1d.js} +1 -1
- package/dist/{PaymentSettingsSection-BTEn9Dxb.js → PaymentSettingsSection-BYF4D-GR.js} +1 -1
- package/dist/{PaymentSettingsSection-KjU_dN_d.mjs → PaymentSettingsSection-EnMxeWjv.mjs} +1 -1
- package/dist/ReturnsSection-BC0L8r2e.mjs +267 -0
- package/dist/ReturnsSection-D_pJVxuG.js +1 -0
- package/dist/{SettingsSection-8QHZB59k.mjs → SettingsSection-KYdEizq_.mjs} +19 -13
- package/dist/SettingsSection-vdYFSNxB.js +1 -0
- package/dist/ShippingSection-1DRSTu49.js +1 -0
- package/dist/ShippingSection-BOgto6_9.mjs +434 -0
- package/dist/{SingleCategorySettings-CRXTMTo5.js → SingleCategorySettings-DwCnBdRf.js} +1 -1
- package/dist/{SingleCategorySettings--LK0TZW0.mjs → SingleCategorySettings-suJ8z9d8.mjs} +4 -4
- package/dist/{StorefrontSection-CeCpr8hn.mjs → StorefrontSection-BRvIGBEJ.mjs} +2 -2
- package/dist/{StorefrontSection-C9DzCmOf.js → StorefrontSection-RumGkb3C.js} +1 -1
- package/dist/{SubscriptionsSection-Dn5SY6S_.js → SubscriptionsSection-C2aLLn7L.js} +1 -1
- package/dist/{SubscriptionsSection-C2xk8ApF.mjs → SubscriptionsSection-D60qrX9a.mjs} +7 -7
- package/dist/TaxSection-C7-pv-Rl.mjs +294 -0
- package/dist/TaxSection-Dt1DnM51.js +1 -0
- package/dist/Token22Section-CrHLQ0EB.mjs +2260 -0
- package/dist/Token22Section-DY3mUwTY.js +1 -0
- package/dist/{WalletManager-Bwk3rgr1.js → WalletManager-B3UdQ5pQ.js} +1 -1
- package/dist/{WalletManager-CXvQ0Zu9.mjs → WalletManager-BIwH8Dw_.mjs} +1 -1
- package/dist/WebhooksSection-CKeiJ7Py.js +1 -0
- package/dist/WebhooksSection-COPW4Ec0.mjs +223 -0
- package/dist/{configApi-Ch0Rr7TD.mjs → configApi-6XhAJGKX.mjs} +31 -0
- package/dist/{configApi-CxEbCAgG.js → configApi-DkduMQg1.js} +1 -1
- package/dist/crypto-only.js +1 -1
- package/dist/crypto-only.mjs +85 -83
- package/dist/index-C0g-JxJk.js +84 -0
- package/dist/{index-BHF82XBB.mjs → index-DXnuQp5x.mjs} +8643 -7678
- package/dist/index.js +1 -1
- package/dist/index.mjs +42 -40
- package/dist/{sections-C1rb9YRh.mjs → sections-C1NpK7hk.mjs} +2 -2
- package/dist/{sections-8e5Y3ukY.js → sections-DVVSZBhW.js} +1 -1
- package/dist/src/admin/plugin.d.ts.map +1 -1
- package/dist/src/components/ComplianceGatePage.d.ts +40 -0
- package/dist/src/components/ComplianceGatePage.d.ts.map +1 -0
- package/dist/src/components/SubscribeButton.d.ts +1 -5
- package/dist/src/components/SubscribeButton.d.ts.map +1 -1
- package/dist/src/components/admin/AdminAuthManager.d.ts +7 -3
- package/dist/src/components/admin/AdminAuthManager.d.ts.map +1 -1
- package/dist/src/components/admin/AssetClassesTab.d.ts.map +1 -1
- package/dist/src/components/admin/CedrosPayAdminDashboard.d.ts +1 -1
- package/dist/src/components/admin/CedrosPayAdminDashboard.d.ts.map +1 -1
- package/dist/src/components/admin/ChatLogsSection.d.ts +3 -0
- package/dist/src/components/admin/ChatLogsSection.d.ts.map +1 -0
- package/dist/src/components/admin/ComplianceKycTab.d.ts +3 -0
- package/dist/src/components/admin/ComplianceKycTab.d.ts.map +1 -0
- package/dist/src/components/admin/ComplianceRequirementsEditor.d.ts +8 -0
- package/dist/src/components/admin/ComplianceRequirementsEditor.d.ts.map +1 -0
- package/dist/src/components/admin/ComplianceSanctionsApi.d.ts +3 -0
- package/dist/src/components/admin/ComplianceSanctionsApi.d.ts.map +1 -0
- package/dist/src/components/admin/ComplianceSection.d.ts +3 -0
- package/dist/src/components/admin/ComplianceSection.d.ts.map +1 -0
- package/dist/src/components/admin/CustomersSection.d.ts +3 -0
- package/dist/src/components/admin/CustomersSection.d.ts.map +1 -0
- package/dist/src/components/admin/DisputesSection.d.ts +3 -0
- package/dist/src/components/admin/DisputesSection.d.ts.map +1 -0
- package/dist/src/components/admin/GiftCardAnalytics.d.ts +3 -0
- package/dist/src/components/admin/GiftCardAnalytics.d.ts.map +1 -0
- package/dist/src/components/admin/GiftCardManager.d.ts +3 -0
- package/dist/src/components/admin/GiftCardManager.d.ts.map +1 -0
- package/dist/src/components/admin/ImagesSection.d.ts +3 -0
- package/dist/src/components/admin/ImagesSection.d.ts.map +1 -0
- package/dist/src/components/admin/InventorySection.d.ts +3 -0
- package/dist/src/components/admin/InventorySection.d.ts.map +1 -0
- package/dist/src/components/admin/LiquidityPoolTab.d.ts.map +1 -1
- package/dist/src/components/admin/NftMetadataPreview.d.ts +20 -0
- package/dist/src/components/admin/NftMetadataPreview.d.ts.map +1 -0
- package/dist/src/components/admin/PoolManagementView.d.ts +14 -0
- package/dist/src/components/admin/PoolManagementView.d.ts.map +1 -0
- package/dist/src/components/admin/ProductsSection.d.ts.map +1 -1
- package/dist/src/components/admin/RefundsSection.d.ts.map +1 -1
- package/dist/src/components/admin/ReturnsSection.d.ts +3 -0
- package/dist/src/components/admin/ReturnsSection.d.ts.map +1 -0
- package/dist/src/components/admin/SettingsSection.d.ts.map +1 -1
- package/dist/src/components/admin/ShippingSection.d.ts +3 -0
- package/dist/src/components/admin/ShippingSection.d.ts.map +1 -0
- package/dist/src/components/admin/TaxSection.d.ts +3 -0
- package/dist/src/components/admin/TaxSection.d.ts.map +1 -0
- package/dist/src/components/admin/Token22Section.d.ts.map +1 -1
- package/dist/src/components/admin/WebhooksSection.d.ts +3 -0
- package/dist/src/components/admin/WebhooksSection.d.ts.map +1 -0
- package/dist/src/components/admin/complianceTypes.d.ts +74 -0
- package/dist/src/components/admin/complianceTypes.d.ts.map +1 -0
- package/dist/src/components/admin/configApi.d.ts.map +1 -1
- package/dist/src/components/admin/icons.d.ts +1 -0
- package/dist/src/components/admin/icons.d.ts.map +1 -1
- package/dist/src/components/admin/useAdminAuth.d.ts +1 -1
- package/dist/src/components/admin/useAdminAuth.d.ts.map +1 -1
- package/dist/src/context/CedrosContext.d.ts.map +1 -1
- package/dist/src/ecommerce/adapters/CommerceAdapter.d.ts +36 -0
- package/dist/src/ecommerce/adapters/CommerceAdapter.d.ts.map +1 -1
- package/dist/src/ecommerce/adapters/paywall/paywallAdapter.d.ts.map +1 -1
- package/dist/src/ecommerce/components/catalog/TokenDisplay.d.ts +36 -0
- package/dist/src/ecommerce/components/catalog/TokenDisplay.d.ts.map +1 -0
- package/dist/src/ecommerce/components/chat/ShopChatPanel.d.ts +8 -5
- package/dist/src/ecommerce/components/chat/ShopChatPanel.d.ts.map +1 -1
- package/dist/src/ecommerce/components/checkout/CheckoutForm.d.ts.map +1 -1
- package/dist/src/ecommerce/components/checkout/SendAsGiftSection.d.ts +15 -0
- package/dist/src/ecommerce/components/checkout/SendAsGiftSection.d.ts.map +1 -0
- package/dist/src/ecommerce/components/gift-cards/GiftCardBalanceChecker.d.ts +19 -0
- package/dist/src/ecommerce/components/gift-cards/GiftCardBalanceChecker.d.ts.map +1 -0
- package/dist/src/ecommerce/components/orders/MyRedemptionsPage.d.ts +13 -0
- package/dist/src/ecommerce/components/orders/MyRedemptionsPage.d.ts.map +1 -0
- package/dist/src/ecommerce/components/orders/MyTokensPage.d.ts +15 -0
- package/dist/src/ecommerce/components/orders/MyTokensPage.d.ts.map +1 -0
- package/dist/src/ecommerce/components/orders/OrderDetails.d.ts.map +1 -1
- package/dist/src/ecommerce/hooks/useCartInventory.d.ts.map +1 -1
- package/dist/src/ecommerce/index.d.ts +12 -2
- package/dist/src/ecommerce/index.d.ts.map +1 -1
- package/dist/src/ecommerce/state/checkout/checkoutSchema.d.ts +3 -0
- package/dist/src/ecommerce/state/checkout/checkoutSchema.d.ts.map +1 -1
- package/dist/src/ecommerce/state/checkout/useCheckout.d.ts.map +1 -1
- package/dist/src/ecommerce/types.d.ts +6 -0
- package/dist/src/ecommerce/types.d.ts.map +1 -1
- package/dist/src/ecommerce/utils/cartItemMetadata.d.ts.map +1 -1
- package/dist/src/hooks/useComplianceCheck.d.ts +30 -0
- package/dist/src/hooks/useComplianceCheck.d.ts.map +1 -0
- package/dist/src/hooks/useSubscriptionManagement.d.ts.map +1 -1
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/managers/CreditsManager.d.ts.map +1 -1
- package/dist/src/managers/ManagerCache.d.ts +2 -2
- package/dist/src/managers/ManagerCache.d.ts.map +1 -1
- package/dist/src/managers/StripeManager.d.ts +7 -1
- package/dist/src/managers/StripeManager.d.ts.map +1 -1
- package/dist/src/managers/SubscriptionChangeManager.d.ts.map +1 -1
- package/dist/src/managers/SubscriptionManager.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +14 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/subscription.d.ts +21 -33
- package/dist/src/types/subscription.d.ts.map +1 -1
- package/dist/src/utils/exponentialBackoff.d.ts +22 -0
- package/dist/src/utils/exponentialBackoff.d.ts.map +1 -1
- package/dist/stripe-only.js +1 -1
- package/dist/stripe-only.mjs +2 -2
- package/dist/styles-BT4bhFey.js +1 -0
- package/dist/{styles-Ag-7ZvAB.mjs → styles-D4SQkuV3.mjs} +606 -609
- package/dist/testing/index.js +1 -1
- package/dist/testing/index.mjs +1 -1
- package/dist/{walletPool-C_0P4mTw.mjs → walletPool-DE-t1wSW.mjs} +1 -1
- package/dist/{walletPool-Ddv33tej.js → walletPool-IS7R3MR1.js} +1 -1
- package/package.json +1 -1
- package/dist/CedrosContext-7dwmEeUY.js +0 -6
- package/dist/SettingsSection-cKF0tLnS.js +0 -1
- package/dist/Token22Section-DUUl59dZ.js +0 -1
- package/dist/Token22Section-HygkDNtL.mjs +0 -1685
- package/dist/index-OaWkrl0G.js +0 -84
- package/dist/styles-21F1-oqx.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("react"),m=require("./index-C0g-JxJk.js"),y=require("./CedrosContext-C2RjHLaQ.js"),_=a=>a.length>12?`${a.slice(0,6)}...${a.slice(-4)}`:a,ie=a=>{switch(a){case"active":return"success";case"frozen":return"failed";case"thawed":return"pending";default:return"muted"}},G=a=>{switch(a){case"freeze":return"failed";case"thaw":return"success";case"sweep_freeze":return"failed";case"report_generated":return"muted";default:return"muted"}},re=a=>{switch(a){case"verified":return"success";case"pending":return"pending";case"expired":return"failed";case"none":default:return"muted"}},ce="https://explorer.solana.com/tx/",de={apiUrl:"",refreshIntervalSecs:3600,enabled:!1};function oe({serverUrl:a,apiKey:h,authManager:u}){const[r,o]=n.useState(de),[b,A]=n.useState(!0),[x,p]=n.useState(!1),[i,N]=n.useState(!1),[C,f]=n.useState(null),[k,j]=n.useState(null),S=n.useCallback(async(s,l)=>{if(u?.isAuthenticated())return u.fetchWithAuth(s,l);const v={"Content-Type":"application/json"};h&&(v["X-API-Key"]=h);const z=await fetch(`${a}${s}`,{...l,headers:{...v,...l?.headers}});if(!z.ok)throw new Error(`Request failed: ${z.status}`);return z.json()},[a,h,u]);n.useEffect(()=>{(async()=>{try{const s=await S("/admin/compliance/sanctions-api");o(s)}catch(s){y.getLogger().error("[ComplianceSanctionsApi] Failed to fetch settings:",s)}finally{A(!1)}})()},[S]);const T=async()=>{p(!0),f(null),j(null);try{await S("/admin/compliance/sanctions-api",{method:"PUT",body:JSON.stringify(r)}),j("Settings saved")}catch(s){y.getLogger().error("[ComplianceSanctionsApi] Save failed:",s),f("Failed to save settings")}finally{p(!1)}},d=async()=>{N(!0),f(null),j(null);try{await S("/admin/compliance/sanctions-api/refresh",{method:"POST"}),j("Sanctions list refreshed")}catch(s){y.getLogger().error("[ComplianceSanctionsApi] Refresh failed:",s),f("Failed to refresh sanctions list")}finally{N(!1)}};return b?e.jsxs("div",{className:"cedros-admin__loading",children:[m.Icons.loading," Loading sanctions API settings..."]}):e.jsxs("div",{style:{maxWidth:"500px",display:"flex",flexDirection:"column",gap:"1rem"},children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Dynamic Sanctions API"})}),C&&e.jsx("div",{className:"cedros-admin__badge cedros-admin__badge--failed",style:{padding:"0.5rem"},children:C}),k&&e.jsx("div",{className:"cedros-admin__badge cedros-admin__badge--success",style:{padding:"0.5rem"},children:k}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.9rem"},children:[e.jsx("input",{type:"checkbox",checked:r.enabled,onChange:s=>o(l=>({...l,enabled:s.target.checked}))}),"Enable dynamic sanctions list"]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["API URL",e.jsx("input",{type:"url",className:"cedros-admin__input",placeholder:"https://sunscreen.cedros.io",value:r.apiUrl,onChange:s=>o(l=>({...l,apiUrl:s.target.value}))})]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["Refresh interval (seconds, min 60)",e.jsx("input",{type:"number",className:"cedros-admin__input",min:60,value:r.refreshIntervalSecs,onChange:s=>o(l=>({...l,refreshIntervalSecs:Number(s.target.value)})),style:{width:"160px"}})]}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:T,disabled:x,children:x?"Saving...":"Save Settings"}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:d,disabled:i||!r.enabled||!r.apiUrl,children:i?"Refreshing...":"Force Refresh"})]})]})}function le({serverUrl:a,apiKey:h,authManager:u}){const[r,o]=n.useState(""),[b,A]=n.useState(!1),[x,p]=n.useState(null),[i,N]=n.useState(null),[C,f]=n.useState(!1),k=n.useCallback(async(d,s)=>{if(u?.isAuthenticated())return u.fetchWithAuth(d,s);const l={"Content-Type":"application/json"};h&&(l["X-API-Key"]=h);const v=await fetch(`${a}${d}`,{...s,headers:{...l,...s?.headers}});if(!v.ok)throw new Error(`Request failed: ${v.status}`);return v.json()},[a,h,u]),j=async()=>{const d=r.trim();if(d){A(!0),p(null),N(null),f(!0);try{const s=await k(`/admin/compliance/user-status/${encodeURIComponent(d)}`);N(s)}catch(s){y.getLogger().error("[ComplianceKycTab] Lookup failed:",s),p("Failed to fetch user compliance status. Ensure cedros-login is configured.")}finally{A(!1)}}},S=d=>{d.key==="Enter"&&j()},T=d=>{switch(d){case"verified":return"Verified";case"pending":return"Pending";case"expired":return"Expired";case"none":default:return"Not Started"}};return e.jsxs("div",{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"KYC & Accredited Investor Status"})}),e.jsx("p",{style:{fontSize:"0.85rem",color:"var(--cedros-admin-text-muted, #888)",marginBottom:"1rem"},children:"Look up a user's KYC verification and accredited investor status from cedros-login."}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"flex-end",marginBottom:"1.5rem",maxWidth:"500px"},children:[e.jsxs("label",{style:{flex:1,display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["User ID",e.jsx("input",{type:"text",className:"cedros-admin__input",placeholder:"user_abc123",value:r,onChange:d=>o(d.target.value),onKeyDown:S})]}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:j,disabled:b||!r.trim(),children:b?"Looking up...":"Look Up"})]}),x&&e.jsx("div",{className:"cedros-admin__badge cedros-admin__badge--failed",style:{padding:"0.5rem",marginBottom:"1rem"},children:x}),b&&e.jsxs("div",{className:"cedros-admin__loading",children:[m.Icons.loading," Fetching compliance status..."]}),i&&!b&&e.jsxs("div",{style:{maxWidth:"500px"},children:[e.jsx("div",{className:"cedros-admin__table-container",children:e.jsx("table",{className:"cedros-admin__table",children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600,width:"40%"},children:"User ID"}),e.jsx("td",{children:e.jsx("code",{children:i.userId})})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"KYC Status"}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${re(i.kycStatus)}`,children:T(i.kycStatus)})})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Accredited Investor"}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${i.accreditedInvestor?"success":"muted"}`,children:i.accreditedInvestor?"Yes":"No"})})]}),i.accreditedVerifiedAt&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Accredited Since"}),e.jsx("td",{children:m.formatDateTime(i.accreditedVerifiedAt)})]})]})})}),e.jsx("div",{style:{marginTop:"0.75rem",padding:"0.75rem",borderRadius:"4px",fontSize:"0.85rem",background:i.kycStatus==="verified"?"var(--cedros-admin-bg-success, #f0fdf4)":"var(--cedros-admin-bg-muted, #f5f5f5)",color:"var(--cedros-admin-text, #333)"},children:i.kycStatus==="verified"&&i.accreditedInvestor?"This user is fully verified and accredited. They can access all compliance-gated products.":i.kycStatus==="verified"?"This user has KYC verification but is not an accredited investor.":i.kycStatus==="pending"?"This user has submitted KYC documents. Verification is in progress.":i.kycStatus==="expired"?"This user's KYC verification has expired. They will need to re-verify.":"This user has not started KYC verification."})]}),C&&!i&&!b&&!x&&e.jsx("div",{className:"cedros-admin__empty",children:"No compliance record found for this user."})]})}function me({serverUrl:a,apiKey:h,pageSize:u=50,authManager:r}){const[o,b]=n.useState("holders"),[A,x]=n.useState(null),[p,i]=n.useState([]),[N,C]=n.useState(!0),[f,k]=n.useState(""),[j,S]=n.useState([]),[T,d]=n.useState(!0),[s,l]=n.useState(null),[v,z]=n.useState(!1),[P,V]=n.useState(""),[W,X]=n.useState(""),[B,O]=n.useState({enabled:!0,batchSize:100}),[M,Q]=n.useState(!0),[H,Y]=n.useState(!1),[g,L]=n.useState(null),[R,$]=n.useState(""),[F,q]=n.useState(!1),w=n.useCallback(async(t,c)=>{if(r?.isAuthenticated())return r.fetchWithAuth(t,c);const I={"Content-Type":"application/json"};h&&(I["X-API-Key"]=h);const U=await fetch(`${a}${t}`,{...c,headers:{...I,...c?.headers}});if(!U.ok)throw new Error(`Request failed: ${U.status}`);return U.json()},[a,h,r]),D=n.useCallback(async()=>{try{const t=f?`&status=${f}`:"",c=await w(`/admin/compliance/holders?limit=${u}&offset=0${t}`);i(c.holders||[])}catch(t){y.getLogger().error("[ComplianceSection] Failed to fetch holders:",t),i([]),x("Failed to load token holders")}finally{C(!1)}},[w,u,f]),E=n.useCallback(async()=>{try{const t=await w(`/admin/compliance/actions?limit=${u}&offset=0`);S(t.actions||[])}catch(t){y.getLogger().error("[ComplianceSection] Failed to fetch actions:",t),S([]),x("Failed to load compliance actions")}finally{d(!1)}},[w,u]),K=n.useCallback(async()=>{try{const t=await w("/admin/compliance/sweep-settings");O(t)}catch(t){y.getLogger().error("[ComplianceSection] Failed to fetch sweep settings:",t)}finally{Q(!1)}},[w]),Z=async()=>{Y(!0);try{await w("/admin/compliance/sweep-settings",{method:"PUT",body:JSON.stringify(B)})}catch(t){y.getLogger().error("[ComplianceSection] Failed to save sweep settings:",t),x("Failed to save sweep settings")}finally{Y(!1)}};n.useEffect(()=>{D()},[D]),n.useEffect(()=>{E()},[E]),n.useEffect(()=>{K()},[K]);const ee=async()=>{if(!(!g||!R.trim())){q(!0);try{const t=g.action==="freeze"?"/admin/compliance/freeze":"/admin/compliance/thaw";await w(t,{method:"POST",body:JSON.stringify({holderId:g.holder.id,reason:R})}),L(null),$(""),await D(),await E()}catch(t){y.getLogger().error(`[ComplianceSection] ${g.action} failed:`,t),x(`Failed to ${g.action} holder`)}finally{q(!1)}}},te=async()=>{z(!0);try{const t=new URLSearchParams;P&&t.set("from",new Date(P).toISOString()),W&&t.set("to",new Date(W).toISOString());const c=await w(`/admin/compliance/report?${t.toString()}`);l(c.report)}catch(t){y.getLogger().error("[ComplianceSection] Failed to generate report:",t),x("Failed to generate compliance report")}finally{z(!1)}},se=()=>{if(!s)return;const t=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),c=URL.createObjectURL(t),I=document.createElement("a");I.href=c,I.download=`compliance-report-${new Date().toISOString().slice(0,10)}.json`,I.click(),URL.revokeObjectURL(c)},ne=p.length,J=p.filter(t=>t.status==="frozen").length,ae=p.filter(t=>t.status==="active").length;return e.jsxs("div",{className:"cedros-admin__page",children:[e.jsx(m.ErrorBanner,{message:A,onRetry:()=>{D(),E()}}),e.jsx(m.StatsBar,{stats:[{label:"Total Holders",value:ne},{label:"Active",value:ae,variant:"success"},{label:"Frozen",value:J,variant:J>0?"warning":"muted"},{label:"Actions Logged",value:j.length}],isLoading:N||T}),e.jsx("div",{className:"cedros-admin__tabs",style:{display:"flex",gap:"0.5rem",marginBottom:"1rem"},children:["holders","actions","reports","sweep-settings","sanctions-api","kyc"].map(t=>{const c=t==="holders"?"Token Holders":t==="actions"?"Actions Log":t==="reports"?"Reports":t==="sweep-settings"?"Sweep Settings":t==="sanctions-api"?"Sanctions API":"KYC & Accreditation";return e.jsx("button",{type:"button",className:`cedros-admin__button ${o===t?"cedros-admin__button--primary":"cedros-admin__button--ghost"}`,onClick:()=>b(t),children:c},t)})}),o==="holders"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin__section-header",style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx("h3",{className:"cedros-admin__section-title",children:"Token Holders"}),e.jsxs("select",{value:f,onChange:t=>{k(t.target.value),C(!0)},className:"cedros-admin__input",style:{width:"auto",padding:"0.25rem 0.5rem",fontSize:"0.85rem"},children:[e.jsx("option",{value:"",children:"All statuses"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"frozen",children:"Frozen"}),e.jsx("option",{value:"thawed",children:"Thawed"})]})]}),N?e.jsxs("div",{className:"cedros-admin__loading",children:[m.Icons.loading," Loading holders..."]}):p.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No token holders found."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Wallet"}),e.jsx("th",{children:"Collection"}),e.jsx("th",{children:"Mint"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Created"}),e.jsx("th",{children:"Actions"})]})}),e.jsx("tbody",{children:p.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{title:t.walletAddress,children:_(t.walletAddress)})}),e.jsx("td",{children:e.jsx("code",{title:t.collectionId,children:_(t.collectionId)})}),e.jsx("td",{children:e.jsx("code",{title:t.mintAddress,children:_(t.mintAddress)})}),e.jsx("td",{children:t.amountMinted}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${ie(t.status)}`,children:t.status})}),e.jsx("td",{children:m.formatDateTime(t.createdAt)}),e.jsx("td",{children:t.status==="active"||t.status==="thawed"?e.jsx("button",{className:"cedros-admin__button cedros-admin__button--danger cedros-admin__button--sm",onClick:()=>{L({holder:t,action:"freeze"}),$("")},children:"Freeze"}):t.status==="frozen"?e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--sm",onClick:()=>{L({holder:t,action:"thaw"}),$("")},children:"Thaw"}):null})]},t.id))})]})})]}),o==="actions"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Compliance Actions"})}),T?e.jsxs("div",{className:"cedros-admin__loading",children:[m.Icons.loading," Loading actions..."]}):j.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No compliance actions recorded."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Timestamp"}),e.jsx("th",{children:"Type"}),e.jsx("th",{children:"Wallet"}),e.jsx("th",{children:"Reason"}),e.jsx("th",{children:"Actor"}),e.jsx("th",{children:"Tx Signature"})]})}),e.jsx("tbody",{children:j.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:m.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${G(t.actionType)}`,children:t.actionType})}),e.jsx("td",{children:e.jsx("code",{title:t.walletAddress,children:_(t.walletAddress)})}),e.jsx("td",{children:t.reason||"—"}),e.jsx("td",{children:e.jsx("code",{children:_(t.actor)})}),e.jsx("td",{children:t.txSignature?e.jsx("a",{href:`${ce}${t.txSignature}`,target:"_blank",rel:"noopener noreferrer",className:"cedros-admin__link",children:_(t.txSignature)}):"—"})]},t.id))})]})})]}),o==="reports"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Compliance Report"})}),e.jsxs("div",{style:{display:"flex",gap:"0.75rem",alignItems:"flex-end",marginBottom:"1rem"},children:[e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["From",e.jsx("input",{type:"date",className:"cedros-admin__input",value:P,onChange:t=>V(t.target.value)})]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["To",e.jsx("input",{type:"date",className:"cedros-admin__input",value:W,onChange:t=>X(t.target.value)})]}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:te,disabled:v,children:v?"Generating...":"Generate Report"})]}),s&&e.jsxs("div",{children:[e.jsx(m.StatsBar,{stats:[{label:"Total Holders",value:s.totalHolders},{label:"Frozen",value:s.totalFrozen,variant:s.totalFrozen>0?"warning":"muted"},{label:"Freezes",value:s.freezeCount},{label:"Thaws",value:s.thawCount},{label:"Sweep Freezes",value:s.sweepFreezeCount,variant:s.sweepFreezeCount>0?"warning":"muted"}],isLoading:!1}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",margin:"1rem 0 0.5rem"},children:[e.jsxs("span",{style:{fontSize:"0.85rem",color:"var(--cedros-admin-text-muted, #888)"},children:["Generated ",m.formatDateTime(s.generatedAt)," · ",s.actionsInPeriod," actions in period"]}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:se,children:"Download JSON"})]}),s.actions.length>0&&e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Timestamp"}),e.jsx("th",{children:"Type"}),e.jsx("th",{children:"Wallet"}),e.jsx("th",{children:"Reason"}),e.jsx("th",{children:"Actor"})]})}),e.jsx("tbody",{children:s.actions.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:m.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${G(t.actionType)}`,children:t.actionType})}),e.jsx("td",{children:e.jsx("code",{title:t.walletAddress,children:_(t.walletAddress)})}),e.jsx("td",{children:t.reason||"—"}),e.jsx("td",{children:e.jsx("code",{children:_(t.actor)})})]},t.id))})]})})]})]}),o==="sweep-settings"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Sanctions Sweep Settings"})}),M?e.jsxs("div",{className:"cedros-admin__loading",children:[m.Icons.loading," Loading settings..."]}):e.jsxs("div",{style:{maxWidth:"400px",display:"flex",flexDirection:"column",gap:"1rem"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.9rem"},children:[e.jsx("input",{type:"checkbox",checked:B.enabled,onChange:t=>O(c=>({...c,enabled:t.target.checked}))}),"Enable automated sanctions sweep"]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["Batch size (1 – 10,000)",e.jsx("input",{type:"number",className:"cedros-admin__input",min:1,max:1e4,value:B.batchSize,onChange:t=>O(c=>({...c,batchSize:Number(t.target.value)})),style:{width:"160px"}})]}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:Z,disabled:H,style:{alignSelf:"flex-start"},children:H?"Saving...":"Save Settings"})]})]}),o==="sanctions-api"&&e.jsx(oe,{serverUrl:a,apiKey:h,authManager:r}),o==="kyc"&&e.jsx(le,{serverUrl:a,apiKey:h,authManager:r}),g&&e.jsx("div",{className:"cedros-admin__modal-overlay",onClick:()=>!F&&L(null),children:e.jsxs("div",{className:"cedros-admin__modal",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"cedros-admin__modal-header",children:[e.jsxs("h4",{className:"cedros-admin__modal-title",children:[g.action==="freeze"?"Freeze":"Thaw"," Token Account"]}),e.jsx("button",{type:"button",className:"cedros-admin__modal-close",onClick:()=>!F&&L(null),children:m.Icons.close})]}),e.jsxs("div",{className:"cedros-admin__modal-body",children:[e.jsxs("p",{style:{marginBottom:"0.5rem",fontSize:"0.9rem"},children:["Wallet: ",e.jsx("code",{children:_(g.holder.walletAddress)})]}),e.jsxs("p",{style:{marginBottom:"0.75rem",fontSize:"0.9rem"},children:["Mint: ",e.jsx("code",{children:_(g.holder.mintAddress)})]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["Reason (required)",e.jsx("textarea",{className:"cedros-admin__input",rows:3,value:R,onChange:t=>$(t.target.value),placeholder:`Reason for ${g.action}...`,maxLength:1024})]})]}),e.jsxs("div",{className:"cedros-admin__modal-footer",children:[e.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>L(null),disabled:F,children:"Cancel"}),e.jsx("button",{className:`cedros-admin__button ${g.action==="freeze"?"cedros-admin__button--danger":"cedros-admin__button--primary"}`,onClick:ee,disabled:F||!R.trim(),children:F?"Processing...":g.action==="freeze"?"Freeze Account":"Thaw Account"})]})]})})]})}exports.ComplianceSection=me;
|
|
@@ -3,8 +3,8 @@ import { useState as K, useRef as R, useCallback as P, useMemo as Y, useEffect a
|
|
|
3
3
|
import { useWallet as be } from "@solana/wallet-adapter-react";
|
|
4
4
|
import { WalletReadyState as pe } from "@solana/wallet-adapter-base";
|
|
5
5
|
import { WalletIcon as Te } from "@solana/wallet-adapter-react-ui";
|
|
6
|
-
import { T as Ie, K as Ee, O as We, U as V, q as Re, n as fe, s as _e, o as ge, p as qe, r as we, t as Z, V as Me, W as ze } from "./styles-
|
|
7
|
-
import { u as he, m as ee, i as n, j as De } from "./CedrosContext-
|
|
6
|
+
import { T as Ie, K as Ee, O as We, U as V, q as Re, n as fe, s as _e, o as ge, p as qe, r as we, t as Z, V as Me, W as ze } from "./styles-D4SQkuV3.mjs";
|
|
7
|
+
import { u as he, m as ee, i as n, j as De } from "./CedrosContext-CY6zvjvJ.mjs";
|
|
8
8
|
function $e() {
|
|
9
9
|
const { x402Manager: g, walletManager: s } = he(), { publicKey: _, signTransaction: q } = be(), [L, d] = K({
|
|
10
10
|
status: "idle",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const p=require("react/jsx-runtime"),a=require("react"),ce=require("@solana/wallet-adapter-react"),le=require("@solana/wallet-adapter-base"),be=require("@solana/wallet-adapter-react-ui"),i=require("./styles-21F1-oqx.js"),t=require("./CedrosContext-7dwmEeUY.js");function ie(){const{x402Manager:C,walletManager:l}=t.useCedrosContext(),{publicKey:W,signTransaction:j}=ce.useWallet(),[N,y]=a.useState({status:"idle",error:null,transactionId:null}),[R,L]=a.useState(null),[K,k]=a.useState(null),P=a.useRef(W);P.current=W;const h=a.useRef(j);h.current=j;const g=a.useRef(0),X=6e4,I=()=>{const o=g.current;return o>0&&Date.now()-o<X},S=a.useCallback(()=>{if(!W){const o="Wallet not connected";return y({status:"error",error:o,transactionId:null}),{valid:!1,error:o}}if(!j){const o="Wallet does not support signing";return y({status:"error",error:o,transactionId:null}),{valid:!1,error:o}}return{valid:!0}},[W,j]),q=a.useCallback(async o=>{try{y(d=>({...d,status:"loading"}));const c=await C.requestQuote({resource:o});if(!C.validateRequirement(c))throw new Error("Invalid requirement received from server");return L(c),y(d=>({...d,status:"idle"})),c}catch(c){const d=t.formatError(c,"Failed to fetch requirement");throw y({status:"error",error:d,transactionId:null}),c}},[C]),B=a.useCallback(async(o,c,d,x,n="regular")=>{const s=P.current,m=h.current;if(!s||!m)throw new Error("Wallet disconnected during payment flow");if(!!o.extra?.feePayer){t.getLogger().debug("[useX402Payment] Gasless flow enabled"),t.getLogger().debug("[useX402Payment] Building gasless transaction");const{transaction:b,blockhash:M}=await C.buildGaslessTransaction({resourceId:c,userWallet:s.toString(),feePayer:o.extra.feePayer,couponCode:d});t.getLogger().debug("[useX402Payment] Deserializing backend transaction");const A=l.deserializeTransaction(b);if(P.current?.toString()!==s.toString())throw new Error("Wallet changed during payment flow");t.getLogger().debug("[useX402Payment] Requesting partial signature");const E=await l.partiallySignTransaction({transaction:A,signTransaction:m,blockhash:M});t.getLogger().debug("[useX402Payment] Submitting partial transaction");const z=await C.submitGaslessTransaction({resource:c,partialTx:E,couponCode:d,metadata:x,resourceType:n,requirement:o});return z.success&&z.settlement&&k(z.settlement),z}else{const b=await l.buildTransaction({requirement:o,payerPublicKey:s});if(P.current?.toString()!==s.toString())throw new Error("Wallet changed during payment flow");const M=await l.signTransaction({transaction:b,signTransaction:m}),A=l.buildPaymentPayload({requirement:o,signedTx:M,payerPublicKey:s}),E=await C.submitPayment({resource:c,payload:A,couponCode:d,metadata:x,resourceType:n});return E.success&&E.settlement&&k(E.settlement),E}},[C,l]),w=a.useCallback(async(o,c,d)=>{if(I())return{success:!1,error:"Payment already in progress"};const x=S();if(!x.valid)return{success:!1,error:x.error};g.current=Date.now(),y({status:"loading",error:null,transactionId:null});try{t.getLogger().debug("[useX402Payment] Fetching fresh quote");const n=await C.requestQuote({resource:o,couponCode:c});t.getLogger().debug("[useX402Payment] Received quote",{amount:n.maxAmountRequired}),L(n),t.getLogger().debug("[useX402Payment] Executing payment flow");const s=await B(n,o,c,d,"regular");return s.success?y({status:"success",error:null,transactionId:s.transactionId||"payment-success"}):y({status:"error",error:s.error||"Payment failed",transactionId:null}),s}catch(n){const s=t.formatError(n,"Payment failed");return y({status:"error",error:s,transactionId:null}),{success:!1,error:s}}finally{g.current=0}},[S,C,B]),_=a.useCallback(async(o,c,d)=>{if(I())return{success:!1,error:"Payment already in progress"};const x=S();if(!x.valid)return{success:!1,error:x.error};g.current=Date.now(),y({status:"loading",error:null,transactionId:null});try{const n=i.normalizeCartItems(o),s=await C.requestCartQuote({items:n,metadata:c,couponCode:d}),m=s.cartId,u=s.quote;if(!C.validateRequirement(u))throw new Error("Invalid cart quote received from server");L(u);const b=await B(u,m,d,c,"cart");return b.success?y({status:"success",error:null,transactionId:b.transactionId||"cart-payment-success"}):y({status:"error",error:b.error||"Cart payment failed",transactionId:null}),b}catch(n){const s=t.formatError(n,"Cart payment failed");return y({status:"error",error:s,transactionId:null}),{success:!1,error:s}}finally{g.current=0}},[S,C,B]),T=a.useCallback(()=>{y({status:"idle",error:null,transactionId:null}),L(null),k(null),g.current=0},[]);return{...N,requirement:R,settlement:K,fetchQuote:q,processPayment:w,processCartPayment:_,reset:T}}function ue({resource:C,items:l,label:W,disabled:j=!1,onAttempt:N,onSuccess:y,onError:R,className:L="",testPageUrl:K,hideMessages:k=!1,metadata:P,couponCode:h}){const{connected:g,connecting:X,connect:I,disconnect:S,select:q,wallets:B,wallet:w,publicKey:_}=ce.useWallet(),{status:T,error:o,transactionId:c,processPayment:d,processCartPayment:x}=ie(),n=t.useCedrosTheme(),{solanaError:s}=t.useCedrosContext(),{isCartMode:m,effectiveResource:u}=i.usePaymentMode(C,l),{t:b,translations:M}=i.useTranslation(),A=W||b("ui.pay_with_crypto"),E=o&&typeof o!="string"?o?.code??null:null,z=s&&typeof s!="string"?s?.code??null:null,U=e=>{if(!e||!M)return"";const r=M.errors[e];return r?r.action?`${r.message} ${r.action}`:r.message:""},Y=o?typeof o=="string"?o:U(E):null,H=s?typeof s=="string"?s:U(z):null,J=a.useRef(y),V=a.useRef(R),Z=a.useRef(d),ee=a.useRef(x);J.current=y,V.current=R,Z.current=d,ee.current=x;const de=a.useMemo(()=>B.map(e=>`${e.adapter.name}-${e.readyState}`).join(","),[B]),G=a.useMemo(()=>B.filter(({readyState:e})=>e===le.WalletReadyState.Installed||e===le.WalletReadyState.Loadable),[de]);a.useEffect(()=>{if(T==="success"&&c){const e=m&&l?i.getCartItemCount(l):void 0;i.emitPaymentSuccess("crypto",c,u,e),J.current?.(c)}},[T,c,m,l,u]),a.useEffect(()=>{if(T==="error"&&o){const e=m&&l?i.getCartItemCount(l):void 0;i.emitPaymentError("crypto",o,u,e),V.current?.(o)}},[T,o,m,l,u]);const te=typeof window<"u"&&window.top!==window.self,[re,$]=a.useState(!1),[ne,Q]=a.useState(!1),[D,v]=a.useState(null),F=s;a.useEffect(()=>{let e=!1;return e||(async()=>{if(ne&&w&&!g&&!X){t.getLogger().debug("[CryptoButton] Wallet detected, attempting auto-connect:",w.adapter.name),Q(!1),i.emitWalletConnect(w.adapter.name);try{await I(),e||t.getLogger().debug("[CryptoButton] Auto-connect successful")}catch(f){if(!e){t.getLogger().error("[CryptoButton] Auto-connect failed:",f);const O=f instanceof Error?f.message:"Failed to connect wallet";i.emitWalletError(O,w.adapter.name),v(null)}}}})(),()=>{e=!0}},[w,ne,g,X,I]),a.useEffect(()=>{let e=!0;if(t.getLogger().debug("[CryptoButton] Payment useEffect triggered",{connected:g,hasPendingPayment:!!D,hasPublicKey:!!_,pendingPaymentType:D?.type}),g&&D&&_&&w&&e){i.emitWalletConnected(w.adapter.name,_.toString()),t.getLogger().debug("[CryptoButton] All conditions met! Processing pending payment:",D);const r=D;v(null),$(!1);const f=r.type==="cart"&&r.items?i.getCartItemCount(r.items):void 0;i.emitPaymentProcessing("crypto",r.resource,f),r.type==="cart"&&r.items?(t.getLogger().debug("[CryptoButton] Auto-processing cart payment"),ee.current(r.items,r.metadata,r.couponCode)):r.type==="single"&&r.resource&&(t.getLogger().debug("[CryptoButton] Auto-processing single payment"),Z.current(r.resource,r.couponCode,r.metadata))}return()=>{e=!1}},[g,D,_,w]);const oe=a.useCallback(async()=>{t.getLogger().debug("[CryptoButton] executePaymentFlow called",{connected:g,wallet:w?.adapter.name,couponCode:h,isCartMode:m,hasItems:!!l,effectiveResource:u});const e=m&&l?i.getCartItemCount(l):void 0;if(i.emitPaymentStart("crypto",u,e),N&&N("crypto"),F){t.getLogger().error("[CryptoButton] Solana dependencies missing:",F),i.emitPaymentError("crypto",F,u,e),R&&R(F);return}if(te){const r=K||window.location.href;try{if(new URL(r,window.location.origin).origin!==window.location.origin)throw t.getLogger().error("[CryptoButton] Blocked attempt to open external URL:",r),new Error("Cannot open external URLs from embedded context");window.open(r,"_blank","noopener,noreferrer")}catch(f){throw t.getLogger().error("[CryptoButton] URL validation failed:",f),f}return}if(g)i.emitPaymentProcessing("crypto",u,e),m&&l?(t.getLogger().debug("[CryptoButton] Processing cart payment with coupon:",h),await x(l,P,h)):u&&(t.getLogger().debug("[CryptoButton] Processing single payment with coupon:",h),await d(u,h,P));else{let r=!1;if(m&&l?(t.getLogger().debug("[CryptoButton] Setting pending cart payment with coupon:",h),v({type:"cart",items:l,metadata:P,couponCode:h}),r=!0):u&&(t.getLogger().debug("[CryptoButton] Setting pending single payment with coupon:",h),v({type:"single",resource:u,metadata:P,couponCode:h}),r=!0),!r){t.getLogger().error("[CryptoButton] No valid payment to process");return}try{if(w)t.getLogger().debug("[CryptoButton] Wallet already selected, connecting:",w.adapter.name),i.emitWalletConnect(w.adapter.name),await I();else{if(t.getLogger().debug("[CryptoButton] No wallet selected, showing selector. Available wallets:",G.map(f=>f.adapter.name)),G.length===0){v(null);const f="No wallets available";throw i.emitWalletError(f),new Error(f)}$(!0)}}catch(f){v(null);const O=f instanceof Error?f.message:"Failed to connect wallet";t.getLogger().error("[CryptoButton] Connection error:",O),i.emitWalletError(O,w?.adapter.name)}}},[g,w,h,m,l,u,te,K,G,I,P,x,d,F,N,R]),ae=a.useMemo(()=>m&&l?`crypto-cart-${l.map(e=>e.resource).join("-")}`:`crypto-${u||"unknown"}`,[m,l,u]),ge=a.useMemo(()=>i.createDedupedClickHandler(ae,oe,{cooldownMs:200,deduplicationWindowMs:0}),[ae,oe]),se=T==="loading",ye=j||se||X||!!F,me=se?b("ui.processing"):A,fe=a.useCallback(async()=>{try{Q(!1),g&&await S(),q(null),$(!0)}catch(e){t.getLogger().error("Failed to change wallet:",e)}},[g,S,q]),pe=a.useCallback(e=>{t.getLogger().debug("[CryptoButton] Wallet clicked:",e),$(!1),q(e),Q(!0),t.getLogger().debug("[CryptoButton] Wallet selected, useEffect will auto-connect")},[q]),we=a.useCallback(async()=>{try{if(await S(),v(null),typeof window<"u"&&window.localStorage)try{window.localStorage.removeItem("walletName")}catch(e){e instanceof Error&&e.name==="QuotaExceededError"?t.getLogger().warn("localStorage quota exceeded when removing wallet preference"):t.getLogger().error("Failed to clear wallet preference from localStorage:",e)}}catch(e){t.getLogger().error("Failed to disconnect wallet:",e)}},[S]);return p.jsxs("div",{className:n.unstyled?L:`${n.className} cedros-theme__crypto-button ${L||""}`,style:n.unstyled?{}:n.style,children:[p.jsx("button",{onClick:ge,disabled:ye,className:n.unstyled?L:"cedros-theme__button cedros-theme__crypto",type:"button",children:me}),re&&!k&&p.jsx("div",{className:"cedros-modal-overlay",style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:n.tokens.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999,padding:"1rem"},onClick:()=>{$(!1),v(null)},children:p.jsxs("div",{className:"cedros-modal-content",style:{backgroundColor:n.tokens.modalBackground,borderRadius:"12px",padding:"2rem",maxWidth:"400px",width:"100%",boxShadow:"0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",border:`1px solid ${n.tokens.modalBorder}`},onClick:e=>e.stopPropagation(),children:[p.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1.5rem"},children:[p.jsx("h3",{style:{margin:0,fontSize:"1.25rem",fontWeight:600,color:n.tokens.surfaceText},children:b("wallet.select_wallet")}),p.jsx("button",{onClick:()=>{$(!1),v(null)},style:i.getModalCloseButtonStyles(n.tokens.surfaceText),"aria-label":"Close modal",type:"button",children:"×"})]}),p.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:G.map(e=>p.jsxs("button",{onClick:()=>pe(e.adapter.name),style:{width:"100%",padding:"1rem",backgroundColor:n.tokens.surfaceBackground,border:`1px solid ${n.tokens.surfaceBorder}`,borderRadius:"0.5rem",cursor:"pointer",fontSize:"1rem",textAlign:"left",color:n.tokens.surfaceText,display:"flex",alignItems:"center",gap:"1rem",transition:"all 0.2s ease"},onMouseEnter:r=>{r.currentTarget.style.backgroundColor=n.tokens.modalBackground,r.currentTarget.style.borderColor=n.tokens.surfaceText,r.currentTarget.style.transform="translateY(-2px)"},onMouseLeave:r=>{r.currentTarget.style.backgroundColor=n.tokens.surfaceBackground,r.currentTarget.style.borderColor=n.tokens.surfaceBorder,r.currentTarget.style.transform="translateY(0)"},type:"button",children:[p.jsx(be.WalletIcon,{wallet:e,style:{width:"24px",height:"24px"}}),p.jsx("span",{style:{fontWeight:500},children:e.adapter.name})]},e.adapter.name))})]})}),g&&!k&&!re&&p.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"0.5rem",fontSize:"0.75rem",color:n.tokens.surfaceText,opacity:.7},children:[p.jsx("button",{onClick:fe,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:b("wallet.change")}),p.jsx("button",{onClick:we,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:b("ui.disconnect")})]}),!k&&H&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__error",children:H}),!k&&Y&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__error",children:Y}),!k&&c&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__success",children:b("ui.payment_successful")})]})}const Ce=Object.freeze(Object.defineProperty({__proto__:null,CryptoButton:ue},Symbol.toStringTag,{value:"Module"}));exports.CryptoButton=ue;exports.CryptoButton$1=Ce;exports.useX402Payment=ie;
|
|
1
|
+
"use strict";const p=require("react/jsx-runtime"),a=require("react"),ce=require("@solana/wallet-adapter-react"),le=require("@solana/wallet-adapter-base"),be=require("@solana/wallet-adapter-react-ui"),i=require("./styles-BT4bhFey.js"),t=require("./CedrosContext-C2RjHLaQ.js");function ie(){const{x402Manager:C,walletManager:l}=t.useCedrosContext(),{publicKey:W,signTransaction:j}=ce.useWallet(),[N,y]=a.useState({status:"idle",error:null,transactionId:null}),[R,L]=a.useState(null),[K,k]=a.useState(null),P=a.useRef(W);P.current=W;const h=a.useRef(j);h.current=j;const g=a.useRef(0),X=6e4,I=()=>{const o=g.current;return o>0&&Date.now()-o<X},S=a.useCallback(()=>{if(!W){const o="Wallet not connected";return y({status:"error",error:o,transactionId:null}),{valid:!1,error:o}}if(!j){const o="Wallet does not support signing";return y({status:"error",error:o,transactionId:null}),{valid:!1,error:o}}return{valid:!0}},[W,j]),q=a.useCallback(async o=>{try{y(d=>({...d,status:"loading"}));const c=await C.requestQuote({resource:o});if(!C.validateRequirement(c))throw new Error("Invalid requirement received from server");return L(c),y(d=>({...d,status:"idle"})),c}catch(c){const d=t.formatError(c,"Failed to fetch requirement");throw y({status:"error",error:d,transactionId:null}),c}},[C]),B=a.useCallback(async(o,c,d,x,n="regular")=>{const s=P.current,m=h.current;if(!s||!m)throw new Error("Wallet disconnected during payment flow");if(!!o.extra?.feePayer){t.getLogger().debug("[useX402Payment] Gasless flow enabled"),t.getLogger().debug("[useX402Payment] Building gasless transaction");const{transaction:b,blockhash:M}=await C.buildGaslessTransaction({resourceId:c,userWallet:s.toString(),feePayer:o.extra.feePayer,couponCode:d});t.getLogger().debug("[useX402Payment] Deserializing backend transaction");const A=l.deserializeTransaction(b);if(P.current?.toString()!==s.toString())throw new Error("Wallet changed during payment flow");t.getLogger().debug("[useX402Payment] Requesting partial signature");const E=await l.partiallySignTransaction({transaction:A,signTransaction:m,blockhash:M});t.getLogger().debug("[useX402Payment] Submitting partial transaction");const z=await C.submitGaslessTransaction({resource:c,partialTx:E,couponCode:d,metadata:x,resourceType:n,requirement:o});return z.success&&z.settlement&&k(z.settlement),z}else{const b=await l.buildTransaction({requirement:o,payerPublicKey:s});if(P.current?.toString()!==s.toString())throw new Error("Wallet changed during payment flow");const M=await l.signTransaction({transaction:b,signTransaction:m}),A=l.buildPaymentPayload({requirement:o,signedTx:M,payerPublicKey:s}),E=await C.submitPayment({resource:c,payload:A,couponCode:d,metadata:x,resourceType:n});return E.success&&E.settlement&&k(E.settlement),E}},[C,l]),w=a.useCallback(async(o,c,d)=>{if(I())return{success:!1,error:"Payment already in progress"};const x=S();if(!x.valid)return{success:!1,error:x.error};g.current=Date.now(),y({status:"loading",error:null,transactionId:null});try{t.getLogger().debug("[useX402Payment] Fetching fresh quote");const n=await C.requestQuote({resource:o,couponCode:c});t.getLogger().debug("[useX402Payment] Received quote",{amount:n.maxAmountRequired}),L(n),t.getLogger().debug("[useX402Payment] Executing payment flow");const s=await B(n,o,c,d,"regular");return s.success?y({status:"success",error:null,transactionId:s.transactionId||"payment-success"}):y({status:"error",error:s.error||"Payment failed",transactionId:null}),s}catch(n){const s=t.formatError(n,"Payment failed");return y({status:"error",error:s,transactionId:null}),{success:!1,error:s}}finally{g.current=0}},[S,C,B]),_=a.useCallback(async(o,c,d)=>{if(I())return{success:!1,error:"Payment already in progress"};const x=S();if(!x.valid)return{success:!1,error:x.error};g.current=Date.now(),y({status:"loading",error:null,transactionId:null});try{const n=i.normalizeCartItems(o),s=await C.requestCartQuote({items:n,metadata:c,couponCode:d}),m=s.cartId,u=s.quote;if(!C.validateRequirement(u))throw new Error("Invalid cart quote received from server");L(u);const b=await B(u,m,d,c,"cart");return b.success?y({status:"success",error:null,transactionId:b.transactionId||"cart-payment-success"}):y({status:"error",error:b.error||"Cart payment failed",transactionId:null}),b}catch(n){const s=t.formatError(n,"Cart payment failed");return y({status:"error",error:s,transactionId:null}),{success:!1,error:s}}finally{g.current=0}},[S,C,B]),T=a.useCallback(()=>{y({status:"idle",error:null,transactionId:null}),L(null),k(null),g.current=0},[]);return{...N,requirement:R,settlement:K,fetchQuote:q,processPayment:w,processCartPayment:_,reset:T}}function ue({resource:C,items:l,label:W,disabled:j=!1,onAttempt:N,onSuccess:y,onError:R,className:L="",testPageUrl:K,hideMessages:k=!1,metadata:P,couponCode:h}){const{connected:g,connecting:X,connect:I,disconnect:S,select:q,wallets:B,wallet:w,publicKey:_}=ce.useWallet(),{status:T,error:o,transactionId:c,processPayment:d,processCartPayment:x}=ie(),n=t.useCedrosTheme(),{solanaError:s}=t.useCedrosContext(),{isCartMode:m,effectiveResource:u}=i.usePaymentMode(C,l),{t:b,translations:M}=i.useTranslation(),A=W||b("ui.pay_with_crypto"),E=o&&typeof o!="string"?o?.code??null:null,z=s&&typeof s!="string"?s?.code??null:null,U=e=>{if(!e||!M)return"";const r=M.errors[e];return r?r.action?`${r.message} ${r.action}`:r.message:""},Y=o?typeof o=="string"?o:U(E):null,H=s?typeof s=="string"?s:U(z):null,J=a.useRef(y),V=a.useRef(R),Z=a.useRef(d),ee=a.useRef(x);J.current=y,V.current=R,Z.current=d,ee.current=x;const de=a.useMemo(()=>B.map(e=>`${e.adapter.name}-${e.readyState}`).join(","),[B]),G=a.useMemo(()=>B.filter(({readyState:e})=>e===le.WalletReadyState.Installed||e===le.WalletReadyState.Loadable),[de]);a.useEffect(()=>{if(T==="success"&&c){const e=m&&l?i.getCartItemCount(l):void 0;i.emitPaymentSuccess("crypto",c,u,e),J.current?.(c)}},[T,c,m,l,u]),a.useEffect(()=>{if(T==="error"&&o){const e=m&&l?i.getCartItemCount(l):void 0;i.emitPaymentError("crypto",o,u,e),V.current?.(o)}},[T,o,m,l,u]);const te=typeof window<"u"&&window.top!==window.self,[re,$]=a.useState(!1),[ne,Q]=a.useState(!1),[D,v]=a.useState(null),F=s;a.useEffect(()=>{let e=!1;return e||(async()=>{if(ne&&w&&!g&&!X){t.getLogger().debug("[CryptoButton] Wallet detected, attempting auto-connect:",w.adapter.name),Q(!1),i.emitWalletConnect(w.adapter.name);try{await I(),e||t.getLogger().debug("[CryptoButton] Auto-connect successful")}catch(f){if(!e){t.getLogger().error("[CryptoButton] Auto-connect failed:",f);const O=f instanceof Error?f.message:"Failed to connect wallet";i.emitWalletError(O,w.adapter.name),v(null)}}}})(),()=>{e=!0}},[w,ne,g,X,I]),a.useEffect(()=>{let e=!0;if(t.getLogger().debug("[CryptoButton] Payment useEffect triggered",{connected:g,hasPendingPayment:!!D,hasPublicKey:!!_,pendingPaymentType:D?.type}),g&&D&&_&&w&&e){i.emitWalletConnected(w.adapter.name,_.toString()),t.getLogger().debug("[CryptoButton] All conditions met! Processing pending payment:",D);const r=D;v(null),$(!1);const f=r.type==="cart"&&r.items?i.getCartItemCount(r.items):void 0;i.emitPaymentProcessing("crypto",r.resource,f),r.type==="cart"&&r.items?(t.getLogger().debug("[CryptoButton] Auto-processing cart payment"),ee.current(r.items,r.metadata,r.couponCode)):r.type==="single"&&r.resource&&(t.getLogger().debug("[CryptoButton] Auto-processing single payment"),Z.current(r.resource,r.couponCode,r.metadata))}return()=>{e=!1}},[g,D,_,w]);const oe=a.useCallback(async()=>{t.getLogger().debug("[CryptoButton] executePaymentFlow called",{connected:g,wallet:w?.adapter.name,couponCode:h,isCartMode:m,hasItems:!!l,effectiveResource:u});const e=m&&l?i.getCartItemCount(l):void 0;if(i.emitPaymentStart("crypto",u,e),N&&N("crypto"),F){t.getLogger().error("[CryptoButton] Solana dependencies missing:",F),i.emitPaymentError("crypto",F,u,e),R&&R(F);return}if(te){const r=K||window.location.href;try{if(new URL(r,window.location.origin).origin!==window.location.origin)throw t.getLogger().error("[CryptoButton] Blocked attempt to open external URL:",r),new Error("Cannot open external URLs from embedded context");window.open(r,"_blank","noopener,noreferrer")}catch(f){throw t.getLogger().error("[CryptoButton] URL validation failed:",f),f}return}if(g)i.emitPaymentProcessing("crypto",u,e),m&&l?(t.getLogger().debug("[CryptoButton] Processing cart payment with coupon:",h),await x(l,P,h)):u&&(t.getLogger().debug("[CryptoButton] Processing single payment with coupon:",h),await d(u,h,P));else{let r=!1;if(m&&l?(t.getLogger().debug("[CryptoButton] Setting pending cart payment with coupon:",h),v({type:"cart",items:l,metadata:P,couponCode:h}),r=!0):u&&(t.getLogger().debug("[CryptoButton] Setting pending single payment with coupon:",h),v({type:"single",resource:u,metadata:P,couponCode:h}),r=!0),!r){t.getLogger().error("[CryptoButton] No valid payment to process");return}try{if(w)t.getLogger().debug("[CryptoButton] Wallet already selected, connecting:",w.adapter.name),i.emitWalletConnect(w.adapter.name),await I();else{if(t.getLogger().debug("[CryptoButton] No wallet selected, showing selector. Available wallets:",G.map(f=>f.adapter.name)),G.length===0){v(null);const f="No wallets available";throw i.emitWalletError(f),new Error(f)}$(!0)}}catch(f){v(null);const O=f instanceof Error?f.message:"Failed to connect wallet";t.getLogger().error("[CryptoButton] Connection error:",O),i.emitWalletError(O,w?.adapter.name)}}},[g,w,h,m,l,u,te,K,G,I,P,x,d,F,N,R]),ae=a.useMemo(()=>m&&l?`crypto-cart-${l.map(e=>e.resource).join("-")}`:`crypto-${u||"unknown"}`,[m,l,u]),ge=a.useMemo(()=>i.createDedupedClickHandler(ae,oe,{cooldownMs:200,deduplicationWindowMs:0}),[ae,oe]),se=T==="loading",ye=j||se||X||!!F,me=se?b("ui.processing"):A,fe=a.useCallback(async()=>{try{Q(!1),g&&await S(),q(null),$(!0)}catch(e){t.getLogger().error("Failed to change wallet:",e)}},[g,S,q]),pe=a.useCallback(e=>{t.getLogger().debug("[CryptoButton] Wallet clicked:",e),$(!1),q(e),Q(!0),t.getLogger().debug("[CryptoButton] Wallet selected, useEffect will auto-connect")},[q]),we=a.useCallback(async()=>{try{if(await S(),v(null),typeof window<"u"&&window.localStorage)try{window.localStorage.removeItem("walletName")}catch(e){e instanceof Error&&e.name==="QuotaExceededError"?t.getLogger().warn("localStorage quota exceeded when removing wallet preference"):t.getLogger().error("Failed to clear wallet preference from localStorage:",e)}}catch(e){t.getLogger().error("Failed to disconnect wallet:",e)}},[S]);return p.jsxs("div",{className:n.unstyled?L:`${n.className} cedros-theme__crypto-button ${L||""}`,style:n.unstyled?{}:n.style,children:[p.jsx("button",{onClick:ge,disabled:ye,className:n.unstyled?L:"cedros-theme__button cedros-theme__crypto",type:"button",children:me}),re&&!k&&p.jsx("div",{className:"cedros-modal-overlay",style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:n.tokens.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999,padding:"1rem"},onClick:()=>{$(!1),v(null)},children:p.jsxs("div",{className:"cedros-modal-content",style:{backgroundColor:n.tokens.modalBackground,borderRadius:"12px",padding:"2rem",maxWidth:"400px",width:"100%",boxShadow:"0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",border:`1px solid ${n.tokens.modalBorder}`},onClick:e=>e.stopPropagation(),children:[p.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1.5rem"},children:[p.jsx("h3",{style:{margin:0,fontSize:"1.25rem",fontWeight:600,color:n.tokens.surfaceText},children:b("wallet.select_wallet")}),p.jsx("button",{onClick:()=>{$(!1),v(null)},style:i.getModalCloseButtonStyles(n.tokens.surfaceText),"aria-label":"Close modal",type:"button",children:"×"})]}),p.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:G.map(e=>p.jsxs("button",{onClick:()=>pe(e.adapter.name),style:{width:"100%",padding:"1rem",backgroundColor:n.tokens.surfaceBackground,border:`1px solid ${n.tokens.surfaceBorder}`,borderRadius:"0.5rem",cursor:"pointer",fontSize:"1rem",textAlign:"left",color:n.tokens.surfaceText,display:"flex",alignItems:"center",gap:"1rem",transition:"all 0.2s ease"},onMouseEnter:r=>{r.currentTarget.style.backgroundColor=n.tokens.modalBackground,r.currentTarget.style.borderColor=n.tokens.surfaceText,r.currentTarget.style.transform="translateY(-2px)"},onMouseLeave:r=>{r.currentTarget.style.backgroundColor=n.tokens.surfaceBackground,r.currentTarget.style.borderColor=n.tokens.surfaceBorder,r.currentTarget.style.transform="translateY(0)"},type:"button",children:[p.jsx(be.WalletIcon,{wallet:e,style:{width:"24px",height:"24px"}}),p.jsx("span",{style:{fontWeight:500},children:e.adapter.name})]},e.adapter.name))})]})}),g&&!k&&!re&&p.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"0.5rem",fontSize:"0.75rem",color:n.tokens.surfaceText,opacity:.7},children:[p.jsx("button",{onClick:fe,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:b("wallet.change")}),p.jsx("button",{onClick:we,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:b("ui.disconnect")})]}),!k&&H&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__error",children:H}),!k&&Y&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__error",children:Y}),!k&&c&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__success",children:b("ui.payment_successful")})]})}const Ce=Object.freeze(Object.defineProperty({__proto__:null,CryptoButton:ue},Symbol.toStringTag,{value:"Module"}));exports.CryptoButton=ue;exports.CryptoButton$1=Ce;exports.useX402Payment=ie;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("react"),y=require("./index-C0g-JxJk.js");function q({serverUrl:g,apiKey:h,pageSize:i=20,authManager:x}){const[_,C]=n.useState([]),[A,N]=n.useState(!0),[F,l]=n.useState(null),[o,v]=n.useState(0),[D,p]=n.useState(!1),[S,w]=n.useState(!1),[r,E]=n.useState(null),[c,I]=n.useState(""),[a,d]=n.useState({email:"",name:"",phone:""}),m=n.useCallback(async(t,s)=>{if(x?.isAuthenticated())return x.fetchWithAuth(t,s);const k={"Content-Type":"application/json"};h&&(k["X-API-Key"]=h);const b=await fetch(`${g}${t}`,{...s,headers:{...k,...s?.headers}});if(!b.ok)throw new Error(`Request failed: ${b.status}`);return b.json()},[g,h,x]),f=n.useCallback(async()=>{N(!0),l(null);try{const t=await m(`/admin/customers?limit=${i}&offset=${o}`);C(t.customers??[])}catch{l("Failed to load customers"),C([])}finally{N(!1)}},[m,i,o]);n.useEffect(()=>{f()},[f]);const j=()=>{d({email:"",name:"",phone:""}),E(null),p(!1)},L=t=>{E(t),d({email:t.email,name:t.name??"",phone:t.phone??""}),p(!0)},P=async t=>{t.preventDefault(),w(!0),l(null);try{r?await m(`/admin/customers/${encodeURIComponent(r.id)}`,{method:"PUT",body:JSON.stringify({email:a.email,name:a.name||null,phone:a.phone||null,addresses:r.addresses})}):await m("/admin/customers",{method:"POST",body:JSON.stringify({email:a.email,name:a.name||null,phone:a.phone||null,addresses:[]})}),j(),f()}catch(s){l(s instanceof Error?s.message:"Failed to save customer")}finally{w(!1)}},u=c.trim()?_.filter(t=>{const s=c.toLowerCase();return t.email.toLowerCase().includes(s)||(t.name??"").toLowerCase().includes(s)||t.id.toLowerCase().includes(s)}):_,T=t=>[t.line1,t.city,t.state,t.postalCode,t.country].filter(Boolean).join(", ");return e.jsxs("div",{children:[e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsx("h3",{className:"cedros-admin__section-title",children:"Customers"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--primary",onClick:()=>{j(),p(!0)},children:"+ Add Customer"})]}),e.jsx(y.ErrorBanner,{message:F}),e.jsx("div",{style:{marginBottom:"1rem",maxWidth:"400px"},children:e.jsx("input",{type:"text",className:"cedros-admin__input",placeholder:"Search by email, name, or ID...",value:c,onChange:t=>I(t.target.value),style:{fontSize:"0.85rem"}})}),D&&e.jsxs("form",{onSubmit:P,style:{border:"1px solid var(--cedros-admin-border, #e0e0e0)",borderRadius:"4px",padding:"1rem",marginBottom:"1.5rem",maxWidth:"500px"},children:[e.jsx("h4",{style:{margin:"0 0 0.75rem",fontSize:"0.9rem",fontWeight:600},children:r?"Edit Customer":"New Customer"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Email *"}),e.jsx("input",{type:"email",className:"cedros-admin__input",value:a.email,onChange:t=>d(s=>({...s,email:t.target.value})),required:!0,placeholder:"customer@example.com"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Name"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.name,onChange:t=>d(s=>({...s,name:t.target.value})),placeholder:"Jane Doe"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Phone"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.phone,onChange:t=>d(s=>({...s,phone:t.target.value})),placeholder:"+1 555 123 4567"})]})]}),e.jsxs("div",{style:{marginTop:"0.75rem",display:"flex",gap:"0.5rem"},children:[e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:S,children:S?"Saving...":r?"Update":"Create"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:j,children:"Cancel"})]})]}),A?e.jsxs("div",{className:"cedros-admin__loading",children:[y.Icons.loading," Loading customers..."]}):u.length===0?e.jsx("div",{className:"cedros-admin__empty",children:c?"No matching customers.":"No customers found."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Email"}),e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Phone"}),e.jsx("th",{children:"Address"}),e.jsx("th",{children:"Created"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:u.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:t.email}),e.jsx("td",{children:t.name??e.jsx("span",{style:{color:"var(--cedros-admin-text-muted, #888)"},children:"—"})}),e.jsx("td",{children:t.phone??e.jsx("span",{style:{color:"var(--cedros-admin-text-muted, #888)"},children:"—"})}),e.jsx("td",{style:{fontSize:"0.8rem",maxWidth:"200px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.addresses.length>0?T(t.addresses[0]):"—"}),e.jsx("td",{children:y.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>L(t),children:"Edit"})})]},t.id))})]})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"0.75rem",fontSize:"0.85rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:o===0,onClick:()=>v(Math.max(0,o-i)),children:"Previous"}),e.jsxs("span",{children:["Showing ",u.length," customer",u.length!==1?"s":""]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:_.length<i,onClick:()=>v(o+i),children:"Next"})]})]})]})}exports.CustomersSection=q;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { jsxs as s, jsx as t, Fragment as $ } from "react/jsx-runtime";
|
|
2
|
+
import { useState as o, useCallback as F, useEffect as O } from "react";
|
|
3
|
+
import { E as B, I as q, k as J } from "./index-DXnuQp5x.mjs";
|
|
4
|
+
function X({ serverUrl: N, apiKey: _, pageSize: r = 20, authManager: p }) {
|
|
5
|
+
const [f, v] = o([]), [I, x] = o(!0), [D, m] = o(null), [i, w] = o(0), [L, b] = o(!1), [S, E] = o(!1), [d, k] = o(null), [c, j] = o(""), [a, l] = o({ email: "", name: "", phone: "" }), h = F(async (e, n) => {
|
|
6
|
+
if (p?.isAuthenticated())
|
|
7
|
+
return p.fetchWithAuth(e, n);
|
|
8
|
+
const A = { "Content-Type": "application/json" };
|
|
9
|
+
_ && (A["X-API-Key"] = _);
|
|
10
|
+
const C = await fetch(`${N}${e}`, { ...n, headers: { ...A, ...n?.headers } });
|
|
11
|
+
if (!C.ok) throw new Error(`Request failed: ${C.status}`);
|
|
12
|
+
return C.json();
|
|
13
|
+
}, [N, _, p]), y = F(async () => {
|
|
14
|
+
x(!0), m(null);
|
|
15
|
+
try {
|
|
16
|
+
const e = await h(
|
|
17
|
+
`/admin/customers?limit=${r}&offset=${i}`
|
|
18
|
+
);
|
|
19
|
+
v(e.customers ?? []);
|
|
20
|
+
} catch {
|
|
21
|
+
m("Failed to load customers"), v([]);
|
|
22
|
+
} finally {
|
|
23
|
+
x(!1);
|
|
24
|
+
}
|
|
25
|
+
}, [h, r, i]);
|
|
26
|
+
O(() => {
|
|
27
|
+
y();
|
|
28
|
+
}, [y]);
|
|
29
|
+
const g = () => {
|
|
30
|
+
l({ email: "", name: "", phone: "" }), k(null), b(!1);
|
|
31
|
+
}, P = (e) => {
|
|
32
|
+
k(e), l({ email: e.email, name: e.name ?? "", phone: e.phone ?? "" }), b(!0);
|
|
33
|
+
}, T = async (e) => {
|
|
34
|
+
e.preventDefault(), E(!0), m(null);
|
|
35
|
+
try {
|
|
36
|
+
d ? await h(`/admin/customers/${encodeURIComponent(d.id)}`, {
|
|
37
|
+
method: "PUT",
|
|
38
|
+
body: JSON.stringify({
|
|
39
|
+
email: a.email,
|
|
40
|
+
name: a.name || null,
|
|
41
|
+
phone: a.phone || null,
|
|
42
|
+
addresses: d.addresses
|
|
43
|
+
})
|
|
44
|
+
}) : await h("/admin/customers", {
|
|
45
|
+
method: "POST",
|
|
46
|
+
body: JSON.stringify({
|
|
47
|
+
email: a.email,
|
|
48
|
+
name: a.name || null,
|
|
49
|
+
phone: a.phone || null,
|
|
50
|
+
addresses: []
|
|
51
|
+
})
|
|
52
|
+
}), g(), y();
|
|
53
|
+
} catch (n) {
|
|
54
|
+
m(n instanceof Error ? n.message : "Failed to save customer");
|
|
55
|
+
} finally {
|
|
56
|
+
E(!1);
|
|
57
|
+
}
|
|
58
|
+
}, u = c.trim() ? f.filter((e) => {
|
|
59
|
+
const n = c.toLowerCase();
|
|
60
|
+
return e.email.toLowerCase().includes(n) || (e.name ?? "").toLowerCase().includes(n) || e.id.toLowerCase().includes(n);
|
|
61
|
+
}) : f, W = (e) => [e.line1, e.city, e.state, e.postalCode, e.country].filter(Boolean).join(", ");
|
|
62
|
+
return /* @__PURE__ */ s("div", { children: [
|
|
63
|
+
/* @__PURE__ */ s("div", { className: "cedros-admin__section-header", children: [
|
|
64
|
+
/* @__PURE__ */ t("h3", { className: "cedros-admin__section-title", children: "Customers" }),
|
|
65
|
+
/* @__PURE__ */ t(
|
|
66
|
+
"button",
|
|
67
|
+
{
|
|
68
|
+
type: "button",
|
|
69
|
+
className: "cedros-admin__button cedros-admin__button--primary",
|
|
70
|
+
onClick: () => {
|
|
71
|
+
g(), b(!0);
|
|
72
|
+
},
|
|
73
|
+
children: "+ Add Customer"
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
] }),
|
|
77
|
+
/* @__PURE__ */ t(B, { message: D }),
|
|
78
|
+
/* @__PURE__ */ t("div", { style: { marginBottom: "1rem", maxWidth: "400px" }, children: /* @__PURE__ */ t(
|
|
79
|
+
"input",
|
|
80
|
+
{
|
|
81
|
+
type: "text",
|
|
82
|
+
className: "cedros-admin__input",
|
|
83
|
+
placeholder: "Search by email, name, or ID...",
|
|
84
|
+
value: c,
|
|
85
|
+
onChange: (e) => j(e.target.value),
|
|
86
|
+
style: { fontSize: "0.85rem" }
|
|
87
|
+
}
|
|
88
|
+
) }),
|
|
89
|
+
L && /* @__PURE__ */ s("form", { onSubmit: T, style: {
|
|
90
|
+
border: "1px solid var(--cedros-admin-border, #e0e0e0)",
|
|
91
|
+
borderRadius: "4px",
|
|
92
|
+
padding: "1rem",
|
|
93
|
+
marginBottom: "1.5rem",
|
|
94
|
+
maxWidth: "500px"
|
|
95
|
+
}, children: [
|
|
96
|
+
/* @__PURE__ */ t("h4", { style: { margin: "0 0 0.75rem", fontSize: "0.9rem", fontWeight: 600 }, children: d ? "Edit Customer" : "New Customer" }),
|
|
97
|
+
/* @__PURE__ */ s("div", { style: { display: "flex", flexDirection: "column", gap: "0.5rem" }, children: [
|
|
98
|
+
/* @__PURE__ */ s("div", { className: "cedros-admin__field", children: [
|
|
99
|
+
/* @__PURE__ */ t("label", { className: "cedros-admin__field-label", children: "Email *" }),
|
|
100
|
+
/* @__PURE__ */ t(
|
|
101
|
+
"input",
|
|
102
|
+
{
|
|
103
|
+
type: "email",
|
|
104
|
+
className: "cedros-admin__input",
|
|
105
|
+
value: a.email,
|
|
106
|
+
onChange: (e) => l((n) => ({ ...n, email: e.target.value })),
|
|
107
|
+
required: !0,
|
|
108
|
+
placeholder: "customer@example.com"
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
] }),
|
|
112
|
+
/* @__PURE__ */ s("div", { className: "cedros-admin__field", children: [
|
|
113
|
+
/* @__PURE__ */ t("label", { className: "cedros-admin__field-label", children: "Name" }),
|
|
114
|
+
/* @__PURE__ */ t(
|
|
115
|
+
"input",
|
|
116
|
+
{
|
|
117
|
+
type: "text",
|
|
118
|
+
className: "cedros-admin__input",
|
|
119
|
+
value: a.name,
|
|
120
|
+
onChange: (e) => l((n) => ({ ...n, name: e.target.value })),
|
|
121
|
+
placeholder: "Jane Doe"
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
] }),
|
|
125
|
+
/* @__PURE__ */ s("div", { className: "cedros-admin__field", children: [
|
|
126
|
+
/* @__PURE__ */ t("label", { className: "cedros-admin__field-label", children: "Phone" }),
|
|
127
|
+
/* @__PURE__ */ t(
|
|
128
|
+
"input",
|
|
129
|
+
{
|
|
130
|
+
type: "text",
|
|
131
|
+
className: "cedros-admin__input",
|
|
132
|
+
value: a.phone,
|
|
133
|
+
onChange: (e) => l((n) => ({ ...n, phone: e.target.value })),
|
|
134
|
+
placeholder: "+1 555 123 4567"
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
] })
|
|
138
|
+
] }),
|
|
139
|
+
/* @__PURE__ */ s("div", { style: { marginTop: "0.75rem", display: "flex", gap: "0.5rem" }, children: [
|
|
140
|
+
/* @__PURE__ */ t("button", { type: "submit", className: "cedros-admin__button cedros-admin__button--primary", disabled: S, children: S ? "Saving..." : d ? "Update" : "Create" }),
|
|
141
|
+
/* @__PURE__ */ t("button", { type: "button", className: "cedros-admin__button cedros-admin__button--ghost", onClick: g, children: "Cancel" })
|
|
142
|
+
] })
|
|
143
|
+
] }),
|
|
144
|
+
I ? /* @__PURE__ */ s("div", { className: "cedros-admin__loading", children: [
|
|
145
|
+
q.loading,
|
|
146
|
+
" Loading customers..."
|
|
147
|
+
] }) : u.length === 0 ? /* @__PURE__ */ t("div", { className: "cedros-admin__empty", children: c ? "No matching customers." : "No customers found." }) : /* @__PURE__ */ s($, { children: [
|
|
148
|
+
/* @__PURE__ */ t("div", { className: "cedros-admin__table-container", children: /* @__PURE__ */ s("table", { className: "cedros-admin__table", children: [
|
|
149
|
+
/* @__PURE__ */ t("thead", { children: /* @__PURE__ */ s("tr", { children: [
|
|
150
|
+
/* @__PURE__ */ t("th", { children: "Email" }),
|
|
151
|
+
/* @__PURE__ */ t("th", { children: "Name" }),
|
|
152
|
+
/* @__PURE__ */ t("th", { children: "Phone" }),
|
|
153
|
+
/* @__PURE__ */ t("th", { children: "Address" }),
|
|
154
|
+
/* @__PURE__ */ t("th", { children: "Created" }),
|
|
155
|
+
/* @__PURE__ */ t("th", {})
|
|
156
|
+
] }) }),
|
|
157
|
+
/* @__PURE__ */ t("tbody", { children: u.map((e) => /* @__PURE__ */ s("tr", { children: [
|
|
158
|
+
/* @__PURE__ */ t("td", { children: e.email }),
|
|
159
|
+
/* @__PURE__ */ t("td", { children: e.name ?? /* @__PURE__ */ t("span", { style: { color: "var(--cedros-admin-text-muted, #888)" }, children: "—" }) }),
|
|
160
|
+
/* @__PURE__ */ t("td", { children: e.phone ?? /* @__PURE__ */ t("span", { style: { color: "var(--cedros-admin-text-muted, #888)" }, children: "—" }) }),
|
|
161
|
+
/* @__PURE__ */ t("td", { style: { fontSize: "0.8rem", maxWidth: "200px", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: e.addresses.length > 0 ? W(e.addresses[0]) : "—" }),
|
|
162
|
+
/* @__PURE__ */ t("td", { children: J(e.createdAt) }),
|
|
163
|
+
/* @__PURE__ */ t("td", { children: /* @__PURE__ */ t(
|
|
164
|
+
"button",
|
|
165
|
+
{
|
|
166
|
+
type: "button",
|
|
167
|
+
className: "cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",
|
|
168
|
+
onClick: () => P(e),
|
|
169
|
+
children: "Edit"
|
|
170
|
+
}
|
|
171
|
+
) })
|
|
172
|
+
] }, e.id)) })
|
|
173
|
+
] }) }),
|
|
174
|
+
/* @__PURE__ */ s("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: "0.75rem", fontSize: "0.85rem" }, children: [
|
|
175
|
+
/* @__PURE__ */ t(
|
|
176
|
+
"button",
|
|
177
|
+
{
|
|
178
|
+
type: "button",
|
|
179
|
+
className: "cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",
|
|
180
|
+
disabled: i === 0,
|
|
181
|
+
onClick: () => w(Math.max(0, i - r)),
|
|
182
|
+
children: "Previous"
|
|
183
|
+
}
|
|
184
|
+
),
|
|
185
|
+
/* @__PURE__ */ s("span", { children: [
|
|
186
|
+
"Showing ",
|
|
187
|
+
u.length,
|
|
188
|
+
" customer",
|
|
189
|
+
u.length !== 1 ? "s" : ""
|
|
190
|
+
] }),
|
|
191
|
+
/* @__PURE__ */ t(
|
|
192
|
+
"button",
|
|
193
|
+
{
|
|
194
|
+
type: "button",
|
|
195
|
+
className: "cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",
|
|
196
|
+
disabled: f.length < r,
|
|
197
|
+
onClick: () => w(i + r),
|
|
198
|
+
children: "Next"
|
|
199
|
+
}
|
|
200
|
+
)
|
|
201
|
+
] })
|
|
202
|
+
] })
|
|
203
|
+
] });
|
|
204
|
+
}
|
|
205
|
+
export {
|
|
206
|
+
X as CustomersSection
|
|
207
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("react"),l=require("./index-C0g-JxJk.js"),I=d=>{switch(d){case"won":return"success";case"lost":return"failed";case"needs_response":case"warning_needs_response":return"pending";default:return"muted"}},C=(d,i)=>`${i.toUpperCase()} ${(d/100).toFixed(2)}`;function k({serverUrl:d,apiKey:i,pageSize:a=20,authManager:j}){const[r,y]=s.useState([]),[W,b]=s.useState(!0),[D,o]=s.useState(null),[c,p]=s.useState(0),[h,U]=s.useState("all"),[u,_]=s.useState(null),[m,v]=s.useState(""),[S,N]=s.useState(!1),x=s.useCallback(async(t,n)=>{if(j?.isAuthenticated())return j.fetchWithAuth(t,n);const w={"Content-Type":"application/json"};i&&(w["X-API-Key"]=i);const g=await fetch(`${d}${t}`,{...n,headers:{...w,...n?.headers}});if(!g.ok)throw new Error(`Request failed: ${g.status}`);return g.json()},[d,i,j]),f=s.useCallback(async()=>{b(!0),o(null);try{const t=new URLSearchParams;t.set("limit",String(a)),t.set("offset",String(c)),h!=="all"&&t.set("status",h);const n=await x(`/admin/disputes?${t.toString()}`);y(n.disputes??[])}catch{o("Failed to load disputes"),y([])}finally{b(!1)}},[x,a,c,h]);s.useEffect(()=>{f()},[f]);const A=async t=>{try{const n=await x(`/admin/disputes/${encodeURIComponent(t)}`);_(n),v(n.status)}catch{o("Failed to load dispute details")}},R=async()=>{if(!(!u||!m.trim())){N(!0);try{const t=await x(`/admin/disputes/${encodeURIComponent(u.id)}/status`,{method:"PUT",body:JSON.stringify({status:m})});_(t),f()}catch{o("Failed to update dispute status")}finally{N(!1)}}};if(u){const t=u;return e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>_(null),style:{marginBottom:"1rem"},children:"← Back to disputes"}),e.jsx("div",{className:"cedros-admin__section-header",children:e.jsxs("h3",{className:"cedros-admin__section-title",children:["Dispute ",e.jsx("code",{style:{fontSize:"0.8rem"},children:t.id.slice(0,12)})]})}),e.jsx("div",{className:"cedros-admin__table-container",style:{maxWidth:"500px"},children:e.jsx("table",{className:"cedros-admin__table",children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600,width:"35%"},children:"Status"}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${I(t.status)}`,children:t.status})})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Amount"}),e.jsx("td",{children:C(t.amount,t.currency)})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Source"}),e.jsx("td",{children:t.source})]}),t.reason&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Reason"}),e.jsx("td",{children:t.reason})]}),t.orderId&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Order ID"}),e.jsx("td",{children:e.jsx("code",{children:t.orderId})})]}),t.chargeId&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Charge ID"}),e.jsx("td",{children:e.jsx("code",{children:t.chargeId})})]}),t.paymentIntentId&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Payment Intent"}),e.jsx("td",{children:e.jsx("code",{children:t.paymentIntentId})})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Created"}),e.jsx("td",{children:l.formatDateTime(t.createdAt)})]}),t.statusUpdatedAt&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Status Updated"}),e.jsx("td",{children:l.formatDateTime(t.statusUpdatedAt)})]})]})})}),e.jsxs("div",{style:{marginTop:"1rem",display:"flex",gap:"0.5rem",alignItems:"flex-end",maxWidth:"400px"},children:[e.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Update Status"}),e.jsxs("select",{className:"cedros-admin__input",value:m,onChange:n=>v(n.target.value),children:[e.jsx("option",{value:"needs_response",children:"Needs Response"}),e.jsx("option",{value:"under_review",children:"Under Review"}),e.jsx("option",{value:"won",children:"Won"}),e.jsx("option",{value:"lost",children:"Lost"}),e.jsx("option",{value:"warning_closed",children:"Warning Closed"})]})]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--primary",onClick:R,disabled:S||m===t.status,children:S?"Updating...":"Update"})]})]})}return e.jsxs("div",{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Disputes & Chargebacks"})}),e.jsx(l.ErrorBanner,{message:D}),e.jsx("div",{style:{display:"flex",gap:"0.5rem",marginBottom:"1rem",alignItems:"center"},children:e.jsxs("select",{className:"cedros-admin__input",value:h,onChange:t=>{U(t.target.value),p(0)},style:{width:"auto",fontSize:"0.85rem"},children:[e.jsx("option",{value:"all",children:"All statuses"}),e.jsx("option",{value:"needs_response",children:"Needs Response"}),e.jsx("option",{value:"under_review",children:"Under Review"}),e.jsx("option",{value:"won",children:"Won"}),e.jsx("option",{value:"lost",children:"Lost"})]})}),W?e.jsxs("div",{className:"cedros-admin__loading",children:[l.Icons.loading," Loading disputes..."]}):r.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No disputes found."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"ID"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Reason"}),e.jsx("th",{children:"Source"}),e.jsx("th",{children:"Created"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:r.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{style:{fontSize:"0.75rem"},children:t.id.slice(0,12)})}),e.jsx("td",{children:C(t.amount,t.currency)}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${I(t.status)}`,children:t.status})}),e.jsx("td",{children:t.reason??"—"}),e.jsx("td",{children:t.source}),e.jsx("td",{children:l.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>A(t.id),children:"View"})})]},t.id))})]})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"0.75rem",fontSize:"0.85rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:c===0,onClick:()=>p(Math.max(0,c-a)),children:"Previous"}),e.jsxs("span",{children:["Showing ",r.length," dispute",r.length!==1?"s":""]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:r.length<a,onClick:()=>p(c+a),children:"Next"})]})]})]})}exports.DisputesSection=k;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { jsxs as n, jsx as e, Fragment as E } from "react/jsx-runtime";
|
|
2
|
+
import { useState as d, useCallback as x, useEffect as L } from "react";
|
|
3
|
+
import { k as v, E as j, I as B } from "./index-DXnuQp5x.mjs";
|
|
4
|
+
const U = (i) => {
|
|
5
|
+
switch (i) {
|
|
6
|
+
case "won":
|
|
7
|
+
return "success";
|
|
8
|
+
case "lost":
|
|
9
|
+
return "failed";
|
|
10
|
+
case "needs_response":
|
|
11
|
+
case "warning_needs_response":
|
|
12
|
+
return "pending";
|
|
13
|
+
default:
|
|
14
|
+
return "muted";
|
|
15
|
+
}
|
|
16
|
+
}, A = (i, a) => `${a.toUpperCase()} ${(i / 100).toFixed(2)}`;
|
|
17
|
+
function q({ serverUrl: i, apiKey: a, pageSize: r = 20, authManager: _ }) {
|
|
18
|
+
const [c, N] = d([]), [D, w] = d(!0), [k, o] = d(null), [l, f] = d(0), [h, R] = d("all"), [u, g] = d(null), [m, I] = d(""), [S, C] = d(!1), p = x(async (t, s) => {
|
|
19
|
+
if (_?.isAuthenticated())
|
|
20
|
+
return _.fetchWithAuth(t, s);
|
|
21
|
+
const W = { "Content-Type": "application/json" };
|
|
22
|
+
a && (W["X-API-Key"] = a);
|
|
23
|
+
const b = await fetch(`${i}${t}`, { ...s, headers: { ...W, ...s?.headers } });
|
|
24
|
+
if (!b.ok) throw new Error(`Request failed: ${b.status}`);
|
|
25
|
+
return b.json();
|
|
26
|
+
}, [i, a, _]), y = x(async () => {
|
|
27
|
+
w(!0), o(null);
|
|
28
|
+
try {
|
|
29
|
+
const t = new URLSearchParams();
|
|
30
|
+
t.set("limit", String(r)), t.set("offset", String(l)), h !== "all" && t.set("status", h);
|
|
31
|
+
const s = await p(`/admin/disputes?${t.toString()}`);
|
|
32
|
+
N(s.disputes ?? []);
|
|
33
|
+
} catch {
|
|
34
|
+
o("Failed to load disputes"), N([]);
|
|
35
|
+
} finally {
|
|
36
|
+
w(!1);
|
|
37
|
+
}
|
|
38
|
+
}, [p, r, l, h]);
|
|
39
|
+
L(() => {
|
|
40
|
+
y();
|
|
41
|
+
}, [y]);
|
|
42
|
+
const $ = async (t) => {
|
|
43
|
+
try {
|
|
44
|
+
const s = await p(`/admin/disputes/${encodeURIComponent(t)}`);
|
|
45
|
+
g(s), I(s.status);
|
|
46
|
+
} catch {
|
|
47
|
+
o("Failed to load dispute details");
|
|
48
|
+
}
|
|
49
|
+
}, F = async () => {
|
|
50
|
+
if (!(!u || !m.trim())) {
|
|
51
|
+
C(!0);
|
|
52
|
+
try {
|
|
53
|
+
const t = await p(
|
|
54
|
+
`/admin/disputes/${encodeURIComponent(u.id)}/status`,
|
|
55
|
+
{ method: "PUT", body: JSON.stringify({ status: m }) }
|
|
56
|
+
);
|
|
57
|
+
g(t), y();
|
|
58
|
+
} catch {
|
|
59
|
+
o("Failed to update dispute status");
|
|
60
|
+
} finally {
|
|
61
|
+
C(!1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
if (u) {
|
|
66
|
+
const t = u;
|
|
67
|
+
return /* @__PURE__ */ n("div", { children: [
|
|
68
|
+
/* @__PURE__ */ e(
|
|
69
|
+
"button",
|
|
70
|
+
{
|
|
71
|
+
type: "button",
|
|
72
|
+
className: "cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",
|
|
73
|
+
onClick: () => g(null),
|
|
74
|
+
style: { marginBottom: "1rem" },
|
|
75
|
+
children: "← Back to disputes"
|
|
76
|
+
}
|
|
77
|
+
),
|
|
78
|
+
/* @__PURE__ */ e("div", { className: "cedros-admin__section-header", children: /* @__PURE__ */ n("h3", { className: "cedros-admin__section-title", children: [
|
|
79
|
+
"Dispute ",
|
|
80
|
+
/* @__PURE__ */ e("code", { style: { fontSize: "0.8rem" }, children: t.id.slice(0, 12) })
|
|
81
|
+
] }) }),
|
|
82
|
+
/* @__PURE__ */ e("div", { className: "cedros-admin__table-container", style: { maxWidth: "500px" }, children: /* @__PURE__ */ e("table", { className: "cedros-admin__table", children: /* @__PURE__ */ n("tbody", { children: [
|
|
83
|
+
/* @__PURE__ */ n("tr", { children: [
|
|
84
|
+
/* @__PURE__ */ e("td", { style: { fontWeight: 600, width: "35%" }, children: "Status" }),
|
|
85
|
+
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ e("span", { className: `cedros-admin__badge cedros-admin__badge--${U(t.status)}`, children: t.status }) })
|
|
86
|
+
] }),
|
|
87
|
+
/* @__PURE__ */ n("tr", { children: [
|
|
88
|
+
/* @__PURE__ */ e("td", { style: { fontWeight: 600 }, children: "Amount" }),
|
|
89
|
+
/* @__PURE__ */ e("td", { children: A(t.amount, t.currency) })
|
|
90
|
+
] }),
|
|
91
|
+
/* @__PURE__ */ n("tr", { children: [
|
|
92
|
+
/* @__PURE__ */ e("td", { style: { fontWeight: 600 }, children: "Source" }),
|
|
93
|
+
/* @__PURE__ */ e("td", { children: t.source })
|
|
94
|
+
] }),
|
|
95
|
+
t.reason && /* @__PURE__ */ n("tr", { children: [
|
|
96
|
+
/* @__PURE__ */ e("td", { style: { fontWeight: 600 }, children: "Reason" }),
|
|
97
|
+
/* @__PURE__ */ e("td", { children: t.reason })
|
|
98
|
+
] }),
|
|
99
|
+
t.orderId && /* @__PURE__ */ n("tr", { children: [
|
|
100
|
+
/* @__PURE__ */ e("td", { style: { fontWeight: 600 }, children: "Order ID" }),
|
|
101
|
+
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ e("code", { children: t.orderId }) })
|
|
102
|
+
] }),
|
|
103
|
+
t.chargeId && /* @__PURE__ */ n("tr", { children: [
|
|
104
|
+
/* @__PURE__ */ e("td", { style: { fontWeight: 600 }, children: "Charge ID" }),
|
|
105
|
+
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ e("code", { children: t.chargeId }) })
|
|
106
|
+
] }),
|
|
107
|
+
t.paymentIntentId && /* @__PURE__ */ n("tr", { children: [
|
|
108
|
+
/* @__PURE__ */ e("td", { style: { fontWeight: 600 }, children: "Payment Intent" }),
|
|
109
|
+
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ e("code", { children: t.paymentIntentId }) })
|
|
110
|
+
] }),
|
|
111
|
+
/* @__PURE__ */ n("tr", { children: [
|
|
112
|
+
/* @__PURE__ */ e("td", { style: { fontWeight: 600 }, children: "Created" }),
|
|
113
|
+
/* @__PURE__ */ e("td", { children: v(t.createdAt) })
|
|
114
|
+
] }),
|
|
115
|
+
t.statusUpdatedAt && /* @__PURE__ */ n("tr", { children: [
|
|
116
|
+
/* @__PURE__ */ e("td", { style: { fontWeight: 600 }, children: "Status Updated" }),
|
|
117
|
+
/* @__PURE__ */ e("td", { children: v(t.statusUpdatedAt) })
|
|
118
|
+
] })
|
|
119
|
+
] }) }) }),
|
|
120
|
+
/* @__PURE__ */ n("div", { style: { marginTop: "1rem", display: "flex", gap: "0.5rem", alignItems: "flex-end", maxWidth: "400px" }, children: [
|
|
121
|
+
/* @__PURE__ */ n("div", { className: "cedros-admin__field", style: { flex: 1 }, children: [
|
|
122
|
+
/* @__PURE__ */ e("label", { className: "cedros-admin__field-label", children: "Update Status" }),
|
|
123
|
+
/* @__PURE__ */ n("select", { className: "cedros-admin__input", value: m, onChange: (s) => I(s.target.value), children: [
|
|
124
|
+
/* @__PURE__ */ e("option", { value: "needs_response", children: "Needs Response" }),
|
|
125
|
+
/* @__PURE__ */ e("option", { value: "under_review", children: "Under Review" }),
|
|
126
|
+
/* @__PURE__ */ e("option", { value: "won", children: "Won" }),
|
|
127
|
+
/* @__PURE__ */ e("option", { value: "lost", children: "Lost" }),
|
|
128
|
+
/* @__PURE__ */ e("option", { value: "warning_closed", children: "Warning Closed" })
|
|
129
|
+
] })
|
|
130
|
+
] }),
|
|
131
|
+
/* @__PURE__ */ e(
|
|
132
|
+
"button",
|
|
133
|
+
{
|
|
134
|
+
type: "button",
|
|
135
|
+
className: "cedros-admin__button cedros-admin__button--primary",
|
|
136
|
+
onClick: F,
|
|
137
|
+
disabled: S || m === t.status,
|
|
138
|
+
children: S ? "Updating..." : "Update"
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
] })
|
|
142
|
+
] });
|
|
143
|
+
}
|
|
144
|
+
return /* @__PURE__ */ n("div", { children: [
|
|
145
|
+
/* @__PURE__ */ e("div", { className: "cedros-admin__section-header", children: /* @__PURE__ */ e("h3", { className: "cedros-admin__section-title", children: "Disputes & Chargebacks" }) }),
|
|
146
|
+
/* @__PURE__ */ e(j, { message: k }),
|
|
147
|
+
/* @__PURE__ */ e("div", { style: { display: "flex", gap: "0.5rem", marginBottom: "1rem", alignItems: "center" }, children: /* @__PURE__ */ n(
|
|
148
|
+
"select",
|
|
149
|
+
{
|
|
150
|
+
className: "cedros-admin__input",
|
|
151
|
+
value: h,
|
|
152
|
+
onChange: (t) => {
|
|
153
|
+
R(t.target.value), f(0);
|
|
154
|
+
},
|
|
155
|
+
style: { width: "auto", fontSize: "0.85rem" },
|
|
156
|
+
children: [
|
|
157
|
+
/* @__PURE__ */ e("option", { value: "all", children: "All statuses" }),
|
|
158
|
+
/* @__PURE__ */ e("option", { value: "needs_response", children: "Needs Response" }),
|
|
159
|
+
/* @__PURE__ */ e("option", { value: "under_review", children: "Under Review" }),
|
|
160
|
+
/* @__PURE__ */ e("option", { value: "won", children: "Won" }),
|
|
161
|
+
/* @__PURE__ */ e("option", { value: "lost", children: "Lost" })
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
) }),
|
|
165
|
+
D ? /* @__PURE__ */ n("div", { className: "cedros-admin__loading", children: [
|
|
166
|
+
B.loading,
|
|
167
|
+
" Loading disputes..."
|
|
168
|
+
] }) : c.length === 0 ? /* @__PURE__ */ e("div", { className: "cedros-admin__empty", children: "No disputes found." }) : /* @__PURE__ */ n(E, { children: [
|
|
169
|
+
/* @__PURE__ */ e("div", { className: "cedros-admin__table-container", children: /* @__PURE__ */ n("table", { className: "cedros-admin__table", children: [
|
|
170
|
+
/* @__PURE__ */ e("thead", { children: /* @__PURE__ */ n("tr", { children: [
|
|
171
|
+
/* @__PURE__ */ e("th", { children: "ID" }),
|
|
172
|
+
/* @__PURE__ */ e("th", { children: "Amount" }),
|
|
173
|
+
/* @__PURE__ */ e("th", { children: "Status" }),
|
|
174
|
+
/* @__PURE__ */ e("th", { children: "Reason" }),
|
|
175
|
+
/* @__PURE__ */ e("th", { children: "Source" }),
|
|
176
|
+
/* @__PURE__ */ e("th", { children: "Created" }),
|
|
177
|
+
/* @__PURE__ */ e("th", {})
|
|
178
|
+
] }) }),
|
|
179
|
+
/* @__PURE__ */ e("tbody", { children: c.map((t) => /* @__PURE__ */ n("tr", { children: [
|
|
180
|
+
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ e("code", { style: { fontSize: "0.75rem" }, children: t.id.slice(0, 12) }) }),
|
|
181
|
+
/* @__PURE__ */ e("td", { children: A(t.amount, t.currency) }),
|
|
182
|
+
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ e("span", { className: `cedros-admin__badge cedros-admin__badge--${U(t.status)}`, children: t.status }) }),
|
|
183
|
+
/* @__PURE__ */ e("td", { children: t.reason ?? "—" }),
|
|
184
|
+
/* @__PURE__ */ e("td", { children: t.source }),
|
|
185
|
+
/* @__PURE__ */ e("td", { children: v(t.createdAt) }),
|
|
186
|
+
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
|
|
187
|
+
"button",
|
|
188
|
+
{
|
|
189
|
+
type: "button",
|
|
190
|
+
className: "cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",
|
|
191
|
+
onClick: () => $(t.id),
|
|
192
|
+
children: "View"
|
|
193
|
+
}
|
|
194
|
+
) })
|
|
195
|
+
] }, t.id)) })
|
|
196
|
+
] }) }),
|
|
197
|
+
/* @__PURE__ */ n("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: "0.75rem", fontSize: "0.85rem" }, children: [
|
|
198
|
+
/* @__PURE__ */ e(
|
|
199
|
+
"button",
|
|
200
|
+
{
|
|
201
|
+
type: "button",
|
|
202
|
+
className: "cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",
|
|
203
|
+
disabled: l === 0,
|
|
204
|
+
onClick: () => f(Math.max(0, l - r)),
|
|
205
|
+
children: "Previous"
|
|
206
|
+
}
|
|
207
|
+
),
|
|
208
|
+
/* @__PURE__ */ n("span", { children: [
|
|
209
|
+
"Showing ",
|
|
210
|
+
c.length,
|
|
211
|
+
" dispute",
|
|
212
|
+
c.length !== 1 ? "s" : ""
|
|
213
|
+
] }),
|
|
214
|
+
/* @__PURE__ */ e(
|
|
215
|
+
"button",
|
|
216
|
+
{
|
|
217
|
+
type: "button",
|
|
218
|
+
className: "cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",
|
|
219
|
+
disabled: c.length < r,
|
|
220
|
+
onClick: () => f(l + r),
|
|
221
|
+
children: "Next"
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
] })
|
|
225
|
+
] })
|
|
226
|
+
] });
|
|
227
|
+
}
|
|
228
|
+
export {
|
|
229
|
+
q as DisputesSection
|
|
230
|
+
};
|