@orderly.network/ui-connector 2.8.1-alpha.0 → 2.8.2-alpha.0

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
@@ -7,8 +7,902 @@ import { jsx, jsxs } from 'react/jsx-runtime';
7
7
  import { useAppContext, useDataTap } from '@orderly.network/react-app';
8
8
  import { ChainSelectorSheetId, ChainSelectorDialogId } from '@orderly.network/ui-chain-selector';
9
9
 
10
- var ne=e=>{let{title:t,description:n,showDivider:r}=e;return jsxs(Box,{position:"relative",className:"oui-pl-8",children:[jsxs(Box,{children:[jsx(Text,{as:"div",intensity:98,size:"sm",children:t}),jsx(Text,{as:"div",intensity:54,size:"2xs",children:n})]}),jsx("div",{className:"oui-absolute oui-left-0 oui-top-1 oui-z-10",children:jsx(Ee,{...e})}),r&&jsx(Box,{position:"absolute",left:12,top:23,bottom:-21,zIndex:0,children:jsx(Divider,{lineStyle:"dashed",direction:"vertical",intensity:16,className:"oui-h-full"})})]})},Ee=e=>{let{active:t,isLoading:n,isCompleted:r}=e;return n?jsx(Spinner,{size:"sm",className:"oui-ml-1"}):r?jsx(CheckedCircleFillIcon,{opacity:1,className:"oui-text-primary"}):jsx(Pe,{active:!!t})},Pe=({active:e,className:t})=>jsx("div",{className:cn("oui-w-[8.3px] oui-h-[8.3px] oui-rounded-full oui-ml-2 oui-mt-1",t,e?"oui-bg-primary-light":"oui-bg-base-2")});var Z=e=>{let{initAccountState:t=AccountStatusEnum.NotConnected}=e,[n,r]=useState(true),o=useEventEmitter(),{t:i}=useTranslation(),{disconnect:g,namespace:u}=useWalletConnector(),{state:m,account:s}=useAccount(),[a,p]=useState(t),[l,k]=useState(0),[x,h]=useState(false),[B,T]=useState(false),{ledgerWallet:N,setLedgerAddress:xe}=useStorageLedgerAddress(),C=useRef(0),[M]=useLocalStorage("orderly-first-show-wallet-connector-dialog",void 0);useEffect(()=>()=>{localStorage.setItem("orderly-first-show-wallet-connector-dialog","1");},[]),useEffect(()=>{p(m.status);},[m]);let O=useMemo(()=>{let d=[];return t<AccountStatusEnum.SignedIn&&d.push({key:"signIn",title:i("connector.createAccount"),description:i("connector.createAccount.description")}),t<AccountStatusEnum.EnableTrading&&d.push({key:"enableTrading",title:i("connector.enableTrading"),description:i("connector.enableTrading.description")}),d},[t,i]);useEffect(()=>{if(u!=ChainNamespace.solana){T(false);return}if(!N){T(true);return}if(N&&s.address&&!N.includes(s.address)){T(true);return}T(false);},[u,s.address,N]);let j=()=>(h(true),e.enableTrading(n).then(async d=>{C.current++,h(false),k(y=>y+1);try{await e.enableTradingComplted?.();}catch{}typeof e.onCompleted=="function"?e.onCompleted():typeof e.close=="function"&&e.close();},d=>{if(h(false),d!==-1){if(d.message.indexOf("Signing off chain messages with Ledger is not yet supported")!==-1){o.emit("wallet:sign-message-with-ledger-error",{message:d.message,userAddress:s.address});return}toast.error(ie(d));}}).catch(d=>{h(false);})),Se=async()=>{localStorage.removeItem("orderly_link_device"),g({label:a.connectWallet?.name}).then(()=>{s.disconnect(),typeof e.close=="function"&&e.close();});},Ne=()=>(h(true),e.signIn().then(d=>{k(y=>y+1),j();},d=>{if(h(false),d!==-1){if(d.message.indexOf("Signing off chain messages with Ledger is not yet supported")!==-1){o.emit("wallet:sign-message-with-ledger-error",{message:d.message,userAddress:s.address});return}toast.error(ie(d));}}).catch(d=>{h(false);}));return jsxs(Box,{id:"oui-wallet-connect-dialog-content",className:"oui-font-semibold",children:[jsx(Text,{intensity:54,size:"xs",children:i("connector.expired")}),jsx(Box,{p:4,my:6,intensity:600,r:"lg",className:"oui-space-y-5",position:"relative",children:O.map((d,y)=>{let We=y===O.length-1;return jsx(ne,{title:d.title,description:d.description,isCompleted:l>y,active:l===y,isLoading:x&&l===y,showDivider:!We},d.key)})}),e.showRefCodeInput&&O.length==2&&jsx(Ze,{...e}),M&&jsxs(Flex,{justify:"between",itemAlign:"center",children:[jsx(Ke,{}),jsx(Switch,{color:"primary",checked:n,onCheckedChange:r,disabled:x,className:"data-[state=checked]:oui-bg-primary-darken"})]}),jsx(Flex,{justify:"center",mt:8,className:"oui-w-full",children:jsx(Box,{className:"oui-w-full",children:jsx(Ue,{state:a,signIn:Ne,enableTrading:j,loading:x,disabled:a>=AccountStatusEnum.EnableTrading,showLedgerButton:B})})}),a>AccountStatusEnum.NotConnected&&jsxs(Flex,{justify:"center",mt:4,gap:1,className:"oui-w-full oui-cursor-pointer",onClick:Se,children:[jsx(Ve,{}),jsx(Text,{className:"oui-text-base-contrast-80 oui-text-sm",children:i("connector.disconnectWallet")})]})]})},Ve=()=>jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",children:jsx("path",{d:"M2.24219 5.24316C2.24219 3.58641 3.58536 2.24316 5.24219 2.24316H8.24219C9.89894 2.24316 11.2422 3.58641 11.2422 5.24316C11.2422 5.65716 10.9062 5.99316 10.4922 5.99316C10.0782 5.99316 9.74219 5.65716 9.74219 5.24316C9.74219 4.41441 9.07094 3.74316 8.24219 3.74316H5.24219C4.41374 3.74316 3.74219 4.41441 3.74219 5.24316V12.7432C3.74219 13.5719 4.41374 14.2432 5.24219 14.2432H8.24219C9.07094 14.2432 9.74219 13.5719 9.74219 12.7432C9.74219 12.3292 10.0782 11.9932 10.4922 11.9932C10.9062 11.9932 11.2422 12.3292 11.2422 12.7432C11.2422 14.3999 9.89894 15.7432 8.24219 15.7432H5.24219C3.58536 15.7432 2.24219 14.3999 2.24219 12.7432V5.24316ZM7.49219 8.99316C7.49219 8.57916 7.82819 8.24316 8.24219 8.24316H13.9144L12.4377 6.74316L13.4922 5.68866L16.2814 8.45391C16.5739 8.74716 16.5739 9.23915 16.2814 9.5324L13.4922 12.2977L12.4377 11.2432L13.9144 9.74316H8.24219C7.82819 9.74316 7.49219 9.40716 7.49219 8.99316Z",fill:"white",fillOpacity:"0.8"})}),Ue=({state:e,signIn:t,enableTrading:n,loading:r,disabled:o,showLedgerButton:i})=>{let{t:g}=useTranslation();return e<=AccountStatusEnum.NotSignedIn?jsxs(Flex,{direction:"column",gap:3,className:"oui-w-full",children:[jsx(Button,{fullWidth:true,onClick:()=>t(),loading:r,disabled:o,children:g("connector.createAccount")}),i&&jsx(ae,{onClick:()=>t(),content:g("connector.createAccountWithLedger")})]}):jsxs(Flex,{direction:"column",gap:3,className:"oui-w-full",children:[jsx(Button,{fullWidth:true,onClick:()=>n(),loading:r,disabled:o,children:g("connector.enableTrading")}),i&&jsx(ae,{onClick:()=>n(),disabled:o,content:g("connector.enableTradingWithLedger")})]})},ae=({onClick:e,disabled:t,content:n})=>{let{t:r}=useTranslation(),{state:o}=useAccount(),i=o.address,{setLedgerAddress:g}=useStorageLedgerAddress();return i?jsx(Button,{variant:"outlined",color:"primary",fullWidth:true,onClick:()=>{g(i),e();},disabled:t,className:"oui-w-full",children:n}):null},Ze=e=>{let{t}=useTranslation();return jsx(TextField,{placeholder:t("connector.referralCode.placeholder"),fullWidth:true,label:"",value:e.refCode,onChange:n=>{let r=n.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"");e.setRefCode(r);},classNames:{label:"oui-text-base-contrast-54 oui-text-xs",input:"placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm"},formatters:[inputFormatter.createRegexInputFormatter(n=>String(n).replace(/[a-z]/g,r=>r.toUpperCase())),inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)],onClear:()=>{e.setRefCode("");},autoComplete:"off",helpText:e.helpText,className:"oui-mb-4",color:e.helpText?"danger":void 0})},Ke=()=>{let{t:e}=useTranslation(),t=()=>{window.innerWidth>768||modal.alert({title:e("connector.rememberMe"),message:jsx("span",{className:"oui-text-2xs oui-text-base-contrast/60",children:e("connector.rememberMe.description")})});};return jsx(Tooltip,{content:e("connector.rememberMe.description"),className:"oui-max-w-[300px]",children:jsx("button",{onClick:t,children:jsx(Text,{intensity:54,size:"xs",className:"oui-underline oui-underline-offset-4 oui-decoration-dashed oui-decoration-base-contrast-36",children:e("connector.rememberMe")})})})};function ie(e){Object.keys(e).forEach(n=>{});let t=i18n.t("connector.somethingWentWrong");return e.toString().includes("rejected")&&(t=i18n.t("connector.userRejected")),capitalizeFirstLetter(t)??t}var K=()=>{let{account:e,state:t,createOrderlyKey:n,createAccount:r}=useAccount(),[o,i]=useState(""),[g,u]=useState(""),{t:m}=useTranslation(),{trigger:s}=useLazyQuery(`/v1/public/referral/verify_ref_code?referral_code=${o}`);useEffect(()=>{let C=localStorage.getItem("referral_code");C!=null&&i(C);},[]);let{referral_code:a,isLoading:p}=useGetReferralCode(e.accountId),[l,{error:k,isMutating:x}]=useMutation("/v1/referral/bind","POST");useEffect(()=>{o.length===0&&u("");},[o]);let h=()=>{toast.success(m("connector.walletConnected")),o.length>=4&&o.length<=10&&l({referral_code:o}).finally(()=>{localStorage.removeItem("referral_code");});},B=async()=>{if(o.length===0)return Promise.resolve(void 0);if(o.length>0&&(o.length<4||o.length>10))return Promise.resolve(m("connector.referralCode.invalid"));let{exist:C}=await s();return C===false?Promise.resolve(m("connector.referralCode.notExist")):Promise.resolve(void 0)},T=(a?.length||0)===0&&!p,N=async()=>{if(T){let C=await B();if(typeof C<"u")return u(C),Promise.reject(-1)}return u(""),r()};return {enableTrading:async C=>{if(T){let M=await B();if(typeof M<"u")return u(M),Promise.reject(-1)}return u(""),n(C)},initAccountState:t.status,signIn:N,enableTradingComplted:h,refCode:o,setRefCode:i,helpText:g,showRefCodeInput:T}};var D="walletConnector",F="walletConnectorSheet",Q=e=>{let t=K();return jsx(Z,{...t,...e})};registerSimpleDialog(D,Q,{size:"sm",title:()=>i18n.t("connector.connectWallet")});registerSimpleSheet(F,Q,{title:()=>i18n.t("connector.connectWallet")});var A=e=>{let{status:t,buttonProps:n,fallback:r,descriptions:o,classNames:i,networkId:g,id:u,bridgeLessOnly:m}=e,{t:s}=useTranslation(),{state:a}=useAccount(),{wrongNetwork:p,disabledConnect:l}=useAppContext(),k=useMemo(()=>t===void 0?a.status===AccountStatusEnum.EnableTradingWithoutConnected?AccountStatusEnum.EnableTradingWithoutConnected:AccountStatusEnum.EnableTrading:t,[t,a.status]),x={connectWallet:s("connector.connectWallet"),switchChain:s("connector.wrongNetwork"),enableTrading:s("connector.enableTrading"),signin:s("connector.createAccount"),...e.labels},h=useMemo(()=>typeof r<"u"?r({validating:a.validating,status:a.status,wrongNetwork:p}):a.validating&&!l?jsx(R,{angle:45,disabled:true,loading:true,description:o?.connectWallet,id:u,type:"button",...n,children:x.connectWallet}):jsx(gt,{bridgeLessOnly:m,status:a.status,buttonProps:{...n,id:u,type:"button"},wrongNetwork:p,networkId:e.networkId,labels:x,descriptions:o,disabledConnect:l}),[a.status,a.validating,n,p]);return jsx(Either,{value:a.status>=k&&!p&&!l,left:h,children:e.children})},dt=()=>{let{t:e}=useTranslation(),{state:t}=useAccount();return t.status<AccountStatusEnum.SignedIn?jsx(Text,{children:e("connector.createAccount")}):t.status<AccountStatusEnum.EnableTrading?jsx(Text,{children:e("connector.enableTrading")}):jsx(Text,{children:e("connector.connectWallet")})},gt=e=>{let{buttonProps:t,labels:n,descriptions:r}=e,{t:o}=useTranslation(),{connectWallet:i}=useAppContext(),{account:g}=useAccount(),{isMobile:u}=useScreen(),m=useMediaQuery(MEDIA_TABLET),s=()=>{modal.show(m?F:D,{title:jsx(dt,{})}).then(l=>{},l=>{});},a=async()=>{let l=await i();l&&(l.wrongNetwork?p():(l?.status??AccountStatusEnum.NotConnected)<AccountStatusEnum.EnableTrading&&s());},p=()=>{g.once("validate:end",l=>{l<AccountStatusEnum.EnableTrading?s():toast.success(o("connector.walletConnected"));}),modal.show(u?ChainSelectorSheetId:ChainSelectorDialogId,{networkId:e.networkId,bridgeLessOnly:e.bridgeLessOnly}).then(l=>{l.wrongNetwork||e.status>=AccountStatusEnum.Connected&&(e.status<AccountStatusEnum.EnableTrading?s():toast.success(o("connector.walletConnected")));},l=>{});};return e.wrongNetwork&&!e.disabledConnect?jsx(R,{color:"warning",onClick:()=>{p();},description:r?.switchChain,...t,children:n.switchChain}):e.status<=AccountStatusEnum.NotConnected||e.disabledConnect?jsx(R,{size:"lg",onClick:()=>{a();},variant:e.disabledConnect?void 0:"gradient",angle:45,description:r?.connectWallet,disabled:e.disabledConnect,...t,children:n.connectWallet}):e.status<=AccountStatusEnum.NotSignedIn?jsx(R,{size:"lg",onClick:()=>{s();},angle:45,description:r?.signin,...t,children:n.signin}):jsx(R,{size:"lg",description:r?.enableTrading,...t,onClick:()=>s(),children:n.enableTrading})};A.displayName="AuthGuard";var R=e=>{let{description:t,...n}=e;return jsxs(Flex,{direction:"column",children:[jsx(Button,{...n}),!!t&&jsx(Box,{mt:4,className:"oui-leading-none",style:{lineHeight:0},children:jsx(Text,{size:"2xs",intensity:36,children:t})})]})};var St=e=>{let{status:t,labels:n,description:r,dataSource:o,children:i,...g}=e,{state:u}=useAccount(),{wrongNetwork:m,disabledConnect:s}=useAppContext(),a=useMemo(()=>t===void 0?u.status===AccountStatusEnum.EnableTradingWithoutConnected?AccountStatusEnum.EnableTradingWithoutConnected:AccountStatusEnum.EnableTrading:t,[t,u.status]),p=useDataTap(o,{accountStatus:a}),l=m||s||u.status<a||e.ignoreLoadingCheck;return jsx(DataTable,{dataSource:p,ignoreLoadingCheck:l,emptyView:jsx(Nt,{status:a,description:r,labels:n,className:e.classNames?.authGuardDescription,visible:!u.validating}),manualPagination:true,...g,children:i})},Nt=e=>{let{t}=useTranslation(),r={...{connectWallet:t("connector.trade.connectWallet.tooltip"),switchChain:t("connector.wrongNetwork.tooltip"),enableTrading:t("connector.trade.enableTrading.tooltip"),signin:t("connector.trade.createAccount.tooltip")},...e.description};return e.visible?jsx(Flex,{py:8,children:jsx(A,{status:e.status,labels:e.labels,descriptions:r,buttonProps:{size:"md"},children:jsx(ExtensionSlot,{position:ExtensionPositionEnum.EmptyDataIdentifier})})}):null};var he=e=>{let{t}=useTranslation(),{hint:n={connectWallet:t("connector.trade.connectWallet.tooltip"),signIn:t("connector.trade.createAccount.tooltip"),enableTrading:t("connector.trade.enableTrading.tooltip"),wrongNetwork:t("connector.wrongNetwork.tooltip")},status:r}=e;return jsx(Box,{my:8,children:jsx(A,{status:r,descriptions:{...n,switchChain:n.wrongNetwork},buttonProps:{size:"md"},children:e.children||jsx(EmptyDataState,{})})})};he.displayName="AuthGuardEmpty";var ye=e=>{let{t}=useTranslation(),{opactiy:n=90,tooltip:r={connectWallet:t("connector.setUp.connectWallet.tooltip"),signIn:t("connector.setUp.createAccount.tooltip"),enableTrading:t("connector.setUp.enableTrading.tooltip"),wrongNetwork:t("connector.wrongNetwork.tooltip")}}=e,[o,i]=useState(false),{state:g}=useAccount(),u=true,{wrongNetwork:m}=useAppContext(),s=useMemo(()=>{if(m)return r?.wrongNetwork;switch(g.status){case AccountStatusEnum.NotConnected:return r?.connectWallet;case AccountStatusEnum.NotSignedIn:return r?.signIn;case AccountStatusEnum.DisabledTrading:return r?.enableTrading;case AccountStatusEnum.EnableTrading:return "";default:return e.content}},[e.content,g,u,r]),a=useMemo(()=>{switch(g.status){case AccountStatusEnum.NotConnected:case AccountStatusEnum.NotSignedIn:return n;case AccountStatusEnum.EnableTrading:return;default:return}},[e.opactiy,g,u]);return jsx(Tooltip,{open:s?o:false,onOpenChange:i,content:s,className:"oui-text-2xs",align:e.align,alignOffset:e.alignOffset,side:e.side,sideOffset:e.sideOffset,children:jsx("div",{style:{opacity:a},children:e.children})})};ye.displayName="AuthGuardTooltip";var Te=(o=>(o[o.WrongNetwork=0]="WrongNetwork",o[o.ConnectWallet=1]="ConnectWallet",o[o.CreateAccount=2]="CreateAccount",o[o.EnableTrading=3]="EnableTrading",o))(Te||{}),Dt=()=>{let{state:e}=useAccount(),{wrongNetwork:t,disabledConnect:n}=useAppContext();return useMemo(()=>t&&!n?0:e.status===AccountStatusEnum.EnableTradingWithoutConnected?3:e.status<=AccountStatusEnum.NotConnected||n?1:e.status<=AccountStatusEnum.NotSignedIn?2:3,[e.status,t,n])};
10
+ // src/component/walletConnectorContent.tsx
11
+ var StepItem = (props) => {
12
+ const { title, description, showDivider } = props;
13
+ return /* @__PURE__ */ jsxs(Box, { position: "relative", className: "oui-pl-8", children: [
14
+ /* @__PURE__ */ jsxs(Box, { children: [
15
+ /* @__PURE__ */ jsx(Text, { as: "div", intensity: 98, size: "sm", children: title }),
16
+ /* @__PURE__ */ jsx(Text, { as: "div", intensity: 54, size: "2xs", children: description })
17
+ ] }),
18
+ /* @__PURE__ */ jsx("div", { className: "oui-absolute oui-left-0 oui-top-1 oui-z-10", children: /* @__PURE__ */ jsx(Identifier, { ...props }) }),
19
+ showDivider && /* @__PURE__ */ jsx(Box, { position: "absolute", left: 12, top: 23, bottom: -21, zIndex: 0, children: /* @__PURE__ */ jsx(
20
+ Divider,
21
+ {
22
+ lineStyle: "dashed",
23
+ direction: "vertical",
24
+ intensity: 16,
25
+ className: "oui-h-full"
26
+ }
27
+ ) })
28
+ ] });
29
+ };
30
+ var Identifier = (props) => {
31
+ const { active, isLoading, isCompleted } = props;
32
+ if (isLoading) {
33
+ return /* @__PURE__ */ jsx(Spinner, { size: "sm", className: "oui-ml-1" });
34
+ }
35
+ if (isCompleted) {
36
+ return /* @__PURE__ */ jsx(CheckedCircleFillIcon, { opacity: 1, className: "oui-text-primary" });
37
+ }
38
+ return /* @__PURE__ */ jsx(Dot, { active: !!active });
39
+ };
40
+ var Dot = ({
41
+ active,
42
+ className
43
+ }) => {
44
+ return /* @__PURE__ */ jsx(
45
+ "div",
46
+ {
47
+ className: cn(
48
+ "oui-w-[8.3px] oui-h-[8.3px] oui-rounded-full oui-ml-2 oui-mt-1",
49
+ className,
50
+ active ? "oui-bg-primary-light" : "oui-bg-base-2"
51
+ )
52
+ }
53
+ );
54
+ };
55
+ var WalletConnectContent = (props) => {
56
+ const { initAccountState = AccountStatusEnum.NotConnected } = props;
57
+ const [remember, setRemember] = useState(true);
58
+ const ee = useEventEmitter();
59
+ const { t } = useTranslation();
60
+ const { disconnect, namespace } = useWalletConnector();
61
+ const { state: accountState, account } = useAccount();
62
+ const [state, setState] = useState(initAccountState);
63
+ const [activeStep, setActiveStep] = useState(0);
64
+ const [loading, setLoading] = useState(false);
65
+ const [showLedgerButton, setShowLedgerButton] = useState(false);
66
+ const { ledgerWallet, setLedgerAddress } = useStorageLedgerAddress();
67
+ const handleRef = useRef(0);
68
+ const [firstShowDialog] = useLocalStorage(
69
+ "orderly-first-show-wallet-connector-dialog",
70
+ void 0
71
+ );
72
+ useEffect(() => {
73
+ return () => {
74
+ localStorage.setItem("orderly-first-show-wallet-connector-dialog", "1");
75
+ };
76
+ }, []);
77
+ useEffect(() => {
78
+ setState(accountState.status);
79
+ }, [accountState]);
80
+ const steps = useMemo(() => {
81
+ const steps2 = [];
82
+ if (initAccountState < AccountStatusEnum.SignedIn) {
83
+ steps2.push({
84
+ key: "signIn",
85
+ title: t("connector.createAccount"),
86
+ description: t("connector.createAccount.description")
87
+ });
88
+ }
89
+ if (initAccountState < AccountStatusEnum.EnableTrading) {
90
+ steps2.push({
91
+ key: "enableTrading",
92
+ title: t("connector.enableTrading"),
93
+ description: t("connector.enableTrading.description")
94
+ });
95
+ }
96
+ return steps2;
97
+ }, [initAccountState, t]);
98
+ useEffect(() => {
99
+ if (namespace != ChainNamespace.solana) {
100
+ setShowLedgerButton(false);
101
+ return;
102
+ }
103
+ if (!ledgerWallet) {
104
+ setShowLedgerButton(true);
105
+ return;
106
+ }
107
+ if (ledgerWallet && account.address) {
108
+ if (!ledgerWallet.includes(account.address)) {
109
+ setShowLedgerButton(true);
110
+ return;
111
+ }
112
+ }
113
+ setShowLedgerButton(false);
114
+ }, [namespace, account.address, ledgerWallet]);
115
+ const onEnableTrading = () => {
116
+ setLoading(true);
117
+ return props.enableTrading(remember).then(
118
+ async (res) => {
119
+ handleRef.current++;
120
+ setLoading(false);
121
+ setActiveStep((step) => step + 1);
122
+ try {
123
+ await props.enableTradingComplted?.();
124
+ } catch (e) {
125
+ }
126
+ if (typeof props.onCompleted === "function") {
127
+ props.onCompleted();
128
+ } else if (typeof props.close === "function") {
129
+ props.close();
130
+ }
131
+ },
132
+ (reject) => {
133
+ setLoading(false);
134
+ if (reject === -1) {
135
+ return;
136
+ }
137
+ if (reject.message.indexOf(
138
+ "Signing off chain messages with Ledger is not yet supported"
139
+ ) !== -1) {
140
+ ee.emit("wallet:sign-message-with-ledger-error", {
141
+ message: reject.message,
142
+ userAddress: account.address
143
+ });
144
+ return;
145
+ }
146
+ toast.error(paseErrorMsg(reject));
147
+ }
148
+ ).catch((e) => {
149
+ setLoading(false);
150
+ });
151
+ };
152
+ const onDisconnect = async () => {
153
+ localStorage.removeItem("orderly_link_device");
154
+ disconnect({
155
+ label: state.connectWallet?.name
156
+ }).then(() => {
157
+ account.disconnect();
158
+ if (typeof props.close === "function") {
159
+ props.close();
160
+ }
161
+ });
162
+ };
163
+ const onSignIn = () => {
164
+ setLoading(true);
165
+ return props.signIn().then(
166
+ (res) => {
167
+ setActiveStep((step) => step + 1);
168
+ onEnableTrading();
169
+ },
170
+ (reject) => {
171
+ setLoading(false);
172
+ if (reject === -1) {
173
+ return;
174
+ }
175
+ if (reject.message.indexOf(
176
+ "Signing off chain messages with Ledger is not yet supported"
177
+ ) !== -1) {
178
+ ee.emit("wallet:sign-message-with-ledger-error", {
179
+ message: reject.message,
180
+ userAddress: account.address
181
+ });
182
+ return;
183
+ }
184
+ toast.error(paseErrorMsg(reject));
185
+ }
186
+ ).catch((e) => {
187
+ setLoading(false);
188
+ });
189
+ };
190
+ return /* @__PURE__ */ jsxs(Box, { id: "oui-wallet-connect-dialog-content", className: "oui-font-semibold", children: [
191
+ /* @__PURE__ */ jsx(Text, { intensity: 54, size: "xs", children: t("connector.expired") }),
192
+ /* @__PURE__ */ jsx(
193
+ Box,
194
+ {
195
+ p: 4,
196
+ my: 6,
197
+ intensity: 600,
198
+ r: "lg",
199
+ className: "oui-space-y-5",
200
+ position: "relative",
201
+ children: steps.map((step, index) => {
202
+ const isLast = index === steps.length - 1;
203
+ return /* @__PURE__ */ jsx(
204
+ StepItem,
205
+ {
206
+ title: step.title,
207
+ description: step.description,
208
+ isCompleted: activeStep > index,
209
+ active: activeStep === index,
210
+ isLoading: loading && activeStep === index,
211
+ showDivider: !isLast
212
+ },
213
+ step.key
214
+ );
215
+ })
216
+ }
217
+ ),
218
+ props.showRefCodeInput && steps.length == 2 && /* @__PURE__ */ jsx(ReferralCode, { ...props }),
219
+ firstShowDialog && /* @__PURE__ */ jsxs(Flex, { justify: "between", itemAlign: "center", children: [
220
+ /* @__PURE__ */ jsx(RememberMe, {}),
221
+ /* @__PURE__ */ jsx(
222
+ Switch,
223
+ {
224
+ color: "primary",
225
+ checked: remember,
226
+ onCheckedChange: setRemember,
227
+ disabled: loading,
228
+ className: "data-[state=checked]:oui-bg-primary-darken"
229
+ }
230
+ )
231
+ ] }),
232
+ /* @__PURE__ */ jsx(Flex, { justify: "center", mt: 8, className: "oui-w-full", children: /* @__PURE__ */ jsx(Box, { className: "oui-w-full", children: /* @__PURE__ */ jsx(
233
+ ActionButton,
234
+ {
235
+ state,
236
+ signIn: onSignIn,
237
+ enableTrading: onEnableTrading,
238
+ loading,
239
+ disabled: state >= AccountStatusEnum.EnableTrading,
240
+ showLedgerButton
241
+ }
242
+ ) }) }),
243
+ state > AccountStatusEnum.NotConnected && /* @__PURE__ */ jsxs(
244
+ Flex,
245
+ {
246
+ justify: "center",
247
+ mt: 4,
248
+ gap: 1,
249
+ className: "oui-w-full oui-cursor-pointer",
250
+ onClick: onDisconnect,
251
+ children: [
252
+ /* @__PURE__ */ jsx(DisconnectIcon, {}),
253
+ /* @__PURE__ */ jsx(Text, { className: "oui-text-base-contrast-80 oui-text-sm", children: t("connector.disconnectWallet") })
254
+ ]
255
+ }
256
+ )
257
+ ] });
258
+ };
259
+ var DisconnectIcon = () => {
260
+ return /* @__PURE__ */ jsx(
261
+ "svg",
262
+ {
263
+ xmlns: "http://www.w3.org/2000/svg",
264
+ width: "18",
265
+ height: "18",
266
+ viewBox: "0 0 18 18",
267
+ fill: "none",
268
+ children: /* @__PURE__ */ jsx(
269
+ "path",
270
+ {
271
+ d: "M2.24219 5.24316C2.24219 3.58641 3.58536 2.24316 5.24219 2.24316H8.24219C9.89894 2.24316 11.2422 3.58641 11.2422 5.24316C11.2422 5.65716 10.9062 5.99316 10.4922 5.99316C10.0782 5.99316 9.74219 5.65716 9.74219 5.24316C9.74219 4.41441 9.07094 3.74316 8.24219 3.74316H5.24219C4.41374 3.74316 3.74219 4.41441 3.74219 5.24316V12.7432C3.74219 13.5719 4.41374 14.2432 5.24219 14.2432H8.24219C9.07094 14.2432 9.74219 13.5719 9.74219 12.7432C9.74219 12.3292 10.0782 11.9932 10.4922 11.9932C10.9062 11.9932 11.2422 12.3292 11.2422 12.7432C11.2422 14.3999 9.89894 15.7432 8.24219 15.7432H5.24219C3.58536 15.7432 2.24219 14.3999 2.24219 12.7432V5.24316ZM7.49219 8.99316C7.49219 8.57916 7.82819 8.24316 8.24219 8.24316H13.9144L12.4377 6.74316L13.4922 5.68866L16.2814 8.45391C16.5739 8.74716 16.5739 9.23915 16.2814 9.5324L13.4922 12.2977L12.4377 11.2432L13.9144 9.74316H8.24219C7.82819 9.74316 7.49219 9.40716 7.49219 8.99316Z",
272
+ fill: "white",
273
+ fillOpacity: "0.8"
274
+ }
275
+ )
276
+ }
277
+ );
278
+ };
279
+ var ActionButton = ({
280
+ state,
281
+ signIn,
282
+ enableTrading,
283
+ loading,
284
+ disabled,
285
+ showLedgerButton
286
+ }) => {
287
+ const { t } = useTranslation();
288
+ if (state <= AccountStatusEnum.NotSignedIn) {
289
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 3, className: "oui-w-full", children: [
290
+ /* @__PURE__ */ jsx(
291
+ Button,
292
+ {
293
+ fullWidth: true,
294
+ onClick: () => signIn(),
295
+ loading,
296
+ disabled,
297
+ children: t("connector.createAccount")
298
+ }
299
+ ),
300
+ showLedgerButton && /* @__PURE__ */ jsx(
301
+ WithLedgerButton,
302
+ {
303
+ onClick: () => signIn(),
304
+ content: t("connector.createAccountWithLedger")
305
+ }
306
+ )
307
+ ] });
308
+ }
309
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 3, className: "oui-w-full", children: [
310
+ /* @__PURE__ */ jsx(
311
+ Button,
312
+ {
313
+ fullWidth: true,
314
+ onClick: () => enableTrading(),
315
+ loading,
316
+ disabled,
317
+ children: t("connector.enableTrading")
318
+ }
319
+ ),
320
+ showLedgerButton && /* @__PURE__ */ jsx(
321
+ WithLedgerButton,
322
+ {
323
+ onClick: () => enableTrading(),
324
+ disabled,
325
+ content: t("connector.enableTradingWithLedger")
326
+ }
327
+ )
328
+ ] });
329
+ };
330
+ var WithLedgerButton = ({
331
+ onClick,
332
+ disabled,
333
+ content
334
+ }) => {
335
+ const { t } = useTranslation();
336
+ const { state } = useAccount();
337
+ const address = state.address;
338
+ const { setLedgerAddress } = useStorageLedgerAddress();
339
+ if (!address) {
340
+ return null;
341
+ }
342
+ return /* @__PURE__ */ jsx(
343
+ Button,
344
+ {
345
+ variant: "outlined",
346
+ color: "primary",
347
+ fullWidth: true,
348
+ onClick: () => {
349
+ setLedgerAddress(address);
350
+ onClick();
351
+ },
352
+ disabled,
353
+ className: "oui-w-full",
354
+ children: content
355
+ }
356
+ );
357
+ };
358
+ var ReferralCode = (props) => {
359
+ const { t } = useTranslation();
360
+ return /* @__PURE__ */ jsx(
361
+ TextField,
362
+ {
363
+ placeholder: t("connector.referralCode.placeholder"),
364
+ fullWidth: true,
365
+ label: "",
366
+ value: props.refCode,
367
+ onChange: (e) => {
368
+ const _value = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, "");
369
+ props.setRefCode(_value);
370
+ },
371
+ classNames: {
372
+ label: "oui-text-base-contrast-54 oui-text-xs",
373
+ input: "placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm"
374
+ },
375
+ formatters: [
376
+ inputFormatter.createRegexInputFormatter((value) => {
377
+ return String(value).replace(
378
+ /[a-z]/g,
379
+ (char) => char.toUpperCase()
380
+ );
381
+ }),
382
+ inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)
383
+ ],
384
+ onClear: () => {
385
+ props.setRefCode("");
386
+ },
387
+ autoComplete: "off",
388
+ helpText: props.helpText,
389
+ className: "oui-mb-4",
390
+ color: props.helpText ? "danger" : void 0
391
+ }
392
+ );
393
+ };
394
+ var RememberMe = () => {
395
+ const { t } = useTranslation();
396
+ const showRememberHint = () => {
397
+ if (window.innerWidth > 768) {
398
+ return;
399
+ }
400
+ modal.alert({
401
+ title: t("connector.rememberMe"),
402
+ message: /* @__PURE__ */ jsx("span", { className: "oui-text-2xs oui-text-base-contrast/60", children: t("connector.rememberMe.description") })
403
+ });
404
+ };
405
+ return /* @__PURE__ */ jsx(
406
+ Tooltip,
407
+ {
408
+ content: t("connector.rememberMe.description"),
409
+ className: "oui-max-w-[300px]",
410
+ children: /* @__PURE__ */ jsx("button", { onClick: showRememberHint, children: /* @__PURE__ */ jsx(
411
+ Text,
412
+ {
413
+ intensity: 54,
414
+ size: "xs",
415
+ className: "oui-underline oui-underline-offset-4 oui-decoration-dashed oui-decoration-base-contrast-36",
416
+ children: t("connector.rememberMe")
417
+ }
418
+ ) })
419
+ }
420
+ );
421
+ };
422
+ function paseErrorMsg(reject) {
423
+ Object.keys(reject).forEach((key) => {
424
+ });
425
+ let msg = i18n.t("connector.somethingWentWrong");
426
+ if (reject.toString().includes("rejected")) {
427
+ msg = i18n.t("connector.userRejected");
428
+ }
429
+ return capitalizeFirstLetter(msg) ?? msg;
430
+ }
431
+ var useWalletConnectorBuilder = () => {
432
+ const { account, state, createOrderlyKey, createAccount } = useAccount();
433
+ const [refCode, setRefCode] = useState("");
434
+ const [helpText, setHelpText] = useState("");
435
+ const { t } = useTranslation();
436
+ const { trigger: verifyRefCode } = useLazyQuery(
437
+ `/v1/public/referral/verify_ref_code?referral_code=${refCode}`
438
+ );
439
+ useEffect(() => {
440
+ const refCode2 = localStorage.getItem("referral_code");
441
+ if (refCode2 != null) {
442
+ setRefCode(refCode2);
443
+ }
444
+ }, []);
445
+ const { referral_code, isLoading } = useGetReferralCode(account.accountId);
446
+ const [bindRefCode, { error: updateOrderError, isMutating: updateMutating }] = useMutation("/v1/referral/bind", "POST");
447
+ useEffect(() => {
448
+ if (refCode.length === 0) {
449
+ setHelpText("");
450
+ }
451
+ }, [refCode]);
452
+ const enableTradingComplted = () => {
453
+ toast.success(t("connector.walletConnected"));
454
+ if (refCode.length >= 4 && refCode.length <= 10)
455
+ bindRefCode({ referral_code: refCode }).finally(() => {
456
+ localStorage.removeItem("referral_code");
457
+ });
458
+ };
459
+ const checkRefCode = async () => {
460
+ if (refCode.length === 0) {
461
+ return Promise.resolve(void 0);
462
+ }
463
+ if (refCode.length > 0 && (refCode.length < 4 || refCode.length > 10)) {
464
+ return Promise.resolve(t("connector.referralCode.invalid"));
465
+ }
466
+ const { exist } = await verifyRefCode();
467
+ if (exist === false) {
468
+ return Promise.resolve(t("connector.referralCode.notExist"));
469
+ }
470
+ return Promise.resolve(void 0);
471
+ };
472
+ const showRefCodeInput = (referral_code?.length || 0) === 0 && !isLoading;
473
+ const signIn = async () => {
474
+ if (showRefCodeInput) {
475
+ const info = await checkRefCode();
476
+ if (typeof info !== "undefined") {
477
+ setHelpText(info);
478
+ return Promise.reject(-1);
479
+ }
480
+ }
481
+ setHelpText("");
482
+ return createAccount();
483
+ };
484
+ const enableTrading = async (remember) => {
485
+ if (showRefCodeInput) {
486
+ const info = await checkRefCode();
487
+ if (typeof info !== "undefined") {
488
+ setHelpText(info);
489
+ return Promise.reject(-1);
490
+ }
491
+ }
492
+ setHelpText("");
493
+ return createOrderlyKey(remember);
494
+ };
495
+ return {
496
+ enableTrading,
497
+ initAccountState: state.status,
498
+ signIn,
499
+ enableTradingComplted,
500
+ refCode,
501
+ setRefCode,
502
+ helpText,
503
+ showRefCodeInput
504
+ };
505
+ };
506
+ var WalletConnectorModalId = "walletConnector";
507
+ var WalletConnectorSheetId = "walletConnectorSheet";
508
+ var WalletConnectorWidget = (props) => {
509
+ const state = useWalletConnectorBuilder();
510
+ return /* @__PURE__ */ jsx(WalletConnectContent, { ...state, ...props });
511
+ };
512
+ registerSimpleDialog(WalletConnectorModalId, WalletConnectorWidget, {
513
+ size: "sm",
514
+ title: () => i18n.t("connector.connectWallet")
515
+ });
516
+ registerSimpleSheet(WalletConnectorSheetId, WalletConnectorWidget, {
517
+ title: () => i18n.t("connector.connectWallet")
518
+ });
519
+ var AuthGuard = (props) => {
520
+ const {
521
+ status,
522
+ buttonProps,
523
+ fallback,
524
+ descriptions,
525
+ classNames,
526
+ networkId,
527
+ id,
528
+ bridgeLessOnly
529
+ // ...rest
530
+ } = props;
531
+ const { t } = useTranslation();
532
+ const { state } = useAccount();
533
+ const { wrongNetwork, disabledConnect } = useAppContext();
534
+ const _status = useMemo(() => {
535
+ if (status === void 0) {
536
+ return state.status === AccountStatusEnum.EnableTradingWithoutConnected ? AccountStatusEnum.EnableTradingWithoutConnected : AccountStatusEnum.EnableTrading;
537
+ }
538
+ return status;
539
+ }, [status, state.status]);
540
+ const labels = {
541
+ connectWallet: t("connector.connectWallet"),
542
+ switchChain: t("connector.wrongNetwork"),
543
+ enableTrading: t("connector.enableTrading"),
544
+ signin: t("connector.createAccount"),
545
+ ...props.labels
546
+ };
547
+ const Left = useMemo(() => {
548
+ if (typeof fallback !== "undefined") {
549
+ return fallback({
550
+ validating: state.validating,
551
+ status: state.status,
552
+ wrongNetwork
553
+ });
554
+ }
555
+ if (state.validating && !disabledConnect) {
556
+ return /* @__PURE__ */ jsx(
557
+ StatusInfo,
558
+ {
559
+ angle: 45,
560
+ disabled: true,
561
+ loading: true,
562
+ description: descriptions?.connectWallet,
563
+ id,
564
+ type: "button",
565
+ ...buttonProps,
566
+ children: labels.connectWallet
567
+ }
568
+ );
569
+ }
570
+ return /* @__PURE__ */ jsx(
571
+ DefaultFallback,
572
+ {
573
+ bridgeLessOnly,
574
+ status: state.status,
575
+ buttonProps: { ...buttonProps, id, type: "button" },
576
+ wrongNetwork,
577
+ networkId: props.networkId,
578
+ labels,
579
+ descriptions,
580
+ disabledConnect
581
+ }
582
+ );
583
+ }, [state.status, state.validating, buttonProps, wrongNetwork]);
584
+ return /* @__PURE__ */ jsx(
585
+ Either,
586
+ {
587
+ value: state.status >= _status && !wrongNetwork && !disabledConnect,
588
+ left: Left,
589
+ children: props.children
590
+ }
591
+ );
592
+ };
593
+ var ModalTitle = () => {
594
+ const { t } = useTranslation();
595
+ const { state } = useAccount();
596
+ if (state.status < AccountStatusEnum.SignedIn) {
597
+ return /* @__PURE__ */ jsx(Text, { children: t("connector.createAccount") });
598
+ }
599
+ if (state.status < AccountStatusEnum.EnableTrading) {
600
+ return /* @__PURE__ */ jsx(Text, { children: t("connector.enableTrading") });
601
+ }
602
+ return /* @__PURE__ */ jsx(Text, { children: t("connector.connectWallet") });
603
+ };
604
+ var DefaultFallback = (props) => {
605
+ const { buttonProps, labels, descriptions } = props;
606
+ const { t } = useTranslation();
607
+ const { connectWallet } = useAppContext();
608
+ const { account } = useAccount();
609
+ const { isMobile } = useScreen();
610
+ const matches = useMediaQuery(MEDIA_TABLET);
611
+ const onConnectOrderly = () => {
612
+ modal.show(matches ? WalletConnectorSheetId : WalletConnectorModalId, {
613
+ title: /* @__PURE__ */ jsx(ModalTitle, {})
614
+ }).then(
615
+ (r) => void 0,
616
+ (error) => void 0
617
+ );
618
+ };
619
+ const onConnectWallet = async () => {
620
+ const res = await connectWallet();
621
+ if (!res) {
622
+ return;
623
+ }
624
+ if (res.wrongNetwork) {
625
+ switchChain();
626
+ } else {
627
+ if ((res?.status ?? AccountStatusEnum.NotConnected) < AccountStatusEnum.EnableTrading) {
628
+ onConnectOrderly();
629
+ }
630
+ }
631
+ };
632
+ const switchChain = () => {
633
+ account.once("validate:end", (status) => {
634
+ if (status < AccountStatusEnum.EnableTrading) {
635
+ onConnectOrderly();
636
+ } else {
637
+ toast.success(t("connector.walletConnected"));
638
+ }
639
+ });
640
+ modal.show(
641
+ isMobile ? ChainSelectorSheetId : ChainSelectorDialogId,
642
+ {
643
+ networkId: props.networkId,
644
+ bridgeLessOnly: props.bridgeLessOnly
645
+ }
646
+ ).then(
647
+ (r) => {
648
+ if (!r.wrongNetwork) {
649
+ if (props.status >= AccountStatusEnum.Connected) {
650
+ if (props.status < AccountStatusEnum.EnableTrading) {
651
+ onConnectOrderly();
652
+ } else {
653
+ toast.success(t("connector.walletConnected"));
654
+ }
655
+ }
656
+ }
657
+ },
658
+ (error) => void 0
659
+ );
660
+ };
661
+ if (props.wrongNetwork && !props.disabledConnect) {
662
+ return /* @__PURE__ */ jsx(
663
+ StatusInfo,
664
+ {
665
+ color: "warning",
666
+ onClick: () => {
667
+ switchChain();
668
+ },
669
+ description: descriptions?.switchChain,
670
+ ...buttonProps,
671
+ children: labels.switchChain
672
+ }
673
+ );
674
+ }
675
+ if (props.status <= AccountStatusEnum.NotConnected || props.disabledConnect) {
676
+ return /* @__PURE__ */ jsx(
677
+ StatusInfo,
678
+ {
679
+ size: "lg",
680
+ onClick: () => {
681
+ onConnectWallet();
682
+ },
683
+ variant: props.disabledConnect ? void 0 : "gradient",
684
+ angle: 45,
685
+ description: descriptions?.connectWallet,
686
+ disabled: props.disabledConnect,
687
+ ...buttonProps,
688
+ children: labels.connectWallet
689
+ }
690
+ );
691
+ }
692
+ if (props.status <= AccountStatusEnum.NotSignedIn) {
693
+ return /* @__PURE__ */ jsx(
694
+ StatusInfo,
695
+ {
696
+ size: "lg",
697
+ onClick: () => {
698
+ onConnectOrderly();
699
+ },
700
+ angle: 45,
701
+ description: descriptions?.signin,
702
+ ...buttonProps,
703
+ children: labels.signin
704
+ }
705
+ );
706
+ }
707
+ return /* @__PURE__ */ jsx(
708
+ StatusInfo,
709
+ {
710
+ size: "lg",
711
+ description: descriptions?.enableTrading,
712
+ ...buttonProps,
713
+ onClick: () => onConnectOrderly(),
714
+ children: labels.enableTrading
715
+ }
716
+ );
717
+ };
718
+ AuthGuard.displayName = "AuthGuard";
719
+ var StatusInfo = (props) => {
720
+ const { description, ...buttonProps } = props;
721
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", children: [
722
+ /* @__PURE__ */ jsx(Button, { ...buttonProps }),
723
+ !!description && /* @__PURE__ */ jsx(Box, { mt: 4, className: "oui-leading-none", style: { lineHeight: 0 }, children: /* @__PURE__ */ jsx(Text, { size: "2xs", intensity: 36, children: description }) })
724
+ ] });
725
+ };
726
+ var AuthGuardDataTable = (props) => {
727
+ const {
728
+ status,
729
+ // message,
730
+ labels,
731
+ description,
732
+ dataSource,
733
+ children,
734
+ ...rest
735
+ } = props;
736
+ const { state } = useAccount();
737
+ const { wrongNetwork, disabledConnect } = useAppContext();
738
+ const _status = useMemo(() => {
739
+ if (status === void 0) {
740
+ return state.status === AccountStatusEnum.EnableTradingWithoutConnected ? AccountStatusEnum.EnableTradingWithoutConnected : AccountStatusEnum.EnableTrading;
741
+ }
742
+ return status;
743
+ }, [status, state.status]);
744
+ const data = useDataTap(dataSource, {
745
+ accountStatus: _status
746
+ });
747
+ const ignoreLoadingCheck = wrongNetwork || disabledConnect || state.status < _status || props.ignoreLoadingCheck;
748
+ return /* @__PURE__ */ jsx(
749
+ DataTable,
750
+ {
751
+ dataSource: data,
752
+ ignoreLoadingCheck,
753
+ emptyView: /* @__PURE__ */ jsx(
754
+ GuardView,
755
+ {
756
+ status: _status,
757
+ description,
758
+ labels,
759
+ className: props.classNames?.authGuardDescription,
760
+ visible: !state.validating
761
+ }
762
+ ),
763
+ manualPagination: true,
764
+ ...rest,
765
+ children
766
+ }
767
+ );
768
+ };
769
+ var GuardView = (props) => {
770
+ const { t } = useTranslation();
771
+ const DESCRIPTIONS = {
772
+ connectWallet: t("connector.trade.connectWallet.tooltip"),
773
+ switchChain: t("connector.wrongNetwork.tooltip"),
774
+ enableTrading: t("connector.trade.enableTrading.tooltip"),
775
+ signin: t("connector.trade.createAccount.tooltip")
776
+ };
777
+ const descriptions = { ...DESCRIPTIONS, ...props.description };
778
+ if (!props.visible) {
779
+ return null;
780
+ }
781
+ return /* @__PURE__ */ jsx(Flex, { py: 8, children: /* @__PURE__ */ jsx(
782
+ AuthGuard,
783
+ {
784
+ status: props.status,
785
+ labels: props.labels,
786
+ descriptions,
787
+ buttonProps: {
788
+ size: "md"
789
+ },
790
+ children: /* @__PURE__ */ jsx(ExtensionSlot, { position: ExtensionPositionEnum.EmptyDataIdentifier })
791
+ }
792
+ ) });
793
+ };
794
+ var AuthGuardEmpty = (props) => {
795
+ const { t } = useTranslation();
796
+ const {
797
+ hint = {
798
+ connectWallet: t("connector.trade.connectWallet.tooltip"),
799
+ signIn: t("connector.trade.createAccount.tooltip"),
800
+ enableTrading: t("connector.trade.enableTrading.tooltip"),
801
+ wrongNetwork: t("connector.wrongNetwork.tooltip")
802
+ },
803
+ status
804
+ } = props;
805
+ return /* @__PURE__ */ jsx(Box, { my: 8, children: /* @__PURE__ */ jsx(
806
+ AuthGuard,
807
+ {
808
+ status,
809
+ descriptions: { ...hint, switchChain: hint.wrongNetwork },
810
+ buttonProps: {
811
+ size: "md"
812
+ },
813
+ children: props.children || /* @__PURE__ */ jsx(EmptyDataState, {})
814
+ }
815
+ ) });
816
+ };
817
+ AuthGuardEmpty.displayName = "AuthGuardEmpty";
818
+ var AuthGuardTooltip = (props) => {
819
+ const { t } = useTranslation();
820
+ const {
821
+ opactiy = 90,
822
+ tooltip = {
823
+ connectWallet: t("connector.setUp.connectWallet.tooltip"),
824
+ signIn: t("connector.setUp.createAccount.tooltip"),
825
+ enableTrading: t("connector.setUp.enableTrading.tooltip"),
826
+ wrongNetwork: t("connector.wrongNetwork.tooltip")
827
+ }
828
+ } = props;
829
+ const [open, setOpen] = useState(false);
830
+ const { state } = useAccount();
831
+ const isSupport = true;
832
+ const { wrongNetwork } = useAppContext();
833
+ const hint = useMemo(() => {
834
+ if (wrongNetwork) {
835
+ return tooltip?.wrongNetwork;
836
+ }
837
+ switch (state.status) {
838
+ case AccountStatusEnum.NotConnected:
839
+ return tooltip?.connectWallet;
840
+ case AccountStatusEnum.NotSignedIn:
841
+ return tooltip?.signIn;
842
+ case AccountStatusEnum.DisabledTrading:
843
+ return tooltip?.enableTrading;
844
+ case AccountStatusEnum.EnableTrading: {
845
+ return "";
846
+ }
847
+ default:
848
+ return props.content;
849
+ }
850
+ }, [props.content, state, isSupport, tooltip]);
851
+ const newOpacity = useMemo(() => {
852
+ switch (state.status) {
853
+ case AccountStatusEnum.NotConnected:
854
+ case AccountStatusEnum.NotSignedIn:
855
+ return opactiy;
856
+ case AccountStatusEnum.EnableTrading: {
857
+ return void 0;
858
+ }
859
+ default:
860
+ return void 0;
861
+ }
862
+ }, [props.opactiy, state, isSupport]);
863
+ return /* @__PURE__ */ jsx(
864
+ Tooltip,
865
+ {
866
+ open: hint ? open : false,
867
+ onOpenChange: setOpen,
868
+ content: hint,
869
+ className: "oui-text-2xs",
870
+ align: props.align,
871
+ alignOffset: props.alignOffset,
872
+ side: props.side,
873
+ sideOffset: props.sideOffset,
874
+ children: /* @__PURE__ */ jsx("div", { style: { opacity: newOpacity }, children: props.children })
875
+ }
876
+ );
877
+ };
878
+ AuthGuardTooltip.displayName = "AuthGuardTooltip";
879
+ var AuthStatusEnum = /* @__PURE__ */ ((AuthStatusEnum2) => {
880
+ AuthStatusEnum2[AuthStatusEnum2["WrongNetwork"] = 0] = "WrongNetwork";
881
+ AuthStatusEnum2[AuthStatusEnum2["ConnectWallet"] = 1] = "ConnectWallet";
882
+ AuthStatusEnum2[AuthStatusEnum2["CreateAccount"] = 2] = "CreateAccount";
883
+ AuthStatusEnum2[AuthStatusEnum2["EnableTrading"] = 3] = "EnableTrading";
884
+ return AuthStatusEnum2;
885
+ })(AuthStatusEnum || {});
886
+ var useAuthStatus = () => {
887
+ const { state } = useAccount();
888
+ const { wrongNetwork, disabledConnect } = useAppContext();
889
+ return useMemo(() => {
890
+ if (wrongNetwork && !disabledConnect) {
891
+ return 0 /* WrongNetwork */;
892
+ }
893
+ if (state.status === AccountStatusEnum.EnableTradingWithoutConnected) {
894
+ return 3 /* EnableTrading */;
895
+ }
896
+ if (state.status <= AccountStatusEnum.NotConnected || disabledConnect) {
897
+ return 1 /* ConnectWallet */;
898
+ }
899
+ if (state.status <= AccountStatusEnum.NotSignedIn) {
900
+ return 2 /* CreateAccount */;
901
+ }
902
+ return 3 /* EnableTrading */;
903
+ }, [state.status, wrongNetwork, disabledConnect]);
904
+ };
11
905
 
12
- export { A as AuthGuard, St as AuthGuardDataTable, he as AuthGuardEmpty, ye as AuthGuardTooltip, Te as AuthStatusEnum, Z as WalletConnectContent, D as WalletConnectorModalId, F as WalletConnectorSheetId, Q as WalletConnectorWidget, Dt as useAuthStatus, K as useWalletConnectorBuilder };
906
+ export { AuthGuard, AuthGuardDataTable, AuthGuardEmpty, AuthGuardTooltip, AuthStatusEnum, WalletConnectContent, WalletConnectorModalId, WalletConnectorSheetId, WalletConnectorWidget, useAuthStatus, useWalletConnectorBuilder };
13
907
  //# sourceMappingURL=out.js.map
14
908
  //# sourceMappingURL=index.mjs.map