@orderly.network/ui-connector 2.0.6 → 2.0.7
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.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -8,16 +8,16 @@ var hooks = require('@orderly.network/hooks');
|
|
|
8
8
|
var reactApp = require('@orderly.network/react-app');
|
|
9
9
|
var uiChainSelector = require('@orderly.network/ui-chain-selector');
|
|
10
10
|
|
|
11
|
-
var V=e=>{let{title:t,description:n}=e;return jsxRuntime.jsxs(ui.Box,{position:"relative",className:"oui-pl-8",children:[jsxRuntime.jsxs(ui.Box,{children:[jsxRuntime.jsx(ui.Text,{as:"div",intensity:98,size:"sm",children:t}),jsxRuntime.jsx(ui.Text,{as:"div",intensity:54,size:"2xs",children:n})]}),jsxRuntime.jsx(me,{...e})]})},me=e=>{let{active:t,isLoading:n,isCompleted:i}=e;return jsxRuntime.jsx(ui.Match,{className:"oui-absolute oui-left-0 oui-top-1 oui-z-10",value:()=>i?"completed":n?"loading":t?"active":"normal",case:{loading:jsxRuntime.jsx("div",{children:jsxRuntime.jsx(ui.Spinner,{size:"sm",className:"oui-ml-1"})}),completed:jsxRuntime.jsx("div",{children:jsxRuntime.jsx(ui.CheckedCircleFillIcon,{opacity:1,className:"oui-text-primary"})})},default:jsxRuntime.jsx(fe,{active:!!t})})},fe=({active:e,className:t})=>jsxRuntime.jsx("div",{className:ui.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 B=e=>{let{initAccountState:t=types.AccountStatusEnum.NotConnected}=e,[n,i]=react.useState(true),o=hooks.useEventEmitter(),{state:d,account:g}=hooks.useAccount(),[l,u]=react.useState(t),[s,m]=react.useState(0),[a,f]=react.useState(false),[A]=hooks.useLocalStorage("orderly-first-show-wallet-connector-dialog",void 0);react.useEffect(()=>()=>{localStorage.setItem("orderly-first-show-wallet-connector-dialog","1");},[]),react.useEffect(()=>{u(d.status);},[d]);let T=react.useMemo(()=>{let r=[];return t<types.AccountStatusEnum.SignedIn&&r.push({key:"signIn",title:"Sign In",description:"Confirm you are the owner of this wallet"}),t<types.AccountStatusEnum.EnableTrading&&r.push({key:"enableTrading",title:"Enable Trading",description:"Enable secure access to our API for lightning fast trading"}),r},[t]),x=()=>(f(true),e.enableTrading(n).then(async r=>{f(false),m(C=>C+1);try{await e.enableTradingComplted?.();}catch{}typeof e.onCompleted=="function"?e.onCompleted():typeof e.close=="function"&&e.close();},r=>{if(f(false),r!==-1){if(r.message.indexOf("Signing off chain messages with Ledger is not yet supported")!==-1){o.emit("wallet:sign-message-with-ledger-error",{message:r.message,userAddress:g.address});return}ui.toast.error(Y(r));}}).catch(r=>{f(false);})),I=()=>(f(true),e.signIn().then(r=>{m(C=>C+1),x();},r=>{if(f(false),r!==-1){if(r.message.indexOf("Signing off chain messages with Ledger is not yet supported")!==-1){o.emit("wallet:sign-message-with-ledger-error",{message:r.message,userAddress:g.address});return}ui.toast.error(Y(r));}}).catch(r=>{f(false);}));return jsxRuntime.jsxs(ui.Box,{id:"oui-wallet-connect-dialog-content",className:"oui-font-semibold",children:[jsxRuntime.jsx(ui.Text,{intensity:54,size:"xs",children:"Your previous access has expired, you will receive a signature request to enable trading. Signing is free and will not send a transaction."}),jsxRuntime.jsxs(ui.Box,{p:4,my:6,intensity:600,r:"lg",className:"oui-space-y-5",position:"relative",children:[T.map((r,C)=>jsxRuntime.jsx(V,{title:r.title,description:r.description,isCompleted:s>C,active:s===C,isLoading:a&&s===C},r.key)),T.length>1&&jsxRuntime.jsx(ui.Box,{position:"absolute",height:"38px",left:28,top:18,zIndex:0,children:jsxRuntime.jsx(ui.Divider,{lineStyle:"dashed",direction:"vertical",intensity:16,className:"oui-h-full"})})]}),e.showRefCodeInput&&T.length==2&&jsxRuntime.jsx(Ae,{...e}),A&&jsxRuntime.jsxs(ui.Flex,{justify:"between",itemAlign:"center",children:[jsxRuntime.jsx(Ne,{}),jsxRuntime.jsx(ui.Switch,{color:"primary",checked:n,onCheckedChange:i,disabled:a,className:"data-[state=checked]:oui-bg-primary-darken"})]}),jsxRuntime.jsx(ui.Flex,{justify:"center",mt:8,children:jsxRuntime.jsx(ui.Box,{width:"45%",children:jsxRuntime.jsx(Ee,{state:l,signIn:I,enableTrading:x,loading:a,disabled:l>=types.AccountStatusEnum.EnableTrading})})})]})},Ee=({state:e,signIn:t,enableTrading:n,loading:i,disabled:o})=>jsxRuntime.jsx(ui.Match,{value:()=>e<=types.AccountStatusEnum.NotSignedIn?"signIn":"enableTrading",case:{signIn:jsxRuntime.jsx(ui.Button,{fullWidth:true,onClick:()=>t(),loading:i,disabled:o,children:"Sign In"}),enableTrading:jsxRuntime.jsx(ui.Button,{fullWidth:true,onClick:()=>n(),loading:i,disabled:o,children:"Enable Trading"})}}),Ae=e=>jsxRuntime.jsx(ui.TextField,{placeholder:"Referral code (Optional)",fullWidth:true,label:"",value:e.refCode,onChange:t=>{e.setRefCode(t.target.value);},classNames:{label:"oui-text-base-contrast-54 oui-text-xs",input:"placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm"},formatters:[ui.inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)],onClear:()=>{e.setRefCode("");},autoComplete:"off",helpText:e.helpText,className:"oui-mb-4",color:e.helpText?"danger":void 0}),Ne=()=>jsxRuntime.jsx(ui.Tooltip,{content:"Toggle this option to skip these steps next time you want to trade.",className:"oui-max-w-[300px]",children:jsxRuntime.jsx("button",{onClick:()=>{window.innerWidth>768||ui.modal.alert({title:"Remember me",message:jsxRuntime.jsx("span",{className:"oui-text-2xs oui-text-base-contrast/60",children:"Toggle this option to skip these steps next time you want to trade."})});},children:jsxRuntime.jsx(ui.Text,{intensity:54,size:"xs",className:"oui-underline oui-underline-offset-4 oui-decoration-dashed oui-decoration-base-contrast-36",children:"Remember me"})})});function Y(e){Object.keys(e).forEach(n=>{});let t="Something went wrong";return e.toString().includes("rejected")&&(t="User rejected the request."),ui.capitalizeFirstLetter(t)??t}var O=()=>{let{account:e,state:t,createOrderlyKey:n,createAccount:i}=hooks.useAccount(),[o,d]=react.useState(""),[g,l]=react.useState(""),{trigger:u}=hooks.useLazyQuery(`/v1/public/referral/verify_ref_code?referral_code=${o}`);react.useEffect(()=>{let w=localStorage.getItem("referral_code");w!=null&&d(w);},[]);let{referral_code:s,isLoading:m}=hooks.useGetReferralCode(e.accountId),[a,{error:f,isMutating:A}]=hooks.useMutation("/v1/referral/bind","POST");react.useEffect(()=>{o.length===0&&l("");},[o]);let T=()=>{ui.toast.success("Wallet connected"),o.length>=4&&o.length<=10&&a({referral_code:o}).finally(()=>{localStorage.removeItem("referral_code");});},x=async()=>{if(o.length===0)return Promise.resolve(void 0);if(o.length>0&&(o.length<4||o.length>10))return Promise.resolve("The referral_code must be 4 to 10 characters long, only accept upper case roman characters and numbers");let{exist:w}=await u();return w===false?Promise.resolve("This referral code does not exist."):Promise.resolve(void 0)},I=(s?.length||0)===0&&!m,r=async()=>{if(I){let w=await x();if(typeof w<"u")return l(w),Promise.reject(-1)}return l(""),i()};return {enableTrading:async w=>{if(I){let F=await x();if(typeof F<"u")return l(F),Promise.reject(-1)}return l(""),n(w)},initAccountState:t.status,signIn:r,enableTradingComplted:T,refCode:o,setRefCode:d,helpText:g,showRefCodeInput:I}};var v="walletConnector",R="walletConnectorSheet",G=e=>{let t=O();return jsxRuntime.jsx(B,{...t,...e})};ui.registerSimpleDialog(v,G,{size:"sm",title:"Connect wallet"});ui.registerSimpleSheet(R,G,{title:"Connect wallet"});var X={connectWallet:"Connect wallet",switchChain:"Wrong network",enableTrading:"Enable trading",signin:"Sign in"},j={connectWallet:"Please Connect wallet before starting to trade",switchChain:"Please switch to a supported network to continue",enableTrading:"Please Enable trading before starting to trade",signin:"Please sign in before starting to trade"};var S=e=>{let{status:t,buttonProps:n,fallback:i,descriptions:o,classNames:d,networkId:g,id:l,bridgeLessOnly:u}=e,{state:s}=hooks.useAccount(),{wrongNetwork:m}=reactApp.useAppContext(),a=react.useMemo(()=>t===void 0?s.status===types.AccountStatusEnum.EnableTradingWithoutConnected?types.AccountStatusEnum.EnableTradingWithoutConnected:types.AccountStatusEnum.EnableTrading:t,[t,s.status]),f={...X,...e.labels},A=react.useMemo(()=>typeof i<"u"?i({validating:s.validating,status:s.status,wrongNetwork:m}):s.validating?jsxRuntime.jsx(k,{angle:45,disabled:true,loading:true,description:o?.connectWallet,id:l,type:"button",...n,children:f.connectWallet}):jsxRuntime.jsx(Ze,{bridgeLessOnly:u,status:s.status,buttonProps:{...n,id:l,type:"button"},wrongNetwork:m,networkId:e.networkId,labels:f,descriptions:o}),[s.status,s.validating,n,m]);return jsxRuntime.jsx(ui.Either,{value:s.status>=a&&!m,left:A,children:e.children})},Ze=e=>{let{buttonProps:t,labels:n,descriptions:i}=e,{connectWallet:o}=reactApp.useAppContext(),{account:d}=hooks.useAccount(),{isMobile:g}=ui.useScreen(),l=hooks.useMediaQuery(types.MEDIA_TABLET),u=()=>{ui.modal.show(l?R:v).then(a=>{},a=>{});},s=async()=>{let a=await o();a&&(a.wrongNetwork?m():(a?.status??types.AccountStatusEnum.NotConnected)<types.AccountStatusEnum.EnableTrading&&u());},m=()=>{d.once("validate:end",a=>{a<types.AccountStatusEnum.EnableTrading?u():ui.toast.success("Wallet connected");}),ui.modal.show(g?uiChainSelector.ChainSelectorSheetId:uiChainSelector.ChainSelectorDialogId,{networkId:e.networkId,bridgeLessOnly:e.bridgeLessOnly}).then(a=>{a.wrongNetwork||e.status>=types.AccountStatusEnum.Connected&&(e.status<types.AccountStatusEnum.EnableTrading?u():ui.toast.success("Wallet connected"));},a=>{});};return e.wrongNetwork?jsxRuntime.jsx(k,{color:"warning",onClick:()=>{m();},description:i?.switchChain,...t,children:n.switchChain}):jsxRuntime.jsx(ui.Match,{value:e.status,case:a=>{if(a<=types.AccountStatusEnum.NotConnected)return jsxRuntime.jsx(k,{size:"lg",onClick:()=>{s();},variant:"gradient",angle:45,description:i?.connectWallet,...t,children:n.connectWallet});if(a<=types.AccountStatusEnum.NotSignedIn)return jsxRuntime.jsx(k,{size:"lg",onClick:()=>{u();},angle:45,description:i?.signin,...t,children:n.signin})},default:jsxRuntime.jsx(k,{size:"lg",description:i?.enableTrading,...t,onClick:()=>u(),children:n.enableTrading})})};S.displayName="AuthGuard";var k=e=>{let{description:t,...n}=e;return jsxRuntime.jsxs(ui.Flex,{direction:"column",children:[jsxRuntime.jsx(ui.Button,{...n}),!!t&&jsxRuntime.jsx(ui.Box,{mt:4,className:"oui-leading-none",style:{lineHeight:0},children:jsxRuntime.jsx(ui.Text,{size:"2xs",intensity:36,children:t})})]})};var st=e=>{let{status:t,labels:n,description:i,dataSource:o,...d}=e,{state:g}=hooks.useAccount(),l=react.useMemo(()=>t===void 0?g.status===types.AccountStatusEnum.EnableTradingWithoutConnected?types.AccountStatusEnum.EnableTradingWithoutConnected:types.AccountStatusEnum.EnableTrading:t,[t,g.status]),u=reactApp.useDataTap(o,{accountStatus:l}),{wrongNetwork:s}=reactApp.useAppContext();return jsxRuntime.jsx(ui.DataTable,{dataSource:u,ignoreLoadingCheck:s||g.status<l||e.ignoreLoadingCheck,emptyView:jsxRuntime.jsx(at,{status:l,description:i,labels:n,className:e.classNames?.authGuardDescription,visible:!g.validating}),manualPagination:true,...d})},at=e=>{let t={...j,...e.description};return e.visible?jsxRuntime.jsx(ui.Flex,{py:8,children:jsxRuntime.jsx(S,{status:e.status,labels:e.labels,descriptions:t,buttonProps:{size:"md"},children:jsxRuntime.jsx(ui.ExtensionSlot,{position:ui.ExtensionPositionEnum.EmptyDataIdentifier})})}):null};var se=e=>{let{hint:t={connectWallet:"Please connect wallet before starting to trade",signIn:"Please sign in before starting to trade",enableTrading:"Please sign in before starting to trade",wrongNetwork:"Please switch to a supported network to continue."},status:n}=e;return jsxRuntime.jsx(ui.Box,{my:8,children:jsxRuntime.jsx(S,{status:n,descriptions:{...t,switchChain:t.wrongNetwork},children:e.children||jsxRuntime.jsx(ui.EmptyDataState,{})})})};se.displayName="AuthGuardEmpty";var le=e=>{let{opactiy:t=90,tooltip:n={connectWallet:"Please connect wallet before set up",signIn:"Please sign in before set up",enableTrading:"Please enable trading before set up",wrongNetwork:"Please switch to a supported network to set up"}}=e,[i,o]=react.useState(false),{state:d}=hooks.useAccount(),g=true,{wrongNetwork:l}=reactApp.useAppContext(),u=react.useMemo(()=>{if(l)return n?.wrongNetwork;switch(d.status){case types.AccountStatusEnum.NotConnected:return n?.connectWallet;case types.AccountStatusEnum.NotSignedIn:return n?.signIn;case types.AccountStatusEnum.DisabledTrading:return n?.enableTrading;case types.AccountStatusEnum.EnableTrading:return "";default:return e.content}},[e.content,d,g,n]),s=react.useMemo(()=>{switch(d.status){case types.AccountStatusEnum.NotConnected:case types.AccountStatusEnum.NotSignedIn:return t;case types.AccountStatusEnum.EnableTrading:return;default:return}},[e.opactiy,d,g]);return jsxRuntime.jsx(ui.Tooltip,{open:u?i:false,onOpenChange:o,content:u,className:"oui-text-2xs",align:e.align,alignOffset:e.alignOffset,side:e.side,sideOffset:e.sideOffset,children:jsxRuntime.jsx("div",{style:{opacity:s},children:e.children})})};le.displayName="AuthGuardTooltip";
|
|
11
|
+
var V=e=>{let{title:t,description:n}=e;return jsxRuntime.jsxs(ui.Box,{position:"relative",className:"oui-pl-8",children:[jsxRuntime.jsxs(ui.Box,{children:[jsxRuntime.jsx(ui.Text,{as:"div",intensity:98,size:"sm",children:t}),jsxRuntime.jsx(ui.Text,{as:"div",intensity:54,size:"2xs",children:n})]}),jsxRuntime.jsx(me,{...e})]})},me=e=>{let{active:t,isLoading:n,isCompleted:i}=e;return jsxRuntime.jsx(ui.Match,{className:"oui-absolute oui-left-0 oui-top-1 oui-z-10",value:()=>i?"completed":n?"loading":t?"active":"normal",case:{loading:jsxRuntime.jsx("div",{children:jsxRuntime.jsx(ui.Spinner,{size:"sm",className:"oui-ml-1"})}),completed:jsxRuntime.jsx("div",{children:jsxRuntime.jsx(ui.CheckedCircleFillIcon,{opacity:1,className:"oui-text-primary"})})},default:jsxRuntime.jsx(fe,{active:!!t})})},fe=({active:e,className:t})=>jsxRuntime.jsx("div",{className:ui.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 B=e=>{let{initAccountState:t=types.AccountStatusEnum.NotConnected}=e,[n,i]=react.useState(true),o=hooks.useEventEmitter(),{state:u,account:g}=hooks.useAccount(),[c,d]=react.useState(t),[r,m]=react.useState(0),[s,p]=react.useState(false),[x]=hooks.useLocalStorage("orderly-first-show-wallet-connector-dialog",void 0);react.useEffect(()=>()=>{localStorage.setItem("orderly-first-show-wallet-connector-dialog","1");},[]),react.useEffect(()=>{d(u.status);},[u]);let y=react.useMemo(()=>{let a=[];return t<types.AccountStatusEnum.SignedIn&&a.push({key:"signIn",title:"Sign In",description:"Confirm you are the owner of this wallet"}),t<types.AccountStatusEnum.EnableTrading&&a.push({key:"enableTrading",title:"Enable Trading",description:"Enable secure access to our API for lightning fast trading"}),a},[t]),I=()=>(p(true),e.enableTrading(n).then(async a=>{p(false),m(C=>C+1);try{await e.enableTradingComplted?.();}catch{}typeof e.onCompleted=="function"?e.onCompleted():typeof e.close=="function"&&e.close();},a=>{if(p(false),a!==-1){if(a.message.indexOf("Signing off chain messages with Ledger is not yet supported")!==-1){o.emit("wallet:sign-message-with-ledger-error",{message:a.message,userAddress:g.address});return}ui.toast.error(Y(a));}}).catch(a=>{p(false);})),P=()=>(p(true),e.signIn().then(a=>{m(C=>C+1),I();},a=>{if(p(false),a!==-1){if(a.message.indexOf("Signing off chain messages with Ledger is not yet supported")!==-1){o.emit("wallet:sign-message-with-ledger-error",{message:a.message,userAddress:g.address});return}ui.toast.error(Y(a));}}).catch(a=>{p(false);}));return jsxRuntime.jsxs(ui.Box,{id:"oui-wallet-connect-dialog-content",className:"oui-font-semibold",children:[jsxRuntime.jsx(ui.Text,{intensity:54,size:"xs",children:"Your previous access has expired, you will receive a signature request to enable trading. Signing is free and will not send a transaction."}),jsxRuntime.jsxs(ui.Box,{p:4,my:6,intensity:600,r:"lg",className:"oui-space-y-5",position:"relative",children:[y.map((a,C)=>jsxRuntime.jsx(V,{title:a.title,description:a.description,isCompleted:r>C,active:r===C,isLoading:s&&r===C},a.key)),y.length>1&&jsxRuntime.jsx(ui.Box,{position:"absolute",height:"38px",left:28,top:18,zIndex:0,children:jsxRuntime.jsx(ui.Divider,{lineStyle:"dashed",direction:"vertical",intensity:16,className:"oui-h-full"})})]}),e.showRefCodeInput&&y.length==2&&jsxRuntime.jsx(Ae,{...e}),x&&jsxRuntime.jsxs(ui.Flex,{justify:"between",itemAlign:"center",children:[jsxRuntime.jsx(Ne,{}),jsxRuntime.jsx(ui.Switch,{color:"primary",checked:n,onCheckedChange:i,disabled:s,className:"data-[state=checked]:oui-bg-primary-darken"})]}),jsxRuntime.jsx(ui.Flex,{justify:"center",mt:8,children:jsxRuntime.jsx(ui.Box,{width:"45%",children:jsxRuntime.jsx(Ee,{state:c,signIn:P,enableTrading:I,loading:s,disabled:c>=types.AccountStatusEnum.EnableTrading})})})]})},Ee=({state:e,signIn:t,enableTrading:n,loading:i,disabled:o})=>jsxRuntime.jsx(ui.Match,{value:()=>e<=types.AccountStatusEnum.NotSignedIn?"signIn":"enableTrading",case:{signIn:jsxRuntime.jsx(ui.Button,{fullWidth:true,onClick:()=>t(),loading:i,disabled:o,children:"Sign In"}),enableTrading:jsxRuntime.jsx(ui.Button,{fullWidth:true,onClick:()=>n(),loading:i,disabled:o,children:"Enable Trading"})}}),Ae=e=>jsxRuntime.jsx(ui.TextField,{placeholder:"Referral code (Optional)",fullWidth:true,label:"",value:e.refCode,onChange:t=>{e.setRefCode(t.target.value);},classNames:{label:"oui-text-base-contrast-54 oui-text-xs",input:"placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm"},formatters:[ui.inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)],onClear:()=>{e.setRefCode("");},autoComplete:"off",helpText:e.helpText,className:"oui-mb-4",color:e.helpText?"danger":void 0}),Ne=()=>jsxRuntime.jsx(ui.Tooltip,{content:"Toggle this option to skip these steps next time you want to trade.",className:"oui-max-w-[300px]",children:jsxRuntime.jsx("button",{onClick:()=>{window.innerWidth>768||ui.modal.alert({title:"Remember me",message:jsxRuntime.jsx("span",{className:"oui-text-2xs oui-text-base-contrast/60",children:"Toggle this option to skip these steps next time you want to trade."})});},children:jsxRuntime.jsx(ui.Text,{intensity:54,size:"xs",className:"oui-underline oui-underline-offset-4 oui-decoration-dashed oui-decoration-base-contrast-36",children:"Remember me"})})});function Y(e){Object.keys(e).forEach(n=>{});let t="Something went wrong";return e.toString().includes("rejected")&&(t="User rejected the request."),ui.capitalizeFirstLetter(t)??t}var L=()=>{let{account:e,state:t,createOrderlyKey:n,createAccount:i}=hooks.useAccount(),[o,u]=react.useState(""),[g,c]=react.useState(""),{trigger:d}=hooks.useLazyQuery(`/v1/public/referral/verify_ref_code?referral_code=${o}`);react.useEffect(()=>{let w=localStorage.getItem("referral_code");w!=null&&u(w);},[]);let{referral_code:r,isLoading:m}=hooks.useGetReferralCode(e.accountId),[s,{error:p,isMutating:x}]=hooks.useMutation("/v1/referral/bind","POST");react.useEffect(()=>{o.length===0&&c("");},[o]);let y=()=>{ui.toast.success("Wallet connected"),o.length>=4&&o.length<=10&&s({referral_code:o}).finally(()=>{localStorage.removeItem("referral_code");});},I=async()=>{if(o.length===0)return Promise.resolve(void 0);if(o.length>0&&(o.length<4||o.length>10))return Promise.resolve("The referral_code must be 4 to 10 characters long, only accept upper case roman characters and numbers");let{exist:w}=await d();return w===false?Promise.resolve("This referral code does not exist."):Promise.resolve(void 0)},P=(r?.length||0)===0&&!m,a=async()=>{if(P){let w=await I();if(typeof w<"u")return c(w),Promise.reject(-1)}return c(""),i()};return {enableTrading:async w=>{if(P){let F=await I();if(typeof F<"u")return c(F),Promise.reject(-1)}return c(""),n(w)},initAccountState:t.status,signIn:a,enableTradingComplted:y,refCode:o,setRefCode:u,helpText:g,showRefCodeInput:P}};var v="walletConnector",R="walletConnectorSheet",O=e=>{let t=L();return jsxRuntime.jsx(B,{...t,...e})};ui.registerSimpleDialog(v,O,{size:"sm",title:"Connect wallet"});ui.registerSimpleSheet(R,O,{title:"Connect wallet"});var X={connectWallet:"Connect wallet",switchChain:"Wrong network",enableTrading:"Enable trading",signin:"Sign in"},j={connectWallet:"Please Connect wallet before starting to trade",switchChain:"Please switch to a supported network to continue",enableTrading:"Please Enable trading before starting to trade",signin:"Please sign in before starting to trade"};var T=e=>{let{status:t,buttonProps:n,fallback:i,descriptions:o,classNames:u,networkId:g,id:c,bridgeLessOnly:d}=e,{state:r}=hooks.useAccount(),{wrongNetwork:m,disabledConnect:s}=reactApp.useAppContext(),p=react.useMemo(()=>t===void 0?r.status===types.AccountStatusEnum.EnableTradingWithoutConnected?types.AccountStatusEnum.EnableTradingWithoutConnected:types.AccountStatusEnum.EnableTrading:t,[t,r.status]),x={...X,...e.labels},y=react.useMemo(()=>typeof i<"u"?i({validating:r.validating,status:r.status,wrongNetwork:m}):r.validating&&!s?jsxRuntime.jsx(E,{angle:45,disabled:true,loading:true,description:o?.connectWallet,id:c,type:"button",...n,children:x.connectWallet}):jsxRuntime.jsx(Ze,{bridgeLessOnly:d,status:r.status,buttonProps:{...n,id:c,type:"button"},wrongNetwork:m,networkId:e.networkId,labels:x,descriptions:o,disabledConnect:s}),[r.status,r.validating,n,m]);return jsxRuntime.jsx(ui.Either,{value:r.status>=p&&!m&&!s,left:y,children:e.children})},Ze=e=>{let{buttonProps:t,labels:n,descriptions:i}=e,{connectWallet:o}=reactApp.useAppContext(),{account:u}=hooks.useAccount(),{isMobile:g}=ui.useScreen(),c=hooks.useMediaQuery(types.MEDIA_TABLET),d=()=>{ui.modal.show(c?R:v).then(s=>{},s=>{});},r=async()=>{let s=await o();s&&(s.wrongNetwork?m():(s?.status??types.AccountStatusEnum.NotConnected)<types.AccountStatusEnum.EnableTrading&&d());},m=()=>{u.once("validate:end",s=>{s<types.AccountStatusEnum.EnableTrading?d():ui.toast.success("Wallet connected");}),ui.modal.show(g?uiChainSelector.ChainSelectorSheetId:uiChainSelector.ChainSelectorDialogId,{networkId:e.networkId,bridgeLessOnly:e.bridgeLessOnly}).then(s=>{s.wrongNetwork||e.status>=types.AccountStatusEnum.Connected&&(e.status<types.AccountStatusEnum.EnableTrading?d():ui.toast.success("Wallet connected"));},s=>{});};return e.wrongNetwork&&!e.disabledConnect?jsxRuntime.jsx(E,{color:"warning",onClick:()=>{m();},description:i?.switchChain,...t,children:n.switchChain}):jsxRuntime.jsx(ui.Match,{value:e.status,case:s=>{if(s<=types.AccountStatusEnum.NotConnected||e.disabledConnect)return jsxRuntime.jsx(E,{size:"lg",onClick:()=>{r();},variant:e.disabledConnect?void 0:"gradient",angle:45,description:i?.connectWallet,disabled:e.disabledConnect,...t,children:n.connectWallet});if(s<=types.AccountStatusEnum.NotSignedIn)return jsxRuntime.jsx(E,{size:"lg",onClick:()=>{d();},angle:45,description:i?.signin,...t,children:n.signin})},default:jsxRuntime.jsx(E,{size:"lg",description:i?.enableTrading,...t,onClick:()=>d(),children:n.enableTrading})})};T.displayName="AuthGuard";var E=e=>{let{description:t,...n}=e;return jsxRuntime.jsxs(ui.Flex,{direction:"column",children:[jsxRuntime.jsx(ui.Button,{...n}),!!t&&jsxRuntime.jsx(ui.Box,{mt:4,className:"oui-leading-none",style:{lineHeight:0},children:jsxRuntime.jsx(ui.Text,{size:"2xs",intensity:36,children:t})})]})};var rt=e=>{let{status:t,labels:n,description:i,dataSource:o,...u}=e,{state:g}=hooks.useAccount(),{wrongNetwork:c,disabledConnect:d}=reactApp.useAppContext(),r=react.useMemo(()=>t===void 0?g.status===types.AccountStatusEnum.EnableTradingWithoutConnected?types.AccountStatusEnum.EnableTradingWithoutConnected:types.AccountStatusEnum.EnableTrading:t,[t,g.status]),m=reactApp.useDataTap(o,{accountStatus:r}),s=c||d||g.status<r||e.ignoreLoadingCheck;return jsxRuntime.jsx(ui.DataTable,{dataSource:m,ignoreLoadingCheck:s,emptyView:jsxRuntime.jsx(at,{status:r,description:i,labels:n,className:e.classNames?.authGuardDescription,visible:!g.validating}),manualPagination:true,...u})},at=e=>{let t={...j,...e.description};return e.visible?jsxRuntime.jsx(ui.Flex,{py:8,children:jsxRuntime.jsx(T,{status:e.status,labels:e.labels,descriptions:t,buttonProps:{size:"md"},children:jsxRuntime.jsx(ui.ExtensionSlot,{position:ui.ExtensionPositionEnum.EmptyDataIdentifier})})}):null};var re=e=>{let{hint:t={connectWallet:"Please connect wallet before starting to trade",signIn:"Please sign in before starting to trade",enableTrading:"Please sign in before starting to trade",wrongNetwork:"Please switch to a supported network to continue."},status:n}=e;return jsxRuntime.jsx(ui.Box,{my:8,children:jsxRuntime.jsx(T,{status:n,descriptions:{...t,switchChain:t.wrongNetwork},children:e.children||jsxRuntime.jsx(ui.EmptyDataState,{})})})};re.displayName="AuthGuardEmpty";var le=e=>{let{opactiy:t=90,tooltip:n={connectWallet:"Please connect wallet before set up",signIn:"Please sign in before set up",enableTrading:"Please enable trading before set up",wrongNetwork:"Please switch to a supported network to set up"}}=e,[i,o]=react.useState(false),{state:u}=hooks.useAccount(),g=true,{wrongNetwork:c}=reactApp.useAppContext(),d=react.useMemo(()=>{if(c)return n?.wrongNetwork;switch(u.status){case types.AccountStatusEnum.NotConnected:return n?.connectWallet;case types.AccountStatusEnum.NotSignedIn:return n?.signIn;case types.AccountStatusEnum.DisabledTrading:return n?.enableTrading;case types.AccountStatusEnum.EnableTrading:return "";default:return e.content}},[e.content,u,g,n]),r=react.useMemo(()=>{switch(u.status){case types.AccountStatusEnum.NotConnected:case types.AccountStatusEnum.NotSignedIn:return t;case types.AccountStatusEnum.EnableTrading:return;default:return}},[e.opactiy,u,g]);return jsxRuntime.jsx(ui.Tooltip,{open:d?i:false,onOpenChange:o,content:d,className:"oui-text-2xs",align:e.align,alignOffset:e.alignOffset,side:e.side,sideOffset:e.sideOffset,children:jsxRuntime.jsx("div",{style:{opacity:r},children:e.children})})};le.displayName="AuthGuardTooltip";
|
|
12
12
|
|
|
13
|
-
exports.AuthGuard =
|
|
14
|
-
exports.AuthGuardDataTable =
|
|
15
|
-
exports.AuthGuardEmpty =
|
|
13
|
+
exports.AuthGuard = T;
|
|
14
|
+
exports.AuthGuardDataTable = rt;
|
|
15
|
+
exports.AuthGuardEmpty = re;
|
|
16
16
|
exports.AuthGuardTooltip = le;
|
|
17
17
|
exports.WalletConnectContent = B;
|
|
18
18
|
exports.WalletConnectorModalId = v;
|
|
19
19
|
exports.WalletConnectorSheetId = R;
|
|
20
|
-
exports.WalletConnectorWidget =
|
|
21
|
-
exports.useWalletConnectorBuilder =
|
|
20
|
+
exports.WalletConnectorWidget = O;
|
|
21
|
+
exports.useWalletConnectorBuilder = L;
|
|
22
22
|
//# sourceMappingURL=out.js.map
|
|
23
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/walletConnectorContent.tsx","../src/component/step.tsx","../src/component/walletConnector.tsx","../src/component/useWalletConnectorBuilder.ts","../src/component/authGuard.tsx","../src/constants/message.ts","../src/component/authGuardDataTable.tsx","../src/component/authGuardEmpty.tsx","../src/component/authGuardTooltip.tsx"],"names":["useEffect","useMemo","useState","Box","Button","capitalizeFirstLetter","Divider","Flex","inputFormatter","Match","modal","Switch","Text","TextField","toast","Tooltip","AccountStatusEnum","CheckedCircleFillIcon","cn","Spinner","jsx","jsxs","StepItem","props","title","description","Identifier","active","isLoading","isCompleted","Dot","className","useAccount","useEventEmitter","useLocalStorage","WalletConnectContent","initAccountState","remember","setRemember","ee","accountState","account","state","setState","activeStep","setActiveStep","loading","setLoading","firstShowDialog","steps","onEnableTrading","res","step","reject","paseErrorMsg","e","onSignIn","index","ReferralCode","RememberMe","ActionButton","signIn","enableTrading","disabled","key","msg","registerSimpleDialog","registerSimpleSheet","useGetReferralCode","useLazyQuery","useMutation","useWalletConnectorBuilder","createOrderlyKey","createAccount","refCode","setRefCode","helpText","setHelpText","verifyRefCode","referral_code","bindRefCode","updateOrderError","updateMutating","enableTradingComplted","checkRefCode","exist","showRefCodeInput","info","WalletConnectorModalId","WalletConnectorSheetId","WalletConnectorWidget","useMediaQuery","MEDIA_TABLET","Either","useScreen","useAppContext","ChainSelectorDialogId","ChainSelectorSheetId","LABELS","DESCRIPTIONS","AuthGuard","status","buttonProps","fallback","descriptions","classNames","networkId","id","bridgeLessOnly","wrongNetwork","_status","labels","Left","StatusInfo","DefaultFallback","connectWallet","isMobile","matches","onConnectOrderly","r","error","onConnectWallet","switchChain","value","ExtensionPositionEnum","ExtensionSlot","DataTable","useDataTap","AuthGuardDataTable","dataSource","rest","data","GuardView","EmptyDataState","AuthGuardEmpty","hint","AuthGuardTooltip","opactiy","tooltip","open","setOpen","isSupport","newOpacity"],"mappings":"AAAA,OAAa,aAAAA,EAAW,WAAAC,GAAS,YAAAC,MAAgB,QACjD,OACE,OAAAC,EACA,UAAAC,EACA,yBAAAC,GAEA,WAAAC,GACA,QAAAC,EAEA,kBAAAC,GACA,SAAAC,GACA,SAAAC,GACA,UAAAC,GACA,QAAAC,EACA,aAAAC,GACA,SAAAC,EACA,WAAAC,OACK,sBACP,OAAS,qBAAAC,MAAyB,yBCjBlC,OACE,OAAAb,EACA,yBAAAc,GACA,MAAAC,GACA,SAAAT,GACA,WAAAU,GACA,QAAAP,MACK,sBAiBD,OACE,OAAAQ,EADF,QAAAC,MAAA,oBAPC,IAAMC,EAAYC,GAAyB,CAChD,GAAM,CAAE,MAAAC,EAAO,YAAAC,CAAY,EAAIF,EAI/B,OACEF,EAAClB,EAAA,CAAI,SAAS,WAAW,UAAU,WACjC,UAAAkB,EAAClB,EAAA,CACC,UAAAiB,EAACR,EAAA,CAAK,GAAG,MAAM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A,EAAM,YACnB,KAAMA,EAAM,KACZ,WAAYA,EAAM,WAElB,SAAAH,GAAC,OACC,MAAO,CACL,QAAS0H,CACX,EAEC,SAAAvH,EAAM,SACT,EACF,CAEJ,EAEAiH,GAAiB,YAAc","sourcesContent":["import { FC, useEffect, useMemo, useState } from \"react\";\nimport {\n Box,\n Button,\n capitalizeFirstLetter,\n cn,\n Divider,\n Flex,\n Input,\n inputFormatter,\n Match,\n modal,\n Switch,\n Text,\n TextField,\n toast,\n Tooltip,\n} from \"@orderly.network/ui\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\nimport { StepItem } from \"./step\";\nimport { useAccount, useEventEmitter, useLocalStorage } from \"@orderly.network/hooks\";\n\nexport type WalletConnectContentProps = {\n initAccountState: AccountStatusEnum;\n signIn: () => Promise<any>;\n enableTrading: (remember: boolean) => Promise<any>;\n enableTradingComplted?: () => Promise<void>;\n onCompleted?: () => void;\n close?: () => void;\n refCode: string;\n setRefCode: React.Dispatch<React.SetStateAction<string>>;\n helpText?: string;\n showRefCodeInput: boolean;\n};\n\nexport const WalletConnectContent = (props: WalletConnectContentProps) => {\n const { initAccountState = AccountStatusEnum.NotConnected } = props;\n const [remember, setRemember] = useState(true);\n const ee = useEventEmitter();\n\n\n const { state: accountState, account } = useAccount();\n const [state, setState] = useState(initAccountState);\n const [activeStep, setActiveStep] = useState(0);\n const [loading, setLoading] = useState(false);\n const [firstShowDialog] = useLocalStorage(\n \"orderly-first-show-wallet-connector-dialog\",\n undefined\n );\n useEffect(() => {\n return () => {\n localStorage.setItem(\"orderly-first-show-wallet-connector-dialog\", \"1\");\n };\n }, []);\n\n useEffect(() => {\n setState(accountState.status);\n }, [accountState]);\n\n const steps = useMemo(() => {\n const steps = [];\n if (initAccountState < AccountStatusEnum.SignedIn) {\n steps.push({\n key: \"signIn\",\n title: \"Sign In\",\n description: \"Confirm you are the owner of this wallet\",\n });\n }\n\n if (initAccountState < AccountStatusEnum.EnableTrading) {\n steps.push({\n key: \"enableTrading\",\n title: \"Enable Trading\",\n description:\n \"Enable secure access to our API for lightning fast trading\",\n });\n }\n\n return steps;\n }, [initAccountState]);\n\n const onEnableTrading = () => {\n setLoading(true);\n return props\n .enableTrading(remember)\n .then(\n async (res) => {\n console.log(res);\n setLoading(false);\n setActiveStep((step) => step + 1);\n try {\n await props.enableTradingComplted?.();\n } catch (e) {}\n if (typeof props.onCompleted === \"function\") {\n props.onCompleted();\n } else if (typeof props.close === \"function\") {\n props.close();\n }\n // props.onCompleted?.();\n },\n (reject) => {\n setLoading(false);\n if (reject === -1) return;\n\n if (reject.message.indexOf('Signing off chain messages with Ledger is not yet supported') !== -1) {\n ee.emit(\"wallet:sign-message-with-ledger-error\", {message: reject.message,userAddress: account.address});\n return;\n }\n toast.error(paseErrorMsg(reject));\n }\n )\n .catch((e) => {\n console.log(\"enable trading catch error\", e);\n setLoading(false);\n });\n };\n\n const onSignIn = () => {\n setLoading(true);\n return props\n .signIn()\n .then(\n (res) => {\n setActiveStep((step) => step + 1);\n onEnableTrading();\n },\n (reject) => {\n setLoading(false);\n\n if (reject === -1) return;\n if (reject.message.indexOf('Signing off chain messages with Ledger is not yet supported') !== -1) {\n ee.emit(\"wallet:sign-message-with-ledger-error\", {message: reject.message,userAddress: account.address});\n return;\n }\n\n toast.error(paseErrorMsg(reject));\n }\n )\n .catch((e) => {\n setLoading(false);\n });\n };\n\n console.log(\"state\", state);\n\n return (\n <Box id=\"oui-wallet-connect-dialog-content\" className=\"oui-font-semibold\">\n <Text intensity={54} size=\"xs\">\n Your previous access has expired, you will receive a signature request\n to enable trading. Signing is free and will not send a transaction.\n </Text>\n <Box\n p={4}\n my={6}\n intensity={600}\n r=\"lg\"\n className=\"oui-space-y-5\"\n position={\"relative\"}\n >\n {steps.map((step, index) => {\n return (\n <StepItem\n title={step.title}\n description={step.description}\n isCompleted={activeStep > index}\n key={step.key}\n active={activeStep === index}\n isLoading={loading && activeStep === index}\n />\n );\n })}\n {steps.length > 1 && (\n <Box\n position={\"absolute\"}\n height={\"38px\"}\n left={28}\n top={18}\n zIndex={0}\n >\n <Divider\n lineStyle={\"dashed\"}\n direction={\"vertical\"}\n intensity={16}\n className=\"oui-h-full\"\n />\n </Box>\n )}\n </Box>\n {props.showRefCodeInput && steps.length == 2 && (\n <ReferralCode {...props} />\n )}\n {firstShowDialog && (\n <Flex justify={\"between\"} itemAlign={\"center\"}>\n <RememberMe />\n <Switch\n color={\"primary\"}\n checked={remember}\n onCheckedChange={setRemember}\n disabled={loading}\n className=\"data-[state=checked]:oui-bg-primary-darken\"\n />\n </Flex>\n )}\n <Flex justify={\"center\"} mt={8}>\n <Box width={\"45%\"}>\n <ActionButton\n state={state}\n signIn={onSignIn}\n enableTrading={onEnableTrading}\n loading={loading}\n disabled={state >= AccountStatusEnum.EnableTrading}\n />\n </Box>\n </Flex>\n </Box>\n );\n};\n\nconst ActionButton: FC<{\n state: AccountStatusEnum;\n signIn: () => Promise<any>;\n enableTrading: () => Promise<any>;\n loading: boolean;\n disabled?: boolean;\n}> = ({ state, signIn, enableTrading, loading, disabled }) => {\n return (\n <Match\n value={() => {\n if (state <= AccountStatusEnum.NotSignedIn) {\n return \"signIn\";\n }\n return \"enableTrading\";\n }}\n case={{\n signIn: (\n <Button\n fullWidth\n onClick={() => signIn()}\n loading={loading}\n disabled={disabled}\n >\n Sign In\n </Button>\n ),\n enableTrading: (\n <Button\n fullWidth\n onClick={() => enableTrading()}\n loading={loading}\n disabled={disabled}\n >\n Enable Trading\n </Button>\n ),\n }}\n />\n );\n};\n\nconst ReferralCode: FC<WalletConnectContentProps> = (props) => {\n return (\n <TextField\n placeholder=\"Referral code (Optional)\"\n fullWidth\n // label={\"Referral code (optional)\"}\n label=\"\"\n value={props.refCode}\n onChange={(e) => {\n props.setRefCode(e.target.value);\n }}\n classNames={{\n label: \"oui-text-base-contrast-54 oui-text-xs\",\n input: \"placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm\",\n }}\n formatters={[inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)]}\n onClear={() => {\n props.setRefCode(\"\");\n }}\n autoComplete=\"off\"\n helpText={props.helpText}\n className=\"oui-mb-4\"\n color={props.helpText ? \"danger\" : undefined}\n />\n );\n};\n\nconst RememberMe = () => {\n const showRememberHint = () => {\n if (window.innerWidth > 768) return;\n modal.alert({\n title: \"Remember me\",\n message: (\n <span className=\"oui-text-2xs oui-text-base-contrast/60\">\n Toggle this option to skip these steps next time you want to trade.\n </span>\n ),\n });\n };\n return (\n <Tooltip\n content={\n \"Toggle this option to skip these steps next time you want to trade.\"\n }\n className=\"oui-max-w-[300px]\"\n >\n <button onClick={showRememberHint}>\n <Text\n intensity={54}\n size={\"xs\"}\n className={\n \"oui-underline oui-underline-offset-4 oui-decoration-dashed oui-decoration-base-contrast-36\"\n }\n >\n Remember me\n </Text>\n </button>\n </Tooltip>\n );\n};\n\nfunction paseErrorMsg(reject: any): string {\n console.log(\"wallet callback error\", reject);\n console.log(\"message *** \", \"reject keys\", Object.keys(reject));\n Object.keys(reject).forEach((key) => {\n console.log(\"key\", key, \"-\", reject[key]);\n });\n let msg = \"Something went wrong\";\n\n // if (typeof reject?.info?.error === \"object\" && \"message\" in reject?.info?.error) {\n // msg = reject?.info?.error?.message;\n // }\n\n // if (typeof reject?.shortMessage === 'string') {\n // msg = reject.shortMessage;\n // }\n\n if (reject.toString().includes(\"rejected\")) {\n msg = \"User rejected the request.\";\n }\n\n\n return capitalizeFirstLetter(msg) ?? msg;\n}\n\n","import { FC } from \"react\";\nimport {\n Box,\n CheckedCircleFillIcon,\n cn,\n Match,\n Spinner,\n Text,\n} from \"@orderly.network/ui\";\n\ntype StepItemProps = {\n active?: boolean;\n isLoading?: boolean;\n isCompleted?: boolean;\n title: string;\n description: string;\n};\n\nexport const StepItem = (props: StepItemProps) => {\n const { title, description } = props;\n\n // console.log(props);\n\n return (\n <Box position=\"relative\" className=\"oui-pl-8\">\n <Box>\n <Text as=\"div\" intensity={98} size={\"sm\"}>\n {title}\n </Text>\n <Text as=\"div\" intensity={54} size={\"2xs\"}>\n {description}\n </Text>\n </Box>\n <Identifier {...props} />\n </Box>\n );\n};\n\nconst Identifier = (props: {\n active?: boolean;\n isLoading?: boolean;\n isCompleted?: boolean;\n}) => {\n const { active, isLoading, isCompleted } = props;\n\n return (\n <Match\n className={\"oui-absolute oui-left-0 oui-top-1 oui-z-10\"}\n value={() => {\n if (isCompleted) {\n return \"completed\";\n }\n if (isLoading) {\n return \"loading\";\n }\n\n if (active) {\n return \"active\";\n }\n\n return \"normal\";\n }}\n case={{\n loading: (\n <div>\n <Spinner size={\"sm\"} className={\"oui-ml-1\"} />\n </div>\n ),\n completed: (\n <div>\n <CheckedCircleFillIcon opacity={1} className=\"oui-text-primary\" />\n </div>\n ),\n }}\n default={<Dot active={!!active} />}\n />\n );\n};\n\nconst Dot: FC<{ active: boolean; className?: string }> = ({\n active,\n className,\n}) => {\n return (\n <div\n className={cn(\n \"oui-w-[8.3px] oui-h-[8.3px] oui-rounded-full oui-ml-2 oui-mt-1\",\n className,\n active ? \"oui-bg-primary-light\" : \"oui-bg-base-2\"\n )}\n />\n );\n};\n","import { registerSimpleDialog, registerSimpleSheet } from \"@orderly.network/ui\";\n\nimport { useWalletConnectorBuilder } from \"./useWalletConnectorBuilder\";\nimport { WalletConnectContent } from \"./walletConnectorContent\";\n\nexport const WalletConnectorModalId = \"walletConnector\" as const;\nexport const WalletConnectorSheetId = \"walletConnectorSheet\" as const;\n\nexport const WalletConnectorWidget = (props: any) => {\n const state = useWalletConnectorBuilder();\n return <WalletConnectContent {...state} {...props} />;\n};\n\nregisterSimpleDialog(WalletConnectorModalId, WalletConnectorWidget, {\n size: \"sm\",\n title: \"Connect wallet\",\n});\n\nregisterSimpleSheet(WalletConnectorSheetId, WalletConnectorWidget, {\n title: \"Connect wallet\",\n});\n","import {\n useAccount,\n useCheckReferralCode,\n useGetReferralCode,\n useLazyQuery,\n useMutation,\n} from \"@orderly.network/hooks\";\nimport { toast } from \"@orderly.network/ui\";\nimport { useEffect, useMemo, useState } from \"react\";\n\n\nexport const useWalletConnectorBuilder = () => {\n const { account, state, createOrderlyKey, createAccount } = useAccount();\n const [refCode, setRefCode] = useState(\"\");\n const [helpText, setHelpText] = useState(\"\");\n\n const { trigger: verifyRefCode } = useLazyQuery(\n `/v1/public/referral/verify_ref_code?referral_code=${refCode}`\n );\n\n useEffect(() => {\n const refCode = localStorage.getItem(\"referral_code\");\n if (refCode != null) {\n setRefCode(refCode);\n }\n }, []);\n\n const { referral_code, isLoading } = useGetReferralCode(account.accountId);\n\n const [bindRefCode, { error: updateOrderError, isMutating: updateMutating }] =\n useMutation(\"/v1/referral/bind\", \"POST\");\n\n useEffect(() => {\n if (refCode.length === 0) {\n setHelpText(\"\");\n }\n }, [refCode]);\n\n const enableTradingComplted = () => {\n toast.success(\"Wallet connected\");\n // validate ref code and bind referral code\n if (refCode.length >= 4 && refCode.length <= 10)\n bindRefCode({ referral_code: refCode }).finally(() => {\n localStorage.removeItem(\"referral_code\");\n });\n };\n\n const checkRefCode = async (): Promise<string | undefined> => {\n if (refCode.length === 0) return Promise.resolve(undefined);\n\n if (refCode.length > 0 && (refCode.length < 4 || refCode.length > 10)) {\n return Promise.resolve(\n \"The referral_code must be 4 to 10 characters long, only accept upper case roman characters and numbers\"\n );\n }\n\n const { exist } = await verifyRefCode();\n \n\n if (exist === false) {\n return Promise.resolve(\"This referral code does not exist.\");\n }\n\n return Promise.resolve(undefined);\n };\n\n\n const showRefCodeInput = (referral_code?.length || 0) === 0 && !isLoading;\n\n\n const signIn = async () => {\n if (showRefCodeInput) {\n const info = await checkRefCode();\n if (typeof info !== \"undefined\") {\n setHelpText(info);\n return Promise.reject(-1);\n }\n }\n setHelpText(\"\");\n return createAccount();\n };\n\n const enableTrading = async (remember: boolean) => {\n if (showRefCodeInput) {\n const info = await checkRefCode();\n if (typeof info !== \"undefined\") {\n setHelpText(info);\n return Promise.reject(-1);\n }\n }\n setHelpText(\"\");\n return createOrderlyKey(remember);\n };\n\n return {\n enableTrading,\n initAccountState: state.status,\n signIn,\n enableTradingComplted,\n refCode,\n setRefCode,\n helpText,\n showRefCodeInput,\n } as const;\n};\n","import { useAccount, useMediaQuery } from \"@orderly.network/hooks\";\nimport {\n AccountStatusEnum,\n MEDIA_TABLET,\n NetworkId,\n} from \"@orderly.network/types\";\nimport {\n Button,\n Either,\n Match,\n modal,\n Text,\n toast,\n useScreen,\n type ButtonProps,\n} from \"@orderly.network/ui\";\nimport { useAppContext } from \"@orderly.network/react-app\";\nimport { PropsWithChildren, ReactElement, useMemo } from \"react\";\nimport {\n WalletConnectorModalId,\n WalletConnectorSheetId,\n} from \"./walletConnector\";\nimport {\n ChainSelectorDialogId,\n ChainSelectorSheetId,\n} from \"@orderly.network/ui-chain-selector\";\nimport { alertMessages, DESCRIPTIONS, LABELS } from \"../constants/message\";\nimport { Flex } from \"@orderly.network/ui\";\nimport { Box } from \"@orderly.network/ui\";\n\ntype ChainProps = {\n networkId?: NetworkId;\n bridgeLessOnly?: boolean;\n};\n\nexport type AuthGuardProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {\n fallback?: (props: {\n validating: boolean;\n status: AccountStatusEnum;\n wrongNetwork: boolean;\n }) => ReactElement;\n // indicator?: ReactElement;\n /**\n * Required state to be satisfied\n * @default AccountStatusEnum.EnableTrading\n */\n status?: AccountStatusEnum;\n\n bridgeLessOnly?: boolean;\n\n buttonProps?: ButtonProps;\n\n descriptions?: alertMessages;\n\n labels?: alertMessages;\n\n classNames?: {\n root?: string;\n description?: string;\n // button?: string;\n };\n\n networkId?: NetworkId;\n\n // validatingIndicator?: ReactElement;\n};\n\nconst AuthGuard = (props: PropsWithChildren<AuthGuardProps>) => {\n const {\n status,\n buttonProps,\n fallback,\n descriptions,\n classNames,\n networkId,\n id,\n bridgeLessOnly,\n // ...rest\n } = props;\n const { state } = useAccount();\n const { wrongNetwork } = useAppContext();\n\n const _status = useMemo(() => {\n if (status === undefined) {\n return state.status === AccountStatusEnum.EnableTradingWithoutConnected\n ? AccountStatusEnum.EnableTradingWithoutConnected\n : AccountStatusEnum.EnableTrading;\n }\n return status;\n }, [status, state.status]);\n\n const labels = { ...LABELS, ...props.labels };\n\n // return Match(state.status)\n // .with(AccountStatusEnum.EnableTrading, () => props.children)\n // .with(AccountStatusEnum.DisableTrading, () => props.fallback)\n // .with(AccountStatusEnum.Validating, () => props.validatingIndicator)\n // .otherwise(() => props.fallback);\n //\n\n const Left = useMemo<ReactElement>(() => {\n if (typeof fallback !== \"undefined\") {\n return fallback({\n validating: state.validating,\n status: state.status,\n wrongNetwork,\n });\n }\n\n if (state.validating) {\n return (\n <StatusInfo\n // variant={\"gradient\"}\n angle={45}\n // fullWidth\n disabled\n loading\n description={descriptions?.connectWallet}\n id={id}\n type=\"button\"\n {...buttonProps}\n >\n {labels.connectWallet}\n </StatusInfo>\n );\n }\n\n return (\n <DefaultFallback\n bridgeLessOnly={bridgeLessOnly}\n status={state.status}\n buttonProps={{ ...buttonProps, id, type: \"button\" }}\n wrongNetwork={wrongNetwork}\n networkId={props.networkId}\n labels={labels}\n descriptions={descriptions}\n />\n );\n }, [state.status, state.validating, buttonProps, wrongNetwork]);\n\n /**\n * **Important: The chldren component will be rendered only if the status is equal to the required status and the network is correct.**\n */\n\n return (\n <Either value={state.status >= _status && !wrongNetwork} left={Left}>\n {props.children}\n </Either>\n );\n};\n\nconst DefaultFallback = (props: {\n status: AccountStatusEnum;\n wrongNetwork: boolean;\n buttonProps?: ButtonProps;\n networkId?: NetworkId;\n labels: alertMessages;\n bridgeLessOnly?: boolean;\n descriptions?: alertMessages;\n}) => {\n const { buttonProps, labels, descriptions } = props;\n const { connectWallet } = useAppContext();\n const { account } = useAccount();\n const { isMobile } = useScreen();\n const matches = useMediaQuery(MEDIA_TABLET);\n const onConnectOrderly = () => {\n modal.show(matches ? WalletConnectorSheetId : WalletConnectorModalId).then(\n (r) => console.log(r),\n (error) => console.log(error)\n );\n };\n\n const onConnectWallet = async () => {\n const res = await connectWallet();\n\n if (!res) return;\n\n if (res.wrongNetwork) {\n switchChain();\n } else {\n if (\n (res?.status ?? AccountStatusEnum.NotConnected) <\n AccountStatusEnum.EnableTrading\n ) {\n onConnectOrderly();\n }\n }\n };\n\n const switchChain = () => {\n account.once(\"validate:end\", (status) => {\n if (status < AccountStatusEnum.EnableTrading) {\n onConnectOrderly();\n } else {\n toast.success(\"Wallet connected\");\n }\n });\n\n modal\n .show<{\n wrongNetwork: boolean;\n }>(isMobile ? ChainSelectorSheetId : ChainSelectorDialogId, {\n networkId: props.networkId,\n bridgeLessOnly: props.bridgeLessOnly,\n })\n .then(\n (r) => {\n if (!r.wrongNetwork) {\n if (props.status >= AccountStatusEnum.Connected) {\n if (props.status < AccountStatusEnum.EnableTrading) {\n onConnectOrderly();\n } else {\n toast.success(\"Wallet connected\");\n }\n }\n }\n },\n (error) => console.log(\"[switchChain error]\", error)\n );\n };\n\n if (props.wrongNetwork) {\n return (\n <StatusInfo\n color=\"warning\"\n // size=\"md\"\n // fullWidth\n onClick={() => {\n switchChain();\n }}\n description={descriptions?.switchChain}\n {...buttonProps}\n >\n {labels.switchChain}\n </StatusInfo>\n );\n }\n\n return (\n <Match\n value={props.status}\n case={(value: AccountStatusEnum) => {\n if (value <= AccountStatusEnum.NotConnected) {\n return (\n <StatusInfo\n size=\"lg\"\n onClick={() => {\n onConnectWallet();\n }}\n // fullWidth\n variant={\"gradient\"}\n angle={45}\n description={descriptions?.connectWallet}\n {...buttonProps}\n >\n {labels.connectWallet}\n </StatusInfo>\n );\n }\n if (value <= AccountStatusEnum.NotSignedIn) {\n return (\n <StatusInfo\n size=\"lg\"\n onClick={() => {\n onConnectOrderly();\n }}\n // fullWidth\n angle={45}\n description={descriptions?.signin}\n {...buttonProps}\n >\n {labels.signin}\n </StatusInfo>\n );\n }\n }}\n default={\n <StatusInfo\n size=\"lg\"\n // fullWidth\n description={descriptions?.enableTrading}\n {...buttonProps}\n onClick={() => onConnectOrderly()}\n >\n {labels.enableTrading}\n </StatusInfo>\n }\n />\n );\n};\n\nAuthGuard.displayName = \"AuthGuard\";\n\nconst StatusInfo = (\n props: ButtonProps & {\n description?: string;\n }\n) => {\n const { description, ...buttonProps } = props;\n return (\n <Flex direction={\"column\"}>\n <Button {...buttonProps}></Button>\n {!!description && (\n <Box mt={4} className=\"oui-leading-none\" style={{ lineHeight: 0 }}>\n <Text size=\"2xs\" intensity={36}>\n {description}\n </Text>\n </Box>\n )}\n </Flex>\n );\n};\n\nexport { AuthGuard };\n","export type alertMessages = {\n connectWallet?: string;\n switchChain?: string;\n enableTrading?: string;\n signin?: string;\n};\n\nexport const LABELS = {\n connectWallet: \"Connect wallet\",\n switchChain: \"Wrong network\",\n enableTrading: \"Enable trading\",\n signin: \"Sign in\",\n};\n\nexport const DESCRIPTIONS: alertMessages = {\n connectWallet: \"Please Connect wallet before starting to trade\",\n switchChain: \"Please switch to a supported network to continue\",\n enableTrading: \"Please Enable trading before starting to trade\",\n signin: \"Please sign in before starting to trade\",\n};\n","import { PropsWithChildren, useMemo } from \"react\";\nimport {\n ExtensionPositionEnum,\n ExtensionSlot,\n DataTable,\n DataTableProps,\n} from \"@orderly.network/ui\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\nimport { alertMessages, DESCRIPTIONS } from \"../constants/message\";\nimport { useAppContext, useDataTap } from \"@orderly.network/react-app\";\nimport { Flex } from \"@orderly.network/ui\";\nimport { AuthGuard } from \"./authGuard\";\nimport { useAccount } from \"@orderly.network/hooks\";\n\nexport const AuthGuardDataTable = <RecordType extends unknown>(\n props: PropsWithChildren<\n DataTableProps<RecordType> &\n Omit<GuardViewProps, \"status\"> & {\n status?: AccountStatusEnum;\n classNames?: DataTableProps<RecordType>[\"classNames\"] & {\n authGuardDescription?: string;\n };\n }\n >\n) => {\n const {\n status,\n // message,\n labels,\n description,\n dataSource,\n ...rest\n } = props;\n const { state } = useAccount();\n\n const _status = useMemo(() => {\n if (status === undefined) {\n return state.status === AccountStatusEnum.EnableTradingWithoutConnected\n ? AccountStatusEnum.EnableTradingWithoutConnected\n : AccountStatusEnum.EnableTrading;\n }\n return status;\n }, [status, state.status]);\n\n const data = useDataTap(dataSource, {\n accountStatus: _status,\n });\n const { wrongNetwork } = useAppContext();\n\n return (\n <DataTable\n dataSource={data}\n ignoreLoadingCheck={\n wrongNetwork || state.status < _status || props.ignoreLoadingCheck\n }\n emptyView={\n <GuardView\n status={_status}\n description={description}\n labels={labels}\n className={props.classNames?.authGuardDescription}\n visible={!state.validating}\n />\n }\n manualPagination\n {...rest}\n />\n );\n};\n\ntype GuardViewProps = {\n status: AccountStatusEnum;\n description?: alertMessages;\n labels?: alertMessages;\n className?: string;\n visible?: boolean;\n};\n\nconst GuardView = (props: GuardViewProps) => {\n const descriptions = { ...DESCRIPTIONS, ...props.description };\n if (!props.visible) return null;\n return (\n <Flex py={8}>\n <AuthGuard\n status={props.status}\n labels={props.labels}\n descriptions={descriptions}\n buttonProps={{\n size: \"md\",\n }}\n >\n <ExtensionSlot position={ExtensionPositionEnum.EmptyDataIdentifier} />\n </AuthGuard>\n </Flex>\n );\n};\n","import { AccountStatusEnum } from \"@orderly.network/types\";\nimport {\n Box,\n EmptyDataState,\n} from \"@orderly.network/ui\";\nimport { PropsWithChildren } from \"react\";\nimport { AuthGuard } from \"./authGuard\";\n\ntype AuthGuardProps = {\n /** default value is\n * ```ts\n * {\n * connectWallet: \"Please connect wallet before starting to trade\",\n * signIn: \"Please sign in before starting to trade\",\n * enableTrading: \"Please sign in before starting to trade\",\n * wrongNetwork: \"Please switch to a supported network to continue.\",\n * }\n * ```\n */\n hint?: {\n connectWallet?: string;\n signIn?: string;\n enableTrading?: string;\n wrongNetwork?: string;\n };\n status?: AccountStatusEnum;\n};\n\nconst AuthGuardEmpty = (props: PropsWithChildren<AuthGuardProps>) => {\n const {\n hint = {\n connectWallet: \"Please connect wallet before starting to trade\",\n signIn: \"Please sign in before starting to trade\",\n enableTrading: \"Please sign in before starting to trade\",\n wrongNetwork: \"Please switch to a supported network to continue.\",\n },\n status,\n } = props;\n\n return (\n <Box my={8}>\n <AuthGuard status={status} descriptions={{...hint, switchChain: hint.wrongNetwork}}>\n {props.children || <EmptyDataState />}\n </AuthGuard>\n </Box>\n );\n};\n\nAuthGuardEmpty.displayName = \"AuthGuardEmpty\";\n\nexport { AuthGuardEmpty };\n","import { useAccount } from \"@orderly.network/hooks\";\nimport { useAppContext } from \"@orderly.network/react-app\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\nimport { Tooltip } from \"@orderly.network/ui\";\nimport { PropsWithChildren, useMemo, useState } from \"react\";\n\ntype AuthGuardProps = {\n content?: string;\n align?: \"center\" | \"end\" | \"start\";\n alignOffset?: number;\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n sideOffset?: number;\n opactiy?: number;\n tooltip?: {\n connectWallet?: string;\n signIn?: string;\n enableTrading?: string;\n wrongNetwork?: string;\n };\n};\n\nconst AuthGuardTooltip = (props: PropsWithChildren<AuthGuardProps>) => {\n const {\n opactiy = 90,\n tooltip = {\n connectWallet: \"Please connect wallet before set up\",\n signIn: \"Please sign in before set up\",\n enableTrading: \"Please enable trading before set up\",\n wrongNetwork: \"Please switch to a supported network to set up\",\n },\n } = props;\n const [open, setOpen] = useState(false);\n const { state } = useAccount();\n const isSupport = true;\n const { wrongNetwork } = useAppContext();\n\n const hint = useMemo(() => {\n if (wrongNetwork) {\n return tooltip?.wrongNetwork;\n }\n switch (state.status) {\n case AccountStatusEnum.NotConnected:\n return tooltip?.connectWallet;\n case AccountStatusEnum.NotSignedIn:\n return tooltip?.signIn;\n case AccountStatusEnum.DisabledTrading:\n return tooltip?.enableTrading;\n case AccountStatusEnum.EnableTrading: {\n return \"\";\n }\n default:\n return props.content;\n }\n }, [props.content, state, isSupport, tooltip]);\n\n const newOpacity = useMemo(() => {\n switch (state.status) {\n case AccountStatusEnum.NotConnected:\n case AccountStatusEnum.NotSignedIn:\n return opactiy;\n case AccountStatusEnum.EnableTrading: {\n return undefined;\n }\n default:\n return undefined;\n }\n }, [props.opactiy, state, isSupport]);\n\n return (\n <Tooltip\n open={hint ? open : false}\n onOpenChange={setOpen}\n content={hint}\n className=\"oui-text-2xs\"\n align={props.align}\n alignOffset={props.alignOffset}\n side={props.side}\n sideOffset={props.sideOffset}\n >\n <div\n style={{\n opacity: newOpacity,\n }}\n >\n {props.children}\n </div>\n </Tooltip>\n );\n};\n\nAuthGuardTooltip.displayName = \"AuthGuardTooltip\";\n\nexport { AuthGuardTooltip };\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/component/walletConnectorContent.tsx","../src/component/step.tsx","../src/component/walletConnector.tsx","../src/component/useWalletConnectorBuilder.ts","../src/component/authGuard.tsx","../src/constants/message.ts","../src/component/authGuardDataTable.tsx","../src/component/authGuardEmpty.tsx","../src/component/authGuardTooltip.tsx"],"names":["useEffect","useMemo","useState","Box","Button","capitalizeFirstLetter","Divider","Flex","inputFormatter","Match","modal","Switch","Text","TextField","toast","Tooltip","AccountStatusEnum","CheckedCircleFillIcon","cn","Spinner","jsx","jsxs","StepItem","props","title","description","Identifier","active","isLoading","isCompleted","Dot","className","useAccount","useEventEmitter","useLocalStorage","WalletConnectContent","initAccountState","remember","setRemember","ee","accountState","account","state","setState","activeStep","setActiveStep","loading","setLoading","firstShowDialog","steps","onEnableTrading","res","step","reject","paseErrorMsg","e","onSignIn","index","ReferralCode","RememberMe","ActionButton","signIn","enableTrading","disabled","key","msg","registerSimpleDialog","registerSimpleSheet","useGetReferralCode","useLazyQuery","useMutation","useWalletConnectorBuilder","createOrderlyKey","createAccount","refCode","setRefCode","helpText","setHelpText","verifyRefCode","referral_code","bindRefCode","updateOrderError","updateMutating","enableTradingComplted","checkRefCode","exist","showRefCodeInput","info","WalletConnectorModalId","WalletConnectorSheetId","WalletConnectorWidget","useMediaQuery","MEDIA_TABLET","Either","useScreen","useAppContext","ChainSelectorDialogId","ChainSelectorSheetId","LABELS","DESCRIPTIONS","AuthGuard","status","buttonProps","fallback","descriptions","classNames","networkId","id","bridgeLessOnly","wrongNetwork","disabledConnect","_status","labels","Left","StatusInfo","DefaultFallback","connectWallet","isMobile","matches","onConnectOrderly","r","error","onConnectWallet","switchChain","value","ExtensionPositionEnum","ExtensionSlot","DataTable","useDataTap","AuthGuardDataTable","dataSource","rest","data","ignoreLoadingCheck","GuardView","EmptyDataState","AuthGuardEmpty","hint","AuthGuardTooltip","opactiy","tooltip","open","setOpen","isSupport","newOpacity"],"mappings":"AAAA,OAAa,aAAAA,EAAW,WAAAC,GAAS,YAAAC,MAAgB,QACjD,OACE,OAAAC,EACA,UAAAC,EACA,yBAAAC,GAEA,WAAAC,GACA,QAAAC,EAEA,kBAAAC,GACA,SAAAC,GACA,SAAAC,GACA,UAAAC,GACA,QAAAC,EACA,aAAAC,GACA,SAAAC,EACA,WAAAC,OACK,sBACP,OAAS,qBAAAC,MAAyB,yBCjBlC,OACE,OAAAb,EACA,yBAAAc,GACA,MAAAC,GACA,SAAAT,GACA,WAAAU,GACA,QAAAP,MACK,sBAiBD,OACE,OAAAQ,EADF,QAAAC,MAAA,oBAPC,IAAMC,EAAYC,GAAyB,CAChD,GAAM,CAAE,MAAAC,EAAO,YAAAC,CAAY,EAAIF,EAI/B,OACEF,EAAClB,EAAA,CAAI,SAAS,WAAW,UAAU,WACjC,UAAAkB,EAAClB,EAAA,CACC,UAAAiB,EAACR,EAAA,CAAK,GAAG,MAAM,UAAW,GAAI,KAAM,KACjC,SAAAY,EACH,EACAJ,EAACR,EAAA,CAAK,GAAG,MAAM,UAAW,GAAI,KAAM,MACjC,SAAAa,EACH,GACF,EACAL,EAACM,GAAA,CAAY,GAAGH,EAAO,GACzB,CAEJ,EAEMG,GAAcH,GAId,CACJ,GAAM,CAAE,OAAAI,EAAQ,UAAAC,EAAW,YAAAC,CAAY,EAAIN,EAE3C,OACEH,EAACX,GAAA,CACC,UAAW,6CACX,MAAO,IACDoB,EACK,YAELD,EACK,UAGLD,EACK,SAGF,SAET,KAAM,CACJ,QACEP,E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\"react\";\nimport {\n Box,\n Button,\n capitalizeFirstLetter,\n cn,\n Divider,\n Flex,\n Input,\n inputFormatter,\n Match,\n modal,\n Switch,\n Text,\n TextField,\n toast,\n Tooltip,\n} from \"@orderly.network/ui\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\nimport { StepItem } from \"./step\";\nimport { useAccount, useEventEmitter, useLocalStorage } from \"@orderly.network/hooks\";\n\nexport type WalletConnectContentProps = {\n initAccountState: AccountStatusEnum;\n signIn: () => Promise<any>;\n enableTrading: (remember: boolean) => Promise<any>;\n enableTradingComplted?: () => Promise<void>;\n onCompleted?: () => void;\n close?: () => void;\n refCode: string;\n setRefCode: React.Dispatch<React.SetStateAction<string>>;\n helpText?: string;\n showRefCodeInput: boolean;\n};\n\nexport const WalletConnectContent = (props: WalletConnectContentProps) => {\n const { initAccountState = AccountStatusEnum.NotConnected } = props;\n const [remember, setRemember] = useState(true);\n const ee = useEventEmitter();\n\n\n const { state: accountState, account } = useAccount();\n const [state, setState] = useState(initAccountState);\n const [activeStep, setActiveStep] = useState(0);\n const [loading, setLoading] = useState(false);\n const [firstShowDialog] = useLocalStorage(\n \"orderly-first-show-wallet-connector-dialog\",\n undefined\n );\n useEffect(() => {\n return () => {\n localStorage.setItem(\"orderly-first-show-wallet-connector-dialog\", \"1\");\n };\n }, []);\n\n useEffect(() => {\n setState(accountState.status);\n }, [accountState]);\n\n const steps = useMemo(() => {\n const steps = [];\n if (initAccountState < AccountStatusEnum.SignedIn) {\n steps.push({\n key: \"signIn\",\n title: \"Sign In\",\n description: \"Confirm you are the owner of this wallet\",\n });\n }\n\n if (initAccountState < AccountStatusEnum.EnableTrading) {\n steps.push({\n key: \"enableTrading\",\n title: \"Enable Trading\",\n description:\n \"Enable secure access to our API for lightning fast trading\",\n });\n }\n\n return steps;\n }, [initAccountState]);\n\n const onEnableTrading = () => {\n setLoading(true);\n return props\n .enableTrading(remember)\n .then(\n async (res) => {\n console.log(res);\n setLoading(false);\n setActiveStep((step) => step + 1);\n try {\n await props.enableTradingComplted?.();\n } catch (e) {}\n if (typeof props.onCompleted === \"function\") {\n props.onCompleted();\n } else if (typeof props.close === \"function\") {\n props.close();\n }\n // props.onCompleted?.();\n },\n (reject) => {\n setLoading(false);\n if (reject === -1) return;\n\n if (reject.message.indexOf('Signing off chain messages with Ledger is not yet supported') !== -1) {\n ee.emit(\"wallet:sign-message-with-ledger-error\", {message: reject.message,userAddress: account.address});\n return;\n }\n toast.error(paseErrorMsg(reject));\n }\n )\n .catch((e) => {\n console.log(\"enable trading catch error\", e);\n setLoading(false);\n });\n };\n\n const onSignIn = () => {\n setLoading(true);\n return props\n .signIn()\n .then(\n (res) => {\n setActiveStep((step) => step + 1);\n onEnableTrading();\n },\n (reject) => {\n setLoading(false);\n\n if (reject === -1) return;\n if (reject.message.indexOf('Signing off chain messages with Ledger is not yet supported') !== -1) {\n ee.emit(\"wallet:sign-message-with-ledger-error\", {message: reject.message,userAddress: account.address});\n return;\n }\n\n toast.error(paseErrorMsg(reject));\n }\n )\n .catch((e) => {\n setLoading(false);\n });\n };\n\n console.log(\"state\", state);\n\n return (\n <Box id=\"oui-wallet-connect-dialog-content\" className=\"oui-font-semibold\">\n <Text intensity={54} size=\"xs\">\n Your previous access has expired, you will receive a signature request\n to enable trading. Signing is free and will not send a transaction.\n </Text>\n <Box\n p={4}\n my={6}\n intensity={600}\n r=\"lg\"\n className=\"oui-space-y-5\"\n position={\"relative\"}\n >\n {steps.map((step, index) => {\n return (\n <StepItem\n title={step.title}\n description={step.description}\n isCompleted={activeStep > index}\n key={step.key}\n active={activeStep === index}\n isLoading={loading && activeStep === index}\n />\n );\n })}\n {steps.length > 1 && (\n <Box\n position={\"absolute\"}\n height={\"38px\"}\n left={28}\n top={18}\n zIndex={0}\n >\n <Divider\n lineStyle={\"dashed\"}\n direction={\"vertical\"}\n intensity={16}\n className=\"oui-h-full\"\n />\n </Box>\n )}\n </Box>\n {props.showRefCodeInput && steps.length == 2 && (\n <ReferralCode {...props} />\n )}\n {firstShowDialog && (\n <Flex justify={\"between\"} itemAlign={\"center\"}>\n <RememberMe />\n <Switch\n color={\"primary\"}\n checked={remember}\n onCheckedChange={setRemember}\n disabled={loading}\n className=\"data-[state=checked]:oui-bg-primary-darken\"\n />\n </Flex>\n )}\n <Flex justify={\"center\"} mt={8}>\n <Box width={\"45%\"}>\n <ActionButton\n state={state}\n signIn={onSignIn}\n enableTrading={onEnableTrading}\n loading={loading}\n disabled={state >= AccountStatusEnum.EnableTrading}\n />\n </Box>\n </Flex>\n </Box>\n );\n};\n\nconst ActionButton: FC<{\n state: AccountStatusEnum;\n signIn: () => Promise<any>;\n enableTrading: () => Promise<any>;\n loading: boolean;\n disabled?: boolean;\n}> = ({ state, signIn, enableTrading, loading, disabled }) => {\n return (\n <Match\n value={() => {\n if (state <= AccountStatusEnum.NotSignedIn) {\n return \"signIn\";\n }\n return \"enableTrading\";\n }}\n case={{\n signIn: (\n <Button\n fullWidth\n onClick={() => signIn()}\n loading={loading}\n disabled={disabled}\n >\n Sign In\n </Button>\n ),\n enableTrading: (\n <Button\n fullWidth\n onClick={() => enableTrading()}\n loading={loading}\n disabled={disabled}\n >\n Enable Trading\n </Button>\n ),\n }}\n />\n );\n};\n\nconst ReferralCode: FC<WalletConnectContentProps> = (props) => {\n return (\n <TextField\n placeholder=\"Referral code (Optional)\"\n fullWidth\n // label={\"Referral code (optional)\"}\n label=\"\"\n value={props.refCode}\n onChange={(e) => {\n props.setRefCode(e.target.value);\n }}\n classNames={{\n label: \"oui-text-base-contrast-54 oui-text-xs\",\n input: \"placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm\",\n }}\n formatters={[inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)]}\n onClear={() => {\n props.setRefCode(\"\");\n }}\n autoComplete=\"off\"\n helpText={props.helpText}\n className=\"oui-mb-4\"\n color={props.helpText ? \"danger\" : undefined}\n />\n );\n};\n\nconst RememberMe = () => {\n const showRememberHint = () => {\n if (window.innerWidth > 768) return;\n modal.alert({\n title: \"Remember me\",\n message: (\n <span className=\"oui-text-2xs oui-text-base-contrast/60\">\n Toggle this option to skip these steps next time you want to trade.\n </span>\n ),\n });\n };\n return (\n <Tooltip\n content={\n \"Toggle this option to skip these steps next time you want to trade.\"\n }\n className=\"oui-max-w-[300px]\"\n >\n <button onClick={showRememberHint}>\n <Text\n intensity={54}\n size={\"xs\"}\n className={\n \"oui-underline oui-underline-offset-4 oui-decoration-dashed oui-decoration-base-contrast-36\"\n }\n >\n Remember me\n </Text>\n </button>\n </Tooltip>\n );\n};\n\nfunction paseErrorMsg(reject: any): string {\n console.log(\"wallet callback error\", reject);\n console.log(\"message *** \", \"reject keys\", Object.keys(reject));\n Object.keys(reject).forEach((key) => {\n console.log(\"key\", key, \"-\", reject[key]);\n });\n let msg = \"Something went wrong\";\n\n // if (typeof reject?.info?.error === \"object\" && \"message\" in reject?.info?.error) {\n // msg = reject?.info?.error?.message;\n // }\n\n // if (typeof reject?.shortMessage === 'string') {\n // msg = reject.shortMessage;\n // }\n\n if (reject.toString().includes(\"rejected\")) {\n msg = \"User rejected the request.\";\n }\n\n\n return capitalizeFirstLetter(msg) ?? msg;\n}\n\n","import { FC } from \"react\";\nimport {\n Box,\n CheckedCircleFillIcon,\n cn,\n Match,\n Spinner,\n Text,\n} from \"@orderly.network/ui\";\n\ntype StepItemProps = {\n active?: boolean;\n isLoading?: boolean;\n isCompleted?: boolean;\n title: string;\n description: string;\n};\n\nexport const StepItem = (props: StepItemProps) => {\n const { title, description } = props;\n\n // console.log(props);\n\n return (\n <Box position=\"relative\" className=\"oui-pl-8\">\n <Box>\n <Text as=\"div\" intensity={98} size={\"sm\"}>\n {title}\n </Text>\n <Text as=\"div\" intensity={54} size={\"2xs\"}>\n {description}\n </Text>\n </Box>\n <Identifier {...props} />\n </Box>\n );\n};\n\nconst Identifier = (props: {\n active?: boolean;\n isLoading?: boolean;\n isCompleted?: boolean;\n}) => {\n const { active, isLoading, isCompleted } = props;\n\n return (\n <Match\n className={\"oui-absolute oui-left-0 oui-top-1 oui-z-10\"}\n value={() => {\n if (isCompleted) {\n return \"completed\";\n }\n if (isLoading) {\n return \"loading\";\n }\n\n if (active) {\n return \"active\";\n }\n\n return \"normal\";\n }}\n case={{\n loading: (\n <div>\n <Spinner size={\"sm\"} className={\"oui-ml-1\"} />\n </div>\n ),\n completed: (\n <div>\n <CheckedCircleFillIcon opacity={1} className=\"oui-text-primary\" />\n </div>\n ),\n }}\n default={<Dot active={!!active} />}\n />\n );\n};\n\nconst Dot: FC<{ active: boolean; className?: string }> = ({\n active,\n className,\n}) => {\n return (\n <div\n className={cn(\n \"oui-w-[8.3px] oui-h-[8.3px] oui-rounded-full oui-ml-2 oui-mt-1\",\n className,\n active ? \"oui-bg-primary-light\" : \"oui-bg-base-2\"\n )}\n />\n );\n};\n","import { registerSimpleDialog, registerSimpleSheet } from \"@orderly.network/ui\";\n\nimport { useWalletConnectorBuilder } from \"./useWalletConnectorBuilder\";\nimport { WalletConnectContent } from \"./walletConnectorContent\";\n\nexport const WalletConnectorModalId = \"walletConnector\" as const;\nexport const WalletConnectorSheetId = \"walletConnectorSheet\" as const;\n\nexport const WalletConnectorWidget = (props: any) => {\n const state = useWalletConnectorBuilder();\n return <WalletConnectContent {...state} {...props} />;\n};\n\nregisterSimpleDialog(WalletConnectorModalId, WalletConnectorWidget, {\n size: \"sm\",\n title: \"Connect wallet\",\n});\n\nregisterSimpleSheet(WalletConnectorSheetId, WalletConnectorWidget, {\n title: \"Connect wallet\",\n});\n","import {\n useAccount,\n useCheckReferralCode,\n useGetReferralCode,\n useLazyQuery,\n useMutation,\n} from \"@orderly.network/hooks\";\nimport { toast } from \"@orderly.network/ui\";\nimport { useEffect, useMemo, useState } from \"react\";\n\n\nexport const useWalletConnectorBuilder = () => {\n const { account, state, createOrderlyKey, createAccount } = useAccount();\n const [refCode, setRefCode] = useState(\"\");\n const [helpText, setHelpText] = useState(\"\");\n\n const { trigger: verifyRefCode } = useLazyQuery(\n `/v1/public/referral/verify_ref_code?referral_code=${refCode}`\n );\n\n useEffect(() => {\n const refCode = localStorage.getItem(\"referral_code\");\n if (refCode != null) {\n setRefCode(refCode);\n }\n }, []);\n\n const { referral_code, isLoading } = useGetReferralCode(account.accountId);\n\n const [bindRefCode, { error: updateOrderError, isMutating: updateMutating }] =\n useMutation(\"/v1/referral/bind\", \"POST\");\n\n useEffect(() => {\n if (refCode.length === 0) {\n setHelpText(\"\");\n }\n }, [refCode]);\n\n const enableTradingComplted = () => {\n toast.success(\"Wallet connected\");\n // validate ref code and bind referral code\n if (refCode.length >= 4 && refCode.length <= 10)\n bindRefCode({ referral_code: refCode }).finally(() => {\n localStorage.removeItem(\"referral_code\");\n });\n };\n\n const checkRefCode = async (): Promise<string | undefined> => {\n if (refCode.length === 0) return Promise.resolve(undefined);\n\n if (refCode.length > 0 && (refCode.length < 4 || refCode.length > 10)) {\n return Promise.resolve(\n \"The referral_code must be 4 to 10 characters long, only accept upper case roman characters and numbers\"\n );\n }\n\n const { exist } = await verifyRefCode();\n \n\n if (exist === false) {\n return Promise.resolve(\"This referral code does not exist.\");\n }\n\n return Promise.resolve(undefined);\n };\n\n\n const showRefCodeInput = (referral_code?.length || 0) === 0 && !isLoading;\n\n\n const signIn = async () => {\n if (showRefCodeInput) {\n const info = await checkRefCode();\n if (typeof info !== \"undefined\") {\n setHelpText(info);\n return Promise.reject(-1);\n }\n }\n setHelpText(\"\");\n return createAccount();\n };\n\n const enableTrading = async (remember: boolean) => {\n if (showRefCodeInput) {\n const info = await checkRefCode();\n if (typeof info !== \"undefined\") {\n setHelpText(info);\n return Promise.reject(-1);\n }\n }\n setHelpText(\"\");\n return createOrderlyKey(remember);\n };\n\n return {\n enableTrading,\n initAccountState: state.status,\n signIn,\n enableTradingComplted,\n refCode,\n setRefCode,\n helpText,\n showRefCodeInput,\n } as const;\n};\n","import { useAccount, useMediaQuery } from \"@orderly.network/hooks\";\nimport {\n AccountStatusEnum,\n MEDIA_TABLET,\n NetworkId,\n} from \"@orderly.network/types\";\nimport {\n Button,\n Either,\n Match,\n modal,\n Text,\n toast,\n useScreen,\n type ButtonProps,\n} from \"@orderly.network/ui\";\nimport { useAppContext } from \"@orderly.network/react-app\";\nimport { PropsWithChildren, ReactElement, useMemo } from \"react\";\nimport {\n WalletConnectorModalId,\n WalletConnectorSheetId,\n} from \"./walletConnector\";\nimport {\n ChainSelectorDialogId,\n ChainSelectorSheetId,\n} from \"@orderly.network/ui-chain-selector\";\nimport { alertMessages, DESCRIPTIONS, LABELS } from \"../constants/message\";\nimport { Flex } from \"@orderly.network/ui\";\nimport { Box } from \"@orderly.network/ui\";\n\ntype ChainProps = {\n networkId?: NetworkId;\n bridgeLessOnly?: boolean;\n};\n\nexport type AuthGuardProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {\n fallback?: (props: {\n validating: boolean;\n status: AccountStatusEnum;\n wrongNetwork: boolean;\n }) => ReactElement;\n // indicator?: ReactElement;\n /**\n * Required state to be satisfied\n * @default AccountStatusEnum.EnableTrading\n */\n status?: AccountStatusEnum;\n\n bridgeLessOnly?: boolean;\n\n buttonProps?: ButtonProps;\n\n descriptions?: alertMessages;\n\n labels?: alertMessages;\n\n classNames?: {\n root?: string;\n description?: string;\n // button?: string;\n };\n\n networkId?: NetworkId;\n\n // validatingIndicator?: ReactElement;\n};\n\nconst AuthGuard = (props: PropsWithChildren<AuthGuardProps>) => {\n const {\n status,\n buttonProps,\n fallback,\n descriptions,\n classNames,\n networkId,\n id,\n bridgeLessOnly,\n // ...rest\n } = props;\n const { state } = useAccount();\n const { wrongNetwork, disabledConnect } = useAppContext();\n\n const _status = useMemo(() => {\n if (status === undefined) {\n return state.status === AccountStatusEnum.EnableTradingWithoutConnected\n ? AccountStatusEnum.EnableTradingWithoutConnected\n : AccountStatusEnum.EnableTrading;\n }\n return status;\n }, [status, state.status]);\n\n const labels = { ...LABELS, ...props.labels };\n\n // return Match(state.status)\n // .with(AccountStatusEnum.EnableTrading, () => props.children)\n // .with(AccountStatusEnum.DisableTrading, () => props.fallback)\n // .with(AccountStatusEnum.Validating, () => props.validatingIndicator)\n // .otherwise(() => props.fallback);\n //\n\n const Left = useMemo<ReactElement>(() => {\n if (typeof fallback !== \"undefined\") {\n return fallback({\n validating: state.validating,\n status: state.status,\n wrongNetwork,\n });\n }\n\n if (state.validating && !disabledConnect) {\n return (\n <StatusInfo\n // variant={\"gradient\"}\n angle={45}\n // fullWidth\n disabled\n loading\n description={descriptions?.connectWallet}\n id={id}\n type=\"button\"\n {...buttonProps}\n >\n {labels.connectWallet}\n </StatusInfo>\n );\n }\n\n return (\n <DefaultFallback\n bridgeLessOnly={bridgeLessOnly}\n status={state.status}\n buttonProps={{ ...buttonProps, id, type: \"button\" }}\n wrongNetwork={wrongNetwork}\n networkId={props.networkId}\n labels={labels}\n descriptions={descriptions}\n disabledConnect={disabledConnect}\n />\n );\n }, [state.status, state.validating, buttonProps, wrongNetwork]);\n\n /**\n * **Important: The chldren component will be rendered only if the status is equal to the required status and the network is correct.**\n */\n\n return (\n <Either\n value={state.status >= _status && !wrongNetwork && !disabledConnect}\n left={Left}\n >\n {props.children}\n </Either>\n );\n};\n\nconst DefaultFallback = (props: {\n status: AccountStatusEnum;\n wrongNetwork: boolean;\n buttonProps?: ButtonProps;\n networkId?: NetworkId;\n labels: alertMessages;\n bridgeLessOnly?: boolean;\n descriptions?: alertMessages;\n disabledConnect?: boolean;\n}) => {\n const { buttonProps, labels, descriptions } = props;\n const { connectWallet } = useAppContext();\n const { account } = useAccount();\n const { isMobile } = useScreen();\n const matches = useMediaQuery(MEDIA_TABLET);\n const onConnectOrderly = () => {\n modal.show(matches ? WalletConnectorSheetId : WalletConnectorModalId).then(\n (r) => console.log(r),\n (error) => console.log(error)\n );\n };\n\n const onConnectWallet = async () => {\n const res = await connectWallet();\n\n if (!res) return;\n\n if (res.wrongNetwork) {\n switchChain();\n } else {\n if (\n (res?.status ?? AccountStatusEnum.NotConnected) <\n AccountStatusEnum.EnableTrading\n ) {\n onConnectOrderly();\n }\n }\n };\n\n const switchChain = () => {\n account.once(\"validate:end\", (status) => {\n if (status < AccountStatusEnum.EnableTrading) {\n onConnectOrderly();\n } else {\n toast.success(\"Wallet connected\");\n }\n });\n\n modal\n .show<{\n wrongNetwork: boolean;\n }>(isMobile ? ChainSelectorSheetId : ChainSelectorDialogId, {\n networkId: props.networkId,\n bridgeLessOnly: props.bridgeLessOnly,\n })\n .then(\n (r) => {\n if (!r.wrongNetwork) {\n if (props.status >= AccountStatusEnum.Connected) {\n if (props.status < AccountStatusEnum.EnableTrading) {\n onConnectOrderly();\n } else {\n toast.success(\"Wallet connected\");\n }\n }\n }\n },\n (error) => console.log(\"[switchChain error]\", error)\n );\n };\n\n if (props.wrongNetwork && !props.disabledConnect) {\n return (\n <StatusInfo\n color=\"warning\"\n // size=\"md\"\n // fullWidth\n onClick={() => {\n switchChain();\n }}\n description={descriptions?.switchChain}\n {...buttonProps}\n >\n {labels.switchChain}\n </StatusInfo>\n );\n }\n\n return (\n <Match\n value={props.status}\n case={(value: AccountStatusEnum) => {\n if (value <= AccountStatusEnum.NotConnected || props.disabledConnect) {\n return (\n <StatusInfo\n size=\"lg\"\n onClick={() => {\n onConnectWallet();\n }}\n // fullWidth\n variant={props.disabledConnect ? undefined : \"gradient\"}\n angle={45}\n description={descriptions?.connectWallet}\n disabled={props.disabledConnect}\n {...buttonProps}\n >\n {labels.connectWallet}\n </StatusInfo>\n );\n }\n if (value <= AccountStatusEnum.NotSignedIn) {\n return (\n <StatusInfo\n size=\"lg\"\n onClick={() => {\n onConnectOrderly();\n }}\n // fullWidth\n angle={45}\n description={descriptions?.signin}\n {...buttonProps}\n >\n {labels.signin}\n </StatusInfo>\n );\n }\n }}\n default={\n <StatusInfo\n size=\"lg\"\n // fullWidth\n description={descriptions?.enableTrading}\n {...buttonProps}\n onClick={() => onConnectOrderly()}\n >\n {labels.enableTrading}\n </StatusInfo>\n }\n />\n );\n};\n\nAuthGuard.displayName = \"AuthGuard\";\n\nconst StatusInfo = (\n props: ButtonProps & {\n description?: string;\n }\n) => {\n const { description, ...buttonProps } = props;\n return (\n <Flex direction={\"column\"}>\n <Button {...buttonProps}></Button>\n {!!description && (\n <Box mt={4} className=\"oui-leading-none\" style={{ lineHeight: 0 }}>\n <Text size=\"2xs\" intensity={36}>\n {description}\n </Text>\n </Box>\n )}\n </Flex>\n );\n};\n\nexport { AuthGuard };\n","export type alertMessages = {\n connectWallet?: string;\n switchChain?: string;\n enableTrading?: string;\n signin?: string;\n};\n\nexport const LABELS = {\n connectWallet: \"Connect wallet\",\n switchChain: \"Wrong network\",\n enableTrading: \"Enable trading\",\n signin: \"Sign in\",\n};\n\nexport const DESCRIPTIONS: alertMessages = {\n connectWallet: \"Please Connect wallet before starting to trade\",\n switchChain: \"Please switch to a supported network to continue\",\n enableTrading: \"Please Enable trading before starting to trade\",\n signin: \"Please sign in before starting to trade\",\n};\n","import { PropsWithChildren, useMemo } from \"react\";\nimport {\n ExtensionPositionEnum,\n ExtensionSlot,\n DataTable,\n DataTableProps,\n} from \"@orderly.network/ui\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\nimport { alertMessages, DESCRIPTIONS } from \"../constants/message\";\nimport { useAppContext, useDataTap } from \"@orderly.network/react-app\";\nimport { Flex } from \"@orderly.network/ui\";\nimport { AuthGuard } from \"./authGuard\";\nimport { useAccount } from \"@orderly.network/hooks\";\n\nexport const AuthGuardDataTable = <RecordType extends unknown>(\n props: PropsWithChildren<\n DataTableProps<RecordType> &\n Omit<GuardViewProps, \"status\"> & {\n status?: AccountStatusEnum;\n classNames?: DataTableProps<RecordType>[\"classNames\"] & {\n authGuardDescription?: string;\n };\n }\n >\n) => {\n const {\n status,\n // message,\n labels,\n description,\n dataSource,\n ...rest\n } = props;\n const { state } = useAccount();\n const { wrongNetwork, disabledConnect } = useAppContext();\n\n const _status = useMemo(() => {\n if (status === undefined) {\n return state.status === AccountStatusEnum.EnableTradingWithoutConnected\n ? AccountStatusEnum.EnableTradingWithoutConnected\n : AccountStatusEnum.EnableTrading;\n }\n return status;\n }, [status, state.status]);\n\n const data = useDataTap(dataSource, {\n accountStatus: _status,\n });\n\n const ignoreLoadingCheck =\n wrongNetwork ||\n disabledConnect ||\n state.status < _status ||\n props.ignoreLoadingCheck;\n\n return (\n <DataTable\n dataSource={data}\n ignoreLoadingCheck={ignoreLoadingCheck}\n emptyView={\n <GuardView\n status={_status}\n description={description}\n labels={labels}\n className={props.classNames?.authGuardDescription}\n visible={!state.validating}\n />\n }\n manualPagination\n {...rest}\n />\n );\n};\n\ntype GuardViewProps = {\n status: AccountStatusEnum;\n description?: alertMessages;\n labels?: alertMessages;\n className?: string;\n visible?: boolean;\n};\n\nconst GuardView = (props: GuardViewProps) => {\n const descriptions = { ...DESCRIPTIONS, ...props.description };\n if (!props.visible) return null;\n return (\n <Flex py={8}>\n <AuthGuard\n status={props.status}\n labels={props.labels}\n descriptions={descriptions}\n buttonProps={{\n size: \"md\",\n }}\n >\n <ExtensionSlot position={ExtensionPositionEnum.EmptyDataIdentifier} />\n </AuthGuard>\n </Flex>\n );\n};\n","import { AccountStatusEnum } from \"@orderly.network/types\";\nimport {\n Box,\n EmptyDataState,\n} from \"@orderly.network/ui\";\nimport { PropsWithChildren } from \"react\";\nimport { AuthGuard } from \"./authGuard\";\n\ntype AuthGuardProps = {\n /** default value is\n * ```ts\n * {\n * connectWallet: \"Please connect wallet before starting to trade\",\n * signIn: \"Please sign in before starting to trade\",\n * enableTrading: \"Please sign in before starting to trade\",\n * wrongNetwork: \"Please switch to a supported network to continue.\",\n * }\n * ```\n */\n hint?: {\n connectWallet?: string;\n signIn?: string;\n enableTrading?: string;\n wrongNetwork?: string;\n };\n status?: AccountStatusEnum;\n};\n\nconst AuthGuardEmpty = (props: PropsWithChildren<AuthGuardProps>) => {\n const {\n hint = {\n connectWallet: \"Please connect wallet before starting to trade\",\n signIn: \"Please sign in before starting to trade\",\n enableTrading: \"Please sign in before starting to trade\",\n wrongNetwork: \"Please switch to a supported network to continue.\",\n },\n status,\n } = props;\n\n return (\n <Box my={8}>\n <AuthGuard status={status} descriptions={{...hint, switchChain: hint.wrongNetwork}}>\n {props.children || <EmptyDataState />}\n </AuthGuard>\n </Box>\n );\n};\n\nAuthGuardEmpty.displayName = \"AuthGuardEmpty\";\n\nexport { AuthGuardEmpty };\n","import { useAccount } from \"@orderly.network/hooks\";\nimport { useAppContext } from \"@orderly.network/react-app\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\nimport { Tooltip } from \"@orderly.network/ui\";\nimport { PropsWithChildren, useMemo, useState } from \"react\";\n\ntype AuthGuardProps = {\n content?: string;\n align?: \"center\" | \"end\" | \"start\";\n alignOffset?: number;\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n sideOffset?: number;\n opactiy?: number;\n tooltip?: {\n connectWallet?: string;\n signIn?: string;\n enableTrading?: string;\n wrongNetwork?: string;\n };\n};\n\nconst AuthGuardTooltip = (props: PropsWithChildren<AuthGuardProps>) => {\n const {\n opactiy = 90,\n tooltip = {\n connectWallet: \"Please connect wallet before set up\",\n signIn: \"Please sign in before set up\",\n enableTrading: \"Please enable trading before set up\",\n wrongNetwork: \"Please switch to a supported network to set up\",\n },\n } = props;\n const [open, setOpen] = useState(false);\n const { state } = useAccount();\n const isSupport = true;\n const { wrongNetwork } = useAppContext();\n\n const hint = useMemo(() => {\n if (wrongNetwork) {\n return tooltip?.wrongNetwork;\n }\n switch (state.status) {\n case AccountStatusEnum.NotConnected:\n return tooltip?.connectWallet;\n case AccountStatusEnum.NotSignedIn:\n return tooltip?.signIn;\n case AccountStatusEnum.DisabledTrading:\n return tooltip?.enableTrading;\n case AccountStatusEnum.EnableTrading: {\n return \"\";\n }\n default:\n return props.content;\n }\n }, [props.content, state, isSupport, tooltip]);\n\n const newOpacity = useMemo(() => {\n switch (state.status) {\n case AccountStatusEnum.NotConnected:\n case AccountStatusEnum.NotSignedIn:\n return opactiy;\n case AccountStatusEnum.EnableTrading: {\n return undefined;\n }\n default:\n return undefined;\n }\n }, [props.opactiy, state, isSupport]);\n\n return (\n <Tooltip\n open={hint ? open : false}\n onOpenChange={setOpen}\n content={hint}\n className=\"oui-text-2xs\"\n align={props.align}\n alignOffset={props.alignOffset}\n side={props.side}\n sideOffset={props.sideOffset}\n >\n <div\n style={{\n opacity: newOpacity,\n }}\n >\n {props.children}\n </div>\n </Tooltip>\n );\n};\n\nAuthGuardTooltip.displayName = \"AuthGuardTooltip\";\n\nexport { AuthGuardTooltip };\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -6,8 +6,8 @@ import { useAccount, useLazyQuery, useGetReferralCode, useMutation, useEventEmit
|
|
|
6
6
|
import { useAppContext, useDataTap } from '@orderly.network/react-app';
|
|
7
7
|
import { ChainSelectorSheetId, ChainSelectorDialogId } from '@orderly.network/ui-chain-selector';
|
|
8
8
|
|
|
9
|
-
var V=e=>{let{title:t,description:n}=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(me,{...e})]})},me=e=>{let{active:t,isLoading:n,isCompleted:i}=e;return jsx(Match,{className:"oui-absolute oui-left-0 oui-top-1 oui-z-10",value:()=>i?"completed":n?"loading":t?"active":"normal",case:{loading:jsx("div",{children:jsx(Spinner,{size:"sm",className:"oui-ml-1"})}),completed:jsx("div",{children:jsx(CheckedCircleFillIcon,{opacity:1,className:"oui-text-primary"})})},default:jsx(fe,{active:!!t})})},fe=({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 B=e=>{let{initAccountState:t=AccountStatusEnum.NotConnected}=e,[n,i]=useState(true),o=useEventEmitter(),{state:d,account:g}=useAccount(),[l,u]=useState(t),[s,m]=useState(0),[a,f]=useState(false),[A]=useLocalStorage("orderly-first-show-wallet-connector-dialog",void 0);useEffect(()=>()=>{localStorage.setItem("orderly-first-show-wallet-connector-dialog","1");},[]),useEffect(()=>{u(d.status);},[d]);let T=useMemo(()=>{let r=[];return t<AccountStatusEnum.SignedIn&&r.push({key:"signIn",title:"Sign In",description:"Confirm you are the owner of this wallet"}),t<AccountStatusEnum.EnableTrading&&r.push({key:"enableTrading",title:"Enable Trading",description:"Enable secure access to our API for lightning fast trading"}),r},[t]),x=()=>(f(true),e.enableTrading(n).then(async r=>{f(false),m(C=>C+1);try{await e.enableTradingComplted?.();}catch{}typeof e.onCompleted=="function"?e.onCompleted():typeof e.close=="function"&&e.close();},r=>{if(f(false),r!==-1){if(r.message.indexOf("Signing off chain messages with Ledger is not yet supported")!==-1){o.emit("wallet:sign-message-with-ledger-error",{message:r.message,userAddress:g.address});return}toast.error(Y(r));}}).catch(r=>{f(false);})),I=()=>(f(true),e.signIn().then(r=>{m(C=>C+1),x();},r=>{if(f(false),r!==-1){if(r.message.indexOf("Signing off chain messages with Ledger is not yet supported")!==-1){o.emit("wallet:sign-message-with-ledger-error",{message:r.message,userAddress:g.address});return}toast.error(Y(r));}}).catch(r=>{f(false);}));return jsxs(Box,{id:"oui-wallet-connect-dialog-content",className:"oui-font-semibold",children:[jsx(Text,{intensity:54,size:"xs",children:"Your previous access has expired, you will receive a signature request to enable trading. Signing is free and will not send a transaction."}),jsxs(Box,{p:4,my:6,intensity:600,r:"lg",className:"oui-space-y-5",position:"relative",children:[T.map((r,C)=>jsx(V,{title:r.title,description:r.description,isCompleted:s>C,active:s===C,isLoading:a&&s===C},r.key)),T.length>1&&jsx(Box,{position:"absolute",height:"38px",left:28,top:18,zIndex:0,children:jsx(Divider,{lineStyle:"dashed",direction:"vertical",intensity:16,className:"oui-h-full"})})]}),e.showRefCodeInput&&T.length==2&&jsx(Ae,{...e}),A&&jsxs(Flex,{justify:"between",itemAlign:"center",children:[jsx(Ne,{}),jsx(Switch,{color:"primary",checked:n,onCheckedChange:i,disabled:a,className:"data-[state=checked]:oui-bg-primary-darken"})]}),jsx(Flex,{justify:"center",mt:8,children:jsx(Box,{width:"45%",children:jsx(Ee,{state:l,signIn:I,enableTrading:x,loading:a,disabled:l>=AccountStatusEnum.EnableTrading})})})]})},Ee=({state:e,signIn:t,enableTrading:n,loading:i,disabled:o})=>jsx(Match,{value:()=>e<=AccountStatusEnum.NotSignedIn?"signIn":"enableTrading",case:{signIn:jsx(Button,{fullWidth:true,onClick:()=>t(),loading:i,disabled:o,children:"Sign In"}),enableTrading:jsx(Button,{fullWidth:true,onClick:()=>n(),loading:i,disabled:o,children:"Enable Trading"})}}),Ae=e=>jsx(TextField,{placeholder:"Referral code (Optional)",fullWidth:true,label:"",value:e.refCode,onChange:t=>{e.setRefCode(t.target.value);},classNames:{label:"oui-text-base-contrast-54 oui-text-xs",input:"placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm"},formatters:[inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)],onClear:()=>{e.setRefCode("");},autoComplete:"off",helpText:e.helpText,className:"oui-mb-4",color:e.helpText?"danger":void 0}),Ne=()=>jsx(Tooltip,{content:"Toggle this option to skip these steps next time you want to trade.",className:"oui-max-w-[300px]",children:jsx("button",{onClick:()=>{window.innerWidth>768||modal.alert({title:"Remember me",message:jsx("span",{className:"oui-text-2xs oui-text-base-contrast/60",children:"Toggle this option to skip these steps next time you want to trade."})});},children:jsx(Text,{intensity:54,size:"xs",className:"oui-underline oui-underline-offset-4 oui-decoration-dashed oui-decoration-base-contrast-36",children:"Remember me"})})});function Y(e){Object.keys(e).forEach(n=>{});let t="Something went wrong";return e.toString().includes("rejected")&&(t="User rejected the request."),capitalizeFirstLetter(t)??t}var O=()=>{let{account:e,state:t,createOrderlyKey:n,createAccount:i}=useAccount(),[o,d]=useState(""),[g,l]=useState(""),{trigger:u}=useLazyQuery(`/v1/public/referral/verify_ref_code?referral_code=${o}`);useEffect(()=>{let w=localStorage.getItem("referral_code");w!=null&&d(w);},[]);let{referral_code:s,isLoading:m}=useGetReferralCode(e.accountId),[a,{error:f,isMutating:A}]=useMutation("/v1/referral/bind","POST");useEffect(()=>{o.length===0&&l("");},[o]);let T=()=>{toast.success("Wallet connected"),o.length>=4&&o.length<=10&&a({referral_code:o}).finally(()=>{localStorage.removeItem("referral_code");});},x=async()=>{if(o.length===0)return Promise.resolve(void 0);if(o.length>0&&(o.length<4||o.length>10))return Promise.resolve("The referral_code must be 4 to 10 characters long, only accept upper case roman characters and numbers");let{exist:w}=await u();return w===false?Promise.resolve("This referral code does not exist."):Promise.resolve(void 0)},I=(s?.length||0)===0&&!m,r=async()=>{if(I){let w=await x();if(typeof w<"u")return l(w),Promise.reject(-1)}return l(""),i()};return {enableTrading:async w=>{if(I){let F=await x();if(typeof F<"u")return l(F),Promise.reject(-1)}return l(""),n(w)},initAccountState:t.status,signIn:r,enableTradingComplted:T,refCode:o,setRefCode:d,helpText:g,showRefCodeInput:I}};var v="walletConnector",R="walletConnectorSheet",G=e=>{let t=O();return jsx(B,{...t,...e})};registerSimpleDialog(v,G,{size:"sm",title:"Connect wallet"});registerSimpleSheet(R,G,{title:"Connect wallet"});var X={connectWallet:"Connect wallet",switchChain:"Wrong network",enableTrading:"Enable trading",signin:"Sign in"},j={connectWallet:"Please Connect wallet before starting to trade",switchChain:"Please switch to a supported network to continue",enableTrading:"Please Enable trading before starting to trade",signin:"Please sign in before starting to trade"};var S=e=>{let{status:t,buttonProps:n,fallback:i,descriptions:o,classNames:d,networkId:g,id:l,bridgeLessOnly:u}=e,{state:s}=useAccount(),{wrongNetwork:m}=useAppContext(),a=useMemo(()=>t===void 0?s.status===AccountStatusEnum.EnableTradingWithoutConnected?AccountStatusEnum.EnableTradingWithoutConnected:AccountStatusEnum.EnableTrading:t,[t,s.status]),f={...X,...e.labels},A=useMemo(()=>typeof i<"u"?i({validating:s.validating,status:s.status,wrongNetwork:m}):s.validating?jsx(k,{angle:45,disabled:true,loading:true,description:o?.connectWallet,id:l,type:"button",...n,children:f.connectWallet}):jsx(Ze,{bridgeLessOnly:u,status:s.status,buttonProps:{...n,id:l,type:"button"},wrongNetwork:m,networkId:e.networkId,labels:f,descriptions:o}),[s.status,s.validating,n,m]);return jsx(Either,{value:s.status>=a&&!m,left:A,children:e.children})},Ze=e=>{let{buttonProps:t,labels:n,descriptions:i}=e,{connectWallet:o}=useAppContext(),{account:d}=useAccount(),{isMobile:g}=useScreen(),l=useMediaQuery(MEDIA_TABLET),u=()=>{modal.show(l?R:v).then(a=>{},a=>{});},s=async()=>{let a=await o();a&&(a.wrongNetwork?m():(a?.status??AccountStatusEnum.NotConnected)<AccountStatusEnum.EnableTrading&&u());},m=()=>{d.once("validate:end",a=>{a<AccountStatusEnum.EnableTrading?u():toast.success("Wallet connected");}),modal.show(g?ChainSelectorSheetId:ChainSelectorDialogId,{networkId:e.networkId,bridgeLessOnly:e.bridgeLessOnly}).then(a=>{a.wrongNetwork||e.status>=AccountStatusEnum.Connected&&(e.status<AccountStatusEnum.EnableTrading?u():toast.success("Wallet connected"));},a=>{});};return e.wrongNetwork?jsx(k,{color:"warning",onClick:()=>{m();},description:i?.switchChain,...t,children:n.switchChain}):jsx(Match,{value:e.status,case:a=>{if(a<=AccountStatusEnum.NotConnected)return jsx(k,{size:"lg",onClick:()=>{s();},variant:"gradient",angle:45,description:i?.connectWallet,...t,children:n.connectWallet});if(a<=AccountStatusEnum.NotSignedIn)return jsx(k,{size:"lg",onClick:()=>{u();},angle:45,description:i?.signin,...t,children:n.signin})},default:jsx(k,{size:"lg",description:i?.enableTrading,...t,onClick:()=>u(),children:n.enableTrading})})};S.displayName="AuthGuard";var k=e=>{let{description:t,...n}=e;return jsxs(Flex,{direction:"column",children:[jsx(Button,{...n}),!!t&&jsx(Box,{mt:4,className:"oui-leading-none",style:{lineHeight:0},children:jsx(Text,{size:"2xs",intensity:36,children:t})})]})};var st=e=>{let{status:t,labels:n,description:i,dataSource:o,...d}=e,{state:g}=useAccount(),l=useMemo(()=>t===void 0?g.status===AccountStatusEnum.EnableTradingWithoutConnected?AccountStatusEnum.EnableTradingWithoutConnected:AccountStatusEnum.EnableTrading:t,[t,g.status]),u=useDataTap(o,{accountStatus:l}),{wrongNetwork:s}=useAppContext();return jsx(DataTable,{dataSource:u,ignoreLoadingCheck:s||g.status<l||e.ignoreLoadingCheck,emptyView:jsx(at,{status:l,description:i,labels:n,className:e.classNames?.authGuardDescription,visible:!g.validating}),manualPagination:true,...d})},at=e=>{let t={...j,...e.description};return e.visible?jsx(Flex,{py:8,children:jsx(S,{status:e.status,labels:e.labels,descriptions:t,buttonProps:{size:"md"},children:jsx(ExtensionSlot,{position:ExtensionPositionEnum.EmptyDataIdentifier})})}):null};var se=e=>{let{hint:t={connectWallet:"Please connect wallet before starting to trade",signIn:"Please sign in before starting to trade",enableTrading:"Please sign in before starting to trade",wrongNetwork:"Please switch to a supported network to continue."},status:n}=e;return jsx(Box,{my:8,children:jsx(S,{status:n,descriptions:{...t,switchChain:t.wrongNetwork},children:e.children||jsx(EmptyDataState,{})})})};se.displayName="AuthGuardEmpty";var le=e=>{let{opactiy:t=90,tooltip:n={connectWallet:"Please connect wallet before set up",signIn:"Please sign in before set up",enableTrading:"Please enable trading before set up",wrongNetwork:"Please switch to a supported network to set up"}}=e,[i,o]=useState(false),{state:d}=useAccount(),g=true,{wrongNetwork:l}=useAppContext(),u=useMemo(()=>{if(l)return n?.wrongNetwork;switch(d.status){case AccountStatusEnum.NotConnected:return n?.connectWallet;case AccountStatusEnum.NotSignedIn:return n?.signIn;case AccountStatusEnum.DisabledTrading:return n?.enableTrading;case AccountStatusEnum.EnableTrading:return "";default:return e.content}},[e.content,d,g,n]),s=useMemo(()=>{switch(d.status){case AccountStatusEnum.NotConnected:case AccountStatusEnum.NotSignedIn:return t;case AccountStatusEnum.EnableTrading:return;default:return}},[e.opactiy,d,g]);return jsx(Tooltip,{open:u?i:false,onOpenChange:o,content:u,className:"oui-text-2xs",align:e.align,alignOffset:e.alignOffset,side:e.side,sideOffset:e.sideOffset,children:jsx("div",{style:{opacity:s},children:e.children})})};le.displayName="AuthGuardTooltip";
|
|
9
|
+
var V=e=>{let{title:t,description:n}=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(me,{...e})]})},me=e=>{let{active:t,isLoading:n,isCompleted:i}=e;return jsx(Match,{className:"oui-absolute oui-left-0 oui-top-1 oui-z-10",value:()=>i?"completed":n?"loading":t?"active":"normal",case:{loading:jsx("div",{children:jsx(Spinner,{size:"sm",className:"oui-ml-1"})}),completed:jsx("div",{children:jsx(CheckedCircleFillIcon,{opacity:1,className:"oui-text-primary"})})},default:jsx(fe,{active:!!t})})},fe=({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 B=e=>{let{initAccountState:t=AccountStatusEnum.NotConnected}=e,[n,i]=useState(true),o=useEventEmitter(),{state:u,account:g}=useAccount(),[c,d]=useState(t),[r,m]=useState(0),[s,p]=useState(false),[x]=useLocalStorage("orderly-first-show-wallet-connector-dialog",void 0);useEffect(()=>()=>{localStorage.setItem("orderly-first-show-wallet-connector-dialog","1");},[]),useEffect(()=>{d(u.status);},[u]);let y=useMemo(()=>{let a=[];return t<AccountStatusEnum.SignedIn&&a.push({key:"signIn",title:"Sign In",description:"Confirm you are the owner of this wallet"}),t<AccountStatusEnum.EnableTrading&&a.push({key:"enableTrading",title:"Enable Trading",description:"Enable secure access to our API for lightning fast trading"}),a},[t]),I=()=>(p(true),e.enableTrading(n).then(async a=>{p(false),m(C=>C+1);try{await e.enableTradingComplted?.();}catch{}typeof e.onCompleted=="function"?e.onCompleted():typeof e.close=="function"&&e.close();},a=>{if(p(false),a!==-1){if(a.message.indexOf("Signing off chain messages with Ledger is not yet supported")!==-1){o.emit("wallet:sign-message-with-ledger-error",{message:a.message,userAddress:g.address});return}toast.error(Y(a));}}).catch(a=>{p(false);})),P=()=>(p(true),e.signIn().then(a=>{m(C=>C+1),I();},a=>{if(p(false),a!==-1){if(a.message.indexOf("Signing off chain messages with Ledger is not yet supported")!==-1){o.emit("wallet:sign-message-with-ledger-error",{message:a.message,userAddress:g.address});return}toast.error(Y(a));}}).catch(a=>{p(false);}));return jsxs(Box,{id:"oui-wallet-connect-dialog-content",className:"oui-font-semibold",children:[jsx(Text,{intensity:54,size:"xs",children:"Your previous access has expired, you will receive a signature request to enable trading. Signing is free and will not send a transaction."}),jsxs(Box,{p:4,my:6,intensity:600,r:"lg",className:"oui-space-y-5",position:"relative",children:[y.map((a,C)=>jsx(V,{title:a.title,description:a.description,isCompleted:r>C,active:r===C,isLoading:s&&r===C},a.key)),y.length>1&&jsx(Box,{position:"absolute",height:"38px",left:28,top:18,zIndex:0,children:jsx(Divider,{lineStyle:"dashed",direction:"vertical",intensity:16,className:"oui-h-full"})})]}),e.showRefCodeInput&&y.length==2&&jsx(Ae,{...e}),x&&jsxs(Flex,{justify:"between",itemAlign:"center",children:[jsx(Ne,{}),jsx(Switch,{color:"primary",checked:n,onCheckedChange:i,disabled:s,className:"data-[state=checked]:oui-bg-primary-darken"})]}),jsx(Flex,{justify:"center",mt:8,children:jsx(Box,{width:"45%",children:jsx(Ee,{state:c,signIn:P,enableTrading:I,loading:s,disabled:c>=AccountStatusEnum.EnableTrading})})})]})},Ee=({state:e,signIn:t,enableTrading:n,loading:i,disabled:o})=>jsx(Match,{value:()=>e<=AccountStatusEnum.NotSignedIn?"signIn":"enableTrading",case:{signIn:jsx(Button,{fullWidth:true,onClick:()=>t(),loading:i,disabled:o,children:"Sign In"}),enableTrading:jsx(Button,{fullWidth:true,onClick:()=>n(),loading:i,disabled:o,children:"Enable Trading"})}}),Ae=e=>jsx(TextField,{placeholder:"Referral code (Optional)",fullWidth:true,label:"",value:e.refCode,onChange:t=>{e.setRefCode(t.target.value);},classNames:{label:"oui-text-base-contrast-54 oui-text-xs",input:"placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm"},formatters:[inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)],onClear:()=>{e.setRefCode("");},autoComplete:"off",helpText:e.helpText,className:"oui-mb-4",color:e.helpText?"danger":void 0}),Ne=()=>jsx(Tooltip,{content:"Toggle this option to skip these steps next time you want to trade.",className:"oui-max-w-[300px]",children:jsx("button",{onClick:()=>{window.innerWidth>768||modal.alert({title:"Remember me",message:jsx("span",{className:"oui-text-2xs oui-text-base-contrast/60",children:"Toggle this option to skip these steps next time you want to trade."})});},children:jsx(Text,{intensity:54,size:"xs",className:"oui-underline oui-underline-offset-4 oui-decoration-dashed oui-decoration-base-contrast-36",children:"Remember me"})})});function Y(e){Object.keys(e).forEach(n=>{});let t="Something went wrong";return e.toString().includes("rejected")&&(t="User rejected the request."),capitalizeFirstLetter(t)??t}var L=()=>{let{account:e,state:t,createOrderlyKey:n,createAccount:i}=useAccount(),[o,u]=useState(""),[g,c]=useState(""),{trigger:d}=useLazyQuery(`/v1/public/referral/verify_ref_code?referral_code=${o}`);useEffect(()=>{let w=localStorage.getItem("referral_code");w!=null&&u(w);},[]);let{referral_code:r,isLoading:m}=useGetReferralCode(e.accountId),[s,{error:p,isMutating:x}]=useMutation("/v1/referral/bind","POST");useEffect(()=>{o.length===0&&c("");},[o]);let y=()=>{toast.success("Wallet connected"),o.length>=4&&o.length<=10&&s({referral_code:o}).finally(()=>{localStorage.removeItem("referral_code");});},I=async()=>{if(o.length===0)return Promise.resolve(void 0);if(o.length>0&&(o.length<4||o.length>10))return Promise.resolve("The referral_code must be 4 to 10 characters long, only accept upper case roman characters and numbers");let{exist:w}=await d();return w===false?Promise.resolve("This referral code does not exist."):Promise.resolve(void 0)},P=(r?.length||0)===0&&!m,a=async()=>{if(P){let w=await I();if(typeof w<"u")return c(w),Promise.reject(-1)}return c(""),i()};return {enableTrading:async w=>{if(P){let F=await I();if(typeof F<"u")return c(F),Promise.reject(-1)}return c(""),n(w)},initAccountState:t.status,signIn:a,enableTradingComplted:y,refCode:o,setRefCode:u,helpText:g,showRefCodeInput:P}};var v="walletConnector",R="walletConnectorSheet",O=e=>{let t=L();return jsx(B,{...t,...e})};registerSimpleDialog(v,O,{size:"sm",title:"Connect wallet"});registerSimpleSheet(R,O,{title:"Connect wallet"});var X={connectWallet:"Connect wallet",switchChain:"Wrong network",enableTrading:"Enable trading",signin:"Sign in"},j={connectWallet:"Please Connect wallet before starting to trade",switchChain:"Please switch to a supported network to continue",enableTrading:"Please Enable trading before starting to trade",signin:"Please sign in before starting to trade"};var T=e=>{let{status:t,buttonProps:n,fallback:i,descriptions:o,classNames:u,networkId:g,id:c,bridgeLessOnly:d}=e,{state:r}=useAccount(),{wrongNetwork:m,disabledConnect:s}=useAppContext(),p=useMemo(()=>t===void 0?r.status===AccountStatusEnum.EnableTradingWithoutConnected?AccountStatusEnum.EnableTradingWithoutConnected:AccountStatusEnum.EnableTrading:t,[t,r.status]),x={...X,...e.labels},y=useMemo(()=>typeof i<"u"?i({validating:r.validating,status:r.status,wrongNetwork:m}):r.validating&&!s?jsx(E,{angle:45,disabled:true,loading:true,description:o?.connectWallet,id:c,type:"button",...n,children:x.connectWallet}):jsx(Ze,{bridgeLessOnly:d,status:r.status,buttonProps:{...n,id:c,type:"button"},wrongNetwork:m,networkId:e.networkId,labels:x,descriptions:o,disabledConnect:s}),[r.status,r.validating,n,m]);return jsx(Either,{value:r.status>=p&&!m&&!s,left:y,children:e.children})},Ze=e=>{let{buttonProps:t,labels:n,descriptions:i}=e,{connectWallet:o}=useAppContext(),{account:u}=useAccount(),{isMobile:g}=useScreen(),c=useMediaQuery(MEDIA_TABLET),d=()=>{modal.show(c?R:v).then(s=>{},s=>{});},r=async()=>{let s=await o();s&&(s.wrongNetwork?m():(s?.status??AccountStatusEnum.NotConnected)<AccountStatusEnum.EnableTrading&&d());},m=()=>{u.once("validate:end",s=>{s<AccountStatusEnum.EnableTrading?d():toast.success("Wallet connected");}),modal.show(g?ChainSelectorSheetId:ChainSelectorDialogId,{networkId:e.networkId,bridgeLessOnly:e.bridgeLessOnly}).then(s=>{s.wrongNetwork||e.status>=AccountStatusEnum.Connected&&(e.status<AccountStatusEnum.EnableTrading?d():toast.success("Wallet connected"));},s=>{});};return e.wrongNetwork&&!e.disabledConnect?jsx(E,{color:"warning",onClick:()=>{m();},description:i?.switchChain,...t,children:n.switchChain}):jsx(Match,{value:e.status,case:s=>{if(s<=AccountStatusEnum.NotConnected||e.disabledConnect)return jsx(E,{size:"lg",onClick:()=>{r();},variant:e.disabledConnect?void 0:"gradient",angle:45,description:i?.connectWallet,disabled:e.disabledConnect,...t,children:n.connectWallet});if(s<=AccountStatusEnum.NotSignedIn)return jsx(E,{size:"lg",onClick:()=>{d();},angle:45,description:i?.signin,...t,children:n.signin})},default:jsx(E,{size:"lg",description:i?.enableTrading,...t,onClick:()=>d(),children:n.enableTrading})})};T.displayName="AuthGuard";var E=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 rt=e=>{let{status:t,labels:n,description:i,dataSource:o,...u}=e,{state:g}=useAccount(),{wrongNetwork:c,disabledConnect:d}=useAppContext(),r=useMemo(()=>t===void 0?g.status===AccountStatusEnum.EnableTradingWithoutConnected?AccountStatusEnum.EnableTradingWithoutConnected:AccountStatusEnum.EnableTrading:t,[t,g.status]),m=useDataTap(o,{accountStatus:r}),s=c||d||g.status<r||e.ignoreLoadingCheck;return jsx(DataTable,{dataSource:m,ignoreLoadingCheck:s,emptyView:jsx(at,{status:r,description:i,labels:n,className:e.classNames?.authGuardDescription,visible:!g.validating}),manualPagination:true,...u})},at=e=>{let t={...j,...e.description};return e.visible?jsx(Flex,{py:8,children:jsx(T,{status:e.status,labels:e.labels,descriptions:t,buttonProps:{size:"md"},children:jsx(ExtensionSlot,{position:ExtensionPositionEnum.EmptyDataIdentifier})})}):null};var re=e=>{let{hint:t={connectWallet:"Please connect wallet before starting to trade",signIn:"Please sign in before starting to trade",enableTrading:"Please sign in before starting to trade",wrongNetwork:"Please switch to a supported network to continue."},status:n}=e;return jsx(Box,{my:8,children:jsx(T,{status:n,descriptions:{...t,switchChain:t.wrongNetwork},children:e.children||jsx(EmptyDataState,{})})})};re.displayName="AuthGuardEmpty";var le=e=>{let{opactiy:t=90,tooltip:n={connectWallet:"Please connect wallet before set up",signIn:"Please sign in before set up",enableTrading:"Please enable trading before set up",wrongNetwork:"Please switch to a supported network to set up"}}=e,[i,o]=useState(false),{state:u}=useAccount(),g=true,{wrongNetwork:c}=useAppContext(),d=useMemo(()=>{if(c)return n?.wrongNetwork;switch(u.status){case AccountStatusEnum.NotConnected:return n?.connectWallet;case AccountStatusEnum.NotSignedIn:return n?.signIn;case AccountStatusEnum.DisabledTrading:return n?.enableTrading;case AccountStatusEnum.EnableTrading:return "";default:return e.content}},[e.content,u,g,n]),r=useMemo(()=>{switch(u.status){case AccountStatusEnum.NotConnected:case AccountStatusEnum.NotSignedIn:return t;case AccountStatusEnum.EnableTrading:return;default:return}},[e.opactiy,u,g]);return jsx(Tooltip,{open:d?i:false,onOpenChange:o,content:d,className:"oui-text-2xs",align:e.align,alignOffset:e.alignOffset,side:e.side,sideOffset:e.sideOffset,children:jsx("div",{style:{opacity:r},children:e.children})})};le.displayName="AuthGuardTooltip";
|
|
10
10
|
|
|
11
|
-
export {
|
|
11
|
+
export { T as AuthGuard, rt as AuthGuardDataTable, re as AuthGuardEmpty, le as AuthGuardTooltip, B as WalletConnectContent, v as WalletConnectorModalId, R as WalletConnectorSheetId, O as WalletConnectorWidget, L as useWalletConnectorBuilder };
|
|
12
12
|
//# sourceMappingURL=out.js.map
|
|
13
13
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/walletConnectorContent.tsx","../src/component/step.tsx","../src/component/walletConnector.tsx","../src/component/useWalletConnectorBuilder.ts","../src/component/authGuard.tsx","../src/constants/message.ts","../src/component/authGuardDataTable.tsx","../src/component/authGuardEmpty.tsx","../src/component/authGuardTooltip.tsx"],"names":["useEffect","useMemo","useState","Box","Button","capitalizeFirstLetter","Divider","Flex","inputFormatter","Match","modal","Switch","Text","TextField","toast","Tooltip","AccountStatusEnum","CheckedCircleFillIcon","cn","Spinner","jsx","jsxs","StepItem","props","title","description","Identifier","active","isLoading","isCompleted","Dot","className","useAccount","useEventEmitter","useLocalStorage","WalletConnectContent","initAccountState","remember","setRemember","ee","accountState","account","state","setState","activeStep","setActiveStep","loading","setLoading","firstShowDialog","steps","onEnableTrading","res","step","reject","paseErrorMsg","e","onSignIn","index","ReferralCode","RememberMe","ActionButton","signIn","enableTrading","disabled","key","msg","registerSimpleDialog","registerSimpleSheet","useGetReferralCode","useLazyQuery","useMutation","useWalletConnectorBuilder","createOrderlyKey","createAccount","refCode","setRefCode","helpText","setHelpText","verifyRefCode","referral_code","bindRefCode","updateOrderError","updateMutating","enableTradingComplted","checkRefCode","exist","showRefCodeInput","info","WalletConnectorModalId","WalletConnectorSheetId","WalletConnectorWidget","useMediaQuery","MEDIA_TABLET","Either","useScreen","useAppContext","ChainSelectorDialogId","ChainSelectorSheetId","LABELS","DESCRIPTIONS","AuthGuard","status","buttonProps","fallback","descriptions","classNames","networkId","id","bridgeLessOnly","wrongNetwork","_status","labels","Left","StatusInfo","DefaultFallback","connectWallet","isMobile","matches","onConnectOrderly","r","error","onConnectWallet","switchChain","value","ExtensionPositionEnum","ExtensionSlot","DataTable","useDataTap","AuthGuardDataTable","dataSource","rest","data","GuardView","EmptyDataState","AuthGuardEmpty","hint","AuthGuardTooltip","opactiy","tooltip","open","setOpen","isSupport","newOpacity"],"mappings":"AAAA,OAAa,aAAAA,EAAW,WAAAC,GAAS,YAAAC,MAAgB,QACjD,OACE,OAAAC,E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ACrB,OAAO0H,GAAS,OAClB,KAAK1H,EAAkB,gBACrB,OAAO0H,GAAS,cAClB,KAAK1H,EAAkB,cACrB,MAAO,GAET,QACE,OAAOO,EAAM,OACjB,CACF,EAAG,CAACA,EAAM,QAASmB,EAAOmG,EAAWH,CAAO,CAAC,EAEvCI,EAAa7I,GAAQ,IAAM,CAC/B,OAAQyC,EAAM,OAAQ,CACpB,KAAK1B,EAAkB,aACvB,KAAKA,EAAkB,YACrB,OAAOyH,EACT,KAAKzH,EAAkB,cACrB,OAEF,QACE,MACJ,CACF,EAAG,CAACO,EAAM,QAASmB,EAAOmG,CAAS,CAAC,EAEpC,OACEzH,GAACL,GAAA,CACC,KAAMwH,EAAOI,EAAO,GACpB,aAAcC,EACd,QAASL,EACT,UAAU,eACV,MAAOhH,EAAM,MACb,YAAaA,EAAM,YACnB,KAAMA,EAAM,KACZ,WAAYA,EAAM,WAElB,SAAAH,GAAC,OACC,MAAO,CACL,QAAS0H,CACX,EAEC,SAAAvH,EAAM,SACT,EACF,CAEJ,EAEAiH,GAAiB,YAAc","sourcesContent":["import { FC, useEffect, useMemo, useState } from \"react\";\nimport {\n Box,\n Button,\n capitalizeFirstLetter,\n cn,\n Divider,\n Flex,\n Input,\n inputFormatter,\n Match,\n modal,\n Switch,\n Text,\n TextField,\n toast,\n Tooltip,\n} from \"@orderly.network/ui\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\nimport { StepItem } from \"./step\";\nimport { useAccount, useEventEmitter, useLocalStorage } from \"@orderly.network/hooks\";\n\nexport type WalletConnectContentProps = {\n initAccountState: AccountStatusEnum;\n signIn: () => Promise<any>;\n enableTrading: (remember: boolean) => Promise<any>;\n enableTradingComplted?: () => Promise<void>;\n onCompleted?: () => void;\n close?: () => void;\n refCode: string;\n setRefCode: React.Dispatch<React.SetStateAction<string>>;\n helpText?: string;\n showRefCodeInput: boolean;\n};\n\nexport const WalletConnectContent = (props: WalletConnectContentProps) => {\n const { initAccountState = AccountStatusEnum.NotConnected } = props;\n const [remember, setRemember] = useState(true);\n const ee = useEventEmitter();\n\n\n const { state: accountState, account } = useAccount();\n const [state, setState] = useState(initAccountState);\n const [activeStep, setActiveStep] = useState(0);\n const [loading, setLoading] = useState(false);\n const [firstShowDialog] = useLocalStorage(\n \"orderly-first-show-wallet-connector-dialog\",\n undefined\n );\n useEffect(() => {\n return () => {\n localStorage.setItem(\"orderly-first-show-wallet-connector-dialog\", \"1\");\n };\n }, []);\n\n useEffect(() => {\n setState(accountState.status);\n }, [accountState]);\n\n const steps = useMemo(() => {\n const steps = [];\n if (initAccountState < AccountStatusEnum.SignedIn) {\n steps.push({\n key: \"signIn\",\n title: \"Sign In\",\n description: \"Confirm you are the owner of this wallet\",\n });\n }\n\n if (initAccountState < AccountStatusEnum.EnableTrading) {\n steps.push({\n key: \"enableTrading\",\n title: \"Enable Trading\",\n description:\n \"Enable secure access to our API for lightning fast trading\",\n });\n }\n\n return steps;\n }, [initAccountState]);\n\n const onEnableTrading = () => {\n setLoading(true);\n return props\n .enableTrading(remember)\n .then(\n async (res) => {\n console.log(res);\n setLoading(false);\n setActiveStep((step) => step + 1);\n try {\n await props.enableTradingComplted?.();\n } catch (e) {}\n if (typeof props.onCompleted === \"function\") {\n props.onCompleted();\n } else if (typeof props.close === \"function\") {\n props.close();\n }\n // props.onCompleted?.();\n },\n (reject) => {\n setLoading(false);\n if (reject === -1) return;\n\n if (reject.message.indexOf('Signing off chain messages with Ledger is not yet supported') !== -1) {\n ee.emit(\"wallet:sign-message-with-ledger-error\", {message: reject.message,userAddress: account.address});\n return;\n }\n toast.error(paseErrorMsg(reject));\n }\n )\n .catch((e) => {\n console.log(\"enable trading catch error\", e);\n setLoading(false);\n });\n };\n\n const onSignIn = () => {\n setLoading(true);\n return props\n .signIn()\n .then(\n (res) => {\n setActiveStep((step) => step + 1);\n onEnableTrading();\n },\n (reject) => {\n setLoading(false);\n\n if (reject === -1) return;\n if (reject.message.indexOf('Signing off chain messages with Ledger is not yet supported') !== -1) {\n ee.emit(\"wallet:sign-message-with-ledger-error\", {message: reject.message,userAddress: account.address});\n return;\n }\n\n toast.error(paseErrorMsg(reject));\n }\n )\n .catch((e) => {\n setLoading(false);\n });\n };\n\n console.log(\"state\", state);\n\n return (\n <Box id=\"oui-wallet-connect-dialog-content\" className=\"oui-font-semibold\">\n <Text intensity={54} size=\"xs\">\n Your previous access has expired, you will receive a signature request\n to enable trading. Signing is free and will not send a transaction.\n </Text>\n <Box\n p={4}\n my={6}\n intensity={600}\n r=\"lg\"\n className=\"oui-space-y-5\"\n position={\"relative\"}\n >\n {steps.map((step, index) => {\n return (\n <StepItem\n title={step.title}\n description={step.description}\n isCompleted={activeStep > index}\n key={step.key}\n active={activeStep === index}\n isLoading={loading && activeStep === index}\n />\n );\n })}\n {steps.length > 1 && (\n <Box\n position={\"absolute\"}\n height={\"38px\"}\n left={28}\n top={18}\n zIndex={0}\n >\n <Divider\n lineStyle={\"dashed\"}\n direction={\"vertical\"}\n intensity={16}\n className=\"oui-h-full\"\n />\n </Box>\n )}\n </Box>\n {props.showRefCodeInput && steps.length == 2 && (\n <ReferralCode {...props} />\n )}\n {firstShowDialog && (\n <Flex justify={\"between\"} itemAlign={\"center\"}>\n <RememberMe />\n <Switch\n color={\"primary\"}\n checked={remember}\n onCheckedChange={setRemember}\n disabled={loading}\n className=\"data-[state=checked]:oui-bg-primary-darken\"\n />\n </Flex>\n )}\n <Flex justify={\"center\"} mt={8}>\n <Box width={\"45%\"}>\n <ActionButton\n state={state}\n signIn={onSignIn}\n enableTrading={onEnableTrading}\n loading={loading}\n disabled={state >= AccountStatusEnum.EnableTrading}\n />\n </Box>\n </Flex>\n </Box>\n );\n};\n\nconst ActionButton: FC<{\n state: AccountStatusEnum;\n signIn: () => Promise<any>;\n enableTrading: () => Promise<any>;\n loading: boolean;\n disabled?: boolean;\n}> = ({ state, signIn, enableTrading, loading, disabled }) => {\n return (\n <Match\n value={() => {\n if (state <= AccountStatusEnum.NotSignedIn) {\n return \"signIn\";\n }\n return \"enableTrading\";\n }}\n case={{\n signIn: (\n <Button\n fullWidth\n onClick={() => signIn()}\n loading={loading}\n disabled={disabled}\n >\n Sign In\n </Button>\n ),\n enableTrading: (\n <Button\n fullWidth\n onClick={() => enableTrading()}\n loading={loading}\n disabled={disabled}\n >\n Enable Trading\n </Button>\n ),\n }}\n />\n );\n};\n\nconst ReferralCode: FC<WalletConnectContentProps> = (props) => {\n return (\n <TextField\n placeholder=\"Referral code (Optional)\"\n fullWidth\n // label={\"Referral code (optional)\"}\n label=\"\"\n value={props.refCode}\n onChange={(e) => {\n props.setRefCode(e.target.value);\n }}\n classNames={{\n label: \"oui-text-base-contrast-54 oui-text-xs\",\n input: \"placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm\",\n }}\n formatters={[inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)]}\n onClear={() => {\n props.setRefCode(\"\");\n }}\n autoComplete=\"off\"\n helpText={props.helpText}\n className=\"oui-mb-4\"\n color={props.helpText ? \"danger\" : undefined}\n />\n );\n};\n\nconst RememberMe = () => {\n const showRememberHint = () => {\n if (window.innerWidth > 768) return;\n modal.alert({\n title: \"Remember me\",\n message: (\n <span className=\"oui-text-2xs oui-text-base-contrast/60\">\n Toggle this option to skip these steps next time you want to trade.\n </span>\n ),\n });\n };\n return (\n <Tooltip\n content={\n \"Toggle this option to skip these steps next time you want to trade.\"\n }\n className=\"oui-max-w-[300px]\"\n >\n <button onClick={showRememberHint}>\n <Text\n intensity={54}\n size={\"xs\"}\n className={\n \"oui-underline oui-underline-offset-4 oui-decoration-dashed oui-decoration-base-contrast-36\"\n }\n >\n Remember me\n </Text>\n </button>\n </Tooltip>\n );\n};\n\nfunction paseErrorMsg(reject: any): string {\n console.log(\"wallet callback error\", reject);\n console.log(\"message *** \", \"reject keys\", Object.keys(reject));\n Object.keys(reject).forEach((key) => {\n console.log(\"key\", key, \"-\", reject[key]);\n });\n let msg = \"Something went wrong\";\n\n // if (typeof reject?.info?.error === \"object\" && \"message\" in reject?.info?.error) {\n // msg = reject?.info?.error?.message;\n // }\n\n // if (typeof reject?.shortMessage === 'string') {\n // msg = reject.shortMessage;\n // }\n\n if (reject.toString().includes(\"rejected\")) {\n msg = \"User rejected the request.\";\n }\n\n\n return capitalizeFirstLetter(msg) ?? msg;\n}\n\n","import { FC } from \"react\";\nimport {\n Box,\n CheckedCircleFillIcon,\n cn,\n Match,\n Spinner,\n Text,\n} from \"@orderly.network/ui\";\n\ntype StepItemProps = {\n active?: boolean;\n isLoading?: boolean;\n isCompleted?: boolean;\n title: string;\n description: string;\n};\n\nexport const StepItem = (props: StepItemProps) => {\n const { title, description } = props;\n\n // console.log(props);\n\n return (\n <Box position=\"relative\" className=\"oui-pl-8\">\n <Box>\n <Text as=\"div\" intensity={98} size={\"sm\"}>\n {title}\n </Text>\n <Text as=\"div\" intensity={54} size={\"2xs\"}>\n {description}\n </Text>\n </Box>\n <Identifier {...props} />\n </Box>\n );\n};\n\nconst Identifier = (props: {\n active?: boolean;\n isLoading?: boolean;\n isCompleted?: boolean;\n}) => {\n const { active, isLoading, isCompleted } = props;\n\n return (\n <Match\n className={\"oui-absolute oui-left-0 oui-top-1 oui-z-10\"}\n value={() => {\n if (isCompleted) {\n return \"completed\";\n }\n if (isLoading) {\n return \"loading\";\n }\n\n if (active) {\n return \"active\";\n }\n\n return \"normal\";\n }}\n case={{\n loading: (\n <div>\n <Spinner size={\"sm\"} className={\"oui-ml-1\"} />\n </div>\n ),\n completed: (\n <div>\n <CheckedCircleFillIcon opacity={1} className=\"oui-text-primary\" />\n </div>\n ),\n }}\n default={<Dot active={!!active} />}\n />\n );\n};\n\nconst Dot: FC<{ active: boolean; className?: string }> = ({\n active,\n className,\n}) => {\n return (\n <div\n className={cn(\n \"oui-w-[8.3px] oui-h-[8.3px] oui-rounded-full oui-ml-2 oui-mt-1\",\n className,\n active ? \"oui-bg-primary-light\" : \"oui-bg-base-2\"\n )}\n />\n );\n};\n","import { registerSimpleDialog, registerSimpleSheet } from \"@orderly.network/ui\";\n\nimport { useWalletConnectorBuilder } from \"./useWalletConnectorBuilder\";\nimport { WalletConnectContent } from \"./walletConnectorContent\";\n\nexport const WalletConnectorModalId = \"walletConnector\" as const;\nexport const WalletConnectorSheetId = \"walletConnectorSheet\" as const;\n\nexport const WalletConnectorWidget = (props: any) => {\n const state = useWalletConnectorBuilder();\n return <WalletConnectContent {...state} {...props} />;\n};\n\nregisterSimpleDialog(WalletConnectorModalId, WalletConnectorWidget, {\n size: \"sm\",\n title: \"Connect wallet\",\n});\n\nregisterSimpleSheet(WalletConnectorSheetId, WalletConnectorWidget, {\n title: \"Connect wallet\",\n});\n","import {\n useAccount,\n useCheckReferralCode,\n useGetReferralCode,\n useLazyQuery,\n useMutation,\n} from \"@orderly.network/hooks\";\nimport { toast } from \"@orderly.network/ui\";\nimport { useEffect, useMemo, useState } from \"react\";\n\n\nexport const useWalletConnectorBuilder = () => {\n const { account, state, createOrderlyKey, createAccount } = useAccount();\n const [refCode, setRefCode] = useState(\"\");\n const [helpText, setHelpText] = useState(\"\");\n\n const { trigger: verifyRefCode } = useLazyQuery(\n `/v1/public/referral/verify_ref_code?referral_code=${refCode}`\n );\n\n useEffect(() => {\n const refCode = localStorage.getItem(\"referral_code\");\n if (refCode != null) {\n setRefCode(refCode);\n }\n }, []);\n\n const { referral_code, isLoading } = useGetReferralCode(account.accountId);\n\n const [bindRefCode, { error: updateOrderError, isMutating: updateMutating }] =\n useMutation(\"/v1/referral/bind\", \"POST\");\n\n useEffect(() => {\n if (refCode.length === 0) {\n setHelpText(\"\");\n }\n }, [refCode]);\n\n const enableTradingComplted = () => {\n toast.success(\"Wallet connected\");\n // validate ref code and bind referral code\n if (refCode.length >= 4 && refCode.length <= 10)\n bindRefCode({ referral_code: refCode }).finally(() => {\n localStorage.removeItem(\"referral_code\");\n });\n };\n\n const checkRefCode = async (): Promise<string | undefined> => {\n if (refCode.length === 0) return Promise.resolve(undefined);\n\n if (refCode.length > 0 && (refCode.length < 4 || refCode.length > 10)) {\n return Promise.resolve(\n \"The referral_code must be 4 to 10 characters long, only accept upper case roman characters and numbers\"\n );\n }\n\n const { exist } = await verifyRefCode();\n \n\n if (exist === false) {\n return Promise.resolve(\"This referral code does not exist.\");\n }\n\n return Promise.resolve(undefined);\n };\n\n\n const showRefCodeInput = (referral_code?.length || 0) === 0 && !isLoading;\n\n\n const signIn = async () => {\n if (showRefCodeInput) {\n const info = await checkRefCode();\n if (typeof info !== \"undefined\") {\n setHelpText(info);\n return Promise.reject(-1);\n }\n }\n setHelpText(\"\");\n return createAccount();\n };\n\n const enableTrading = async (remember: boolean) => {\n if (showRefCodeInput) {\n const info = await checkRefCode();\n if (typeof info !== \"undefined\") {\n setHelpText(info);\n return Promise.reject(-1);\n }\n }\n setHelpText(\"\");\n return createOrderlyKey(remember);\n };\n\n return {\n enableTrading,\n initAccountState: state.status,\n signIn,\n enableTradingComplted,\n refCode,\n setRefCode,\n helpText,\n showRefCodeInput,\n } as const;\n};\n","import { useAccount, useMediaQuery } from \"@orderly.network/hooks\";\nimport {\n AccountStatusEnum,\n MEDIA_TABLET,\n NetworkId,\n} from \"@orderly.network/types\";\nimport {\n Button,\n Either,\n Match,\n modal,\n Text,\n toast,\n useScreen,\n type ButtonProps,\n} from \"@orderly.network/ui\";\nimport { useAppContext } from \"@orderly.network/react-app\";\nimport { PropsWithChildren, ReactElement, useMemo } from \"react\";\nimport {\n WalletConnectorModalId,\n WalletConnectorSheetId,\n} from \"./walletConnector\";\nimport {\n ChainSelectorDialogId,\n ChainSelectorSheetId,\n} from \"@orderly.network/ui-chain-selector\";\nimport { alertMessages, DESCRIPTIONS, LABELS } from \"../constants/message\";\nimport { Flex } from \"@orderly.network/ui\";\nimport { Box } from \"@orderly.network/ui\";\n\ntype ChainProps = {\n networkId?: NetworkId;\n bridgeLessOnly?: boolean;\n};\n\nexport type AuthGuardProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {\n fallback?: (props: {\n validating: boolean;\n status: AccountStatusEnum;\n wrongNetwork: boolean;\n }) => ReactElement;\n // indicator?: ReactElement;\n /**\n * Required state to be satisfied\n * @default AccountStatusEnum.EnableTrading\n */\n status?: AccountStatusEnum;\n\n bridgeLessOnly?: boolean;\n\n buttonProps?: ButtonProps;\n\n descriptions?: alertMessages;\n\n labels?: alertMessages;\n\n classNames?: {\n root?: string;\n description?: string;\n // button?: string;\n };\n\n networkId?: NetworkId;\n\n // validatingIndicator?: ReactElement;\n};\n\nconst AuthGuard = (props: PropsWithChildren<AuthGuardProps>) => {\n const {\n status,\n buttonProps,\n fallback,\n descriptions,\n classNames,\n networkId,\n id,\n bridgeLessOnly,\n // ...rest\n } = props;\n const { state } = useAccount();\n const { wrongNetwork } = useAppContext();\n\n const _status = useMemo(() => {\n if (status === undefined) {\n return state.status === AccountStatusEnum.EnableTradingWithoutConnected\n ? AccountStatusEnum.EnableTradingWithoutConnected\n : AccountStatusEnum.EnableTrading;\n }\n return status;\n }, [status, state.status]);\n\n const labels = { ...LABELS, ...props.labels };\n\n // return Match(state.status)\n // .with(AccountStatusEnum.EnableTrading, () => props.children)\n // .with(AccountStatusEnum.DisableTrading, () => props.fallback)\n // .with(AccountStatusEnum.Validating, () => props.validatingIndicator)\n // .otherwise(() => props.fallback);\n //\n\n const Left = useMemo<ReactElement>(() => {\n if (typeof fallback !== \"undefined\") {\n return fallback({\n validating: state.validating,\n status: state.status,\n wrongNetwork,\n });\n }\n\n if (state.validating) {\n return (\n <StatusInfo\n // variant={\"gradient\"}\n angle={45}\n // fullWidth\n disabled\n loading\n description={descriptions?.connectWallet}\n id={id}\n type=\"button\"\n {...buttonProps}\n >\n {labels.connectWallet}\n </StatusInfo>\n );\n }\n\n return (\n <DefaultFallback\n bridgeLessOnly={bridgeLessOnly}\n status={state.status}\n buttonProps={{ ...buttonProps, id, type: \"button\" }}\n wrongNetwork={wrongNetwork}\n networkId={props.networkId}\n labels={labels}\n descriptions={descriptions}\n />\n );\n }, [state.status, state.validating, buttonProps, wrongNetwork]);\n\n /**\n * **Important: The chldren component will be rendered only if the status is equal to the required status and the network is correct.**\n */\n\n return (\n <Either value={state.status >= _status && !wrongNetwork} left={Left}>\n {props.children}\n </Either>\n );\n};\n\nconst DefaultFallback = (props: {\n status: AccountStatusEnum;\n wrongNetwork: boolean;\n buttonProps?: ButtonProps;\n networkId?: NetworkId;\n labels: alertMessages;\n bridgeLessOnly?: boolean;\n descriptions?: alertMessages;\n}) => {\n const { buttonProps, labels, descriptions } = props;\n const { connectWallet } = useAppContext();\n const { account } = useAccount();\n const { isMobile } = useScreen();\n const matches = useMediaQuery(MEDIA_TABLET);\n const onConnectOrderly = () => {\n modal.show(matches ? WalletConnectorSheetId : WalletConnectorModalId).then(\n (r) => console.log(r),\n (error) => console.log(error)\n );\n };\n\n const onConnectWallet = async () => {\n const res = await connectWallet();\n\n if (!res) return;\n\n if (res.wrongNetwork) {\n switchChain();\n } else {\n if (\n (res?.status ?? AccountStatusEnum.NotConnected) <\n AccountStatusEnum.EnableTrading\n ) {\n onConnectOrderly();\n }\n }\n };\n\n const switchChain = () => {\n account.once(\"validate:end\", (status) => {\n if (status < AccountStatusEnum.EnableTrading) {\n onConnectOrderly();\n } else {\n toast.success(\"Wallet connected\");\n }\n });\n\n modal\n .show<{\n wrongNetwork: boolean;\n }>(isMobile ? ChainSelectorSheetId : ChainSelectorDialogId, {\n networkId: props.networkId,\n bridgeLessOnly: props.bridgeLessOnly,\n })\n .then(\n (r) => {\n if (!r.wrongNetwork) {\n if (props.status >= AccountStatusEnum.Connected) {\n if (props.status < AccountStatusEnum.EnableTrading) {\n onConnectOrderly();\n } else {\n toast.success(\"Wallet connected\");\n }\n }\n }\n },\n (error) => console.log(\"[switchChain error]\", error)\n );\n };\n\n if (props.wrongNetwork) {\n return (\n <StatusInfo\n color=\"warning\"\n // size=\"md\"\n // fullWidth\n onClick={() => {\n switchChain();\n }}\n description={descriptions?.switchChain}\n {...buttonProps}\n >\n {labels.switchChain}\n </StatusInfo>\n );\n }\n\n return (\n <Match\n value={props.status}\n case={(value: AccountStatusEnum) => {\n if (value <= AccountStatusEnum.NotConnected) {\n return (\n <StatusInfo\n size=\"lg\"\n onClick={() => {\n onConnectWallet();\n }}\n // fullWidth\n variant={\"gradient\"}\n angle={45}\n description={descriptions?.connectWallet}\n {...buttonProps}\n >\n {labels.connectWallet}\n </StatusInfo>\n );\n }\n if (value <= AccountStatusEnum.NotSignedIn) {\n return (\n <StatusInfo\n size=\"lg\"\n onClick={() => {\n onConnectOrderly();\n }}\n // fullWidth\n angle={45}\n description={descriptions?.signin}\n {...buttonProps}\n >\n {labels.signin}\n </StatusInfo>\n );\n }\n }}\n default={\n <StatusInfo\n size=\"lg\"\n // fullWidth\n description={descriptions?.enableTrading}\n {...buttonProps}\n onClick={() => onConnectOrderly()}\n >\n {labels.enableTrading}\n </StatusInfo>\n }\n />\n );\n};\n\nAuthGuard.displayName = \"AuthGuard\";\n\nconst StatusInfo = (\n props: ButtonProps & {\n description?: string;\n }\n) => {\n const { description, ...buttonProps } = props;\n return (\n <Flex direction={\"column\"}>\n <Button {...buttonProps}></Button>\n {!!description && (\n <Box mt={4} className=\"oui-leading-none\" style={{ lineHeight: 0 }}>\n <Text size=\"2xs\" intensity={36}>\n {description}\n </Text>\n </Box>\n )}\n </Flex>\n );\n};\n\nexport { AuthGuard };\n","export type alertMessages = {\n connectWallet?: string;\n switchChain?: string;\n enableTrading?: string;\n signin?: string;\n};\n\nexport const LABELS = {\n connectWallet: \"Connect wallet\",\n switchChain: \"Wrong network\",\n enableTrading: \"Enable trading\",\n signin: \"Sign in\",\n};\n\nexport const DESCRIPTIONS: alertMessages = {\n connectWallet: \"Please Connect wallet before starting to trade\",\n switchChain: \"Please switch to a supported network to continue\",\n enableTrading: \"Please Enable trading before starting to trade\",\n signin: \"Please sign in before starting to trade\",\n};\n","import { PropsWithChildren, useMemo } from \"react\";\nimport {\n ExtensionPositionEnum,\n ExtensionSlot,\n DataTable,\n DataTableProps,\n} from \"@orderly.network/ui\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\nimport { alertMessages, DESCRIPTIONS } from \"../constants/message\";\nimport { useAppContext, useDataTap } from \"@orderly.network/react-app\";\nimport { Flex } from \"@orderly.network/ui\";\nimport { AuthGuard } from \"./authGuard\";\nimport { useAccount } from \"@orderly.network/hooks\";\n\nexport const AuthGuardDataTable = <RecordType extends unknown>(\n props: PropsWithChildren<\n DataTableProps<RecordType> &\n Omit<GuardViewProps, \"status\"> & {\n status?: AccountStatusEnum;\n classNames?: DataTableProps<RecordType>[\"classNames\"] & {\n authGuardDescription?: string;\n };\n }\n >\n) => {\n const {\n status,\n // message,\n labels,\n description,\n dataSource,\n ...rest\n } = props;\n const { state } = useAccount();\n\n const _status = useMemo(() => {\n if (status === undefined) {\n return state.status === AccountStatusEnum.EnableTradingWithoutConnected\n ? AccountStatusEnum.EnableTradingWithoutConnected\n : AccountStatusEnum.EnableTrading;\n }\n return status;\n }, [status, state.status]);\n\n const data = useDataTap(dataSource, {\n accountStatus: _status,\n });\n const { wrongNetwork } = useAppContext();\n\n return (\n <DataTable\n dataSource={data}\n ignoreLoadingCheck={\n wrongNetwork || state.status < _status || props.ignoreLoadingCheck\n }\n emptyView={\n <GuardView\n status={_status}\n description={description}\n labels={labels}\n className={props.classNames?.authGuardDescription}\n visible={!state.validating}\n />\n }\n manualPagination\n {...rest}\n />\n );\n};\n\ntype GuardViewProps = {\n status: AccountStatusEnum;\n description?: alertMessages;\n labels?: alertMessages;\n className?: string;\n visible?: boolean;\n};\n\nconst GuardView = (props: GuardViewProps) => {\n const descriptions = { ...DESCRIPTIONS, ...props.description };\n if (!props.visible) return null;\n return (\n <Flex py={8}>\n <AuthGuard\n status={props.status}\n labels={props.labels}\n descriptions={descriptions}\n buttonProps={{\n size: \"md\",\n }}\n >\n <ExtensionSlot position={ExtensionPositionEnum.EmptyDataIdentifier} />\n </AuthGuard>\n </Flex>\n );\n};\n","import { AccountStatusEnum } from \"@orderly.network/types\";\nimport {\n Box,\n EmptyDataState,\n} from \"@orderly.network/ui\";\nimport { PropsWithChildren } from \"react\";\nimport { AuthGuard } from \"./authGuard\";\n\ntype AuthGuardProps = {\n /** default value is\n * ```ts\n * {\n * connectWallet: \"Please connect wallet before starting to trade\",\n * signIn: \"Please sign in before starting to trade\",\n * enableTrading: \"Please sign in before starting to trade\",\n * wrongNetwork: \"Please switch to a supported network to continue.\",\n * }\n * ```\n */\n hint?: {\n connectWallet?: string;\n signIn?: string;\n enableTrading?: string;\n wrongNetwork?: string;\n };\n status?: AccountStatusEnum;\n};\n\nconst AuthGuardEmpty = (props: PropsWithChildren<AuthGuardProps>) => {\n const {\n hint = {\n connectWallet: \"Please connect wallet before starting to trade\",\n signIn: \"Please sign in before starting to trade\",\n enableTrading: \"Please sign in before starting to trade\",\n wrongNetwork: \"Please switch to a supported network to continue.\",\n },\n status,\n } = props;\n\n return (\n <Box my={8}>\n <AuthGuard status={status} descriptions={{...hint, switchChain: hint.wrongNetwork}}>\n {props.children || <EmptyDataState />}\n </AuthGuard>\n </Box>\n );\n};\n\nAuthGuardEmpty.displayName = \"AuthGuardEmpty\";\n\nexport { AuthGuardEmpty };\n","import { useAccount } from \"@orderly.network/hooks\";\nimport { useAppContext } from \"@orderly.network/react-app\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\nimport { Tooltip } from \"@orderly.network/ui\";\nimport { PropsWithChildren, useMemo, useState } from \"react\";\n\ntype AuthGuardProps = {\n content?: string;\n align?: \"center\" | \"end\" | \"start\";\n alignOffset?: number;\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n sideOffset?: number;\n opactiy?: number;\n tooltip?: {\n connectWallet?: string;\n signIn?: string;\n enableTrading?: string;\n wrongNetwork?: string;\n };\n};\n\nconst AuthGuardTooltip = (props: PropsWithChildren<AuthGuardProps>) => {\n const {\n opactiy = 90,\n tooltip = {\n connectWallet: \"Please connect wallet before set up\",\n signIn: \"Please sign in before set up\",\n enableTrading: \"Please enable trading before set up\",\n wrongNetwork: \"Please switch to a supported network to set up\",\n },\n } = props;\n const [open, setOpen] = useState(false);\n const { state } = useAccount();\n const isSupport = true;\n const { wrongNetwork } = useAppContext();\n\n const hint = useMemo(() => {\n if (wrongNetwork) {\n return tooltip?.wrongNetwork;\n }\n switch (state.status) {\n case AccountStatusEnum.NotConnected:\n return tooltip?.connectWallet;\n case AccountStatusEnum.NotSignedIn:\n return tooltip?.signIn;\n case AccountStatusEnum.DisabledTrading:\n return tooltip?.enableTrading;\n case AccountStatusEnum.EnableTrading: {\n return \"\";\n }\n default:\n return props.content;\n }\n }, [props.content, state, isSupport, tooltip]);\n\n const newOpacity = useMemo(() => {\n switch (state.status) {\n case AccountStatusEnum.NotConnected:\n case AccountStatusEnum.NotSignedIn:\n return opactiy;\n case AccountStatusEnum.EnableTrading: {\n return undefined;\n }\n default:\n return undefined;\n }\n }, [props.opactiy, state, isSupport]);\n\n return (\n <Tooltip\n open={hint ? open : false}\n onOpenChange={setOpen}\n content={hint}\n className=\"oui-text-2xs\"\n align={props.align}\n alignOffset={props.alignOffset}\n side={props.side}\n sideOffset={props.sideOffset}\n >\n <div\n style={{\n opacity: newOpacity,\n }}\n >\n {props.children}\n </div>\n </Tooltip>\n );\n};\n\nAuthGuardTooltip.displayName = \"AuthGuardTooltip\";\n\nexport { AuthGuardTooltip };\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/component/walletConnectorContent.tsx","../src/component/step.tsx","../src/component/walletConnector.tsx","../src/component/useWalletConnectorBuilder.ts","../src/component/authGuard.tsx","../src/constants/message.ts","../src/component/authGuardDataTable.tsx","../src/component/authGuardEmpty.tsx","../src/component/authGuardTooltip.tsx"],"names":["useEffect","useMemo","useState","Box","Button","capitalizeFirstLetter","Divider","Flex","inputFormatter","Match","modal","Switch","Text","TextField","toast","Tooltip","AccountStatusEnum","CheckedCircleFillIcon","cn","Spinner","jsx","jsxs","StepItem","props","title","description","Identifier","active","isLoading","isCompleted","Dot","className","useAccount","useEventEmitter","useLocalStorage","WalletConnectContent","initAccountState","remember","setRemember","ee","accountState","account","state","setState","activeStep","setActiveStep","loading","setLoading","firstShowDialog","steps","onEnableTrading","res","step","reject","paseErrorMsg","e","onSignIn","index","ReferralCode","RememberMe","ActionButton","signIn","enableTrading","disabled","key","msg","registerSimpleDialog","registerSimpleSheet","useGetReferralCode","useLazyQuery","useMutation","useWalletConnectorBuilder","createOrderlyKey","createAccount","refCode","setRefCode","helpText","setHelpText","verifyRefCode","referral_code","bindRefCode","updateOrderError","updateMutating","enableTradingComplted","checkRefCode","exist","showRefCodeInput","info","WalletConnectorModalId","WalletConnectorSheetId","WalletConnectorWidget","useMediaQuery","MEDIA_TABLET","Either","useScreen","useAppContext","ChainSelectorDialogId","ChainSelectorSheetId","LABELS","DESCRIPTIONS","AuthGuard","status","buttonProps","fallback","descriptions","classNames","networkId","id","bridgeLessOnly","wrongNetwork","disabledConnect","_status","labels","Left","StatusInfo","DefaultFallback","connectWallet","isMobile","matches","onConnectOrderly","r","error","onConnectWallet","switchChain","value","ExtensionPositionEnum","ExtensionSlot","DataTable","useDataTap","AuthGuardDataTable","dataSource","rest","data","ignoreLoadingCheck","GuardView","EmptyDataState","AuthGuardEmpty","hint","AuthGuardTooltip","opactiy","tooltip","open","setOpen","isSupport","newOpacity"],"mappings":"AAAA,OAAa,aAAAA,EAAW,WAAAC,GAAS,YAAAC,MAAgB,QACjD,OACE,OAAAC,EACA,UAAAC,EACA,yBAAAC,GAEA,WAAAC,GACA,QAAAC,EAEA,kBAAAC,GACA,SAAAC,GACA,SAAAC,GACA,UAAAC,GACA,QAAAC,EACA,aAAAC,GACA,SAAAC,EACA,WAAAC,OACK,sBACP,OAAS,qBAAAC,MAAyB,yBCjBlC,OACE,OAAAb,EACA,yBAAAc,GACA,MAAAC,GACA,SAAAT,GACA,WAAAU,GACA,QAAAP,MACK,sBAiBD,OACE,OAAAQ,EADF,QAAAC,MAAA,oBAPC,IAAMC,EAAYC,GAAyB,CAChD,GAAM,CAAE,MAAAC,EA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vCI,EAAa/I,GAAQ,IAAM,CAC/B,OAAQyC,EAAM,OAAQ,CACpB,KAAK1B,EAAkB,aACvB,KAAKA,EAAkB,YACrB,OAAO2H,EACT,KAAK3H,EAAkB,cACrB,OAEF,QACE,MACJ,CACF,EAAG,CAACO,EAAM,QAASmB,EAAOqG,CAAS,CAAC,EAEpC,OACE3H,GAACL,GAAA,CACC,KAAM0H,EAAOI,EAAO,GACpB,aAAcC,EACd,QAASL,EACT,UAAU,eACV,MAAOlH,EAAM,MACb,YAAaA,EAAM,YACnB,KAAMA,EAAM,KACZ,WAAYA,EAAM,WAElB,SAAAH,GAAC,OACC,MAAO,CACL,QAAS4H,CACX,EAEC,SAAAzH,EAAM,SACT,EACF,CAEJ,EAEAmH,GAAiB,YAAc","sourcesContent":["import { FC, useEffect, useMemo, useState } from \"react\";\nimport {\n Box,\n Button,\n capitalizeFirstLetter,\n cn,\n Divider,\n Flex,\n Input,\n inputFormatter,\n Match,\n modal,\n Switch,\n Text,\n TextField,\n toast,\n Tooltip,\n} from \"@orderly.network/ui\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\nimport { StepItem } from \"./step\";\nimport { useAccount, useEventEmitter, useLocalStorage } from \"@orderly.network/hooks\";\n\nexport type WalletConnectContentProps = {\n initAccountState: AccountStatusEnum;\n signIn: () => Promise<any>;\n enableTrading: (remember: boolean) => Promise<any>;\n enableTradingComplted?: () => Promise<void>;\n onCompleted?: () => void;\n close?: () => void;\n refCode: string;\n setRefCode: React.Dispatch<React.SetStateAction<string>>;\n helpText?: string;\n showRefCodeInput: boolean;\n};\n\nexport const WalletConnectContent = (props: WalletConnectContentProps) => {\n const { initAccountState = AccountStatusEnum.NotConnected } = props;\n const [remember, setRemember] = useState(true);\n const ee = useEventEmitter();\n\n\n const { state: accountState, account } = useAccount();\n const [state, setState] = useState(initAccountState);\n const [activeStep, setActiveStep] = useState(0);\n const [loading, setLoading] = useState(false);\n const [firstShowDialog] = useLocalStorage(\n \"orderly-first-show-wallet-connector-dialog\",\n undefined\n );\n useEffect(() => {\n return () => {\n localStorage.setItem(\"orderly-first-show-wallet-connector-dialog\", \"1\");\n };\n }, []);\n\n useEffect(() => {\n setState(accountState.status);\n }, [accountState]);\n\n const steps = useMemo(() => {\n const steps = [];\n if (initAccountState < AccountStatusEnum.SignedIn) {\n steps.push({\n key: \"signIn\",\n title: \"Sign In\",\n description: \"Confirm you are the owner of this wallet\",\n });\n }\n\n if (initAccountState < AccountStatusEnum.EnableTrading) {\n steps.push({\n key: \"enableTrading\",\n title: \"Enable Trading\",\n description:\n \"Enable secure access to our API for lightning fast trading\",\n });\n }\n\n return steps;\n }, [initAccountState]);\n\n const onEnableTrading = () => {\n setLoading(true);\n return props\n .enableTrading(remember)\n .then(\n async (res) => {\n console.log(res);\n setLoading(false);\n setActiveStep((step) => step + 1);\n try {\n await props.enableTradingComplted?.();\n } catch (e) {}\n if (typeof props.onCompleted === \"function\") {\n props.onCompleted();\n } else if (typeof props.close === \"function\") {\n props.close();\n }\n // props.onCompleted?.();\n },\n (reject) => {\n setLoading(false);\n if (reject === -1) return;\n\n if (reject.message.indexOf('Signing off chain messages with Ledger is not yet supported') !== -1) {\n ee.emit(\"wallet:sign-message-with-ledger-error\", {message: reject.message,userAddress: account.address});\n return;\n }\n toast.error(paseErrorMsg(reject));\n }\n )\n .catch((e) => {\n console.log(\"enable trading catch error\", e);\n setLoading(false);\n });\n };\n\n const onSignIn = () => {\n setLoading(true);\n return props\n .signIn()\n .then(\n (res) => {\n setActiveStep((step) => step + 1);\n onEnableTrading();\n },\n (reject) => {\n setLoading(false);\n\n if (reject === -1) return;\n if (reject.message.indexOf('Signing off chain messages with Ledger is not yet supported') !== -1) {\n ee.emit(\"wallet:sign-message-with-ledger-error\", {message: reject.message,userAddress: account.address});\n return;\n }\n\n toast.error(paseErrorMsg(reject));\n }\n )\n .catch((e) => {\n setLoading(false);\n });\n };\n\n console.log(\"state\", state);\n\n return (\n <Box id=\"oui-wallet-connect-dialog-content\" className=\"oui-font-semibold\">\n <Text intensity={54} size=\"xs\">\n Your previous access has expired, you will receive a signature request\n to enable trading. Signing is free and will not send a transaction.\n </Text>\n <Box\n p={4}\n my={6}\n intensity={600}\n r=\"lg\"\n className=\"oui-space-y-5\"\n position={\"relative\"}\n >\n {steps.map((step, index) => {\n return (\n <StepItem\n title={step.title}\n description={step.description}\n isCompleted={activeStep > index}\n key={step.key}\n active={activeStep === index}\n isLoading={loading && activeStep === index}\n />\n );\n })}\n {steps.length > 1 && (\n <Box\n position={\"absolute\"}\n height={\"38px\"}\n left={28}\n top={18}\n zIndex={0}\n >\n <Divider\n lineStyle={\"dashed\"}\n direction={\"vertical\"}\n intensity={16}\n className=\"oui-h-full\"\n />\n </Box>\n )}\n </Box>\n {props.showRefCodeInput && steps.length == 2 && (\n <ReferralCode {...props} />\n )}\n {firstShowDialog && (\n <Flex justify={\"between\"} itemAlign={\"center\"}>\n <RememberMe />\n <Switch\n color={\"primary\"}\n checked={remember}\n onCheckedChange={setRemember}\n disabled={loading}\n className=\"data-[state=checked]:oui-bg-primary-darken\"\n />\n </Flex>\n )}\n <Flex justify={\"center\"} mt={8}>\n <Box width={\"45%\"}>\n <ActionButton\n state={state}\n signIn={onSignIn}\n enableTrading={onEnableTrading}\n loading={loading}\n disabled={state >= AccountStatusEnum.EnableTrading}\n />\n </Box>\n </Flex>\n </Box>\n );\n};\n\nconst ActionButton: FC<{\n state: AccountStatusEnum;\n signIn: () => Promise<any>;\n enableTrading: () => Promise<any>;\n loading: boolean;\n disabled?: boolean;\n}> = ({ state, signIn, enableTrading, loading, disabled }) => {\n return (\n <Match\n value={() => {\n if (state <= AccountStatusEnum.NotSignedIn) {\n return \"signIn\";\n }\n return \"enableTrading\";\n }}\n case={{\n signIn: (\n <Button\n fullWidth\n onClick={() => signIn()}\n loading={loading}\n disabled={disabled}\n >\n Sign In\n </Button>\n ),\n enableTrading: (\n <Button\n fullWidth\n onClick={() => enableTrading()}\n loading={loading}\n disabled={disabled}\n >\n Enable Trading\n </Button>\n ),\n }}\n />\n );\n};\n\nconst ReferralCode: FC<WalletConnectContentProps> = (props) => {\n return (\n <TextField\n placeholder=\"Referral code (Optional)\"\n fullWidth\n // label={\"Referral code (optional)\"}\n label=\"\"\n value={props.refCode}\n onChange={(e) => {\n props.setRefCode(e.target.value);\n }}\n classNames={{\n label: \"oui-text-base-contrast-54 oui-text-xs\",\n input: \"placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm\",\n }}\n formatters={[inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)]}\n onClear={() => {\n props.setRefCode(\"\");\n }}\n autoComplete=\"off\"\n helpText={props.helpText}\n className=\"oui-mb-4\"\n color={props.helpText ? \"danger\" : undefined}\n />\n );\n};\n\nconst RememberMe = () => {\n const showRememberHint = () => {\n if (window.innerWidth > 768) return;\n modal.alert({\n title: \"Remember me\",\n message: (\n <span className=\"oui-text-2xs oui-text-base-contrast/60\">\n Toggle this option to skip these steps next time you want to trade.\n </span>\n ),\n });\n };\n return (\n <Tooltip\n content={\n \"Toggle this option to skip these steps next time you want to trade.\"\n }\n className=\"oui-max-w-[300px]\"\n >\n <button onClick={showRememberHint}>\n <Text\n intensity={54}\n size={\"xs\"}\n className={\n \"oui-underline oui-underline-offset-4 oui-decoration-dashed oui-decoration-base-contrast-36\"\n }\n >\n Remember me\n </Text>\n </button>\n </Tooltip>\n );\n};\n\nfunction paseErrorMsg(reject: any): string {\n console.log(\"wallet callback error\", reject);\n console.log(\"message *** \", \"reject keys\", Object.keys(reject));\n Object.keys(reject).forEach((key) => {\n console.log(\"key\", key, \"-\", reject[key]);\n });\n let msg = \"Something went wrong\";\n\n // if (typeof reject?.info?.error === \"object\" && \"message\" in reject?.info?.error) {\n // msg = reject?.info?.error?.message;\n // }\n\n // if (typeof reject?.shortMessage === 'string') {\n // msg = reject.shortMessage;\n // }\n\n if (reject.toString().includes(\"rejected\")) {\n msg = \"User rejected the request.\";\n }\n\n\n return capitalizeFirstLetter(msg) ?? msg;\n}\n\n","import { FC } from \"react\";\nimport {\n Box,\n CheckedCircleFillIcon,\n cn,\n Match,\n Spinner,\n Text,\n} from \"@orderly.network/ui\";\n\ntype StepItemProps = {\n active?: boolean;\n isLoading?: boolean;\n isCompleted?: boolean;\n title: string;\n description: string;\n};\n\nexport const StepItem = (props: StepItemProps) => {\n const { title, description } = props;\n\n // console.log(props);\n\n return (\n <Box position=\"relative\" className=\"oui-pl-8\">\n <Box>\n <Text as=\"div\" intensity={98} size={\"sm\"}>\n {title}\n </Text>\n <Text as=\"div\" intensity={54} size={\"2xs\"}>\n {description}\n </Text>\n </Box>\n <Identifier {...props} />\n </Box>\n );\n};\n\nconst Identifier = (props: {\n active?: boolean;\n isLoading?: boolean;\n isCompleted?: boolean;\n}) => {\n const { active, isLoading, isCompleted } = props;\n\n return (\n <Match\n className={\"oui-absolute oui-left-0 oui-top-1 oui-z-10\"}\n value={() => {\n if (isCompleted) {\n return \"completed\";\n }\n if (isLoading) {\n return \"loading\";\n }\n\n if (active) {\n return \"active\";\n }\n\n return \"normal\";\n }}\n case={{\n loading: (\n <div>\n <Spinner size={\"sm\"} className={\"oui-ml-1\"} />\n </div>\n ),\n completed: (\n <div>\n <CheckedCircleFillIcon opacity={1} className=\"oui-text-primary\" />\n </div>\n ),\n }}\n default={<Dot active={!!active} />}\n />\n );\n};\n\nconst Dot: FC<{ active: boolean; className?: string }> = ({\n active,\n className,\n}) => {\n return (\n <div\n className={cn(\n \"oui-w-[8.3px] oui-h-[8.3px] oui-rounded-full oui-ml-2 oui-mt-1\",\n className,\n active ? \"oui-bg-primary-light\" : \"oui-bg-base-2\"\n )}\n />\n );\n};\n","import { registerSimpleDialog, registerSimpleSheet } from \"@orderly.network/ui\";\n\nimport { useWalletConnectorBuilder } from \"./useWalletConnectorBuilder\";\nimport { WalletConnectContent } from \"./walletConnectorContent\";\n\nexport const WalletConnectorModalId = \"walletConnector\" as const;\nexport const WalletConnectorSheetId = \"walletConnectorSheet\" as const;\n\nexport const WalletConnectorWidget = (props: any) => {\n const state = useWalletConnectorBuilder();\n return <WalletConnectContent {...state} {...props} />;\n};\n\nregisterSimpleDialog(WalletConnectorModalId, WalletConnectorWidget, {\n size: \"sm\",\n title: \"Connect wallet\",\n});\n\nregisterSimpleSheet(WalletConnectorSheetId, WalletConnectorWidget, {\n title: \"Connect wallet\",\n});\n","import {\n useAccount,\n useCheckReferralCode,\n useGetReferralCode,\n useLazyQuery,\n useMutation,\n} from \"@orderly.network/hooks\";\nimport { toast } from \"@orderly.network/ui\";\nimport { useEffect, useMemo, useState } from \"react\";\n\n\nexport const useWalletConnectorBuilder = () => {\n const { account, state, createOrderlyKey, createAccount } = useAccount();\n const [refCode, setRefCode] = useState(\"\");\n const [helpText, setHelpText] = useState(\"\");\n\n const { trigger: verifyRefCode } = useLazyQuery(\n `/v1/public/referral/verify_ref_code?referral_code=${refCode}`\n );\n\n useEffect(() => {\n const refCode = localStorage.getItem(\"referral_code\");\n if (refCode != null) {\n setRefCode(refCode);\n }\n }, []);\n\n const { referral_code, isLoading } = useGetReferralCode(account.accountId);\n\n const [bindRefCode, { error: updateOrderError, isMutating: updateMutating }] =\n useMutation(\"/v1/referral/bind\", \"POST\");\n\n useEffect(() => {\n if (refCode.length === 0) {\n setHelpText(\"\");\n }\n }, [refCode]);\n\n const enableTradingComplted = () => {\n toast.success(\"Wallet connected\");\n // validate ref code and bind referral code\n if (refCode.length >= 4 && refCode.length <= 10)\n bindRefCode({ referral_code: refCode }).finally(() => {\n localStorage.removeItem(\"referral_code\");\n });\n };\n\n const checkRefCode = async (): Promise<string | undefined> => {\n if (refCode.length === 0) return Promise.resolve(undefined);\n\n if (refCode.length > 0 && (refCode.length < 4 || refCode.length > 10)) {\n return Promise.resolve(\n \"The referral_code must be 4 to 10 characters long, only accept upper case roman characters and numbers\"\n );\n }\n\n const { exist } = await verifyRefCode();\n \n\n if (exist === false) {\n return Promise.resolve(\"This referral code does not exist.\");\n }\n\n return Promise.resolve(undefined);\n };\n\n\n const showRefCodeInput = (referral_code?.length || 0) === 0 && !isLoading;\n\n\n const signIn = async () => {\n if (showRefCodeInput) {\n const info = await checkRefCode();\n if (typeof info !== \"undefined\") {\n setHelpText(info);\n return Promise.reject(-1);\n }\n }\n setHelpText(\"\");\n return createAccount();\n };\n\n const enableTrading = async (remember: boolean) => {\n if (showRefCodeInput) {\n const info = await checkRefCode();\n if (typeof info !== \"undefined\") {\n setHelpText(info);\n return Promise.reject(-1);\n }\n }\n setHelpText(\"\");\n return createOrderlyKey(remember);\n };\n\n return {\n enableTrading,\n initAccountState: state.status,\n signIn,\n enableTradingComplted,\n refCode,\n setRefCode,\n helpText,\n showRefCodeInput,\n } as const;\n};\n","import { useAccount, useMediaQuery } from \"@orderly.network/hooks\";\nimport {\n AccountStatusEnum,\n MEDIA_TABLET,\n NetworkId,\n} from \"@orderly.network/types\";\nimport {\n Button,\n Either,\n Match,\n modal,\n Text,\n toast,\n useScreen,\n type ButtonProps,\n} from \"@orderly.network/ui\";\nimport { useAppContext } from \"@orderly.network/react-app\";\nimport { PropsWithChildren, ReactElement, useMemo } from \"react\";\nimport {\n WalletConnectorModalId,\n WalletConnectorSheetId,\n} from \"./walletConnector\";\nimport {\n ChainSelectorDialogId,\n ChainSelectorSheetId,\n} from \"@orderly.network/ui-chain-selector\";\nimport { alertMessages, DESCRIPTIONS, LABELS } from \"../constants/message\";\nimport { Flex } from \"@orderly.network/ui\";\nimport { Box } from \"@orderly.network/ui\";\n\ntype ChainProps = {\n networkId?: NetworkId;\n bridgeLessOnly?: boolean;\n};\n\nexport type AuthGuardProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {\n fallback?: (props: {\n validating: boolean;\n status: AccountStatusEnum;\n wrongNetwork: boolean;\n }) => ReactElement;\n // indicator?: ReactElement;\n /**\n * Required state to be satisfied\n * @default AccountStatusEnum.EnableTrading\n */\n status?: AccountStatusEnum;\n\n bridgeLessOnly?: boolean;\n\n buttonProps?: ButtonProps;\n\n descriptions?: alertMessages;\n\n labels?: alertMessages;\n\n classNames?: {\n root?: string;\n description?: string;\n // button?: string;\n };\n\n networkId?: NetworkId;\n\n // validatingIndicator?: ReactElement;\n};\n\nconst AuthGuard = (props: PropsWithChildren<AuthGuardProps>) => {\n const {\n status,\n buttonProps,\n fallback,\n descriptions,\n classNames,\n networkId,\n id,\n bridgeLessOnly,\n // ...rest\n } = props;\n const { state } = useAccount();\n const { wrongNetwork, disabledConnect } = useAppContext();\n\n const _status = useMemo(() => {\n if (status === undefined) {\n return state.status === AccountStatusEnum.EnableTradingWithoutConnected\n ? AccountStatusEnum.EnableTradingWithoutConnected\n : AccountStatusEnum.EnableTrading;\n }\n return status;\n }, [status, state.status]);\n\n const labels = { ...LABELS, ...props.labels };\n\n // return Match(state.status)\n // .with(AccountStatusEnum.EnableTrading, () => props.children)\n // .with(AccountStatusEnum.DisableTrading, () => props.fallback)\n // .with(AccountStatusEnum.Validating, () => props.validatingIndicator)\n // .otherwise(() => props.fallback);\n //\n\n const Left = useMemo<ReactElement>(() => {\n if (typeof fallback !== \"undefined\") {\n return fallback({\n validating: state.validating,\n status: state.status,\n wrongNetwork,\n });\n }\n\n if (state.validating && !disabledConnect) {\n return (\n <StatusInfo\n // variant={\"gradient\"}\n angle={45}\n // fullWidth\n disabled\n loading\n description={descriptions?.connectWallet}\n id={id}\n type=\"button\"\n {...buttonProps}\n >\n {labels.connectWallet}\n </StatusInfo>\n );\n }\n\n return (\n <DefaultFallback\n bridgeLessOnly={bridgeLessOnly}\n status={state.status}\n buttonProps={{ ...buttonProps, id, type: \"button\" }}\n wrongNetwork={wrongNetwork}\n networkId={props.networkId}\n labels={labels}\n descriptions={descriptions}\n disabledConnect={disabledConnect}\n />\n );\n }, [state.status, state.validating, buttonProps, wrongNetwork]);\n\n /**\n * **Important: The chldren component will be rendered only if the status is equal to the required status and the network is correct.**\n */\n\n return (\n <Either\n value={state.status >= _status && !wrongNetwork && !disabledConnect}\n left={Left}\n >\n {props.children}\n </Either>\n );\n};\n\nconst DefaultFallback = (props: {\n status: AccountStatusEnum;\n wrongNetwork: boolean;\n buttonProps?: ButtonProps;\n networkId?: NetworkId;\n labels: alertMessages;\n bridgeLessOnly?: boolean;\n descriptions?: alertMessages;\n disabledConnect?: boolean;\n}) => {\n const { buttonProps, labels, descriptions } = props;\n const { connectWallet } = useAppContext();\n const { account } = useAccount();\n const { isMobile } = useScreen();\n const matches = useMediaQuery(MEDIA_TABLET);\n const onConnectOrderly = () => {\n modal.show(matches ? WalletConnectorSheetId : WalletConnectorModalId).then(\n (r) => console.log(r),\n (error) => console.log(error)\n );\n };\n\n const onConnectWallet = async () => {\n const res = await connectWallet();\n\n if (!res) return;\n\n if (res.wrongNetwork) {\n switchChain();\n } else {\n if (\n (res?.status ?? AccountStatusEnum.NotConnected) <\n AccountStatusEnum.EnableTrading\n ) {\n onConnectOrderly();\n }\n }\n };\n\n const switchChain = () => {\n account.once(\"validate:end\", (status) => {\n if (status < AccountStatusEnum.EnableTrading) {\n onConnectOrderly();\n } else {\n toast.success(\"Wallet connected\");\n }\n });\n\n modal\n .show<{\n wrongNetwork: boolean;\n }>(isMobile ? ChainSelectorSheetId : ChainSelectorDialogId, {\n networkId: props.networkId,\n bridgeLessOnly: props.bridgeLessOnly,\n })\n .then(\n (r) => {\n if (!r.wrongNetwork) {\n if (props.status >= AccountStatusEnum.Connected) {\n if (props.status < AccountStatusEnum.EnableTrading) {\n onConnectOrderly();\n } else {\n toast.success(\"Wallet connected\");\n }\n }\n }\n },\n (error) => console.log(\"[switchChain error]\", error)\n );\n };\n\n if (props.wrongNetwork && !props.disabledConnect) {\n return (\n <StatusInfo\n color=\"warning\"\n // size=\"md\"\n // fullWidth\n onClick={() => {\n switchChain();\n }}\n description={descriptions?.switchChain}\n {...buttonProps}\n >\n {labels.switchChain}\n </StatusInfo>\n );\n }\n\n return (\n <Match\n value={props.status}\n case={(value: AccountStatusEnum) => {\n if (value <= AccountStatusEnum.NotConnected || props.disabledConnect) {\n return (\n <StatusInfo\n size=\"lg\"\n onClick={() => {\n onConnectWallet();\n }}\n // fullWidth\n variant={props.disabledConnect ? undefined : \"gradient\"}\n angle={45}\n description={descriptions?.connectWallet}\n disabled={props.disabledConnect}\n {...buttonProps}\n >\n {labels.connectWallet}\n </StatusInfo>\n );\n }\n if (value <= AccountStatusEnum.NotSignedIn) {\n return (\n <StatusInfo\n size=\"lg\"\n onClick={() => {\n onConnectOrderly();\n }}\n // fullWidth\n angle={45}\n description={descriptions?.signin}\n {...buttonProps}\n >\n {labels.signin}\n </StatusInfo>\n );\n }\n }}\n default={\n <StatusInfo\n size=\"lg\"\n // fullWidth\n description={descriptions?.enableTrading}\n {...buttonProps}\n onClick={() => onConnectOrderly()}\n >\n {labels.enableTrading}\n </StatusInfo>\n }\n />\n );\n};\n\nAuthGuard.displayName = \"AuthGuard\";\n\nconst StatusInfo = (\n props: ButtonProps & {\n description?: string;\n }\n) => {\n const { description, ...buttonProps } = props;\n return (\n <Flex direction={\"column\"}>\n <Button {...buttonProps}></Button>\n {!!description && (\n <Box mt={4} className=\"oui-leading-none\" style={{ lineHeight: 0 }}>\n <Text size=\"2xs\" intensity={36}>\n {description}\n </Text>\n </Box>\n )}\n </Flex>\n );\n};\n\nexport { AuthGuard };\n","export type alertMessages = {\n connectWallet?: string;\n switchChain?: string;\n enableTrading?: string;\n signin?: string;\n};\n\nexport const LABELS = {\n connectWallet: \"Connect wallet\",\n switchChain: \"Wrong network\",\n enableTrading: \"Enable trading\",\n signin: \"Sign in\",\n};\n\nexport const DESCRIPTIONS: alertMessages = {\n connectWallet: \"Please Connect wallet before starting to trade\",\n switchChain: \"Please switch to a supported network to continue\",\n enableTrading: \"Please Enable trading before starting to trade\",\n signin: \"Please sign in before starting to trade\",\n};\n","import { PropsWithChildren, useMemo } from \"react\";\nimport {\n ExtensionPositionEnum,\n ExtensionSlot,\n DataTable,\n DataTableProps,\n} from \"@orderly.network/ui\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\nimport { alertMessages, DESCRIPTIONS } from \"../constants/message\";\nimport { useAppContext, useDataTap } from \"@orderly.network/react-app\";\nimport { Flex } from \"@orderly.network/ui\";\nimport { AuthGuard } from \"./authGuard\";\nimport { useAccount } from \"@orderly.network/hooks\";\n\nexport const AuthGuardDataTable = <RecordType extends unknown>(\n props: PropsWithChildren<\n DataTableProps<RecordType> &\n Omit<GuardViewProps, \"status\"> & {\n status?: AccountStatusEnum;\n classNames?: DataTableProps<RecordType>[\"classNames\"] & {\n authGuardDescription?: string;\n };\n }\n >\n) => {\n const {\n status,\n // message,\n labels,\n description,\n dataSource,\n ...rest\n } = props;\n const { state } = useAccount();\n const { wrongNetwork, disabledConnect } = useAppContext();\n\n const _status = useMemo(() => {\n if (status === undefined) {\n return state.status === AccountStatusEnum.EnableTradingWithoutConnected\n ? AccountStatusEnum.EnableTradingWithoutConnected\n : AccountStatusEnum.EnableTrading;\n }\n return status;\n }, [status, state.status]);\n\n const data = useDataTap(dataSource, {\n accountStatus: _status,\n });\n\n const ignoreLoadingCheck =\n wrongNetwork ||\n disabledConnect ||\n state.status < _status ||\n props.ignoreLoadingCheck;\n\n return (\n <DataTable\n dataSource={data}\n ignoreLoadingCheck={ignoreLoadingCheck}\n emptyView={\n <GuardView\n status={_status}\n description={description}\n labels={labels}\n className={props.classNames?.authGuardDescription}\n visible={!state.validating}\n />\n }\n manualPagination\n {...rest}\n />\n );\n};\n\ntype GuardViewProps = {\n status: AccountStatusEnum;\n description?: alertMessages;\n labels?: alertMessages;\n className?: string;\n visible?: boolean;\n};\n\nconst GuardView = (props: GuardViewProps) => {\n const descriptions = { ...DESCRIPTIONS, ...props.description };\n if (!props.visible) return null;\n return (\n <Flex py={8}>\n <AuthGuard\n status={props.status}\n labels={props.labels}\n descriptions={descriptions}\n buttonProps={{\n size: \"md\",\n }}\n >\n <ExtensionSlot position={ExtensionPositionEnum.EmptyDataIdentifier} />\n </AuthGuard>\n </Flex>\n );\n};\n","import { AccountStatusEnum } from \"@orderly.network/types\";\nimport {\n Box,\n EmptyDataState,\n} from \"@orderly.network/ui\";\nimport { PropsWithChildren } from \"react\";\nimport { AuthGuard } from \"./authGuard\";\n\ntype AuthGuardProps = {\n /** default value is\n * ```ts\n * {\n * connectWallet: \"Please connect wallet before starting to trade\",\n * signIn: \"Please sign in before starting to trade\",\n * enableTrading: \"Please sign in before starting to trade\",\n * wrongNetwork: \"Please switch to a supported network to continue.\",\n * }\n * ```\n */\n hint?: {\n connectWallet?: string;\n signIn?: string;\n enableTrading?: string;\n wrongNetwork?: string;\n };\n status?: AccountStatusEnum;\n};\n\nconst AuthGuardEmpty = (props: PropsWithChildren<AuthGuardProps>) => {\n const {\n hint = {\n connectWallet: \"Please connect wallet before starting to trade\",\n signIn: \"Please sign in before starting to trade\",\n enableTrading: \"Please sign in before starting to trade\",\n wrongNetwork: \"Please switch to a supported network to continue.\",\n },\n status,\n } = props;\n\n return (\n <Box my={8}>\n <AuthGuard status={status} descriptions={{...hint, switchChain: hint.wrongNetwork}}>\n {props.children || <EmptyDataState />}\n </AuthGuard>\n </Box>\n );\n};\n\nAuthGuardEmpty.displayName = \"AuthGuardEmpty\";\n\nexport { AuthGuardEmpty };\n","import { useAccount } from \"@orderly.network/hooks\";\nimport { useAppContext } from \"@orderly.network/react-app\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\nimport { Tooltip } from \"@orderly.network/ui\";\nimport { PropsWithChildren, useMemo, useState } from \"react\";\n\ntype AuthGuardProps = {\n content?: string;\n align?: \"center\" | \"end\" | \"start\";\n alignOffset?: number;\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n sideOffset?: number;\n opactiy?: number;\n tooltip?: {\n connectWallet?: string;\n signIn?: string;\n enableTrading?: string;\n wrongNetwork?: string;\n };\n};\n\nconst AuthGuardTooltip = (props: PropsWithChildren<AuthGuardProps>) => {\n const {\n opactiy = 90,\n tooltip = {\n connectWallet: \"Please connect wallet before set up\",\n signIn: \"Please sign in before set up\",\n enableTrading: \"Please enable trading before set up\",\n wrongNetwork: \"Please switch to a supported network to set up\",\n },\n } = props;\n const [open, setOpen] = useState(false);\n const { state } = useAccount();\n const isSupport = true;\n const { wrongNetwork } = useAppContext();\n\n const hint = useMemo(() => {\n if (wrongNetwork) {\n return tooltip?.wrongNetwork;\n }\n switch (state.status) {\n case AccountStatusEnum.NotConnected:\n return tooltip?.connectWallet;\n case AccountStatusEnum.NotSignedIn:\n return tooltip?.signIn;\n case AccountStatusEnum.DisabledTrading:\n return tooltip?.enableTrading;\n case AccountStatusEnum.EnableTrading: {\n return \"\";\n }\n default:\n return props.content;\n }\n }, [props.content, state, isSupport, tooltip]);\n\n const newOpacity = useMemo(() => {\n switch (state.status) {\n case AccountStatusEnum.NotConnected:\n case AccountStatusEnum.NotSignedIn:\n return opactiy;\n case AccountStatusEnum.EnableTrading: {\n return undefined;\n }\n default:\n return undefined;\n }\n }, [props.opactiy, state, isSupport]);\n\n return (\n <Tooltip\n open={hint ? open : false}\n onOpenChange={setOpen}\n content={hint}\n className=\"oui-text-2xs\"\n align={props.align}\n alignOffset={props.alignOffset}\n side={props.side}\n sideOffset={props.sideOffset}\n >\n <div\n style={{\n opacity: newOpacity,\n }}\n >\n {props.children}\n </div>\n </Tooltip>\n );\n};\n\nAuthGuardTooltip.displayName = \"AuthGuardTooltip\";\n\nexport { AuthGuardTooltip };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orderly.network/ui-connector",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@orderly.network/hooks": "2.0.
|
|
21
|
-
"@orderly.network/ui": "2.0.
|
|
22
|
-
"@orderly.network/types": "2.0.
|
|
23
|
-
"@orderly.network/react-app": "2.0.
|
|
24
|
-
"@orderly.network/ui
|
|
20
|
+
"@orderly.network/hooks": "2.0.7",
|
|
21
|
+
"@orderly.network/ui-chain-selector": "2.0.7",
|
|
22
|
+
"@orderly.network/types": "2.0.7",
|
|
23
|
+
"@orderly.network/react-app": "2.0.7",
|
|
24
|
+
"@orderly.network/ui": "2.0.7"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/react": "^18.3.2",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"react-dom": "^18.2.0",
|
|
31
31
|
"tailwindcss": "^3.4.4",
|
|
32
32
|
"tsup": "^7.3.0",
|
|
33
|
-
"tsconfig": "0.3.
|
|
33
|
+
"tsconfig": "0.3.22"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": ">=18",
|