├── .eslintrc.js ├── .github ├── dependabot.yml └── workflows │ ├── main.yml │ └── release.yml ├── .gitignore ├── .husky └── pre-commit ├── .prettierignore ├── .vscode ├── extensions.json └── settings.json ├── .yarn ├── plugins │ └── @yarnpkg │ │ ├── plugin-interactive-tools.cjs │ │ └── plugin-typescript.cjs ├── releases │ └── yarn-4.0.0-rc.6.cjs └── sdks │ ├── eslint │ ├── bin │ │ └── eslint.js │ ├── lib │ │ └── api.js │ └── package.json │ ├── integrations.yml │ ├── prettier │ ├── index.js │ └── package.json │ └── typescript │ ├── bin │ ├── tsc │ └── tsserver │ ├── lib │ ├── tsc.js │ ├── tsserver.js │ ├── tsserverlibrary.js │ └── typescript.js │ └── package.json ├── .yarnrc.yml ├── LICENSE ├── README.md ├── images ├── banner.png ├── wallet-intro.png └── wallet-select.png ├── lerna.json ├── package.json ├── packages ├── example │ ├── .gitignore │ ├── README.md │ ├── craco.config.js │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ ├── src │ │ ├── App.tsx │ │ ├── Body.tsx │ │ ├── index.css │ │ ├── index.tsx │ │ └── react-app-env.d.ts │ └── tsconfig.json └── walletkit │ ├── README.md │ ├── package.json │ ├── src │ ├── WalletKitProvider.tsx │ ├── components │ │ ├── ConnectWalletButton │ │ │ └── index.tsx │ │ ├── LabeledInput.tsx │ │ ├── Modal │ │ │ ├── icons.tsx │ │ │ └── index.tsx │ │ └── WalletSelectorModal │ │ │ ├── ButtonWithFooter.tsx │ │ │ ├── WalletStepConnecting │ │ │ ├── ConnectingAnimation.tsx │ │ │ └── index.tsx │ │ │ ├── WalletStepIntro │ │ │ ├── DefaultAppIcon.tsx │ │ │ ├── Detail.tsx │ │ │ ├── icons.tsx │ │ │ └── index.tsx │ │ │ ├── WalletStepLedgerAdvanced │ │ │ └── index.tsx │ │ │ ├── WalletStepRedirect │ │ │ └── index.tsx │ │ │ ├── WalletStepSecretKey │ │ │ └── index.tsx │ │ │ ├── WalletStepSelect │ │ │ ├── WalletProviderOption.tsx │ │ │ └── index.tsx │ │ │ └── index.tsx │ ├── index.ts │ └── types.ts │ ├── tsconfig.cjs.json │ └── tsconfig.json ├── tsconfig.json └── yarn.lock /.eslintrc.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | require("@rushstack/eslint-patch/modern-module-resolution"); 4 | 5 | module.exports = { 6 | extends: ["@saberhq/eslint-config-react"], 7 | env: { 8 | browser: true, 9 | es2021: true, 10 | }, 11 | ignorePatterns: ["*.js"], 12 | parserOptions: { 13 | project: "tsconfig.json", 14 | }, 15 | }; 16 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | 8 | - package-ecosystem: "github-actions" 9 | directory: "/" 10 | schedule: 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | pull_request: 7 | branches: [master] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Checkout repo 15 | uses: actions/checkout@v3 16 | - uses: actions/setup-node@v3 17 | - name: Get yarn cache directory path 18 | id: yarn-cache-dir-path 19 | run: echo "::set-output name=dir::$(yarn config get cacheFolder)" 20 | - name: Yarn Cache 21 | uses: actions/cache@v3.0.2 22 | with: 23 | path: ${{ steps.yarn-cache-dir-path.outputs.dir }} 24 | key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} 25 | restore-keys: | 26 | ${{ runner.os }}-modules- 27 | - run: yarn install 28 | - run: yarn build 29 | - run: yarn typecheck 30 | - run: yarn lint:ci 31 | - run: yarn doctor 32 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | workflow_dispatch: {} 5 | push: 6 | tags: 7 | - "v*.*.*" 8 | 9 | jobs: 10 | programs: 11 | runs-on: ubuntu-latest 12 | name: Build and publish the SDK 13 | steps: 14 | - uses: actions/checkout@v3 15 | - name: Setup Node 16 | uses: actions/setup-node@v3 17 | with: 18 | registry-url: "https://registry.npmjs.org" 19 | - name: Get yarn cache directory path 20 | id: yarn-cache-dir-path 21 | run: echo "::set-output name=dir::$(yarn config get cacheFolder)" 22 | - name: Yarn Cache 23 | uses: actions/cache@v3.0.2 24 | with: 25 | path: ${{ steps.yarn-cache-dir-path.outputs.dir }} 26 | key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} 27 | restore-keys: | 28 | ${{ runner.os }}-modules- 29 | - run: yarn install 30 | - run: yarn build 31 | - name: Publish 32 | run: | 33 | echo 'npmAuthToken: "${NODE_AUTH_TOKEN}"' >> .yarnrc.yml 34 | git update-index --assume-unchanged .yarnrc.yml 35 | yarn lerna publish --yes from-package --no-verify-access 36 | env: 37 | NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} 38 | 39 | gh-pages: 40 | runs-on: ubuntu-latest 41 | steps: 42 | - name: Checkout 🛎️ 43 | uses: actions/checkout@v3 44 | - name: Setup Node 45 | uses: actions/setup-node@v3 46 | - name: Get yarn cache directory path 47 | id: yarn-cache-dir-path 48 | run: echo "::set-output name=dir::$(yarn config get cacheFolder)" 49 | - name: Yarn Cache 50 | uses: actions/cache@v3.0.2 51 | with: 52 | path: ${{ steps.yarn-cache-dir-path.outputs.dir }} 53 | key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} 54 | restore-keys: | 55 | ${{ runner.os }}-modules- 56 | - run: yarn install 57 | - run: yarn build 58 | - name: Deploy 🚀 59 | uses: JamesIves/github-pages-deploy-action@v4.3.3 60 | with: 61 | branch: gh-pages 62 | folder: packages/example/build/ 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Node ### 2 | # Logs 3 | logs 4 | *.log 5 | npm-debug.log* 6 | yarn-debug.log* 7 | yarn-error.log* 8 | lerna-debug.log* 9 | .pnpm-debug.log* 10 | 11 | # Diagnostic reports (https://nodejs.org/api/report.html) 12 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 13 | 14 | # Runtime data 15 | pids 16 | *.pid 17 | *.seed 18 | *.pid.lock 19 | 20 | # Directory for instrumented libs generated by jscoverage/JSCover 21 | lib-cov 22 | 23 | # Coverage directory used by tools like istanbul 24 | coverage 25 | *.lcov 26 | 27 | # nyc test coverage 28 | .nyc_output 29 | 30 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 31 | .grunt 32 | 33 | # Bower dependency directory (https://bower.io/) 34 | bower_components 35 | 36 | # node-waf configuration 37 | .lock-wscript 38 | 39 | # Compiled binary addons (https://nodejs.org/api/addons.html) 40 | build/Release 41 | 42 | # Dependency directories 43 | node_modules/ 44 | jspm_packages/ 45 | 46 | # Snowpack dependency directory (https://snowpack.dev/) 47 | web_modules/ 48 | 49 | # TypeScript cache 50 | *.tsbuildinfo 51 | 52 | # Optional npm cache directory 53 | .npm 54 | 55 | # Optional eslint cache 56 | .eslintcache 57 | 58 | # Microbundle cache 59 | .rpt2_cache/ 60 | .rts2_cache_cjs/ 61 | .rts2_cache_es/ 62 | .rts2_cache_umd/ 63 | 64 | # Optional REPL history 65 | .node_repl_history 66 | 67 | # Output of 'npm pack' 68 | *.tgz 69 | 70 | # Yarn Integrity file 71 | .yarn-integrity 72 | 73 | # dotenv environment variables file 74 | .env 75 | .env.test 76 | .env.production 77 | 78 | # parcel-bundler cache (https://parceljs.org/) 79 | .cache 80 | .parcel-cache 81 | 82 | # Next.js build output 83 | .next 84 | out 85 | 86 | # Nuxt.js build / generate output 87 | .nuxt 88 | dist 89 | 90 | # Gatsby files 91 | .cache/ 92 | # Comment in the public line in if your project uses Gatsby and not Next.js 93 | # https://nextjs.org/blog/next-9-1#public-directory-support 94 | # public 95 | 96 | # vuepress build output 97 | .vuepress/dist 98 | 99 | # Serverless directories 100 | .serverless/ 101 | 102 | # FuseBox cache 103 | .fusebox/ 104 | 105 | # DynamoDB Local files 106 | .dynamodb/ 107 | 108 | # TernJS port file 109 | .tern-port 110 | 111 | # Stores VSCode versions used for testing VSCode extensions 112 | .vscode-test 113 | 114 | # yarn v2 115 | .yarn/* 116 | !.yarn/patches 117 | !.yarn/releases 118 | !.yarn/plugins 119 | !.yarn/sdks 120 | !.yarn/versions 121 | .pnp.* 122 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn lint-staged 5 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .yarn/ 2 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "arcanis.vscode-zipfs", 4 | "dbaeumer.vscode-eslint", 5 | "esbenp.prettier-vscode" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": ".yarn/sdks/typescript/lib", 3 | "search.exclude": { 4 | "**/.yarn": true, 5 | "**/.pnp.*": true 6 | }, 7 | "eslint.nodePath": ".yarn/sdks", 8 | "prettier.prettierPath": ".yarn/sdks/prettier/index.js", 9 | "typescript.enablePromptUseWorkspaceTsdk": true 10 | } 11 | -------------------------------------------------------------------------------- /.yarn/plugins/@yarnpkg/plugin-typescript.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | //prettier-ignore 3 | module.exports = { 4 | name: "@yarnpkg/plugin-typescript", 5 | factory: function (require) { 6 | var plugin=(()=>{var Ft=Object.create,H=Object.defineProperty,Bt=Object.defineProperties,Kt=Object.getOwnPropertyDescriptor,zt=Object.getOwnPropertyDescriptors,Gt=Object.getOwnPropertyNames,Q=Object.getOwnPropertySymbols,$t=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty,De=Object.prototype.propertyIsEnumerable;var Re=(e,t,r)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,u=(e,t)=>{for(var r in t||(t={}))ne.call(t,r)&&Re(e,r,t[r]);if(Q)for(var r of Q(t))De.call(t,r)&&Re(e,r,t[r]);return e},g=(e,t)=>Bt(e,zt(t)),Lt=e=>H(e,"__esModule",{value:!0});var R=(e,t)=>{var r={};for(var s in e)ne.call(e,s)&&t.indexOf(s)<0&&(r[s]=e[s]);if(e!=null&&Q)for(var s of Q(e))t.indexOf(s)<0&&De.call(e,s)&&(r[s]=e[s]);return r};var I=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Vt=(e,t)=>{for(var r in t)H(e,r,{get:t[r],enumerable:!0})},Qt=(e,t,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Gt(t))!ne.call(e,s)&&s!=="default"&&H(e,s,{get:()=>t[s],enumerable:!(r=Kt(t,s))||r.enumerable});return e},C=e=>Qt(Lt(H(e!=null?Ft($t(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var xe=I(J=>{"use strict";Object.defineProperty(J,"__esModule",{value:!0});function _(e){let t=[...e.caches],r=t.shift();return r===void 0?ve():{get(s,n,a={miss:()=>Promise.resolve()}){return r.get(s,n,a).catch(()=>_({caches:t}).get(s,n,a))},set(s,n){return r.set(s,n).catch(()=>_({caches:t}).set(s,n))},delete(s){return r.delete(s).catch(()=>_({caches:t}).delete(s))},clear(){return r.clear().catch(()=>_({caches:t}).clear())}}}function ve(){return{get(e,t,r={miss:()=>Promise.resolve()}){return t().then(n=>Promise.all([n,r.miss(n)])).then(([n])=>n)},set(e,t){return Promise.resolve(t)},delete(e){return Promise.resolve()},clear(){return Promise.resolve()}}}J.createFallbackableCache=_;J.createNullCache=ve});var Ee=I(($s,qe)=>{qe.exports=xe()});var Te=I(ae=>{"use strict";Object.defineProperty(ae,"__esModule",{value:!0});function Jt(e={serializable:!0}){let t={};return{get(r,s,n={miss:()=>Promise.resolve()}){let a=JSON.stringify(r);if(a in t)return Promise.resolve(e.serializable?JSON.parse(t[a]):t[a]);let o=s(),d=n&&n.miss||(()=>Promise.resolve());return o.then(y=>d(y)).then(()=>o)},set(r,s){return t[JSON.stringify(r)]=e.serializable?JSON.stringify(s):s,Promise.resolve(s)},delete(r){return delete t[JSON.stringify(r)],Promise.resolve()},clear(){return t={},Promise.resolve()}}}ae.createInMemoryCache=Jt});var we=I((Vs,Me)=>{Me.exports=Te()});var Ce=I(M=>{"use strict";Object.defineProperty(M,"__esModule",{value:!0});function Xt(e,t,r){let s={"x-algolia-api-key":r,"x-algolia-application-id":t};return{headers(){return e===oe.WithinHeaders?s:{}},queryParameters(){return e===oe.WithinQueryParameters?s:{}}}}function Yt(e){let t=0,r=()=>(t++,new Promise(s=>{setTimeout(()=>{s(e(r))},Math.min(100*t,1e3))}));return e(r)}function ke(e,t=(r,s)=>Promise.resolve()){return Object.assign(e,{wait(r){return ke(e.then(s=>Promise.all([t(s,r),s])).then(s=>s[1]))}})}function Zt(e){let t=e.length-1;for(t;t>0;t--){let r=Math.floor(Math.random()*(t+1)),s=e[t];e[t]=e[r],e[r]=s}return e}function er(e,t){return Object.keys(t!==void 0?t:{}).forEach(r=>{e[r]=t[r](e)}),e}function tr(e,...t){let r=0;return e.replace(/%s/g,()=>encodeURIComponent(t[r++]))}var rr="4.2.0",sr=e=>()=>e.transporter.requester.destroy(),oe={WithinQueryParameters:0,WithinHeaders:1};M.AuthMode=oe;M.addMethods=er;M.createAuth=Xt;M.createRetryablePromise=Yt;M.createWaitablePromise=ke;M.destroy=sr;M.encode=tr;M.shuffle=Zt;M.version=rr});var F=I((Js,Ue)=>{Ue.exports=Ce()});var Ne=I(ie=>{"use strict";Object.defineProperty(ie,"__esModule",{value:!0});var nr={Delete:"DELETE",Get:"GET",Post:"POST",Put:"PUT"};ie.MethodEnum=nr});var B=I((Ys,We)=>{We.exports=Ne()});var Ze=I(A=>{"use strict";Object.defineProperty(A,"__esModule",{value:!0});var He=B();function ce(e,t){let r=e||{},s=r.data||{};return Object.keys(r).forEach(n=>{["timeout","headers","queryParameters","data","cacheable"].indexOf(n)===-1&&(s[n]=r[n])}),{data:Object.entries(s).length>0?s:void 0,timeout:r.timeout||t,headers:r.headers||{},queryParameters:r.queryParameters||{},cacheable:r.cacheable}}var X={Read:1,Write:2,Any:3},U={Up:1,Down:2,Timeouted:3},_e=2*60*1e3;function ue(e,t=U.Up){return g(u({},e),{status:t,lastUpdate:Date.now()})}function Fe(e){return e.status===U.Up||Date.now()-e.lastUpdate>_e}function Be(e){return e.status===U.Timeouted&&Date.now()-e.lastUpdate<=_e}function le(e){return{protocol:e.protocol||"https",url:e.url,accept:e.accept||X.Any}}function ar(e,t){return Promise.all(t.map(r=>e.get(r,()=>Promise.resolve(ue(r))))).then(r=>{let s=r.filter(d=>Fe(d)),n=r.filter(d=>Be(d)),a=[...s,...n],o=a.length>0?a.map(d=>le(d)):t;return{getTimeout(d,y){return(n.length===0&&d===0?1:n.length+3+d)*y},statelessHosts:o}})}var or=({isTimedOut:e,status:t})=>!e&&~~t==0,ir=e=>{let t=e.status;return e.isTimedOut||or(e)||~~(t/100)!=2&&~~(t/100)!=4},cr=({status:e})=>~~(e/100)==2,ur=(e,t)=>ir(e)?t.onRetry(e):cr(e)?t.onSucess(e):t.onFail(e);function Qe(e,t,r,s){let n=[],a=$e(r,s),o=Le(e,s),d=r.method,y=r.method!==He.MethodEnum.Get?{}:u(u({},r.data),s.data),b=u(u(u({"x-algolia-agent":e.userAgent.value},e.queryParameters),y),s.queryParameters),f=0,p=(h,S)=>{let O=h.pop();if(O===void 0)throw Ve(de(n));let P={data:a,headers:o,method:d,url:Ge(O,r.path,b),connectTimeout:S(f,e.timeouts.connect),responseTimeout:S(f,s.timeout)},x=j=>{let T={request:P,response:j,host:O,triesLeft:h.length};return n.push(T),T},v={onSucess:j=>Ke(j),onRetry(j){let T=x(j);return j.isTimedOut&&f++,Promise.all([e.logger.info("Retryable failure",pe(T)),e.hostsCache.set(O,ue(O,j.isTimedOut?U.Timeouted:U.Down))]).then(()=>p(h,S))},onFail(j){throw x(j),ze(j,de(n))}};return e.requester.send(P).then(j=>ur(j,v))};return ar(e.hostsCache,t).then(h=>p([...h.statelessHosts].reverse(),h.getTimeout))}function lr(e){let{hostsCache:t,logger:r,requester:s,requestsCache:n,responsesCache:a,timeouts:o,userAgent:d,hosts:y,queryParameters:b,headers:f}=e,p={hostsCache:t,logger:r,requester:s,requestsCache:n,responsesCache:a,timeouts:o,userAgent:d,headers:f,queryParameters:b,hosts:y.map(h=>le(h)),read(h,S){let O=ce(S,p.timeouts.read),P=()=>Qe(p,p.hosts.filter(j=>(j.accept&X.Read)!=0),h,O);if((O.cacheable!==void 0?O.cacheable:h.cacheable)!==!0)return P();let v={request:h,mappedRequestOptions:O,transporter:{queryParameters:p.queryParameters,headers:p.headers}};return p.responsesCache.get(v,()=>p.requestsCache.get(v,()=>p.requestsCache.set(v,P()).then(j=>Promise.all([p.requestsCache.delete(v),j]),j=>Promise.all([p.requestsCache.delete(v),Promise.reject(j)])).then(([j,T])=>T)),{miss:j=>p.responsesCache.set(v,j)})},write(h,S){return Qe(p,p.hosts.filter(O=>(O.accept&X.Write)!=0),h,ce(S,p.timeouts.write))}};return p}function dr(e){let t={value:`Algolia for JavaScript (${e})`,add(r){let s=`; ${r.segment}${r.version!==void 0?` (${r.version})`:""}`;return t.value.indexOf(s)===-1&&(t.value=`${t.value}${s}`),t}};return t}function Ke(e){try{return JSON.parse(e.content)}catch(t){throw Je(t.message,e)}}function ze({content:e,status:t},r){let s=e;try{s=JSON.parse(e).message}catch(n){}return Xe(s,t,r)}function pr(e,...t){let r=0;return e.replace(/%s/g,()=>encodeURIComponent(t[r++]))}function Ge(e,t,r){let s=Ye(r),n=`${e.protocol}://${e.url}/${t.charAt(0)==="/"?t.substr(1):t}`;return s.length&&(n+=`?${s}`),n}function Ye(e){let t=r=>Object.prototype.toString.call(r)==="[object Object]"||Object.prototype.toString.call(r)==="[object Array]";return Object.keys(e).map(r=>pr("%s=%s",r,t(e[r])?JSON.stringify(e[r]):e[r])).join("&")}function $e(e,t){if(e.method===He.MethodEnum.Get||e.data===void 0&&t.data===void 0)return;let r=Array.isArray(e.data)?e.data:u(u({},e.data),t.data);return JSON.stringify(r)}function Le(e,t){let r=u(u({},e.headers),t.headers),s={};return Object.keys(r).forEach(n=>{let a=r[n];s[n.toLowerCase()]=a}),s}function de(e){return e.map(t=>pe(t))}function pe(e){let t=e.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return g(u({},e),{request:g(u({},e.request),{headers:u(u({},e.request.headers),t)})})}function Xe(e,t,r){return{name:"ApiError",message:e,status:t,transporterStackTrace:r}}function Je(e,t){return{name:"DeserializationError",message:e,response:t}}function Ve(e){return{name:"RetryError",message:"Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.",transporterStackTrace:e}}A.CallEnum=X;A.HostStatusEnum=U;A.createApiError=Xe;A.createDeserializationError=Je;A.createMappedRequestOptions=ce;A.createRetryError=Ve;A.createStatefulHost=ue;A.createStatelessHost=le;A.createTransporter=lr;A.createUserAgent=dr;A.deserializeFailure=ze;A.deserializeSuccess=Ke;A.isStatefulHostTimeouted=Be;A.isStatefulHostUp=Fe;A.serializeData=$e;A.serializeHeaders=Le;A.serializeQueryParameters=Ye;A.serializeUrl=Ge;A.stackFrameWithoutCredentials=pe;A.stackTraceWithoutCredentials=de});var K=I((en,et)=>{et.exports=Ze()});var tt=I(w=>{"use strict";Object.defineProperty(w,"__esModule",{value:!0});var N=F(),mr=K(),z=B(),hr=e=>{let t=e.region||"us",r=N.createAuth(N.AuthMode.WithinHeaders,e.appId,e.apiKey),s=mr.createTransporter(g(u({hosts:[{url:`analytics.${t}.algolia.com`}]},e),{headers:u(g(u({},r.headers()),{"content-type":"application/json"}),e.headers),queryParameters:u(u({},r.queryParameters()),e.queryParameters)})),n=e.appId;return N.addMethods({appId:n,transporter:s},e.methods)},yr=e=>(t,r)=>e.transporter.write({method:z.MethodEnum.Post,path:"2/abtests",data:t},r),gr=e=>(t,r)=>e.transporter.write({method:z.MethodEnum.Delete,path:N.encode("2/abtests/%s",t)},r),fr=e=>(t,r)=>e.transporter.read({method:z.MethodEnum.Get,path:N.encode("2/abtests/%s",t)},r),br=e=>t=>e.transporter.read({method:z.MethodEnum.Get,path:"2/abtests"},t),Pr=e=>(t,r)=>e.transporter.write({method:z.MethodEnum.Post,path:N.encode("2/abtests/%s/stop",t)},r);w.addABTest=yr;w.createAnalyticsClient=hr;w.deleteABTest=gr;w.getABTest=fr;w.getABTests=br;w.stopABTest=Pr});var st=I((rn,rt)=>{rt.exports=tt()});var at=I(G=>{"use strict";Object.defineProperty(G,"__esModule",{value:!0});var me=F(),jr=K(),nt=B(),Or=e=>{let t=e.region||"us",r=me.createAuth(me.AuthMode.WithinHeaders,e.appId,e.apiKey),s=jr.createTransporter(g(u({hosts:[{url:`recommendation.${t}.algolia.com`}]},e),{headers:u(g(u({},r.headers()),{"content-type":"application/json"}),e.headers),queryParameters:u(u({},r.queryParameters()),e.queryParameters)}));return me.addMethods({appId:e.appId,transporter:s},e.methods)},Ir=e=>t=>e.transporter.read({method:nt.MethodEnum.Get,path:"1/strategies/personalization"},t),Ar=e=>(t,r)=>e.transporter.write({method:nt.MethodEnum.Post,path:"1/strategies/personalization",data:t},r);G.createRecommendationClient=Or;G.getPersonalizationStrategy=Ir;G.setPersonalizationStrategy=Ar});var it=I((nn,ot)=>{ot.exports=at()});var jt=I(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0});var l=F(),q=K(),m=B(),Sr=require("crypto");function Y(e){let t=r=>e.request(r).then(s=>{if(e.batch!==void 0&&e.batch(s.hits),!e.shouldStop(s))return s.cursor?t({cursor:s.cursor}):t({page:(r.page||0)+1})});return t({})}var Dr=e=>{let t=e.appId,r=l.createAuth(e.authMode!==void 0?e.authMode:l.AuthMode.WithinHeaders,t,e.apiKey),s=q.createTransporter(g(u({hosts:[{url:`${t}-dsn.algolia.net`,accept:q.CallEnum.Read},{url:`${t}.algolia.net`,accept:q.CallEnum.Write}].concat(l.shuffle([{url:`${t}-1.algolianet.com`},{url:`${t}-2.algolianet.com`},{url:`${t}-3.algolianet.com`}]))},e),{headers:u(g(u({},r.headers()),{"content-type":"application/x-www-form-urlencoded"}),e.headers),queryParameters:u(u({},r.queryParameters()),e.queryParameters)})),n={transporter:s,appId:t,addAlgoliaAgent(a,o){s.userAgent.add({segment:a,version:o})},clearCache(){return Promise.all([s.requestsCache.clear(),s.responsesCache.clear()]).then(()=>{})}};return l.addMethods(n,e.methods)};function ct(){return{name:"MissingObjectIDError",message:"All objects must have an unique objectID (like a primary key) to be valid. Algolia is also able to generate objectIDs automatically but *it's not recommended*. To do it, use the `{'autoGenerateObjectIDIfNotExist': true}` option."}}function ut(){return{name:"ObjectNotFoundError",message:"Object not found."}}function lt(){return{name:"ValidUntilNotFoundError",message:"ValidUntil not found in given secured api key."}}var Rr=e=>(t,r)=>{let d=r||{},{queryParameters:s}=d,n=R(d,["queryParameters"]),a=u({acl:t},s!==void 0?{queryParameters:s}:{}),o=(y,b)=>l.createRetryablePromise(f=>$(e)(y.key,b).catch(p=>{if(p.status!==404)throw p;return f()}));return l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:"1/keys",data:a},n),o)},vr=e=>(t,r,s)=>{let n=q.createMappedRequestOptions(s);return n.queryParameters["X-Algolia-User-ID"]=t,e.transporter.write({method:m.MethodEnum.Post,path:"1/clusters/mapping",data:{cluster:r}},n)},xr=e=>(t,r,s)=>e.transporter.write({method:m.MethodEnum.Post,path:"1/clusters/mapping/batch",data:{users:t,cluster:r}},s),Z=e=>(t,r,s)=>{let n=(a,o)=>L(e)(t,{methods:{waitTask:D}}).waitTask(a.taskID,o);return l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/operation",t),data:{operation:"copy",destination:r}},s),n)},qr=e=>(t,r,s)=>Z(e)(t,r,g(u({},s),{scope:[ee.Rules]})),Er=e=>(t,r,s)=>Z(e)(t,r,g(u({},s),{scope:[ee.Settings]})),Tr=e=>(t,r,s)=>Z(e)(t,r,g(u({},s),{scope:[ee.Synonyms]})),Mr=e=>(t,r)=>{let s=(n,a)=>l.createRetryablePromise(o=>$(e)(t,a).then(o).catch(d=>{if(d.status!==404)throw d}));return l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Delete,path:l.encode("1/keys/%s",t)},r),s)},wr=()=>(e,t)=>{let r=q.serializeQueryParameters(t),s=Sr.createHmac("sha256",e).update(r).digest("hex");return Buffer.from(s+r).toString("base64")},$=e=>(t,r)=>e.transporter.read({method:m.MethodEnum.Get,path:l.encode("1/keys/%s",t)},r),kr=e=>t=>e.transporter.read({method:m.MethodEnum.Get,path:"1/logs"},t),Cr=()=>e=>{let t=Buffer.from(e,"base64").toString("ascii"),r=/validUntil=(\d+)/,s=t.match(r);if(s===null)throw lt();return parseInt(s[1],10)-Math.round(new Date().getTime()/1e3)},Ur=e=>t=>e.transporter.read({method:m.MethodEnum.Get,path:"1/clusters/mapping/top"},t),Nr=e=>(t,r)=>e.transporter.read({method:m.MethodEnum.Get,path:l.encode("1/clusters/mapping/%s",t)},r),Wr=e=>t=>{let n=t||{},{retrieveMappings:r}=n,s=R(n,["retrieveMappings"]);return r===!0&&(s.getClusters=!0),e.transporter.read({method:m.MethodEnum.Get,path:"1/clusters/mapping/pending"},s)},L=e=>(t,r={})=>{let s={transporter:e.transporter,appId:e.appId,indexName:t};return l.addMethods(s,r.methods)},Hr=e=>t=>e.transporter.read({method:m.MethodEnum.Get,path:"1/keys"},t),_r=e=>t=>e.transporter.read({method:m.MethodEnum.Get,path:"1/clusters"},t),Fr=e=>t=>e.transporter.read({method:m.MethodEnum.Get,path:"1/indexes"},t),Br=e=>t=>e.transporter.read({method:m.MethodEnum.Get,path:"1/clusters/mapping"},t),Kr=e=>(t,r,s)=>{let n=(a,o)=>L(e)(t,{methods:{waitTask:D}}).waitTask(a.taskID,o);return l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/operation",t),data:{operation:"move",destination:r}},s),n)},zr=e=>(t,r)=>{let s=(n,a)=>Promise.all(Object.keys(n.taskID).map(o=>L(e)(o,{methods:{waitTask:D}}).waitTask(n.taskID[o],a)));return l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:"1/indexes/*/batch",data:{requests:t}},r),s)},Gr=e=>(t,r)=>e.transporter.read({method:m.MethodEnum.Post,path:"1/indexes/*/objects",data:{requests:t}},r),$r=e=>(t,r)=>{let s=t.map(n=>g(u({},n),{params:q.serializeQueryParameters(n.params||{})}));return e.transporter.read({method:m.MethodEnum.Post,path:"1/indexes/*/queries",data:{requests:s},cacheable:!0},r)},Lr=e=>(t,r)=>Promise.all(t.map(s=>{let d=s.params,{facetName:n,facetQuery:a}=d,o=R(d,["facetName","facetQuery"]);return L(e)(s.indexName,{methods:{searchForFacetValues:dt}}).searchForFacetValues(n,a,u(u({},r),o))})),Vr=e=>(t,r)=>{let s=q.createMappedRequestOptions(r);return s.queryParameters["X-Algolia-User-ID"]=t,e.transporter.write({method:m.MethodEnum.Delete,path:"1/clusters/mapping"},s)},Qr=e=>(t,r)=>{let s=(n,a)=>l.createRetryablePromise(o=>$(e)(t,a).catch(d=>{if(d.status!==404)throw d;return o()}));return l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:l.encode("1/keys/%s/restore",t)},r),s)},Jr=e=>(t,r)=>e.transporter.read({method:m.MethodEnum.Post,path:"1/clusters/mapping/search",data:{query:t}},r),Xr=e=>(t,r)=>{let s=Object.assign({},r),f=r||{},{queryParameters:n}=f,a=R(f,["queryParameters"]),o=n?{queryParameters:n}:{},d=["acl","indexes","referers","restrictSources","queryParameters","description","maxQueriesPerIPPerHour","maxHitsPerQuery"],y=p=>Object.keys(s).filter(h=>d.indexOf(h)!==-1).every(h=>p[h]===s[h]),b=(p,h)=>l.createRetryablePromise(S=>$(e)(t,h).then(O=>y(O)?Promise.resolve():S()));return l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Put,path:l.encode("1/keys/%s",t),data:o},a),b)},pt=e=>(t,r)=>{let s=(n,a)=>D(e)(n.taskID,a);return l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/batch",e.indexName),data:{requests:t}},r),s)},Yr=e=>t=>Y(g(u({},t),{shouldStop:r=>r.cursor===void 0,request:r=>e.transporter.read({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/browse",e.indexName),data:r},t)})),Zr=e=>t=>{let r=u({hitsPerPage:1e3},t);return Y(g(u({},r),{shouldStop:s=>s.hits.lengthg(u({},n),{hits:n.hits.map(a=>(delete a._highlightResult,a))}))}}))},es=e=>t=>{let r=u({hitsPerPage:1e3},t);return Y(g(u({},r),{shouldStop:s=>s.hits.lengthg(u({},n),{hits:n.hits.map(a=>(delete a._highlightResult,a))}))}}))},te=e=>(t,r,s)=>{let y=s||{},{batchSize:n}=y,a=R(y,["batchSize"]),o={taskIDs:[],objectIDs:[]},d=(b=0)=>{let f=[],p;for(p=b;p({action:r,body:h})),a).then(h=>(o.objectIDs=o.objectIDs.concat(h.objectIDs),o.taskIDs.push(h.taskID),p++,d(p)))};return l.createWaitablePromise(d(),(b,f)=>Promise.all(b.taskIDs.map(p=>D(e)(p,f))))},ts=e=>t=>l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/clear",e.indexName)},t),(r,s)=>D(e)(r.taskID,s)),rs=e=>t=>{let a=t||{},{forwardToReplicas:r}=a,s=R(a,["forwardToReplicas"]),n=q.createMappedRequestOptions(s);return r&&(n.queryParameters.forwardToReplicas=1),l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/rules/clear",e.indexName)},n),(o,d)=>D(e)(o.taskID,d))},ss=e=>t=>{let a=t||{},{forwardToReplicas:r}=a,s=R(a,["forwardToReplicas"]),n=q.createMappedRequestOptions(s);return r&&(n.queryParameters.forwardToReplicas=1),l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/synonyms/clear",e.indexName)},n),(o,d)=>D(e)(o.taskID,d))},ns=e=>(t,r)=>l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/deleteByQuery",e.indexName),data:t},r),(s,n)=>D(e)(s.taskID,n)),as=e=>t=>l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Delete,path:l.encode("1/indexes/%s",e.indexName)},t),(r,s)=>D(e)(r.taskID,s)),os=e=>(t,r)=>l.createWaitablePromise(yt(e)([t],r).then(s=>({taskID:s.taskIDs[0]})),(s,n)=>D(e)(s.taskID,n)),yt=e=>(t,r)=>{let s=t.map(n=>({objectID:n}));return te(e)(s,k.DeleteObject,r)},is=e=>(t,r)=>{let o=r||{},{forwardToReplicas:s}=o,n=R(o,["forwardToReplicas"]),a=q.createMappedRequestOptions(n);return s&&(a.queryParameters.forwardToReplicas=1),l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Delete,path:l.encode("1/indexes/%s/rules/%s",e.indexName,t)},a),(d,y)=>D(e)(d.taskID,y))},cs=e=>(t,r)=>{let o=r||{},{forwardToReplicas:s}=o,n=R(o,["forwardToReplicas"]),a=q.createMappedRequestOptions(n);return s&&(a.queryParameters.forwardToReplicas=1),l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Delete,path:l.encode("1/indexes/%s/synonyms/%s",e.indexName,t)},a),(d,y)=>D(e)(d.taskID,y))},us=e=>t=>gt(e)(t).then(()=>!0).catch(r=>{if(r.status!==404)throw r;return!1}),ls=e=>(t,r)=>{let y=r||{},{query:s,paginate:n}=y,a=R(y,["query","paginate"]),o=0,d=()=>ft(e)(s||"",g(u({},a),{page:o})).then(b=>{for(let[f,p]of Object.entries(b.hits))if(t(p))return{object:p,position:parseInt(f,10),page:o};if(o++,n===!1||o>=b.nbPages)throw ut();return d()});return d()},ds=e=>(t,r)=>e.transporter.read({method:m.MethodEnum.Get,path:l.encode("1/indexes/%s/%s",e.indexName,t)},r),ps=()=>(e,t)=>{for(let[r,s]of Object.entries(e.hits))if(s.objectID===t)return parseInt(r,10);return-1},ms=e=>(t,r)=>{let o=r||{},{attributesToRetrieve:s}=o,n=R(o,["attributesToRetrieve"]),a=t.map(d=>u({indexName:e.indexName,objectID:d},s?{attributesToRetrieve:s}:{}));return e.transporter.read({method:m.MethodEnum.Post,path:"1/indexes/*/objects",data:{requests:a}},n)},hs=e=>(t,r)=>e.transporter.read({method:m.MethodEnum.Get,path:l.encode("1/indexes/%s/rules/%s",e.indexName,t)},r),gt=e=>t=>e.transporter.read({method:m.MethodEnum.Get,path:l.encode("1/indexes/%s/settings",e.indexName),data:{getVersion:2}},t),ys=e=>(t,r)=>e.transporter.read({method:m.MethodEnum.Get,path:l.encode("1/indexes/%s/synonyms/%s",e.indexName,t)},r),bt=e=>(t,r)=>e.transporter.read({method:m.MethodEnum.Get,path:l.encode("1/indexes/%s/task/%s",e.indexName,t.toString())},r),gs=e=>(t,r)=>l.createWaitablePromise(Pt(e)([t],r).then(s=>({objectID:s.objectIDs[0],taskID:s.taskIDs[0]})),(s,n)=>D(e)(s.taskID,n)),Pt=e=>(t,r)=>{let o=r||{},{createIfNotExists:s}=o,n=R(o,["createIfNotExists"]),a=s?k.PartialUpdateObject:k.PartialUpdateObjectNoCreate;return te(e)(t,a,n)},fs=e=>(t,r)=>{let O=r||{},{safe:s,autoGenerateObjectIDIfNotExist:n,batchSize:a}=O,o=R(O,["safe","autoGenerateObjectIDIfNotExist","batchSize"]),d=(P,x,v,j)=>l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/operation",P),data:{operation:v,destination:x}},j),(T,V)=>D(e)(T.taskID,V)),y=Math.random().toString(36).substring(7),b=`${e.indexName}_tmp_${y}`,f=he({appId:e.appId,transporter:e.transporter,indexName:b}),p=[],h=d(e.indexName,b,"copy",g(u({},o),{scope:["settings","synonyms","rules"]}));p.push(h);let S=(s?h.wait(o):h).then(()=>{let P=f(t,g(u({},o),{autoGenerateObjectIDIfNotExist:n,batchSize:a}));return p.push(P),s?P.wait(o):P}).then(()=>{let P=d(b,e.indexName,"move",o);return p.push(P),s?P.wait(o):P}).then(()=>Promise.all(p)).then(([P,x,v])=>({objectIDs:x.objectIDs,taskIDs:[P.taskID,...x.taskIDs,v.taskID]}));return l.createWaitablePromise(S,(P,x)=>Promise.all(p.map(v=>v.wait(x))))},bs=e=>(t,r)=>ye(e)(t,g(u({},r),{clearExistingRules:!0})),Ps=e=>(t,r)=>ge(e)(t,g(u({},r),{replaceExistingSynonyms:!0})),js=e=>(t,r)=>l.createWaitablePromise(he(e)([t],r).then(s=>({objectID:s.objectIDs[0],taskID:s.taskIDs[0]})),(s,n)=>D(e)(s.taskID,n)),he=e=>(t,r)=>{let o=r||{},{autoGenerateObjectIDIfNotExist:s}=o,n=R(o,["autoGenerateObjectIDIfNotExist"]),a=s?k.AddObject:k.UpdateObject;if(a===k.UpdateObject){for(let d of t)if(d.objectID===void 0)return l.createWaitablePromise(Promise.reject(ct()))}return te(e)(t,a,n)},Os=e=>(t,r)=>ye(e)([t],r),ye=e=>(t,r)=>{let d=r||{},{forwardToReplicas:s,clearExistingRules:n}=d,a=R(d,["forwardToReplicas","clearExistingRules"]),o=q.createMappedRequestOptions(a);return s&&(o.queryParameters.forwardToReplicas=1),n&&(o.queryParameters.clearExistingRules=1),l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/rules/batch",e.indexName),data:t},o),(y,b)=>D(e)(y.taskID,b))},Is=e=>(t,r)=>ge(e)([t],r),ge=e=>(t,r)=>{let d=r||{},{forwardToReplicas:s,replaceExistingSynonyms:n}=d,a=R(d,["forwardToReplicas","replaceExistingSynonyms"]),o=q.createMappedRequestOptions(a);return s&&(o.queryParameters.forwardToReplicas=1),n&&(o.queryParameters.replaceExistingSynonyms=1),l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/synonyms/batch",e.indexName),data:t},o),(y,b)=>D(e)(y.taskID,b))},ft=e=>(t,r)=>e.transporter.read({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/query",e.indexName),data:{query:t},cacheable:!0},r),dt=e=>(t,r,s)=>e.transporter.read({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/facets/%s/query",e.indexName,t),data:{facetQuery:r},cacheable:!0},s),mt=e=>(t,r)=>e.transporter.read({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/rules/search",e.indexName),data:{query:t}},r),ht=e=>(t,r)=>e.transporter.read({method:m.MethodEnum.Post,path:l.encode("1/indexes/%s/synonyms/search",e.indexName),data:{query:t}},r),As=e=>(t,r)=>{let o=r||{},{forwardToReplicas:s}=o,n=R(o,["forwardToReplicas"]),a=q.createMappedRequestOptions(n);return s&&(a.queryParameters.forwardToReplicas=1),l.createWaitablePromise(e.transporter.write({method:m.MethodEnum.Put,path:l.encode("1/indexes/%s/settings",e.indexName),data:t},a),(d,y)=>D(e)(d.taskID,y))},D=e=>(t,r)=>l.createRetryablePromise(s=>bt(e)(t,r).then(n=>n.status!=="published"?s():void 0)),Ss={AddObject:"addObject",Analytics:"analytics",Browser:"browse",DeleteIndex:"deleteIndex",DeleteObject:"deleteObject",EditSettings:"editSettings",ListIndexes:"listIndexes",Logs:"logs",Recommendation:"recommendation",Search:"search",SeeUnretrievableAttributes:"seeUnretrievableAttributes",Settings:"settings",Usage:"usage"},k={AddObject:"addObject",UpdateObject:"updateObject",PartialUpdateObject:"partialUpdateObject",PartialUpdateObjectNoCreate:"partialUpdateObjectNoCreate",DeleteObject:"deleteObject"},ee={Settings:"settings",Synonyms:"synonyms",Rules:"rules"},Ds={None:"none",StopIfEnoughMatches:"stopIfEnoughMatches"},Rs={Synonym:"synonym",OneWaySynonym:"oneWaySynonym",AltCorrection1:"altCorrection1",AltCorrection2:"altCorrection2",Placeholder:"placeholder"};i.ApiKeyACLEnum=Ss;i.BatchActionEnum=k;i.ScopeEnum=ee;i.StrategyEnum=Ds;i.SynonymEnum=Rs;i.addApiKey=Rr;i.assignUserID=vr;i.assignUserIDs=xr;i.batch=pt;i.browseObjects=Yr;i.browseRules=Zr;i.browseSynonyms=es;i.chunkedBatch=te;i.clearObjects=ts;i.clearRules=rs;i.clearSynonyms=ss;i.copyIndex=Z;i.copyRules=qr;i.copySettings=Er;i.copySynonyms=Tr;i.createBrowsablePromise=Y;i.createMissingObjectIDError=ct;i.createObjectNotFoundError=ut;i.createSearchClient=Dr;i.createValidUntilNotFoundError=lt;i.deleteApiKey=Mr;i.deleteBy=ns;i.deleteIndex=as;i.deleteObject=os;i.deleteObjects=yt;i.deleteRule=is;i.deleteSynonym=cs;i.exists=us;i.findObject=ls;i.generateSecuredApiKey=wr;i.getApiKey=$;i.getLogs=kr;i.getObject=ds;i.getObjectPosition=ps;i.getObjects=ms;i.getRule=hs;i.getSecuredApiKeyRemainingValidity=Cr;i.getSettings=gt;i.getSynonym=ys;i.getTask=bt;i.getTopUserIDs=Ur;i.getUserID=Nr;i.hasPendingMappings=Wr;i.initIndex=L;i.listApiKeys=Hr;i.listClusters=_r;i.listIndices=Fr;i.listUserIDs=Br;i.moveIndex=Kr;i.multipleBatch=zr;i.multipleGetObjects=Gr;i.multipleQueries=$r;i.multipleSearchForFacetValues=Lr;i.partialUpdateObject=gs;i.partialUpdateObjects=Pt;i.removeUserID=Vr;i.replaceAllObjects=fs;i.replaceAllRules=bs;i.replaceAllSynonyms=Ps;i.restoreApiKey=Qr;i.saveObject=js;i.saveObjects=he;i.saveRule=Os;i.saveRules=ye;i.saveSynonym=Is;i.saveSynonyms=ge;i.search=ft;i.searchForFacetValues=dt;i.searchRules=mt;i.searchSynonyms=ht;i.searchUserIDs=Jr;i.setSettings=As;i.updateApiKey=Xr;i.waitTask=D});var It=I((on,Ot)=>{Ot.exports=jt()});var At=I(re=>{"use strict";Object.defineProperty(re,"__esModule",{value:!0});function vs(){return{debug(e,t){return Promise.resolve()},info(e,t){return Promise.resolve()},error(e,t){return Promise.resolve()}}}var xs={Debug:1,Info:2,Error:3};re.LogLevelEnum=xs;re.createNullLogger=vs});var Dt=I((un,St)=>{St.exports=At()});var xt=I(fe=>{"use strict";Object.defineProperty(fe,"__esModule",{value:!0});var Rt=require("http"),vt=require("https"),qs=require("url");function Es(){let e={keepAlive:!0},t=new Rt.Agent(e),r=new vt.Agent(e);return{send(s){return new Promise(n=>{let a=qs.parse(s.url),o=a.query===null?a.pathname:`${a.pathname}?${a.query}`,d=u({agent:a.protocol==="https:"?r:t,hostname:a.hostname,path:o,method:s.method,headers:s.headers},a.port!==void 0?{port:a.port||""}:{}),y=(a.protocol==="https:"?vt:Rt).request(d,h=>{let S="";h.on("data",O=>S+=O),h.on("end",()=>{clearTimeout(f),clearTimeout(p),n({status:h.statusCode||0,content:S,isTimedOut:!1})})}),b=(h,S)=>setTimeout(()=>{y.abort(),n({status:0,content:S,isTimedOut:!0})},h*1e3),f=b(s.connectTimeout,"Connection timeout"),p;y.on("error",h=>{clearTimeout(f),clearTimeout(p),n({status:0,content:h.message,isTimedOut:!1})}),y.once("response",()=>{clearTimeout(f),p=b(s.responseTimeout,"Socket timeout")}),s.data!==void 0&&y.write(s.data),y.end()})},destroy(){return t.destroy(),r.destroy(),Promise.resolve()}}}fe.createNodeHttpRequester=Es});var Et=I((dn,qt)=>{qt.exports=xt()});var kt=I((pn,Tt)=>{"use strict";var Mt=Ee(),Ts=we(),W=st(),be=F(),Pe=it(),c=It(),Ms=Dt(),ws=Et(),ks=K();function wt(e,t,r){let s={appId:e,apiKey:t,timeouts:{connect:2,read:5,write:30},requester:ws.createNodeHttpRequester(),logger:Ms.createNullLogger(),responsesCache:Mt.createNullCache(),requestsCache:Mt.createNullCache(),hostsCache:Ts.createInMemoryCache(),userAgent:ks.createUserAgent(be.version).add({segment:"Node.js",version:process.versions.node})};return c.createSearchClient(g(u(u({},s),r),{methods:{search:c.multipleQueries,searchForFacetValues:c.multipleSearchForFacetValues,multipleBatch:c.multipleBatch,multipleGetObjects:c.multipleGetObjects,multipleQueries:c.multipleQueries,copyIndex:c.copyIndex,copySettings:c.copySettings,copyRules:c.copyRules,copySynonyms:c.copySynonyms,moveIndex:c.moveIndex,listIndices:c.listIndices,getLogs:c.getLogs,listClusters:c.listClusters,multipleSearchForFacetValues:c.multipleSearchForFacetValues,getApiKey:c.getApiKey,addApiKey:c.addApiKey,listApiKeys:c.listApiKeys,updateApiKey:c.updateApiKey,deleteApiKey:c.deleteApiKey,restoreApiKey:c.restoreApiKey,assignUserID:c.assignUserID,assignUserIDs:c.assignUserIDs,getUserID:c.getUserID,searchUserIDs:c.searchUserIDs,listUserIDs:c.listUserIDs,getTopUserIDs:c.getTopUserIDs,removeUserID:c.removeUserID,hasPendingMappings:c.hasPendingMappings,generateSecuredApiKey:c.generateSecuredApiKey,getSecuredApiKeyRemainingValidity:c.getSecuredApiKeyRemainingValidity,destroy:be.destroy,initIndex:n=>a=>c.initIndex(n)(a,{methods:{batch:c.batch,delete:c.deleteIndex,getObject:c.getObject,getObjects:c.getObjects,saveObject:c.saveObject,saveObjects:c.saveObjects,search:c.search,searchForFacetValues:c.searchForFacetValues,waitTask:c.waitTask,setSettings:c.setSettings,getSettings:c.getSettings,partialUpdateObject:c.partialUpdateObject,partialUpdateObjects:c.partialUpdateObjects,deleteObject:c.deleteObject,deleteObjects:c.deleteObjects,deleteBy:c.deleteBy,clearObjects:c.clearObjects,browseObjects:c.browseObjects,getObjectPosition:c.getObjectPosition,findObject:c.findObject,exists:c.exists,saveSynonym:c.saveSynonym,saveSynonyms:c.saveSynonyms,getSynonym:c.getSynonym,searchSynonyms:c.searchSynonyms,browseSynonyms:c.browseSynonyms,deleteSynonym:c.deleteSynonym,clearSynonyms:c.clearSynonyms,replaceAllObjects:c.replaceAllObjects,replaceAllSynonyms:c.replaceAllSynonyms,searchRules:c.searchRules,getRule:c.getRule,deleteRule:c.deleteRule,saveRule:c.saveRule,saveRules:c.saveRules,replaceAllRules:c.replaceAllRules,browseRules:c.browseRules,clearRules:c.clearRules}}),initAnalytics:()=>n=>W.createAnalyticsClient(g(u(u({},s),n),{methods:{addABTest:W.addABTest,getABTest:W.getABTest,getABTests:W.getABTests,stopABTest:W.stopABTest,deleteABTest:W.deleteABTest}})),initRecommendation:()=>n=>Pe.createRecommendationClient(g(u(u({},s),n),{methods:{getPersonalizationStrategy:Pe.getPersonalizationStrategy,setPersonalizationStrategy:Pe.setPersonalizationStrategy}}))}}))}wt.version=be.version;Tt.exports=wt});var Ut=I((mn,je)=>{var Ct=kt();je.exports=Ct;je.exports.default=Ct});var Ws={};Vt(Ws,{default:()=>Ks});var Oe=C(require("@yarnpkg/core")),E=C(require("@yarnpkg/core")),Ie=C(require("@yarnpkg/plugin-essentials")),Ht=C(require("semver"));var se=C(require("@yarnpkg/core")),Nt=C(Ut()),Cs="e8e1bd300d860104bb8c58453ffa1eb4",Us="OFCNCOG2CU",Wt=async(e,t)=>{var a;let r=se.structUtils.stringifyIdent(e),n=Ns(t).initIndex("npm-search");try{return((a=(await n.getObject(r,{attributesToRetrieve:["types"]})).types)==null?void 0:a.ts)==="definitely-typed"}catch(o){return!1}},Ns=e=>(0,Nt.default)(Us,Cs,{requester:{async send(r){try{let s=await se.httpUtils.request(r.url,r.data||null,{configuration:e,headers:r.headers});return{content:s.body,isTimedOut:!1,status:s.statusCode}}catch(s){return{content:s.response.body,isTimedOut:!1,status:s.response.statusCode}}}}});var _t=e=>e.scope?`${e.scope}__${e.name}`:`${e.name}`,Hs=async(e,t,r,s)=>{if(r.scope==="types")return;let{project:n}=e,{configuration:a}=n,o=a.makeResolver(),d={project:n,resolver:o,report:new E.ThrowReport};if(!await Wt(r,a))return;let b=_t(r),f=E.structUtils.parseRange(r.range).selector;if(!E.semverUtils.validRange(f)){let P=await o.getCandidates(r,new Map,d);f=E.structUtils.parseRange(P[0].reference).selector}let p=Ht.default.coerce(f);if(p===null)return;let h=`${Ie.suggestUtils.Modifier.CARET}${p.major}`,S=E.structUtils.makeDescriptor(E.structUtils.makeIdent("types",b),h),O=E.miscUtils.mapAndFind(n.workspaces,P=>{var T,V;let x=(T=P.manifest.dependencies.get(r.identHash))==null?void 0:T.descriptorHash,v=(V=P.manifest.devDependencies.get(r.identHash))==null?void 0:V.descriptorHash;if(x!==r.descriptorHash&&v!==r.descriptorHash)return E.miscUtils.mapAndFind.skip;let j=[];for(let Ae of Oe.Manifest.allDependencies){let Se=P.manifest[Ae].get(S.identHash);typeof Se!="undefined"&&j.push([Ae,Se])}return j.length===0?E.miscUtils.mapAndFind.skip:j});if(typeof O!="undefined")for(let[P,x]of O)e.manifest[P].set(x.identHash,x);else{try{if((await o.getCandidates(S,new Map,d)).length===0)return}catch{return}e.manifest[Ie.suggestUtils.Target.DEVELOPMENT].set(S.identHash,S)}},_s=async(e,t,r)=>{if(r.scope==="types")return;let s=_t(r),n=E.structUtils.makeIdent("types",s);for(let a of Oe.Manifest.allDependencies)typeof e.manifest[a].get(n.identHash)!="undefined"&&e.manifest[a].delete(n.identHash)},Fs=(e,t)=>{t.publishConfig&&t.publishConfig.typings&&(t.typings=t.publishConfig.typings),t.publishConfig&&t.publishConfig.types&&(t.types=t.publishConfig.types)},Bs={hooks:{afterWorkspaceDependencyAddition:Hs,afterWorkspaceDependencyRemoval:_s,beforeWorkspacePacking:Fs}},Ks=Bs;return Ws;})(); 7 | return plugin; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /.yarn/sdks/eslint/bin/eslint.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const {existsSync} = require(`fs`); 4 | const {createRequire, createRequireFromPath} = require(`module`); 5 | const {resolve} = require(`path`); 6 | 7 | const relPnpApiPath = "../../../../.pnp.cjs"; 8 | 9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); 10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); 11 | 12 | if (existsSync(absPnpApiPath)) { 13 | if (!process.versions.pnp) { 14 | // Setup the environment to be able to require eslint/bin/eslint.js 15 | require(absPnpApiPath).setup(); 16 | } 17 | } 18 | 19 | // Defer to the real eslint/bin/eslint.js your application uses 20 | module.exports = absRequire(`eslint/bin/eslint.js`); 21 | -------------------------------------------------------------------------------- /.yarn/sdks/eslint/lib/api.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const {existsSync} = require(`fs`); 4 | const {createRequire, createRequireFromPath} = require(`module`); 5 | const {resolve} = require(`path`); 6 | 7 | const relPnpApiPath = "../../../../.pnp.cjs"; 8 | 9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); 10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); 11 | 12 | if (existsSync(absPnpApiPath)) { 13 | if (!process.versions.pnp) { 14 | // Setup the environment to be able to require eslint 15 | require(absPnpApiPath).setup(); 16 | } 17 | } 18 | 19 | // Defer to the real eslint your application uses 20 | module.exports = absRequire(`eslint`); 21 | -------------------------------------------------------------------------------- /.yarn/sdks/eslint/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint", 3 | "version": "8.16.0-sdk", 4 | "main": "./lib/api.js", 5 | "type": "commonjs" 6 | } 7 | -------------------------------------------------------------------------------- /.yarn/sdks/integrations.yml: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by @yarnpkg/sdks. 2 | # Manual changes might be lost! 3 | 4 | integrations: 5 | - vscode 6 | -------------------------------------------------------------------------------- /.yarn/sdks/prettier/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const {existsSync} = require(`fs`); 4 | const {createRequire, createRequireFromPath} = require(`module`); 5 | const {resolve} = require(`path`); 6 | 7 | const relPnpApiPath = "../../../.pnp.cjs"; 8 | 9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); 10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); 11 | 12 | if (existsSync(absPnpApiPath)) { 13 | if (!process.versions.pnp) { 14 | // Setup the environment to be able to require prettier/index.js 15 | require(absPnpApiPath).setup(); 16 | } 17 | } 18 | 19 | // Defer to the real prettier/index.js your application uses 20 | module.exports = absRequire(`prettier/index.js`); 21 | -------------------------------------------------------------------------------- /.yarn/sdks/prettier/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prettier", 3 | "version": "2.6.2-sdk", 4 | "main": "./index.js", 5 | "type": "commonjs" 6 | } 7 | -------------------------------------------------------------------------------- /.yarn/sdks/typescript/bin/tsc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const {existsSync} = require(`fs`); 4 | const {createRequire, createRequireFromPath} = require(`module`); 5 | const {resolve} = require(`path`); 6 | 7 | const relPnpApiPath = "../../../../.pnp.cjs"; 8 | 9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); 10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); 11 | 12 | if (existsSync(absPnpApiPath)) { 13 | if (!process.versions.pnp) { 14 | // Setup the environment to be able to require typescript/bin/tsc 15 | require(absPnpApiPath).setup(); 16 | } 17 | } 18 | 19 | // Defer to the real typescript/bin/tsc your application uses 20 | module.exports = absRequire(`typescript/bin/tsc`); 21 | -------------------------------------------------------------------------------- /.yarn/sdks/typescript/bin/tsserver: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const {existsSync} = require(`fs`); 4 | const {createRequire, createRequireFromPath} = require(`module`); 5 | const {resolve} = require(`path`); 6 | 7 | const relPnpApiPath = "../../../../.pnp.cjs"; 8 | 9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); 10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); 11 | 12 | if (existsSync(absPnpApiPath)) { 13 | if (!process.versions.pnp) { 14 | // Setup the environment to be able to require typescript/bin/tsserver 15 | require(absPnpApiPath).setup(); 16 | } 17 | } 18 | 19 | // Defer to the real typescript/bin/tsserver your application uses 20 | module.exports = absRequire(`typescript/bin/tsserver`); 21 | -------------------------------------------------------------------------------- /.yarn/sdks/typescript/lib/tsc.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const {existsSync} = require(`fs`); 4 | const {createRequire, createRequireFromPath} = require(`module`); 5 | const {resolve} = require(`path`); 6 | 7 | const relPnpApiPath = "../../../../.pnp.cjs"; 8 | 9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); 10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); 11 | 12 | if (existsSync(absPnpApiPath)) { 13 | if (!process.versions.pnp) { 14 | // Setup the environment to be able to require typescript/lib/tsc.js 15 | require(absPnpApiPath).setup(); 16 | } 17 | } 18 | 19 | // Defer to the real typescript/lib/tsc.js your application uses 20 | module.exports = absRequire(`typescript/lib/tsc.js`); 21 | -------------------------------------------------------------------------------- /.yarn/sdks/typescript/lib/tsserver.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const {existsSync} = require(`fs`); 4 | const {createRequire, createRequireFromPath} = require(`module`); 5 | const {resolve} = require(`path`); 6 | 7 | const relPnpApiPath = "../../../../.pnp.cjs"; 8 | 9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); 10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); 11 | 12 | const moduleWrapper = tsserver => { 13 | if (!process.versions.pnp) { 14 | return tsserver; 15 | } 16 | 17 | const {isAbsolute} = require(`path`); 18 | const pnpApi = require(`pnpapi`); 19 | 20 | const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//); 21 | const isPortal = str => str.startsWith("portal:/"); 22 | const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`); 23 | 24 | const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => { 25 | return `${locator.name}@${locator.reference}`; 26 | })); 27 | 28 | // VSCode sends the zip paths to TS using the "zip://" prefix, that TS 29 | // doesn't understand. This layer makes sure to remove the protocol 30 | // before forwarding it to TS, and to add it back on all returned paths. 31 | 32 | function toEditorPath(str) { 33 | // We add the `zip:` prefix to both `.zip/` paths and virtual paths 34 | if (isAbsolute(str) && !str.match(/^\^?(zip:|\/zip\/)/) && (str.match(/\.zip\//) || isVirtual(str))) { 35 | // We also take the opportunity to turn virtual paths into physical ones; 36 | // this makes it much easier to work with workspaces that list peer 37 | // dependencies, since otherwise Ctrl+Click would bring us to the virtual 38 | // file instances instead of the real ones. 39 | // 40 | // We only do this to modules owned by the the dependency tree roots. 41 | // This avoids breaking the resolution when jumping inside a vendor 42 | // with peer dep (otherwise jumping into react-dom would show resolution 43 | // errors on react). 44 | // 45 | const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str; 46 | if (resolved) { 47 | const locator = pnpApi.findPackageLocator(resolved); 48 | if (locator && (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference))) { 49 | str = resolved; 50 | } 51 | } 52 | 53 | str = normalize(str); 54 | 55 | if (str.match(/\.zip\//)) { 56 | switch (hostInfo) { 57 | // Absolute VSCode `Uri.fsPath`s need to start with a slash. 58 | // VSCode only adds it automatically for supported schemes, 59 | // so we have to do it manually for the `zip` scheme. 60 | // The path needs to start with a caret otherwise VSCode doesn't handle the protocol 61 | // 62 | // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910 63 | // 64 | // Update 2021-10-08: VSCode changed their format in 1.61. 65 | // Before | ^zip:/c:/foo/bar.zip/package.json 66 | // After | ^/zip//c:/foo/bar.zip/package.json 67 | // 68 | // Update 2022-04-06: VSCode changed the format in 1.66. 69 | // Before | ^/zip//c:/foo/bar.zip/package.json 70 | // After | ^/zip/c:/foo/bar.zip/package.json 71 | // 72 | case `vscode <1.61`: { 73 | str = `^zip:${str}`; 74 | } break; 75 | 76 | case `vscode <1.66`: { 77 | str = `^/zip/${str}`; 78 | } break; 79 | 80 | case `vscode`: { 81 | str = `^/zip${str}`; 82 | } break; 83 | 84 | // To make "go to definition" work, 85 | // We have to resolve the actual file system path from virtual path 86 | // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip) 87 | case `coc-nvim`: { 88 | str = normalize(resolved).replace(/\.zip\//, `.zip::`); 89 | str = resolve(`zipfile:${str}`); 90 | } break; 91 | 92 | // Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server) 93 | // We have to resolve the actual file system path from virtual path, 94 | // everything else is up to neovim 95 | case `neovim`: { 96 | str = normalize(resolved).replace(/\.zip\//, `.zip::`); 97 | str = `zipfile://${str}`; 98 | } break; 99 | 100 | default: { 101 | str = `zip:${str}`; 102 | } break; 103 | } 104 | } 105 | } 106 | 107 | return str; 108 | } 109 | 110 | function fromEditorPath(str) { 111 | switch (hostInfo) { 112 | case `coc-nvim`: { 113 | str = str.replace(/\.zip::/, `.zip/`); 114 | // The path for coc-nvim is in format of //zipfile://.yarn/... 115 | // So in order to convert it back, we use .* to match all the thing 116 | // before `zipfile:` 117 | return process.platform === `win32` 118 | ? str.replace(/^.*zipfile:\//, ``) 119 | : str.replace(/^.*zipfile:/, ``); 120 | } break; 121 | 122 | case `neovim`: { 123 | str = str.replace(/\.zip::/, `.zip/`); 124 | // The path for neovim is in format of zipfile:////.yarn/... 125 | return str.replace(/^zipfile:\/\//, ``); 126 | } break; 127 | 128 | case `vscode`: 129 | default: { 130 | return process.platform === `win32` 131 | ? str.replace(/^\^?(zip:|\/zip)\/+/, ``) 132 | : str.replace(/^\^?(zip:|\/zip)\/+/, `/`); 133 | } break; 134 | } 135 | } 136 | 137 | // Force enable 'allowLocalPluginLoads' 138 | // TypeScript tries to resolve plugins using a path relative to itself 139 | // which doesn't work when using the global cache 140 | // https://github.com/microsoft/TypeScript/blob/1b57a0395e0bff191581c9606aab92832001de62/src/server/project.ts#L2238 141 | // VSCode doesn't want to enable 'allowLocalPluginLoads' due to security concerns but 142 | // TypeScript already does local loads and if this code is running the user trusts the workspace 143 | // https://github.com/microsoft/vscode/issues/45856 144 | const ConfiguredProject = tsserver.server.ConfiguredProject; 145 | const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype; 146 | ConfiguredProject.prototype.enablePluginsWithOptions = function() { 147 | this.projectService.allowLocalPluginLoads = true; 148 | return originalEnablePluginsWithOptions.apply(this, arguments); 149 | }; 150 | 151 | // And here is the point where we hijack the VSCode <-> TS communications 152 | // by adding ourselves in the middle. We locate everything that looks 153 | // like an absolute path of ours and normalize it. 154 | 155 | const Session = tsserver.server.Session; 156 | const {onMessage: originalOnMessage, send: originalSend} = Session.prototype; 157 | let hostInfo = `unknown`; 158 | 159 | Object.assign(Session.prototype, { 160 | onMessage(/** @type {string | object} */ message) { 161 | const isStringMessage = typeof message === 'string'; 162 | const parsedMessage = isStringMessage ? JSON.parse(message) : message; 163 | 164 | if ( 165 | parsedMessage != null && 166 | typeof parsedMessage === `object` && 167 | parsedMessage.arguments && 168 | typeof parsedMessage.arguments.hostInfo === `string` 169 | ) { 170 | hostInfo = parsedMessage.arguments.hostInfo; 171 | if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK) { 172 | if (/(\/|-)1\.([1-5][0-9]|60)\./.test(process.env.VSCODE_IPC_HOOK)) { 173 | hostInfo += ` <1.61`; 174 | } else if (/(\/|-)1\.(6[1-5])\./.test(process.env.VSCODE_IPC_HOOK)) { 175 | hostInfo += ` <1.66`; 176 | } 177 | } 178 | } 179 | 180 | const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => { 181 | return typeof value === 'string' ? fromEditorPath(value) : value; 182 | }); 183 | 184 | return originalOnMessage.call( 185 | this, 186 | isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON) 187 | ); 188 | }, 189 | 190 | send(/** @type {any} */ msg) { 191 | return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => { 192 | return typeof value === `string` ? toEditorPath(value) : value; 193 | }))); 194 | } 195 | }); 196 | 197 | return tsserver; 198 | }; 199 | 200 | if (existsSync(absPnpApiPath)) { 201 | if (!process.versions.pnp) { 202 | // Setup the environment to be able to require typescript/lib/tsserver.js 203 | require(absPnpApiPath).setup(); 204 | } 205 | } 206 | 207 | // Defer to the real typescript/lib/tsserver.js your application uses 208 | module.exports = moduleWrapper(absRequire(`typescript/lib/tsserver.js`)); 209 | -------------------------------------------------------------------------------- /.yarn/sdks/typescript/lib/tsserverlibrary.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const {existsSync} = require(`fs`); 4 | const {createRequire, createRequireFromPath} = require(`module`); 5 | const {resolve} = require(`path`); 6 | 7 | const relPnpApiPath = "../../../../.pnp.cjs"; 8 | 9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); 10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); 11 | 12 | const moduleWrapper = tsserver => { 13 | if (!process.versions.pnp) { 14 | return tsserver; 15 | } 16 | 17 | const {isAbsolute} = require(`path`); 18 | const pnpApi = require(`pnpapi`); 19 | 20 | const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//); 21 | const isPortal = str => str.startsWith("portal:/"); 22 | const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`); 23 | 24 | const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => { 25 | return `${locator.name}@${locator.reference}`; 26 | })); 27 | 28 | // VSCode sends the zip paths to TS using the "zip://" prefix, that TS 29 | // doesn't understand. This layer makes sure to remove the protocol 30 | // before forwarding it to TS, and to add it back on all returned paths. 31 | 32 | function toEditorPath(str) { 33 | // We add the `zip:` prefix to both `.zip/` paths and virtual paths 34 | if (isAbsolute(str) && !str.match(/^\^?(zip:|\/zip\/)/) && (str.match(/\.zip\//) || isVirtual(str))) { 35 | // We also take the opportunity to turn virtual paths into physical ones; 36 | // this makes it much easier to work with workspaces that list peer 37 | // dependencies, since otherwise Ctrl+Click would bring us to the virtual 38 | // file instances instead of the real ones. 39 | // 40 | // We only do this to modules owned by the the dependency tree roots. 41 | // This avoids breaking the resolution when jumping inside a vendor 42 | // with peer dep (otherwise jumping into react-dom would show resolution 43 | // errors on react). 44 | // 45 | const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str; 46 | if (resolved) { 47 | const locator = pnpApi.findPackageLocator(resolved); 48 | if (locator && (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference))) { 49 | str = resolved; 50 | } 51 | } 52 | 53 | str = normalize(str); 54 | 55 | if (str.match(/\.zip\//)) { 56 | switch (hostInfo) { 57 | // Absolute VSCode `Uri.fsPath`s need to start with a slash. 58 | // VSCode only adds it automatically for supported schemes, 59 | // so we have to do it manually for the `zip` scheme. 60 | // The path needs to start with a caret otherwise VSCode doesn't handle the protocol 61 | // 62 | // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910 63 | // 64 | // Update 2021-10-08: VSCode changed their format in 1.61. 65 | // Before | ^zip:/c:/foo/bar.zip/package.json 66 | // After | ^/zip//c:/foo/bar.zip/package.json 67 | // 68 | // Update 2022-04-06: VSCode changed the format in 1.66. 69 | // Before | ^/zip//c:/foo/bar.zip/package.json 70 | // After | ^/zip/c:/foo/bar.zip/package.json 71 | // 72 | case `vscode <1.61`: { 73 | str = `^zip:${str}`; 74 | } break; 75 | 76 | case `vscode <1.66`: { 77 | str = `^/zip/${str}`; 78 | } break; 79 | 80 | case `vscode`: { 81 | str = `^/zip${str}`; 82 | } break; 83 | 84 | // To make "go to definition" work, 85 | // We have to resolve the actual file system path from virtual path 86 | // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip) 87 | case `coc-nvim`: { 88 | str = normalize(resolved).replace(/\.zip\//, `.zip::`); 89 | str = resolve(`zipfile:${str}`); 90 | } break; 91 | 92 | // Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server) 93 | // We have to resolve the actual file system path from virtual path, 94 | // everything else is up to neovim 95 | case `neovim`: { 96 | str = normalize(resolved).replace(/\.zip\//, `.zip::`); 97 | str = `zipfile://${str}`; 98 | } break; 99 | 100 | default: { 101 | str = `zip:${str}`; 102 | } break; 103 | } 104 | } 105 | } 106 | 107 | return str; 108 | } 109 | 110 | function fromEditorPath(str) { 111 | switch (hostInfo) { 112 | case `coc-nvim`: { 113 | str = str.replace(/\.zip::/, `.zip/`); 114 | // The path for coc-nvim is in format of //zipfile://.yarn/... 115 | // So in order to convert it back, we use .* to match all the thing 116 | // before `zipfile:` 117 | return process.platform === `win32` 118 | ? str.replace(/^.*zipfile:\//, ``) 119 | : str.replace(/^.*zipfile:/, ``); 120 | } break; 121 | 122 | case `neovim`: { 123 | str = str.replace(/\.zip::/, `.zip/`); 124 | // The path for neovim is in format of zipfile:////.yarn/... 125 | return str.replace(/^zipfile:\/\//, ``); 126 | } break; 127 | 128 | case `vscode`: 129 | default: { 130 | return process.platform === `win32` 131 | ? str.replace(/^\^?(zip:|\/zip)\/+/, ``) 132 | : str.replace(/^\^?(zip:|\/zip)\/+/, `/`); 133 | } break; 134 | } 135 | } 136 | 137 | // Force enable 'allowLocalPluginLoads' 138 | // TypeScript tries to resolve plugins using a path relative to itself 139 | // which doesn't work when using the global cache 140 | // https://github.com/microsoft/TypeScript/blob/1b57a0395e0bff191581c9606aab92832001de62/src/server/project.ts#L2238 141 | // VSCode doesn't want to enable 'allowLocalPluginLoads' due to security concerns but 142 | // TypeScript already does local loads and if this code is running the user trusts the workspace 143 | // https://github.com/microsoft/vscode/issues/45856 144 | const ConfiguredProject = tsserver.server.ConfiguredProject; 145 | const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype; 146 | ConfiguredProject.prototype.enablePluginsWithOptions = function() { 147 | this.projectService.allowLocalPluginLoads = true; 148 | return originalEnablePluginsWithOptions.apply(this, arguments); 149 | }; 150 | 151 | // And here is the point where we hijack the VSCode <-> TS communications 152 | // by adding ourselves in the middle. We locate everything that looks 153 | // like an absolute path of ours and normalize it. 154 | 155 | const Session = tsserver.server.Session; 156 | const {onMessage: originalOnMessage, send: originalSend} = Session.prototype; 157 | let hostInfo = `unknown`; 158 | 159 | Object.assign(Session.prototype, { 160 | onMessage(/** @type {string | object} */ message) { 161 | const isStringMessage = typeof message === 'string'; 162 | const parsedMessage = isStringMessage ? JSON.parse(message) : message; 163 | 164 | if ( 165 | parsedMessage != null && 166 | typeof parsedMessage === `object` && 167 | parsedMessage.arguments && 168 | typeof parsedMessage.arguments.hostInfo === `string` 169 | ) { 170 | hostInfo = parsedMessage.arguments.hostInfo; 171 | if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK) { 172 | if (/(\/|-)1\.([1-5][0-9]|60)\./.test(process.env.VSCODE_IPC_HOOK)) { 173 | hostInfo += ` <1.61`; 174 | } else if (/(\/|-)1\.(6[1-5])\./.test(process.env.VSCODE_IPC_HOOK)) { 175 | hostInfo += ` <1.66`; 176 | } 177 | } 178 | } 179 | 180 | const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => { 181 | return typeof value === 'string' ? fromEditorPath(value) : value; 182 | }); 183 | 184 | return originalOnMessage.call( 185 | this, 186 | isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON) 187 | ); 188 | }, 189 | 190 | send(/** @type {any} */ msg) { 191 | return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => { 192 | return typeof value === `string` ? toEditorPath(value) : value; 193 | }))); 194 | } 195 | }); 196 | 197 | return tsserver; 198 | }; 199 | 200 | if (existsSync(absPnpApiPath)) { 201 | if (!process.versions.pnp) { 202 | // Setup the environment to be able to require typescript/lib/tsserverlibrary.js 203 | require(absPnpApiPath).setup(); 204 | } 205 | } 206 | 207 | // Defer to the real typescript/lib/tsserverlibrary.js your application uses 208 | module.exports = moduleWrapper(absRequire(`typescript/lib/tsserverlibrary.js`)); 209 | -------------------------------------------------------------------------------- /.yarn/sdks/typescript/lib/typescript.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const {existsSync} = require(`fs`); 4 | const {createRequire, createRequireFromPath} = require(`module`); 5 | const {resolve} = require(`path`); 6 | 7 | const relPnpApiPath = "../../../../.pnp.cjs"; 8 | 9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); 10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); 11 | 12 | if (existsSync(absPnpApiPath)) { 13 | if (!process.versions.pnp) { 14 | // Setup the environment to be able to require typescript/lib/typescript.js 15 | require(absPnpApiPath).setup(); 16 | } 17 | } 18 | 19 | // Defer to the real typescript/lib/typescript.js your application uses 20 | module.exports = absRequire(`typescript/lib/typescript.js`); 21 | -------------------------------------------------------------------------------- /.yarn/sdks/typescript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typescript", 3 | "version": "4.7.2-sdk", 4 | "main": "./lib/typescript.js", 5 | "type": "commonjs" 6 | } 7 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | enableGlobalCache: true 2 | 3 | nodeLinker: pnp 4 | 5 | yarnPath: .yarn/releases/yarn-4.0.0-rc.6.cjs 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # walletkit 🔑 2 | 3 | [![NPM](https://img.shields.io/npm/v/@gokiprotocol/walletkit)](https://www.npmjs.com/package/@gokiprotocol/walletkit) 4 | [![License](https://img.shields.io/npm/l/@gokiprotocol/walletkit)](/LICENSE) 5 | 6 | ![Banner](/images/banner.png) 7 | 8 | WalletKit is a React library that allows a Solana dApp to display a modal for connecting wallets. 9 | 10 | It is intended to be used with [use-solana](https://github.com/saber-hq/saber-common/tree/master/packages/use-solana). 11 | 12 | ## Developing 13 | 14 | ### Adding a Wallet 15 | 16 | To add a wallet, please add it to [use-solana](https://github.com/saber-hq/saber-common/tree/master/packages/use-solana). 17 | 18 | `use-solana` supports wallet adapters from the official Solana wallet adapter library, so it may be as easy as adding a wallet to an array. 19 | 20 | ## Installation 21 | 22 | ```bash 23 | yarn add @gokiprotocol/walletkit 24 | ``` 25 | 26 | ## Usage 27 | 28 | Check out the [example app](/packages/example) to understand how to use this library. 29 | 30 | ## Publishing 31 | 32 | ``` 33 | yarn lerna version --force-publish --no-git-tag-version 34 | 35 | # This is important for updating yarn.lock! 36 | yarn install 37 | 38 | git tag vx.x.x 39 | git push origin HEAD 40 | git push origin vx.x.x 41 | ``` 42 | 43 | ## License 44 | 45 | GPL v3 46 | -------------------------------------------------------------------------------- /images/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GokiProtocol/walletkit/be0b834b2a12c06b8696a1e3b2c97dd992a7c6bd/images/banner.png -------------------------------------------------------------------------------- /images/wallet-intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GokiProtocol/walletkit/be0b834b2a12c06b8696a1e3b2c97dd992a7c6bd/images/wallet-intro.png -------------------------------------------------------------------------------- /images/wallet-select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GokiProtocol/walletkit/be0b834b2a12c06b8696a1e3b2c97dd992a7c6bd/images/wallet-select.png -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "useWorkspaces": true, 3 | "packages": ["packages/*"], 4 | "version": "1.7.3", 5 | "npmClient": "yarn" 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@gokiprotocol/walletkit-monorepo", 3 | "version": "0.0.0", 4 | "description": "Wallet connector modal for Solana dApps.", 5 | "repository": "git@github.com:GokiProtocol/walletkit.git", 6 | "author": "Goki Rajesh ", 7 | "license": "GPL-3.0", 8 | "private": true, 9 | "devDependencies": { 10 | "@babel/core": "^7.18.2", 11 | "@babel/plugin-proposal-private-property-in-object": "^7.17.12", 12 | "@rushstack/eslint-patch": "^1.1.3", 13 | "@saberhq/eslint-config": "^1.13.19", 14 | "@saberhq/eslint-config-react": "^1.13.19", 15 | "@saberhq/tsconfig": "^1.13.19", 16 | "@types/babel__core": "^7.1.19", 17 | "@yarnpkg/doctor": "^4.0.0-rc.6", 18 | "babel-loader": "^8.2.5", 19 | "buffer": "^6.0.3", 20 | "eslint": "^8.16.0", 21 | "eslint-import-resolver-node": "^0.3.6", 22 | "eslint-plugin-import": "^2.26.0", 23 | "husky": "^8.0.1", 24 | "lerna": "^4.0.0", 25 | "lint-staged": "^12.4.2", 26 | "prettier": "^2.6.2", 27 | "typescript": "^4.7.2", 28 | "webpack": "^5.72.1" 29 | }, 30 | "workspaces": [ 31 | "packages/*" 32 | ], 33 | "scripts": { 34 | "build": "yarn workspaces foreach --exclude @moving/workspace -vpti run build", 35 | "lint": "eslint --cache .", 36 | "lint:ci": "eslint --cache . --max-warnings=0", 37 | "typecheck": "tsc", 38 | "prepare": "husky install" 39 | }, 40 | "lint-staged": { 41 | "*.{ts,tsx}": "eslint --cache --fix", 42 | "*.{js,json,jsx,html,css,md,yml,yaml}": "prettier --write" 43 | }, 44 | "packageManager": "yarn@4.0.0-rc.6" 45 | } 46 | -------------------------------------------------------------------------------- /packages/example/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /packages/example/README.md: -------------------------------------------------------------------------------- 1 | # WalletKit example 2 | 3 | The example is live at [walletkit.goki.so/](https://walletkit.goki.so/). 4 | 5 | ## Running 6 | 7 | ```bash 8 | # in root of the Git repo, to build dependencies 9 | yarn install 10 | yarn build 11 | 12 | # in packages/example/ 13 | yarn start 14 | ``` 15 | -------------------------------------------------------------------------------- /packages/example/craco.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require("webpack"); 2 | 3 | module.exports = { 4 | babel: { 5 | presets: [ 6 | [ 7 | "@babel/preset-react", 8 | { runtime: "automatic", importSource: "@emotion/react" }, 9 | ], 10 | ], 11 | plugins: ["@emotion/babel-plugin"], 12 | }, 13 | eslint: { 14 | enable: false, 15 | }, 16 | typescript: { enableTypeChecking: false }, 17 | webpack: { 18 | configure: (config) => { 19 | config.ignoreWarnings = [/Failed to parse source map/]; 20 | config.plugins.unshift( 21 | new webpack.ProvidePlugin({ 22 | Buffer: ["buffer", "Buffer"], 23 | }) 24 | ); 25 | 26 | config.module.rules.push({ 27 | test: /\.m?js/, 28 | resolve: { 29 | fullySpecified: false, 30 | }, 31 | }); 32 | 33 | // solana wallet adapter, ledger need to be transpiled 34 | config.module.rules.push({ 35 | test: /\.js/, 36 | loader: require.resolve("babel-loader"), 37 | exclude: (file) => 38 | !file.includes("@solana/wallet-adapter") && 39 | !file.includes("@ledgerhq/devices") && 40 | !file.includes("@saberhq/use-solana"), 41 | }); 42 | return config; 43 | }, 44 | }, 45 | }; 46 | -------------------------------------------------------------------------------- /packages/example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@gokiprotocol/example", 3 | "version": "1.7.3", 4 | "private": true, 5 | "license": "GPL-3.0", 6 | "dependencies": { 7 | "@craco/craco": "^6.4.3", 8 | "@emotion/react": "^11.9.0", 9 | "@emotion/styled": "^11.8.1", 10 | "@gokiprotocol/walletkit": "^1.7.3", 11 | "@reach/dialog": "^0.17.0", 12 | "@saberhq/solana-contrib": "^1.13.19", 13 | "@saberhq/token-utils": "^1.13.19", 14 | "@saberhq/use-solana": "^1.13.19", 15 | "@solana/web3.js": "^1.43.2", 16 | "@types/bn.js": "^5.1.0", 17 | "@types/react": "^18.0.9", 18 | "bn.js": "^5.2.1", 19 | "buffer": "^6.0.3", 20 | "jsbi": "^4.3.0", 21 | "polished": "^4.2.2", 22 | "react": "^18.1.0", 23 | "react-dom": "^18.1.0", 24 | "react-scripts": "5.0.1", 25 | "tiny-invariant": "^1.2.0" 26 | }, 27 | "scripts": { 28 | "start": "craco start", 29 | "build": "craco build", 30 | "test": "craco test" 31 | }, 32 | "browserslist": { 33 | "production": [ 34 | ">0.2%", 35 | "not dead", 36 | "not op_mini all" 37 | ], 38 | "development": [ 39 | "last 1 chrome version", 40 | "last 1 firefox version", 41 | "last 1 safari version" 42 | ] 43 | }, 44 | "devDependencies": { 45 | "@babel/core": "^7.18.2", 46 | "@babel/plugin-proposal-private-property-in-object": "^7.17.12", 47 | "@babel/preset-react": "^7.17.12", 48 | "@emotion/babel-plugin": "^11.9.2", 49 | "@types/babel__core": "^7.1.19", 50 | "@types/jest": "^27.5.1", 51 | "@types/node": "^17.0.36", 52 | "@types/react-dom": "18.0.5", 53 | "babel-loader": "^8.2.5", 54 | "babel-preset-react-app": "^10.0.1", 55 | "react-dev-utils": "^12.0.1", 56 | "typescript": "^4.7.2", 57 | "webpack": "^5.72.1" 58 | }, 59 | "resolutions": { 60 | "@solana/buffer-layout": "^4" 61 | }, 62 | "repository": "git@github.com:GokiProtocol/walletkit.git" 63 | } 64 | -------------------------------------------------------------------------------- /packages/example/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GokiProtocol/walletkit/be0b834b2a12c06b8696a1e3b2c97dd992a7c6bd/packages/example/public/favicon.ico -------------------------------------------------------------------------------- /packages/example/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 26 | 27 | 36 | WalletKit by Goki 37 | 38 | 39 | 40 |
41 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /packages/example/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GokiProtocol/walletkit/be0b834b2a12c06b8696a1e3b2c97dd992a7c6bd/packages/example/public/logo192.png -------------------------------------------------------------------------------- /packages/example/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GokiProtocol/walletkit/be0b834b2a12c06b8696a1e3b2c97dd992a7c6bd/packages/example/public/logo512.png -------------------------------------------------------------------------------- /packages/example/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /packages/example/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /packages/example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import { WalletKitProvider } from "@gokiprotocol/walletkit"; 2 | 3 | import { Body } from "./Body"; 4 | 5 | export const BREAKPOINT_SIZES = [576, 780, 992, 1200] as const; 6 | 7 | const maxMediaQueries = BREAKPOINT_SIZES.map( 8 | (bp) => `@media (max-width: ${bp}px)` 9 | ); 10 | 11 | export const breakpoints = { 12 | mobile: maxMediaQueries[0], 13 | tablet: maxMediaQueries[1], 14 | medium: maxMediaQueries[2], 15 | }; 16 | 17 | const App: React.FC = () => { 18 | return ( 19 | 28 | ), 29 | }} 30 | debugMode={true} // you may want to set this in REACT_APP_DEBUG_MODE 31 | > 32 | 33 | 34 | ); 35 | }; 36 | 37 | export default App; 38 | -------------------------------------------------------------------------------- /packages/example/src/Body.tsx: -------------------------------------------------------------------------------- 1 | import { css } from "@emotion/react"; 2 | import styled from "@emotion/styled"; 3 | import { ConnectWalletButton } from "@gokiprotocol/walletkit"; 4 | import { PendingTransaction } from "@saberhq/solana-contrib"; 5 | import { createInitMintInstructions } from "@saberhq/token-utils"; 6 | import { useConnectedWallet, useSolana } from "@saberhq/use-solana"; 7 | import { Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js"; 8 | import { lighten } from "polished"; 9 | import { useCallback, useEffect, useState } from "react"; 10 | import invariant from "tiny-invariant"; 11 | 12 | import { breakpoints } from "./App"; 13 | 14 | export const Body: React.FC = () => { 15 | const { walletProviderInfo, disconnect, providerMut, network, setNetwork } = 16 | useSolana(); 17 | const wallet = useConnectedWallet(); 18 | const [balance, setBalance] = useState(null); 19 | 20 | const refetchSOL = useCallback(async () => { 21 | if (wallet && providerMut) { 22 | setBalance(await providerMut.connection.getBalance(wallet.publicKey)); 23 | } 24 | }, [providerMut, wallet]); 25 | 26 | useEffect(() => { 27 | void refetchSOL(); 28 | }, [refetchSOL]); 29 | 30 | return ( 31 | 32 |

41 | WalletKit 42 |

43 |

49 | A wallet connector for Solana dApps. 50 |

51 | 52 |

58 | Powered by Goki 59 |

60 | {wallet ? ( 61 | 62 |

Connected Wallet

63 |
    64 |
  • Wallet key: {wallet?.publicKey?.toString()}
  • 65 |
  • Provider: {walletProviderInfo?.name}
  • 66 |
  • Network: {network}
  • 67 |
  • 68 | Balance:{" "} 69 | {typeof balance === "number" 70 | ? `${(balance / LAMPORTS_PER_SOL).toLocaleString()} SOL` 71 | : "--"} 72 |
  • 73 |
74 | 75 | 76 | 83 | 101 | 117 | 118 |
119 | ) : ( 120 | 121 |

Connect a wallet above.

122 |
123 | )} 124 |
125 | ); 126 | }; 127 | 128 | const AppWrapper = styled.div` 129 | background-color: #282c34; 130 | min-height: 100vh; 131 | display: flex; 132 | flex-direction: column; 133 | align-items: center; 134 | justify-content: center; 135 | font-size: calc(10px + 2vmin); 136 | color: white; 137 | text-align: center; 138 | `; 139 | 140 | const WalletInfo = styled.div` 141 | background: ${lighten(0.1, "#282c34")}; 142 | padding: 12px 24px; 143 | border-radius: 8px; 144 | font-size: 16px; 145 | text-align: left; 146 | `; 147 | 148 | const Button = styled.button` 149 | display: flex; 150 | align-items: center; 151 | gap: 12px; 152 | 153 | cursor: pointer; 154 | border: none; 155 | outline: none; 156 | height: 40px; 157 | mix-blend-mode: normal; 158 | box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25); 159 | border-radius: 4px; 160 | padding: 0 12px; 161 | 162 | background: #000; 163 | color: #fff; 164 | &:hover { 165 | background: ${lighten(0.1, "#000")}; 166 | } 167 | 168 | font-weight: bold; 169 | font-size: 16px; 170 | line-height: 20px; 171 | `; 172 | 173 | const Buttons = styled.div` 174 | display: flex; 175 | flex-direction: row; 176 | gap: 12px; 177 | `; 178 | -------------------------------------------------------------------------------- /packages/example/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /packages/example/src/index.tsx: -------------------------------------------------------------------------------- 1 | import "./index.css"; 2 | 3 | import React from "react"; 4 | import ReactDOM from "react-dom"; 5 | 6 | import App from "./App"; 7 | 8 | ReactDOM.render( 9 | 10 | 11 | , 12 | document.getElementById("root") 13 | ); 14 | -------------------------------------------------------------------------------- /packages/example/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /packages/example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "exclude": ["build/"], 4 | "include": ["src/"], 5 | "compilerOptions": { 6 | "allowJs": true, 7 | "module": "esnext", 8 | "resolveJsonModule": true, 9 | "isolatedModules": true, 10 | "jsx": "react-jsx", 11 | "jsxImportSource": "@emotion/react" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/walletkit/README.md: -------------------------------------------------------------------------------- 1 | # `@gokiprotocol/walletkit` 2 | 3 | WalletKit is a React library that allows a Solana dApp to display a modal for connecting wallets. 4 | 5 | ## Common questions 6 | 7 | ### My modal is behind something else. How do I fix this? 8 | 9 | You can change the z-index of the modal like so: 10 | 11 | ``` 12 | [data-reach-dialog-overlay] { 13 | z-index: 9999999; 14 | } 15 | ``` 16 | -------------------------------------------------------------------------------- /packages/walletkit/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@gokiprotocol/walletkit", 3 | "version": "1.7.3", 4 | "description": "Wallet connector modal for Solana dApps.", 5 | "author": "Goki Rajesh ", 6 | "homepage": "https://goki.so", 7 | "license": "GPL-3.0", 8 | "main": "dist/cjs/index.js", 9 | "module": "dist/esm/index.js", 10 | "files": [ 11 | "dist/", 12 | "src/" 13 | ], 14 | "repository": "git@github.com:GokiProtocol/walletkit.git", 15 | "scripts": { 16 | "build": "rm -fr dist/ && tsc && tsc -P tsconfig.cjs.json" 17 | }, 18 | "bugs": { 19 | "url": "https://github.com/GokiProtocol/walletkit/issues" 20 | }, 21 | "devDependencies": { 22 | "@emotion/react": "^11.9.0", 23 | "@emotion/styled": "^11.8.1", 24 | "@reach/dialog": "^0.17.0", 25 | "@saberhq/solana-contrib": "^1.13.19", 26 | "@saberhq/tsconfig": "^1.13.19", 27 | "@saberhq/use-solana": "^1.13.19", 28 | "@solana/web3.js": "^1.43.2", 29 | "@types/react-dom": "18.0.5", 30 | "bn.js": "^5.2.1", 31 | "react": "^18.1.0", 32 | "react-dom": "^18.1.0", 33 | "typescript": "^4.7.2" 34 | }, 35 | "dependencies": { 36 | "@react-spring/web": "^9.4.5", 37 | "@types/react": "^18.0.9", 38 | "react-device-detect": "^2.2.2", 39 | "react-use-gesture": "^9.1.3", 40 | "tslib": "^2.4.0" 41 | }, 42 | "peerDependencies": { 43 | "@emotion/react": "^11", 44 | "@emotion/styled": "^11", 45 | "@reach/dialog": "^0.16.2 || ^0.17", 46 | "@saberhq/solana-contrib": "^1.12.4", 47 | "@saberhq/use-solana": "^1.12.4", 48 | "react": "^17 || ^18", 49 | "react-dom": "^17 || ^18" 50 | }, 51 | "publishConfig": { 52 | "access": "public" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/walletkit/src/WalletKitProvider.tsx: -------------------------------------------------------------------------------- 1 | import type { UseSolanaArgs } from "@saberhq/use-solana"; 2 | import { SolanaProvider } from "@saberhq/use-solana"; 3 | import React, { useContext, useMemo, useState } from "react"; 4 | 5 | import { 6 | ModalStep, 7 | WalletSelectorModal, 8 | } from "./components/WalletSelectorModal"; 9 | import type { WalletKitArgs } from "./types"; 10 | 11 | export { useConnectedWallet, useSolana, useWallet } from "@saberhq/use-solana"; 12 | 13 | export interface WalletKit { 14 | connect: () => void; 15 | } 16 | 17 | export const WalletKitContext = React.createContext(null); 18 | 19 | interface Props extends WalletKitArgs, UseSolanaArgs { 20 | children: React.ReactNode; 21 | } 22 | 23 | export const WalletKitProvider: React.FC = ({ 24 | children, 25 | app, 26 | initialStep = ModalStep.Intro, 27 | debugMode = false, 28 | ...solanaProviderArgs 29 | }: Props) => { 30 | const [showWalletSelector, setShowWalletSelector] = useState(false); 31 | 32 | const kit = useMemo(() => { 33 | return { connect: () => setShowWalletSelector(true) }; 34 | }, []); 35 | 36 | return ( 37 | 38 | 39 | setShowWalletSelector(false)} 44 | debugMode={debugMode} 45 | /> 46 | {children} 47 | 48 | 49 | ); 50 | }; 51 | 52 | /** 53 | * Returns a function which shows the wallet selector modal. 54 | */ 55 | export const useWalletKit = (): WalletKit => { 56 | const kit = useContext(WalletKitContext); 57 | if (!kit) { 58 | throw new Error("Not in WalletConnector context"); 59 | } 60 | return kit; 61 | }; 62 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/ConnectWalletButton/index.tsx: -------------------------------------------------------------------------------- 1 | import { css } from "@emotion/react"; 2 | import styled from "@emotion/styled"; 3 | 4 | import { useWalletKit } from "../../WalletKitProvider"; 5 | 6 | interface Props 7 | extends Omit< 8 | React.DetailedHTMLProps< 9 | React.ButtonHTMLAttributes, 10 | HTMLButtonElement 11 | >, 12 | "onClick" 13 | > { 14 | variant?: "primary" | "secondary"; 15 | } 16 | 17 | const Logomark: React.FC> = (props) => ( 18 | 26 | 27 | 31 | 35 | 39 | 40 | 41 | 42 | 48 | 49 | 50 | 51 | ); 52 | 53 | export const ConnectWalletButton: React.FC = ({ 54 | variant = "primary", 55 | ...buttonProps 56 | }: Props) => { 57 | const { connect } = useWalletKit(); 58 | return ( 59 | 68 | ); 69 | }; 70 | 71 | const Button = styled.button<{ 72 | variant: "primary" | "secondary"; 73 | }>` 74 | display: flex; 75 | align-items: center; 76 | gap: 12px; 77 | 78 | cursor: pointer; 79 | border: none; 80 | outline: none; 81 | height: 40px; 82 | mix-blend-mode: normal; 83 | box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25); 84 | border-radius: 4px; 85 | padding: 0 12px; 86 | 87 | ${({ variant = "primary" }) => 88 | variant === "primary" 89 | ? css` 90 | background: #70ed9d; 91 | color: #000; 92 | &:hover { 93 | background: #9bf3bb; 94 | } 95 | ` 96 | : css` 97 | background: #000; 98 | color: #fff; 99 | &:hover { 100 | background: #1a1a1a; 101 | } 102 | `} 103 | 104 | & > span { 105 | font-weight: bold; 106 | font-size: 16px; 107 | line-height: 20px; 108 | } 109 | `; 110 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/LabeledInput.tsx: -------------------------------------------------------------------------------- 1 | import styled from "@emotion/styled"; 2 | 3 | type Props = React.DetailedHTMLProps< 4 | React.InputHTMLAttributes, 5 | HTMLInputElement 6 | > & { 7 | label: string; 8 | name: string; 9 | }; 10 | 11 | export const LabeledInput: React.FC = ({ 12 | label, 13 | ...inputProps 14 | }: Props) => { 15 | return ( 16 |
17 | 18 | 19 | 20 | 21 |
22 | ); 23 | }; 24 | 25 | const Fieldset = styled.fieldset` 26 | border: none; 27 | outline: none; 28 | 29 | height: 66px; 30 | position: relative; 31 | width: 100%; 32 | padding: 0; 33 | margin: 0; 34 | `; 35 | 36 | const InputBorder = styled.div` 37 | position: absolute; 38 | height: 56px; 39 | top: 10px; 40 | border: 1px solid #dfdfdf; 41 | box-sizing: border-box; 42 | border-radius: 4px; 43 | z-index: 1; 44 | width: 100%; 45 | padding: 0 4px; 46 | 47 | display: flex; 48 | align-items: center; 49 | 50 | &:hover { 51 | border: 1px solid #aaa; 52 | } 53 | &:focus-within { 54 | border: 1px solid #6764fb; 55 | } 56 | transition: border 0.2s ease; 57 | `; 58 | 59 | const Label = styled.label` 60 | position: absolute; 61 | display: block; 62 | left: 11px; 63 | z-index: 2; 64 | padding: 0 4px; 65 | height: 20px; 66 | 67 | background: #fff; 68 | font-size: 12px; 69 | line-height: 20px; 70 | display: flex; 71 | align-items: center; 72 | letter-spacing: -0.02em; 73 | 74 | color: #696969; 75 | `; 76 | 77 | const Input = styled.input` 78 | border: none; 79 | outline: none; 80 | height: 43px; 81 | 82 | padding: 0 11px; 83 | flex-grow: 1; 84 | font-size: 16px; 85 | line-height: 24px; 86 | letter-spacing: -0.02em; 87 | 88 | color: #000; 89 | &::placeholder { 90 | color: #b5b5b5; 91 | } 92 | `; 93 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/Modal/icons.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | export const BackIcon: React.FC> = (props) => ( 4 | 12 | 16 | 17 | ); 18 | 19 | export const CloseIcon: React.FC> = (props) => ( 20 | 28 | 35 | 42 | 43 | ); 44 | 45 | export const SolanaLogo: React.FC> = (props) => ( 46 | 54 | 58 | 62 | 66 | 70 | 74 | 78 | 84 | 85 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | ); 103 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/Modal/index.tsx: -------------------------------------------------------------------------------- 1 | import { css, Global } from "@emotion/react"; 2 | import styled from "@emotion/styled"; 3 | import { DialogContent, DialogOverlay } from "@reach/dialog"; 4 | import { animated, useSpring, useTransition } from "@react-spring/web"; 5 | import React from "react"; 6 | import { isMobile } from "react-device-detect"; 7 | import { useGesture } from "react-use-gesture"; 8 | 9 | import { BackIcon, CloseIcon, SolanaLogo } from "./icons"; 10 | 11 | export interface ModalProps { 12 | children: React.ReactNode; 13 | isOpen: boolean; 14 | onDismiss: () => void; 15 | darkenOverlay?: boolean; 16 | 17 | onBack?: () => void; 18 | hideCloseButton?: boolean; 19 | hideSolanaLogo?: boolean; 20 | } 21 | 22 | export const Modal: React.FC = ({ 23 | children, 24 | isOpen, 25 | onDismiss, 26 | darkenOverlay = true, 27 | 28 | onBack, 29 | hideCloseButton = false, 30 | hideSolanaLogo = true, 31 | }: ModalProps) => { 32 | const fadeTransition = useTransition(isOpen, { 33 | config: { duration: 150 }, 34 | from: { opacity: 0 }, 35 | enter: { opacity: 1 }, 36 | leave: { opacity: 0 }, 37 | }); 38 | 39 | const [{ y }, set] = useSpring(() => ({ 40 | y: 0, 41 | config: { mass: 1, tension: 210, friction: 20 }, 42 | })); 43 | const bind = useGesture({ 44 | onDrag: (state) => { 45 | set({ 46 | y: state.down ? state.movement[1] : 0, 47 | }); 48 | if ( 49 | state.movement[1] > 300 || 50 | (state.velocity > 3 && state.direction[1] > 0) 51 | ) { 52 | onDismiss(); 53 | } 54 | }, 55 | }); 56 | 57 | return ( 58 | <> 59 | {/* @reach/dialog/styles.css */} 60 | 85 | {fadeTransition( 86 | (styles, item) => 87 | item && ( 88 | 94 | `translateY(${n > 0 ? n : 0}px)` 103 | ), 104 | }, 105 | } 106 | : {})} 107 | > 108 | 109 | {onBack ? ( 110 | { 113 | e.stopPropagation(); 114 | e.preventDefault(); 115 | onBack(); 116 | }} 117 | > 118 | 119 | 120 | ) : ( 121 |
122 | )} 123 | {hideSolanaLogo ? ( 124 |
125 | ) : ( 126 | 127 | 128 | 129 | )} 130 | {hideCloseButton ? ( 131 |
132 | ) : ( 133 | { 136 | e.stopPropagation(); 137 | e.preventDefault(); 138 | onDismiss(); 139 | }} 140 | > 141 | 142 | 143 | )} 144 | 145 | {children} 146 | 147 | 148 | ) 149 | )} 150 | 151 | ); 152 | }; 153 | 154 | const LogoWrapper = styled.div` 155 | flex: 1 1 auto; 156 | 157 | display: flex; 158 | justify-content: center; 159 | `; 160 | 161 | const TopArea = styled.div` 162 | position: absolute; 163 | top: 12px; 164 | left: 16px; 165 | right: 16px; 166 | 167 | display: flex; 168 | align-items: center; 169 | justify-content: space-between; 170 | `; 171 | 172 | const ButtonIcon = styled.a` 173 | flex: 0 0 24px; 174 | color: #ccd2e3; 175 | &:hover { 176 | color: #adb6d2; 177 | } 178 | transition: 0.1s ease; 179 | `; 180 | 181 | const Content = styled.div` 182 | position: absolute; 183 | top: 28px; 184 | left: 0; 185 | right: 0; 186 | bottom: 0; 187 | `; 188 | 189 | const ModalWrapper = styled(animated(DialogContent))` 190 | * { 191 | box-sizing: border-box; 192 | } 193 | font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, 194 | Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", 195 | "Segoe UI Symbol"; 196 | 197 | position: relative; 198 | 199 | box-shadow: 0px 4px 16px rgba(207, 207, 207, 0.25); 200 | width: 100%; 201 | max-width: 360px; 202 | height: 608px; 203 | border-radius: 8px; 204 | background: #fff; 205 | color: #696969; 206 | 207 | font-weight: normal; 208 | font-size: 12px; 209 | line-height: 15px; 210 | letter-spacing: -0.02em; 211 | color: #696969; 212 | `; 213 | 214 | const StyledDialogOverlay = styled(animated(DialogOverlay), { 215 | shouldForwardProp(prop) { 216 | return prop !== "darkenOverlay"; 217 | }, 218 | })<{ 219 | darkenOverlay: boolean; 220 | }>` 221 | [data-reach-dialog-content] { 222 | padding: 0; 223 | } 224 | 225 | ${({ darkenOverlay }) => 226 | darkenOverlay 227 | ? css` 228 | background: rgba(0, 0, 0, 0.55); 229 | ` 230 | : css` 231 | background: none; 232 | `} 233 | `; 234 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/ButtonWithFooter.tsx: -------------------------------------------------------------------------------- 1 | import styled from "@emotion/styled"; 2 | 3 | interface Props 4 | extends React.DetailedHTMLProps< 5 | React.ButtonHTMLAttributes, 6 | HTMLButtonElement 7 | > { 8 | footer?: React.ReactNode; 9 | } 10 | 11 | export const ButtonWithFooter: React.FC = ({ 12 | footer, 13 | children, 14 | ...props 15 | }: Props) => { 16 | return ( 17 | 18 | {children} 19 | {footer} 20 | 21 | ); 22 | }; 23 | 24 | export const BottomArea = styled.div` 25 | position: absolute; 26 | left: 28px; 27 | right: 28px; 28 | bottom: 28px; 29 | 30 | display: flex; 31 | flex-direction: column; 32 | align-items: center; 33 | gap: 18px; 34 | `; 35 | 36 | export const FooterText = styled.div` 37 | font-size: 12px; 38 | line-height: 15px; 39 | letter-spacing: -0.02em; 40 | color: #696969; 41 | & > a { 42 | color: #696969; 43 | font-weight: bold; 44 | } 45 | `; 46 | 47 | export const BigButton = styled.button` 48 | border: none; 49 | outline: none; 50 | 51 | border-radius: 16px; 52 | height: 55px; 53 | width: 100%; 54 | 55 | display: flex; 56 | align-items: center; 57 | justify-content: center; 58 | 59 | font-weight: bold; 60 | font-size: 16px; 61 | line-height: 20px; 62 | text-align: center; 63 | 64 | background: #000000; 65 | color: #fff; 66 | &:hover { 67 | background: #212121; 68 | } 69 | &:active { 70 | background: #363636; 71 | } 72 | transition: 0.2s ease; 73 | cursor: pointer; 74 | &:disabled { 75 | background: #aaa; 76 | cursor: not-allowed; 77 | } 78 | `; 79 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/WalletStepConnecting/ConnectingAnimation.tsx: -------------------------------------------------------------------------------- 1 | import { css } from "@emotion/react"; 2 | import { useEffect, useMemo, useState } from "react"; 3 | 4 | interface Props { 5 | fill?: string; 6 | frameMs?: number; 7 | } 8 | 9 | export const ConnectingAnimation: React.FC = ({ 10 | fill = "#6764FB", 11 | frameMs = 160, 12 | }: Props) => { 13 | const [now, setNow] = useState(Date.now()); 14 | 15 | useEffect(() => { 16 | const interval = setInterval(() => { 17 | setNow(Date.now()); 18 | }, frameMs); 19 | return () => clearInterval(interval); 20 | }, [frameMs]); 21 | 22 | const frame = useMemo(() => Math.floor(now / frameMs) % 7, [frameMs, now]); 23 | 24 | return ( 25 | 37 | 38 | 44 | 50 | 56 | 57 | 63 | 69 | 75 | 76 | ); 77 | }; 78 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/WalletStepConnecting/index.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable jsx-a11y/anchor-is-valid */ 2 | import { css } from "@emotion/react"; 3 | import styled from "@emotion/styled"; 4 | import { DefaultWalletType, useSolana } from "@saberhq/use-solana"; 5 | import { useCallback, useEffect, useState } from "react"; 6 | import { isMobile } from "react-device-detect"; 7 | 8 | import { BottomArea, FooterText } from "../ButtonWithFooter"; 9 | import type { ProviderInfo } from "../WalletStepSelect"; 10 | import { ConnectingAnimation } from "./ConnectingAnimation"; 11 | 12 | interface Props { 13 | appIcon: React.ReactNode; 14 | info: ProviderInfo; 15 | onBack?: () => void; 16 | onComplete?: () => void; 17 | } 18 | 19 | export const WalletStepConnecting: React.FC = ({ 20 | appIcon, 21 | info, 22 | onBack, 23 | onComplete, 24 | }: Props) => { 25 | const walletProviderInfo = info.info; 26 | const icon = 27 | typeof walletProviderInfo.icon === "string" ? ( 28 | {`Icon 32 | ) : ( 33 | 34 | ); 35 | const { activate, connected, wallet } = useSolana(); 36 | const [error, setError] = useState(null); 37 | 38 | const isManualConnect = 39 | isMobile && 40 | (info.type === DefaultWalletType.Sollet || 41 | info.type === DefaultWalletType.Solflare); 42 | 43 | const doActivate = useCallback(async () => { 44 | try { 45 | await activate(info.type); 46 | setError(null); 47 | } catch (e) { 48 | setError((e as Error).message); 49 | } 50 | }, [activate, info.type]); 51 | 52 | // attempt to activate the wallet on initial load 53 | useEffect(() => { 54 | if (isManualConnect) { 55 | return; 56 | } 57 | // delay so people can see a message 58 | const timeout = setTimeout(() => { 59 | void doActivate(); 60 | }, 1); 61 | return () => clearTimeout(timeout); 62 | // only run this on the first display of this modal 63 | // eslint-disable-next-line react-hooks/exhaustive-deps 64 | }, []); 65 | 66 | // close modal only when the wallet is connected 67 | useEffect(() => { 68 | if (wallet && connected) { 69 | onComplete?.(); 70 | } 71 | }, [wallet, connected, onComplete]); 72 | 73 | return ( 74 | 75 | 76 | {error ? ( 77 | 78 | Error connecting wallet 79 | {error} 80 | 81 | { 88 | e.stopPropagation(); 89 | e.preventDefault(); 90 | void doActivate(); 91 | }} 92 | > 93 | Retry 94 | 95 | 96 | 97 | ) : ( 98 | 99 | Connecting... 100 | {isManualConnect ? ( 101 | 102 | Please{" "} 103 | { 110 | e.stopPropagation(); 111 | e.preventDefault(); 112 | void wallet?.connect(); 113 | }} 114 | > 115 | click here 116 | {" "} 117 | to unlock your {walletProviderInfo.name} wallet. 118 | 119 | ) : ( 120 | 121 | Please unlock your {walletProviderInfo.name} wallet. 122 | 123 | )} 124 | 125 | )} 126 | 127 | 128 | {icon} 129 | 130 | {appIcon} 131 | 132 | 133 | 134 | 135 | Having trouble?{" "} 136 | { 139 | e.stopPropagation(); 140 | e.preventDefault(); 141 | onBack?.(); 142 | }} 143 | > 144 | Go back 145 | 146 | 147 | 148 | 149 | 150 | ); 151 | }; 152 | 153 | const ConnectingHeader = styled.div` 154 | display: flex; 155 | flex-direction: column; 156 | gap: 9px; 157 | margin-top: 68px; 158 | margin-bottom: 71px; 159 | `; 160 | 161 | const Connecting = styled.h2` 162 | margin: 0; 163 | font-weight: bold; 164 | font-size: 24px; 165 | line-height: 29px; 166 | text-align: center; 167 | letter-spacing: -0.02em; 168 | color: #000000; 169 | `; 170 | 171 | const ConnectingInstructions = styled.p` 172 | margin: 0; 173 | font-weight: normal; 174 | font-size: 14px; 175 | line-height: 17px; 176 | text-align: center; 177 | letter-spacing: -0.02em; 178 | color: #696969; 179 | `; 180 | 181 | const Wrapper = styled.div` 182 | position: relative; 183 | overflow: hidden; 184 | 185 | top: 0; 186 | left: 0; 187 | width: 100%; 188 | height: 100%; 189 | `; 190 | 191 | const AppIcons = styled.div` 192 | display: grid; 193 | grid-template-columns: 48px 1fr 48px; 194 | grid-column-gap: 20px; 195 | align-items: center; 196 | width: 192px; 197 | 198 | & > img, 199 | & > svg { 200 | width: 48px; 201 | height: 48px; 202 | } 203 | `; 204 | 205 | const AppIconsWrapper = styled.div` 206 | width: 100%; 207 | display: flex; 208 | justify-content: center; 209 | `; 210 | 211 | const ConnectingWrapper = styled.div` 212 | position: absolute; 213 | bottom: 0; 214 | left: 0; 215 | right: 0; 216 | height: calc(100% - 154px); 217 | 218 | background: #f9f9f9; 219 | border-radius: 32px 32px 8px 8px; 220 | 221 | animation: fadeIn 0.2s forwards; 222 | animation-timing-function: ease-out; 223 | 224 | @keyframes fadeIn { 225 | 0% { 226 | bottom: -300px; 227 | } 228 | 100% { 229 | bottom: 0; 230 | } 231 | } 232 | `; 233 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/WalletStepIntro/DefaultAppIcon.tsx: -------------------------------------------------------------------------------- 1 | import styled from "@emotion/styled"; 2 | 3 | export const DefaultAppIcon: React.FC = () => ?; 4 | 5 | export const Wrapper = styled.div` 6 | width: 48px; 7 | height: 48px; 8 | border-radius: 50%; 9 | border: 3px dashed #dedede; 10 | background: #f9f9f9; 11 | 12 | display: flex; 13 | align-items: center; 14 | justify-content: center; 15 | 16 | font-size: 36px; 17 | color: #dedede; 18 | user-select: none; 19 | `; 20 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/WalletStepIntro/Detail.tsx: -------------------------------------------------------------------------------- 1 | import styled from "@emotion/styled"; 2 | 3 | interface Props { 4 | icon: React.ReactNode; 5 | title: string; 6 | description: string; 7 | } 8 | 9 | export const Detail: React.FC = ({ 10 | icon, 11 | title, 12 | description, 13 | }: Props) => { 14 | return ( 15 | 16 | {icon} 17 | 18 | {title} 19 | {description} 20 | 21 | 22 | ); 23 | }; 24 | 25 | const Wrapper = styled.div` 26 | display: grid; 27 | grid-template-columns: 18px 1fr; 28 | grid-column-gap: 9px; 29 | width: 100%; 30 | `; 31 | 32 | const Info = styled.div` 33 | display: flex; 34 | flex-direction: column; 35 | gap: 4px; 36 | `; 37 | 38 | const Title = styled.span` 39 | font-weight: bold; 40 | font-size: 14px; 41 | line-height: 18px; 42 | letter-spacing: -0.02em; 43 | color: #000000; 44 | `; 45 | 46 | const Description = styled.p` 47 | margin: 0; 48 | font-size: 12px; 49 | line-height: 15px; 50 | letter-spacing: -0.02em; 51 | color: #696969; 52 | `; 53 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/WalletStepIntro/icons.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | export const SolanaIcon: React.FC> = (props) => ( 4 | 12 | 16 | 22 | 23 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | ); 38 | 39 | export const ConnectDots: React.FC> = (props) => ( 40 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | ); 57 | 58 | export const LockIcon: React.FC> = (props) => ( 59 | 67 | 72 | 78 | 79 | 80 | ); 81 | 82 | export const BoltIcon: React.FC> = (props) => ( 83 | 91 | 97 | 98 | ); 99 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/WalletStepIntro/index.tsx: -------------------------------------------------------------------------------- 1 | import { css } from "@emotion/react"; 2 | import styled from "@emotion/styled"; 3 | 4 | import { ButtonWithFooter } from "../ButtonWithFooter"; 5 | import { Detail } from "./Detail"; 6 | import { BoltIcon, ConnectDots, LockIcon, SolanaIcon } from "./icons"; 7 | 8 | interface Props { 9 | appName: string; 10 | appIcon?: React.ReactNode; 11 | onContinue?: () => void; 12 | } 13 | 14 | export const WalletStepIntro: React.FC = ({ 15 | appName, 16 | appIcon, 17 | onContinue, 18 | }: Props) => { 19 | return ( 20 | 21 | 22 | 23 | 24 | 25 |
img, 30 | & > svg { 31 | width: 100%; 32 | height: 100%; 33 | } 34 | `} 35 | > 36 | {appIcon} 37 |
38 |
39 |
40 | 41 | To use {appName}, you need to connect a Solana wallet. 42 | 43 | 44 | } 46 | title="You control your crypto" 47 | description="Using a non-custodial wallet enables you to control your crypto without having to trust third parties." 48 | /> 49 | } 51 | title="Transact quickly and cheaply" 52 | description="Solana's scalability ensures transactions remain less than $0.01 and at lightning fast speeds." 53 | /> 54 | 55 | 60 | First time using Solana?{" "} 61 | 66 | Learn more 67 | 68 | 69 | } 70 | > 71 | Continue 72 | 73 |
74 | ); 75 | }; 76 | 77 | const Wrapper = styled.div` 78 | padding: 28px; 79 | padding-top: 33px; 80 | `; 81 | 82 | const AppIcons = styled.div` 83 | display: grid; 84 | grid-template-columns: 48px 1fr 48px; 85 | grid-column-gap: 20px; 86 | align-items: center; 87 | width: 192px; 88 | `; 89 | 90 | const Instruction = styled.h2` 91 | font-weight: normal; 92 | margin-top: 27px; 93 | font-size: 24px; 94 | line-height: 30px; 95 | text-align: center; 96 | letter-spacing: -0.02em; 97 | color: #000000; 98 | `; 99 | 100 | const DetailsWrapper = styled.div` 101 | margin-top: 92px; 102 | display: grid; 103 | grid-row-gap: 28px; 104 | `; 105 | 106 | const AppIconsWrapper = styled.div` 107 | width: 100%; 108 | display: flex; 109 | justify-content: center; 110 | `; 111 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/WalletStepLedgerAdvanced/index.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable jsx-a11y/anchor-is-valid */ 2 | import styled from "@emotion/styled"; 3 | import { 4 | DEFAULT_WALLET_PROVIDERS, 5 | DefaultWalletType, 6 | useSolana, 7 | } from "@saberhq/use-solana"; 8 | import { useState } from "react"; 9 | 10 | import { LabeledInput } from "../../LabeledInput"; 11 | import { ButtonWithFooter } from "../ButtonWithFooter"; 12 | 13 | interface Props { 14 | onBack?: () => void; 15 | onError: (err: Error) => void; 16 | onSuccess?: () => void; 17 | } 18 | 19 | export const WalletStepLedgerAdvanced: React.FC = ({ 20 | onBack, 21 | onSuccess, 22 | onError, 23 | }: Props) => { 24 | const [accountStr, setAccountStr] = useState(""); 25 | const [changeStr, setChangeStr] = useState(""); 26 | const { activate } = useSolana(); 27 | 28 | return ( 29 | 30 | 31 | 32 | 33 |

Enter your Ledger account info

34 |

35 | Not sure what to enter here? You’re probably looking for the basic{" "} 36 | Ledger Connect. 37 |

38 | 39 | { 45 | setAccountStr(e.target.value); 46 | }} 47 | /> 48 | { 54 | setChangeStr(e.target.value); 55 | }} 56 | /> 57 | 58 | { 61 | try { 62 | const account = 63 | accountStr === "" ? undefined : parseInt(accountStr); 64 | const change = changeStr === "" ? undefined : parseInt(changeStr); 65 | await activate(DefaultWalletType.Ledger, { 66 | account, 67 | change, 68 | }); 69 | } catch (e) { 70 | onError?.(e as Error); 71 | return; 72 | } 73 | onSuccess?.(); 74 | }} 75 | footer={ 76 | <> 77 | Having trouble?{" "} 78 | { 81 | e.preventDefault(); 82 | e.stopPropagation(); 83 | onBack?.(); 84 | }} 85 | > 86 | Go back 87 | 88 | 89 | } 90 | > 91 | Continue 92 | 93 |
94 | ); 95 | }; 96 | 97 | const IconWrapper = styled.div` 98 | & > svg, 99 | & > img { 100 | width: 36px; 101 | height: 36px; 102 | } 103 | margin-bottom: 32px; 104 | `; 105 | 106 | const Wrapper = styled.div` 107 | padding: 28px; 108 | padding-top: 67px; 109 | 110 | & > h2 { 111 | font-weight: bold; 112 | font-size: 20px; 113 | line-height: 25px; 114 | letter-spacing: -0.02em; 115 | color: #000000; 116 | } 117 | 118 | & > p { 119 | font-weight: normal; 120 | font-size: 14px; 121 | line-height: 18px; 122 | letter-spacing: -0.02em; 123 | color: #696969; 124 | } 125 | `; 126 | 127 | const Fields = styled.div` 128 | display: flex; 129 | flex-direction: column; 130 | gap: 8px; 131 | width: 100%; 132 | `; 133 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/WalletStepRedirect/index.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable jsx-a11y/anchor-is-valid */ 2 | import styled from "@emotion/styled"; 3 | import type { WalletProviderInfo } from "@saberhq/use-solana"; 4 | import { useEffect, useMemo } from "react"; 5 | 6 | import { ButtonWithFooter } from "../ButtonWithFooter"; 7 | 8 | interface Props { 9 | info: WalletProviderInfo; 10 | } 11 | 12 | export const WalletStepRedirect: React.FC = ({ info }: Props) => { 13 | const providerURL = useMemo(() => { 14 | try { 15 | return new URL(info.url).hostname; 16 | } catch (e) { 17 | return info.url; 18 | } 19 | }, [info.url]); 20 | 21 | const icon = 22 | typeof info.icon === "string" ? ( 23 | {`Icon 24 | ) : ( 25 | 26 | ); 27 | 28 | // autoredirect after 1 second 29 | useEffect(() => { 30 | const timeout = setTimeout(() => { 31 | window.open(info.url, "_blank", "noopener"); 32 | }, 1_000); 33 | return () => clearTimeout(timeout); 34 | }); 35 | 36 | return ( 37 | 38 | {icon} 39 |

You're being redirected

40 |

41 | In order to use {info.name}, you must first install their browser 42 | extension. 43 |

44 |

45 | Make sure you only install their wallet from the official{" "} 46 | {providerURL} website. 47 |

48 | { 50 | window.open(info.url, "_blank", "noopener"); 51 | }} 52 | footer={ 53 | <> 54 | Finished installing?{" "} 55 | { 58 | e.preventDefault(); 59 | e.stopPropagation(); 60 | window.location.reload(); 61 | }} 62 | > 63 | Refresh 64 | 65 | 66 | } 67 | > 68 | Continue 69 | 70 |
71 | ); 72 | }; 73 | 74 | const IconWrapper = styled.div` 75 | & > svg, 76 | & > img { 77 | width: 36px; 78 | height: 36px; 79 | } 80 | margin-bottom: 32px; 81 | `; 82 | 83 | const Wrapper = styled.div` 84 | padding: 28px; 85 | padding-top: 67px; 86 | 87 | & > h2 { 88 | font-weight: bold; 89 | font-size: 20px; 90 | line-height: 25px; 91 | letter-spacing: -0.02em; 92 | color: #000000; 93 | } 94 | 95 | & > p { 96 | font-weight: normal; 97 | font-size: 14px; 98 | line-height: 18px; 99 | letter-spacing: -0.02em; 100 | color: #696969; 101 | } 102 | `; 103 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/WalletStepSecretKey/index.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable jsx-a11y/anchor-is-valid */ 2 | import { css } from "@emotion/react"; 3 | import styled from "@emotion/styled"; 4 | import { 5 | DEFAULT_WALLET_PROVIDERS, 6 | DefaultWalletType, 7 | useSolana, 8 | } from "@saberhq/use-solana"; 9 | import { Keypair } from "@solana/web3.js"; 10 | import { useMemo, useState } from "react"; 11 | 12 | import { LabeledInput } from "../../LabeledInput"; 13 | import { ButtonWithFooter } from "../ButtonWithFooter"; 14 | 15 | interface Props { 16 | onBack?: () => void; 17 | onError: (err: Error) => void; 18 | onSuccess?: () => void; 19 | } 20 | 21 | export const WalletStepSecretKey: React.FC = ({ 22 | onBack, 23 | onSuccess, 24 | onError, 25 | }: Props) => { 26 | const [keypairStr, setKeypairStr] = useState( 27 | JSON.stringify([...Keypair.generate().secretKey]) 28 | ); 29 | const [keypair, keypairErr] = useMemo(() => { 30 | try { 31 | return [ 32 | Keypair.fromSecretKey( 33 | Uint8Array.from(JSON.parse(keypairStr) as number[]) 34 | ), 35 | null, 36 | ]; 37 | } catch (e) { 38 | return [null, e as Error]; 39 | } 40 | }, [keypairStr]); 41 | const { activate } = useSolana(); 42 | 43 | return ( 44 | 45 | 46 | 47 | 48 |

Enter a JSON Keypair

49 |

54 | Warning: do not use this outside of testing. If you were told to go here 55 | by someone else, don't do it. 56 |

57 | 58 | { 64 | setKeypairStr(e.target.value); 65 | }} 66 | /> 67 | {keypair && ( 68 | 75 | )} 76 | 77 | {keypairErr && ( 78 |

79 | 84 | Error: {keypairErr.message} 85 | 86 |

87 | )} 88 | { 93 | if (!keypair) { 94 | throw new Error("keypair missing"); 95 | } 96 | try { 97 | await activate(DefaultWalletType.SecretKey, { 98 | secretKey: [...keypair.secretKey], 99 | }); 100 | } catch (e) { 101 | onError?.(e as Error); 102 | return; 103 | } 104 | onSuccess?.(); 105 | }} 106 | footer={ 107 | <> 108 | Having trouble?{" "} 109 | { 112 | e.preventDefault(); 113 | e.stopPropagation(); 114 | onBack?.(); 115 | }} 116 | > 117 | Go back 118 | 119 | 120 | } 121 | > 122 | Continue 123 | 124 |
125 | ); 126 | }; 127 | 128 | const IconWrapper = styled.div` 129 | & > svg, 130 | & > img { 131 | width: 36px; 132 | height: 36px; 133 | } 134 | margin-bottom: 32px; 135 | `; 136 | 137 | const Wrapper = styled.div` 138 | padding: 28px; 139 | padding-top: 67px; 140 | 141 | & > h2 { 142 | font-weight: bold; 143 | font-size: 20px; 144 | line-height: 25px; 145 | letter-spacing: -0.02em; 146 | color: #000000; 147 | } 148 | 149 | & > p { 150 | font-weight: normal; 151 | font-size: 14px; 152 | line-height: 18px; 153 | letter-spacing: -0.02em; 154 | color: #696969; 155 | } 156 | `; 157 | 158 | const Fields = styled.div` 159 | display: flex; 160 | flex-direction: column; 161 | gap: 8px; 162 | width: 100%; 163 | `; 164 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/WalletStepSelect/WalletProviderOption.tsx: -------------------------------------------------------------------------------- 1 | import styled from "@emotion/styled"; 2 | import type { 3 | DefaultWalletType, 4 | WalletProviderInfo, 5 | } from "@saberhq/use-solana"; 6 | import React, { useMemo } from "react"; 7 | 8 | interface Props { 9 | type: DefaultWalletType; 10 | info: WalletProviderInfo; 11 | 12 | onInstall?: (info: WalletProviderInfo) => void; 13 | onSelect?: () => void; 14 | } 15 | 16 | export const WalletProviderOption: React.FC = ({ 17 | type, 18 | info, 19 | onInstall, 20 | onSelect, 21 | }: Props) => { 22 | const mustInstall = 23 | typeof window !== "undefined" && info.isInstalled?.() === false; 24 | const icon = 25 | typeof info.icon === "string" ? ( 26 | {`Icon 27 | ) : ( 28 | 29 | ); 30 | 31 | const providerURL = useMemo(() => { 32 | try { 33 | const name = new URL(info.url).hostname; 34 | if (name.startsWith("www.")) { 35 | return name.slice(4); 36 | } 37 | return name; 38 | } catch (e) { 39 | return info.url; 40 | } 41 | }, [info.url]); 42 | 43 | return ( 44 | { 48 | e.stopPropagation(); 49 | e.preventDefault(); 50 | 51 | if (mustInstall) { 52 | onInstall?.(info); 53 | return; 54 | } 55 | onSelect?.(); 56 | }} 57 | > 58 | 59 | 60 | {icon} 61 | 62 | {info.name} 63 | 64 | {providerURL} 65 | {mustInstall ? " (not installed)" : ""} 66 | 67 | 68 | 69 | 70 | 71 | ); 72 | }; 73 | 74 | const IconWrapper = styled.div` 75 | height: 33px; 76 | width: 33px; 77 | 78 | & > img, 79 | & > svg { 80 | height: 100%; 81 | width: 100%; 82 | } 83 | `; 84 | 85 | const InfoTileWrapper = styled.div` 86 | flex: 1 1 auto; 87 | height: 100%; 88 | 89 | display: flex; 90 | align-items: center; 91 | `; 92 | 93 | const InfoTile = styled.div` 94 | display: grid; 95 | grid-template-columns: 33px 1fr; 96 | grid-column-gap: 16px; 97 | `; 98 | 99 | const ProviderDesc = styled.div` 100 | display: flex; 101 | flex-direction: column; 102 | `; 103 | 104 | const ProviderName = styled.span` 105 | font-weight: 600; 106 | font-size: 14px; 107 | line-height: 18px; 108 | letter-spacing: -0.02em; 109 | color: #000000; 110 | `; 111 | 112 | const ProviderUrl = styled.span` 113 | font-weight: normal; 114 | font-size: 12px; 115 | line-height: 15px; 116 | letter-spacing: -0.02em; 117 | color: #696969; 118 | `; 119 | 120 | const Wrapper = styled.div` 121 | width: 100%; 122 | height: 65px; 123 | user-select: none; 124 | cursor: pointer; 125 | padding: 0 28px; 126 | 127 | display: flex; 128 | align-items: center; 129 | 130 | background: #fff; 131 | .wallet-info-tile { 132 | border-bottom: 1px solid #f8f8f8; 133 | } 134 | &:hover { 135 | background: #f9f9f9; 136 | .wallet-info-tile { 137 | border-bottom: 1px solid #e6e6e6; 138 | } 139 | } 140 | `; 141 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/WalletStepSelect/index.tsx: -------------------------------------------------------------------------------- 1 | import styled from "@emotion/styled"; 2 | import type { WalletProviderInfo } from "@saberhq/use-solana"; 3 | import { 4 | DEFAULT_WALLET_PROVIDERS, 5 | DefaultWalletType, 6 | } from "@saberhq/use-solana"; 7 | import React, { useEffect, useState } from "react"; 8 | import { isMobile } from "react-device-detect"; 9 | 10 | import { WalletProviderOption } from "./WalletProviderOption"; 11 | 12 | export interface ProviderInfo { 13 | type: DefaultWalletType; 14 | info: WalletProviderInfo; 15 | mustInstall: boolean; 16 | } 17 | 18 | const getWalletProviders = (debugMode = false): readonly ProviderInfo[] => { 19 | const base = ( 20 | Object.entries(DEFAULT_WALLET_PROVIDERS) as readonly [ 21 | DefaultWalletType, 22 | WalletProviderInfo 23 | ][] 24 | ) 25 | .filter(([, p]) => 26 | typeof window !== "undefined" && isMobile ? p.isMobile : true 27 | ) 28 | .slice() 29 | .sort(([, a], [, b]) => { 30 | if (typeof window !== "undefined") { 31 | return (a.isInstalled?.() ?? true) === (b.isInstalled?.() ?? true) 32 | ? a.name < b.name 33 | ? -1 34 | : 1 35 | : a.isInstalled?.() ?? true 36 | ? -1 37 | : 1; 38 | } 39 | return a.name < b.name ? -1 : 1; 40 | }) 41 | .map( 42 | ([walletType, info]): ProviderInfo => ({ 43 | type: walletType, 44 | info, 45 | mustInstall: 46 | walletType === DefaultWalletType.ReadOnly 47 | ? !debugMode 48 | : !!( 49 | typeof window !== "undefined" && 50 | info.isInstalled && 51 | info.isInstalled() 52 | ), 53 | }) 54 | ) 55 | .filter((p) => 56 | debugMode 57 | ? true 58 | : p.type !== DefaultWalletType.SecretKey && 59 | p.type !== DefaultWalletType.ReadOnly 60 | ); 61 | return [ 62 | ...base, 63 | { 64 | type: DefaultWalletType.Ledger, 65 | info: { 66 | ...DEFAULT_WALLET_PROVIDERS.Ledger, 67 | name: "Ledger (advanced)", 68 | url: "https://ledger.com", 69 | isMobile: false, 70 | }, 71 | mustInstall: false, 72 | }, 73 | ]; 74 | }; 75 | 76 | interface Props { 77 | onSelect?: (info: ProviderInfo) => void; 78 | onInstall?: (info: WalletProviderInfo) => void; 79 | debugMode?: boolean; 80 | } 81 | 82 | export const WalletStepSelect: React.FC = ({ 83 | onSelect, 84 | onInstall, 85 | debugMode, 86 | }: Props) => { 87 | const [showUninstalled, setShowUninstalled] = useState(false); 88 | const [providerInfo, setProviderInfo] = useState( 89 | getWalletProviders(debugMode) 90 | ); 91 | 92 | useEffect(() => { 93 | // wait a second for everything to load 94 | const timeout = setTimeout(() => { 95 | setProviderInfo(getWalletProviders(debugMode)); 96 | }, 1_000); 97 | return () => clearTimeout(timeout); 98 | }, [debugMode]); 99 | 100 | return ( 101 | <> 102 | Select your wallet 103 | 104 | 105 | {providerInfo 106 | .filter((prov) => 107 | showUninstalled 108 | ? true 109 | : prov.mustInstall || !prov.info.isInstalled 110 | ) 111 | .map((fullInfo) => { 112 | const { info: provider, type } = fullInfo; 113 | return ( 114 | { 119 | onSelect?.(fullInfo); 120 | }} 121 | onInstall={onInstall} 122 | /> 123 | ); 124 | })} 125 | 126 | 127 | setShowUninstalled(!showUninstalled)}> 128 | {showUninstalled ? "Hide" : "Show"} uninstalled wallets 129 | 130 | 131 | 132 | 133 | ); 134 | }; 135 | 136 | const ScrollArea = styled.div` 137 | height: calc(100% - 125px); 138 | overflow-y: scroll; 139 | `; 140 | 141 | const Wallets = styled.div` 142 | display: grid; 143 | grid-auto-flow: row; 144 | grid-auto-rows: 65px; 145 | `; 146 | 147 | const Heading = styled.h2` 148 | padding: 48px 28px 0; 149 | 150 | font-weight: bold; 151 | font-size: 20px; 152 | line-height: 25px; 153 | letter-spacing: -0.02em; 154 | color: #000000; 155 | margin-bottom: 24px; 156 | `; 157 | 158 | const ShowUninstalled = styled.a` 159 | text-decoration: none; 160 | cursor: pointer; 161 | &:hover { 162 | text-decoration: underline; 163 | } 164 | `; 165 | 166 | const ShowUninstalledWrapper = styled.div` 167 | margin: 24px 0; 168 | width: 100%; 169 | 170 | display: flex; 171 | flex-direction: column; 172 | align-items: center; 173 | `; 174 | -------------------------------------------------------------------------------- /packages/walletkit/src/components/WalletSelectorModal/index.tsx: -------------------------------------------------------------------------------- 1 | import type { WalletProviderInfo } from "@saberhq/use-solana"; 2 | import { DefaultWalletType, useSolana } from "@saberhq/use-solana"; 3 | import React, { useMemo, useState } from "react"; 4 | import { isMobile } from "react-device-detect"; 5 | 6 | import type { WalletKitArgs } from "../../types"; 7 | import type { ModalProps } from "../Modal"; 8 | import { Modal } from "../Modal"; 9 | import { WalletStepConnecting } from "./WalletStepConnecting"; 10 | import { WalletStepIntro } from "./WalletStepIntro"; 11 | import { DefaultAppIcon } from "./WalletStepIntro/DefaultAppIcon"; 12 | import { WalletStepLedgerAdvanced } from "./WalletStepLedgerAdvanced"; 13 | import { WalletStepRedirect } from "./WalletStepRedirect"; 14 | import { WalletStepSecretKey } from "./WalletStepSecretKey"; 15 | import type { ProviderInfo } from "./WalletStepSelect"; 16 | import { WalletStepSelect } from "./WalletStepSelect"; 17 | 18 | type Props = Omit & WalletKitArgs; 19 | 20 | export enum ModalStep { 21 | Intro = "intro", 22 | Select = "select", 23 | Redirect = "redirect", 24 | Connecting = "connecting", 25 | LedgerAdvanced = "ledger-advanced", 26 | SecretKey = "secret-key", 27 | } 28 | 29 | const defaultOnWalletKitError = (err: Error) => { 30 | console.error(err); 31 | }; 32 | 33 | export const WalletSelectorModal: React.FC = ({ 34 | app, 35 | onWalletKitError = defaultOnWalletKitError, 36 | initialStep = ModalStep.Intro, 37 | debugMode, 38 | ...modalProps 39 | }: Props) => { 40 | const appIcon = useMemo(() => app.icon ?? , [app.icon]); 41 | 42 | const [step, setStep] = useState(initialStep); 43 | 44 | const [installProvider, setInstallProvider] = 45 | useState(null); 46 | 47 | const { disconnect, activate } = useSolana(); 48 | const [walletToConnect, setWalletToConnect] = useState( 49 | null 50 | ); 51 | 52 | const onDismiss = () => { 53 | modalProps.onDismiss(); 54 | 55 | // unset everything else after the modal unhide animation 56 | setTimeout(() => { 57 | setInstallProvider(null); 58 | setWalletToConnect(null); 59 | setStep(ModalStep.Intro); 60 | }, 500); 61 | }; 62 | 63 | return ( 64 | { 71 | switch (step) { 72 | case ModalStep.Select: 73 | setStep(ModalStep.Intro); 74 | break; 75 | case ModalStep.Redirect: 76 | case ModalStep.Connecting: 77 | case ModalStep.SecretKey: 78 | case ModalStep.LedgerAdvanced: 79 | setStep(ModalStep.Select); 80 | break; 81 | } 82 | } 83 | } 84 | hideSolanaLogo={step === ModalStep.Intro} 85 | > 86 | {step === ModalStep.Intro && ( 87 | setStep(ModalStep.Select)} 91 | /> 92 | )} 93 | {step === ModalStep.Select && ( 94 | { 98 | // Allow the wallet to disconnect before attempting to reconnect. 99 | await disconnect(); 100 | 101 | if ( 102 | info.type === DefaultWalletType.Ledger && 103 | info.info.name === "Ledger (advanced)" 104 | ) { 105 | setStep(ModalStep.LedgerAdvanced); 106 | return; 107 | } 108 | if (info.type === DefaultWalletType.SecretKey) { 109 | setStep(ModalStep.SecretKey); 110 | return; 111 | } 112 | 113 | setWalletToConnect(info); 114 | setStep(ModalStep.Connecting); 115 | 116 | if ( 117 | isMobile && 118 | (info.type === DefaultWalletType.Sollet || 119 | info.type === DefaultWalletType.Solflare) 120 | ) { 121 | await activate(info.type); 122 | } 123 | }} 124 | onInstall={(info) => { 125 | setInstallProvider(info); 126 | setStep(ModalStep.Redirect); 127 | }} 128 | /> 129 | )} 130 | {step === ModalStep.Redirect && installProvider && ( 131 | 132 | )} 133 | {step === ModalStep.Connecting && walletToConnect && ( 134 | { 138 | setStep(ModalStep.Select); 139 | }} 140 | onComplete={onDismiss} 141 | /> 142 | )} 143 | {step === ModalStep.LedgerAdvanced && ( 144 | { 146 | setStep(ModalStep.Select); 147 | }} 148 | onError={onWalletKitError} 149 | onSuccess={onDismiss} 150 | /> 151 | )} 152 | {step === ModalStep.SecretKey && ( 153 | { 155 | setStep(ModalStep.Select); 156 | }} 157 | onError={onWalletKitError} 158 | onSuccess={onDismiss} 159 | /> 160 | )} 161 | 162 | ); 163 | }; 164 | -------------------------------------------------------------------------------- /packages/walletkit/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./components/ConnectWalletButton"; 2 | export * from "./components/Modal"; 3 | export * from "./WalletKitProvider"; 4 | -------------------------------------------------------------------------------- /packages/walletkit/src/types.ts: -------------------------------------------------------------------------------- 1 | import type React from "react"; 2 | 3 | import type { ModalStep } from "./components/WalletSelectorModal"; 4 | 5 | export interface WalletKitArgs { 6 | /** 7 | * Information about the current application. 8 | */ 9 | app: { 10 | /** 11 | * The name of the application. 12 | */ 13 | name: string; 14 | /** 15 | * The icon of the application. 16 | */ 17 | icon?: React.ReactNode; 18 | }; 19 | /** 20 | * The initial step to display in the wallet connector modal. 21 | * 22 | * If you do not want to show the intro screen, use ModalStep.Select. 23 | */ 24 | initialStep?: ModalStep; 25 | /** 26 | * Called when an error occurs. 27 | */ 28 | onWalletKitError?: (err: Error) => void; 29 | /** 30 | * Whether or not to display the debug and secret key wallets in the list. 31 | */ 32 | debugMode?: boolean; 33 | } 34 | -------------------------------------------------------------------------------- /packages/walletkit/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "CommonJS", 5 | "outDir": "dist/cjs/" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/walletkit/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@saberhq/tsconfig/tsconfig.react.json", 3 | "compilerOptions": { 4 | "outDir": "dist/esm/", 5 | "noEmit": false 6 | }, 7 | "include": ["src/"] 8 | } 9 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@saberhq/tsconfig/tsconfig.react.json", 3 | "compilerOptions": { 4 | "module": "CommonJS", 5 | "noEmit": true 6 | }, 7 | "include": ["packages/"] 8 | } 9 | --------------------------------------------------------------------------------