@kodiak-finance/orderly-affiliate 2.8.18 → 2.8.19

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/index.mjs CHANGED
@@ -1,18 +1,4073 @@
1
- import { modal, useModal, SimpleDialog, TextField, inputFormatter, Flex, Text, cn, toast, Dialog, DialogContent, DialogTitle, Divider, Input, Button, Box, Tabs, TabPanel, usePagination, DatePicker, TabsBase, TabsList, TabsTrigger, TabsContent, ListView, Select, CopyIcon, DataTable, Statistic, useScreen, Tooltip, DialogTrigger, DialogHeader, DialogBody } from '@kodiak-finance/orderly-ui';
2
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
- import { Decimal, commify, commifyOptional } from '@kodiak-finance/orderly-utils';
1
+ import { modal, useModal, SimpleDialog, TextField, inputFormatter, Flex, Text, cn, toast, Dialog, DialogContent, DialogTitle, Divider, Input as Input$1, Button, Box, Tabs, TabPanel, usePagination, DatePicker, TabsBase, TabsList, TabsTrigger, TabsContent, ListView, Select, CopyIcon, DataTable, Statistic, useScreen, Tooltip, DialogTrigger, DialogHeader, DialogBody } from '@kodiak-finance/orderly-ui';
4
2
  import { useTranslation, Trans, i18n } from '@kodiak-finance/orderly-i18n';
3
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
5
4
  import { createContext, useState, useEffect, useRef, useContext, useMemo } from 'react';
6
5
  import { subDays, format, toDate } from 'date-fns';
7
6
  import { useMutation, cleanStringStyle, useAccount, usePrivateQuery, noCacheConfig, useDaily, useMemoizedFn, useMediaQuery, useLocalStorage, useReferralRebateSummary, useRefereeRebateSummary, useRefereeInfo, useCheckReferralCode } from '@kodiak-finance/orderly-hooks';
8
7
  import { useAppContext } from '@kodiak-finance/orderly-react-app';
9
8
  import { AccountStatusEnum, EMPTY_LIST } from '@kodiak-finance/orderly-types';
9
+ import { Decimal, commify, commifyOptional } from '@kodiak-finance/orderly-utils';
10
10
  import { VolBarChart } from '@kodiak-finance/orderly-chart';
11
- import { AuthGuardDataTable } from '@kodiak-finance/orderly-ui-connector';
11
+ import { AuthGuardDataTable, useAuthStatus, AuthStatusEnum, AuthGuard } from '@kodiak-finance/orderly-ui-connector';
12
12
  import { Scaffold, SideBar } from '@kodiak-finance/orderly-ui-scaffold';
13
13
 
14
- var gi=Object.defineProperty;var hi=(e,t)=>{for(var r in t)gi(e,r,{get:t[r],enumerable:true});};var si={};hi(si,{AffiliatePage:()=>_e,DashboardPage:()=>li,HomePage:()=>ve,TraderPage:()=>Le});var mt=e=>{let{size:t=16,className:r,...a}=e;return jsxs("svg",{width:t,height:t,viewBox:"0 0 16 16",fill:"#fff",fillOpacity:".98",xmlns:"http://www.w3.org/2000/svg",className:e.className,...a,children:[jsx("path",{d:"M8 1.302c-3.683 0-6.655 2.985-6.667 6.667-.013 3.676 2.987 6.68 6.666 6.687s6.674-3.037 6.667-6.687c-.007-3.682-2.985-6.667-6.667-6.667m0 1.333a5.333 5.333 0 0 1 5.333 5.334c0 1.5-.625 2.852-1.622 3.821-.49-1.062-1.545-1.821-2.753-1.821H7.04c-1.207 0-2.259.75-2.75 1.812A5.3 5.3 0 0 1 2.666 7.97a5.333 5.333 0 0 1 5.333-5.334M8 3.97a2.667 2.667 0 1 0 0 5.333A2.667 2.667 0 0 0 8 3.97"}),jsx("path",{d:"M16 12.667a3.333 3.333 0 1 1-6.667 0 3.333 3.333 0 0 1 6.667 0",fill:"#1828C3"}),jsx("path",{d:"M11.917 11.433a.917.917 0 0 0-.917.917c0 .53.302 1.031.802 1.49a4.6 4.6 0 0 0 .713.53l.068.043c.05.027.117.027.167 0l.068-.042q.08-.05.177-.115c.182-.123.366-.26.536-.416.5-.459.802-.96.802-1.49a.917.917 0 0 0-.917-.917.97.97 0 0 0-.744.386.95.95 0 0 0-.756-.386"})]})};var dt=e=>{let{size:t=16,className:r,...a}=e;return jsxs("svg",{width:t,height:t,viewBox:"0 0 16 16",fill:"white",fillOpacity:"0.36",xmlns:"http://www.w3.org/2000/svg",className:e.className,...a,children:[jsx("path",{d:"M7.99929 1.30212C4.31735 1.30212 1.34509 4.28679 1.33262 7.96878C1.32015 11.6454 4.32042 14.6488 7.99929 14.6561C11.6782 14.6634 14.6726 11.6194 14.666 7.96878C14.6593 4.28679 11.6812 1.30212 7.99929 1.30212ZM7.99929 2.63546C10.9448 2.63546 13.3326 5.02345 13.3326 7.96878C13.3326 9.46878 12.7078 10.8208 11.7112 11.7901C11.2202 10.7281 10.1656 9.96878 8.95762 9.96878C8.71802 9.96878 7.28042 9.96878 7.04095 9.96878C5.83369 9.96878 4.78215 10.7188 4.29095 11.7814C3.29429 10.8121 2.66595 9.46878 2.66595 7.96878C2.66595 5.02345 5.05375 2.63546 7.99929 2.63546ZM7.99929 3.96879C6.52649 3.96879 5.33255 5.16279 5.33262 6.63545C5.33262 8.10812 6.52649 9.30212 7.99929 9.30212C9.47202 9.30212 10.666 8.10812 10.666 6.63545C10.666 5.16279 9.47202 3.96879 7.99929 3.96879Z"}),jsx("path",{d:"M16 12.6667C16 14.5076 14.5076 16 12.6666 16C10.8257 16 9.33331 14.5076 9.33331 12.6667C9.33331 10.8257 10.8257 9.33333 12.6666 9.33333C14.5076 9.33333 16 10.8257 16 12.6667Z",fill:"#005A4F"}),jsx("path",{d:"M14.3325 13.3345C14.3325 13.2918 14.3182 13.2473 14.2857 13.2147L13.6658 12.6002L13.4315 12.8345L13.7595 13.1678H11.3325C11.2405 13.1678 11.1658 13.2425 11.1658 13.3345C11.1658 13.4265 11.2405 13.5012 11.3325 13.5012H13.7595L13.4315 13.8345L13.6658 14.0688L14.2857 13.4543C14.3182 13.4217 14.3325 13.3772 14.3325 13.3345ZM14.1658 12.0012C14.1658 11.9092 14.0912 11.8345 13.9992 11.8345H11.572L11.9002 11.5012L11.6658 11.2668L11.046 11.8813C10.981 11.9465 10.981 12.0558 11.046 12.121L11.6658 12.7355L11.9002 12.5012L11.572 12.1678H13.9992C14.0912 12.1678 14.1658 12.0932 14.1658 12.0012Z",fill:"white",fillOpacity:"0.98"})]})};var J=e=>jsxs("svg",{width:"21",height:"20",viewBox:"0 0 21 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:e.className,children:[jsxs("g",{clipPath:"url(#a)",children:[jsx("path",{d:"M10.5 20c5.542 0 10-4.458 10-10s-4.458-10-10-10S.5 4.458.5 10s4.458 10 10 10",fill:"#2775CA"}),jsx("path",{d:"M13.5 11.473c0-1.452-.94-1.95-2.82-2.158-1.344-.166-1.613-.498-1.613-1.078s.448-.955 1.343-.955c.806 0 1.254.25 1.478.872.045.124.18.207.313.207h.717c.179 0 .313-.125.313-.29v-.042c-.179-.913-.985-1.618-2.015-1.701v-.996c0-.166-.134-.29-.358-.332h-.671c-.18 0-.314.124-.359.332v.954c-1.343.166-2.194.996-2.194 2.034 0 1.369.896 1.908 2.776 2.116 1.254.207 1.657.456 1.657 1.12s-.627 1.12-1.477 1.12c-1.165 0-1.568-.456-1.702-1.078a.32.32 0 0 0-.313-.25h-.762c-.179 0-.313.125-.313.291v.042c.179 1.037.895 1.784 2.373 1.991v.996c0 .166.134.29.358.332h.672c.18 0 .313-.124.358-.332v-.996c1.344-.207 2.239-1.079 2.239-2.199",fill:"#fff",fillOpacity:".98"}),jsx("path",{d:"M8.24 16.57c-3.458-1.215-5.23-4.986-3.945-8.324.665-1.821 2.127-3.208 3.944-3.859.178-.086.266-.216.266-.433v-.607c0-.174-.088-.304-.266-.347-.044 0-.133 0-.177.043-4.21 1.3-6.516 5.68-5.186 9.798.798 2.428 2.704 4.292 5.186 5.072.177.087.355 0 .4-.173.043-.043.043-.087.043-.173v-.608c0-.13-.133-.303-.266-.39m4.698-13.527c-.178-.086-.355 0-.4.174-.043.043-.043.086-.043.173v.607c0 .174.133.347.266.434 3.457 1.213 5.23 4.985 3.944 8.323-.664 1.821-2.127 3.209-3.944 3.859-.178.086-.266.216-.266.433v.607c0 .174.088.304.266.347.044 0 .133 0 .177-.043 4.21-1.3 6.515-5.68 5.186-9.798-.798-2.471-2.748-4.335-5.186-5.116",fill:"#fff",fillOpacity:".98"})]}),jsx("defs",{children:jsx("clipPath",{id:"a",children:jsx("path",{fill:"#fff",d:"M.5 0h20v20H.5z"})})})]});var gt=e=>{let{t}=useTranslation();return jsxs(Flex,{id:"oui-affiliate-affiliate-summary",r:"2xl",p:6,width:"100%",height:"100%",gap:4,direction:"column",className:"oui-bg-base-9",children:[jsx(yi,{...e}),jsx(vi,{...e}),jsxs(Flex,{direction:"column",width:"100%",gap:2,children:[jsx(xt,{title:`${t("affiliate.referralVol")} (USDC)`,value:e.referralVol,dp:2,...e}),jsx(xt,{title:t("affiliate.referees"),value:e.referees,dp:0,...e}),jsx(xt,{title:t("affiliate.summary.refereesTraded"),value:e.refereesTades,dp:0,...e})]})]})},yi=e=>{let{t}=useTranslation();return jsxs(Flex,{direction:"row",justify:"between",width:"100%",children:[jsx(Text,{className:"oui-text-lg",children:t("affiliate.summary")}),jsx("div",{className:"oui-min-w-14",children:jsx(Select.options,{size:"xs",value:e.period,onValueChange:e.onPeriodChange,options:e.periodTypes})})]})},vi=e=>{let{t}=useTranslation();return jsxs(Flex,{gradient:"primary",angle:180,r:"xl",py:4,px:6,width:"100%",direction:"column",gap:3,height:"100%",className:"oui-max-h-[104px]",children:[jsx(Text,{intensity:54,className:"oui-text-base 2xl:oui-text-lg",children:`${t("affiliate.commission")} (USDC)`}),jsxs(Flex,{direction:"row",gap:3,className:"oui-text-xl md:oui-text-2xl xl:oui-text-3xl",children:[jsx(J,{className:"md:oui-w-[24px] md:oui-h-[24px] lg:oui-w-[28px] lg:oui-h-[28px] "}),jsx(Text,{children:commifyOptional(e.commission,{fix:2,fallback:"0"})})]})]})},xt=e=>jsxs(Flex,{direction:"row",justify:"between",width:"100%",children:[jsx(Text,{intensity:54,className:"oui-text-2xs md:oui-text-xs xl:oui-text-sm",children:e.title}),jsx(Text,{className:"oui-text-xs md:oui-text-sm xl:oui-text-base",children:commifyOptional(e.value,{fix:e.dp,fallback:"0"})})]});var Ne=(r=>(r.affiliate="affiliate",r.trader="trader",r))(Ne||{}),Vr=createContext({}),Ss=e=>{let{becomeAnAffiliateUrl:t="https://orderly.network/",learnAffiliateUrl:r="https://orderly.network/",referralLinkUrl:a="https://orderly.network/",chartConfig:o,overwrite:n,children:i,splashPage:f,onBecomeAnAffiliate:s,bindReferralCodeState:x,onLearnAffiliate:m,showReferralPage:u}=e,{state:l}=useAccount(),{data:d,mutate:p,isLoading:c}=usePrivateQuery("/v1/referral/info",{revalidateOnFocus:true,errorRetryCount:3,...noCacheConfig}),{data:C,mutate:k}=usePrivateQuery("/v1/referral/auto_referral/progress",{revalidateOnFocus:true,errorRetryCount:2,formatter:O=>({code:O.auto_referral_code,requireVolume:O.required_volume,completedVolume:O.completed_volume})}),[ne,U]=useState(c);useEffect(()=>{U(true);},[c]);let{data:I,mutate:_}=useDaily({startDate:subDays(new Date,1),endDate:subDays(new Date,90)}),{data:A,mutate:B}=usePrivateQuery("/v1/volume/user/stats",{revalidateOnFocus:true}),ce=useMemo(()=>(d?.referrer_info?.referral_codes?.length||0)>0,[d?.referrer_info]),H=useMemo(()=>(d?.referee_info?.referer_code?.length||0)>0,[d?.referee_info]),K=useMemo(()=>{let O={};if(I&&I.length>0){let Be=format(new Date,"yyyy-MM-dd"),_r=I.findIndex(pi=>pi.date===Be),Mr=0;_r!==-1&&(Mr=I[_r].perp_volume),O["1d_volume"]=Mr;}return A&&(O["7d_volume"]=A.perp_volume_last_7_days,O["30d_volume"]=A.perp_volume_last_30_days,O.all_volume=A.perp_volume_ltd),O},[I,A]);useEffect(()=>{(ce||H)&&U(false);},[ce,H]);let Ie=useMemoizedFn(()=>{B(),_(),p(),k();});useEffect(()=>{let Be=new URLSearchParams(window.location.search).get("ref");Be&&localStorage.setItem("referral_code",Be);},[]);let[Nr,di]=useState("affiliate"),{wrongNetwork:Ar,disabledConnect:Dr}=useAppContext(),Fr=useRef(AccountStatusEnum.NotConnected),ft=useRef(null);useEffect(()=>(Fr.current!==l.status&&(Fr.current=l.status,ft.current=setTimeout(()=>{Ie();},1e3)),()=>{ft.current&&clearTimeout(ft.current);}),[Ie,l.status]);let xi=useMemo(()=>({generateCode:C,showHome:ne,referralInfo:d,isAffiliate:ce,isTrader:H,tab:Nr,becomeAnAffiliateUrl:t,learnAffiliateUrl:r,referralLinkUrl:a,userVolume:K,dailyVolume:I,chartConfig:o,overwrite:n,isLoading:c,wrongNetwork:Ar,disabledConnect:Dr,setShowHome:U,setTab:di,mutate:Ie,onBecomeAnAffiliate:s,bindReferralCodeState:x,onLearnAffiliate:m,showReferralPage:u,splashPage:f}),[t,o,I,d,Dr,C,ce,c,H,r,n,a,ne,Nr,K,Ar,s,x,m,u,f,Ie]);return jsx(Vr.Provider,{value:xi,children:i})},y=()=>useContext(Vr);var bt=()=>{let{t:e}=useTranslation(),[t,r]=useState("All"),a=[{label:e("common.all"),value:"All"},{label:e("common.select.1d"),value:"1D"},{label:e("common.select.7d"),value:"7D"},{label:e("common.select.30d"),value:"30D"}],{referralInfo:o}=y(),n=useMemo(()=>{if(!o||!o.referrer_info)return 0;switch(t){case "All":return o.referrer_info.total_referrer_rebate;case "1D":return o.referrer_info["1d_referrer_rebate"];case "7D":return o.referrer_info["7d_referrer_rebate"];case "30D":return o.referrer_info["30d_referrer_rebate"]}},[o,t]),i=useMemo(()=>{if(!o||!o.referrer_info)return 0;switch(t){case "All":return o.referrer_info.total_referee_volume;case "1D":return o.referrer_info["1d_referee_volume"];case "7D":return o.referrer_info["7d_referee_volume"];case "30D":return o.referrer_info["30d_referee_volume"]}},[o,t]),f=useMemo(()=>{if(!o||!o.referrer_info)return 0;switch(t){case "All":return o.referrer_info.total_invites;case "1D":return o.referrer_info["1d_invites"];case "7D":return o.referrer_info["7d_invites"];case "30D":return o.referrer_info["30d_invites"]}},[o,t]),s=useMemo(()=>{if(!o||!o.referrer_info)return 0;switch(t){case "All":return o.referrer_info.total_traded;case "1D":return o.referrer_info["1d_traded"];case "7D":return o.referrer_info["7d_traded"];case "30D":return o.referrer_info["30d_traded"]}},[o,t]);return {period:t,periodTypes:a,onPeriodChange:m=>{r(m);},commission:n,referralVol:i,referees:f,refereesTades:s}};var Ee=()=>{let e=bt();return jsx(gt,{...e})};var Or=e=>{let{text:t,visibleCount:r}=e,a=useRef(null),o=useRef(null),n=useRef(void 0);function i(m,u){let d=document.createElement("canvas").getContext("2d"),p=m;if(d&&p){let c=getComputedStyle(p).font;return c.length===0&&(c=[getComputedStyle(p).fontWeight,getComputedStyle(p).fontSize,getComputedStyle(p).fontFamily].join(" ")),d.font=c,d.letterSpacing=getComputedStyle(p).letterSpacing,d.measureText(u).width}}let[f,s]=useState(0);useEffect(()=>{let m=()=>{if(e.visibleCount===void 0&&a.current&&o.current){let u=a.current.clientWidth;if(u==n.current)return;n.current=u;let l=o.current,d=t,p=Math.ceil(i(l,"...")||0),c=u-p,C=0;for(;C<t.length&&!((i(l,Oi(t,C++))||c)<=c););s(d.length-C);}};return n.current=void 0,m(),window.addEventListener("resize",m),()=>{n.current=void 0,window.removeEventListener("resize",m);}},[t,o]);let x=useMemo(()=>{if(f+1>=t.length)return t;let m=r||f,u=t.slice(0,Math.ceil(m/2)),l=t.slice(t.length-Math.floor(m/2),t.length);return `${u}...${l}`},[t,r,f]);return jsxs("div",{ref:a,className:cn("oui-relative oui-w-full oui-text-end",e.className),children:[jsx("div",{className:cn("oui-hidden oui-whitespace-nowrap oui-absolute oui-top-0 oui-bottom-0 oui-right-0 oui-left-0"),children:jsx("span",{ref:o,children:t})}),jsx("span",{children:x})]})},Oi=(e,t)=>{let r=Math.floor(e.length/2-(t>0?t/2:1)),a=e.slice(0,r),o=e.slice(r+t);return a+o};var vt=e=>{let{t}=useTranslation();return jsxs(Flex,{id:"oui-affiliate-affiliate-referralLink",r:"2xl",p:6,width:"100%",gap:4,direction:"column",className:"oui-bg-base-9",children:[jsx(qi,{...e}),jsxs(Flex,{width:"100%",className:"oui-flex oui-flex-col 3xl:oui-flex-row",gap:4,children:[jsx("div",{className:"oui-w-full 3xl:oui-w-1/3",children:jsx(Zi,{...e})}),jsxs(Flex,{direction:"column",width:"100%",className:"3xl:oui-w-2/3 3xl:oui-gap-2",children:[jsx(Er,{title:t("affiliate.referralCode"),value:e.refCode,...e}),jsx(Er,{title:t("affiliate.referralLink"),value:e.refLink,...e})]})]})]})},qi=e=>{let{t}=useTranslation();return jsx(Flex,{direction:"row",justify:"between",width:"100%",children:jsx(Text,{className:"oui-text-lg",children:t("affiliate.referralLink")})})},Zi=e=>{let{t}=useTranslation(),r=(a,o,n,i,f)=>{let s="oui-text-lg md:oui-text-xl lg:oui-text-2xl xl:oui-text-3xl";return jsxs(Flex,{direction:"column",itemAlign:"start",className:i,children:[jsx(Flex,{direction:"row",gap:2,children:jsx(Qi,{title:a,tooltip:f})}),n?jsx(Text.gradient,{color:"brand",className:s,children:o}):jsx(Text,{className:s,children:o})]})};return jsxs(Flex,{direction:"row",width:"100%",children:[r(t("affiliate.referralLink.earn"),e.earn||"-",true,"oui-flex-1",jsxs("span",{children:[jsx(Text.gradient,{color:"brand",children:e.earn||"-"})," ",t("affiliate.referralLink.earn.tooltip",{brokerName:e.brokerName})]})),r(t("affiliate.referralLink.share"),e.share||"-",false,"oui-flex-1",jsx(Trans,{i18nKey:"affiliate.referralLink.share.tooltip",values:{value:e.share||"-",brokerName:e.brokerName},components:[jsx(Text.gradient,{color:"brand"})]}))]})},Er=e=>{let{title:t,value:r="-"}=e;return jsxs(Flex,{r:"xl",p:3,gap:4,direction:"row",width:"100%",className:"oui-bg-base-8",children:[jsx(Text,{className:"oui-text-base-contrast-54 oui-flex-shrink oui-text-2xs md:oui-text-xs xl:oui-text-sm",children:t}),jsxs(Flex,{direction:"row",justify:"end",gap:2,className:"oui-flex-1 oui-text-xs md:oui-text-sm xl:oui-text-base",children:[jsx(Or,{text:r}),jsx("button",{className:"oui-cursor-pointer oui-text-sm oui-flex-shrink",onClick:()=>{navigator.clipboard.writeText(r),e.onCopy?.(r);},children:jsx(CopyIcon,{size:12,color:"white",className:"oui-w-[13px] oui-h-[13px] md:oui-w-[14px] md:oui-h-[14px] xl:oui-w-4 xl:oui-h-4"})})]})]})},Qi=e=>jsx(Tooltip,{content:e.tooltip,className:"oui-max-w-[200px]",children:jsx("div",{onClick:()=>{modal.alert({title:e.title,message:jsx("div",{className:"oui-text-base-contrast/30 oui-space-y-3 oui-text-xs desktop:oui-text-xs",children:e.tooltip})});},children:jsxs(Flex,{direction:"column",children:[jsx(Text,{intensity:54,className:"oui-text-2xs md:oui-text-xs xl:oui-text-sm",children:e.title}),jsx(Divider,{className:"oui-w-full",lineStyle:"dotted",intensity:16})]})})});function ze(e,t,r){try{let a=new URL(e),o=new URLSearchParams(a.search);return o.set(t,r),a.search=o.toString(),a.toString()}catch{return e}}async function Rt(e){try{await navigator.clipboard.writeText(e),toast.success(i18n.t("common.copy.copied"));}catch{toast.success(i18n.t("common.copy.failed"));}}function Gr(e){if(e===void 0)return "";let t=toDate(e),r=Qr(t);return format(r,"yyyy-MM-dd HH:mm:ss 'UTC'")}function qr(e){if(e===void 0)return;let t=toDate(e),r=Qr(t);return format(r,"yyyy-MM-dd")}function Zr(e,t){return e&&t&&e.toISOString().substring(0,10)===t.toISOString().substring(0,10)}function Qr(e){return new Date(e.toUTCString())}var Tt=()=>{let{t:e}=useTranslation(),t=d=>{toast.success(e("common.copy.copied"));},{referralInfo:r,referralLinkUrl:a,overwrite:o}=y(),[n,i]=useLocalStorage("orderly_referral_codes",[]),f=useMemo(()=>{if(!r?.referrer_info?.referral_codes)return [];let d=[...r?.referrer_info?.referral_codes],p=[];for(let c=0;c<n.length;c++){let C=n[c],k=d.findIndex(ne=>ne.code===C);k!==-1&&(p.push({...d[k]}),d.splice(k,1));}return [...p,...d]},[r?.referrer_info?.referral_codes,n]),s=useMemo(()=>{if(f.length!==0)return f[0]},[f]),x=useMemo(()=>s?.code,[s]),m=useMemo(()=>s?ze(a,"ref",s.code):"",[s]),u=useMemo(()=>`${new Decimal(s?.referrer_rebate_rate||"0").mul(100).toDecimalPlaces(0,Decimal.ROUND_DOWN).toString()}%`,[s?.referrer_rebate_rate]),l=useMemo(()=>`${new Decimal(s?.referee_rebate_rate||"0").mul(100).toDecimalPlaces(0,Decimal.ROUND_DOWN).toString()}%`,[s?.referee_rebate_rate]);return {onCopy:t,refLink:m,refCode:x,share:l,earn:u,brokerName:o?.brokerName??o?.shortBrokerName}};var He=()=>{let e=Tt();return jsx(vt,{...e})};var Nt=e=>jsxs(Flex,{id:"oui-affiliate-affiliate-titleStatistic",r:"2xl",p:6,width:"100%",gap:4,direction:"column",className:"oui-bg-base-9",children:[jsx(ia,{...e}),jsx(Flex,{className:"oui-h-[170px] 2xl:oui-h-[196px] oui-w-full oui-flex oui-flex-row oui-items-stretch",children:jsx(VolBarChart,{data:e.dataSource||EMPTY_LIST,colors:{fill:"rgba(0, 180, 158, 1)"},className:"oui-w-full oui-flex-1",tooltip:{rm:Decimal.ROUND_DOWN,dp:e.volType==="Commission"?6:2}})})]}),ia=e=>{let{t}=useTranslation();return jsxs(Flex,{direction:"row",justify:"between",width:"100%",children:[jsx(Text,{className:"oui-text-lg",children:t("affiliate.statistics")}),jsxs(Flex,{direction:"row",gap:2,className:"oui-min-w-14",children:[jsx(Select.options,{size:"xs",value:e.period,onValueChange:e.onPeriodChange,options:e.periodTypes}),jsx(Select.options,{size:"xs",value:e.volType,onValueChange:e.onVolTypeChange,options:e.volTypes})]})]})};function Ge(e,t){let r=Date(),a=new Array(e).fill(0).map((n,i)=>({date:format(subDays(r,i+1),"yyyy-MM-dd"),volume:0,opacity:0})).reverse(),o=t?.reduce((n,i)=>(n[i.date]=i,n),{});for(let n=0;n<a.length;n++){let i=a[n],f=o?.[i.date];f&&(a[n]={...f,opacity:f.volume>0?1:0});}return a}var At=()=>{let{t:e}=useTranslation(),[t,r]=useState("7"),a=[{label:e("common.select.7d"),value:"7"},{label:e("common.select.30d"),value:"30"},{label:e("common.select.90d"),value:"90"}],o=l=>{r(l);},[n,i]=useState("Commission"),f=[{label:e("affiliate.commission"),value:"Commission"},{label:e("affiliate.referralVol"),value:"ref"}],s=l=>{i(l);},x=useMemo(()=>t==="7"?{startDate:subDays(new Date,7),endDate:subDays(new Date,1)}:t==="30"?{startDate:subDays(new Date,30),endDate:subDays(new Date,1)}:t==="90"?{startDate:subDays(new Date,90),endDate:subDays(new Date,1)}:{startDate:subDays(new Date,7),endDate:subDays(new Date,1)},[t]),[m]=useReferralRebateSummary({startDate:format(x.startDate,"yyyy-MM-dd"),endDate:format(x.endDate,"yyyy-MM-dd"),size:Number(t)}),u=useMemo(()=>(m?.map(l=>({date:l.date,volume:n==="Commission"?l.referral_rebate:l.volume}))||[]).reverse(),[m,n]);return {period:t,periodTypes:a,onPeriodChange:o,volType:n,volTypes:f,onVolTypeChange:s,dataSource:Ge(Number(t),u)}};var qe=()=>{let e=At();return jsx(Nt,{...e})};var Ae=e=>{let{className:t,...r}=e;return jsx("svg",{width:"12",height:"13",viewBox:"0 0 12 13",xmlns:"http://www.w3.org/2000/svg",fill:"white",fillOpacity:"0.36",className:t,...r,children:jsx("path",{d:"M8.49773 1.47656C8.36523 1.47656 8.23223 1.52357 8.13823 1.61707C7.86023 1.89507 6.85973 2.89558 6.63773 3.11808L2.13523 7.62059L1.63473 8.12059C1.56523 8.19059 1.52923 8.28958 1.50973 8.38658L1.00973 10.8881C0.939727 11.2381 1.23773 11.5361 1.58773 11.4666C1.90073 11.4036 3.77673 11.0286 4.08923 10.9661C4.18623 10.9466 4.28523 10.9106 4.35523 10.8411L4.85523 10.3406L9.35773 5.83808C9.58023 5.61608 10.5807 4.61506 10.8587 4.33756C10.9522 4.24356 10.9992 4.11056 10.9992 3.97806C10.9992 3.15956 10.7907 2.57456 10.3582 2.13306C9.92173 1.68756 9.33873 1.47656 8.49773 1.47656ZM8.69473 2.48606C9.14623 2.51256 9.43873 2.61608 9.63923 2.82108C9.84423 3.03008 9.97373 3.32008 10.0017 3.76258C9.72773 4.03608 9.32673 4.43106 8.99823 4.75956C8.60173 4.36306 8.11273 3.87407 7.71623 3.47757C8.04523 3.14907 8.42123 2.75956 8.69473 2.48606ZM6.99723 4.19657L8.27923 5.47858L4.49573 9.26207L3.21373 7.98009L6.99723 4.19657ZM2.49473 8.69908L3.77673 9.98107L3.72973 10.0281C3.39973 10.0941 2.73323 10.2336 2.11923 10.3566L2.44773 8.74608L2.49473 8.69908Z"})})};var to=e=>jsx("button",{children:jsx(Ae,{className:" oui-mt-px oui-cursor-pointer oui-fill-base-contrast-36 hover:oui-fill-base-contrast-80",fillOpacity:1,fill:"currentColor",onClick:e.onClick})});var Dt=e=>jsx("button",{onClick:t=>{e?.onClick?.(!e.pinned);},children:e.pinned===false?jsx(ma,{size:e.size,fillOpacity:1,className:"orderly-fill-primary-darken hover:orderly-fill-primary-darken/80"}):jsx(ua,{size:e.size,fillOpacity:1,className:"orderly-fill-base-contrast-36 hover:orderly-fill-base-contrast"})}),ua=e=>{let{size:t=12}=e;return jsx("svg",{width:t,height:t,viewBox:"0 0 16 16",fill:"#608CFF",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M10.008 1.302a.74.74 0 0 0-.486.215c-1.033.988-1.349 1.815-.972 2.947-.88.675-1.437.841-2.536.841-1.503 0-2.484.181-3.152.848v.021a1.583 1.583 0 0 0 0 2.249l1.867 1.881-3.181 3.18c-.26.26-.28.696-.02.956.261.26.699.26.959 0l3.193-3.193 1.87 1.86a1.585 1.585 0 0 0 2.25 0h.02c.668-.667.854-1.522.854-3.144 0-1.03.212-1.758.853-2.523 1.232.361 1.95.015 2.96-.995a.68.68 0 0 0 .188-.479c0-.234-.06-.594-.209-1.041a5.34 5.34 0 0 0-1.312-2.103A5.35 5.35 0 0 0 11.05 1.51c-.448-.149-.808-.208-1.042-.208"})})},ma=e=>{let{size:t=12}=e;return jsx("svg",{width:t,height:t,viewBox:"0 0 16 16",fill:"#fff",fillOpacity:".36",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M10.008 1.302a.74.74 0 0 0-.486.215c-1.033.988-1.349 1.815-.972 2.947-.88.675-1.437.841-2.536.841-1.503 0-2.484.181-3.152.848v.021a1.583 1.583 0 0 0 0 2.249l1.867 1.881-3.181 3.18c-.26.26-.28.696-.02.956.261.26.699.26.959 0l3.193-3.193 1.87 1.86a1.585 1.585 0 0 0 2.25 0h.02c.668-.667.854-1.522.854-3.144 0-1.03.212-1.758.853-2.523 1.232.361 1.95.015 2.96-.995a.68.68 0 0 0 .188-.479c0-.234-.06-.594-.209-1.041a5.34 5.34 0 0 0-1.312-2.103A5.35 5.35 0 0 0 11.05 1.51c-.448-.149-.808-.208-1.042-.208m.258 1.37c.708.131 1.421.6 1.93 1.108.507.507.94 1.13 1.119 1.944-.636.61-1.026.659-1.662.324a.67.67 0 0 0-.779.116c-1.214 1.213-1.533 2.314-1.533 3.8 0 1.293-.076 1.774-.48 2.207-.113.123-.27.104-.374 0L3.799 7.486a.24.24 0 0 1-.017-.34c.239-.29.769-.514 2.226-.514 1.742.001 2.668-.447 3.812-1.52a.67.67 0 0 0 .125-.77c-.343-.685-.29-1.046.321-1.67"})})};var _t=e=>{let t=useMediaQuery("(max-width: 767px)");return jsxs(Flex,{r:"2xl",p:6,width:"100%",gap:4,direction:"column",className:"oui-h-full oui-bg-base-9 oui-p-6 oui-tabular-nums",children:[jsx(ba,{...e}),jsxs("div",{className:"oui-flex oui-w-full oui-flex-col 2xl:oui-h-full",children:[jsx(Divider,{}),t?jsx(Ca,{...e}):jsx(ya,{...e})]})]})},ba=e=>{let{t}=useTranslation();return jsxs(Flex,{direction:"row",justify:"between",width:"100%",children:[jsx(Text,{className:"oui-text-lg",children:t("affiliate.referralCodes")}),jsxs("div",{className:"oui-text-2xs md:oui-text-xs xl:oui-text-sm",children:[jsx(Text,{className:"oui-text-base-contrast-54",children:`${t("affiliate.referralCodes.remaining")}: `}),jsx(Text,{className:"oui-text-primary-light",children:e.codes?.length||"--"})]})]})},Ca=e=>jsx(ListView,{dataSource:e.codes,className:"oui-max-h-[240px] oui-w-full",renderItem:(t,r)=>jsxs(Flex,{direction:"column",children:[jsx(wa,{data:t,editRate:e.editRate,copyLink:e.copyLink,copyCode:e.copyCode,setPinCode:e.setPinCode,editCode:e.editCode},r),jsx(Divider,{className:"oui-mt-3 oui-w-full"})]})}),De=e=>{let{title:t,copyable:r,value:a,align:o,className:n,editRate:i,onCopy:f}=e;return jsx(Statistic,{id:"oui-affiliate-affiliate-referralCodes",className:cn("oui-flex-1",n),label:jsx(Text,{className:"oui-text-2xs oui-text-base-contrast-36",children:t}),align:o,children:jsxs(Flex,{direction:"row",gap:1,children:[jsx(Text.formatted,{copyable:r,onCopy:()=>{f?.();},className:"oui-mt-[6px] oui-text-sm oui-text-base-contrast-80",children:a}),i&&jsx(Ae,{className:"oui-mt-px oui-cursor-pointer oui-fill-white/[.36] hover:oui-fill-white/80",fillOpacity:1,fill:"currentColor",onClick:()=>i()})]})})},wa=e=>{let{data:t,setPinCode:r,copyLink:a,editRate:o,editCode:n}=e,{t:i}=useTranslation();return jsxs(Flex,{gap:3,direction:"column",className:"oui-w-full",children:[jsxs(Flex,{direction:"row",justify:"between",itemAlign:"stretch",width:"100%",children:[jsx(De,{title:i("affiliate.referralCode"),value:t.code,copyable:true,onCopy:()=>{e.copyCode?.(t.code);},editRate:()=>{n(t);}}),jsx(De,{title:i("affiliate.referralCodes.column.you&Referee"),value:ao(t),align:"end",editRate:()=>{o(t);}}),jsx(De,{title:i("affiliate.referralCodes.column.referees&Traders"),value:Ce(t),align:"end",className:"oui-hidden md:oui-flex"})]}),jsxs(Flex,{direction:"row",justify:"between",itemAlign:"stretch",width:"100%",className:"md:oui-hidden",children:[jsx(De,{title:i("affiliate.referees"),value:Ce(t).split("/")?.[0],align:"start"}),jsx(De,{title:i("affiliate.referralCodes.column.traders"),value:Ce(t).split("/")?.[1],align:"end"})]}),jsxs(Flex,{direction:"row",justify:"between",itemAlign:"stretch",width:"100%",children:[jsx(Dt,{pinned:t.isPined||false,onClick:f=>{r(t.code,!f);}}),jsx(Button,{variant:"outlined",size:"xs",className:"oui-px-[20px]",onClick:f=>{a(t.code);},children:i("affiliate.referralCodes.copyLink")})]})]},t.code)},ya=e=>{let{t}=useTranslation(),r=useMediaQuery("(min-width: 1024px)"),a=useMemo(()=>{let o=[{title:t("affiliate.referralCode"),dataIndex:"code",width:r?115:120,className:"!oui-px-0",render:(n,i)=>jsxs(Flex,{direction:"row",itemAlign:"center",gap:1,children:[jsx(Dt,{size:12,pinned:i.isPined||false,onClick:f=>{e.setPinCode(i.code,!f);}}),jsx(Text.formatted,{suffix:jsxs(Fragment,{children:[i.isAutoGenerated&&i.total_invites<1&&jsx(to,{onClick:()=>e.editCode?.(i)}),jsx(CopyIcon,{className:"oui-cursor-pointer",size:12,color:"white",onClick:()=>e.copyCode?.(i.code)})]}),copyable:true,onCopy:()=>{e.copyCode?.(i.code);},children:n})]})},{title:t("affiliate.referralCodes.column.you&Referee"),dataIndex:"dffd",width:120,className:"oui-pr-0",render:(n,i)=>jsxs(Flex,{direction:"row",itemAlign:"center",gap:1,children:[ao(i),jsx(Ae,{className:"oui-mt-[6px] oui-cursor-pointer oui-fill-white/[.36] hover:oui-fill-white/80",fillOpacity:1,fill:"currentColor",onClick:f=>e.editRate?.(i)})]})}];return r?(o.push({title:t("affiliate.referees"),dataIndex:"referee_rebate_rate",width:65,className:"oui-pr-0",render:(n,i)=>Ce(i).split("/")[0]}),o.push({title:t("affiliate.referralCodes.column.traders"),dataIndex:"referrer_rebate_rate",width:65,className:"oui-pr-0",render:(n,i)=>Ce(i).split("/")[1]})):o.push({title:t("affiliate.referralCodes.column.referees&Traders"),dataIndex:"total_invites/total_traded",width:120,fixed:"left",render:(n,i)=>Ce(i)}),o.push({dataIndex:"link",align:"right",width:74,className:"!oui-px-0",render:(n,i)=>jsx(Button,{variant:"outlined",size:"sm",className:"oui-px-5",onClick:f=>{e?.copyLink?.(i.code);},children:t("affiliate.referralCodes.copyLink")})}),o},[r,t]);return jsx(DataTable,{bordered:true,columns:a,dataSource:e.codes,classNames:{header:"oui-px-0",root:"2xl:oui-flex-1 2xl:oui-max-h-[230px] 3xl:oui-max-h-[300px]"},onRow:o=>({className:"oui-h-[45px]"})})},ao=e=>{let t=new Decimal(e.referee_rebate_rate).mul(100).toFixed(1,Decimal.ROUND_DOWN).toString();return `${new Decimal(e.referrer_rebate_rate).mul(100).toFixed(1,Decimal.ROUND_DOWN).toString()}% / ${t}%`},Ce=e=>`${e.total_invites} / ${e.total_traded}`;var xo=modal.create(e=>{let{t}=useTranslation(),{visible:r,onOpenChange:a}=useModal(),[o,n]=useState(""),[i,f]=useState({length:false,format:false}),[s,{error:x,isMutating:m}]=useMutation("/v1/referral/edit_referral_code","POST");return useEffect(()=>{n(e.code.code);},[e.code]),useEffect(()=>{let u=o.toUpperCase(),l={length:false,format:false};(u.length<4||u.length>10)&&(l.length=true),/^[A-Z0-9]+$/.test(u)||(l.format=true),f(l);},[o]),jsxs(SimpleDialog,{classNames:{content:"oui-max-w-[360px]"},title:jsx("div",{children:t("affiliate.referralCode.editCodeModal.title")}),open:r,onOpenChange:a,actions:{primary:{loading:m,disabled:i.length||i.format,label:t("common.confirm"),onClick:async()=>{try{let u=await s({current_referral_code:e.code.code,new_referral_code:o.toUpperCase()});if(u.success){toast.success(t("affiliate.referralCode.editCodeModal.success")),e.successCallback(),a(!1);return}toast.error(u.message);}catch{}}}},children:[jsx("div",{className:"oui-mb-6 oui-text-xs oui-text-base-contrast-54",children:t("affiliate.referralCode.editCodeModal.description")}),jsx(TextField,{placeholder:"",fullWidth:true,label:t("affiliate.referralCode.editCodeModal.label"),onClean:()=>{n("");},value:o,onChange:u=>{let l=u.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"");n(l);},formatters:[inputFormatter.createRegexInputFormatter(u=>String(u).replace(/[a-z]/g,l=>l.toUpperCase())),inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)],classNames:{label:"oui-text-base-contrast-54 oui-text-xs",input:"placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm"},maxLength:10,minLength:4,autoComplete:"off",helpText:""}),jsxs(Flex,{direction:"column",justify:"center",itemAlign:"start",gap:1,className:"oui-mt-3",children:[jsx(Text,{className:cn("oui-ml-4 oui-list-item oui-list-outside oui-list-disc oui-text-xs oui-text-base-contrast-36 marker:oui-text-3xs",i.length?"oui-text-danger":"oui-text-success"),children:t("affiliate.referralCode.editCodeModal.helpText.length")}),jsx(Text,{className:cn("oui-ml-4 oui-list-item oui-list-outside oui-list-disc oui-text-xs oui-text-base-contrast-36 marker:oui-text-3xs","oui-text-success"),children:t("affiliate.referralCode.editCodeModal.helpText.format")})]})]})});var wo=modal.create(e=>{let{code:t,mutate:r}=e,{visible:a,hide:o,resolve:n,reject:i,onOpenChange:f}=useModal(),s=new Decimal(t.max_rebate_rate).mul(100),[x,m]=useState(`${new Decimal(t.referee_rebate_rate).mul(100)}`),[u,l]=useState(`${new Decimal(t.referrer_rebate_rate).mul(100)}`),[d,p]=useState(false),c=useRef(null),{t:C}=useTranslation();useEffect(()=>{c?.current&&(c.current.focus(),c.current.setSelectionRange(c.current.value.length,c.current.value.length));},[c]),useEffect(()=>{m(`${new Decimal(t.referee_rebate_rate).mul(100)}`),l(`${new Decimal(t.referrer_rebate_rate).mul(100)}`);},[t]);let[k,{error:ne,isMutating:U}]=useMutation("/v1/referral/edit_split","POST"),I=async()=>{try{let _=Number.parseFloat(x),A=Number.parseFloat(u);await k({referral_code:t.code,referee_rebate_rate:_/100,referrer_rebate_rate:A/100}),toast.success(C("affiliate.referralRate.editRateModal.success")),r(),o();}catch(_){toast.error(_?.message||_||"");}};return jsx(Dialog,{open:a,onOpenChange:f,children:jsxs(DialogContent,{className:"oui-px-6 oui-max-w-[320px] oui-bg-base-8 oui-shadow-[0px_12px_20px_0px_rgba(0,0,0,0.25)]",closable:true,children:[jsxs(DialogTitle,{children:[jsx("div",{className:"oui-my-3",children:C("affiliate.referralRate.editRateModal.title")}),jsx(Divider,{})]}),jsxs("div",{className:"oui-mt-3 oui-h-full oui-flex oui-flex-col oui-justify-end",children:[jsx("div",{className:"oui-text-xs oui-text-base-contrast-54",children:C("affiliate.referralRate.editRateModal.description")}),jsxs("div",{className:"oui-text-xs oui-text-base-contrast-80 oui-mt-2 oui-flex",children:[C("affiliate.referralRate.editRateModal.label"),jsx("div",{className:"oui-text-warning-darken oui-pl-1",children:`${new Decimal(t.max_rebate_rate).mul(100).toFixed(0,Decimal.ROUND_DOWN)}%`})]}),jsx("div",{className:"oui-text-2xs oui-mt-6 oui-text-base-contrast-80",children:C("affiliate.referralRate.editRateModal.label.you")}),jsx(Input,{ref:c,containerClassName:"oui-h-[40px] oui-mt-3 oui-bg-base-700 oui-outline oui-outline-1 oui-outline-base-contrast-12 focus-within:oui-outline-primary-darken",placeholder:"Enter code",type:"text",inputMode:"decimal",autoComplete:"off",value:u,onChange:_=>{let A=cleanStringStyle(_.target.value),B=Number.parseFloat(A);l(A),Number.isNaN(B)?(m(""),l("")):(m(`${Co(new Decimal(0),s.sub(B))}`),p(s.sub(B)<new Decimal(0)));},suffix:jsx("div",{className:"oui-px-3 oui-text-base-contrast-54 oui-text-base",children:"%"}),color:d?"danger":void 0}),jsx("div",{className:"oui-text-2xs oui-mt-6 oui-text-base-contrast-80",children:C("affiliate.referralRate.editRateModal.label.referee")}),jsx(Input,{containerClassName:"oui-h-[40px] oui-mt-3 oui-bg-base-700 oui-outline oui-outline-1 oui-outline-base-contrast-12 focus-within:oui-outline-primary-darken",placeholder:"Enter code",type:"text",inputMode:"decimal",autoComplete:"off",autoFocus:false,value:x,onChange:_=>{let A=cleanStringStyle(_.target.value),B=Number.parseFloat(A);m(A),Number.isNaN(B)?(m(""),l("")):(l(`${Co(new Decimal(0),s.sub(B))}`),p(s.sub(B)<new Decimal(0)));},suffix:jsx("div",{className:"oui-px-3 oui-text-base-contrast-54 oui-text-base",children:"%"}),color:d?"danger":void 0}),d&&jsx("div",{className:"oui-text-danger oui-text-xs oui-mt-8 oui-text-center oui-px-4",children:C("affiliate.referralRate.editRateModal.helpText.max")}),jsx(Flex,{width:"100%",justify:"center",children:jsx(Button,{id:"referral_bind_referral_code_btn",disabled:x.length===0||u.length===0||d,loading:U,className:cn("oui-mt-8 oui-mb-4 oui-w-[154px]",d&&"oui-mt-3"),onClick:_=>{_.stopPropagation(),I();},children:C("common.confirm")})})]})]})})});function Co(e,t){return e>t?e:t}var Pt=()=>{let{referralInfo:e,referralLinkUrl:t,mutate:r,generateCode:a}=y(),o=l=>{Rt(ze(t,"ref",l));},n=l=>{Rt(l);},i=l=>{modal.show(wo,{code:{...l},mutate:r});},f=l=>{modal.show(xo,{code:{...l},successCallback:()=>{r();}});},[s,x]=useLocalStorage("orderly_referral_codes",[]),m=(l,d)=>{if(d){let p=s.findIndex(c=>c===l);p!==-1&&s.splice(p,1);}else s.splice(0,0,l);s.length>6&&s.splice(s.length-1,1),x([...s]);},u=useMemo(()=>{if(!e?.referrer_info?.referral_codes)return;let l=e?.referrer_info?.referral_codes?.map(p=>(a&&a.code===p.code&&(p.isAutoGenerated=true),p)),d=[];for(let p=0;p<s.length;p++){let c=s[p],C=l.findIndex(k=>k.code===c);C!==-1&&(d.push({...l[C],isPined:true}),l.splice(C,1));}return [...d,...l]},[e?.referrer_info?.referral_codes,s,a]);return {copyCode:n,copyLink:o,editRate:i,editCode:f,setPinCode:m,codes:u}};var Ye=()=>{let e=Pt();return jsx(_t,{...e})};var kt=e=>{let{t}=useTranslation();return jsx(Flex,{id:"oui-affiliate-affiliate-commissionAndReferees",r:"2xl",p:6,width:"100%",gap:4,direction:"column",className:"oui-bg-base-9 oui-tabular-nums",children:jsxs(Tabs,{defaultValue:"account",className:"oui-w-full",variant:"contained",children:[jsx(TabPanel,{value:"account",title:t("affiliate.commission"),children:jsx(Xa,{...e})}),jsx(TabPanel,{value:"password",title:t("affiliate.myReferees"),children:jsx(Ka,{...e})})]})})},G=e=>{let{title:t,value:r,align:a,className:o,rule:n,formatString:i,prefix:f}=e;return jsx(Statistic,{className:cn("oui-flex-1",o),label:jsx(Text,{className:"oui-text-base-contrast-36 oui-text-2xs",children:t}),align:a,children:jsx(Text.formatted,{rule:n||"",formatString:i,prefix:f,className:"oui-text-base-contrast-80 oui-text-sm oui-mt-[6px]",children:r})})},Xa=e=>{let{t}=useTranslation(),r=useMediaQuery("(max-width: 767px)"),a=useMemo(()=>[{title:`${t("affiliate.commission")} (USDC)`,dataIndex:"referral_rebate",render:i=>jsx(Text,{children:commifyOptional(i,{fix:6,fallback:"0",padEnd:true,prefix:"$"})}),width:216},{title:`${t("affiliate.referralVol")} (USDC)`,dataIndex:"volume",render:i=>jsx(Text,{children:commifyOptional(i,{fix:2,fallback:"0",padEnd:true,prefix:"$"})}),width:216},{title:t("affiliate.commission.column.activeUsers"),dataIndex:"daily_traded_referral",render:i=>jsx(Text,{children:i}),width:216},{title:t("common.date"),dataIndex:"date",render:i=>qr(i),width:216}],[t]),o=useMemo(()=>r?jsx(ListView,{className:"oui-max-h-[200px] oui-w-full",dataSource:e.commission.data,loadMore:e.commission.loadMore,isLoading:e.commission.isLoading,renderItem:n=>jsxs("div",{children:[jsxs(Flex,{direction:"row",width:"100%",children:[jsx(G,{title:t("affiliate.commission"),value:commifyOptional(n.referral_rebate,{fix:6,fallback:"0",padEnd:true}),prefix:"$"}),jsx(G,{title:t("affiliate.referralVol"),value:commifyOptional(n.volume,{fix:2,fallback:"0",padEnd:true}),prefix:"$"}),jsx(G,{title:t("affiliate.commission.column.activeUsers"),value:n.daily_traded_referral}),jsx(G,{title:t("common.date"),value:n.date,rule:"date",formatString:"yyyy-MM-dd",align:"end"})]}),jsx(Divider,{className:"oui-mt-3 oui-w-full"})]})}):jsx(AuthGuardDataTable,{bordered:true,columns:a,loading:e.commission.isLoading,ignoreLoadingCheck:true,dataSource:e.commission.data,pagination:e.commission.pagination,onRow:n=>({className:"oui-h-[41px]"})}),[r,e.commission]);return jsxs(Flex,{direction:"column",width:"100%",justify:"start",itemAlign:"start",children:[jsx(Ja,{value:e.commission.dateRange,setValue:e.commission.setDateRange}),o]})},Ka=e=>{let{t}=useTranslation(),r=useMediaQuery("(max-width: 767px)"),a=useMemo(()=>[{title:t("affiliate.referees.column.refereeAddress"),dataIndex:"user_address",render:i=>jsx(Text.formatted,{rule:"address",children:i}),className:"oui-w-1/5"},{title:t("affiliate.referralCode"),dataIndex:"referral_code",className:"oui-w-1/5"},{title:`${t("affiliate.referees.column.totalCommission")} (USDC)`,dataIndex:"referral_rebate",render:i=>jsx(Text,{children:commifyOptional(i,{fix:6,prefix:"$",padEnd:true})}),className:"oui-w-1/5"},{title:`${t("affiliate.referees.column.totalVol")} (USDC)`,dataIndex:"volume",render:i=>jsx(Text,{children:commifyOptional(i,{fix:2,prefix:"$",padEnd:true})}),className:"oui-w-1/5"},{title:t("affiliate.referees.column.invitationTime"),dataIndex:"code_binding_time",render:i=>jsx(Text.formatted,{rule:"date",formatString:"yyyy-MM-dd",children:i}),className:"oui-w-1/5"}],[t]),o=useMemo(()=>r?jsx(ListView,{className:"oui-w-full oui-max-h-[200px]",dataSource:e.referees.data,loadMore:e.referees.loadMore,isLoading:e.referees.isLoading,renderItem:(n,i)=>jsxs(Flex,{direction:"column",gap:3,className:"oui-border-b-2 oui-border-line-6 oui-pb-3",children:[jsxs(Flex,{direction:"row",width:"100%",children:[jsx(G,{title:t("affiliate.referralCode"),value:n.referral_code}),jsx(G,{title:`${t("affiliate.referees.column.totalCommission")} (USDC)`,value:commifyOptional(n.referral_rebate,{fix:6,prefix:"$",padEnd:true}),className:"oui-min-w-[102px]"}),jsx(G,{title:t("affiliate.referees.column.totalVol"),value:commifyOptional(n.volume,{fix:2,prefix:"$",padEnd:true}),align:"end"})]}),jsxs(Flex,{direction:"row",pt:3,gap:3,width:"100%",children:[jsx(G,{title:t("affiliate.referees.column.refereeAddress"),value:n.user_address,rule:"address"}),jsx(G,{title:t("affiliate.referees.column.invitationTime"),value:n.code_binding_time,align:"end",rule:"date",formatString:"yyyy-MM-dd"})]})]},i)}):jsx(AuthGuardDataTable,{bordered:true,loading:e.referees.isLoading,ignoreLoadingCheck:true,columns:a,dataSource:e.referees.data,pagination:e.referees.pagination,onRow:n=>({className:"oui-h-[41px]"})}),[r,e.referees]);return jsx(Flex,{direction:"column",width:"100%",justify:"start",itemAlign:"start",children:o})},Ja=e=>jsx(Flex,{width:"100%",height:49,className:"oui-border-b oui-border-line-6",children:jsx("div",{children:jsx(DatePicker.range,{size:"xs",value:e.value,onChange:t=>{e.setValue(t);},max:90,disabled:{after:new Date}})})});var It=()=>{let e=tn(),t=rn();return {commission:e,referees:t}},tn=()=>{let[e,t]=useState({from:subDays(new Date,90),to:subDays(new Date,1)}),r=useMediaQuery("(max-width: 767px)"),{page:a,pageSize:o,setPage:n,parsePagination:i}=usePagination(),[f,{refresh:s,isLoading:x,loadMore:m,meta:u}]=useReferralRebateSummary({startDate:e?.from!==void 0?format(e.from,"yyyy-MM-dd"):void 0,endDate:e?.to!==void 0?format(e.to,"yyyy-MM-dd"):void 0,size:o,page:r?void 0:a});useEffect(()=>{s();},[e]);let l=useMemo(()=>i(u),[i,u]);return useEffect(()=>{n(1);},[e]),{data:f||void 0,pagination:l,dateRange:e,setDateRange:t,isLoading:x,loadMore:m}},rn=()=>{let[e,t]=useState({from:subDays(new Date,90),to:subDays(new Date,1)}),r=useMediaQuery("(max-width: 767px)"),{page:a,pageSize:o,setPage:n,parsePagination:i}=usePagination(),[f,{refresh:s,isLoading:x,loadMore:m,meta:u}]=useRefereeInfo({startDate:e?.from!==void 0?format(e.from,"yyyy-MM-dd"):void 0,endDate:e?.to!==void 0?format(e.to,"yyyy-MM-dd"):void 0,size:o,page:r?void 0:a,sort:"descending_code_binding_time"});useEffect(()=>{s();},[e]);let l=useMemo(()=>i(u),[i,u]);return useEffect(()=>{n(1);},[e]),{data:f||void 0,pagination:l,dateRange:e,setDateRange:t,isLoading:x,loadMore:m}};var Bt=()=>{let e=It();return jsx(kt,{...e})};var _e=()=>jsxs(Flex,{id:"oui-affiliate-affiliate-page",className:cn("oui-h-lvw","oui-font-semibold"),direction:"column",gap:4,children:[jsx(ln,{}),jsx(Bt,{})]}),ln=()=>useMediaQuery("(max-width: 1279px)")?jsx(sn,{}):jsx(fn,{}),sn=()=>jsxs(Fragment,{children:[jsxs("div",{className:"oui-flex oui-flex-col xl:oui-flex-row oui-gap-4 oui-w-full",children:[jsx(Ee,{}),jsx(He,{})]}),jsx(qe,{}),jsx(Ye,{})]}),fn=()=>jsxs(Flex,{direction:"row",itemAlign:"stretch",gap:4,children:[jsxs(Flex,{direction:"column",gap:4,className:"oui-flex-1 oui-w-1/2",children:[jsx("div",{className:"oui-flex-1 oui-h-full oui-w-full",children:jsx(Ee,{})}),jsx(qe,{})]}),jsxs(Flex,{direction:"column",gap:4,className:"oui-w-1/2",children:[jsx(He,{}),jsx("div",{className:"oui-flex-1",children:jsx(Ye,{})})]})]});var Vt=e=>{let{t}=useTranslation();return jsxs(Flex,{id:"oui-affiliate-trader-summary",r:"2xl",p:6,width:"100%",height:"100%",gap:4,direction:"column",className:"oui-bg-base-9 xl:oui-flex-1",children:[jsx(dn,{...e}),jsx(Mo,{className:"md:oui-hidden",...e}),jsxs(Flex,{direction:"column",gap:3,width:"100%",className:"md:oui-mt-3",children:[jsx(xn,{...e}),jsx(pn,{...e})]}),jsx(gn,{title:`${t("affiliate.trader.tradingVol")} (USDC)`,...e})]})},dn=e=>{let{t}=useTranslation();return jsxs(Flex,{direction:"row",width:"100%",gap:3,children:[jsxs(Flex,{direction:"row",gap:3,className:"oui-flex-1",children:[jsx(Text,{className:"oui-text-lg",children:t("affiliate.trader.yourReferrer")}),jsx(Button,{color:"secondary",size:"sm",className:"oui-text-primary-light oui-text-2xs md:oui-text-xs 2xl:oui-text-sm oui-bg-base-6",children:e.code})]}),jsx(Mo,{className:"oui-hidden md:oui-flex md:oui-flex-shrink md:oui-w-fit",...e})]})},Mo=e=>{let{t}=useTranslation();return jsxs(Flex,{direction:"row",width:"100%",gap:2,className:e.className,children:[jsx(Text,{intensity:54,className:"oui-text-sm md:oui-text-base 2xl:oui-text-lg",children:`${t("affiliate.trader.rebate")}:`}),jsx(Text.gradient,{color:"brand",className:"oui-text-lg md:oui-text-xl 2xl:oui-text-2xl",children:e.rebateText})]})},xn=e=>{let{t}=useTranslation();return jsxs(Flex,{direction:"row",width:"100%",justify:"between",gap:3,children:[jsx(Text,{className:"oui-text-sm",children:t("affiliate.summary")}),jsx("div",{children:jsx(Select.options,{size:"xs",value:e.period,onValueChange:e.onPeriodChange,options:e.periodTypes})})]})},pn=e=>{let{t}=useTranslation();return jsxs(Flex,{gradient:"success",angle:180,r:"xl",py:4,px:6,width:"100%",direction:"column",gap:3,children:[jsx(Text,{intensity:54,className:"oui-text-base 2xl:oui-text-lg",children:`${t("affiliate.trader.rebates")} (USDC)`}),jsxs(Flex,{direction:"row",gap:3,className:"oui-text-xl md:oui-text-2xl xl:oui-text-3xl",children:[jsx(J,{className:"md:oui-w-[24px] md:oui-h-[24px] lg:oui-w-[28px] lg:oui-h-[28px] "}),jsx(Text,{children:commifyOptional(e.rebates,{fix:2,fallback:"0"})})]})]})},gn=e=>jsxs(Flex,{direction:"row",justify:"between",width:"100%",children:[jsx(Text,{intensity:54,className:"oui-text-2xs md:oui-text-xs xl:oui-text-sm",children:e.title}),jsx(Text,{className:"oui-text-xs md:oui-text-sm xl:oui-text-base",children:commifyOptional(e.vol,{fix:2,fallback:"0"})})]});var Ot=()=>{let{t:e}=useTranslation(),[t,r]=useState("All"),a=[{label:e("common.all"),value:"All"},{label:e("common.select.1d"),value:"1D"},{label:e("common.select.7d"),value:"7D"},{label:e("common.select.30d"),value:"30D"}],{referralInfo:o,userVolume:n}=y(),i=useMemo(()=>{if(!o)return 0;switch(t){case "All":return o.referee_info.total_referee_rebate;case "1D":return o.referee_info["1d_referee_rebate"];case "7D":return o.referee_info["7d_referee_rebate"];case "30D":return o.referee_info["30d_referee_rebate"]}},[o,t]),f=useMemo(()=>{if(n)switch(t){case "All":return n.all_volume;case "1D":return n["1d_volume"];case "7D":return n["7d_volume"];case "30D":return n["30d_volume"]}},[n,t]),s=o?.referee_info?.referer_code,x=o?.referee_info?.referee_rebate_rate,m=useMemo(()=>x?new Decimal(x).mul(100).toDecimalPlaces(2,Decimal.ROUND_DOWN).toString()+"%":"-",[x]);return {period:t,periodTypes:a,onPeriodChange:l=>{r(l);},rebates:i,vol:f,rebateText:m,code:s}};var Et=()=>{let e=Ot();return jsx(Vt,{...e})};var Ut=e=>jsxs(Flex,{id:"oui-affiliate-trader-titleStatistic",r:"2xl",p:6,width:"100%",gap:4,direction:"column",className:"oui-bg-base-9 xl:oui-flex-1",children:[jsx(Tn,{...e}),jsx(Flex,{className:"oui-min-h-[170px] oui-h-full oui-w-full oui-flex oui-flex-row oui-items-stretch",children:jsx(VolBarChart,{data:e.dataSource,colors:{fill:"rgba(0, 180, 158, 1)"},className:"oui-w-full oui-flex-1",tooltip:{rm:Decimal.ROUND_DOWN,dp:e.volType==="volume"?2:6}})})]}),Tn=e=>{let{t}=useTranslation();return jsxs(Flex,{direction:"row",justify:"between",width:"100%",children:[jsx(Text,{className:"oui-text-lg",children:t("affiliate.statistics")}),jsxs(Flex,{direction:"row",gap:2,className:"oui-min-w-14",children:[jsx(Select.options,{size:"xs",value:e.period,onValueChange:e.onPeriodChange,options:e.periodTypes}),jsx(Select.options,{size:"xs",value:e.volType,onValueChange:e.onVolTypeChange,options:e.volTypes})]})]})};var Ht=()=>{let{t:e}=useTranslation(),[t,r]=useState("7"),a=[{label:e("common.select.7d"),value:"7"},{label:e("common.select.30d"),value:"30"},{label:e("common.select.90d"),value:"90"}],o=c=>{r(c);},[n,i]=useState("rebate"),f=[{label:e("affiliate.trader.rebate"),value:"rebate"},{label:e("common.volume"),value:"volume"}],s=c=>{i(c);},x=useMemo(()=>t==="7"?{startDate:subDays(new Date,7),endDate:subDays(new Date,1)}:t==="30"?{startDate:subDays(new Date,30),endDate:subDays(new Date,1)}:t==="90"?{startDate:subDays(new Date,90),endDate:subDays(new Date,1)}:{startDate:subDays(new Date,7),endDate:subDays(new Date,1)},[t]),{data:m,mutate:u}=useRefereeRebateSummary(x),{dailyVolume:l,chartConfig:d}=y(),p=useMemo(()=>n==="rebate"?(m||[]).map(C=>({date:C.date,volume:C.referee_rebate})).reverse():n==="volume"?l?.filter(c=>c.date>format(subDays(Date(),Number(t)+1),"yyyy-MM-dd")).map(c=>({date:c.date,volume:c.perp_volume}))||[]:[],[m,l,n]);return {period:t,periodTypes:a,onPeriodChange:o,volType:n,volTypes:f,onVolTypeChange:s,dataSource:Ge(Number(t),p)}};var $t=()=>{let e=Ht();return jsx(Ut,{...e})};var Zt=e=>jsxs(Flex,{id:"oui-affiliate-trader-rebates",r:"2xl",p:6,width:"100%",gap:4,direction:"column",className:"oui-bg-base-9 oui-tabular-nums",children:[jsx(kn,{...e}),jsx(Flex,{width:"100%",className:"oui-border-y-2 oui-border-line-6",height:49,direction:"row",itemAlign:"center",children:jsx("div",{children:jsx(DatePicker.range,{size:"xs",value:e.dateRange,onChange:t=>{e.setDateRange(t);},max:90,disabled:{after:new Date}})})}),jsx(In,{...e})]}),kn=e=>{let{t}=useTranslation();return jsxs(Flex,{direction:"row",justify:"between",width:"100%",children:[jsx(Text,{className:"oui-text-lg",children:t("affiliate.trader.myRebates")}),jsx(Text,{intensity:36,className:"oui-text-2xs",children:e.displayDate})]})},In=e=>{let{t}=useTranslation(),r=useMediaQuery("(max-width: 767px)"),a=[{title:`${t("affiliate.trader.rebates")} (USDC)`,dataIndex:"referee_rebate",render:o=>jsx(Text,{children:commifyOptional(o,{fix:6,fallback:"0",padEnd:true,prefix:"$"})}),width:127},{title:`${t("affiliate.trader.tradingVol")} (USDC)`,dataIndex:"vol",render:o=>commifyOptional(o,{fix:2,fallback:"0",padEnd:true,prefix:"$"}),width:127},{title:t("common.date"),dataIndex:"date",render:o=>jsx(Text.formatted,{formatString:"yyyy-MM-dd",children:o}),width:127}];return r?jsx(ListView,{dataSource:e.dataSource,className:"oui-h-[197px] oui-w-full",renderItem:(o,n)=>jsx(Bn,{item:o})}):jsx(AuthGuardDataTable,{bordered:true,loading:e.isLoading,columns:a,dataSource:e.dataSource,ignoreLoadingCheck:true,onRow:o=>({className:"oui-h-[41px]"}),pagination:e.pagination,manualPagination:false})},Bn=e=>{let{t}=useTranslation();return jsxs(Flex,{direction:"column",width:"100%",children:[jsxs(Flex,{width:"100%",gap:1,children:[jsx(Statistic,{label:`${t("affiliate.trader.rebates")} (USDC)`,className:"oui-text-xs oui-text-base-contrast-54 oui-flex-1 oui-min-w-[105px]",children:jsx(Text,{size:"sm",intensity:80,children:commifyOptional(e.item.referee_rebate,{fix:6,fallback:"0",padEnd:true,prefix:"$"})})}),jsx(Statistic,{label:`${t("affiliate.trader.tradingVol")} (USDC)`,className:"oui-text-xs oui-text-base-contrast-54 oui-flex-shrink",children:jsx(Text,{size:"sm",intensity:80,children:commifyOptional(e.item.vol,{fix:2,fallback:"0",padEnd:true,prefix:"$"})})}),jsx(Statistic,{label:t("common.date"),className:"oui-text-xs oui-text-base-contrast-54 oui-flex-1",align:"end",children:jsx(Text.formatted,{size:"sm",intensity:80,formatString:"yyyy-MM-dd",children:e.item.date})})]}),jsx(Divider,{className:"oui-w-full oui-mt-3"})]})};var Qt=()=>{let[e,t]=useState({from:subDays(new Date,90),to:subDays(new Date,1)}),{data:r,mutate:a,isLoading:o}=useRefereeRebateSummary({startDate:e?.from,endDate:e?.to}),{data:n,mutate:i}=useDaily({startDate:e?.to,endDate:e?.from}),f=useMemo(()=>typeof r>"u"?[]:r.map(u=>{let l=u.date,d=n?.filter(p=>Zr(toDate(l),toDate(p.date)))?.[0];return d?{...u,vol:d.perp_volume}:u}),[r,n]),s;(f?.length||0)>0&&(s=Gr(f?.[0].date));let{pagination:x,setPage:m}=usePagination();return useEffect(()=>{m(1);},[e]),{dateRange:e,setDateRange:t,displayDate:s,dataSource:f,pagination:x,isLoading:o}};var Yt=()=>{let e=Qt();return jsx(Zt,{...e})};var Le=()=>jsxs(Flex,{id:"oui-affiliate-trader-page",className:cn("oui-h-lvw oui-w-full","oui-font-semibold"),direction:"column",gap:4,children:[jsxs(Flex,{width:"100%",gap:4,className:"oui-flex oui-flex-col xl:oui-flex-row xl:oui-items-stretch",children:[jsx(Et,{}),jsx($t,{})]}),jsx(Yt,{})]});var jt=e=>{let{t}=useTranslation(),{generateCode:r}=y(),a=useMemo(()=>r?r.requireVolume>0?{title:t("affiliate.process.step1.volumeGt0.title",{requireVolume:r.requireVolume}),desc:t("affiliate.process.step1.volumeGt0.description",{volume:commify(r.completedVolume??0,2),requireVolume:commify(r.requireVolume)})}:{title:t("affiliate.process.step1.volumeEq0.title"),desc:t("affiliate.process.step1.volumeEq0.description")}:{title:t("affiliate.process.step1.title"),desc:t("affiliate.process.step1.description")},[r,t]);return typeof e.overwrite=="function"?e.overwrite?.(e.state):jsxs(Flex,{id:"oui-affiliate-home-becomeAffiliate",direction:"column",gap:6,p:6,itemAlign:"center",r:"2xl",className:"oui-bg-base-9",width:"100%",children:[jsx(Text,{children:t("affiliate.process.title")}),jsxs(Flex,{className:"oui-flex oui-flex-col oui-gap-3 lg:oui-w-full lg:oui-flex-row lg:oui-items-stretch",children:[jsx(Kt,{icon:jsx(Zn,{}),title:a.title,content:a.desc}),jsx("div",{className:"oui-shrink lg:oui-flex lg:-oui-rotate-90 lg:oui-flex-row lg:oui-items-center lg:oui-justify-center",children:jsx(Uo,{})}),jsx(Kt,{icon:jsx(Qn,{}),title:t("affiliate.process.step2.title"),content:t("affiliate.process.step2.description")}),jsx("div",{className:"oui-shrink lg:oui-flex lg:-oui-rotate-90 lg:oui-flex-row lg:oui-items-center lg:oui-justify-center",children:jsx(Uo,{})}),jsx(Kt,{icon:jsx(Yn,{}),title:t("affiliate.process.step3.title"),content:t("affiliate.process.step3.description")})]})]})},Kt=e=>jsxs(Flex,{className:cn("oui-flex oui-flex-row oui-gap-3","lg:oui-flex-1 lg:oui-flex-col lg:oui-gap-[6px]"),width:"100%",children:[jsx("div",{className:"oui-shrink-0",children:e.icon}),jsxs(Flex,{className:cn("oui-flex oui-flex-col oui-items-start oui-h-full oui-justify-between","lg:oui-items-center lg:oui-justify-start"),children:[jsx(Text,{className:"oui-text-sm md:oui-text-base 2xl:oui-text-lg lg:oui-text-center",children:e.title}),jsx(Text,{className:"oui-text-2xs oui-text-base-contrast-36 lg:oui-text-center",children:e.content})]})]}),Zn=()=>jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"lg:oui-w-[64px] lg:oui-h-[64px] 2xl:oui-w-[80px] 2xl:oui-h-[80px]",children:[jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M24.941 5.4h-6.682a.6.6 0 0 0-.593.509l-.462 3a.6.6 0 0 0 .593.691h7.606a.6.6 0 0 0 .593-.691l-.462-3a.6.6 0 0 0-.593-.509m-6.682-1.8a2.4 2.4 0 0 0-2.372 2.035l-.462 3a2.4 2.4 0 0 0 2.372 2.765h7.606a2.4 2.4 0 0 0 2.372-2.765l-.462-3A2.4 2.4 0 0 0 24.941 3.6z",fill:"#fff",fillOpacity:".36"}),jsx("path",{d:"M32.721 28.2c.924-1.6 3.233-1.6 4.157 0l7.275 12.6c.924 1.6-.231 3.6-2.079 3.6H27.525c-1.848 0-3.002-2-2.078-3.6z",fill:"#335FFC"}),jsx("path",{d:"M33.492 38.12H31.56c-.252 0-.426-.276-.336-.535l1.92-5.53a.4.4 0 0 1 .132-.185.34.34 0 0 1 .204-.07h3.24c.255 0 .43.284.333.544l-1.118 3.011h2.104c.31 0 .475.4.27.656l-5.158 6.453c-.251.313-.716.041-.619-.362z",fill:"#fff",fillOpacity:".98"}),jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M14.4 16.8v2.4h2.4v-2.4zM13.2 15a.6.6 0 0 0-.6.6v4.8a.6.6 0 0 0 .6.6H18a.6.6 0 0 0 .6-.6v-4.8a.6.6 0 0 0-.6-.6z",fill:"#fff",fillOpacity:".36"}),jsx("path",{d:"M20.4 16.2a.6.6 0 0 1 .6-.6h2.4a.6.6 0 0 1 .6.6v.6a.6.6 0 0 1-.6.6H21a.6.6 0 0 1-.6-.6zm0 3a.6.6 0 0 1 .6-.6h9a.6.6 0 0 1 .6.6v.6a.6.6 0 0 1-.6.6h-9a.6.6 0 0 1-.6-.6zm-7.8 5.4a.6.6 0 0 1 .6-.6H30a.6.6 0 0 1 .6.6v.6a.6.6 0 0 1-.6.6H13.2a.6.6 0 0 1-.6-.6zm0 3.6a.6.6 0 0 1 .6-.6H30a.6.6 0 0 1 .6.6v.6a.6.6 0 0 1-.6.6H13.2a.6.6 0 0 1-.6-.6zm0 3.6a.6.6 0 0 1 .6-.6h9a.6.6 0 0 1 .6.6v.6a.6.6 0 0 1-.6.6h-9a.6.6 0 0 1-.6-.6z",fill:"#fff",fillOpacity:".36"}),jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M15.739 6.6H10.2A2.4 2.4 0 0 0 7.8 9v30a2.4 2.4 0 0 0 2.4 2.4h13.84l1.014-1.8H10.2a.6.6 0 0 1-.6-.6V9a.6.6 0 0 1 .6-.6h5.262zm12 1.8H33a.6.6 0 0 1 .6.6v16.47a2.8 2.8 0 0 1 1.8-.205V9A2.4 2.4 0 0 0 33 6.6h-5.538z",fill:"#fff",fillOpacity:".36"})]}),Qn=()=>jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"lg:oui-w-[64px] lg:oui-h-[64px] 2xl:oui-w-[80px] 2xl:oui-h-[80px]",children:[jsx("path",{d:"M24 33a9 9 0 1 1-18 0 9 9 0 0 1 18 0",fill:"#335FFC"}),jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M15 32.4a1.8 1.8 0 1 0 0-3.6 1.8 1.8 0 0 0 0 3.6m0 1.8a3.6 3.6 0 1 0 0-7.2 3.6 3.6 0 0 0 0 7.2m-6.578 4.942A4.8 4.8 0 0 1 13.2 34.8h3.6a4.8 4.8 0 0 1 4.778 4.342 9 9 0 0 1-1.778 1.473V39.6a3 3 0 0 0-3-3h-3.6a3 3 0 0 0-3 3v1.015a9 9 0 0 1-1.778-1.473",fill:"#fff",fillOpacity:".98"}),jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M16.2 12a4.2 4.2 0 1 1-8.4 0 4.2 4.2 0 0 1 8.4 0m1.8 0c0 1.37-.459 2.632-1.231 3.642l2.308 2.308a7.76 7.76 0 0 1 4.023-1.7v-.764A3.602 3.602 0 0 1 24 8.4a3.6 3.6 0 0 1 .9 7.087v.764c1.48.17 2.833.754 3.942 1.633l2.326-2.326a6 6 0 1 1 1.273 1.273l-2.326 2.326a7.76 7.76 0 0 1 1.634 3.943h.764a3.602 3.602 0 0 1 7.087.9 3.6 3.6 0 0 1-7.087.9h-.764a7.76 7.76 0 0 1-1.699 4.023l2.308 2.308a6 6 0 1 1-1.25 1.295l-2.347-2.347a7.8 7.8 0 0 1-3.05 1.433 11 11 0 0 0-.377-1.76 6 6 0 1 0-7.185-7.185q-.855-.261-1.76-.379a7.8 7.8 0 0 1 1.432-3.049l-2.347-2.347A6 6 0 1 1 18 12m7.8 0a1.8 1.8 0 1 1-3.6 0 1.8 1.8 0 0 1 3.6 0M36 25.8a1.8 1.8 0 1 0 0-3.6 1.8 1.8 0 0 0 0 3.6m0-9.6a4.2 4.2 0 1 0 0-8.4 4.2 4.2 0 0 0 0 8.4M40.2 36a4.2 4.2 0 1 1-8.4 0 4.2 4.2 0 0 1 8.4 0",fill:"#fff",fillOpacity:".36"})]}),Yn=()=>jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"lg:oui-w-[64px] lg:oui-h-[64px] 2xl:oui-w-[80px] 2xl:oui-h-[80px]",children:[jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M24 24a2.4 2.4 0 1 0 0-4.8 2.4 2.4 0 0 0 0 4.8m0 1.8a4.2 4.2 0 1 0 0-8.4 4.2 4.2 0 0 0 0 8.4",fill:"#fff",fillOpacity:".36"}),jsx("path",{d:"M45 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0",fill:"#335FFC"}),jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M35.1 6.6a.9.9 0 1 1 1.8 0v.437A3 3 0 0 1 39 9.9h-1.8a1.2 1.2 0 1 0-1.2 1.2 3 3 0 0 1 .9 5.863v.437a.9.9 0 0 1-1.8 0v-.437A3 3 0 0 1 33 14.1h1.8a1.2 1.2 0 1 0 1.2-1.2 3 3 0 0 1-.9-5.863z",fill:"#fff",fillOpacity:".98"}),jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M40.2 23.7a.9.9 0 0 1 1.8 0v.6q0 .045-.004.086c-.197 9.351-7.525 16.948-16.765 17.573l1.205 1.205a.9.9 0 1 1-1.272 1.272l-2.7-2.7a.9.9 0 0 1 0-1.272l2.7-2.7a.9.9 0 1 1 1.272 1.272l-1.11 1.11c8.325-.674 14.87-7.642 14.874-16.14zM21.564 4.836a.9.9 0 1 1 1.272-1.272l2.7 2.7a.9.9 0 0 1 0 1.272l-2.7 2.7a.9.9 0 1 1-1.272-1.272l1.11-1.11C14.347 8.528 7.8 15.5 7.8 24v.3a.9.9 0 1 1-1.8 0v-.6l.004-.086C6.201 14.263 13.53 6.666 22.77 6.042z",fill:"#fff",fillOpacity:".36"}),jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M24 11.4q.615 0 1.213.058a11 11 0 0 0 .061 1.816Q24.647 13.2 24 13.2c-5.965 0-10.8 4.835-10.8 10.8 0 2.898 1.142 5.53 3 7.47a4.8 4.8 0 0 1 4.8-4.79h6a4.8 4.8 0 0 1 4.8 4.789c1.858-1.94 3-4.572 3-7.47q0-.647-.074-1.274a11 11 0 0 0 1.816.06q.057.6.058 1.214c0 6.959-5.641 12.6-12.6 12.6S11.4 30.959 11.4 24 17.041 11.4 24 11.4m6 21.581v-1.5a3 3 0 0 0-3-3h-6a3 3 0 0 0-3 3v1.5a10.75 10.75 0 0 0 6 1.819c2.22 0 4.284-.67 6-1.819",fill:"#fff",fillOpacity:".36"})]}),Uo=()=>jsx("svg",{width:"17",height:"16",viewBox:"0 0 17 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M8.5048 4.00806C8.8728 4.00806 9.1708 4.30626 9.1708 4.67406C9.1708 4.99259 9.1708 8.71739 9.1708 9.71072L11.1688 7.73339L12.1055 8.67005L8.98346 11.8127C8.85346 11.9434 8.6788 12.0081 8.50413 12.0081C8.33013 12.0081 8.15612 11.9427 8.02612 11.8127L4.90413 8.67005L5.8408 7.73339L7.83881 9.71072C7.83881 8.71739 7.83881 4.99259 7.83881 4.67406C7.83881 4.30626 8.1368 4.00806 8.5048 4.00806Z",fill:"#608CFF"})});var er=()=>{let e=y();return {overwrite:e.overwrite?.ref?.step,state:e}};var tr=()=>{let e=er();return jsx(jt,{...e})};var rr=()=>{let{t:e}=useTranslation();return jsx("div",{id:"oui-affiliate-home-title",className:"oui-text-center oui-text-3xl oui-font-bold md:oui-text-3xl lg:oui-text-4xl xl:oui-text-5xl",children:e("affiliate.page.title")})};var or=()=>jsx(rr,{});var ir=e=>{let{t}=useTranslation();return jsxs(Flex,{id:"oui-affiliate-home-subtitle",direction:"column",className:"oui-text-sm md:oui-text-base xl:oui-text-lg oui-text-base-contrast-80 oui-text-center",gap:3,children:[jsx(Text,{children:t("affiliate.page.subTitle")}),jsxs(Flex,{direction:"row",gap:1,className:"oui-text-primary-light oui-fill-primary-light hover:oui-text-primary-darken oui-cursor-pointer oui-text-2xs md:oui-text-xs xl:oui-text-sm",onClick:r=>{e.onLearnAffiliate?e.onLearnAffiliate?.():e.learnAffiliateUrl&&window.open(e.learnAffiliateUrl,"_blank");},children:[jsx(Text,{children:t("affiliate.page.learnMore")}),jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M4.008 7.995c0-.368.298-.666.666-.666H9.71L7.733 5.331l.937-.936 3.143 3.122c.13.13.195.304.195.479a.67.67 0 0 1-.195.478L8.67 11.596l-.937-.937 1.978-1.998H4.674a.666.666 0 0 1-.666-.666"})})]})]})};var ar=()=>{let e=y(),{onLearnAffiliate:t,learnAffiliateUrl:r}=e;return {onLearnAffiliate:t,learnAffiliateUrl:r}};var nr=()=>{let e=ar();return jsx(ir,{...e})};var lr=e=>e.overwriteTop!==void 0?e.overwriteTop?.(e.state):jsxs(Flex,{id:"oui-affiliate-home-top",direction:"column",gap:6,children:[jsx(or,{}),jsx(nr,{})]});var sr=()=>{let e=y();return {overwriteTop:e.overwrite?.ref?.top,state:e}};var fr=()=>{let e=sr();return jsx(lr,{...e})};var nt=e=>jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"white",fillOpacity:"0.98",xmlns:"http://www.w3.org/2000/svg",className:e.className,children:jsx("path",{d:"M4.00806 7.9952C4.00806 7.6272 4.30626 7.3292 4.67406 7.3292C4.99259 7.3292 8.71739 7.3292 9.71072 7.3292L7.73339 5.3312L8.67005 4.39453L11.8127 7.51654C11.9434 7.64654 12.0081 7.8212 12.0081 7.99587C12.0081 8.16987 11.9427 8.34388 11.8127 8.47388L8.67005 11.5959L7.73339 10.6592L9.71072 8.66119C8.71739 8.66119 4.99259 8.66119 4.67406 8.66119C4.30626 8.66119 4.00806 8.3632 4.00806 7.9952Z"})});var cr=e=>{let{t}=useTranslation();return jsxs(Flex,{id:"oui-affiliate-home-asTrader",gradient:"success",r:"2xl",p:6,gap:6,direction:"column",angle:180,width:"100%",justify:"between",children:[jsxs(Flex,{height:80,direction:"row",gap:3,itemAlign:"start",width:"100%",justify:"between",children:[jsxs(Flex,{direction:"column",itemAlign:"start",justify:"between",className:"oui-h-full",children:[jsx(Text,{className:"oui-text-lg md:oui-text-xl lg:oui-text-2xl xl:oui-text-3xl",children:e.isTrader?t("affiliate.trader"):t("affiliate.asTrader.title")}),jsx(Text,{className:cn("oui-text-xs md:oui-text-sm 2xl:oui-text-base oui-text-base-contrast-54",e.isTrader&&"oui-hidden"),children:t("affiliate.asTrader.description")})]}),jsx("div",{className:"oui-flex-shrink-0",children:jsx(hl,{})})]}),jsx(bl,{...e})]})},hl=()=>jsxs("svg",{width:"72",height:"72",viewBox:"0 0 90 90",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"xl:oui-w-[90px] xl:oui-h-[90px] ",children:[jsx("path",{d:"M44.996 7.324c-20.71 0-37.43 16.79-37.5 37.5-.07 20.682 16.806 37.575 37.5 37.617 20.694.04 37.537-17.082 37.5-37.617-.037-20.71-16.79-37.5-37.5-37.5m0 7.5c16.569 0 30 13.433 30 30 0 8.438-3.514 16.043-9.12 21.495-2.762-5.973-8.694-10.245-15.49-10.245h-10.78c-6.791 0-12.706 4.22-15.47 10.197-5.606-5.453-9.14-13.01-9.14-21.447 0-16.567 13.431-30 30-30m0 7.5c-8.284 0-15 6.717-15 15s6.716 15 15 15 15-6.716 15-15-6.716-15-15-15",fill:"#fff",fillOpacity:".2"}),jsx("path",{d:"M90 71.25C90 81.605 81.605 90 71.25 90S52.5 81.605 52.5 71.25 60.895 52.5 71.25 52.5 90 60.895 90 71.25",fill:"#005A4F"}),jsx("path",{d:"M80.62 75.007c0-.24-.08-.49-.263-.675l-3.487-3.456-1.318 1.318 1.845 1.875H63.745a.938.938 0 0 0 0 1.875h13.652l-1.845 1.875 1.318 1.318 3.487-3.456a.95.95 0 0 0 .263-.674m-.937-7.5a.94.94 0 0 0-.938-.938H65.093l1.846-1.875-1.319-1.318-3.486 3.456a.966.966 0 0 0 0 1.349l3.486 3.456 1.319-1.318-1.846-1.875h13.652c.518 0 .938-.42.938-.937",fill:"#fff",fillOpacity:".98"})]}),bl=e=>{let{t}=useTranslation();return jsx(Flex,{direction:"row",justify:"between",width:"100%",itemAlign:"end",children:(()=>{if(e.isTrader&&!e.wrongNetwork){let a=e.referralInfo?.referee_info?.total_referee_rebate;return jsxs(Fragment,{children:[jsxs(Flex,{direction:"column",itemAlign:"start",gap:2,children:[jsxs(Text,{className:"oui-text-2xs md:oui-text-xs xl:oui-text-sm",children:[t("affiliate.commission")," ",jsx(Text,{intensity:36,children:"(USDC)"})]}),jsxs(Flex,{direction:"row",gap:1,children:[jsx(J,{}),jsx(Text,{className:"oui-text-base md:oui-text-lg lg:oui-text-xl xl:oui-text-2xl",children:commifyOptional(a,{fix:2,fallback:"0"})})]})]}),jsxs(Flex,{direction:"row",gap:1,justify:"end",itemAlign:"center",className:"oui-cursor-pointer",onClick:e?.onEnterTraderPage,children:[jsx(Text,{className:"oui-text-sm md:oui-text-base xl:oui-text-lg",children:t("affiliate.enter")}),jsx(nt,{className:"md:oui-size-[18px] lg:oui-size-[20px] xl:oui-size-[24px]"})]})]})}return jsx(Cl,{...e})})()})},Cl=e=>{let{t}=useTranslation();return jsxs(Dialog,{open:e.open,onOpenChange:e.setOpen,children:[jsx(DialogTrigger,{children:jsx(Tooltip,{content:e.wrongNetwork?t("connector.wrongNetwork.tooltip"):t("affiliate.connectWallet.tooltip"),children:e.isMobile?jsx(Button,{variant:"contained",color:"light",onClick:r=>{(!e.isSignIn||e.wrongNetwork)&&(r.stopPropagation(),r.preventDefault(),modal.alert({title:t("common.tips"),message:jsx(Text,{intensity:54,children:e.wrongNetwork?t("connector.wrongNetwork.tooltip"):t("affiliate.connectWallet.tooltip")})}));},className:!e.isSignIn||e.wrongNetwork?"oui-bg-white/[.54] oui-text-black/[.36] hover:oui-bg-white/[.54]":void 0,children:t("affiliate.asTrader.button")}):jsx(Button,{variant:"contained",color:"light",disabled:!e.isSignIn||e.wrongNetwork,children:t("affiliate.asTrader.button")})})}),jsxs(DialogContent,{className:"oui-w-[320px] oui-font-semibold",children:[jsx(DialogHeader,{children:jsx(DialogTitle,{children:t("affiliate.referralCode.dialog.title")})}),jsx(Divider,{}),jsxs(DialogBody,{children:[jsx(Text,{size:"sm",intensity:54,children:t("affiliate.referralCode.dialog.description")}),jsx(TextField,{className:"oui-mt-4 oui-w-full",placeholder:t("affiliate.referralCode"),value:e.code,onChange:r=>{let a=r.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"");e.setCode(a);},formatters:[inputFormatter.createRegexInputFormatter(r=>String(r).replace(/[a-z]/g,a=>a.toUpperCase())),inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)],onClean:()=>{e.setCode("");},label:t("affiliate.referralCode.label"),classNames:{label:"oui-text-2xs oui-text-base-contrast-54"},helpText:!e.isExist&&!e.isLoading&&e.code.length>0?t("affiliate.referralCode.notExist"):void 0,color:!e.isExist&&!e.isLoading&&e.code.length>0?"danger":void 0}),jsx(Flex,{itemAlign:"center",width:"100%",direction:"row",justify:"center",mt:6,children:jsx(Button,{variant:"contained",color:"primary",size:"md",className:"oui-px-[40px]",disabled:e.code.length<4||!e.isExist,onClick:r=>{r.stopPropagation(),e.onClickConfirm();},children:t("common.confirm")})})]})]})]})};var xr=()=>{let{t:e}=useTranslation(),{isTrader:t,referralInfo:r,setShowHome:a,bindReferralCodeState:o,setTab:n,mutate:i,wrongNetwork:f,disabledConnect:s}=y(),{state:x}=useAccount(),m=!s&&(x.status===AccountStatusEnum.EnableTrading||x.status===AccountStatusEnum.EnableTradingWithoutConnected),u=()=>{n("trader"),a(false);},[l,d]=useState(""),[p,c]=useState(false),{isExist:C,error:k,isLoading:ne}=useCheckReferralCode(l),U=()=>{c(false);},[I,{error:_,isMutating:A}]=useMutation("/v1/referral/bind","POST"),B=async()=>{try{await I({referral_code:l}),toast.success(e("affiliate.referralCode.bound")),i(),o?o(!0,null,U,{tab:1}):U();}catch(H){let K=`${H}`;"message"in H&&(K=H.message),K==="referral code not exist"&&(K=e("affiliate.referralCode.notExist")),o?(toast.error(K),o(false,H,U,{})):toast.error(K);}},{isMobile:ce}=useScreen();return {isSignIn:m,isTrader:t,isLoading:ne,referralInfo:r,onEnterTraderPage:u,code:l,setCode:d,open:p,setOpen:c,onClickConfirm:B,isExist:C,wrongNetwork:f,isMobile:ce}};var pr=()=>{let e=xr();return jsx(cr,{...e})};var gr=e=>{let{t}=useTranslation();return jsxs(Flex,{id:"oui-affiliate-home-asAnAffiliate",gradient:"primary",r:"2xl",p:6,gap:6,direction:"column",angle:180,width:"100%",justify:"between",children:[jsxs(Flex,{direction:"row",gap:3,itemAlign:"start",width:"100%",justify:"between",children:[jsxs(Flex,{direction:"column",itemAlign:"start",justify:"between",className:"oui-h-full",children:[jsx(Text,{className:"oui-text-lg md:oui-text-xl lg:oui-text-2xl xl:oui-text-3xl",children:e.isAffiliate?t("common.affiliate"):t("affiliate.asAffiliate.title")}),jsx(Text,{className:cn("oui-text-xs oui-text-base-contrast-54 md:oui-text-sm 2xl:oui-text-base",e.isAffiliate&&"oui-hidden"),children:t("affiliate.asAffiliate.description")})]}),jsx("div",{className:"oui-shrink-0",children:jsx(Ml,{})})]}),jsx(Pl,{...e})]})},Ml=()=>jsxs("svg",{width:"72",height:"72",viewBox:"0 0 72 72",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"xl:oui-w-[90px] xl:oui-h-[90px]",children:[jsx("path",{d:"M35.997 5.86c-16.569 0-29.944 13.43-30 30-.056 16.545 13.445 30.06 30 30.093s30.03-13.665 30-30.093c-.03-16.57-13.432-30-30-30m0 6c13.255 0 24 10.746 24 24 0 6.75-2.812 12.834-7.297 17.196-2.209-4.78-6.955-8.196-12.39-8.196h-8.626c-5.432 0-10.164 3.375-12.375 8.157-4.485-4.362-7.312-10.407-7.312-17.157 0-13.254 10.745-24 24-24m0 6c-6.628 0-12 5.373-12 12s5.372 12 12 12c6.627 0 12-5.373 12-12s-5.373-12-12-12",fill:"#fff",fillOpacity:".2"}),jsx("path",{d:"M72 57c0 8.284-6.716 15-15 15s-15-6.716-15-15 6.716-15 15-15 15 6.716 15 15",fill:"#1828C3"}),jsx("path",{d:"M53.624 51.45a4.125 4.125 0 0 0-4.125 4.125c0 2.388 1.36 4.641 3.61 6.703a21 21 0 0 0 2.414 1.875c.287.194.556.37.797.516.147.089.243.154.304.187a.79.79 0 0 0 .75 0c.061-.033.158-.098.305-.187.24-.147.51-.322.797-.516a21 21 0 0 0 2.414-1.875c2.25-2.062 3.61-4.315 3.61-6.703a4.125 4.125 0 0 0-4.126-4.125c-1.294 0-2.557.705-3.351 1.734-.775-1.047-2.034-1.734-3.399-1.734",fill:"#fff",fillOpacity:".98"})]}),Pl=e=>{let{t}=useTranslation();return jsx(Flex,{direction:"row",justify:"between",width:"100%",itemAlign:"end",children:(()=>{if(e.isAffiliate&&!e.wrongNetwork){let a=e.referralInfo?.referrer_info?.total_referrer_rebate;return jsxs(Fragment,{children:[jsxs(Flex,{direction:"column",itemAlign:"start",gap:2,children:[jsxs(Text,{className:"oui-text-2xs md:oui-text-xs xl:oui-text-sm",children:[t("affiliate.commission")," ",jsx(Text,{intensity:36,children:"(USDC)"})]}),jsxs(Flex,{direction:"row",gap:1,children:[jsx(J,{}),jsx(Text,{className:"oui-text-base md:oui-text-lg lg:oui-text-xl xl:oui-text-2xl",children:commifyOptional(a,{fix:2,fallback:"0"})})]})]}),jsxs(Flex,{direction:"row",gap:1,justify:"end",itemAlign:"center",className:"oui-cursor-pointer",onClick:o=>{e.onEnterAffiliatePage?.(e.referralInfo);},children:[jsx(Text,{className:"oui-text-sm md:oui-text-base xl:oui-text-lg",children:t("affiliate.enter")}),jsx(nt,{className:"md:oui-w-[18px] md:oui-h-[18px] lg:oui-w-[20px] lg:oui-h-[20px] xl:oui-w-[24px] xl:oui-h-[24px]"})]})]})}return jsxs(Fragment,{children:[jsx(Tooltip,{content:e.wrongNetwork?t("connector.wrongNetwork.tooltip"):t("affiliate.connectWallet.tooltip"),children:e.isMobile?jsx(Button,{variant:"contained",color:"light",onClick:a=>{!e.isSignIn||e.wrongNetwork?(a.stopPropagation(),a.preventDefault(),modal.alert({title:t("common.tips"),message:jsx(Text,{intensity:54,children:e.wrongNetwork?t("connector.wrongNetwork.tooltip"):t("affiliate.connectWallet.tooltip")})})):e.becomeAnAffiliate?.();},className:!e.isSignIn||e.wrongNetwork?"oui-bg-white/[.54] oui-text-black/[.36] hover:oui-bg-white/[.54]":void 0,children:t("affiliate.asAffiliate.button")}):jsx(Button,{variant:"contained",color:"light",onClick:e.becomeAnAffiliate,disabled:!e.isSignIn||e.wrongNetwork,children:t("affiliate.asAffiliate.button")})}),jsxs(Flex,{direction:"column",justify:"between",className:"oui-h-full",itemAlign:"end",children:[jsx(Text,{className:"oui-text-base md:oui-text-lg lg:oui-text-xl 2xl:oui-text-2xl",children:t("affiliate.upTo")}),jsx(Text,{className:"oui-text-2xs oui-text-base-contrast-54 md:oui-text-xs 2xl:oui-text-sm",children:t("affiliate.commission")})]})]})})()})};var hr=()=>{let{isAffiliate:e,isLoading:t,referralInfo:r,becomeAnAffiliateUrl:a,setShowHome:o,setTab:n,wrongNetwork:i,disabledConnect:f}=y(),{state:s}=useAccount(),x=!f&&(s.status===AccountStatusEnum.EnableTrading||s.status===AccountStatusEnum.EnableTradingWithoutConnected),m=()=>{window.open(a,"_blank");},u=()=>{n("affiliate"),o(false);},{isMobile:l}=useScreen();return {isSignIn:x,isAffiliate:e,isLoading:t,referralInfo:r,onEnterAffiliatePage:u,becomeAnAffiliate:m,wrongNetwork:i,isMobile:l}};var br=()=>{let e=hr();return jsx(gr,{...e})};var Cr=e=>typeof e.overwrite=="function"?e.overwrite?.(e.state):jsxs(Flex,{id:"oui-affiliate-home-card",className:"oui-flex oui-w-full oui-flex-col oui-items-stretch oui-gap-6 xl:oui-flex-row xl:oui-gap-[36px]",children:[jsx(br,{}),jsx(pr,{})]});var wr=()=>{let e=y();return {overwrite:e.overwrite?.ref?.card,state:e}};var yr=()=>{let e=wr();return jsx(Cr,{...e})};var ve=()=>jsxs(Flex,{id:"oui-affiliate-home-page",className:cn("oui-h-lvw ","oui-font-semibold"),direction:"column",gap:4,children:[jsx(fr,{}),jsx(yr,{}),jsx(tr,{})]});var Rr=e=>{let{t}=useTranslation(),r=()=>{if(e.isAffiliate&&!e.isTrader)return jsxs(Button,{variant:"contained",color:"success",size:"sm",className:"oui-px-2 oui-flex oui-gap-1",style:{position:"absolute",top:"50%",right:"24px",transform:"translateY(-50%)"},onClick:a=>{e.anATrader();},children:[jsx(dt,{}),jsx(Text,{children:t("affiliate.asTrader.title")})]});if(!e.isAffiliate&&e.isTrader)return jsxs(Button,{variant:"contained",color:"primary",size:"sm",className:"oui-px-2 oui-flex oui-gap-1",style:{position:"absolute",top:"50%",right:"24px",transform:"translateY(-50%)"},onClick:a=>{e.anAnAffiliate();},children:[jsx(mt,{}),jsx(Text,{children:t("affiliate.asAffiliate.title")})]})};return e.isLoading?jsx("div",{className:cn("oui-max-w-[960px]",e.classNames?.loadding),children:e.splashPage?.()||jsx(ve,{})}):!e.isAffiliate&&!e.isTrader||e.showHome?jsx("div",{className:cn("oui-max-w-[960px]",e?.classNames?.home),children:jsx(ve,{})}):jsxs(TabsBase,{id:"oui-affiliate-dashboard-tab",value:e.tab,onValueChange:a=>{e.setTab(a);},className:cn("oui-w-full",e.classNames?.dashboard),children:[jsxs(TabsList,{className:cn("oui-px-6 oui-flex oui-flex-row oui-justify-start oui-h-[44px] oui-relative oui-items-end","oui-text-base md:oui-text-lg","oui-rounded-xl oui-bg-base-9","oui-border oui-border-line-6",e.isAffiliate&&e.isTrader&&"oui-justify-center"),children:[e.isAffiliate&&jsx(TabsTrigger,{id:"oui-affiliate-dashboard-tab-affiliate",value:"affiliate",children:jsxs(Flex,{direction:"row",gap:1,mb:2,children:[jsx(mt,{fillOpacity:1,fill:"currentColor",className:e.tab==="affiliate"?"oui-fill-white/[.98]":"oui-fill-white/[.36]"}),jsx(Text,{children:t("common.affiliate")})]})}),e.isTrader&&jsx(TabsTrigger,{id:"oui-affiliate-dashboard-tab-trader",value:"trader",children:jsxs(Flex,{direction:"row",gap:1,mb:2,children:[jsx(dt,{fillOpacity:1,fill:"currentColor",className:e.tab==="trader"?"oui-fill-white/[.98]":"oui-fill-white/[.36]"}),jsx(Text,{children:t("affiliate.trader")})]})}),r()]}),e.isAffiliate&&jsx(TabsContent,{value:"affiliate",className:"oui-mt-4",children:jsx(_e,{})}),e.isTrader&&jsx(TabsContent,{value:"trader",className:"oui-mt-4",children:jsx(Le,{})})]})};var Tr=()=>{let{isAffiliate:e,isTrader:t,isLoading:r,becomeAnAffiliateUrl:a,onBecomeAnAffiliate:o,showReferralPage:n,splashPage:i,showHome:f,setShowHome:s,tab:x,setTab:m}=y(),u=useMemo(()=>e&&t?x:e&&!t?"affiliate":!e&&t?"trader":"affiliate",[x,e,t]);return useEffect(()=>{let c=new URLSearchParams(window.location.search).get("tab");c&&m(c);},[window.location.search]),{setTab:m,tab:u,isAffiliate:e,isTrader:t,isLoading:r,anAnAffiliate:()=>{s(true);},anATrader:()=>{s(true);},splashPage:i,showHome:f,setShowHome:s}};var Sr=e=>{let t=Tr();return jsx(Rr,{classNames:e.classNames,...t})};var li=e=>{let{classNames:t={}}=e,{root:r,...a}=t;return jsx("div",{id:"oui-affiliate-dashboard-page",className:cn("oui-w-full oui-tracking-tight",r),children:jsx(Sr,{classNames:a})})};var ui=e=>{let{...t}=e;return jsx(Scaffold,{leftSidebar:jsx(Kl,{...t}),children:jsx(Box,{mx:3,my:6,children:e.children})})},Kl=e=>jsx(Box,{p:4,m:3,border:true,borderColor:8,r:"xl",children:jsx(SideBar,{...e})});var ci=()=>{let[e,t]=useState("/"),{t:r}=useTranslation();return {items:useMemo(()=>[{name:r("common.trading"),href:"/",icon:jsxs("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M4.883 1.5c-.166.01-.393.076-.515.173a2 2 0 0 0-.18.173L.918 6.553a.86.86 0 0 0-.168.475c0 .339.232.543.232.543l7.374 8.633c.005.006.269.301.644.296s.64-.29.644-.296l7.402-8.663s.204-.269.204-.513-.196-.517-.196-.517L13.82 1.848c-.023-.032-.076-.021-.103-.049-.033-.038-.037-.091-.077-.124-.123-.097-.267-.106-.413-.123-.04-.005-.063-.049-.103-.049h-.078zm1.745 1.582h4.744L9 5.795zm-1.675.542 2.294 2.615H3.122zm8.094 0 1.831 2.615h-4.125zM3.328 7.818h4.847v5.672zm6.497 0h4.847c-1.151 1.345-3.422 4.007-4.847 5.672z",fill:"url(#a)"}),jsx("defs",{children:jsxs("linearGradient",{id:"a",x1:"17.25",y1:"9",x2:".75",y2:"9",gradientUnits:"userSpaceOnUse",children:[jsx("stop",{stopColor:"rgb(var(--oui-gradient-brand-end))"}),jsx("stop",{offset:"1",stopColor:"rgb(var(--oui-gradient-brand-start))"})]})})]})},{name:r("common.affiliate"),href:"/affiliate",icon:jsx("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.625 4.95c0-.746.604-1.35 1.35-1.35h4.05c.746 0 1.35.604 1.35 1.35v4.62L9 12.195 5.625 9.57zm8.624 3.163-.524.407v-.96l.074.05c.193.128.346.302.45.502m-4.42 5.148L14.4 9.705v3.345a1.35 1.35 0 0 1-1.35 1.35h-8.1a1.35 1.35 0 0 1-1.35-1.35V9.705l4.571 3.556c.488.379 1.17.379 1.658 0M4.275 8.52l-.524-.407c.104-.2.257-.374.45-.503l.074-.049zm0-2.581V4.95a2.7 2.7 0 0 1 2.7-2.7h4.05a2.7 2.7 0 0 1 2.7 2.7v.989l.823.548a2.7 2.7 0 0 1 1.202 2.247v4.316a2.7 2.7 0 0 1-2.7 2.7h-8.1a2.7 2.7 0 0 1-2.7-2.7V8.734a2.7 2.7 0 0 1 1.202-2.247zM9 6.089l.111-.118.005-.005a1.08 1.08 0 0 1 1.58.004 1.223 1.223 0 0 1 0 1.668l-1.515 1.62-.004.004c-.1.102-.26.1-.358-.004l-1.516-1.62a1.223 1.223 0 0 1 0-1.668l.004-.004a1.08 1.08 0 0 1 1.58.004z",fill:"#fff",fillOpacity:".54"})})}],[r]),current:e,onItemSelect:o=>{t(o.href);}}};var ts=e=>{let t=ci();return jsx(ui,{...t,children:e.children})};
14
+ var __defProp = Object.defineProperty;
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+
20
+ // src/pages/dashboard/index.tsx
21
+ var dashboard_exports = {};
22
+ __export(dashboard_exports, {
23
+ AffiliatePage: () => AffiliatePage,
24
+ DashboardPage: () => DashboardPage,
25
+ HomePage: () => HomePage,
26
+ TraderPage: () => TraderPage
27
+ });
28
+ var AffiliateIcon = (props) => {
29
+ const { size = 16, className, ...rest } = props;
30
+ return /* @__PURE__ */ jsxs(
31
+ "svg",
32
+ {
33
+ width: size,
34
+ height: size,
35
+ viewBox: "0 0 16 16",
36
+ fill: "#fff",
37
+ fillOpacity: ".98",
38
+ xmlns: "http://www.w3.org/2000/svg",
39
+ className: props.className,
40
+ ...rest,
41
+ children: [
42
+ /* @__PURE__ */ jsx("path", { d: "M8 1.302c-3.683 0-6.655 2.985-6.667 6.667-.013 3.676 2.987 6.68 6.666 6.687s6.674-3.037 6.667-6.687c-.007-3.682-2.985-6.667-6.667-6.667m0 1.333a5.333 5.333 0 0 1 5.333 5.334c0 1.5-.625 2.852-1.622 3.821-.49-1.062-1.545-1.821-2.753-1.821H7.04c-1.207 0-2.259.75-2.75 1.812A5.3 5.3 0 0 1 2.666 7.97a5.333 5.333 0 0 1 5.333-5.334M8 3.97a2.667 2.667 0 1 0 0 5.333A2.667 2.667 0 0 0 8 3.97" }),
43
+ /* @__PURE__ */ jsx(
44
+ "path",
45
+ {
46
+ d: "M16 12.667a3.333 3.333 0 1 1-6.667 0 3.333 3.333 0 0 1 6.667 0",
47
+ fill: "#1828C3"
48
+ }
49
+ ),
50
+ /* @__PURE__ */ jsx("path", { d: "M11.917 11.433a.917.917 0 0 0-.917.917c0 .53.302 1.031.802 1.49a4.6 4.6 0 0 0 .713.53l.068.043c.05.027.117.027.167 0l.068-.042q.08-.05.177-.115c.182-.123.366-.26.536-.416.5-.459.802-.96.802-1.49a.917.917 0 0 0-.917-.917.97.97 0 0 0-.744.386.95.95 0 0 0-.756-.386" })
51
+ ]
52
+ }
53
+ );
54
+ };
55
+ var TraderIcon = (props) => {
56
+ const { size = 16, className, ...rest } = props;
57
+ return /* @__PURE__ */ jsxs(
58
+ "svg",
59
+ {
60
+ width: size,
61
+ height: size,
62
+ viewBox: "0 0 16 16",
63
+ fill: "white",
64
+ fillOpacity: "0.36",
65
+ xmlns: "http://www.w3.org/2000/svg",
66
+ className: props.className,
67
+ ...rest,
68
+ children: [
69
+ /* @__PURE__ */ jsx("path", { d: "M7.99929 1.30212C4.31735 1.30212 1.34509 4.28679 1.33262 7.96878C1.32015 11.6454 4.32042 14.6488 7.99929 14.6561C11.6782 14.6634 14.6726 11.6194 14.666 7.96878C14.6593 4.28679 11.6812 1.30212 7.99929 1.30212ZM7.99929 2.63546C10.9448 2.63546 13.3326 5.02345 13.3326 7.96878C13.3326 9.46878 12.7078 10.8208 11.7112 11.7901C11.2202 10.7281 10.1656 9.96878 8.95762 9.96878C8.71802 9.96878 7.28042 9.96878 7.04095 9.96878C5.83369 9.96878 4.78215 10.7188 4.29095 11.7814C3.29429 10.8121 2.66595 9.46878 2.66595 7.96878C2.66595 5.02345 5.05375 2.63546 7.99929 2.63546ZM7.99929 3.96879C6.52649 3.96879 5.33255 5.16279 5.33262 6.63545C5.33262 8.10812 6.52649 9.30212 7.99929 9.30212C9.47202 9.30212 10.666 8.10812 10.666 6.63545C10.666 5.16279 9.47202 3.96879 7.99929 3.96879Z" }),
70
+ /* @__PURE__ */ jsx(
71
+ "path",
72
+ {
73
+ d: "M16 12.6667C16 14.5076 14.5076 16 12.6666 16C10.8257 16 9.33331 14.5076 9.33331 12.6667C9.33331 10.8257 10.8257 9.33333 12.6666 9.33333C14.5076 9.33333 16 10.8257 16 12.6667Z",
74
+ fill: "#005A4F"
75
+ }
76
+ ),
77
+ /* @__PURE__ */ jsx(
78
+ "path",
79
+ {
80
+ d: "M14.3325 13.3345C14.3325 13.2918 14.3182 13.2473 14.2857 13.2147L13.6658 12.6002L13.4315 12.8345L13.7595 13.1678H11.3325C11.2405 13.1678 11.1658 13.2425 11.1658 13.3345C11.1658 13.4265 11.2405 13.5012 11.3325 13.5012H13.7595L13.4315 13.8345L13.6658 14.0688L14.2857 13.4543C14.3182 13.4217 14.3325 13.3772 14.3325 13.3345ZM14.1658 12.0012C14.1658 11.9092 14.0912 11.8345 13.9992 11.8345H11.572L11.9002 11.5012L11.6658 11.2668L11.046 11.8813C10.981 11.9465 10.981 12.0558 11.046 12.121L11.6658 12.7355L11.9002 12.5012L11.572 12.1678H13.9992C14.0912 12.1678 14.1658 12.0932 14.1658 12.0012Z",
81
+ fill: "white",
82
+ fillOpacity: "0.98"
83
+ }
84
+ )
85
+ ]
86
+ }
87
+ );
88
+ };
89
+ var TabTypes = /* @__PURE__ */ ((TabTypes2) => {
90
+ TabTypes2["affiliate"] = "affiliate";
91
+ TabTypes2["trader"] = "trader";
92
+ return TabTypes2;
93
+ })(TabTypes || {});
94
+ var ReferralContext = createContext(
95
+ {}
96
+ );
97
+ var useReferralContext = () => {
98
+ return useContext(ReferralContext);
99
+ };
100
+ var ReferralProvider = (props) => {
101
+ const {
102
+ becomeAnAffiliateUrl = "https://orderly.network/",
103
+ learnAffiliateUrl = "https://orderly.network/",
104
+ referralLinkUrl,
105
+ chartConfig,
106
+ overwrite,
107
+ children,
108
+ splashPage,
109
+ onBecomeAnAffiliate,
110
+ bindReferralCodeState,
111
+ onLearnAffiliate,
112
+ showReferralPage
113
+ } = props;
114
+ const { state } = useAccount();
115
+ const {
116
+ data,
117
+ mutate: referralInfoMutate,
118
+ isLoading
119
+ } = usePrivateQuery("/v1/referral/info", {
120
+ revalidateOnFocus: true,
121
+ errorRetryCount: 3,
122
+ ...noCacheConfig
123
+ });
124
+ const { data: generateCode, mutate: generateCodeMutate } = usePrivateQuery(
125
+ "/v1/referral/auto_referral/progress",
126
+ {
127
+ revalidateOnFocus: true,
128
+ errorRetryCount: 2,
129
+ formatter: (data2) => {
130
+ return {
131
+ code: data2.auto_referral_code,
132
+ requireVolume: data2.required_volume,
133
+ completedVolume: data2.completed_volume
134
+ };
135
+ }
136
+ }
137
+ );
138
+ const [showHome, setShowHome] = useState(isLoading);
139
+ useEffect(() => {
140
+ setShowHome(true);
141
+ }, [isLoading]);
142
+ const { data: dailyVolume, mutate: dailyVolumeMutate } = useDaily({
143
+ startDate: subDays(/* @__PURE__ */ new Date(), 1),
144
+ endDate: subDays(/* @__PURE__ */ new Date(), 90)
145
+ });
146
+ const { data: volumeStatistics, mutate: volumeStatisticsMutate } = usePrivateQuery("/v1/volume/user/stats", {
147
+ revalidateOnFocus: true
148
+ });
149
+ const isAffiliate = useMemo(() => {
150
+ return (data?.referrer_info?.referral_codes?.length || 0) > 0;
151
+ }, [data?.referrer_info]);
152
+ const isTrader = useMemo(() => {
153
+ return (data?.referee_info?.referer_code?.length || 0) > 0;
154
+ }, [data?.referee_info]);
155
+ const userVolume = useMemo(() => {
156
+ const volume = {};
157
+ if (dailyVolume && dailyVolume.length > 0) {
158
+ const now = format(/* @__PURE__ */ new Date(), "yyyy-MM-dd");
159
+ const index = dailyVolume.findIndex((item) => item.date === now);
160
+ let oneDayVolume = 0;
161
+ if (index !== -1) {
162
+ oneDayVolume = dailyVolume[index].perp_volume;
163
+ }
164
+ volume["1d_volume"] = oneDayVolume;
165
+ }
166
+ if (volumeStatistics) {
167
+ volume["7d_volume"] = volumeStatistics.perp_volume_last_7_days;
168
+ volume["30d_volume"] = volumeStatistics.perp_volume_last_30_days;
169
+ volume["all_volume"] = volumeStatistics.perp_volume_ltd;
170
+ }
171
+ return volume;
172
+ }, [dailyVolume, volumeStatistics]);
173
+ useEffect(() => {
174
+ if (isAffiliate || isTrader) {
175
+ setShowHome(false);
176
+ }
177
+ }, [isAffiliate, isTrader]);
178
+ const memoMutate = useMemoizedFn(() => {
179
+ volumeStatisticsMutate();
180
+ dailyVolumeMutate();
181
+ referralInfoMutate();
182
+ generateCodeMutate();
183
+ });
184
+ useEffect(() => {
185
+ const searchParams = new URLSearchParams(window.location.search);
186
+ const refCode = searchParams.get("ref");
187
+ if (refCode) {
188
+ localStorage.setItem("referral_code", refCode);
189
+ }
190
+ }, []);
191
+ const [tab, setTab] = useState(() => {
192
+ const savedTab = localStorage.getItem("orderly_affiliate_dashboard_tab");
193
+ return savedTab || "affiliate" /* affiliate */;
194
+ });
195
+ useEffect(() => {
196
+ localStorage.setItem("orderly_affiliate_dashboard_tab", tab);
197
+ }, [tab]);
198
+ const { wrongNetwork, disabledConnect } = useAppContext();
199
+ const lastStete = useRef(AccountStatusEnum.NotConnected);
200
+ const timerRef = useRef(null);
201
+ useEffect(() => {
202
+ if (lastStete.current !== state.status) {
203
+ lastStete.current = state.status;
204
+ timerRef.current = setTimeout(() => {
205
+ memoMutate();
206
+ }, 1e3);
207
+ }
208
+ return () => {
209
+ if (timerRef.current) {
210
+ clearTimeout(timerRef.current);
211
+ }
212
+ };
213
+ }, [memoMutate, state.status]);
214
+ const memoizedValue = useMemo(() => {
215
+ return {
216
+ generateCode,
217
+ showHome,
218
+ referralInfo: data,
219
+ isAffiliate,
220
+ isTrader,
221
+ tab,
222
+ becomeAnAffiliateUrl,
223
+ learnAffiliateUrl,
224
+ referralLinkUrl,
225
+ userVolume,
226
+ dailyVolume,
227
+ chartConfig,
228
+ overwrite,
229
+ isLoading,
230
+ wrongNetwork,
231
+ disabledConnect,
232
+ setShowHome,
233
+ setTab,
234
+ mutate: memoMutate,
235
+ onBecomeAnAffiliate,
236
+ bindReferralCodeState,
237
+ onLearnAffiliate,
238
+ showReferralPage,
239
+ splashPage
240
+ };
241
+ }, [
242
+ becomeAnAffiliateUrl,
243
+ chartConfig,
244
+ dailyVolume,
245
+ data,
246
+ disabledConnect,
247
+ generateCode,
248
+ isAffiliate,
249
+ isLoading,
250
+ isTrader,
251
+ learnAffiliateUrl,
252
+ overwrite,
253
+ referralLinkUrl,
254
+ showHome,
255
+ tab,
256
+ userVolume,
257
+ wrongNetwork,
258
+ onBecomeAnAffiliate,
259
+ bindReferralCodeState,
260
+ onLearnAffiliate,
261
+ showReferralPage,
262
+ splashPage,
263
+ memoMutate
264
+ ]);
265
+ return /* @__PURE__ */ jsx(ReferralContext.Provider, { value: memoizedValue, children });
266
+ };
267
+ var USDCIcon = (props) => {
268
+ return /* @__PURE__ */ jsxs(
269
+ "svg",
270
+ {
271
+ width: "21",
272
+ height: "20",
273
+ viewBox: "0 0 21 20",
274
+ fill: "none",
275
+ xmlns: "http://www.w3.org/2000/svg",
276
+ className: props.className,
277
+ children: [
278
+ /* @__PURE__ */ jsxs("g", { clipPath: "url(#a)", children: [
279
+ /* @__PURE__ */ jsx(
280
+ "path",
281
+ {
282
+ d: "M10.5 20c5.542 0 10-4.458 10-10s-4.458-10-10-10S.5 4.458.5 10s4.458 10 10 10",
283
+ fill: "#2775CA"
284
+ }
285
+ ),
286
+ /* @__PURE__ */ jsx(
287
+ "path",
288
+ {
289
+ d: "M13.5 11.473c0-1.452-.94-1.95-2.82-2.158-1.344-.166-1.613-.498-1.613-1.078s.448-.955 1.343-.955c.806 0 1.254.25 1.478.872.045.124.18.207.313.207h.717c.179 0 .313-.125.313-.29v-.042c-.179-.913-.985-1.618-2.015-1.701v-.996c0-.166-.134-.29-.358-.332h-.671c-.18 0-.314.124-.359.332v.954c-1.343.166-2.194.996-2.194 2.034 0 1.369.896 1.908 2.776 2.116 1.254.207 1.657.456 1.657 1.12s-.627 1.12-1.477 1.12c-1.165 0-1.568-.456-1.702-1.078a.32.32 0 0 0-.313-.25h-.762c-.179 0-.313.125-.313.291v.042c.179 1.037.895 1.784 2.373 1.991v.996c0 .166.134.29.358.332h.672c.18 0 .313-.124.358-.332v-.996c1.344-.207 2.239-1.079 2.239-2.199",
290
+ fill: "#fff",
291
+ fillOpacity: ".98"
292
+ }
293
+ ),
294
+ /* @__PURE__ */ jsx(
295
+ "path",
296
+ {
297
+ d: "M8.24 16.57c-3.458-1.215-5.23-4.986-3.945-8.324.665-1.821 2.127-3.208 3.944-3.859.178-.086.266-.216.266-.433v-.607c0-.174-.088-.304-.266-.347-.044 0-.133 0-.177.043-4.21 1.3-6.516 5.68-5.186 9.798.798 2.428 2.704 4.292 5.186 5.072.177.087.355 0 .4-.173.043-.043.043-.087.043-.173v-.608c0-.13-.133-.303-.266-.39m4.698-13.527c-.178-.086-.355 0-.4.174-.043.043-.043.086-.043.173v.607c0 .174.133.347.266.434 3.457 1.213 5.23 4.985 3.944 8.323-.664 1.821-2.127 3.209-3.944 3.859-.178.086-.266.216-.266.433v.607c0 .174.088.304.266.347.044 0 .133 0 .177-.043 4.21-1.3 6.515-5.68 5.186-9.798-.798-2.471-2.748-4.335-5.186-5.116",
298
+ fill: "#fff",
299
+ fillOpacity: ".98"
300
+ }
301
+ )
302
+ ] }),
303
+ /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("clipPath", { id: "a", children: /* @__PURE__ */ jsx("path", { fill: "#fff", d: "M.5 0h20v20H.5z" }) }) })
304
+ ]
305
+ }
306
+ );
307
+ };
308
+ var Summary = (props) => {
309
+ const { t } = useTranslation();
310
+ return /* @__PURE__ */ jsxs(
311
+ Flex,
312
+ {
313
+ id: "oui-affiliate-affiliate-summary",
314
+ r: "2xl",
315
+ p: 6,
316
+ width: "100%",
317
+ height: "100%",
318
+ gap: 4,
319
+ direction: "column",
320
+ className: "oui-bg-base-9",
321
+ children: [
322
+ /* @__PURE__ */ jsx(Title, { ...props }),
323
+ /* @__PURE__ */ jsx(CommissionData, { ...props }),
324
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", width: "100%", gap: 2, children: [
325
+ /* @__PURE__ */ jsx(
326
+ Row,
327
+ {
328
+ title: `${t("affiliate.referralVol")} (USDC)`,
329
+ value: props.referralVol,
330
+ dp: 2,
331
+ ...props
332
+ }
333
+ ),
334
+ /* @__PURE__ */ jsx(
335
+ Row,
336
+ {
337
+ title: t("affiliate.referees"),
338
+ value: props.referees,
339
+ dp: 0,
340
+ ...props
341
+ }
342
+ ),
343
+ /* @__PURE__ */ jsx(
344
+ Row,
345
+ {
346
+ title: t("affiliate.summary.refereesTraded"),
347
+ value: props.refereesTades,
348
+ dp: 0,
349
+ ...props
350
+ }
351
+ )
352
+ ] })
353
+ ]
354
+ }
355
+ );
356
+ };
357
+ var Title = (props) => {
358
+ const { t } = useTranslation();
359
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", justify: "between", width: "100%", children: [
360
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-lg", children: t("affiliate.summary") }),
361
+ /* @__PURE__ */ jsx("div", { className: "oui-min-w-14", children: /* @__PURE__ */ jsx(
362
+ Select.options,
363
+ {
364
+ size: "xs",
365
+ value: props.period,
366
+ onValueChange: props.onPeriodChange,
367
+ options: props.periodTypes
368
+ }
369
+ ) })
370
+ ] });
371
+ };
372
+ var CommissionData = (props) => {
373
+ const { t } = useTranslation();
374
+ return /* @__PURE__ */ jsxs(
375
+ Flex,
376
+ {
377
+ gradient: "primary",
378
+ angle: 180,
379
+ r: "xl",
380
+ py: 4,
381
+ px: 6,
382
+ width: "100%",
383
+ direction: "column",
384
+ gap: 3,
385
+ height: "100%",
386
+ className: "oui-max-h-[104px]",
387
+ children: [
388
+ /* @__PURE__ */ jsx(Text, { intensity: 54, className: "oui-text-base 2xl:oui-text-lg", children: `${t("affiliate.commission")} (USDC)` }),
389
+ /* @__PURE__ */ jsxs(
390
+ Flex,
391
+ {
392
+ direction: "row",
393
+ gap: 3,
394
+ className: "oui-text-xl md:oui-text-2xl xl:oui-text-3xl",
395
+ children: [
396
+ /* @__PURE__ */ jsx(USDCIcon, { className: "md:oui-w-[24px] md:oui-h-[24px] lg:oui-w-[28px] lg:oui-h-[28px] " }),
397
+ /* @__PURE__ */ jsx(Text, { children: commifyOptional(props.commission, { fix: 2, fallback: "0" }) })
398
+ ]
399
+ }
400
+ )
401
+ ]
402
+ }
403
+ );
404
+ };
405
+ var Row = (props) => {
406
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", justify: "between", width: "100%", children: [
407
+ /* @__PURE__ */ jsx(
408
+ Text,
409
+ {
410
+ intensity: 54,
411
+ className: "oui-text-2xs md:oui-text-xs xl:oui-text-sm",
412
+ children: props.title
413
+ }
414
+ ),
415
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-xs md:oui-text-sm xl:oui-text-base", children: commifyOptional(props.value, { fix: props.dp, fallback: "0" }) })
416
+ ] });
417
+ };
418
+ var useSummaryScript = () => {
419
+ const { t } = useTranslation();
420
+ const [period, setPeriod] = useState("All");
421
+ const periodTypes = [
422
+ { label: t("common.all"), value: "All" },
423
+ { label: t("common.select.1d"), value: "1D" },
424
+ { label: t("common.select.7d"), value: "7D" },
425
+ { label: t("common.select.30d"), value: "30D" }
426
+ ];
427
+ const { referralInfo } = useReferralContext();
428
+ const commission = useMemo(() => {
429
+ if (!referralInfo || !referralInfo.referrer_info) {
430
+ return 0;
431
+ }
432
+ switch (period) {
433
+ case "All":
434
+ return referralInfo.referrer_info.total_referrer_rebate;
435
+ case "1D":
436
+ return referralInfo.referrer_info["1d_referrer_rebate"];
437
+ case "7D":
438
+ return referralInfo.referrer_info["7d_referrer_rebate"];
439
+ case "30D":
440
+ return referralInfo.referrer_info["30d_referrer_rebate"];
441
+ }
442
+ }, [referralInfo, period]);
443
+ const referralVol = useMemo(() => {
444
+ if (!referralInfo || !referralInfo.referrer_info) {
445
+ return 0;
446
+ }
447
+ switch (period) {
448
+ case "All":
449
+ return referralInfo.referrer_info.total_referee_volume;
450
+ case "1D":
451
+ return referralInfo.referrer_info["1d_referee_volume"];
452
+ case "7D":
453
+ return referralInfo.referrer_info["7d_referee_volume"];
454
+ case "30D":
455
+ return referralInfo.referrer_info["30d_referee_volume"];
456
+ }
457
+ }, [referralInfo, period]);
458
+ const referees = useMemo(() => {
459
+ if (!referralInfo || !referralInfo.referrer_info) {
460
+ return 0;
461
+ }
462
+ switch (period) {
463
+ case "All":
464
+ return referralInfo.referrer_info.total_invites;
465
+ case "1D":
466
+ return referralInfo.referrer_info["1d_invites"];
467
+ case "7D":
468
+ return referralInfo.referrer_info["7d_invites"];
469
+ case "30D":
470
+ return referralInfo.referrer_info["30d_invites"];
471
+ }
472
+ }, [referralInfo, period]);
473
+ const refereesTades = useMemo(() => {
474
+ if (!referralInfo || !referralInfo.referrer_info) {
475
+ return 0;
476
+ }
477
+ switch (period) {
478
+ case "All":
479
+ return referralInfo.referrer_info.total_traded;
480
+ case "1D":
481
+ return referralInfo.referrer_info["1d_traded"];
482
+ case "7D":
483
+ return referralInfo.referrer_info["7d_traded"];
484
+ case "30D":
485
+ return referralInfo.referrer_info["30d_traded"];
486
+ }
487
+ }, [referralInfo, period]);
488
+ const onPeriodChange = (item) => {
489
+ setPeriod(item);
490
+ };
491
+ return {
492
+ period,
493
+ periodTypes,
494
+ onPeriodChange,
495
+ commission,
496
+ referralVol,
497
+ referees,
498
+ refereesTades
499
+ };
500
+ };
501
+ var SummaryWidget = () => {
502
+ const state = useSummaryScript();
503
+ return /* @__PURE__ */ jsx(Summary, { ...state });
504
+ };
505
+ var AutoHideText = (props) => {
506
+ const { text, visibleCount } = props;
507
+ const containerRef = useRef(null);
508
+ const textRef = useRef(null);
509
+ const lastContainerWidth = useRef(void 0);
510
+ function getTextWidth(ref, text2) {
511
+ const canvas = document.createElement("canvas");
512
+ const context = canvas.getContext("2d");
513
+ const element = ref;
514
+ if (context && element) {
515
+ let fontStyle = getComputedStyle(element).font;
516
+ if (fontStyle.length === 0) {
517
+ fontStyle = [
518
+ getComputedStyle(element).fontWeight,
519
+ getComputedStyle(element).fontSize,
520
+ getComputedStyle(element).fontFamily
521
+ ].join(" ");
522
+ }
523
+ context.font = fontStyle;
524
+ context.letterSpacing = getComputedStyle(element).letterSpacing;
525
+ const width = context.measureText(text2).width;
526
+ return width;
527
+ }
528
+ return void 0;
529
+ }
530
+ const [visibleChars, setVisibleChars] = useState(0);
531
+ useEffect(() => {
532
+ const calculateVisibleChars = () => {
533
+ if (props.visibleCount !== void 0)
534
+ return;
535
+ if (containerRef.current && textRef.current) {
536
+ const containerWidth = containerRef.current.clientWidth;
537
+ if (containerWidth == lastContainerWidth.current)
538
+ return;
539
+ lastContainerWidth.current = containerWidth;
540
+ const textElement = textRef.current;
541
+ const textContent = text;
542
+ const pWidth = Math.ceil(getTextWidth(textElement, "...") || 0);
543
+ const maxDisplayW = containerWidth - pWidth;
544
+ let count = 0;
545
+ while (count < text.length) {
546
+ let contentW = getTextWidth(textElement, subText(text, count++)) || maxDisplayW;
547
+ if (contentW <= maxDisplayW) {
548
+ break;
549
+ }
550
+ }
551
+ setVisibleChars(textContent.length - count);
552
+ }
553
+ };
554
+ lastContainerWidth.current = void 0;
555
+ calculateVisibleChars();
556
+ window.addEventListener("resize", calculateVisibleChars);
557
+ return () => {
558
+ lastContainerWidth.current = void 0;
559
+ window.removeEventListener("resize", calculateVisibleChars);
560
+ };
561
+ }, [text, textRef]);
562
+ const truncatedText = useMemo(() => {
563
+ if (visibleChars + 1 >= text.length) {
564
+ return text;
565
+ }
566
+ const maxCharacters = visibleCount || visibleChars;
567
+ const startText = text.slice(0, Math.ceil(maxCharacters / 2));
568
+ const endText = text.slice(
569
+ text.length - Math.floor(maxCharacters / 2),
570
+ text.length
571
+ );
572
+ return `${startText}...${endText}`;
573
+ }, [text, visibleCount, visibleChars]);
574
+ return /* @__PURE__ */ jsxs("div", { ref: containerRef, className: cn("oui-relative oui-w-full oui-text-end", props.className), children: [
575
+ /* @__PURE__ */ jsx(
576
+ "div",
577
+ {
578
+ className: cn(
579
+ "oui-hidden oui-whitespace-nowrap oui-absolute oui-top-0 oui-bottom-0 oui-right-0 oui-left-0"
580
+ ),
581
+ children: /* @__PURE__ */ jsx("span", { ref: textRef, children: text })
582
+ }
583
+ ),
584
+ /* @__PURE__ */ jsx("span", { children: truncatedText })
585
+ ] });
586
+ };
587
+ var subText = (text, count) => {
588
+ const start = Math.floor(text.length / 2 - (count > 0 ? count / 2 : 1));
589
+ const first = text.slice(0, start);
590
+ const end = text.slice(start + count);
591
+ return first + end;
592
+ };
593
+ var ReferralLink = (props) => {
594
+ const { t } = useTranslation();
595
+ return /* @__PURE__ */ jsxs(
596
+ Flex,
597
+ {
598
+ id: "oui-affiliate-affiliate-referralLink",
599
+ r: "2xl",
600
+ p: 6,
601
+ width: "100%",
602
+ gap: 4,
603
+ direction: "column",
604
+ className: "oui-bg-base-9",
605
+ children: [
606
+ /* @__PURE__ */ jsx(Title2, { ...props }),
607
+ /* @__PURE__ */ jsxs(
608
+ Flex,
609
+ {
610
+ width: "100%",
611
+ className: "oui-flex oui-flex-col 3xl:oui-flex-row",
612
+ gap: 4,
613
+ children: [
614
+ /* @__PURE__ */ jsx("div", { className: "oui-w-full 3xl:oui-w-1/3", children: /* @__PURE__ */ jsx(Subtitle, { ...props }) }),
615
+ /* @__PURE__ */ jsxs(
616
+ Flex,
617
+ {
618
+ direction: "column",
619
+ width: "100%",
620
+ className: "3xl:oui-w-2/3 3xl:oui-gap-2",
621
+ children: [
622
+ /* @__PURE__ */ jsx(
623
+ Input,
624
+ {
625
+ title: t("affiliate.referralCode"),
626
+ value: props.refCode,
627
+ ...props
628
+ }
629
+ ),
630
+ /* @__PURE__ */ jsx(
631
+ Input,
632
+ {
633
+ title: t("affiliate.referralLink"),
634
+ value: props.refLink,
635
+ ...props
636
+ }
637
+ )
638
+ ]
639
+ }
640
+ )
641
+ ]
642
+ }
643
+ )
644
+ ]
645
+ }
646
+ );
647
+ };
648
+ var Title2 = (props) => {
649
+ const { t } = useTranslation();
650
+ return /* @__PURE__ */ jsx(Flex, { direction: "row", justify: "between", width: "100%", children: /* @__PURE__ */ jsx(Text, { className: "oui-text-lg", children: t("affiliate.referralLink") }) });
651
+ };
652
+ var Subtitle = (props) => {
653
+ const { t } = useTranslation();
654
+ const item = (title, value, gradient, className, tooltip) => {
655
+ const valueClsName = "oui-text-lg md:oui-text-xl lg:oui-text-2xl xl:oui-text-3xl";
656
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", itemAlign: "start", className, children: [
657
+ /* @__PURE__ */ jsx(Flex, { direction: "row", gap: 2, children: /* @__PURE__ */ jsx(Alert, { title, tooltip }) }),
658
+ gradient ? /* @__PURE__ */ jsx(Text.gradient, { color: "brand", className: valueClsName, children: value }) : /* @__PURE__ */ jsx(Text, { className: valueClsName, children: value })
659
+ ] });
660
+ };
661
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", width: "100%", children: [
662
+ item(
663
+ t("affiliate.referralLink.earn"),
664
+ props.earn || "-",
665
+ true,
666
+ "oui-flex-1",
667
+ /* @__PURE__ */ jsxs("span", { children: [
668
+ /* @__PURE__ */ jsx(Text.gradient, { color: "brand", children: props.earn || "-" }),
669
+ " ",
670
+ t("affiliate.referralLink.earn.tooltip", {
671
+ brokerName: props.brokerName
672
+ })
673
+ ] })
674
+ // @ts-ignore
675
+ // <Trans
676
+ // i18nKey="affiliate.referralLink.earn.tooltip"
677
+ // values={{
678
+ // value: props.earn || "-",
679
+ // brokerName: props.brokerName,
680
+ // }}
681
+ // components={[<Text.gradient color="brand" />]}
682
+ // />
683
+ ),
684
+ item(
685
+ t("affiliate.referralLink.share"),
686
+ props.share || "-",
687
+ false,
688
+ "oui-flex-1",
689
+ // @ts-ignore
690
+ /* @__PURE__ */ jsx(
691
+ Trans,
692
+ {
693
+ i18nKey: "affiliate.referralLink.share.tooltip",
694
+ values: {
695
+ value: props.share || "-",
696
+ brokerName: props.brokerName
697
+ },
698
+ components: [/* @__PURE__ */ jsx(Text.gradient, { color: "brand" })]
699
+ }
700
+ )
701
+ )
702
+ ] });
703
+ };
704
+ var Input = (props) => {
705
+ const { title, value = "-" } = props;
706
+ return /* @__PURE__ */ jsxs(
707
+ Flex,
708
+ {
709
+ r: "xl",
710
+ p: 3,
711
+ gap: 4,
712
+ direction: "row",
713
+ width: "100%",
714
+ className: "oui-bg-base-8",
715
+ children: [
716
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-base-contrast-54 oui-flex-shrink oui-text-2xs md:oui-text-xs xl:oui-text-sm", children: title }),
717
+ /* @__PURE__ */ jsxs(
718
+ Flex,
719
+ {
720
+ direction: "row",
721
+ justify: "end",
722
+ gap: 2,
723
+ className: "oui-flex-1 oui-text-xs md:oui-text-sm xl:oui-text-base",
724
+ children: [
725
+ /* @__PURE__ */ jsx(AutoHideText, { text: value }),
726
+ /* @__PURE__ */ jsx(
727
+ "button",
728
+ {
729
+ className: "oui-cursor-pointer oui-text-sm oui-flex-shrink",
730
+ onClick: () => {
731
+ navigator.clipboard.writeText(value);
732
+ props.onCopy?.(value);
733
+ },
734
+ children: /* @__PURE__ */ jsx(
735
+ CopyIcon,
736
+ {
737
+ size: 12,
738
+ color: "white",
739
+ className: "oui-w-[13px] oui-h-[13px] md:oui-w-[14px] md:oui-h-[14px] xl:oui-w-4 xl:oui-h-4"
740
+ }
741
+ )
742
+ }
743
+ )
744
+ ]
745
+ }
746
+ )
747
+ ]
748
+ }
749
+ );
750
+ };
751
+ var Alert = (props) => {
752
+ return /* @__PURE__ */ jsx(Tooltip, { content: props.tooltip, className: "oui-max-w-[200px]", children: /* @__PURE__ */ jsx(
753
+ "div",
754
+ {
755
+ onClick: () => {
756
+ modal.alert({
757
+ title: props.title,
758
+ message: /* @__PURE__ */ jsx("div", { className: "oui-text-base-contrast/30 oui-space-y-3 oui-text-xs desktop:oui-text-xs", children: props.tooltip })
759
+ });
760
+ },
761
+ children: /* @__PURE__ */ jsxs(Flex, { direction: "column", children: [
762
+ /* @__PURE__ */ jsx(
763
+ Text,
764
+ {
765
+ intensity: 54,
766
+ className: "oui-text-2xs md:oui-text-xs xl:oui-text-sm",
767
+ children: props.title
768
+ }
769
+ ),
770
+ /* @__PURE__ */ jsx(Divider, { className: "oui-w-full", lineStyle: "dotted", intensity: 16 })
771
+ ] })
772
+ }
773
+ ) });
774
+ };
775
+ function generateReferralLink(referralLinkUrl, code) {
776
+ return `${referralLinkUrl || window?.location?.origin}?ref=${code}`;
777
+ }
778
+ async function copyText(content) {
779
+ try {
780
+ await navigator.clipboard.writeText(content);
781
+ toast.success(i18n.t("common.copy.copied"));
782
+ } catch (error) {
783
+ toast.success(i18n.t("common.copy.failed"));
784
+ }
785
+ }
786
+ function formatDateTimeToUTC(input) {
787
+ if (input === void 0) {
788
+ return "";
789
+ }
790
+ const date = toDate(input);
791
+ const utcDate = toUTCDate(date);
792
+ return format(utcDate, "yyyy-MM-dd HH:mm:ss 'UTC'");
793
+ }
794
+ function formatYMDTime(time) {
795
+ if (time === void 0) {
796
+ return void 0;
797
+ }
798
+ const date = toDate(time);
799
+ const utcDate = toUTCDate(date);
800
+ return format(utcDate, "yyyy-MM-dd");
801
+ }
802
+ function compareDate(d1, d2) {
803
+ const isEqual = d1 && d2 && d1.toISOString().substring(0, 10) === d2.toISOString().substring(0, 10);
804
+ return isEqual;
805
+ }
806
+ function toUTCDate(date) {
807
+ return new Date(date.toUTCString());
808
+ }
809
+
810
+ // src/pages/affiliate/referralLink/referralLink.script.tsx
811
+ var useReferralLinkScript = () => {
812
+ const { t } = useTranslation();
813
+ const onCopy = (value) => {
814
+ toast.success(t("common.copy.copied"));
815
+ };
816
+ const { referralInfo, referralLinkUrl, overwrite } = useReferralContext();
817
+ const [pinCodes, setPinCodes] = useLocalStorage(
818
+ "orderly_referral_codes",
819
+ []
820
+ );
821
+ const codes = useMemo(() => {
822
+ if (!referralInfo?.referrer_info?.referral_codes)
823
+ return [];
824
+ const referralCodes = [...referralInfo?.referrer_info?.referral_codes];
825
+ const pinedItems = [];
826
+ for (let i = 0; i < pinCodes.length; i++) {
827
+ const code2 = pinCodes[i];
828
+ const index = referralCodes.findIndex((item) => item.code === code2);
829
+ if (index !== -1) {
830
+ pinedItems.push({ ...referralCodes[index] });
831
+ referralCodes.splice(index, 1);
832
+ }
833
+ }
834
+ return [...pinedItems, ...referralCodes];
835
+ }, [referralInfo?.referrer_info?.referral_codes, pinCodes]);
836
+ const firstCode = useMemo(() => {
837
+ if (codes.length === 0) {
838
+ return void 0;
839
+ }
840
+ return codes[0];
841
+ }, [codes]);
842
+ const code = useMemo(() => {
843
+ return firstCode?.code;
844
+ }, [firstCode]);
845
+ const referralLink = useMemo(() => {
846
+ if (!firstCode)
847
+ return "";
848
+ return generateReferralLink(referralLinkUrl, firstCode.code);
849
+ }, [firstCode]);
850
+ const earn = useMemo(() => {
851
+ const value = new Decimal(firstCode?.referrer_rebate_rate || "0").mul(100).toDecimalPlaces(0, Decimal.ROUND_DOWN).toString();
852
+ return `${value}%`;
853
+ }, [firstCode?.referrer_rebate_rate]);
854
+ const share = useMemo(() => {
855
+ const value = new Decimal(firstCode?.referee_rebate_rate || "0").mul(100).toDecimalPlaces(0, Decimal.ROUND_DOWN).toString();
856
+ return `${value}%`;
857
+ }, [firstCode?.referee_rebate_rate]);
858
+ return {
859
+ onCopy,
860
+ refLink: referralLink,
861
+ refCode: code,
862
+ share,
863
+ earn,
864
+ brokerName: overwrite?.brokerName ?? overwrite?.shortBrokerName
865
+ };
866
+ };
867
+ var ReferralLinkWidget = () => {
868
+ const state = useReferralLinkScript();
869
+ return /* @__PURE__ */ jsx(ReferralLink, { ...state });
870
+ };
871
+ var TitleStatistic = (props) => {
872
+ return /* @__PURE__ */ jsxs(
873
+ Flex,
874
+ {
875
+ id: "oui-affiliate-affiliate-titleStatistic",
876
+ r: "2xl",
877
+ p: 6,
878
+ width: "100%",
879
+ gap: 4,
880
+ direction: "column",
881
+ className: "oui-bg-base-9",
882
+ children: [
883
+ /* @__PURE__ */ jsx(Title3, { ...props }),
884
+ /* @__PURE__ */ jsx(Flex, { className: "oui-h-[170px] 2xl:oui-h-[196px] oui-w-full oui-flex oui-flex-row oui-items-stretch", children: /* @__PURE__ */ jsx(
885
+ VolBarChart,
886
+ {
887
+ data: props.dataSource || EMPTY_LIST,
888
+ colors: { fill: "rgba(0, 180, 158, 1)" },
889
+ className: "oui-w-full oui-flex-1",
890
+ tooltip: {
891
+ rm: Decimal.ROUND_DOWN,
892
+ dp: props.volType === "Commission" ? 6 : 2
893
+ }
894
+ }
895
+ ) })
896
+ ]
897
+ }
898
+ );
899
+ };
900
+ var Title3 = (props) => {
901
+ const { t } = useTranslation();
902
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", justify: "between", width: "100%", children: [
903
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-lg", children: t("affiliate.statistics") }),
904
+ /* @__PURE__ */ jsxs(Flex, { direction: "row", gap: 2, className: "oui-min-w-14", children: [
905
+ /* @__PURE__ */ jsx(
906
+ Select.options,
907
+ {
908
+ size: "xs",
909
+ value: props.period,
910
+ onValueChange: props.onPeriodChange,
911
+ options: props.periodTypes
912
+ }
913
+ ),
914
+ /* @__PURE__ */ jsx(
915
+ Select.options,
916
+ {
917
+ size: "xs",
918
+ value: props.volType,
919
+ onValueChange: props.onVolTypeChange,
920
+ options: props.volTypes
921
+ }
922
+ )
923
+ ] })
924
+ ] });
925
+ };
926
+ function fillData(days, origin) {
927
+ const now = Date();
928
+ const result = new Array(days).fill(0).map((_, index) => {
929
+ return {
930
+ date: format(subDays(now, index + 1), "yyyy-MM-dd"),
931
+ volume: 0,
932
+ opacity: 0
933
+ };
934
+ }).reverse();
935
+ const dataObject = origin?.reduce(
936
+ (acc, curr) => {
937
+ acc[curr.date] = curr;
938
+ return acc;
939
+ },
940
+ {}
941
+ );
942
+ for (let index = 0; index < result.length; index++) {
943
+ const element = result[index];
944
+ const originData = dataObject?.[element.date];
945
+ if (originData) {
946
+ result[index] = { ...originData, opacity: originData.volume > 0 ? 1 : 0 };
947
+ }
948
+ }
949
+ return result;
950
+ }
951
+ var useTitleStatisticScript = () => {
952
+ const { t } = useTranslation();
953
+ const [period, setPeriod] = useState("7");
954
+ const periodTypes = [
955
+ { label: t("common.select.7d"), value: "7" },
956
+ { label: t("common.select.30d"), value: "30" },
957
+ { label: t("common.select.90d"), value: "90" }
958
+ ];
959
+ const onPeriodChange = (item) => {
960
+ setPeriod(item);
961
+ };
962
+ const [volType, setVolType] = useState("Commission");
963
+ const volTypes = [
964
+ { label: t("affiliate.commission"), value: "Commission" },
965
+ { label: t("affiliate.referralVol"), value: "ref" }
966
+ ];
967
+ const onVolTypeChange = (item) => {
968
+ setVolType(item);
969
+ };
970
+ const dateRange = useMemo(() => {
971
+ if (period === "7") {
972
+ return {
973
+ startDate: subDays(/* @__PURE__ */ new Date(), 7),
974
+ endDate: subDays(/* @__PURE__ */ new Date(), 1)
975
+ };
976
+ } else if (period === "30") {
977
+ return {
978
+ startDate: subDays(/* @__PURE__ */ new Date(), 30),
979
+ endDate: subDays(/* @__PURE__ */ new Date(), 1)
980
+ };
981
+ } else if (period === "90") {
982
+ return {
983
+ startDate: subDays(/* @__PURE__ */ new Date(), 90),
984
+ endDate: subDays(/* @__PURE__ */ new Date(), 1)
985
+ };
986
+ } else {
987
+ return {
988
+ startDate: subDays(/* @__PURE__ */ new Date(), 7),
989
+ endDate: subDays(/* @__PURE__ */ new Date(), 1)
990
+ };
991
+ }
992
+ }, [period]);
993
+ const [rebateSummary] = useReferralRebateSummary({
994
+ startDate: format(dateRange.startDate, "yyyy-MM-dd"),
995
+ endDate: format(dateRange.endDate, "yyyy-MM-dd"),
996
+ size: Number(period)
997
+ });
998
+ const dataSource = useMemo(() => {
999
+ return (rebateSummary?.map(
1000
+ (e) => ({
1001
+ date: e.date,
1002
+ volume: volType === "Commission" ? e.referral_rebate : e.volume
1003
+ })
1004
+ ) || []).reverse();
1005
+ }, [rebateSummary, volType]);
1006
+ return {
1007
+ period,
1008
+ periodTypes,
1009
+ onPeriodChange,
1010
+ volType,
1011
+ volTypes,
1012
+ onVolTypeChange,
1013
+ dataSource: fillData(Number(period), dataSource)
1014
+ };
1015
+ };
1016
+ var TitleStatisticWidget = () => {
1017
+ const state = useTitleStatisticScript();
1018
+ return /* @__PURE__ */ jsx(TitleStatistic, { ...state });
1019
+ };
1020
+ var EditIcon = (props) => {
1021
+ const { className, ...rest } = props;
1022
+ return /* @__PURE__ */ jsx(
1023
+ "svg",
1024
+ {
1025
+ width: "12",
1026
+ height: "13",
1027
+ viewBox: "0 0 12 13",
1028
+ xmlns: "http://www.w3.org/2000/svg",
1029
+ fill: "white",
1030
+ fillOpacity: "0.36",
1031
+ className,
1032
+ ...rest,
1033
+ children: /* @__PURE__ */ jsx("path", { d: "M8.49773 1.47656C8.36523 1.47656 8.23223 1.52357 8.13823 1.61707C7.86023 1.89507 6.85973 2.89558 6.63773 3.11808L2.13523 7.62059L1.63473 8.12059C1.56523 8.19059 1.52923 8.28958 1.50973 8.38658L1.00973 10.8881C0.939727 11.2381 1.23773 11.5361 1.58773 11.4666C1.90073 11.4036 3.77673 11.0286 4.08923 10.9661C4.18623 10.9466 4.28523 10.9106 4.35523 10.8411L4.85523 10.3406L9.35773 5.83808C9.58023 5.61608 10.5807 4.61506 10.8587 4.33756C10.9522 4.24356 10.9992 4.11056 10.9992 3.97806C10.9992 3.15956 10.7907 2.57456 10.3582 2.13306C9.92173 1.68756 9.33873 1.47656 8.49773 1.47656ZM8.69473 2.48606C9.14623 2.51256 9.43873 2.61608 9.63923 2.82108C9.84423 3.03008 9.97373 3.32008 10.0017 3.76258C9.72773 4.03608 9.32673 4.43106 8.99823 4.75956C8.60173 4.36306 8.11273 3.87407 7.71623 3.47757C8.04523 3.14907 8.42123 2.75956 8.69473 2.48606ZM6.99723 4.19657L8.27923 5.47858L4.49573 9.26207L3.21373 7.98009L6.99723 4.19657ZM2.49473 8.69908L3.77673 9.98107L3.72973 10.0281C3.39973 10.0941 2.73323 10.2336 2.11923 10.3566L2.44773 8.74608L2.49473 8.69908Z" })
1034
+ }
1035
+ );
1036
+ };
1037
+ var EditCode = (props) => {
1038
+ return /* @__PURE__ */ jsx("button", { children: /* @__PURE__ */ jsx(
1039
+ EditIcon,
1040
+ {
1041
+ className: " oui-mt-px oui-cursor-pointer oui-fill-base-contrast-36 hover:oui-fill-base-contrast-80",
1042
+ fillOpacity: 1,
1043
+ fill: "currentColor",
1044
+ onClick: props.onClick
1045
+ }
1046
+ ) });
1047
+ };
1048
+ var PinBtn = (props) => {
1049
+ return /* @__PURE__ */ jsx(
1050
+ "button",
1051
+ {
1052
+ onClick: (e) => {
1053
+ props?.onClick?.(!props.pinned);
1054
+ },
1055
+ children: props.pinned === false ? /* @__PURE__ */ jsx(
1056
+ UnPinIcon,
1057
+ {
1058
+ size: props.size,
1059
+ fillOpacity: 1,
1060
+ className: "orderly-fill-primary-darken hover:orderly-fill-primary-darken/80"
1061
+ }
1062
+ ) : /* @__PURE__ */ jsx(
1063
+ PinnedIcon,
1064
+ {
1065
+ size: props.size,
1066
+ fillOpacity: 1,
1067
+ className: "orderly-fill-base-contrast-36 hover:orderly-fill-base-contrast"
1068
+ }
1069
+ )
1070
+ }
1071
+ );
1072
+ };
1073
+ var PinnedIcon = (props) => {
1074
+ const { size = 12 } = props;
1075
+ return /* @__PURE__ */ jsx(
1076
+ "svg",
1077
+ {
1078
+ width: size,
1079
+ height: size,
1080
+ viewBox: "0 0 16 16",
1081
+ fill: "#608CFF",
1082
+ xmlns: "http://www.w3.org/2000/svg",
1083
+ children: /* @__PURE__ */ jsx("path", { d: "M10.008 1.302a.74.74 0 0 0-.486.215c-1.033.988-1.349 1.815-.972 2.947-.88.675-1.437.841-2.536.841-1.503 0-2.484.181-3.152.848v.021a1.583 1.583 0 0 0 0 2.249l1.867 1.881-3.181 3.18c-.26.26-.28.696-.02.956.261.26.699.26.959 0l3.193-3.193 1.87 1.86a1.585 1.585 0 0 0 2.25 0h.02c.668-.667.854-1.522.854-3.144 0-1.03.212-1.758.853-2.523 1.232.361 1.95.015 2.96-.995a.68.68 0 0 0 .188-.479c0-.234-.06-.594-.209-1.041a5.34 5.34 0 0 0-1.312-2.103A5.35 5.35 0 0 0 11.05 1.51c-.448-.149-.808-.208-1.042-.208" })
1084
+ }
1085
+ );
1086
+ };
1087
+ var UnPinIcon = (props) => {
1088
+ const { size = 12 } = props;
1089
+ return /* @__PURE__ */ jsx(
1090
+ "svg",
1091
+ {
1092
+ width: size,
1093
+ height: size,
1094
+ viewBox: "0 0 16 16",
1095
+ fill: "#fff",
1096
+ fillOpacity: ".36",
1097
+ xmlns: "http://www.w3.org/2000/svg",
1098
+ children: /* @__PURE__ */ jsx("path", { d: "M10.008 1.302a.74.74 0 0 0-.486.215c-1.033.988-1.349 1.815-.972 2.947-.88.675-1.437.841-2.536.841-1.503 0-2.484.181-3.152.848v.021a1.583 1.583 0 0 0 0 2.249l1.867 1.881-3.181 3.18c-.26.26-.28.696-.02.956.261.26.699.26.959 0l3.193-3.193 1.87 1.86a1.585 1.585 0 0 0 2.25 0h.02c.668-.667.854-1.522.854-3.144 0-1.03.212-1.758.853-2.523 1.232.361 1.95.015 2.96-.995a.68.68 0 0 0 .188-.479c0-.234-.06-.594-.209-1.041a5.34 5.34 0 0 0-1.312-2.103A5.35 5.35 0 0 0 11.05 1.51c-.448-.149-.808-.208-1.042-.208m.258 1.37c.708.131 1.421.6 1.93 1.108.507.507.94 1.13 1.119 1.944-.636.61-1.026.659-1.662.324a.67.67 0 0 0-.779.116c-1.214 1.213-1.533 2.314-1.533 3.8 0 1.293-.076 1.774-.48 2.207-.113.123-.27.104-.374 0L3.799 7.486a.24.24 0 0 1-.017-.34c.239-.29.769-.514 2.226-.514 1.742.001 2.668-.447 3.812-1.52a.67.67 0 0 0 .125-.77c-.343-.685-.29-1.046.321-1.67" })
1099
+ }
1100
+ );
1101
+ };
1102
+ var ReferralCodes = (props) => {
1103
+ const isTablet = useMediaQuery("(max-width: 767px)");
1104
+ return /* @__PURE__ */ jsxs(
1105
+ Flex,
1106
+ {
1107
+ r: "2xl",
1108
+ p: 6,
1109
+ width: "100%",
1110
+ gap: 4,
1111
+ direction: "column",
1112
+ className: "oui-h-full oui-bg-base-9 oui-p-6 oui-tabular-nums",
1113
+ children: [
1114
+ /* @__PURE__ */ jsx(Title4, { ...props }),
1115
+ /* @__PURE__ */ jsxs("div", { className: "oui-flex oui-w-full oui-flex-col 2xl:oui-h-full", children: [
1116
+ /* @__PURE__ */ jsx(Divider, {}),
1117
+ isTablet ? /* @__PURE__ */ jsx(MobileLayout, { ...props }) : /* @__PURE__ */ jsx(DesktopLayout, { ...props })
1118
+ ] })
1119
+ ]
1120
+ }
1121
+ );
1122
+ };
1123
+ var Title4 = (props) => {
1124
+ const { t } = useTranslation();
1125
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", justify: "between", width: "100%", children: [
1126
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-lg", children: t("affiliate.referralCodes") }),
1127
+ /* @__PURE__ */ jsxs("div", { className: "oui-text-2xs md:oui-text-xs xl:oui-text-sm", children: [
1128
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-base-contrast-54", children: `${t("affiliate.referralCodes.remaining")}: ` }),
1129
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-primary-light", children: props.codes?.length || "--" })
1130
+ ] })
1131
+ ] });
1132
+ };
1133
+ var MobileLayout = (props) => {
1134
+ return /* @__PURE__ */ jsx(
1135
+ ListView,
1136
+ {
1137
+ dataSource: props.codes,
1138
+ className: "oui-max-h-[240px] oui-w-full",
1139
+ renderItem: (e, index) => {
1140
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", children: [
1141
+ /* @__PURE__ */ jsx(
1142
+ MobileCell,
1143
+ {
1144
+ data: e,
1145
+ editRate: props.editRate,
1146
+ copyLink: props.copyLink,
1147
+ copyCode: props.copyCode,
1148
+ setPinCode: props.setPinCode,
1149
+ editCode: props.editCode
1150
+ },
1151
+ index
1152
+ ),
1153
+ /* @__PURE__ */ jsx(Divider, { className: "oui-mt-3 oui-w-full" })
1154
+ ] });
1155
+ }
1156
+ }
1157
+ );
1158
+ };
1159
+ var MobileCellItem = (props) => {
1160
+ const { title, copyable, value, align, className, editRate, onCopy } = props;
1161
+ return /* @__PURE__ */ jsx(
1162
+ Statistic,
1163
+ {
1164
+ id: "oui-affiliate-affiliate-referralCodes",
1165
+ className: cn("oui-flex-1", className),
1166
+ label: /* @__PURE__ */ jsx(Text, { className: "oui-text-2xs oui-text-base-contrast-36", children: title }),
1167
+ align,
1168
+ children: /* @__PURE__ */ jsxs(Flex, { direction: "row", gap: 1, children: [
1169
+ /* @__PURE__ */ jsx(
1170
+ Text.formatted,
1171
+ {
1172
+ copyable,
1173
+ onCopy: () => {
1174
+ onCopy?.();
1175
+ },
1176
+ className: "oui-mt-[6px] oui-text-sm oui-text-base-contrast-80",
1177
+ children: value
1178
+ }
1179
+ ),
1180
+ editRate && /* @__PURE__ */ jsx(
1181
+ EditIcon,
1182
+ {
1183
+ className: "oui-mt-px oui-cursor-pointer oui-fill-white/[.36] hover:oui-fill-white/80",
1184
+ fillOpacity: 1,
1185
+ fill: "currentColor",
1186
+ onClick: () => editRate()
1187
+ }
1188
+ )
1189
+ ] })
1190
+ }
1191
+ );
1192
+ };
1193
+ var MobileCell = (props) => {
1194
+ const { data, setPinCode, copyLink, editRate, editCode } = props;
1195
+ const { t } = useTranslation();
1196
+ return /* @__PURE__ */ jsxs(Flex, { gap: 3, direction: "column", className: "oui-w-full", children: [
1197
+ /* @__PURE__ */ jsxs(
1198
+ Flex,
1199
+ {
1200
+ direction: "row",
1201
+ justify: "between",
1202
+ itemAlign: "stretch",
1203
+ width: "100%",
1204
+ children: [
1205
+ /* @__PURE__ */ jsx(
1206
+ MobileCellItem,
1207
+ {
1208
+ title: t("affiliate.referralCode"),
1209
+ value: data.code,
1210
+ copyable: true,
1211
+ onCopy: () => {
1212
+ props.copyCode?.(data.code);
1213
+ },
1214
+ editRate: () => {
1215
+ editCode(data);
1216
+ }
1217
+ }
1218
+ ),
1219
+ /* @__PURE__ */ jsx(
1220
+ MobileCellItem,
1221
+ {
1222
+ title: t("affiliate.referralCodes.column.you&Referee"),
1223
+ value: getRate(data),
1224
+ align: "end",
1225
+ editRate: () => {
1226
+ editRate(data);
1227
+ }
1228
+ }
1229
+ ),
1230
+ /* @__PURE__ */ jsx(
1231
+ MobileCellItem,
1232
+ {
1233
+ title: t("affiliate.referralCodes.column.referees&Traders"),
1234
+ value: getCount(data),
1235
+ align: "end",
1236
+ className: "oui-hidden md:oui-flex"
1237
+ }
1238
+ )
1239
+ ]
1240
+ }
1241
+ ),
1242
+ /* @__PURE__ */ jsxs(
1243
+ Flex,
1244
+ {
1245
+ direction: "row",
1246
+ justify: "between",
1247
+ itemAlign: "stretch",
1248
+ width: "100%",
1249
+ className: "md:oui-hidden",
1250
+ children: [
1251
+ /* @__PURE__ */ jsx(
1252
+ MobileCellItem,
1253
+ {
1254
+ title: t("affiliate.referees"),
1255
+ value: getCount(data).split("/")?.[0],
1256
+ align: "start"
1257
+ }
1258
+ ),
1259
+ /* @__PURE__ */ jsx(
1260
+ MobileCellItem,
1261
+ {
1262
+ title: t("affiliate.referralCodes.column.traders"),
1263
+ value: getCount(data).split("/")?.[1],
1264
+ align: "end"
1265
+ }
1266
+ )
1267
+ ]
1268
+ }
1269
+ ),
1270
+ /* @__PURE__ */ jsxs(
1271
+ Flex,
1272
+ {
1273
+ direction: "row",
1274
+ justify: "between",
1275
+ itemAlign: "stretch",
1276
+ width: "100%",
1277
+ children: [
1278
+ /* @__PURE__ */ jsx(
1279
+ PinBtn,
1280
+ {
1281
+ pinned: data.isPined || false,
1282
+ onClick: (e) => {
1283
+ setPinCode(data.code, !e);
1284
+ }
1285
+ }
1286
+ ),
1287
+ /* @__PURE__ */ jsx(
1288
+ Button,
1289
+ {
1290
+ variant: "outlined",
1291
+ size: "xs",
1292
+ className: "oui-px-[20px]",
1293
+ onClick: (e) => {
1294
+ copyLink(data.code);
1295
+ },
1296
+ children: t("affiliate.referralCodes.copyLink")
1297
+ }
1298
+ )
1299
+ ]
1300
+ }
1301
+ )
1302
+ ] }, data.code);
1303
+ };
1304
+ var DesktopLayout = (props) => {
1305
+ const { t } = useTranslation();
1306
+ const moreColumn = useMediaQuery("(min-width: 1024px)");
1307
+ const columns = useMemo(() => {
1308
+ const cols = [
1309
+ {
1310
+ title: t("affiliate.referralCode"),
1311
+ dataIndex: "code",
1312
+ width: moreColumn ? 115 : 120,
1313
+ className: "!oui-px-0",
1314
+ render: (value, data) => {
1315
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", itemAlign: "center", gap: 1, children: [
1316
+ /* @__PURE__ */ jsx(
1317
+ PinBtn,
1318
+ {
1319
+ size: 12,
1320
+ pinned: data.isPined || false,
1321
+ onClick: (e) => {
1322
+ props.setPinCode(data.code, !e);
1323
+ }
1324
+ }
1325
+ ),
1326
+ /* @__PURE__ */ jsx(
1327
+ Text.formatted,
1328
+ {
1329
+ suffix: /* @__PURE__ */ jsxs(Fragment, { children: [
1330
+ data.isAutoGenerated && data.total_invites < 1 && /* @__PURE__ */ jsx(EditCode, { onClick: () => props.editCode?.(data) }),
1331
+ /* @__PURE__ */ jsx(
1332
+ CopyIcon,
1333
+ {
1334
+ className: "oui-cursor-pointer",
1335
+ size: 12,
1336
+ color: "white",
1337
+ onClick: () => props.copyCode?.(data.code)
1338
+ }
1339
+ )
1340
+ ] }),
1341
+ copyable: true,
1342
+ onCopy: () => {
1343
+ props.copyCode?.(data.code);
1344
+ },
1345
+ children: value
1346
+ }
1347
+ )
1348
+ ] });
1349
+ }
1350
+ },
1351
+ {
1352
+ title: t("affiliate.referralCodes.column.you&Referee"),
1353
+ dataIndex: "dffd",
1354
+ width: moreColumn ? 120 : 120,
1355
+ className: "oui-pr-0",
1356
+ render: (value, data) => {
1357
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", itemAlign: "center", gap: 1, children: [
1358
+ getRate(data),
1359
+ /* @__PURE__ */ jsx(
1360
+ EditIcon,
1361
+ {
1362
+ className: "oui-mt-[6px] oui-cursor-pointer oui-fill-white/[.36] hover:oui-fill-white/80",
1363
+ fillOpacity: 1,
1364
+ fill: "currentColor",
1365
+ onClick: (e) => props.editRate?.(data)
1366
+ }
1367
+ )
1368
+ ] });
1369
+ }
1370
+ }
1371
+ ];
1372
+ if (moreColumn) {
1373
+ cols.push({
1374
+ title: t("affiliate.referees"),
1375
+ dataIndex: "referee_rebate_rate",
1376
+ width: 65,
1377
+ className: "oui-pr-0",
1378
+ render: (value, data) => getCount(data).split("/")[0]
1379
+ });
1380
+ cols.push({
1381
+ title: t("affiliate.referralCodes.column.traders"),
1382
+ dataIndex: "referrer_rebate_rate",
1383
+ width: 65,
1384
+ className: "oui-pr-0",
1385
+ render: (value, data) => getCount(data).split("/")[1]
1386
+ });
1387
+ } else {
1388
+ cols.push({
1389
+ title: t("affiliate.referralCodes.column.referees&Traders"),
1390
+ dataIndex: "total_invites/total_traded",
1391
+ width: 120,
1392
+ fixed: "left",
1393
+ render: (value, data) => getCount(data)
1394
+ });
1395
+ }
1396
+ cols.push({
1397
+ dataIndex: "link",
1398
+ align: "right",
1399
+ width: 74,
1400
+ className: "!oui-px-0",
1401
+ render: (value, data) => /* @__PURE__ */ jsx(
1402
+ Button,
1403
+ {
1404
+ variant: "outlined",
1405
+ size: "sm",
1406
+ className: "oui-px-5",
1407
+ onClick: (e) => {
1408
+ props?.copyLink?.(data.code);
1409
+ },
1410
+ children: t("affiliate.referralCodes.copyLink")
1411
+ }
1412
+ )
1413
+ });
1414
+ return cols;
1415
+ }, [moreColumn, t]);
1416
+ return /* @__PURE__ */ jsx(
1417
+ DataTable,
1418
+ {
1419
+ bordered: true,
1420
+ columns,
1421
+ dataSource: props.codes,
1422
+ classNames: {
1423
+ header: "oui-px-0",
1424
+ root: "2xl:oui-flex-1 2xl:oui-max-h-[230px] 3xl:oui-max-h-[300px]"
1425
+ },
1426
+ onRow: (record) => {
1427
+ return {
1428
+ className: "oui-h-[45px]"
1429
+ };
1430
+ }
1431
+ }
1432
+ );
1433
+ };
1434
+ var getRate = (item) => {
1435
+ const refereeRate = new Decimal(item.referee_rebate_rate).mul(100).toFixed(1, Decimal.ROUND_DOWN).toString();
1436
+ const referralRate = new Decimal(item.referrer_rebate_rate).mul(100).toFixed(1, Decimal.ROUND_DOWN).toString();
1437
+ return `${referralRate}% / ${refereeRate}%`;
1438
+ };
1439
+ var getCount = (item) => {
1440
+ return `${item.total_invites} / ${item.total_traded}`;
1441
+ };
1442
+ var EditCodeModal = modal.create((props) => {
1443
+ const { t } = useTranslation();
1444
+ const { visible, onOpenChange } = useModal();
1445
+ const [newCode, setNewCode] = useState("");
1446
+ const [filedError, setFiledError] = useState({
1447
+ length: false,
1448
+ format: false
1449
+ });
1450
+ const [editCode, { error, isMutating }] = useMutation(
1451
+ "/v1/referral/edit_referral_code",
1452
+ "POST"
1453
+ );
1454
+ useEffect(() => {
1455
+ setNewCode(props.code.code);
1456
+ }, [props.code]);
1457
+ useEffect(() => {
1458
+ const _code = newCode.toUpperCase();
1459
+ const _fieldError = {
1460
+ length: false,
1461
+ format: false
1462
+ };
1463
+ if (_code.length < 4 || _code.length > 10) {
1464
+ _fieldError.length = true;
1465
+ }
1466
+ if (!/^[A-Z0-9]+$/.test(_code)) {
1467
+ _fieldError.format = true;
1468
+ }
1469
+ setFiledError(_fieldError);
1470
+ }, [newCode]);
1471
+ return /* @__PURE__ */ jsxs(
1472
+ SimpleDialog,
1473
+ {
1474
+ classNames: {
1475
+ content: "oui-max-w-[360px]"
1476
+ },
1477
+ title: /* @__PURE__ */ jsx("div", { children: t("affiliate.referralCode.editCodeModal.title") }),
1478
+ open: visible,
1479
+ onOpenChange,
1480
+ actions: {
1481
+ primary: {
1482
+ loading: isMutating,
1483
+ disabled: filedError.length || filedError.format,
1484
+ label: t("common.confirm"),
1485
+ onClick: async () => {
1486
+ try {
1487
+ const res = await editCode({
1488
+ current_referral_code: props.code.code,
1489
+ new_referral_code: newCode.toUpperCase()
1490
+ });
1491
+ if (res.success) {
1492
+ toast.success(
1493
+ t("affiliate.referralCode.editCodeModal.success")
1494
+ );
1495
+ props.successCallback();
1496
+ onOpenChange(false);
1497
+ return;
1498
+ }
1499
+ toast.error(res.message);
1500
+ } catch (e) {
1501
+ }
1502
+ }
1503
+ }
1504
+ },
1505
+ children: [
1506
+ /* @__PURE__ */ jsx("div", { className: "oui-mb-6 oui-text-xs oui-text-base-contrast-54", children: t("affiliate.referralCode.editCodeModal.description") }),
1507
+ /* @__PURE__ */ jsx(
1508
+ TextField,
1509
+ {
1510
+ placeholder: "",
1511
+ fullWidth: true,
1512
+ label: t("affiliate.referralCode.editCodeModal.label"),
1513
+ onClean: () => {
1514
+ setNewCode("");
1515
+ },
1516
+ value: newCode,
1517
+ onChange: (e) => {
1518
+ const _value = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, "");
1519
+ setNewCode(_value);
1520
+ },
1521
+ formatters: [
1522
+ inputFormatter.createRegexInputFormatter((value) => {
1523
+ return String(value).replace(
1524
+ /[a-z]/g,
1525
+ (char) => char.toUpperCase()
1526
+ );
1527
+ }),
1528
+ inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)
1529
+ ],
1530
+ classNames: {
1531
+ label: "oui-text-base-contrast-54 oui-text-xs",
1532
+ input: "placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm"
1533
+ },
1534
+ maxLength: 10,
1535
+ minLength: 4,
1536
+ autoComplete: "off",
1537
+ helpText: ""
1538
+ }
1539
+ ),
1540
+ /* @__PURE__ */ jsxs(
1541
+ Flex,
1542
+ {
1543
+ direction: "column",
1544
+ justify: "center",
1545
+ itemAlign: "start",
1546
+ gap: 1,
1547
+ className: "oui-mt-3",
1548
+ children: [
1549
+ /* @__PURE__ */ jsx(
1550
+ Text,
1551
+ {
1552
+ className: cn(
1553
+ "oui-ml-4 oui-list-item oui-list-outside oui-list-disc oui-text-xs oui-text-base-contrast-36 marker:oui-text-3xs",
1554
+ filedError.length ? "oui-text-danger" : "oui-text-success"
1555
+ ),
1556
+ children: t("affiliate.referralCode.editCodeModal.helpText.length")
1557
+ }
1558
+ ),
1559
+ /* @__PURE__ */ jsx(
1560
+ Text,
1561
+ {
1562
+ className: cn(
1563
+ "oui-ml-4 oui-list-item oui-list-outside oui-list-disc oui-text-xs oui-text-base-contrast-36 marker:oui-text-3xs",
1564
+ "oui-text-success"
1565
+ ),
1566
+ children: t("affiliate.referralCode.editCodeModal.helpText.format")
1567
+ }
1568
+ )
1569
+ ]
1570
+ }
1571
+ )
1572
+ ]
1573
+ }
1574
+ );
1575
+ });
1576
+ var EditReferralRate = modal.create((props) => {
1577
+ const { code, mutate } = props;
1578
+ const { visible, hide, resolve, reject, onOpenChange } = useModal();
1579
+ const maxRate = new Decimal(code.max_rebate_rate).mul(100);
1580
+ const [refereeRebateRate, setRefereeRebateRate] = useState(
1581
+ `${new Decimal(code.referee_rebate_rate).mul(100)}`
1582
+ );
1583
+ const [referrerRebateRate, setReferrerRebateRate] = useState(
1584
+ `${new Decimal(code.referrer_rebate_rate).mul(100)}`
1585
+ );
1586
+ const [showError, setShowError] = useState(false);
1587
+ const inputRef = useRef(null);
1588
+ const { t } = useTranslation();
1589
+ useEffect(() => {
1590
+ if (inputRef?.current) {
1591
+ inputRef.current.focus();
1592
+ inputRef.current.setSelectionRange(
1593
+ inputRef.current.value.length,
1594
+ inputRef.current.value.length
1595
+ );
1596
+ }
1597
+ }, [inputRef]);
1598
+ useEffect(() => {
1599
+ setRefereeRebateRate(`${new Decimal(code.referee_rebate_rate).mul(100)}`);
1600
+ setReferrerRebateRate(`${new Decimal(code.referrer_rebate_rate).mul(100)}`);
1601
+ }, [code]);
1602
+ const [editRate, { error, isMutating }] = useMutation(
1603
+ "/v1/referral/edit_split",
1604
+ "POST"
1605
+ );
1606
+ const onClickConfirm = async () => {
1607
+ try {
1608
+ const r1 = Number.parseFloat(refereeRebateRate);
1609
+ const r2 = Number.parseFloat(referrerRebateRate);
1610
+ await editRate({
1611
+ referral_code: code.code,
1612
+ referee_rebate_rate: r1 / 100,
1613
+ referrer_rebate_rate: r2 / 100
1614
+ });
1615
+ toast.success(t("affiliate.referralRate.editRateModal.success"));
1616
+ mutate();
1617
+ hide();
1618
+ } catch (e) {
1619
+ toast.error(e?.message || e || "");
1620
+ }
1621
+ };
1622
+ return /* @__PURE__ */ jsx(Dialog, { open: visible, onOpenChange, children: /* @__PURE__ */ jsxs(
1623
+ DialogContent,
1624
+ {
1625
+ className: "oui-px-6 oui-max-w-[320px] oui-bg-base-8 oui-shadow-[0px_12px_20px_0px_rgba(0,0,0,0.25)]",
1626
+ closable: true,
1627
+ children: [
1628
+ /* @__PURE__ */ jsxs(DialogTitle, { children: [
1629
+ /* @__PURE__ */ jsx("div", { className: "oui-my-3", children: t("affiliate.referralRate.editRateModal.title") }),
1630
+ /* @__PURE__ */ jsx(Divider, {})
1631
+ ] }),
1632
+ /* @__PURE__ */ jsxs("div", { className: "oui-mt-3 oui-h-full oui-flex oui-flex-col oui-justify-end", children: [
1633
+ /* @__PURE__ */ jsx("div", { className: "oui-text-xs oui-text-base-contrast-54", children: t("affiliate.referralRate.editRateModal.description") }),
1634
+ /* @__PURE__ */ jsxs("div", { className: "oui-text-xs oui-text-base-contrast-80 oui-mt-2 oui-flex", children: [
1635
+ t("affiliate.referralRate.editRateModal.label"),
1636
+ /* @__PURE__ */ jsx("div", { className: "oui-text-warning-darken oui-pl-1", children: `${new Decimal(
1637
+ code.max_rebate_rate
1638
+ ).mul(100).toFixed(0, Decimal.ROUND_DOWN)}%` })
1639
+ ] }),
1640
+ /* @__PURE__ */ jsx("div", { className: "oui-text-2xs oui-mt-6 oui-text-base-contrast-80", children: t("affiliate.referralRate.editRateModal.label.you") }),
1641
+ /* @__PURE__ */ jsx(
1642
+ Input$1,
1643
+ {
1644
+ ref: inputRef,
1645
+ containerClassName: "oui-h-[40px] oui-mt-3 oui-bg-base-700 oui-outline oui-outline-1 oui-outline-base-contrast-12 focus-within:oui-outline-primary-darken",
1646
+ placeholder: "Enter code",
1647
+ type: "text",
1648
+ inputMode: "decimal",
1649
+ autoComplete: "off",
1650
+ value: referrerRebateRate,
1651
+ onChange: (e) => {
1652
+ const text = cleanStringStyle(e.target.value);
1653
+ const rate = Number.parseFloat(text);
1654
+ setReferrerRebateRate(text);
1655
+ if (!Number.isNaN(rate)) {
1656
+ setRefereeRebateRate(
1657
+ `${maxDecimal(new Decimal(0), maxRate.sub(rate))}`
1658
+ );
1659
+ setShowError(maxRate.sub(rate) < new Decimal(0));
1660
+ } else {
1661
+ setRefereeRebateRate("");
1662
+ setReferrerRebateRate("");
1663
+ }
1664
+ },
1665
+ suffix: /* @__PURE__ */ jsx("div", { className: "oui-px-3 oui-text-base-contrast-54 oui-text-base", children: "%" }),
1666
+ color: showError ? "danger" : void 0
1667
+ }
1668
+ ),
1669
+ /* @__PURE__ */ jsx("div", { className: "oui-text-2xs oui-mt-6 oui-text-base-contrast-80", children: t("affiliate.referralRate.editRateModal.label.referee") }),
1670
+ /* @__PURE__ */ jsx(
1671
+ Input$1,
1672
+ {
1673
+ containerClassName: "oui-h-[40px] oui-mt-3 oui-bg-base-700 oui-outline oui-outline-1 oui-outline-base-contrast-12 focus-within:oui-outline-primary-darken",
1674
+ placeholder: "Enter code",
1675
+ type: "text",
1676
+ inputMode: "decimal",
1677
+ autoComplete: "off",
1678
+ autoFocus: false,
1679
+ value: refereeRebateRate,
1680
+ onChange: (e) => {
1681
+ const text = cleanStringStyle(e.target.value);
1682
+ const rate = Number.parseFloat(text);
1683
+ setRefereeRebateRate(text);
1684
+ if (!Number.isNaN(rate)) {
1685
+ setReferrerRebateRate(
1686
+ `${maxDecimal(new Decimal(0), maxRate.sub(rate))}`
1687
+ );
1688
+ setShowError(maxRate.sub(rate) < new Decimal(0));
1689
+ } else {
1690
+ setRefereeRebateRate("");
1691
+ setReferrerRebateRate("");
1692
+ }
1693
+ },
1694
+ suffix: /* @__PURE__ */ jsx("div", { className: "oui-px-3 oui-text-base-contrast-54 oui-text-base", children: "%" }),
1695
+ color: showError ? "danger" : void 0
1696
+ }
1697
+ ),
1698
+ showError && /* @__PURE__ */ jsx("div", { className: "oui-text-danger oui-text-xs oui-mt-8 oui-text-center oui-px-4", children: t("affiliate.referralRate.editRateModal.helpText.max") }),
1699
+ /* @__PURE__ */ jsx(Flex, { width: "100%", justify: "center", children: /* @__PURE__ */ jsx(
1700
+ Button,
1701
+ {
1702
+ id: "referral_bind_referral_code_btn",
1703
+ disabled: refereeRebateRate.length === 0 || referrerRebateRate.length === 0 || showError,
1704
+ loading: isMutating,
1705
+ className: cn(
1706
+ "oui-mt-8 oui-mb-4 oui-w-[154px]",
1707
+ showError && "oui-mt-3"
1708
+ ),
1709
+ onClick: (e) => {
1710
+ e.stopPropagation();
1711
+ onClickConfirm();
1712
+ },
1713
+ children: t("common.confirm")
1714
+ }
1715
+ ) })
1716
+ ] })
1717
+ ]
1718
+ }
1719
+ ) });
1720
+ });
1721
+ function maxDecimal(a, b) {
1722
+ return a > b ? a : b;
1723
+ }
1724
+
1725
+ // src/pages/affiliate/referralCodes/referralCodes.script.tsx
1726
+ var useReferralCodesScript = () => {
1727
+ const { referralInfo, referralLinkUrl, mutate, generateCode } = useReferralContext();
1728
+ const copyLink = (code) => {
1729
+ copyText(generateReferralLink(referralLinkUrl, code));
1730
+ };
1731
+ const copyCode = (code) => {
1732
+ copyText(code);
1733
+ };
1734
+ const editRate = (code) => {
1735
+ modal.show(EditReferralRate, { code: { ...code }, mutate });
1736
+ };
1737
+ const editCode = (code) => {
1738
+ modal.show(EditCodeModal, {
1739
+ code: { ...code },
1740
+ successCallback: () => {
1741
+ mutate();
1742
+ }
1743
+ });
1744
+ };
1745
+ const [pinCodes, setPinCodes] = useLocalStorage(
1746
+ "orderly_referral_codes",
1747
+ []
1748
+ );
1749
+ const setPinCode = (code, del) => {
1750
+ if (del) {
1751
+ const index = pinCodes.findIndex((item) => item === code);
1752
+ if (index !== -1) {
1753
+ pinCodes.splice(index, 1);
1754
+ }
1755
+ } else {
1756
+ pinCodes.splice(0, 0, code);
1757
+ }
1758
+ if (pinCodes.length > 6) {
1759
+ pinCodes.splice(pinCodes.length - 1, 1);
1760
+ }
1761
+ setPinCodes([...pinCodes]);
1762
+ };
1763
+ const codes = useMemo(() => {
1764
+ if (!referralInfo?.referrer_info?.referral_codes) {
1765
+ return void 0;
1766
+ }
1767
+ const referralCodes = referralInfo?.referrer_info?.referral_codes?.map((item) => {
1768
+ if (generateCode && generateCode.code === item.code) {
1769
+ item.isAutoGenerated = true;
1770
+ }
1771
+ return item;
1772
+ });
1773
+ const pinedItems = [];
1774
+ for (let i = 0; i < pinCodes.length; i++) {
1775
+ const code = pinCodes[i];
1776
+ const index = referralCodes.findIndex((item) => item.code === code);
1777
+ if (index !== -1) {
1778
+ pinedItems.push({ ...referralCodes[index], isPined: true });
1779
+ referralCodes.splice(index, 1);
1780
+ }
1781
+ }
1782
+ return [...pinedItems, ...referralCodes];
1783
+ }, [referralInfo?.referrer_info?.referral_codes, pinCodes, generateCode]);
1784
+ return {
1785
+ copyCode,
1786
+ copyLink,
1787
+ editRate,
1788
+ editCode,
1789
+ setPinCode,
1790
+ codes
1791
+ };
1792
+ };
1793
+ var ReferralCodesWidget = () => {
1794
+ const state = useReferralCodesScript();
1795
+ return /* @__PURE__ */ jsx(ReferralCodes, { ...state });
1796
+ };
1797
+ var CommissionAndReferees = (props) => {
1798
+ const { t } = useTranslation();
1799
+ return /* @__PURE__ */ jsx(
1800
+ Flex,
1801
+ {
1802
+ id: "oui-affiliate-affiliate-commissionAndReferees",
1803
+ r: "2xl",
1804
+ p: 6,
1805
+ width: "100%",
1806
+ gap: 4,
1807
+ direction: "column",
1808
+ className: "oui-bg-base-9 oui-tabular-nums",
1809
+ children: /* @__PURE__ */ jsxs(Tabs, { defaultValue: "account", className: "oui-w-full", variant: "contained", children: [
1810
+ /* @__PURE__ */ jsx(TabPanel, { value: "account", title: t("affiliate.commission"), children: /* @__PURE__ */ jsx(CommissionList, { ...props }) }),
1811
+ /* @__PURE__ */ jsx(TabPanel, { value: "password", title: t("affiliate.myReferees"), children: /* @__PURE__ */ jsx(RefereesList, { ...props }) })
1812
+ ] })
1813
+ }
1814
+ );
1815
+ };
1816
+ var MobileCellItem2 = (props) => {
1817
+ const { title, value, align, className, rule, formatString, prefix } = props;
1818
+ return /* @__PURE__ */ jsx(
1819
+ Statistic,
1820
+ {
1821
+ className: cn("oui-flex-1", className),
1822
+ label: /* @__PURE__ */ jsx(Text, { className: "oui-text-base-contrast-36 oui-text-2xs", children: title }),
1823
+ align,
1824
+ children: /* @__PURE__ */ jsx(
1825
+ Text.formatted,
1826
+ {
1827
+ rule: rule || "",
1828
+ formatString,
1829
+ prefix,
1830
+ className: "oui-text-base-contrast-80 oui-text-sm oui-mt-[6px]",
1831
+ children: value
1832
+ }
1833
+ )
1834
+ }
1835
+ );
1836
+ };
1837
+ var CommissionList = (props) => {
1838
+ const { t } = useTranslation();
1839
+ const isLG = useMediaQuery("(max-width: 767px)");
1840
+ const columns = useMemo(() => {
1841
+ const cols = [
1842
+ {
1843
+ title: `${t("affiliate.commission")} (USDC)`,
1844
+ dataIndex: "referral_rebate",
1845
+ render: (value) => /* @__PURE__ */ jsx(Text, { children: commifyOptional(value, {
1846
+ fix: 6,
1847
+ fallback: "0",
1848
+ padEnd: true,
1849
+ prefix: "$"
1850
+ }) }),
1851
+ width: 216
1852
+ },
1853
+ {
1854
+ title: `${t("affiliate.referralVol")} (USDC)`,
1855
+ dataIndex: "volume",
1856
+ render: (value) => /* @__PURE__ */ jsx(Text, { children: commifyOptional(value, {
1857
+ fix: 2,
1858
+ fallback: "0",
1859
+ padEnd: true,
1860
+ prefix: "$"
1861
+ }) }),
1862
+ width: 216
1863
+ },
1864
+ {
1865
+ title: t("affiliate.commission.column.activeUsers"),
1866
+ dataIndex: "daily_traded_referral",
1867
+ render: (value) => /* @__PURE__ */ jsx(Text, { children: value }),
1868
+ width: 216
1869
+ },
1870
+ {
1871
+ title: t("common.date"),
1872
+ dataIndex: "date",
1873
+ render: (value) => formatYMDTime(value),
1874
+ width: 216
1875
+ }
1876
+ ];
1877
+ return cols;
1878
+ }, [t]);
1879
+ const body = useMemo(() => {
1880
+ if (isLG) {
1881
+ return /* @__PURE__ */ jsx(
1882
+ ListView,
1883
+ {
1884
+ className: "oui-max-h-[200px] oui-w-full",
1885
+ dataSource: props.commission.data,
1886
+ loadMore: props.commission.loadMore,
1887
+ isLoading: props.commission.isLoading,
1888
+ renderItem: (e) => {
1889
+ return /* @__PURE__ */ jsxs("div", { children: [
1890
+ /* @__PURE__ */ jsxs(Flex, { direction: "row", width: "100%", children: [
1891
+ /* @__PURE__ */ jsx(
1892
+ MobileCellItem2,
1893
+ {
1894
+ title: t("affiliate.commission"),
1895
+ value: commifyOptional(e.referral_rebate, {
1896
+ fix: 6,
1897
+ fallback: "0",
1898
+ padEnd: true
1899
+ }),
1900
+ prefix: "$"
1901
+ }
1902
+ ),
1903
+ /* @__PURE__ */ jsx(
1904
+ MobileCellItem2,
1905
+ {
1906
+ title: t("affiliate.referralVol"),
1907
+ value: commifyOptional(e.volume, {
1908
+ fix: 2,
1909
+ fallback: "0",
1910
+ padEnd: true
1911
+ }),
1912
+ prefix: "$"
1913
+ }
1914
+ ),
1915
+ /* @__PURE__ */ jsx(
1916
+ MobileCellItem2,
1917
+ {
1918
+ title: t("affiliate.commission.column.activeUsers"),
1919
+ value: e.daily_traded_referral
1920
+ }
1921
+ ),
1922
+ /* @__PURE__ */ jsx(
1923
+ MobileCellItem2,
1924
+ {
1925
+ title: t("common.date"),
1926
+ value: e.date,
1927
+ rule: "date",
1928
+ formatString: "yyyy-MM-dd",
1929
+ align: "end"
1930
+ }
1931
+ )
1932
+ ] }),
1933
+ /* @__PURE__ */ jsx(Divider, { className: "oui-mt-3 oui-w-full" })
1934
+ ] });
1935
+ }
1936
+ }
1937
+ );
1938
+ }
1939
+ return /* @__PURE__ */ jsx(
1940
+ AuthGuardDataTable,
1941
+ {
1942
+ bordered: true,
1943
+ columns,
1944
+ loading: props.commission.isLoading,
1945
+ ignoreLoadingCheck: true,
1946
+ dataSource: props.commission.data,
1947
+ pagination: props.commission.pagination,
1948
+ onRow: (record) => {
1949
+ return {
1950
+ className: "oui-h-[41px]"
1951
+ };
1952
+ }
1953
+ }
1954
+ );
1955
+ }, [isLG, props.commission]);
1956
+ return /* @__PURE__ */ jsxs(
1957
+ Flex,
1958
+ {
1959
+ direction: "column",
1960
+ width: "100%",
1961
+ justify: "start",
1962
+ itemAlign: "start",
1963
+ children: [
1964
+ /* @__PURE__ */ jsx(
1965
+ DateFiler,
1966
+ {
1967
+ value: props.commission.dateRange,
1968
+ setValue: props.commission.setDateRange
1969
+ }
1970
+ ),
1971
+ body
1972
+ ]
1973
+ }
1974
+ );
1975
+ };
1976
+ var RefereesList = (props) => {
1977
+ const { t } = useTranslation();
1978
+ const isLG = useMediaQuery("(max-width: 767px)");
1979
+ const columns = useMemo(() => {
1980
+ const cols = [
1981
+ {
1982
+ title: t("affiliate.referees.column.refereeAddress"),
1983
+ dataIndex: "user_address",
1984
+ render: (value) => /* @__PURE__ */ jsx(Text.formatted, { rule: "address", children: value }),
1985
+ className: "oui-w-1/5"
1986
+ },
1987
+ {
1988
+ title: t("affiliate.referralCode"),
1989
+ dataIndex: "referral_code",
1990
+ // render: (value) => value,
1991
+ className: "oui-w-1/5"
1992
+ },
1993
+ {
1994
+ title: `${t("affiliate.referees.column.totalCommission")} (USDC)`,
1995
+ dataIndex: "referral_rebate",
1996
+ render: (value) => /* @__PURE__ */ jsx(Text, { children: commifyOptional(value, { fix: 6, prefix: "$", padEnd: true }) }),
1997
+ className: "oui-w-1/5"
1998
+ },
1999
+ {
2000
+ title: `${t("affiliate.referees.column.totalVol")} (USDC)`,
2001
+ dataIndex: "volume",
2002
+ render: (value) => /* @__PURE__ */ jsx(Text, { children: commifyOptional(value, { fix: 2, prefix: "$", padEnd: true }) }),
2003
+ className: "oui-w-1/5"
2004
+ },
2005
+ {
2006
+ title: t("affiliate.referees.column.invitationTime"),
2007
+ dataIndex: "code_binding_time",
2008
+ render: (value) => /* @__PURE__ */ jsx(
2009
+ Text.formatted,
2010
+ {
2011
+ rule: "date",
2012
+ formatString: "yyyy-MM-dd",
2013
+ children: value
2014
+ }
2015
+ ),
2016
+ className: "oui-w-1/5"
2017
+ }
2018
+ ];
2019
+ return cols;
2020
+ }, [t]);
2021
+ const body = useMemo(() => {
2022
+ if (isLG) {
2023
+ return /* @__PURE__ */ jsx(
2024
+ ListView,
2025
+ {
2026
+ className: "oui-w-full oui-max-h-[200px]",
2027
+ dataSource: props.referees.data,
2028
+ loadMore: props.referees.loadMore,
2029
+ isLoading: props.referees.isLoading,
2030
+ renderItem: (e, index) => {
2031
+ return /* @__PURE__ */ jsxs(
2032
+ Flex,
2033
+ {
2034
+ direction: "column",
2035
+ gap: 3,
2036
+ className: "oui-border-b-2 oui-border-line-6 oui-pb-3",
2037
+ children: [
2038
+ /* @__PURE__ */ jsxs(Flex, { direction: "row", width: "100%", children: [
2039
+ /* @__PURE__ */ jsx(
2040
+ MobileCellItem2,
2041
+ {
2042
+ title: t("affiliate.referralCode"),
2043
+ value: e.referral_code
2044
+ }
2045
+ ),
2046
+ /* @__PURE__ */ jsx(
2047
+ MobileCellItem2,
2048
+ {
2049
+ title: `${t(
2050
+ "affiliate.referees.column.totalCommission"
2051
+ )} (USDC)`,
2052
+ value: commifyOptional(e.referral_rebate, {
2053
+ fix: 6,
2054
+ prefix: "$",
2055
+ padEnd: true
2056
+ }),
2057
+ className: "oui-min-w-[102px]"
2058
+ }
2059
+ ),
2060
+ /* @__PURE__ */ jsx(
2061
+ MobileCellItem2,
2062
+ {
2063
+ title: t("affiliate.referees.column.totalVol"),
2064
+ value: commifyOptional(e.volume, {
2065
+ fix: 2,
2066
+ prefix: "$",
2067
+ padEnd: true
2068
+ }),
2069
+ align: "end"
2070
+ }
2071
+ )
2072
+ ] }),
2073
+ /* @__PURE__ */ jsxs(Flex, { direction: "row", pt: 3, gap: 3, width: "100%", children: [
2074
+ /* @__PURE__ */ jsx(
2075
+ MobileCellItem2,
2076
+ {
2077
+ title: t("affiliate.referees.column.refereeAddress"),
2078
+ value: e.user_address,
2079
+ rule: "address"
2080
+ }
2081
+ ),
2082
+ /* @__PURE__ */ jsx(
2083
+ MobileCellItem2,
2084
+ {
2085
+ title: t("affiliate.referees.column.invitationTime"),
2086
+ value: e.code_binding_time,
2087
+ align: "end",
2088
+ rule: "date",
2089
+ formatString: "yyyy-MM-dd"
2090
+ }
2091
+ )
2092
+ ] })
2093
+ ]
2094
+ },
2095
+ index
2096
+ );
2097
+ }
2098
+ }
2099
+ );
2100
+ }
2101
+ return /* @__PURE__ */ jsx(
2102
+ AuthGuardDataTable,
2103
+ {
2104
+ bordered: true,
2105
+ loading: props.referees.isLoading,
2106
+ ignoreLoadingCheck: true,
2107
+ columns,
2108
+ dataSource: props.referees.data,
2109
+ pagination: props.referees.pagination,
2110
+ onRow: (record) => {
2111
+ return {
2112
+ className: "oui-h-[41px]"
2113
+ };
2114
+ }
2115
+ }
2116
+ );
2117
+ }, [isLG, props.referees]);
2118
+ return /* @__PURE__ */ jsx(
2119
+ Flex,
2120
+ {
2121
+ direction: "column",
2122
+ width: "100%",
2123
+ justify: "start",
2124
+ itemAlign: "start",
2125
+ children: body
2126
+ }
2127
+ );
2128
+ };
2129
+ var DateFiler = (props) => {
2130
+ return /* @__PURE__ */ jsx(Flex, { width: "100%", height: 49, className: "oui-border-b oui-border-line-6", children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
2131
+ DatePicker.range,
2132
+ {
2133
+ size: "xs",
2134
+ value: props.value,
2135
+ onChange: (range) => {
2136
+ props.setValue(range);
2137
+ },
2138
+ max: 90,
2139
+ disabled: {
2140
+ after: /* @__PURE__ */ new Date()
2141
+ }
2142
+ }
2143
+ ) }) });
2144
+ };
2145
+ var useCommissionAndRefereesScript = () => {
2146
+ const commission = useCommissionDataScript();
2147
+ const referees = useRefereesDataScript();
2148
+ return {
2149
+ commission,
2150
+ referees
2151
+ };
2152
+ };
2153
+ var useCommissionDataScript = () => {
2154
+ const [commissionRange, setCommissionRange] = useState(
2155
+ {
2156
+ from: subDays(/* @__PURE__ */ new Date(), 90),
2157
+ to: subDays(/* @__PURE__ */ new Date(), 1)
2158
+ }
2159
+ );
2160
+ const isLG = useMediaQuery("(max-width: 767px)");
2161
+ const { page, pageSize, setPage, parsePagination } = usePagination();
2162
+ const [commissionData, { refresh, isLoading, loadMore, meta }] = useReferralRebateSummary({
2163
+ startDate: commissionRange?.from !== void 0 ? format(commissionRange.from, "yyyy-MM-dd") : void 0,
2164
+ endDate: commissionRange?.to !== void 0 ? format(commissionRange.to, "yyyy-MM-dd") : void 0,
2165
+ size: pageSize,
2166
+ page: !isLG ? page : void 0
2167
+ });
2168
+ useEffect(() => {
2169
+ refresh();
2170
+ }, [commissionRange]);
2171
+ const pagination = useMemo(
2172
+ () => parsePagination(meta),
2173
+ [parsePagination, meta]
2174
+ );
2175
+ useEffect(() => {
2176
+ setPage(1);
2177
+ }, [commissionRange]);
2178
+ return {
2179
+ data: commissionData || void 0,
2180
+ pagination,
2181
+ dateRange: commissionRange,
2182
+ setDateRange: setCommissionRange,
2183
+ isLoading,
2184
+ loadMore
2185
+ };
2186
+ };
2187
+ var useRefereesDataScript = () => {
2188
+ const [commissionRange, setCommissionRange] = useState(
2189
+ {
2190
+ from: subDays(/* @__PURE__ */ new Date(), 90),
2191
+ to: subDays(/* @__PURE__ */ new Date(), 1)
2192
+ }
2193
+ );
2194
+ const isLG = useMediaQuery("(max-width: 767px)");
2195
+ const { page, pageSize, setPage, parsePagination } = usePagination();
2196
+ const [commissionData, { refresh, isLoading, loadMore, meta }] = useRefereeInfo({
2197
+ startDate: commissionRange?.from !== void 0 ? format(commissionRange.from, "yyyy-MM-dd") : void 0,
2198
+ endDate: commissionRange?.to !== void 0 ? format(commissionRange.to, "yyyy-MM-dd") : void 0,
2199
+ size: pageSize,
2200
+ page: !isLG ? page : void 0,
2201
+ sort: "descending_code_binding_time"
2202
+ });
2203
+ useEffect(() => {
2204
+ refresh();
2205
+ }, [commissionRange]);
2206
+ const pagination = useMemo(
2207
+ () => parsePagination(meta),
2208
+ [parsePagination, meta]
2209
+ );
2210
+ useEffect(() => {
2211
+ setPage(1);
2212
+ }, [commissionRange]);
2213
+ return {
2214
+ data: commissionData || void 0,
2215
+ pagination,
2216
+ dateRange: commissionRange,
2217
+ setDateRange: setCommissionRange,
2218
+ isLoading,
2219
+ loadMore
2220
+ };
2221
+ };
2222
+ var CommissionAndRefereesWidget = () => {
2223
+ const state = useCommissionAndRefereesScript();
2224
+ return /* @__PURE__ */ jsx(CommissionAndReferees, { ...state });
2225
+ };
2226
+ var AffiliatePage = () => {
2227
+ return /* @__PURE__ */ jsxs(
2228
+ Flex,
2229
+ {
2230
+ id: "oui-affiliate-affiliate-page",
2231
+ className: cn(
2232
+ "oui-h-lvw",
2233
+ // padding
2234
+ // "oui-p-4 lg:oui-p-6 xl:oui-p-3",
2235
+ "oui-font-semibold"
2236
+ ),
2237
+ direction: "column",
2238
+ gap: 4,
2239
+ children: [
2240
+ /* @__PURE__ */ jsx(Layout, {}),
2241
+ /* @__PURE__ */ jsx(CommissionAndRefereesWidget, {})
2242
+ ]
2243
+ }
2244
+ );
2245
+ };
2246
+ var Layout = () => {
2247
+ const is2XL = useMediaQuery("(max-width: 1279px)");
2248
+ if (is2XL) {
2249
+ return /* @__PURE__ */ jsx(Layout1024, {});
2250
+ }
2251
+ return /* @__PURE__ */ jsx(Layout1280, {});
2252
+ };
2253
+ var Layout1024 = () => {
2254
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2255
+ /* @__PURE__ */ jsxs("div", { className: "oui-flex oui-flex-col xl:oui-flex-row oui-gap-4 oui-w-full", children: [
2256
+ /* @__PURE__ */ jsx(SummaryWidget, {}),
2257
+ /* @__PURE__ */ jsx(ReferralLinkWidget, {})
2258
+ ] }),
2259
+ /* @__PURE__ */ jsx(TitleStatisticWidget, {}),
2260
+ /* @__PURE__ */ jsx(ReferralCodesWidget, {})
2261
+ ] });
2262
+ };
2263
+ var Layout1280 = () => {
2264
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", itemAlign: "stretch", gap: 4, children: [
2265
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 4, className: "oui-flex-1 oui-w-1/2", children: [
2266
+ /* @__PURE__ */ jsx("div", { className: "oui-flex-1 oui-h-full oui-w-full", children: /* @__PURE__ */ jsx(SummaryWidget, {}) }),
2267
+ /* @__PURE__ */ jsx(TitleStatisticWidget, {})
2268
+ ] }),
2269
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 4, className: "oui-w-1/2", children: [
2270
+ /* @__PURE__ */ jsx(ReferralLinkWidget, {}),
2271
+ /* @__PURE__ */ jsx("div", { className: "oui-flex-1", children: /* @__PURE__ */ jsx(ReferralCodesWidget, {}) })
2272
+ ] })
2273
+ ] });
2274
+ };
2275
+ var BecomeAffiliate = (props) => {
2276
+ const { t } = useTranslation();
2277
+ const { generateCode } = useReferralContext();
2278
+ const applyText = useMemo(() => {
2279
+ if (!generateCode) {
2280
+ return {
2281
+ title: t("affiliate.process.step1.title"),
2282
+ desc: t("affiliate.process.step1.description")
2283
+ };
2284
+ }
2285
+ if (generateCode.requireVolume > 0) {
2286
+ return {
2287
+ title: t("affiliate.process.step1.volumeGt0.title", {
2288
+ requireVolume: generateCode.requireVolume
2289
+ }),
2290
+ desc: t("affiliate.process.step1.volumeGt0.description", {
2291
+ volume: commify(generateCode.completedVolume ?? 0, 2),
2292
+ requireVolume: commify(generateCode.requireVolume)
2293
+ })
2294
+ };
2295
+ }
2296
+ return {
2297
+ title: t("affiliate.process.step1.volumeEq0.title"),
2298
+ desc: t("affiliate.process.step1.volumeEq0.description")
2299
+ };
2300
+ }, [generateCode, t]);
2301
+ if (typeof props.overwrite === "function") {
2302
+ return props.overwrite?.(props.state);
2303
+ }
2304
+ return /* @__PURE__ */ jsxs(
2305
+ Flex,
2306
+ {
2307
+ id: "oui-affiliate-home-becomeAffiliate",
2308
+ direction: "column",
2309
+ gap: 6,
2310
+ p: 6,
2311
+ itemAlign: "center",
2312
+ r: "2xl",
2313
+ className: "oui-bg-base-9",
2314
+ width: "100%",
2315
+ children: [
2316
+ /* @__PURE__ */ jsx(Text, { children: t("affiliate.process.title") }),
2317
+ /* @__PURE__ */ jsxs(Flex, { className: "oui-flex oui-flex-col oui-gap-3 lg:oui-w-full lg:oui-flex-row lg:oui-items-stretch", children: [
2318
+ /* @__PURE__ */ jsx(
2319
+ Item,
2320
+ {
2321
+ icon: /* @__PURE__ */ jsx(ApplyIcon, {}),
2322
+ title: applyText.title,
2323
+ content: applyText.desc
2324
+ }
2325
+ ),
2326
+ /* @__PURE__ */ jsx("div", { className: "oui-shrink lg:oui-flex lg:-oui-rotate-90 lg:oui-flex-row lg:oui-items-center lg:oui-justify-center", children: /* @__PURE__ */ jsx(ArrowDownIcon, {}) }),
2327
+ /* @__PURE__ */ jsx(
2328
+ Item,
2329
+ {
2330
+ icon: /* @__PURE__ */ jsx(ShareIcon, {}),
2331
+ title: t("affiliate.process.step2.title"),
2332
+ content: t("affiliate.process.step2.description")
2333
+ }
2334
+ ),
2335
+ /* @__PURE__ */ jsx("div", { className: "oui-shrink lg:oui-flex lg:-oui-rotate-90 lg:oui-flex-row lg:oui-items-center lg:oui-justify-center", children: /* @__PURE__ */ jsx(ArrowDownIcon, {}) }),
2336
+ /* @__PURE__ */ jsx(
2337
+ Item,
2338
+ {
2339
+ icon: /* @__PURE__ */ jsx(EarnIcon, {}),
2340
+ title: t("affiliate.process.step3.title"),
2341
+ content: t("affiliate.process.step3.description")
2342
+ }
2343
+ )
2344
+ ] })
2345
+ ]
2346
+ }
2347
+ );
2348
+ };
2349
+ var Item = (props) => {
2350
+ return /* @__PURE__ */ jsxs(
2351
+ Flex,
2352
+ {
2353
+ className: cn(
2354
+ "oui-flex oui-flex-row oui-gap-3",
2355
+ "lg:oui-flex-1 lg:oui-flex-col lg:oui-gap-[6px]"
2356
+ ),
2357
+ width: "100%",
2358
+ children: [
2359
+ /* @__PURE__ */ jsx("div", { className: "oui-shrink-0", children: props.icon }),
2360
+ /* @__PURE__ */ jsxs(
2361
+ Flex,
2362
+ {
2363
+ className: cn(
2364
+ "oui-flex oui-flex-col oui-items-start oui-h-full oui-justify-between",
2365
+ // lg
2366
+ "lg:oui-items-center lg:oui-justify-start"
2367
+ ),
2368
+ children: [
2369
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-sm md:oui-text-base 2xl:oui-text-lg lg:oui-text-center", children: props.title }),
2370
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-2xs oui-text-base-contrast-36 lg:oui-text-center", children: props.content })
2371
+ ]
2372
+ }
2373
+ )
2374
+ ]
2375
+ }
2376
+ );
2377
+ };
2378
+ var ApplyIcon = () => {
2379
+ return /* @__PURE__ */ jsxs(
2380
+ "svg",
2381
+ {
2382
+ width: "48",
2383
+ height: "48",
2384
+ viewBox: "0 0 48 48",
2385
+ fill: "none",
2386
+ xmlns: "http://www.w3.org/2000/svg",
2387
+ className: "lg:oui-w-[64px] lg:oui-h-[64px] 2xl:oui-w-[80px] 2xl:oui-h-[80px]",
2388
+ children: [
2389
+ /* @__PURE__ */ jsx(
2390
+ "path",
2391
+ {
2392
+ fillRule: "evenodd",
2393
+ clipRule: "evenodd",
2394
+ d: "M24.941 5.4h-6.682a.6.6 0 0 0-.593.509l-.462 3a.6.6 0 0 0 .593.691h7.606a.6.6 0 0 0 .593-.691l-.462-3a.6.6 0 0 0-.593-.509m-6.682-1.8a2.4 2.4 0 0 0-2.372 2.035l-.462 3a2.4 2.4 0 0 0 2.372 2.765h7.606a2.4 2.4 0 0 0 2.372-2.765l-.462-3A2.4 2.4 0 0 0 24.941 3.6z",
2395
+ fill: "#fff",
2396
+ fillOpacity: ".36"
2397
+ }
2398
+ ),
2399
+ /* @__PURE__ */ jsx(
2400
+ "path",
2401
+ {
2402
+ d: "M32.721 28.2c.924-1.6 3.233-1.6 4.157 0l7.275 12.6c.924 1.6-.231 3.6-2.079 3.6H27.525c-1.848 0-3.002-2-2.078-3.6z",
2403
+ fill: "#335FFC"
2404
+ }
2405
+ ),
2406
+ /* @__PURE__ */ jsx(
2407
+ "path",
2408
+ {
2409
+ d: "M33.492 38.12H31.56c-.252 0-.426-.276-.336-.535l1.92-5.53a.4.4 0 0 1 .132-.185.34.34 0 0 1 .204-.07h3.24c.255 0 .43.284.333.544l-1.118 3.011h2.104c.31 0 .475.4.27.656l-5.158 6.453c-.251.313-.716.041-.619-.362z",
2410
+ fill: "#fff",
2411
+ fillOpacity: ".98"
2412
+ }
2413
+ ),
2414
+ /* @__PURE__ */ jsx(
2415
+ "path",
2416
+ {
2417
+ fillRule: "evenodd",
2418
+ clipRule: "evenodd",
2419
+ d: "M14.4 16.8v2.4h2.4v-2.4zM13.2 15a.6.6 0 0 0-.6.6v4.8a.6.6 0 0 0 .6.6H18a.6.6 0 0 0 .6-.6v-4.8a.6.6 0 0 0-.6-.6z",
2420
+ fill: "#fff",
2421
+ fillOpacity: ".36"
2422
+ }
2423
+ ),
2424
+ /* @__PURE__ */ jsx(
2425
+ "path",
2426
+ {
2427
+ d: "M20.4 16.2a.6.6 0 0 1 .6-.6h2.4a.6.6 0 0 1 .6.6v.6a.6.6 0 0 1-.6.6H21a.6.6 0 0 1-.6-.6zm0 3a.6.6 0 0 1 .6-.6h9a.6.6 0 0 1 .6.6v.6a.6.6 0 0 1-.6.6h-9a.6.6 0 0 1-.6-.6zm-7.8 5.4a.6.6 0 0 1 .6-.6H30a.6.6 0 0 1 .6.6v.6a.6.6 0 0 1-.6.6H13.2a.6.6 0 0 1-.6-.6zm0 3.6a.6.6 0 0 1 .6-.6H30a.6.6 0 0 1 .6.6v.6a.6.6 0 0 1-.6.6H13.2a.6.6 0 0 1-.6-.6zm0 3.6a.6.6 0 0 1 .6-.6h9a.6.6 0 0 1 .6.6v.6a.6.6 0 0 1-.6.6h-9a.6.6 0 0 1-.6-.6z",
2428
+ fill: "#fff",
2429
+ fillOpacity: ".36"
2430
+ }
2431
+ ),
2432
+ /* @__PURE__ */ jsx(
2433
+ "path",
2434
+ {
2435
+ fillRule: "evenodd",
2436
+ clipRule: "evenodd",
2437
+ d: "M15.739 6.6H10.2A2.4 2.4 0 0 0 7.8 9v30a2.4 2.4 0 0 0 2.4 2.4h13.84l1.014-1.8H10.2a.6.6 0 0 1-.6-.6V9a.6.6 0 0 1 .6-.6h5.262zm12 1.8H33a.6.6 0 0 1 .6.6v16.47a2.8 2.8 0 0 1 1.8-.205V9A2.4 2.4 0 0 0 33 6.6h-5.538z",
2438
+ fill: "#fff",
2439
+ fillOpacity: ".36"
2440
+ }
2441
+ )
2442
+ ]
2443
+ }
2444
+ );
2445
+ };
2446
+ var ShareIcon = () => {
2447
+ return /* @__PURE__ */ jsxs(
2448
+ "svg",
2449
+ {
2450
+ width: "48",
2451
+ height: "48",
2452
+ viewBox: "0 0 48 48",
2453
+ fill: "none",
2454
+ xmlns: "http://www.w3.org/2000/svg",
2455
+ className: "lg:oui-w-[64px] lg:oui-h-[64px] 2xl:oui-w-[80px] 2xl:oui-h-[80px]",
2456
+ children: [
2457
+ /* @__PURE__ */ jsx("path", { d: "M24 33a9 9 0 1 1-18 0 9 9 0 0 1 18 0", fill: "#335FFC" }),
2458
+ /* @__PURE__ */ jsx(
2459
+ "path",
2460
+ {
2461
+ fillRule: "evenodd",
2462
+ clipRule: "evenodd",
2463
+ d: "M15 32.4a1.8 1.8 0 1 0 0-3.6 1.8 1.8 0 0 0 0 3.6m0 1.8a3.6 3.6 0 1 0 0-7.2 3.6 3.6 0 0 0 0 7.2m-6.578 4.942A4.8 4.8 0 0 1 13.2 34.8h3.6a4.8 4.8 0 0 1 4.778 4.342 9 9 0 0 1-1.778 1.473V39.6a3 3 0 0 0-3-3h-3.6a3 3 0 0 0-3 3v1.015a9 9 0 0 1-1.778-1.473",
2464
+ fill: "#fff",
2465
+ fillOpacity: ".98"
2466
+ }
2467
+ ),
2468
+ /* @__PURE__ */ jsx(
2469
+ "path",
2470
+ {
2471
+ fillRule: "evenodd",
2472
+ clipRule: "evenodd",
2473
+ d: "M16.2 12a4.2 4.2 0 1 1-8.4 0 4.2 4.2 0 0 1 8.4 0m1.8 0c0 1.37-.459 2.632-1.231 3.642l2.308 2.308a7.76 7.76 0 0 1 4.023-1.7v-.764A3.602 3.602 0 0 1 24 8.4a3.6 3.6 0 0 1 .9 7.087v.764c1.48.17 2.833.754 3.942 1.633l2.326-2.326a6 6 0 1 1 1.273 1.273l-2.326 2.326a7.76 7.76 0 0 1 1.634 3.943h.764a3.602 3.602 0 0 1 7.087.9 3.6 3.6 0 0 1-7.087.9h-.764a7.76 7.76 0 0 1-1.699 4.023l2.308 2.308a6 6 0 1 1-1.25 1.295l-2.347-2.347a7.8 7.8 0 0 1-3.05 1.433 11 11 0 0 0-.377-1.76 6 6 0 1 0-7.185-7.185q-.855-.261-1.76-.379a7.8 7.8 0 0 1 1.432-3.049l-2.347-2.347A6 6 0 1 1 18 12m7.8 0a1.8 1.8 0 1 1-3.6 0 1.8 1.8 0 0 1 3.6 0M36 25.8a1.8 1.8 0 1 0 0-3.6 1.8 1.8 0 0 0 0 3.6m0-9.6a4.2 4.2 0 1 0 0-8.4 4.2 4.2 0 0 0 0 8.4M40.2 36a4.2 4.2 0 1 1-8.4 0 4.2 4.2 0 0 1 8.4 0",
2474
+ fill: "#fff",
2475
+ fillOpacity: ".36"
2476
+ }
2477
+ )
2478
+ ]
2479
+ }
2480
+ );
2481
+ };
2482
+ var EarnIcon = () => {
2483
+ return /* @__PURE__ */ jsxs(
2484
+ "svg",
2485
+ {
2486
+ width: "48",
2487
+ height: "48",
2488
+ viewBox: "0 0 48 48",
2489
+ fill: "none",
2490
+ xmlns: "http://www.w3.org/2000/svg",
2491
+ className: "lg:oui-w-[64px] lg:oui-h-[64px] 2xl:oui-w-[80px] 2xl:oui-h-[80px]",
2492
+ children: [
2493
+ /* @__PURE__ */ jsx(
2494
+ "path",
2495
+ {
2496
+ fillRule: "evenodd",
2497
+ clipRule: "evenodd",
2498
+ d: "M24 24a2.4 2.4 0 1 0 0-4.8 2.4 2.4 0 0 0 0 4.8m0 1.8a4.2 4.2 0 1 0 0-8.4 4.2 4.2 0 0 0 0 8.4",
2499
+ fill: "#fff",
2500
+ fillOpacity: ".36"
2501
+ }
2502
+ ),
2503
+ /* @__PURE__ */ jsx("path", { d: "M45 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0", fill: "#335FFC" }),
2504
+ /* @__PURE__ */ jsx(
2505
+ "path",
2506
+ {
2507
+ fillRule: "evenodd",
2508
+ clipRule: "evenodd",
2509
+ d: "M35.1 6.6a.9.9 0 1 1 1.8 0v.437A3 3 0 0 1 39 9.9h-1.8a1.2 1.2 0 1 0-1.2 1.2 3 3 0 0 1 .9 5.863v.437a.9.9 0 0 1-1.8 0v-.437A3 3 0 0 1 33 14.1h1.8a1.2 1.2 0 1 0 1.2-1.2 3 3 0 0 1-.9-5.863z",
2510
+ fill: "#fff",
2511
+ fillOpacity: ".98"
2512
+ }
2513
+ ),
2514
+ /* @__PURE__ */ jsx(
2515
+ "path",
2516
+ {
2517
+ fillRule: "evenodd",
2518
+ clipRule: "evenodd",
2519
+ d: "M40.2 23.7a.9.9 0 0 1 1.8 0v.6q0 .045-.004.086c-.197 9.351-7.525 16.948-16.765 17.573l1.205 1.205a.9.9 0 1 1-1.272 1.272l-2.7-2.7a.9.9 0 0 1 0-1.272l2.7-2.7a.9.9 0 1 1 1.272 1.272l-1.11 1.11c8.325-.674 14.87-7.642 14.874-16.14zM21.564 4.836a.9.9 0 1 1 1.272-1.272l2.7 2.7a.9.9 0 0 1 0 1.272l-2.7 2.7a.9.9 0 1 1-1.272-1.272l1.11-1.11C14.347 8.528 7.8 15.5 7.8 24v.3a.9.9 0 1 1-1.8 0v-.6l.004-.086C6.201 14.263 13.53 6.666 22.77 6.042z",
2520
+ fill: "#fff",
2521
+ fillOpacity: ".36"
2522
+ }
2523
+ ),
2524
+ /* @__PURE__ */ jsx(
2525
+ "path",
2526
+ {
2527
+ fillRule: "evenodd",
2528
+ clipRule: "evenodd",
2529
+ d: "M24 11.4q.615 0 1.213.058a11 11 0 0 0 .061 1.816Q24.647 13.2 24 13.2c-5.965 0-10.8 4.835-10.8 10.8 0 2.898 1.142 5.53 3 7.47a4.8 4.8 0 0 1 4.8-4.79h6a4.8 4.8 0 0 1 4.8 4.789c1.858-1.94 3-4.572 3-7.47q0-.647-.074-1.274a11 11 0 0 0 1.816.06q.057.6.058 1.214c0 6.959-5.641 12.6-12.6 12.6S11.4 30.959 11.4 24 17.041 11.4 24 11.4m6 21.581v-1.5a3 3 0 0 0-3-3h-6a3 3 0 0 0-3 3v1.5a10.75 10.75 0 0 0 6 1.819c2.22 0 4.284-.67 6-1.819",
2530
+ fill: "#fff",
2531
+ fillOpacity: ".36"
2532
+ }
2533
+ )
2534
+ ]
2535
+ }
2536
+ );
2537
+ };
2538
+ var ArrowDownIcon = () => {
2539
+ return /* @__PURE__ */ jsx(
2540
+ "svg",
2541
+ {
2542
+ width: "17",
2543
+ height: "16",
2544
+ viewBox: "0 0 17 16",
2545
+ fill: "none",
2546
+ xmlns: "http://www.w3.org/2000/svg",
2547
+ children: /* @__PURE__ */ jsx(
2548
+ "path",
2549
+ {
2550
+ d: "M8.5048 4.00806C8.8728 4.00806 9.1708 4.30626 9.1708 4.67406C9.1708 4.99259 9.1708 8.71739 9.1708 9.71072L11.1688 7.73339L12.1055 8.67005L8.98346 11.8127C8.85346 11.9434 8.6788 12.0081 8.50413 12.0081C8.33013 12.0081 8.15612 11.9427 8.02612 11.8127L4.90413 8.67005L5.8408 7.73339L7.83881 9.71072C7.83881 8.71739 7.83881 4.99259 7.83881 4.67406C7.83881 4.30626 8.1368 4.00806 8.5048 4.00806Z",
2551
+ fill: "#608CFF"
2552
+ }
2553
+ )
2554
+ }
2555
+ );
2556
+ };
2557
+
2558
+ // src/pages/home/becomeAffiliate/becomeAffiliate.script.tsx
2559
+ var useBecomeAffiliateScript = () => {
2560
+ const state = useReferralContext();
2561
+ return {
2562
+ overwrite: state.overwrite?.ref?.step,
2563
+ state
2564
+ };
2565
+ };
2566
+ var BecomeAffiliateWidget = () => {
2567
+ const state = useBecomeAffiliateScript();
2568
+ return /* @__PURE__ */ jsx(BecomeAffiliate, { ...state });
2569
+ };
2570
+ var Title5 = () => {
2571
+ const { t } = useTranslation();
2572
+ return /* @__PURE__ */ jsx(
2573
+ "div",
2574
+ {
2575
+ id: "oui-affiliate-home-title",
2576
+ className: "oui-text-center oui-text-3xl oui-font-bold md:oui-text-3xl lg:oui-text-4xl xl:oui-text-5xl",
2577
+ children: t("affiliate.page.title")
2578
+ }
2579
+ );
2580
+ };
2581
+ var TitleWidget = () => {
2582
+ return /* @__PURE__ */ jsx(Title5, {});
2583
+ };
2584
+ var Subtitle2 = (props) => {
2585
+ const { t } = useTranslation();
2586
+ return /* @__PURE__ */ jsxs(
2587
+ Flex,
2588
+ {
2589
+ id: "oui-affiliate-home-subtitle",
2590
+ direction: "column",
2591
+ className: "oui-text-sm md:oui-text-base xl:oui-text-lg oui-text-base-contrast-80 oui-text-center",
2592
+ gap: 3,
2593
+ children: [
2594
+ /* @__PURE__ */ jsx(Text, { children: t("affiliate.page.subTitle") }),
2595
+ /* @__PURE__ */ jsxs(
2596
+ Flex,
2597
+ {
2598
+ direction: "row",
2599
+ gap: 1,
2600
+ className: "oui-text-primary-light oui-fill-primary-light hover:oui-text-primary-darken oui-cursor-pointer oui-text-2xs md:oui-text-xs xl:oui-text-sm",
2601
+ onClick: (e) => {
2602
+ if (props.onLearnAffiliate) {
2603
+ props.onLearnAffiliate?.();
2604
+ } else if (props.learnAffiliateUrl) {
2605
+ window.open(props.learnAffiliateUrl, "_blank");
2606
+ }
2607
+ },
2608
+ children: [
2609
+ /* @__PURE__ */ jsx(Text, { children: t("affiliate.page.learnMore") }),
2610
+ /* @__PURE__ */ jsx(
2611
+ "svg",
2612
+ {
2613
+ width: "16",
2614
+ height: "16",
2615
+ viewBox: "0 0 16 16",
2616
+ fill: "currentColor",
2617
+ xmlns: "http://www.w3.org/2000/svg",
2618
+ children: /* @__PURE__ */ jsx("path", { d: "M4.008 7.995c0-.368.298-.666.666-.666H9.71L7.733 5.331l.937-.936 3.143 3.122c.13.13.195.304.195.479a.67.67 0 0 1-.195.478L8.67 11.596l-.937-.937 1.978-1.998H4.674a.666.666 0 0 1-.666-.666" })
2619
+ }
2620
+ )
2621
+ ]
2622
+ }
2623
+ )
2624
+ ]
2625
+ }
2626
+ );
2627
+ };
2628
+
2629
+ // src/pages/home/subtitle/subtitle.script.tsx
2630
+ var useSubtitleScript = () => {
2631
+ const state = useReferralContext();
2632
+ const { onLearnAffiliate, learnAffiliateUrl } = state;
2633
+ return {
2634
+ onLearnAffiliate,
2635
+ learnAffiliateUrl
2636
+ };
2637
+ };
2638
+ var SubtitleWidget = () => {
2639
+ const state = useSubtitleScript();
2640
+ return /* @__PURE__ */ jsx(Subtitle2, { ...state });
2641
+ };
2642
+ var Top = (props) => {
2643
+ if (props.overwriteTop !== void 0) {
2644
+ return props.overwriteTop?.(props.state);
2645
+ }
2646
+ return /* @__PURE__ */ jsxs(Flex, { id: "oui-affiliate-home-top", direction: "column", gap: 6, children: [
2647
+ /* @__PURE__ */ jsx(TitleWidget, {}),
2648
+ /* @__PURE__ */ jsx(SubtitleWidget, {})
2649
+ ] });
2650
+ };
2651
+
2652
+ // src/pages/home/top/top.script.tsx
2653
+ var useTopScript = () => {
2654
+ const state = useReferralContext();
2655
+ return {
2656
+ overwriteTop: state.overwrite?.ref?.top,
2657
+ state
2658
+ };
2659
+ };
2660
+ var TopWidget = () => {
2661
+ const state = useTopScript();
2662
+ return /* @__PURE__ */ jsx(Top, { ...state });
2663
+ };
2664
+ var ArrowRightIcon = (props) => {
2665
+ return /* @__PURE__ */ jsx(
2666
+ "svg",
2667
+ {
2668
+ width: "16",
2669
+ height: "16",
2670
+ viewBox: "0 0 16 16",
2671
+ fill: "white",
2672
+ fillOpacity: "0.98",
2673
+ xmlns: "http://www.w3.org/2000/svg",
2674
+ className: props.className,
2675
+ children: /* @__PURE__ */ jsx("path", { d: "M4.00806 7.9952C4.00806 7.6272 4.30626 7.3292 4.67406 7.3292C4.99259 7.3292 8.71739 7.3292 9.71072 7.3292L7.73339 5.3312L8.67005 4.39453L11.8127 7.51654C11.9434 7.64654 12.0081 7.8212 12.0081 7.99587C12.0081 8.16987 11.9427 8.34388 11.8127 8.47388L8.67005 11.5959L7.73339 10.6592L9.71072 8.66119C8.71739 8.66119 4.99259 8.66119 4.67406 8.66119C4.30626 8.66119 4.00806 8.3632 4.00806 7.9952Z" })
2676
+ }
2677
+ );
2678
+ };
2679
+ var AsTrader = (props) => {
2680
+ const { t } = useTranslation();
2681
+ return /* @__PURE__ */ jsxs(
2682
+ Flex,
2683
+ {
2684
+ id: "oui-affiliate-home-asTrader",
2685
+ gradient: "success",
2686
+ r: "2xl",
2687
+ p: 6,
2688
+ gap: 6,
2689
+ direction: "column",
2690
+ angle: 180,
2691
+ width: "100%",
2692
+ justify: "between",
2693
+ children: [
2694
+ /* @__PURE__ */ jsxs(
2695
+ Flex,
2696
+ {
2697
+ height: 80,
2698
+ direction: "row",
2699
+ gap: 3,
2700
+ itemAlign: "start",
2701
+ width: "100%",
2702
+ justify: "between",
2703
+ children: [
2704
+ /* @__PURE__ */ jsxs(
2705
+ Flex,
2706
+ {
2707
+ direction: "column",
2708
+ itemAlign: "start",
2709
+ justify: "between",
2710
+ className: "oui-h-full",
2711
+ children: [
2712
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-lg md:oui-text-xl lg:oui-text-2xl xl:oui-text-3xl", children: props.isTrader ? t("affiliate.trader") : t("affiliate.asTrader.title") }),
2713
+ /* @__PURE__ */ jsx(
2714
+ Text,
2715
+ {
2716
+ className: cn(
2717
+ "oui-text-xs oui-text-base-contrast-54 md:oui-text-sm 2xl:oui-text-base",
2718
+ props.isTrader && "oui-hidden"
2719
+ ),
2720
+ children: t("affiliate.asTrader.description")
2721
+ }
2722
+ )
2723
+ ]
2724
+ }
2725
+ ),
2726
+ /* @__PURE__ */ jsx("div", { className: "oui-shrink-0", children: /* @__PURE__ */ jsx(Icon, {}) })
2727
+ ]
2728
+ }
2729
+ ),
2730
+ /* @__PURE__ */ jsx(Bottom, { ...props })
2731
+ ]
2732
+ }
2733
+ );
2734
+ };
2735
+ var Icon = () => {
2736
+ return /* @__PURE__ */ jsxs(
2737
+ "svg",
2738
+ {
2739
+ width: "72",
2740
+ height: "72",
2741
+ viewBox: "0 0 90 90",
2742
+ fill: "none",
2743
+ xmlns: "http://www.w3.org/2000/svg",
2744
+ className: "xl:oui-size-[90px] ",
2745
+ children: [
2746
+ /* @__PURE__ */ jsx(
2747
+ "path",
2748
+ {
2749
+ d: "M44.996 7.324c-20.71 0-37.43 16.79-37.5 37.5-.07 20.682 16.806 37.575 37.5 37.617 20.694.04 37.537-17.082 37.5-37.617-.037-20.71-16.79-37.5-37.5-37.5m0 7.5c16.569 0 30 13.433 30 30 0 8.438-3.514 16.043-9.12 21.495-2.762-5.973-8.694-10.245-15.49-10.245h-10.78c-6.791 0-12.706 4.22-15.47 10.197-5.606-5.453-9.14-13.01-9.14-21.447 0-16.567 13.431-30 30-30m0 7.5c-8.284 0-15 6.717-15 15s6.716 15 15 15 15-6.716 15-15-6.716-15-15-15",
2750
+ fill: "#fff",
2751
+ fillOpacity: ".2"
2752
+ }
2753
+ ),
2754
+ /* @__PURE__ */ jsx(
2755
+ "path",
2756
+ {
2757
+ d: "M90 71.25C90 81.605 81.605 90 71.25 90S52.5 81.605 52.5 71.25 60.895 52.5 71.25 52.5 90 60.895 90 71.25",
2758
+ fill: "#005A4F"
2759
+ }
2760
+ ),
2761
+ /* @__PURE__ */ jsx(
2762
+ "path",
2763
+ {
2764
+ d: "M80.62 75.007c0-.24-.08-.49-.263-.675l-3.487-3.456-1.318 1.318 1.845 1.875H63.745a.938.938 0 0 0 0 1.875h13.652l-1.845 1.875 1.318 1.318 3.487-3.456a.95.95 0 0 0 .263-.674m-.937-7.5a.94.94 0 0 0-.938-.938H65.093l1.846-1.875-1.319-1.318-3.486 3.456a.966.966 0 0 0 0 1.349l3.486 3.456 1.319-1.318-1.846-1.875h13.652c.518 0 .938-.42.938-.937",
2765
+ fill: "#fff",
2766
+ fillOpacity: ".98"
2767
+ }
2768
+ )
2769
+ ]
2770
+ }
2771
+ );
2772
+ };
2773
+ var Bottom = (props) => {
2774
+ const { t } = useTranslation();
2775
+ const content = () => {
2776
+ if (props.isTrader && !props.wrongNetwork) {
2777
+ const totalReferrerRebate = props.referralInfo?.referee_info?.total_referee_rebate;
2778
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2779
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", itemAlign: "start", gap: 2, children: [
2780
+ /* @__PURE__ */ jsxs(Text, { className: "oui-text-2xs md:oui-text-xs xl:oui-text-sm", children: [
2781
+ t("affiliate.commission"),
2782
+ " ",
2783
+ /* @__PURE__ */ jsx(Text, { intensity: 36, children: "(USDC)" })
2784
+ ] }),
2785
+ /* @__PURE__ */ jsxs(Flex, { direction: "row", gap: 1, children: [
2786
+ /* @__PURE__ */ jsx(USDCIcon, {}),
2787
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-base md:oui-text-lg lg:oui-text-xl xl:oui-text-2xl", children: commifyOptional(totalReferrerRebate, {
2788
+ fix: 2,
2789
+ fallback: "0"
2790
+ }) })
2791
+ ] })
2792
+ ] }),
2793
+ /* @__PURE__ */ jsxs(
2794
+ Flex,
2795
+ {
2796
+ direction: "row",
2797
+ gap: 1,
2798
+ justify: "end",
2799
+ itemAlign: "center",
2800
+ className: "oui-cursor-pointer",
2801
+ onClick: props?.onEnterTraderPage,
2802
+ children: [
2803
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-sm md:oui-text-base xl:oui-text-lg", children: t("affiliate.enter") }),
2804
+ /* @__PURE__ */ jsx(ArrowRightIcon, { className: "md:oui-size-[18px] lg:oui-size-[20px] xl:oui-size-[24px]" })
2805
+ ]
2806
+ }
2807
+ )
2808
+ ] });
2809
+ }
2810
+ return /* @__PURE__ */ jsx(EntryCode, { ...props });
2811
+ };
2812
+ return /* @__PURE__ */ jsx(
2813
+ Flex,
2814
+ {
2815
+ direction: "row",
2816
+ justify: "between",
2817
+ width: "100%",
2818
+ itemAlign: "end",
2819
+ children: content()
2820
+ }
2821
+ );
2822
+ };
2823
+ var EntryCode = (props) => {
2824
+ const { t } = useTranslation();
2825
+ return /* @__PURE__ */ jsxs(Dialog, { open: props.open, onOpenChange: props.setOpen, children: [
2826
+ /* @__PURE__ */ jsx(DialogTrigger, { children: /* @__PURE__ */ jsx(Button, { variant: "contained", color: "light", children: t("affiliate.asTrader.button") }) }),
2827
+ /* @__PURE__ */ jsxs(DialogContent, { className: "oui-w-[320px] oui-font-semibold", children: [
2828
+ /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: t("affiliate.referralCode.dialog.title") }) }),
2829
+ /* @__PURE__ */ jsx(Divider, {}),
2830
+ /* @__PURE__ */ jsxs(DialogBody, { children: [
2831
+ /* @__PURE__ */ jsx(Text, { size: "sm", intensity: 54, children: t("affiliate.referralCode.dialog.description") }),
2832
+ /* @__PURE__ */ jsx(
2833
+ TextField,
2834
+ {
2835
+ className: "oui-mt-4 oui-w-full",
2836
+ placeholder: t("affiliate.referralCode"),
2837
+ value: props.code,
2838
+ onChange: (e) => {
2839
+ const _value = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, "");
2840
+ props.setCode(_value);
2841
+ },
2842
+ formatters: [
2843
+ inputFormatter.createRegexInputFormatter(
2844
+ (value) => {
2845
+ return String(value).replace(
2846
+ /[a-z]/g,
2847
+ (char) => char.toUpperCase()
2848
+ );
2849
+ }
2850
+ ),
2851
+ inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)
2852
+ ],
2853
+ onClean: () => {
2854
+ props.setCode("");
2855
+ },
2856
+ label: t("affiliate.referralCode.label"),
2857
+ classNames: {
2858
+ label: "oui-text-2xs oui-text-base-contrast-54"
2859
+ },
2860
+ helpText: !props.isExist && !props.isLoading && props.code.length > 0 ? t("affiliate.referralCode.notExist") : void 0,
2861
+ color: !props.isExist && !props.isLoading && props.code.length > 0 ? "danger" : void 0
2862
+ }
2863
+ ),
2864
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", gapY: 3, mt: 6, children: [
2865
+ props.warningMessage && /* @__PURE__ */ jsx(Text, { size: "2xs", className: "oui-text-warning-darken", children: props.warningMessage }),
2866
+ /* @__PURE__ */ jsx(AuthGuard, { buttonProps: { size: "md", fullWidth: true }, children: /* @__PURE__ */ jsx(
2867
+ Button,
2868
+ {
2869
+ variant: "contained",
2870
+ color: "primary",
2871
+ size: "md",
2872
+ className: "oui-px-[40px]",
2873
+ fullWidth: true,
2874
+ disabled: props.code.length < 4 || !props.isExist,
2875
+ onClick: (e) => {
2876
+ e.stopPropagation();
2877
+ props.onClickConfirm();
2878
+ },
2879
+ children: t("common.confirm")
2880
+ }
2881
+ ) })
2882
+ ] })
2883
+ ] })
2884
+ ] })
2885
+ ] });
2886
+ };
2887
+ var useAsTraderScript = () => {
2888
+ const { t } = useTranslation();
2889
+ const {
2890
+ isTrader,
2891
+ referralInfo,
2892
+ setShowHome,
2893
+ bindReferralCodeState,
2894
+ setTab,
2895
+ mutate
2896
+ } = useReferralContext();
2897
+ const { wrongNetwork, disabledConnect } = useAppContext();
2898
+ const { state } = useAccount();
2899
+ const onEnterTraderPage = () => {
2900
+ setTab("trader" /* trader */);
2901
+ setShowHome(false);
2902
+ };
2903
+ const [code, setCode] = useState("");
2904
+ const [open, setOpen] = useState(false);
2905
+ const {
2906
+ isExist,
2907
+ error: checkCodeError,
2908
+ isLoading
2909
+ } = useCheckReferralCode(code);
2910
+ const hide = () => {
2911
+ setOpen(false);
2912
+ };
2913
+ const [bindCode, { error, isMutating }] = useMutation(
2914
+ "/v1/referral/bind",
2915
+ "POST"
2916
+ );
2917
+ const onClickConfirm = async () => {
2918
+ try {
2919
+ await bindCode({ referral_code: code });
2920
+ toast.success(t("affiliate.referralCode.bound"));
2921
+ mutate();
2922
+ if (bindReferralCodeState) {
2923
+ bindReferralCodeState(true, null, hide, { tab: 1 });
2924
+ } else {
2925
+ hide();
2926
+ }
2927
+ } catch (e) {
2928
+ let errorText = `${e}`;
2929
+ if ("message" in e) {
2930
+ errorText = e.message;
2931
+ }
2932
+ if ("referral code not exist" === errorText) {
2933
+ errorText = t("affiliate.referralCode.notExist");
2934
+ }
2935
+ if (bindReferralCodeState) {
2936
+ toast.error(errorText);
2937
+ bindReferralCodeState(false, e, hide, {});
2938
+ } else {
2939
+ toast.error(errorText);
2940
+ }
2941
+ }
2942
+ };
2943
+ const { isMobile } = useScreen();
2944
+ const authStatus = useAuthStatus();
2945
+ const warningMessage = useMemo(() => {
2946
+ const message = {
2947
+ [AuthStatusEnum.ConnectWallet]: t("affiliate.connectWallet.tooltip"),
2948
+ [AuthStatusEnum.CreateAccount]: t("affiliate.createAccount.tooltip"),
2949
+ [AuthStatusEnum.WrongNetwork]: t("connector.wrongNetwork.tooltip")
2950
+ };
2951
+ return message[authStatus];
2952
+ }, [authStatus]);
2953
+ return {
2954
+ isTrader,
2955
+ isLoading,
2956
+ referralInfo,
2957
+ onEnterTraderPage,
2958
+ code,
2959
+ setCode,
2960
+ open,
2961
+ setOpen,
2962
+ onClickConfirm,
2963
+ isExist,
2964
+ wrongNetwork,
2965
+ isMobile,
2966
+ warningMessage
2967
+ };
2968
+ };
2969
+ var AsTraderWidget = () => {
2970
+ const state = useAsTraderScript();
2971
+ return /* @__PURE__ */ jsx(AsTrader, { ...state });
2972
+ };
2973
+ var AsAnAffiliate = (props) => {
2974
+ const { t } = useTranslation();
2975
+ return /* @__PURE__ */ jsxs(
2976
+ Flex,
2977
+ {
2978
+ id: "oui-affiliate-home-asAnAffiliate",
2979
+ gradient: "primary",
2980
+ r: "2xl",
2981
+ p: 6,
2982
+ gap: 6,
2983
+ direction: "column",
2984
+ angle: 180,
2985
+ width: "100%",
2986
+ justify: "between",
2987
+ children: [
2988
+ /* @__PURE__ */ jsxs(
2989
+ Flex,
2990
+ {
2991
+ direction: "row",
2992
+ gap: 3,
2993
+ itemAlign: "start",
2994
+ width: "100%",
2995
+ justify: "between",
2996
+ children: [
2997
+ /* @__PURE__ */ jsxs(
2998
+ Flex,
2999
+ {
3000
+ direction: "column",
3001
+ itemAlign: "start",
3002
+ justify: "between",
3003
+ className: "oui-h-full",
3004
+ children: [
3005
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-lg md:oui-text-xl lg:oui-text-2xl xl:oui-text-3xl", children: props.isAffiliate ? t("common.affiliate") : t("affiliate.asAffiliate.title") }),
3006
+ /* @__PURE__ */ jsx(
3007
+ Text,
3008
+ {
3009
+ className: cn(
3010
+ "oui-text-xs oui-text-base-contrast-54 md:oui-text-sm 2xl:oui-text-base",
3011
+ props.isAffiliate && "oui-hidden"
3012
+ ),
3013
+ children: t("affiliate.asAffiliate.description")
3014
+ }
3015
+ )
3016
+ ]
3017
+ }
3018
+ ),
3019
+ /* @__PURE__ */ jsx("div", { className: "oui-shrink-0", children: /* @__PURE__ */ jsx(Icon2, {}) })
3020
+ ]
3021
+ }
3022
+ ),
3023
+ /* @__PURE__ */ jsx(Bottom2, { ...props })
3024
+ ]
3025
+ }
3026
+ );
3027
+ };
3028
+ var Icon2 = () => {
3029
+ return /* @__PURE__ */ jsxs(
3030
+ "svg",
3031
+ {
3032
+ width: "72",
3033
+ height: "72",
3034
+ viewBox: "0 0 72 72",
3035
+ fill: "none",
3036
+ xmlns: "http://www.w3.org/2000/svg",
3037
+ className: "xl:oui-size-[90px]",
3038
+ children: [
3039
+ /* @__PURE__ */ jsx(
3040
+ "path",
3041
+ {
3042
+ d: "M35.997 5.86c-16.569 0-29.944 13.43-30 30-.056 16.545 13.445 30.06 30 30.093s30.03-13.665 30-30.093c-.03-16.57-13.432-30-30-30m0 6c13.255 0 24 10.746 24 24 0 6.75-2.812 12.834-7.297 17.196-2.209-4.78-6.955-8.196-12.39-8.196h-8.626c-5.432 0-10.164 3.375-12.375 8.157-4.485-4.362-7.312-10.407-7.312-17.157 0-13.254 10.745-24 24-24m0 6c-6.628 0-12 5.373-12 12s5.372 12 12 12c6.627 0 12-5.373 12-12s-5.373-12-12-12",
3043
+ fill: "#fff",
3044
+ fillOpacity: ".2"
3045
+ }
3046
+ ),
3047
+ /* @__PURE__ */ jsx(
3048
+ "path",
3049
+ {
3050
+ d: "M72 57c0 8.284-6.716 15-15 15s-15-6.716-15-15 6.716-15 15-15 15 6.716 15 15",
3051
+ fill: "#1828C3"
3052
+ }
3053
+ ),
3054
+ /* @__PURE__ */ jsx(
3055
+ "path",
3056
+ {
3057
+ d: "M53.624 51.45a4.125 4.125 0 0 0-4.125 4.125c0 2.388 1.36 4.641 3.61 6.703a21 21 0 0 0 2.414 1.875c.287.194.556.37.797.516.147.089.243.154.304.187a.79.79 0 0 0 .75 0c.061-.033.158-.098.305-.187.24-.147.51-.322.797-.516a21 21 0 0 0 2.414-1.875c2.25-2.062 3.61-4.315 3.61-6.703a4.125 4.125 0 0 0-4.126-4.125c-1.294 0-2.557.705-3.351 1.734-.775-1.047-2.034-1.734-3.399-1.734",
3058
+ fill: "#fff",
3059
+ fillOpacity: ".98"
3060
+ }
3061
+ )
3062
+ ]
3063
+ }
3064
+ );
3065
+ };
3066
+ var Bottom2 = (props) => {
3067
+ const { t } = useTranslation();
3068
+ const content = () => {
3069
+ if (props.isAffiliate && !props.wrongNetwork) {
3070
+ const totalReferrerRebate = props.referralInfo?.referrer_info?.total_referrer_rebate;
3071
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
3072
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", itemAlign: "start", gap: 2, children: [
3073
+ /* @__PURE__ */ jsxs(Text, { className: "oui-text-2xs md:oui-text-xs xl:oui-text-sm", children: [
3074
+ t("affiliate.commission"),
3075
+ " ",
3076
+ /* @__PURE__ */ jsx(Text, { intensity: 36, children: "(USDC)" })
3077
+ ] }),
3078
+ /* @__PURE__ */ jsxs(Flex, { direction: "row", gap: 1, children: [
3079
+ /* @__PURE__ */ jsx(USDCIcon, {}),
3080
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-base md:oui-text-lg lg:oui-text-xl xl:oui-text-2xl", children: commifyOptional(totalReferrerRebate, {
3081
+ fix: 2,
3082
+ fallback: "0"
3083
+ }) })
3084
+ ] })
3085
+ ] }),
3086
+ /* @__PURE__ */ jsxs(
3087
+ Flex,
3088
+ {
3089
+ direction: "row",
3090
+ gap: 1,
3091
+ justify: "end",
3092
+ itemAlign: "center",
3093
+ className: "oui-cursor-pointer",
3094
+ onClick: props.onEnterAffiliatePage,
3095
+ children: [
3096
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-sm md:oui-text-base xl:oui-text-lg", children: t("affiliate.enter") }),
3097
+ /* @__PURE__ */ jsx(ArrowRightIcon, { className: "md:oui-size-[18px] lg:oui-size-[20px] xl:oui-size-[24px]" })
3098
+ ]
3099
+ }
3100
+ )
3101
+ ] });
3102
+ }
3103
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
3104
+ /* @__PURE__ */ jsx(
3105
+ Button,
3106
+ {
3107
+ variant: "contained",
3108
+ color: "light",
3109
+ onClick: props.becomeAnAffiliate,
3110
+ children: t("affiliate.asAffiliate.button")
3111
+ }
3112
+ ),
3113
+ /* @__PURE__ */ jsxs(
3114
+ Flex,
3115
+ {
3116
+ direction: "column",
3117
+ justify: "between",
3118
+ className: "oui-h-full",
3119
+ itemAlign: "end",
3120
+ children: [
3121
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-base md:oui-text-lg lg:oui-text-xl 2xl:oui-text-2xl", children: t("affiliate.upTo") }),
3122
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-2xs oui-text-base-contrast-54 md:oui-text-xs 2xl:oui-text-sm", children: t("affiliate.commission") })
3123
+ ]
3124
+ }
3125
+ )
3126
+ ] });
3127
+ };
3128
+ return /* @__PURE__ */ jsx(
3129
+ Flex,
3130
+ {
3131
+ direction: "row",
3132
+ justify: "between",
3133
+ width: "100%",
3134
+ itemAlign: "end",
3135
+ children: content()
3136
+ }
3137
+ );
3138
+ };
3139
+ var useAsAnAffiliateScript = () => {
3140
+ const {
3141
+ isAffiliate,
3142
+ isLoading,
3143
+ referralInfo,
3144
+ becomeAnAffiliateUrl,
3145
+ setShowHome,
3146
+ setTab
3147
+ } = useReferralContext();
3148
+ const { wrongNetwork } = useAppContext();
3149
+ const becomeAnAffiliate = () => {
3150
+ window.open(becomeAnAffiliateUrl, "_blank");
3151
+ };
3152
+ const onEnterAffiliatePage = () => {
3153
+ setTab("affiliate" /* affiliate */);
3154
+ setShowHome(false);
3155
+ };
3156
+ const { isMobile } = useScreen();
3157
+ return {
3158
+ isAffiliate,
3159
+ isLoading,
3160
+ referralInfo,
3161
+ onEnterAffiliatePage,
3162
+ becomeAnAffiliate,
3163
+ wrongNetwork,
3164
+ isMobile
3165
+ };
3166
+ };
3167
+ var AsAnAffiliateWidget = () => {
3168
+ const state = useAsAnAffiliateScript();
3169
+ return /* @__PURE__ */ jsx(AsAnAffiliate, { ...state });
3170
+ };
3171
+ var Card = (props) => {
3172
+ if (typeof props.overwrite === "function") {
3173
+ return props.overwrite?.(props.state);
3174
+ }
3175
+ return /* @__PURE__ */ jsxs(
3176
+ Flex,
3177
+ {
3178
+ id: "oui-affiliate-home-card",
3179
+ className: "oui-flex oui-w-full oui-flex-col oui-items-stretch oui-gap-6 xl:oui-flex-row xl:oui-gap-[36px]",
3180
+ children: [
3181
+ /* @__PURE__ */ jsx(AsAnAffiliateWidget, {}),
3182
+ /* @__PURE__ */ jsx(AsTraderWidget, {})
3183
+ ]
3184
+ }
3185
+ );
3186
+ };
3187
+
3188
+ // src/pages/home/card/card.script.tsx
3189
+ var useCardScript = () => {
3190
+ const state = useReferralContext();
3191
+ return {
3192
+ overwrite: state.overwrite?.ref?.card,
3193
+ state
3194
+ };
3195
+ };
3196
+ var CardWidget = () => {
3197
+ const state = useCardScript();
3198
+ return /* @__PURE__ */ jsx(Card, { ...state });
3199
+ };
3200
+ var HomePage = () => {
3201
+ return /* @__PURE__ */ jsxs(
3202
+ Flex,
3203
+ {
3204
+ id: "oui-affiliate-home-page",
3205
+ className: cn(
3206
+ "oui-h-lvw ",
3207
+ // padding
3208
+ // "oui-p-4 lg:oui-p-6 xl:oui-p-3",
3209
+ "oui-font-semibold"
3210
+ ),
3211
+ direction: "column",
3212
+ gap: 4,
3213
+ children: [
3214
+ /* @__PURE__ */ jsx(TopWidget, {}),
3215
+ /* @__PURE__ */ jsx(CardWidget, {}),
3216
+ /* @__PURE__ */ jsx(BecomeAffiliateWidget, {})
3217
+ ]
3218
+ }
3219
+ );
3220
+ };
3221
+ var Summary2 = (props) => {
3222
+ const { t } = useTranslation();
3223
+ return /* @__PURE__ */ jsxs(
3224
+ Flex,
3225
+ {
3226
+ id: "oui-affiliate-trader-summary",
3227
+ r: "2xl",
3228
+ p: 6,
3229
+ width: "100%",
3230
+ height: "100%",
3231
+ gap: 4,
3232
+ direction: "column",
3233
+ className: "oui-bg-base-9 xl:oui-flex-1",
3234
+ children: [
3235
+ /* @__PURE__ */ jsx(Title6, { ...props }),
3236
+ /* @__PURE__ */ jsx(Rebate, { className: "md:oui-hidden", ...props }),
3237
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 3, width: "100%", className: "md:oui-mt-3", children: [
3238
+ /* @__PURE__ */ jsx(SummaryFilter, { ...props }),
3239
+ /* @__PURE__ */ jsx(CommissionData2, { ...props })
3240
+ ] }),
3241
+ /* @__PURE__ */ jsx(Row2, { title: `${t("affiliate.trader.tradingVol")} (USDC)`, ...props })
3242
+ ]
3243
+ }
3244
+ );
3245
+ };
3246
+ var Title6 = (props) => {
3247
+ const { t } = useTranslation();
3248
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", width: "100%", gap: 3, children: [
3249
+ /* @__PURE__ */ jsxs(Flex, { direction: "row", gap: 3, className: "oui-flex-1", children: [
3250
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-lg", children: t("affiliate.trader.yourReferrer") }),
3251
+ /* @__PURE__ */ jsx(
3252
+ Button,
3253
+ {
3254
+ color: "secondary",
3255
+ size: "sm",
3256
+ className: "oui-text-primary-light oui-text-2xs md:oui-text-xs 2xl:oui-text-sm oui-bg-base-6",
3257
+ children: props.code
3258
+ }
3259
+ )
3260
+ ] }),
3261
+ /* @__PURE__ */ jsx(
3262
+ Rebate,
3263
+ {
3264
+ className: "oui-hidden md:oui-flex md:oui-flex-shrink md:oui-w-fit",
3265
+ ...props
3266
+ }
3267
+ )
3268
+ ] });
3269
+ };
3270
+ var Rebate = (props) => {
3271
+ const { t } = useTranslation();
3272
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", width: "100%", gap: 2, className: props.className, children: [
3273
+ /* @__PURE__ */ jsx(
3274
+ Text,
3275
+ {
3276
+ intensity: 54,
3277
+ className: "oui-text-sm md:oui-text-base 2xl:oui-text-lg",
3278
+ children: `${t("affiliate.trader.rebate")}:`
3279
+ }
3280
+ ),
3281
+ /* @__PURE__ */ jsx(
3282
+ Text.gradient,
3283
+ {
3284
+ color: "brand",
3285
+ className: "oui-text-lg md:oui-text-xl 2xl:oui-text-2xl",
3286
+ children: props.rebateText
3287
+ }
3288
+ )
3289
+ ] });
3290
+ };
3291
+ var SummaryFilter = (props) => {
3292
+ const { t } = useTranslation();
3293
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", width: "100%", justify: "between", gap: 3, children: [
3294
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-sm", children: t("affiliate.summary") }),
3295
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
3296
+ Select.options,
3297
+ {
3298
+ size: "xs",
3299
+ value: props.period,
3300
+ onValueChange: props.onPeriodChange,
3301
+ options: props.periodTypes
3302
+ }
3303
+ ) })
3304
+ ] });
3305
+ };
3306
+ var CommissionData2 = (props) => {
3307
+ const { t } = useTranslation();
3308
+ return /* @__PURE__ */ jsxs(
3309
+ Flex,
3310
+ {
3311
+ gradient: "success",
3312
+ angle: 180,
3313
+ r: "xl",
3314
+ py: 4,
3315
+ px: 6,
3316
+ width: "100%",
3317
+ direction: "column",
3318
+ gap: 3,
3319
+ children: [
3320
+ /* @__PURE__ */ jsx(Text, { intensity: 54, className: "oui-text-base 2xl:oui-text-lg", children: `${t("affiliate.trader.rebates")} (USDC)` }),
3321
+ /* @__PURE__ */ jsxs(
3322
+ Flex,
3323
+ {
3324
+ direction: "row",
3325
+ gap: 3,
3326
+ className: "oui-text-xl md:oui-text-2xl xl:oui-text-3xl",
3327
+ children: [
3328
+ /* @__PURE__ */ jsx(USDCIcon, { className: "md:oui-w-[24px] md:oui-h-[24px] lg:oui-w-[28px] lg:oui-h-[28px] " }),
3329
+ /* @__PURE__ */ jsx(Text, { children: commifyOptional(props.rebates, { fix: 2, fallback: "0" }) })
3330
+ ]
3331
+ }
3332
+ )
3333
+ ]
3334
+ }
3335
+ );
3336
+ };
3337
+ var Row2 = (props) => {
3338
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", justify: "between", width: "100%", children: [
3339
+ /* @__PURE__ */ jsx(
3340
+ Text,
3341
+ {
3342
+ intensity: 54,
3343
+ className: "oui-text-2xs md:oui-text-xs xl:oui-text-sm",
3344
+ children: props.title
3345
+ }
3346
+ ),
3347
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-xs md:oui-text-sm xl:oui-text-base", children: commifyOptional(props.vol, { fix: 2, fallback: "0" }) })
3348
+ ] });
3349
+ };
3350
+ var useSummaryScript2 = () => {
3351
+ const { t } = useTranslation();
3352
+ const [period, setPeriod] = useState("All");
3353
+ const periodTypes = [
3354
+ { label: t("common.all"), value: "All" },
3355
+ { label: t("common.select.1d"), value: "1D" },
3356
+ { label: t("common.select.7d"), value: "7D" },
3357
+ { label: t("common.select.30d"), value: "30D" }
3358
+ ];
3359
+ const { referralInfo, userVolume } = useReferralContext();
3360
+ const rebates = useMemo(() => {
3361
+ if (!referralInfo)
3362
+ return 0;
3363
+ switch (period) {
3364
+ case "All":
3365
+ return referralInfo.referee_info.total_referee_rebate;
3366
+ case "1D":
3367
+ return referralInfo.referee_info["1d_referee_rebate"];
3368
+ case "7D":
3369
+ return referralInfo.referee_info["7d_referee_rebate"];
3370
+ case "30D":
3371
+ return referralInfo.referee_info["30d_referee_rebate"];
3372
+ }
3373
+ }, [referralInfo, period]);
3374
+ const vol = useMemo(() => {
3375
+ if (!userVolume)
3376
+ return void 0;
3377
+ switch (period) {
3378
+ case "All":
3379
+ return userVolume.all_volume;
3380
+ case "1D":
3381
+ return userVolume["1d_volume"];
3382
+ case "7D":
3383
+ return userVolume["7d_volume"];
3384
+ case "30D":
3385
+ return userVolume["30d_volume"];
3386
+ }
3387
+ }, [userVolume, period]);
3388
+ const code = referralInfo?.referee_info?.referer_code;
3389
+ const rebate = referralInfo?.referee_info?.referee_rebate_rate;
3390
+ const rebateText = useMemo(() => {
3391
+ if (!!rebate) {
3392
+ return new Decimal(rebate).mul(100).toDecimalPlaces(2, Decimal.ROUND_DOWN).toString() + "%";
3393
+ }
3394
+ return "-";
3395
+ }, [rebate]);
3396
+ const onPeriodChange = (item) => {
3397
+ setPeriod(item);
3398
+ };
3399
+ return {
3400
+ period,
3401
+ periodTypes,
3402
+ onPeriodChange,
3403
+ rebates,
3404
+ vol,
3405
+ rebateText,
3406
+ code
3407
+ };
3408
+ };
3409
+ var SummaryWidget2 = () => {
3410
+ const state = useSummaryScript2();
3411
+ return /* @__PURE__ */ jsx(Summary2, { ...state });
3412
+ };
3413
+ var TitleStatistic2 = (props) => {
3414
+ return /* @__PURE__ */ jsxs(
3415
+ Flex,
3416
+ {
3417
+ id: "oui-affiliate-trader-titleStatistic",
3418
+ r: "2xl",
3419
+ p: 6,
3420
+ width: "100%",
3421
+ gap: 4,
3422
+ direction: "column",
3423
+ className: "oui-bg-base-9 xl:oui-flex-1",
3424
+ children: [
3425
+ /* @__PURE__ */ jsx(Title7, { ...props }),
3426
+ /* @__PURE__ */ jsx(Flex, { className: "oui-min-h-[170px] oui-h-full oui-w-full oui-flex oui-flex-row oui-items-stretch", children: /* @__PURE__ */ jsx(
3427
+ VolBarChart,
3428
+ {
3429
+ data: props.dataSource,
3430
+ colors: { fill: "rgba(0, 180, 158, 1)" },
3431
+ className: "oui-w-full oui-flex-1",
3432
+ tooltip: {
3433
+ rm: Decimal.ROUND_DOWN,
3434
+ dp: props.volType === "volume" ? 2 : 6
3435
+ }
3436
+ }
3437
+ ) })
3438
+ ]
3439
+ }
3440
+ );
3441
+ };
3442
+ var Title7 = (props) => {
3443
+ const { t } = useTranslation();
3444
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", justify: "between", width: "100%", children: [
3445
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-lg", children: t("affiliate.statistics") }),
3446
+ /* @__PURE__ */ jsxs(Flex, { direction: "row", gap: 2, className: "oui-min-w-14", children: [
3447
+ /* @__PURE__ */ jsx(
3448
+ Select.options,
3449
+ {
3450
+ size: "xs",
3451
+ value: props.period,
3452
+ onValueChange: props.onPeriodChange,
3453
+ options: props.periodTypes
3454
+ }
3455
+ ),
3456
+ /* @__PURE__ */ jsx(
3457
+ Select.options,
3458
+ {
3459
+ size: "xs",
3460
+ value: props.volType,
3461
+ onValueChange: props.onVolTypeChange,
3462
+ options: props.volTypes
3463
+ }
3464
+ )
3465
+ ] })
3466
+ ] });
3467
+ };
3468
+ var useTitleStatisticScript2 = () => {
3469
+ const { t } = useTranslation();
3470
+ const [period, setPeriod] = useState("7");
3471
+ const periodTypes = [
3472
+ { label: t("common.select.7d"), value: "7" },
3473
+ { label: t("common.select.30d"), value: "30" },
3474
+ { label: t("common.select.90d"), value: "90" }
3475
+ ];
3476
+ const onPeriodChange = (item) => {
3477
+ setPeriod(item);
3478
+ };
3479
+ const [volType, setVolType] = useState("rebate");
3480
+ const volTypes = [
3481
+ { label: t("affiliate.trader.rebate"), value: "rebate" },
3482
+ { label: t("common.volume"), value: "volume" }
3483
+ ];
3484
+ const onVolTypeChange = (item) => {
3485
+ setVolType(item);
3486
+ };
3487
+ const dateRange = useMemo(() => {
3488
+ if (period === "7") {
3489
+ return {
3490
+ startDate: subDays(/* @__PURE__ */ new Date(), 7),
3491
+ endDate: subDays(/* @__PURE__ */ new Date(), 1)
3492
+ };
3493
+ } else if (period === "30") {
3494
+ return {
3495
+ startDate: subDays(/* @__PURE__ */ new Date(), 30),
3496
+ endDate: subDays(/* @__PURE__ */ new Date(), 1)
3497
+ };
3498
+ } else if (period === "90") {
3499
+ return {
3500
+ startDate: subDays(/* @__PURE__ */ new Date(), 90),
3501
+ endDate: subDays(/* @__PURE__ */ new Date(), 1)
3502
+ };
3503
+ } else {
3504
+ return {
3505
+ startDate: subDays(/* @__PURE__ */ new Date(), 7),
3506
+ endDate: subDays(/* @__PURE__ */ new Date(), 1)
3507
+ };
3508
+ }
3509
+ }, [period]);
3510
+ const { data: distributionData, mutate } = useRefereeRebateSummary(dateRange);
3511
+ const { dailyVolume, chartConfig } = useReferralContext();
3512
+ const dataSource = useMemo(() => {
3513
+ if (volType === "rebate") {
3514
+ const newData = distributionData || [];
3515
+ return newData.map((e) => ({
3516
+ date: e.date,
3517
+ volume: e.referee_rebate
3518
+ })).reverse();
3519
+ } else if (volType === "volume") {
3520
+ return dailyVolume?.filter((e) => {
3521
+ return e.date > format(subDays(Date(), Number(period) + 1), "yyyy-MM-dd");
3522
+ }).map((e) => ({
3523
+ date: e.date,
3524
+ volume: e.perp_volume
3525
+ })) || [];
3526
+ } else {
3527
+ return [];
3528
+ }
3529
+ }, [distributionData, dailyVolume, volType]);
3530
+ return {
3531
+ period,
3532
+ periodTypes,
3533
+ onPeriodChange,
3534
+ volType,
3535
+ volTypes,
3536
+ onVolTypeChange,
3537
+ dataSource: fillData(Number(period), dataSource)
3538
+ };
3539
+ };
3540
+ var TitleStatisticWidget2 = () => {
3541
+ const state = useTitleStatisticScript2();
3542
+ return /* @__PURE__ */ jsx(TitleStatistic2, { ...state });
3543
+ };
3544
+ var Rebates = (props) => {
3545
+ return /* @__PURE__ */ jsxs(
3546
+ Flex,
3547
+ {
3548
+ id: "oui-affiliate-trader-rebates",
3549
+ r: "2xl",
3550
+ p: 6,
3551
+ width: "100%",
3552
+ gap: 4,
3553
+ direction: "column",
3554
+ className: "oui-bg-base-9 oui-tabular-nums",
3555
+ children: [
3556
+ /* @__PURE__ */ jsx(Title8, { ...props }),
3557
+ /* @__PURE__ */ jsx(
3558
+ Flex,
3559
+ {
3560
+ width: "100%",
3561
+ className: "oui-border-y-2 oui-border-line-6",
3562
+ height: 49,
3563
+ direction: "row",
3564
+ itemAlign: "center",
3565
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
3566
+ DatePicker.range,
3567
+ {
3568
+ size: "xs",
3569
+ value: props.dateRange,
3570
+ onChange: (range) => {
3571
+ props.setDateRange(range);
3572
+ },
3573
+ max: 90,
3574
+ disabled: {
3575
+ after: /* @__PURE__ */ new Date()
3576
+ }
3577
+ }
3578
+ ) })
3579
+ }
3580
+ ),
3581
+ /* @__PURE__ */ jsx(List, { ...props })
3582
+ ]
3583
+ }
3584
+ );
3585
+ };
3586
+ var Title8 = (props) => {
3587
+ const { t } = useTranslation();
3588
+ return /* @__PURE__ */ jsxs(Flex, { direction: "row", justify: "between", width: "100%", children: [
3589
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-lg", children: t("affiliate.trader.myRebates") }),
3590
+ /* @__PURE__ */ jsx(Text, { intensity: 36, className: "oui-text-2xs", children: props.displayDate })
3591
+ ] });
3592
+ };
3593
+ var List = (props) => {
3594
+ const { t } = useTranslation();
3595
+ const layout767 = useMediaQuery("(max-width: 767px)");
3596
+ const columns = [
3597
+ {
3598
+ title: `${t("affiliate.trader.rebates")} (USDC)`,
3599
+ dataIndex: "referee_rebate",
3600
+ render: (value) => /* @__PURE__ */ jsx(Text, { children: commifyOptional(value, {
3601
+ fix: 6,
3602
+ fallback: "0",
3603
+ padEnd: true,
3604
+ prefix: "$"
3605
+ }) }),
3606
+ width: 127
3607
+ },
3608
+ {
3609
+ title: `${t("affiliate.trader.tradingVol")} (USDC)`,
3610
+ dataIndex: "vol",
3611
+ render: (value) => commifyOptional(value, {
3612
+ fix: 2,
3613
+ fallback: "0",
3614
+ padEnd: true,
3615
+ prefix: "$"
3616
+ }),
3617
+ width: 127
3618
+ },
3619
+ {
3620
+ title: t("common.date"),
3621
+ dataIndex: "date",
3622
+ render: (value) => /* @__PURE__ */ jsx(Text.formatted, { formatString: "yyyy-MM-dd", children: value }),
3623
+ width: 127
3624
+ }
3625
+ ];
3626
+ if (layout767) {
3627
+ return /* @__PURE__ */ jsx(
3628
+ ListView,
3629
+ {
3630
+ dataSource: props.dataSource,
3631
+ className: "oui-h-[197px] oui-w-full",
3632
+ renderItem: (item, index) => {
3633
+ return /* @__PURE__ */ jsx(Cell, { item });
3634
+ }
3635
+ }
3636
+ );
3637
+ }
3638
+ return /* @__PURE__ */ jsx(
3639
+ AuthGuardDataTable,
3640
+ {
3641
+ bordered: true,
3642
+ loading: props.isLoading,
3643
+ columns,
3644
+ dataSource: props.dataSource,
3645
+ ignoreLoadingCheck: true,
3646
+ onRow: (record) => {
3647
+ return {
3648
+ className: "oui-h-[41px]"
3649
+ };
3650
+ },
3651
+ pagination: props.pagination,
3652
+ manualPagination: false
3653
+ }
3654
+ );
3655
+ };
3656
+ var Cell = (props) => {
3657
+ const { t } = useTranslation();
3658
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", width: "100%", children: [
3659
+ /* @__PURE__ */ jsxs(Flex, { width: "100%", gap: 1, children: [
3660
+ /* @__PURE__ */ jsx(
3661
+ Statistic,
3662
+ {
3663
+ label: `${t("affiliate.trader.rebates")} (USDC)`,
3664
+ className: "oui-text-xs oui-text-base-contrast-54 oui-flex-1 oui-min-w-[105px]",
3665
+ children: /* @__PURE__ */ jsx(Text, { size: "sm", intensity: 80, children: commifyOptional(props.item.referee_rebate, {
3666
+ fix: 6,
3667
+ fallback: "0",
3668
+ padEnd: true,
3669
+ prefix: "$"
3670
+ }) })
3671
+ }
3672
+ ),
3673
+ /* @__PURE__ */ jsx(
3674
+ Statistic,
3675
+ {
3676
+ label: `${t("affiliate.trader.tradingVol")} (USDC)`,
3677
+ className: "oui-text-xs oui-text-base-contrast-54 oui-flex-shrink",
3678
+ children: /* @__PURE__ */ jsx(Text, { size: "sm", intensity: 80, children: commifyOptional(props.item.vol, {
3679
+ fix: 2,
3680
+ fallback: "0",
3681
+ padEnd: true,
3682
+ prefix: "$"
3683
+ }) })
3684
+ }
3685
+ ),
3686
+ /* @__PURE__ */ jsx(
3687
+ Statistic,
3688
+ {
3689
+ label: t("common.date"),
3690
+ className: "oui-text-xs oui-text-base-contrast-54 oui-flex-1",
3691
+ align: "end",
3692
+ children: /* @__PURE__ */ jsx(Text.formatted, { size: "sm", intensity: 80, formatString: "yyyy-MM-dd", children: props.item.date })
3693
+ }
3694
+ )
3695
+ ] }),
3696
+ /* @__PURE__ */ jsx(Divider, { className: "oui-w-full oui-mt-3" })
3697
+ ] });
3698
+ };
3699
+ var useRebatesScript = () => {
3700
+ const [dateRange, setDateRange] = useState({
3701
+ from: subDays(/* @__PURE__ */ new Date(), 90),
3702
+ to: subDays(/* @__PURE__ */ new Date(), 1)
3703
+ });
3704
+ const {
3705
+ data: distributionData,
3706
+ mutate,
3707
+ isLoading
3708
+ } = useRefereeRebateSummary({
3709
+ startDate: dateRange?.from,
3710
+ endDate: dateRange?.to
3711
+ });
3712
+ const { data: dailyVolume, mutate: dailyVolumeMutate } = useDaily({
3713
+ startDate: dateRange?.to,
3714
+ endDate: dateRange?.from
3715
+ });
3716
+ const dataSource = useMemo(() => {
3717
+ if (typeof distributionData === "undefined")
3718
+ return [];
3719
+ return distributionData.map((item) => {
3720
+ const createdTime = item.date;
3721
+ const volume = dailyVolume?.filter((item2) => {
3722
+ return compareDate(toDate(createdTime), toDate(item2.date));
3723
+ })?.[0];
3724
+ if (volume) {
3725
+ return { ...item, vol: volume.perp_volume };
3726
+ }
3727
+ return item;
3728
+ });
3729
+ }, [distributionData, dailyVolume]);
3730
+ let displayDate = void 0;
3731
+ if ((dataSource?.length || 0) > 0) {
3732
+ displayDate = formatDateTimeToUTC(dataSource?.[0].date);
3733
+ }
3734
+ const { pagination, setPage } = usePagination();
3735
+ useEffect(() => {
3736
+ setPage(1);
3737
+ }, [dateRange]);
3738
+ return {
3739
+ dateRange,
3740
+ setDateRange,
3741
+ displayDate,
3742
+ dataSource,
3743
+ // meta,
3744
+ // onPageChange,
3745
+ // onPageSizeChange,
3746
+ pagination,
3747
+ isLoading
3748
+ };
3749
+ };
3750
+ var RebatesWidget = () => {
3751
+ const state = useRebatesScript();
3752
+ return /* @__PURE__ */ jsx(Rebates, { ...state });
3753
+ };
3754
+ var TraderPage = () => {
3755
+ return /* @__PURE__ */ jsxs(
3756
+ Flex,
3757
+ {
3758
+ id: "oui-affiliate-trader-page",
3759
+ className: cn(
3760
+ "oui-h-lvw oui-w-full",
3761
+ // padding
3762
+ // "oui-p-4 lg:oui-p-6 xl:oui-p-3",
3763
+ "oui-font-semibold"
3764
+ ),
3765
+ direction: "column",
3766
+ gap: 4,
3767
+ children: [
3768
+ /* @__PURE__ */ jsxs(
3769
+ Flex,
3770
+ {
3771
+ width: "100%",
3772
+ gap: 4,
3773
+ className: "oui-flex oui-flex-col xl:oui-flex-row xl:oui-items-stretch",
3774
+ children: [
3775
+ /* @__PURE__ */ jsx(SummaryWidget2, {}),
3776
+ /* @__PURE__ */ jsx(TitleStatisticWidget2, {})
3777
+ ]
3778
+ }
3779
+ ),
3780
+ /* @__PURE__ */ jsx(RebatesWidget, {})
3781
+ ]
3782
+ }
3783
+ );
3784
+ };
3785
+ var Tab = (props) => {
3786
+ const { t } = useTranslation();
3787
+ const extendNode = () => {
3788
+ if (props.isAffiliate && !props.isTrader) {
3789
+ return /* @__PURE__ */ jsxs(
3790
+ Button,
3791
+ {
3792
+ variant: "contained",
3793
+ color: "success",
3794
+ size: "sm",
3795
+ className: "oui-px-2 oui-flex oui-gap-1",
3796
+ style: {
3797
+ position: "absolute",
3798
+ top: "50%",
3799
+ right: "24px",
3800
+ transform: "translateY(-50%)"
3801
+ },
3802
+ onClick: (e) => {
3803
+ props.anATrader();
3804
+ },
3805
+ children: [
3806
+ /* @__PURE__ */ jsx(TraderIcon, {}),
3807
+ /* @__PURE__ */ jsx(Text, { children: t("affiliate.asTrader.title") })
3808
+ ]
3809
+ }
3810
+ );
3811
+ }
3812
+ if (!props.isAffiliate && props.isTrader) {
3813
+ return /* @__PURE__ */ jsxs(
3814
+ Button,
3815
+ {
3816
+ variant: "contained",
3817
+ color: "primary",
3818
+ size: "sm",
3819
+ className: "oui-px-2 oui-flex oui-gap-1",
3820
+ style: {
3821
+ position: "absolute",
3822
+ top: "50%",
3823
+ right: "24px",
3824
+ transform: "translateY(-50%)"
3825
+ },
3826
+ onClick: (e) => {
3827
+ props.anAnAffiliate();
3828
+ },
3829
+ children: [
3830
+ /* @__PURE__ */ jsx(AffiliateIcon, {}),
3831
+ /* @__PURE__ */ jsx(Text, { children: t("affiliate.asAffiliate.title") })
3832
+ ]
3833
+ }
3834
+ );
3835
+ }
3836
+ return void 0;
3837
+ };
3838
+ if (props.isLoading) {
3839
+ return /* @__PURE__ */ jsx("div", { className: cn("oui-max-w-[960px]", props.classNames?.loadding), children: props.splashPage?.() || /* @__PURE__ */ jsx(HomePage, {}) });
3840
+ }
3841
+ if (!props.isAffiliate && !props.isTrader || props.showHome) {
3842
+ return /* @__PURE__ */ jsx("div", { className: cn("oui-max-w-[960px]", props?.classNames?.home), children: /* @__PURE__ */ jsx(HomePage, {}) });
3843
+ }
3844
+ return /* @__PURE__ */ jsxs(
3845
+ TabsBase,
3846
+ {
3847
+ id: "oui-affiliate-dashboard-tab",
3848
+ value: props.tab,
3849
+ onValueChange: (e) => {
3850
+ props.setTab(e);
3851
+ },
3852
+ className: cn("oui-w-full", props.classNames?.dashboard),
3853
+ children: [
3854
+ /* @__PURE__ */ jsxs(
3855
+ TabsList,
3856
+ {
3857
+ className: cn(
3858
+ "oui-px-6 oui-flex oui-flex-row oui-justify-start oui-h-[44px] oui-relative oui-items-end",
3859
+ "oui-text-base md:oui-text-lg",
3860
+ "oui-rounded-xl oui-bg-base-9",
3861
+ "oui-border oui-border-line-6",
3862
+ props.isAffiliate && props.isTrader && "oui-justify-center"
3863
+ ),
3864
+ children: [
3865
+ props.isAffiliate && /* @__PURE__ */ jsx(
3866
+ TabsTrigger,
3867
+ {
3868
+ id: "oui-affiliate-dashboard-tab-affiliate",
3869
+ value: "affiliate" /* affiliate */,
3870
+ children: /* @__PURE__ */ jsxs(Flex, { direction: "row", gap: 1, mb: 2, children: [
3871
+ /* @__PURE__ */ jsx(
3872
+ AffiliateIcon,
3873
+ {
3874
+ fillOpacity: 1,
3875
+ fill: "currentColor",
3876
+ className: props.tab === "affiliate" /* affiliate */ ? "oui-fill-white/[.98]" : "oui-fill-white/[.36]"
3877
+ }
3878
+ ),
3879
+ /* @__PURE__ */ jsx(Text, { children: t("common.affiliate") })
3880
+ ] })
3881
+ }
3882
+ ),
3883
+ props.isTrader && /* @__PURE__ */ jsx(
3884
+ TabsTrigger,
3885
+ {
3886
+ id: "oui-affiliate-dashboard-tab-trader",
3887
+ value: "trader" /* trader */,
3888
+ children: /* @__PURE__ */ jsxs(Flex, { direction: "row", gap: 1, mb: 2, children: [
3889
+ /* @__PURE__ */ jsx(
3890
+ TraderIcon,
3891
+ {
3892
+ fillOpacity: 1,
3893
+ fill: "currentColor",
3894
+ className: props.tab === "trader" /* trader */ ? "oui-fill-white/[.98]" : "oui-fill-white/[.36]"
3895
+ }
3896
+ ),
3897
+ /* @__PURE__ */ jsx(Text, { children: t("affiliate.trader") })
3898
+ ] })
3899
+ }
3900
+ ),
3901
+ extendNode()
3902
+ ]
3903
+ }
3904
+ ),
3905
+ props.isAffiliate && /* @__PURE__ */ jsx(TabsContent, { value: "affiliate" /* affiliate */, className: "oui-mt-4", children: /* @__PURE__ */ jsx(AffiliatePage, {}) }),
3906
+ props.isTrader && /* @__PURE__ */ jsx(TabsContent, { value: "trader" /* trader */, className: "oui-mt-4", children: /* @__PURE__ */ jsx(TraderPage, {}) })
3907
+ ]
3908
+ }
3909
+ );
3910
+ };
3911
+ var useTabScript = () => {
3912
+ const {
3913
+ isAffiliate,
3914
+ isTrader,
3915
+ isLoading,
3916
+ splashPage,
3917
+ showHome,
3918
+ setShowHome,
3919
+ tab,
3920
+ setTab
3921
+ } = useReferralContext();
3922
+ const tableValue = useMemo(() => {
3923
+ if (isAffiliate && isTrader) {
3924
+ return tab;
3925
+ } else if (isAffiliate && !isTrader) {
3926
+ return "affiliate" /* affiliate */;
3927
+ } else if (!isAffiliate && isTrader) {
3928
+ return "trader" /* trader */;
3929
+ } else {
3930
+ return "affiliate" /* affiliate */;
3931
+ }
3932
+ }, [tab, isAffiliate, isTrader]);
3933
+ useEffect(() => {
3934
+ const searchParams = new URLSearchParams(window.location.search);
3935
+ const tab2 = searchParams.get("tab");
3936
+ if (tab2) {
3937
+ setTab(tab2);
3938
+ }
3939
+ }, [window.location.search]);
3940
+ const anAnAffiliate = () => {
3941
+ setShowHome(true);
3942
+ };
3943
+ const anATrader = () => {
3944
+ setShowHome(true);
3945
+ };
3946
+ return {
3947
+ setTab,
3948
+ tab: tableValue,
3949
+ isAffiliate,
3950
+ isTrader,
3951
+ isLoading,
3952
+ anAnAffiliate,
3953
+ anATrader,
3954
+ splashPage,
3955
+ showHome,
3956
+ setShowHome
3957
+ // tab: TabTypes.affiliate,
3958
+ // isAffiliate: false,
3959
+ // isTrader: false,
3960
+ // isLoading: false,
3961
+ };
3962
+ };
3963
+ var TabWidget = (props) => {
3964
+ const state = useTabScript();
3965
+ return /* @__PURE__ */ jsx(Tab, { classNames: props.classNames, ...state });
3966
+ };
3967
+ var DashboardPage = (props) => {
3968
+ const { classNames = {} } = props;
3969
+ const { root, ...rest } = classNames;
3970
+ return /* @__PURE__ */ jsx("div", { id: "oui-affiliate-dashboard-page", className: cn("oui-w-full oui-tracking-tight", root), children: /* @__PURE__ */ jsx(TabWidget, { classNames: rest }) });
3971
+ };
3972
+ var AffiliateLayout = (props) => {
3973
+ const { ...rest } = props;
3974
+ return /* @__PURE__ */ jsx(Scaffold, { leftSidebar: /* @__PURE__ */ jsx(LeftSidebar, { ...rest }), children: /* @__PURE__ */ jsx(Box, { mx: 3, my: 6, children: props.children }) });
3975
+ };
3976
+ var LeftSidebar = (props) => {
3977
+ return /* @__PURE__ */ jsx(Box, { p: 4, m: 3, border: true, borderColor: 8, r: "xl", children: /* @__PURE__ */ jsx(SideBar, { ...props }) });
3978
+ };
3979
+ var useLayoutBuilder = () => {
3980
+ const [current, setCurrent] = useState("/");
3981
+ const { t } = useTranslation();
3982
+ const items = useMemo(() => {
3983
+ return [
3984
+ {
3985
+ name: t("common.trading"),
3986
+ href: "/",
3987
+ icon: /* @__PURE__ */ jsxs(
3988
+ "svg",
3989
+ {
3990
+ width: "18",
3991
+ height: "18",
3992
+ viewBox: "0 0 18 18",
3993
+ fill: "none",
3994
+ xmlns: "http://www.w3.org/2000/svg",
3995
+ children: [
3996
+ /* @__PURE__ */ jsx(
3997
+ "path",
3998
+ {
3999
+ d: "M4.883 1.5c-.166.01-.393.076-.515.173a2 2 0 0 0-.18.173L.918 6.553a.86.86 0 0 0-.168.475c0 .339.232.543.232.543l7.374 8.633c.005.006.269.301.644.296s.64-.29.644-.296l7.402-8.663s.204-.269.204-.513-.196-.517-.196-.517L13.82 1.848c-.023-.032-.076-.021-.103-.049-.033-.038-.037-.091-.077-.124-.123-.097-.267-.106-.413-.123-.04-.005-.063-.049-.103-.049h-.078zm1.745 1.582h4.744L9 5.795zm-1.675.542 2.294 2.615H3.122zm8.094 0 1.831 2.615h-4.125zM3.328 7.818h4.847v5.672zm6.497 0h4.847c-1.151 1.345-3.422 4.007-4.847 5.672z",
4000
+ fill: "url(#a)"
4001
+ }
4002
+ ),
4003
+ /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
4004
+ "linearGradient",
4005
+ {
4006
+ id: "a",
4007
+ x1: "17.25",
4008
+ y1: "9",
4009
+ x2: ".75",
4010
+ y2: "9",
4011
+ gradientUnits: "userSpaceOnUse",
4012
+ children: [
4013
+ /* @__PURE__ */ jsx("stop", { stopColor: "rgb(var(--oui-gradient-brand-end))" }),
4014
+ /* @__PURE__ */ jsx(
4015
+ "stop",
4016
+ {
4017
+ offset: "1",
4018
+ stopColor: "rgb(var(--oui-gradient-brand-start))"
4019
+ }
4020
+ )
4021
+ ]
4022
+ }
4023
+ ) })
4024
+ ]
4025
+ }
4026
+ )
4027
+ },
4028
+ {
4029
+ name: t("common.affiliate"),
4030
+ href: "/affiliate",
4031
+ icon: /* @__PURE__ */ jsx(
4032
+ "svg",
4033
+ {
4034
+ width: "18",
4035
+ height: "18",
4036
+ viewBox: "0 0 18 18",
4037
+ fill: "none",
4038
+ xmlns: "http://www.w3.org/2000/svg",
4039
+ children: /* @__PURE__ */ jsx(
4040
+ "path",
4041
+ {
4042
+ fillRule: "evenodd",
4043
+ clipRule: "evenodd",
4044
+ d: "M5.625 4.95c0-.746.604-1.35 1.35-1.35h4.05c.746 0 1.35.604 1.35 1.35v4.62L9 12.195 5.625 9.57zm8.624 3.163-.524.407v-.96l.074.05c.193.128.346.302.45.502m-4.42 5.148L14.4 9.705v3.345a1.35 1.35 0 0 1-1.35 1.35h-8.1a1.35 1.35 0 0 1-1.35-1.35V9.705l4.571 3.556c.488.379 1.17.379 1.658 0M4.275 8.52l-.524-.407c.104-.2.257-.374.45-.503l.074-.049zm0-2.581V4.95a2.7 2.7 0 0 1 2.7-2.7h4.05a2.7 2.7 0 0 1 2.7 2.7v.989l.823.548a2.7 2.7 0 0 1 1.202 2.247v4.316a2.7 2.7 0 0 1-2.7 2.7h-8.1a2.7 2.7 0 0 1-2.7-2.7V8.734a2.7 2.7 0 0 1 1.202-2.247zM9 6.089l.111-.118.005-.005a1.08 1.08 0 0 1 1.58.004 1.223 1.223 0 0 1 0 1.668l-1.515 1.62-.004.004c-.1.102-.26.1-.358-.004l-1.516-1.62a1.223 1.223 0 0 1 0-1.668l.004-.004a1.08 1.08 0 0 1 1.58.004z",
4045
+ fill: "#fff",
4046
+ fillOpacity: ".54"
4047
+ }
4048
+ )
4049
+ }
4050
+ )
4051
+ }
4052
+ ];
4053
+ }, [t]);
4054
+ return {
4055
+ items,
4056
+ current,
4057
+ // open: sideOpen,
4058
+ // onOpenChange(open) {
4059
+ // setSideOpen(open);
4060
+ // },
4061
+ onItemSelect: (item) => {
4062
+ setCurrent(item.href);
4063
+ }
4064
+ };
4065
+ };
4066
+ var AffiliateLayoutWidget = (props) => {
4067
+ const state = useLayoutBuilder();
4068
+ return /* @__PURE__ */ jsx(AffiliateLayout, { ...state, children: props.children });
4069
+ };
15
4070
 
16
- export { ts as AffiliateLayoutWidget, si as Dashboard, Vr as ReferralContext, Ss as ReferralProvider, Ne as TabTypes, y as useReferralContext };
4071
+ export { AffiliateLayoutWidget, dashboard_exports as Dashboard, ReferralContext, ReferralProvider, TabTypes, useReferralContext };
17
4072
  //# sourceMappingURL=out.js.map
18
4073
  //# sourceMappingURL=index.mjs.map