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