UNPKG

starknetkit

Version:

<!-- logo --> <p align="center"> <img width='300' src="https://starknetkit-website-git-blo-1541-argentlabs.vercel.app/starknetKit-logo.svg"> </p>

14 lines (13 loc) 4.73 kB
"use strict";var A=Object.defineProperty;var E=(e,o,t)=>o in e?A(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t;var a=(e,o,t)=>(E(e,typeof o!="symbol"?o+"":o,t),t);require("./core-aa9478e0.cjs");const l=require("starknet"),n=require("./lastConnected-966555c5.cjs"),k=require("./getStarknetChainId-db957824.cjs"),v=require("./index-725d5c1d.cjs"),q={mainnet:"https://starknet-mainnet.public.blastapi.io",testnet:"https://starknet-sepolia.public.blastapi.io"},M={mainnet:"https://rpc.starknet.lava.build",testnet:"https://rpc.starknet-sepolia.lava.build"},u=[q,M];function P(){const e=Math.floor(Math.random()*u.length);return u[e]}const R=()=>Object.keys(localStorage).some(e=>e==="walletconnect"||e.startsWith("wc@2:")),i=()=>{if(R()){delete localStorage.walletconnect;for(const e in localStorage)e.startsWith("wc@2:")&&delete localStorage[e]}},d="f2e613881f7a0e811295cdd57999e31b",C=`<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg" > <rect width="32" height="32" rx="8" fill="#FF875B" /> <path d="M18.316 8H13.684C13.5292 8 13.4052 8.1272 13.4018 8.28531C13.3082 12.7296 11.0323 16.9477 7.11513 19.9355C6.99077 20.0303 6.96243 20.2085 7.05335 20.3369L9.76349 24.1654C9.85569 24.2957 10.0353 24.3251 10.1618 24.2294C12.6111 22.3734 14.5812 20.1345 16 17.6529C17.4187 20.1345 19.389 22.3734 21.8383 24.2294C21.9646 24.3251 22.1443 24.2957 22.2366 24.1654L24.9467 20.3369C25.0375 20.2085 25.0092 20.0303 24.885 19.9355C20.9676 16.9477 18.6918 12.7296 18.5983 8.28531C18.5949 8.1272 18.4708 8 18.316 8Z" fill="white" /> </svg>`,_=()=>typeof window>"u"||!window?.starknet_argentX?!1:window?.starknet_argentX?.isInAppBrowser;class p extends n.Connector{constructor(t){super();a(this,"_wallet",null);a(this,"_options");this._options=t}available(){return!0}async ready(){if(!this._wallet)return!1;try{return(await this._wallet.request({type:"wallet_getPermissions"})).includes(n.Permission.ACCOUNTS)}catch{return!1}}get id(){return"argentMobile"}get name(){return"Argent (mobile)"}get icon(){return{dark:C,light:C}}get wallet(){if(!this._wallet)throw new n.ConnectorNotConnectedError;return this._wallet}async connect(t={}){if(await this.ensureWallet(),!this._wallet)throw new n.ConnectorNotFoundError;const r=await this._wallet.request({type:"wallet_requestAccounts"}),s=await this.chainId();return{account:r[0],chainId:s}}async disconnect(){if(await this._wallet.disable(),i(),!this.available()&&!this._wallet)throw new n.ConnectorNotFoundError;this._wallet=null}async account(t){if(!this._wallet)throw new n.ConnectorNotConnectedError;const r=await this._wallet.request({type:"wallet_requestAccounts",params:{silent_mode:!0}});return new l.WalletAccount(t,this._wallet,void 0,r[0])}async chainId(){if(!this._wallet)throw new n.ConnectorNotConnectedError;const t=await this._wallet.request({type:"wallet_requestChainId"}),r=k.getStarknetChainId(t);return BigInt(r)}async request(t){if(!this._wallet)throw new n.ConnectorNotConnectedError;try{return await this._wallet.request(t)}catch{throw new n.UserRejectedRequestError}}async initEventListener(t){if(!this._wallet)throw new n.ConnectorNotConnectedError;this._wallet.on("accountsChanged",t)}async removeEventListener(t){if(!this._wallet)throw new n.ConnectorNotConnectedError;this._wallet.off("accountsChanged",t),this._wallet=null}async ensureWallet(){const{getStarknetWindowObject:t}=await Promise.resolve().then(()=>require("./index-01146b04.cjs")),{chainId:r,projectId:s,dappName:g,description:f,url:m,icons:I,rpcUrl:N}=this._options,c=P(),b=N??(!r||r===l.constants.NetworkName.SN_MAIN?c.mainnet:c.testnet),y={chainId:r??l.constants.NetworkName.SN_MAIN,name:g,projectId:s??d,description:f,url:m,icons:I,rpcUrl:b};s===d&&(console.log("========= NOTICE ========="),console.log("While your application will continue to function, we highly recommended"),console.log("signing up for your own API keys."),console.log("Go to WalletConnect Cloud (https://cloud.walletconnect.com) and create a new account."),console.log("Once your account is created, create a new project and collect the Project ID"),console.log("=========================="));const w=await t(y);if(!w)throw new n.UserRejectedRequestError;this._wallet=w;const h=this._wallet;await h.enable(),h.client.on("session_delete",()=>{i(),this._wallet=null,n.removeStarknetLastConnectedWallet(),document.dispatchEvent(new Event("wallet_disconnected"))})}}class S{static init({options:o,inAppBrowserOptions:t}){return _()?new v.InjectedConnector({options:{id:"argentX",...t}}):new p(o)}}exports.ArgentMobileBaseConnector=p;exports.ArgentMobileConnector=S;exports.isInArgentMobileAppBrowser=_;exports.resetWalletConnect=i;