@kodiak-finance/orderly-ui-connector 2.8.18-rc.1 → 2.8.19-rc.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,915 @@ import { jsx, jsxs } from 'react/jsx-runtime';
7
7
  import { useAppContext, useDataTap } from '@kodiak-finance/orderly-react-app';
8
8
  import { ChainSelectorSheetId, ChainSelectorDialogId } from '@kodiak-finance/orderly-ui-chain-selector';
9
9
 
10
- var te=e=>{let{title:t,description:n,showDivider:o}=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(Ie,{...e})}),o&&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"})})]})},Ie=e=>{let{active:t,isLoading:n,isCompleted:o}=e;return n?jsx(Spinner,{size:"sm",className:"oui-ml-1"}):o?jsx(CheckedCircleFillIcon,{opacity:1,className:"oui-text-primary"}):jsx(ve,{active:!!t})},ve=({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,o]=useState(true),r=useEventEmitter(),{t:i}=useTranslation(),{disconnect:g,namespace:d}=useWalletConnector(),{state:m,account:s}=useAccount(),[a,p]=useState(t),[l,A]=useState(0),[x,b]=useState(false),[B,T]=useState(false),{ledgerWallet:N,setLedgerAddress:ye}=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 u=[];return t<AccountStatusEnum.SignedIn&&u.push({key:"signIn",title:i("connector.createAccount"),description:i("connector.createAccount.description")}),t<AccountStatusEnum.EnableTrading&&u.push({key:"enableTrading",title:i("connector.enableTrading"),description:i("connector.enableTrading.description")}),u},[t,i]);useEffect(()=>{if(d!=ChainNamespace.solana){T(false);return}if(!N){T(true);return}if(N&&s.address&&!N.includes(s.address)){T(true);return}T(false);},[d,s.address,N]);let Y=()=>(b(true),e.enableTrading(n).then(async u=>{C.current++,b(false),A(y=>y+1);try{await e.enableTradingComplted?.();}catch{}typeof e.onCompleted=="function"?e.onCompleted():typeof e.close=="function"&&e.close();},u=>{if(b(false),u!==-1){if(u.message.indexOf("Signing off chain messages with Ledger is not yet supported")!==-1){r.emit("wallet:sign-message-with-ledger-error",{message:u.message,userAddress:s.address});return}toast.error(ae(u));}}).catch(u=>{b(false);})),Te=async()=>{localStorage.removeItem("orderly_link_device"),g({label:a.connectWallet?.name}).then(()=>{s.disconnect(),typeof e.close=="function"&&e.close();});},xe=()=>(b(true),e.signIn().then(u=>{A(y=>y+1),Y();},u=>{if(b(false),u!==-1){if(u.message.indexOf("Signing off chain messages with Ledger is not yet supported")!==-1){r.emit("wallet:sign-message-with-ledger-error",{message:u.message,userAddress:s.address});return}toast.error(ae(u));}}).catch(u=>{b(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((u,y)=>{let Se=y===O.length-1;return jsx(te,{title:u.title,description:u.description,isCompleted:l>y,active:l===y,isLoading:x&&l===y,showDivider:!Se},u.key)})}),e.showRefCodeInput&&O.length==2&&jsx(Ve,{...e}),M&&jsxs(Flex,{justify:"between",itemAlign:"center",children:[jsx(Ue,{}),jsx(Switch,{color:"primary",checked:n,onCheckedChange:o,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(He,{state:a,signIn:xe,enableTrading:Y,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:Te,children:[jsx(_e,{}),jsx(Text,{className:"oui-text-base-contrast-80 oui-text-sm",children:i("connector.disconnectWallet")})]})]})},_e=()=>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"})}),He=({state:e,signIn:t,enableTrading:n,loading:o,disabled:r,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:o,disabled:r,children:g("connector.createAccount")}),i&&jsx(se,{onClick:()=>t(),content:g("connector.createAccountWithLedger")})]}):jsxs(Flex,{direction:"column",gap:3,className:"oui-w-full",children:[jsx(Button,{fullWidth:true,onClick:()=>n(),loading:o,disabled:r,children:g("connector.enableTrading")}),i&&jsx(se,{onClick:()=>n(),disabled:r,content:g("connector.enableTradingWithLedger")})]})},se=({onClick:e,disabled:t,content:n})=>{let{t:o}=useTranslation(),{state:r}=useAccount(),i=r.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},Ve=e=>{let{t}=useTranslation();return jsx(TextField,{placeholder:t("connector.referralCode.placeholder"),fullWidth:true,label:"",value:e.refCode,onChange:n=>{let o=n.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"");e.setRefCode(o);},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,o=>o.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})},Ue=()=>{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 ae(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:o}=useAccount(),[r,i]=useState(""),[g,d]=useState(""),{t:m}=useTranslation(),{trigger:s}=useLazyQuery(`/v1/public/referral/verify_ref_code?referral_code=${r}`);useEffect(()=>{let C=localStorage.getItem("referral_code");C!=null&&i(C);},[]);let{referral_code:a,isLoading:p}=useGetReferralCode(e.accountId),[l,{error:A,isMutating:x}]=useMutation("/v1/referral/bind","POST");useEffect(()=>{r.length===0&&d("");},[r]);let b=()=>{toast.success(m("connector.walletConnected")),r.length>=4&&r.length<=10&&l({referral_code:r}).finally(()=>{localStorage.removeItem("referral_code");});},B=async()=>{if(r.length===0)return Promise.resolve(void 0);if(r.length>0&&(r.length<4||r.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 d(C),Promise.reject(-1)}return d(""),o()};return {enableTrading:async C=>{if(T){let M=await B();if(typeof M<"u")return d(M),Promise.reject(-1)}return d(""),n(C)},initAccountState:t.status,signIn:N,enableTradingComplted:b,refCode:r,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 k=e=>{let{status:t,buttonProps:n,fallback:o,descriptions:r,classNames:i,networkId:g,id:d,bridgeLessOnly:m}=e,{t:s}=useTranslation(),{state:a}=useAccount(),{wrongNetwork:p,disabledConnect:l}=useAppContext(),A=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},b=useMemo(()=>typeof o<"u"?o({validating:a.validating,status:a.status,wrongNetwork:p}):a.validating&&!l?jsx(R,{angle:45,disabled:true,loading:true,description:r?.connectWallet,id:d,type:"button",...n,children:x.connectWallet}):jsx(dt,{bridgeLessOnly:m,status:a.status,buttonProps:{...n,id:d,type:"button"},wrongNetwork:p,networkId:e.networkId,labels:x,descriptions:r,disabledConnect:l}),[a.status,a.validating,n,p]);return jsx(Either,{value:a.status>=A&&!p&&!l,left:b,children:e.children})},lt=()=>{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")})},dt=e=>{let{buttonProps:t,labels:n,descriptions:o}=e,{t:r}=useTranslation(),{connectWallet:i}=useAppContext(),{account:g}=useAccount(),{isMobile:d}=useScreen(),m=useMediaQuery(MEDIA_TABLET),s=()=>{modal.show(m?F:D,{title:jsx(lt,{})}).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(r("connector.walletConnected"));}),modal.show(d?ChainSelectorSheetId:ChainSelectorDialogId,{networkId:e.networkId,bridgeLessOnly:e.bridgeLessOnly}).then(l=>{l.wrongNetwork||e.status>=AccountStatusEnum.Connected&&(e.status<AccountStatusEnum.EnableTrading?s():toast.success(r("connector.walletConnected")));},l=>{});};return e.wrongNetwork&&!e.disabledConnect?jsx(R,{color:"warning",onClick:()=>{p();},description:o?.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:o?.connectWallet,disabled:e.disabledConnect,...t,children:n.connectWallet}):e.status<=AccountStatusEnum.NotSignedIn?jsx(R,{size:"lg",onClick:()=>{s();},angle:45,description:o?.signin,...t,children:n.signin}):jsx(R,{size:"lg",description:o?.enableTrading,...t,onClick:()=>s(),children:n.enableTrading})};k.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 Tt=e=>{let{status:t,labels:n,description:o,dataSource:r,children:i,...g}=e,{state:d}=useAccount(),{wrongNetwork:m,disabledConnect:s}=useAppContext(),a=useMemo(()=>t===void 0?d.status===AccountStatusEnum.EnableTradingWithoutConnected?AccountStatusEnum.EnableTradingWithoutConnected:AccountStatusEnum.EnableTrading:t,[t,d.status]),p=useDataTap(r,{accountStatus:a}),l=m||s||d.status<a||e.ignoreLoadingCheck;return jsx(DataTable,{dataSource:p,ignoreLoadingCheck:l,emptyView:jsx(xt,{status:a,description:o,labels:n,className:e.classNames?.authGuardDescription,visible:!d.validating}),manualPagination:true,...g,children:i})},xt=e=>{let{t}=useTranslation(),o={...{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(k,{status:e.status,labels:e.labels,descriptions:o,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:o}=e;return jsx(Box,{my:8,children:jsx(k,{status:o,descriptions:{...n,switchChain:n.wrongNetwork},children:e.children||jsx(EmptyDataState,{})})})};he.displayName="AuthGuardEmpty";var we=e=>{let{t}=useTranslation(),{opactiy:n=90,tooltip:o={connectWallet:t("connector.setUp.connectWallet.tooltip"),signIn:t("connector.setUp.createAccount.tooltip"),enableTrading:t("connector.setUp.enableTrading.tooltip"),wrongNetwork:t("connector.wrongNetwork.tooltip")}}=e,[r,i]=useState(false),{state:g}=useAccount(),d=true,{wrongNetwork:m}=useAppContext(),s=useMemo(()=>{if(m)return o?.wrongNetwork;switch(g.status){case AccountStatusEnum.NotConnected:return o?.connectWallet;case AccountStatusEnum.NotSignedIn:return o?.signIn;case AccountStatusEnum.DisabledTrading:return o?.enableTrading;case AccountStatusEnum.EnableTrading:return "";default:return e.content}},[e.content,g,d,o]),a=useMemo(()=>{switch(g.status){case AccountStatusEnum.NotConnected:case AccountStatusEnum.NotSignedIn:return n;case AccountStatusEnum.EnableTrading:return;default:return}},[e.opactiy,g,d]);return jsx(Tooltip,{open:s?r: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})})};we.displayName="AuthGuardTooltip";
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 useAuthGuard = (status) => {
520
+ const { state } = useAccount();
521
+ const { wrongNetwork, disabledConnect } = useAppContext();
522
+ const _status = useMemo(() => {
523
+ if (status === void 0) {
524
+ return state.status === AccountStatusEnum.EnableTradingWithoutConnected ? AccountStatusEnum.EnableTradingWithoutConnected : AccountStatusEnum.EnableTrading;
525
+ }
526
+ return status;
527
+ }, [status, state.status]);
528
+ return useMemo(() => {
529
+ return state.status >= _status && !wrongNetwork && !disabledConnect;
530
+ }, [state.status, _status, wrongNetwork, disabledConnect]);
531
+ };
532
+ var AuthGuard = (props) => {
533
+ const {
534
+ status,
535
+ buttonProps,
536
+ fallback,
537
+ descriptions,
538
+ classNames,
539
+ networkId,
540
+ id,
541
+ bridgeLessOnly
542
+ // ...rest
543
+ } = props;
544
+ const { t } = useTranslation();
545
+ const { state } = useAccount();
546
+ const { wrongNetwork, disabledConnect } = useAppContext();
547
+ const _status = useMemo(() => {
548
+ if (status === void 0) {
549
+ return state.status === AccountStatusEnum.EnableTradingWithoutConnected ? AccountStatusEnum.EnableTradingWithoutConnected : AccountStatusEnum.EnableTrading;
550
+ }
551
+ return status;
552
+ }, [status, state.status]);
553
+ const labels = {
554
+ connectWallet: t("connector.connectWallet"),
555
+ switchChain: t("connector.wrongNetwork"),
556
+ enableTrading: t("connector.enableTrading"),
557
+ signin: t("connector.createAccount"),
558
+ ...props.labels
559
+ };
560
+ const Left = useMemo(() => {
561
+ if (typeof fallback !== "undefined") {
562
+ return fallback({
563
+ validating: state.validating,
564
+ status: state.status,
565
+ wrongNetwork
566
+ });
567
+ }
568
+ if (state.validating && !disabledConnect) {
569
+ return /* @__PURE__ */ jsx(
570
+ StatusInfo,
571
+ {
572
+ angle: 45,
573
+ disabled: true,
574
+ loading: true,
575
+ description: descriptions?.connectWallet,
576
+ id,
577
+ type: "button",
578
+ ...buttonProps,
579
+ children: labels.connectWallet
580
+ }
581
+ );
582
+ }
583
+ return /* @__PURE__ */ jsx(
584
+ DefaultFallback,
585
+ {
586
+ bridgeLessOnly,
587
+ status: state.status,
588
+ buttonProps: { ...buttonProps, id, type: "button" },
589
+ wrongNetwork,
590
+ networkId: props.networkId,
591
+ labels,
592
+ descriptions,
593
+ disabledConnect
594
+ }
595
+ );
596
+ }, [state.status, state.validating, buttonProps, wrongNetwork]);
597
+ return /* @__PURE__ */ jsx(
598
+ Either,
599
+ {
600
+ value: state.status >= _status && !wrongNetwork && !disabledConnect,
601
+ left: Left,
602
+ children: props.children
603
+ }
604
+ );
605
+ };
606
+ var ModalTitle = () => {
607
+ const { t } = useTranslation();
608
+ const { state } = useAccount();
609
+ if (state.status < AccountStatusEnum.SignedIn) {
610
+ return /* @__PURE__ */ jsx(Text, { children: t("connector.createAccount") });
611
+ }
612
+ if (state.status < AccountStatusEnum.EnableTrading) {
613
+ return /* @__PURE__ */ jsx(Text, { children: t("connector.enableTrading") });
614
+ }
615
+ return /* @__PURE__ */ jsx(Text, { children: t("connector.connectWallet") });
616
+ };
617
+ var DefaultFallback = (props) => {
618
+ const { buttonProps, labels, descriptions } = props;
619
+ const { t } = useTranslation();
620
+ const { connectWallet } = useAppContext();
621
+ const { account } = useAccount();
622
+ const { isMobile } = useScreen();
623
+ const matches = useMediaQuery(MEDIA_TABLET);
624
+ const onConnectOrderly = () => {
625
+ modal.show(matches ? WalletConnectorSheetId : WalletConnectorModalId, {
626
+ title: /* @__PURE__ */ jsx(ModalTitle, {})
627
+ }).then(
628
+ (r) => void 0,
629
+ (error) => void 0
630
+ );
631
+ };
632
+ const onConnectWallet = async () => {
633
+ const res = await connectWallet();
634
+ if (!res) {
635
+ return;
636
+ }
637
+ if (res.wrongNetwork) {
638
+ switchChain();
639
+ } else {
640
+ if ((res?.status ?? AccountStatusEnum.NotConnected) < AccountStatusEnum.EnableTrading) {
641
+ onConnectOrderly();
642
+ }
643
+ }
644
+ };
645
+ const switchChain = () => {
646
+ account.once("validate:end", (status) => {
647
+ if (status < AccountStatusEnum.EnableTrading) {
648
+ onConnectOrderly();
649
+ } else {
650
+ toast.success(t("connector.walletConnected"));
651
+ }
652
+ });
653
+ modal.show(
654
+ isMobile ? ChainSelectorSheetId : ChainSelectorDialogId,
655
+ {
656
+ networkId: props.networkId,
657
+ bridgeLessOnly: props.bridgeLessOnly
658
+ }
659
+ ).then(
660
+ (r) => {
661
+ if (!r.wrongNetwork) {
662
+ if (props.status >= AccountStatusEnum.Connected) {
663
+ if (props.status < AccountStatusEnum.EnableTrading) {
664
+ onConnectOrderly();
665
+ } else {
666
+ toast.success(t("connector.walletConnected"));
667
+ }
668
+ }
669
+ }
670
+ },
671
+ (error) => void 0
672
+ );
673
+ };
674
+ if (props.wrongNetwork && !props.disabledConnect) {
675
+ return /* @__PURE__ */ jsx(
676
+ StatusInfo,
677
+ {
678
+ color: "warning",
679
+ onClick: () => {
680
+ switchChain();
681
+ },
682
+ description: descriptions?.switchChain,
683
+ ...buttonProps,
684
+ children: labels.switchChain
685
+ }
686
+ );
687
+ }
688
+ if (props.status <= AccountStatusEnum.NotConnected || props.disabledConnect) {
689
+ return /* @__PURE__ */ jsx(
690
+ StatusInfo,
691
+ {
692
+ size: "lg",
693
+ onClick: () => {
694
+ onConnectWallet();
695
+ },
696
+ variant: props.disabledConnect ? void 0 : "gradient",
697
+ angle: 45,
698
+ description: descriptions?.connectWallet,
699
+ disabled: props.disabledConnect,
700
+ ...buttonProps,
701
+ children: labels.connectWallet
702
+ }
703
+ );
704
+ }
705
+ if (props.status <= AccountStatusEnum.NotSignedIn) {
706
+ return /* @__PURE__ */ jsx(
707
+ StatusInfo,
708
+ {
709
+ size: "lg",
710
+ onClick: () => {
711
+ onConnectOrderly();
712
+ },
713
+ angle: 45,
714
+ description: descriptions?.signin,
715
+ ...buttonProps,
716
+ children: labels.signin
717
+ }
718
+ );
719
+ }
720
+ return /* @__PURE__ */ jsx(
721
+ StatusInfo,
722
+ {
723
+ size: "lg",
724
+ description: descriptions?.enableTrading,
725
+ ...buttonProps,
726
+ onClick: () => onConnectOrderly(),
727
+ children: labels.enableTrading
728
+ }
729
+ );
730
+ };
731
+ AuthGuard.displayName = "AuthGuard";
732
+ var StatusInfo = (props) => {
733
+ const { description, ...buttonProps } = props;
734
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", children: [
735
+ /* @__PURE__ */ jsx(Button, { ...buttonProps }),
736
+ !!description && /* @__PURE__ */ jsx(Box, { mt: 4, className: "oui-leading-none", style: { lineHeight: 0 }, children: /* @__PURE__ */ jsx(Text, { size: "2xs", intensity: 36, children: description }) })
737
+ ] });
738
+ };
739
+ var AuthGuardDataTable = (props) => {
740
+ const {
741
+ status,
742
+ // message,
743
+ labels,
744
+ description,
745
+ dataSource,
746
+ children,
747
+ ...rest
748
+ } = props;
749
+ const { state } = useAccount();
750
+ const { wrongNetwork, disabledConnect } = useAppContext();
751
+ const _status = useMemo(() => {
752
+ if (status === void 0) {
753
+ return state.status === AccountStatusEnum.EnableTradingWithoutConnected ? AccountStatusEnum.EnableTradingWithoutConnected : AccountStatusEnum.EnableTrading;
754
+ }
755
+ return status;
756
+ }, [status, state.status]);
757
+ const data = useDataTap(dataSource, {
758
+ accountStatus: _status
759
+ });
760
+ const ignoreLoadingCheck = wrongNetwork || disabledConnect || state.status < _status || props.ignoreLoadingCheck;
761
+ return /* @__PURE__ */ jsx(
762
+ DataTable,
763
+ {
764
+ dataSource: data,
765
+ ignoreLoadingCheck,
766
+ emptyView: /* @__PURE__ */ jsx(
767
+ GuardView,
768
+ {
769
+ status: _status,
770
+ description,
771
+ labels,
772
+ className: props.classNames?.authGuardDescription,
773
+ visible: !state.validating
774
+ }
775
+ ),
776
+ manualPagination: true,
777
+ ...rest,
778
+ children
779
+ }
780
+ );
781
+ };
782
+ var GuardView = (props) => {
783
+ const { t } = useTranslation();
784
+ const DESCRIPTIONS = {
785
+ connectWallet: t("connector.trade.connectWallet.tooltip"),
786
+ switchChain: t("connector.wrongNetwork.tooltip"),
787
+ enableTrading: t("connector.trade.enableTrading.tooltip"),
788
+ signin: t("connector.trade.createAccount.tooltip")
789
+ };
790
+ const descriptions = { ...DESCRIPTIONS, ...props.description };
791
+ if (!props.visible) {
792
+ return null;
793
+ }
794
+ return /* @__PURE__ */ jsx(Flex, { py: 8, children: /* @__PURE__ */ jsx(
795
+ AuthGuard,
796
+ {
797
+ status: props.status,
798
+ labels: props.labels,
799
+ descriptions,
800
+ buttonProps: {
801
+ size: "md"
802
+ },
803
+ children: /* @__PURE__ */ jsx(ExtensionSlot, { position: ExtensionPositionEnum.EmptyDataIdentifier })
804
+ }
805
+ ) });
806
+ };
807
+ var AuthGuardEmpty = (props) => {
808
+ const { t } = useTranslation();
809
+ const {
810
+ hint = {
811
+ connectWallet: t("connector.trade.connectWallet.tooltip"),
812
+ signIn: t("connector.trade.createAccount.tooltip"),
813
+ enableTrading: t("connector.trade.enableTrading.tooltip"),
814
+ wrongNetwork: t("connector.wrongNetwork.tooltip")
815
+ },
816
+ status
817
+ } = props;
818
+ return /* @__PURE__ */ jsx(Box, { my: 8, children: /* @__PURE__ */ jsx(
819
+ AuthGuard,
820
+ {
821
+ status,
822
+ descriptions: { ...hint, switchChain: hint.wrongNetwork },
823
+ buttonProps: {
824
+ size: "md"
825
+ },
826
+ children: props.children || /* @__PURE__ */ jsx(EmptyDataState, {})
827
+ }
828
+ ) });
829
+ };
830
+ AuthGuardEmpty.displayName = "AuthGuardEmpty";
831
+ var AuthGuardTooltip = (props) => {
832
+ const { t } = useTranslation();
833
+ const {
834
+ opactiy = 90,
835
+ tooltip = {
836
+ connectWallet: t("connector.setUp.connectWallet.tooltip"),
837
+ signIn: t("connector.setUp.createAccount.tooltip"),
838
+ enableTrading: t("connector.setUp.enableTrading.tooltip"),
839
+ wrongNetwork: t("connector.wrongNetwork.tooltip")
840
+ }
841
+ } = props;
842
+ const [open, setOpen] = useState(false);
843
+ const { state } = useAccount();
844
+ const isSupport = true;
845
+ const { wrongNetwork } = useAppContext();
846
+ const hint = useMemo(() => {
847
+ if (wrongNetwork) {
848
+ return tooltip?.wrongNetwork;
849
+ }
850
+ switch (state.status) {
851
+ case AccountStatusEnum.NotConnected:
852
+ return tooltip?.connectWallet;
853
+ case AccountStatusEnum.NotSignedIn:
854
+ return tooltip?.signIn;
855
+ case AccountStatusEnum.DisabledTrading:
856
+ return tooltip?.enableTrading;
857
+ case AccountStatusEnum.EnableTrading: {
858
+ return "";
859
+ }
860
+ default:
861
+ return props.content;
862
+ }
863
+ }, [props.content, state, isSupport, tooltip]);
864
+ const newOpacity = useMemo(() => {
865
+ switch (state.status) {
866
+ case AccountStatusEnum.NotConnected:
867
+ case AccountStatusEnum.NotSignedIn:
868
+ return opactiy;
869
+ case AccountStatusEnum.EnableTrading: {
870
+ return void 0;
871
+ }
872
+ default:
873
+ return void 0;
874
+ }
875
+ }, [props.opactiy, state, isSupport]);
876
+ return /* @__PURE__ */ jsx(
877
+ Tooltip,
878
+ {
879
+ open: hint ? open : false,
880
+ onOpenChange: setOpen,
881
+ content: hint,
882
+ className: "oui-text-2xs",
883
+ align: props.align,
884
+ alignOffset: props.alignOffset,
885
+ side: props.side,
886
+ sideOffset: props.sideOffset,
887
+ children: /* @__PURE__ */ jsx("div", { style: { opacity: newOpacity }, children: props.children })
888
+ }
889
+ );
890
+ };
891
+ AuthGuardTooltip.displayName = "AuthGuardTooltip";
892
+ var AuthStatusEnum = /* @__PURE__ */ ((AuthStatusEnum2) => {
893
+ AuthStatusEnum2[AuthStatusEnum2["WrongNetwork"] = 0] = "WrongNetwork";
894
+ AuthStatusEnum2[AuthStatusEnum2["ConnectWallet"] = 1] = "ConnectWallet";
895
+ AuthStatusEnum2[AuthStatusEnum2["CreateAccount"] = 2] = "CreateAccount";
896
+ AuthStatusEnum2[AuthStatusEnum2["EnableTrading"] = 3] = "EnableTrading";
897
+ return AuthStatusEnum2;
898
+ })(AuthStatusEnum || {});
899
+ var useAuthStatus = () => {
900
+ const { state } = useAccount();
901
+ const { wrongNetwork, disabledConnect } = useAppContext();
902
+ return useMemo(() => {
903
+ if (wrongNetwork && !disabledConnect) {
904
+ return 0 /* WrongNetwork */;
905
+ }
906
+ if (state.status === AccountStatusEnum.EnableTradingWithoutConnected) {
907
+ return 3 /* EnableTrading */;
908
+ }
909
+ if (state.status <= AccountStatusEnum.NotConnected || disabledConnect) {
910
+ return 1 /* ConnectWallet */;
911
+ }
912
+ if (state.status <= AccountStatusEnum.NotSignedIn) {
913
+ return 2 /* CreateAccount */;
914
+ }
915
+ return 3 /* EnableTrading */;
916
+ }, [state.status, wrongNetwork, disabledConnect]);
917
+ };
11
918
 
12
- export { k as AuthGuard, Tt as AuthGuardDataTable, he as AuthGuardEmpty, we as AuthGuardTooltip, Z as WalletConnectContent, D as WalletConnectorModalId, F as WalletConnectorSheetId, Q as WalletConnectorWidget, K as useWalletConnectorBuilder };
919
+ export { AuthGuard, AuthGuardDataTable, AuthGuardEmpty, AuthGuardTooltip, AuthStatusEnum, WalletConnectContent, WalletConnectorModalId, WalletConnectorSheetId, WalletConnectorWidget, useAuthGuard, useAuthStatus, useWalletConnectorBuilder };
13
920
  //# sourceMappingURL=out.js.map
14
921
  //# sourceMappingURL=index.mjs.map