diff --git a/package-lock.json b/package-lock.json index 4c2f8eeaa..28aa0626e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5059,40 +5059,40 @@ "dev": true }, "node_modules/@ledgerhq/cryptoassets": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@ledgerhq/cryptoassets/-/cryptoassets-7.0.0.tgz", - "integrity": "sha512-mjx5rcmYtZdgHGQlSy8KVKGUNWwmdFeFWDkyBluvXX9/lruuAXrUMai2eAz4EaZ2S48bPpxWpLKloEA1KEo4Yw==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/@ledgerhq/cryptoassets/-/cryptoassets-7.1.0.tgz", + "integrity": "sha512-1M8KPvSS1TG2zZfSVYQOzNkB2E2e+wiN+jBlsV0z2WGyjUzVLjRnfQ6vuIQmYtHnS4kudFJy941bpLTIjpjhhA==", "dependencies": { "invariant": "2" } }, "node_modules/@ledgerhq/devices": { - "version": "7.0.5", - "resolved": "https://registry.npmjs.org/@ledgerhq/devices/-/devices-7.0.5.tgz", - "integrity": "sha512-2o2zD2Yv1Hgd3+R2aLCvlyT7NxBz2nltawTCPSXaf3+8MDIyZbiJlXi43hLEISRFBG3u3bYwAQuiOisimN9C6Q==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/@ledgerhq/devices/-/devices-7.0.6.tgz", + "integrity": "sha512-trEqJqgXuXLgb228c6kJdur0idTVxtofy8NxumvsspZKh5x/pHJX8EoNxWX91Pg7H3AA+jxLEeRvAjNDVDJgGQ==", "dependencies": { - "@ledgerhq/errors": "^6.12.1", + "@ledgerhq/errors": "^6.12.2", "@ledgerhq/logs": "^6.10.1", "rxjs": "6", "semver": "^7.3.5" } }, "node_modules/@ledgerhq/errors": { - "version": "6.12.1", - "resolved": "https://registry.npmjs.org/@ledgerhq/errors/-/errors-6.12.1.tgz", - "integrity": "sha512-2qeUSUCpQbMhV9eLJDLI8wycFwTcWszP8g3cJycBt9Jf1VczC5MRERwAQv5AYhPa4rcy+jLKBOVZYxc35r5l7g==" + "version": "6.12.2", + "resolved": "https://registry.npmjs.org/@ledgerhq/errors/-/errors-6.12.2.tgz", + "integrity": "sha512-qYTkxlWHVItxPAb9pQewfVoN8nFvvFYzWEyzVRX/NuO/g3JKL5kef5lLuqTtUIFOvFROMLi3EBxU+vbvV0ktow==" }, "node_modules/@ledgerhq/hw-app-eth": { - "version": "6.30.2", - "resolved": "https://registry.npmjs.org/@ledgerhq/hw-app-eth/-/hw-app-eth-6.30.2.tgz", - "integrity": "sha512-2Bs6aaeSiMvSGhGCepz4YwitlBMwSZPw+4SX62hrU3rTfMTALlI6yUnrn6M7Ld70Rbw9g1pLzY1heR5al6SVLQ==", + "version": "6.30.3", + "resolved": "https://registry.npmjs.org/@ledgerhq/hw-app-eth/-/hw-app-eth-6.30.3.tgz", + "integrity": "sha512-zMQYAy7+4W7Iqq+oOi38muRSV82uFxHRHKO8oWaeLp5Hyu4imiSp1UIwCUhHz2yMunmuewiV8QJSsPHWgMnJTA==", "dependencies": { "@ethersproject/abi": "^5.5.0", "@ethersproject/rlp": "^5.5.0", - "@ledgerhq/cryptoassets": "^7.0.0", - "@ledgerhq/errors": "^6.12.1", - "@ledgerhq/hw-transport": "^6.27.8", - "@ledgerhq/hw-transport-mocker": "^6.27.8", + "@ledgerhq/cryptoassets": "^7.1.0", + "@ledgerhq/errors": "^6.12.2", + "@ledgerhq/hw-transport": "^6.27.9", + "@ledgerhq/hw-transport-mocker": "^6.27.9", "@ledgerhq/logs": "^6.10.1", "axios": "^0.26.1", "bignumber.js": "^9.1.0", @@ -5100,21 +5100,21 @@ } }, "node_modules/@ledgerhq/hw-transport": { - "version": "6.27.8", - "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport/-/hw-transport-6.27.8.tgz", - "integrity": "sha512-WSUgF1W3tAikSnAfeNAT2e2dgTdEQd5Vi/095C2mR5Fr0/POCSl9X4T9rlBhK5NSVD+nGXI0rN2ISj08zai8HQ==", + "version": "6.27.9", + "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport/-/hw-transport-6.27.9.tgz", + "integrity": "sha512-Po0eFWyH3C6I5oxLW3t/jtjqFJdF6/zmF9WL3n5lvSVbtmilPGz2IFOwHoz/XWSwM4PLwV6JXgFBIC6h6UNn/Q==", "dependencies": { - "@ledgerhq/devices": "^7.0.5", - "@ledgerhq/errors": "^6.12.1", + "@ledgerhq/devices": "^7.0.6", + "@ledgerhq/errors": "^6.12.2", "events": "^3.3.0" } }, "node_modules/@ledgerhq/hw-transport-mocker": { - "version": "6.27.8", - "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport-mocker/-/hw-transport-mocker-6.27.8.tgz", - "integrity": "sha512-I9/TMQK0+3rgvm5+AZVFFB84wyEREqVpVVmkwhuYZj084g0Z+WRINOlr1ep3d21E67li4tzxFtkG1dzfVPD45w==", + "version": "6.27.9", + "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport-mocker/-/hw-transport-mocker-6.27.9.tgz", + "integrity": "sha512-Y4XniipcZ0VktZCycyWKvIDsQ3Fo2IxnXMdfjw12vLrkGD15jEvohUFeL97AvbbC3nSBl52+nOcxjypYmSGKww==", "dependencies": { - "@ledgerhq/hw-transport": "^6.27.8", + "@ledgerhq/hw-transport": "^6.27.9", "@ledgerhq/logs": "^6.10.1" } }, @@ -5162,13 +5162,13 @@ "integrity": "sha512-swKHYCOZUGyVt4ge0u8a7AwNcA//h4nx5wIi0sruGye1IJ5Cva0GyK9L2/WdX+kWVTKp92ZiEo1df31lrWGPgA==" }, "node_modules/@ledgerhq/hw-transport-webusb": { - "version": "6.27.8", - "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport-webusb/-/hw-transport-webusb-6.27.8.tgz", - "integrity": "sha512-WU0Vz0jbACDUd31knHp38b4EQk02Zs4G5UVaw2Q3j45ZQsABvSBNzEEjXELdZDNMirvSBxE/YTAg8MLO1SFIvA==", + "version": "6.27.9", + "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport-webusb/-/hw-transport-webusb-6.27.9.tgz", + "integrity": "sha512-/nII54hWkAVQldercMlS8WgQ4jLOpxdSH5+KC5tUtGLxgyYcD9tCUfhmAUidfkknz67/2s/UJj4cHNkaEykAOg==", "dependencies": { - "@ledgerhq/devices": "^7.0.5", - "@ledgerhq/errors": "^6.12.1", - "@ledgerhq/hw-transport": "^6.27.8", + "@ledgerhq/devices": "^7.0.6", + "@ledgerhq/errors": "^6.12.2", + "@ledgerhq/hw-transport": "^6.27.9", "@ledgerhq/logs": "^6.10.1" } }, @@ -8521,9 +8521,9 @@ } }, "node_modules/@toruslabs/torus-embed": { - "version": "1.38.3", - "resolved": "https://registry.npmjs.org/@toruslabs/torus-embed/-/torus-embed-1.38.3.tgz", - "integrity": "sha512-NG/Mr7nVDLkz4Cyhr/puOAmTGrnDqA8Un2qWcTMDVp2hwP0yeeMsHbtDWri+m9Y7xSGf4dFliKc70n3JUZ44qA==", + "version": "1.38.4", + "resolved": "https://registry.npmjs.org/@toruslabs/torus-embed/-/torus-embed-1.38.4.tgz", + "integrity": "sha512-26QNAsmioVr3xhwIqB6ECCUTE3qMpDBQUuwM0JOOb4o5qzLpzP8ZyvFjElsj4Mc1NceVlX1O95br6HVdoEfaog==", "dependencies": { "@metamask/obs-store": "^7.0.0", "@toruslabs/http-helpers": "^3.2.0", @@ -29063,9 +29063,9 @@ } }, "node_modules/rtl-css-js": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/rtl-css-js/-/rtl-css-js-1.16.0.tgz", - "integrity": "sha512-Oc7PnzwIEU4M0K1J4h/7qUUaljXhQ0kCObRsZjxs2HjkpKsnoTMvSmvJ4sqgJZd0zBoEfAyTdnK/jMIYvrjySQ==", + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/rtl-css-js/-/rtl-css-js-1.16.1.tgz", + "integrity": "sha512-lRQgou1mu19e+Ya0LsTvKrVJ5TYUbqCVPAiImX3UfLTenarvPUl1QFdvu5Z3PYmHT9RCcwIfbjRQBntExyj3Zg==", "dependencies": { "@babel/runtime": "^7.1.2" } diff --git a/packages/connectors/src/base/web3auth-base.ts b/packages/connectors/src/base/web3auth-base.ts index 01a31caf2..f215aef58 100644 --- a/packages/connectors/src/base/web3auth-base.ts +++ b/packages/connectors/src/base/web3auth-base.ts @@ -1,13 +1,6 @@ import { CustodyType } from '@flair-sdk/common'; import type { Chain } from '@wagmi/core'; -import { - normalizeChainId, - ProviderRpcError, - SwitchChainError, - UserRejectedRequestError, -} from '@wagmi/core'; -import * as web3authBase from '@web3auth/base'; -import { hexlify } from 'ethers/lib/utils.js'; +import { SwitchChainError } from '@wagmi/core'; import { ExtendedConnector } from './extended-connector'; import { Web3AuthConnector } from './web3auth-core'; @@ -22,93 +15,48 @@ export abstract class Web3AuthBaseConnector async connect() { return new Promise(async (resolve, reject) => { - try { - await this.disconnect(); - } catch (e) {} + await this.initIfNotYet(); try { - if ( - this.web3AuthInstance?.status !== web3authBase.ADAPTER_STATUS.READY - ) { - await this.web3AuthInstance?.init(); - } - } catch (e) {} - - return this.web3AuthInstance - ?.connectTo('openlogin', { - loginProvider: this.loginProvider, - }) - .then(async (provider) => { + if (this.socialLoginAdapter.status === 'connected') { const account = await this.getAccount(); const id = await this.getChainId(); - resolve({ + const response = { account, - provider, + provider: await this.getProvider(), chain: { id, unsupported: await this.isChainUnsupported(id) }, + }; + + return resolve(response); + } + + return this.web3AuthInstance + ?.connectTo('openlogin', { + loginProvider: this.loginProvider, + }) + .then(async (provider) => { + const account = await this.getAccount(); + const id = await this.getChainId(); + + resolve({ + account, + provider, + chain: { id, unsupported: await this.isChainUnsupported(id) }, + }); + }) + .catch((error) => { + reject(error); }); - }) - .catch((error) => { - reject(error); - }); + } catch (e) { + reject(e); + } }); } async switchChain(chainId: number): Promise { - const id = normalizeChainId(chainId); - - try { - try { - await this.disconnect(); - } catch (e) {} - - const tmp = new Web3AuthConnector({ - chains: this.chains, - options: { - ...this.options, - chainId: hexlify(id).toString(), - }, - }); - - this.web3AuthInstance = tmp.web3AuthInstance; - - // @ts-ignore - this.socialLoginAdapter = tmp.socialLoginAdapter; - - // @ts-ignore - this.loginModal = tmp.loginModal; - - // @ts-ignore - this.subscribeToLoginModalEvents(); - - await this.connect(); - - this.onChainChanged(id); - const provider = await this.getProvider(); - - if (provider?.on) { - provider.on('accountsChanged', this.onAccountsChanged.bind(this)); - //provider.on('chainChanged', this.onChainChanged.bind(this)); - provider.on('disconnect', this.onDisconnect.bind(this)); - } - - return ( - this.chains.find((x) => x.id === chainId) ?? { - id: chainId, - name: `Chain ${id}`, - network: `${id}`, - rpcUrls: { default: { http: [''] } }, - nativeCurrency: { name: 'Token', symbol: 'Token', decimals: 18 }, - } - ); - } catch (error) { - const message = - typeof error === 'string' - ? error - : (error as ProviderRpcError)?.message; - if (/user rejected request/i.test(message)) - throw new UserRejectedRequestError(error); - throw new SwitchChainError(error); - } + throw new SwitchChainError( + `Cannot switch chain for Web3Auth ${this.name}, must provide preferredChainId via props to or `, + ); } } diff --git a/packages/connectors/src/base/web3auth-core.ts b/packages/connectors/src/base/web3auth-core.ts index 6929bde17..578670bdb 100644 --- a/packages/connectors/src/base/web3auth-core.ts +++ b/packages/connectors/src/base/web3auth-core.ts @@ -1,15 +1,7 @@ -import { - Chain, - Connector, - ConnectorData, - normalizeChainId, - UserRejectedRequestError, -} from '@wagmi/core'; +import { Chain, Connector, normalizeChainId } from '@wagmi/core'; import * as web3authBase from '@web3auth/base'; import * as web3authCore from '@web3auth/core'; import * as web3authOpenLogin from '@web3auth/openlogin-adapter'; -import LoginModal from '@web3auth/ui'; -import * as web3authUi from '@web3auth/ui'; import { ethers, Signer } from 'ethers'; import { getAddress } from 'ethers/lib/utils.js'; import log from 'loglevel'; @@ -18,7 +10,11 @@ import { Web3AuthOptions } from './web3auth-interfaces'; const IS_SERVER = typeof window === 'undefined'; -export class Web3AuthConnector extends Connector { +let globalInstanceWeb3Auth: web3authCore.Web3AuthCore | null = null; +let globalInstanceSocialLoginAdapter: web3authOpenLogin.OpenloginAdapter | null = + null; + +export abstract class Web3AuthConnector extends Connector { ready = !IS_SERVER; readonly id = 'web3Auth'; @@ -27,15 +23,13 @@ export class Web3AuthConnector extends Connector { provider!: web3authBase.SafeEventEmitterProvider | null; - web3AuthInstance?: web3authCore.Web3AuthCore; + web3AuthInstance!: web3authCore.Web3AuthCore; isModalOpen = false; web3AuthOptions: Web3AuthOptions; - private loginModal: LoginModal; - - private socialLoginAdapter: web3authOpenLogin.OpenloginAdapter; + socialLoginAdapter: web3authOpenLogin.OpenloginAdapter; constructor(config: { chains?: Chain[]; options: Web3AuthOptions }) { super(config); @@ -73,134 +67,65 @@ export class Web3AuthConnector extends Connector { blockExplorer: currentChain?.blockExplorers?.default?.url as string, }; } - this.web3AuthInstance = new web3authCore.Web3AuthCore({ - clientId: config.options.clientId, - enableLogging: config.options.enableLogging, - storageKey: config.options.storageKey, - chainConfig: { - // @ts-ignore - chainNamespace: web3authBase.CHAIN_NAMESPACES.EIP155, - ...finalChainConfig, - }, - }); - - this.socialLoginAdapter = new web3authOpenLogin.OpenloginAdapter({ - adapterSettings: { - ...config.options, - }, - loginSettings: { - ...(config.options?.socialLoginConfig || {}), - }, - chainConfig: finalChainConfig, - }); - - this.web3AuthInstance.configureAdapter(this.socialLoginAdapter); - - this.loginModal = new LoginModal({ - theme: this.options.uiConfig?.theme, - appLogo: this.options.uiConfig?.appLogo || '', - version: '', - adapterListener: this.web3AuthInstance, - displayErrorsOnModal: this.options.displayErrorsOnModal, - }); - - this.subscribeToLoginModalEvents(); - } - - async connect(): Promise> { - try { - this.emit('message', { - type: 'connecting', + if (!globalInstanceWeb3Auth) { + globalInstanceWeb3Auth = new web3authCore.Web3AuthCore({ + clientId: config.options.clientId, + enableLogging: config.options.enableLogging, + storageKey: config.options.storageKey, + chainConfig: finalChainConfig, }); + } + + this.web3AuthInstance = globalInstanceWeb3Auth; - await this.loginModal.initModal(); - - this.loginModal.addSocialLogins( - web3authBase.WALLET_ADAPTERS.OPENLOGIN, - web3authUi.getAdapterSocialLogins( - web3authBase.WALLET_ADAPTERS.OPENLOGIN, - this.socialLoginAdapter, - this.options.uiConfig?.loginMethodConfig, - ), - this.options.uiConfig?.loginMethodsOrder || - web3authUi.OPENLOGIN_PROVIDERS, + if (!globalInstanceSocialLoginAdapter) { + globalInstanceSocialLoginAdapter = new web3authOpenLogin.OpenloginAdapter( + { + adapterSettings: { + ...config.options, + }, + loginSettings: { + ...(config.options?.socialLoginConfig || {}), + }, + chainConfig: finalChainConfig, + }, ); - if (this.web3AuthInstance?.status !== web3authBase.ADAPTER_STATUS.READY) { - await this.web3AuthInstance?.init(); - } + this.web3AuthInstance.configureAdapter(globalInstanceSocialLoginAdapter); + } - // Check if there is a user logged in - const isLoggedIn = await this.isAuthorized(); + this.socialLoginAdapter = globalInstanceSocialLoginAdapter; - // if there is a user logged in, return the user - if (isLoggedIn) { - const provider = await this.getProvider(); - const chainId = await this.getChainId(); - if (provider?.on) { - provider.on('accountsChanged', this.onAccountsChanged.bind(this)); - provider.on('chainChanged', this.onChainChanged.bind(this)); - } - const unsupported = this.isChainUnsupported(chainId); + this.initIfNotYet(); + } - return { - provider, - chain: { - id: chainId, - unsupported, - }, - account: await this.getAccount(), - }; + async initIfNotYet(): Promise { + try { + if ( + !this.socialLoginAdapter?.status || + [ + web3authBase.ADAPTER_STATUS.DISCONNECTED, + web3authBase.ADAPTER_STATUS.ERRORED, + web3authBase.ADAPTER_STATUS.NOT_READY, + ].includes(this.socialLoginAdapter.status as any) + ) { + await this.web3AuthInstance?.init(); } + } catch (e) {} - this.loginModal.open(); - const elem = document.getElementById('w3a-container'); - if (elem?.style) elem.style.zIndex = '10000000000'; - - return await new Promise((resolve, reject) => { - this.loginModal.once( - web3authUi.LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, - (isVisible: boolean) => { - if (!isVisible && !this.web3AuthInstance?.provider) { - return reject(new Error('User closed popup')); - } - }, - ); - this.web3AuthInstance?.once( - web3authBase.ADAPTER_EVENTS.CONNECTED, - async () => { - const signer = await this.getSigner(); - const account = (await signer.getAddress()) as `0x${string}`; - const provider = await this.getProvider(); - - if (provider?.on) { - provider.on('accountsChanged', this.onAccountsChanged.bind(this)); - provider.on('chainChanged', this.onChainChanged.bind(this)); - } - const chainId = await this.getChainId(); - const unsupported = this.isChainUnsupported(chainId); - - return resolve({ - account, - chain: { - id: chainId, - unsupported, - }, - provider, - }); - }, - ); - this.web3AuthInstance?.once( - web3authBase.ADAPTER_EVENTS.ERRORED, - (err: unknown) => { - log.error('error while connecting', err); - return reject(err); - }, - ); - }); - } catch (error) { - log.error('error while connecting', error); - throw new UserRejectedRequestError('Something went wrong'); - } + try { + if ( + !this.socialLoginAdapter?.status || + [ + web3authBase.ADAPTER_STATUS.DISCONNECTED, + web3authBase.ADAPTER_STATUS.ERRORED, + web3authBase.ADAPTER_STATUS.NOT_READY, + ].includes(this.socialLoginAdapter.status as any) + ) { + await this.socialLoginAdapter.init({ + autoConnect: this.web3AuthInstance.cachedAdapter === 'openlogin', + }); + } + } catch (e) {} } async getAccount(): Promise<`0x${string}`> { @@ -217,8 +142,11 @@ export class Web3AuthConnector extends Connector { return this.provider; } - if (this.web3AuthInstance?.provider) + await this.initIfNotYet(); + + if (this.web3AuthInstance?.provider) { this.provider = this.web3AuthInstance?.provider; + } return this.provider; } @@ -324,34 +252,4 @@ export class Web3AuthConnector extends Connector { protected onDisconnect(): void { this.emit('disconnect'); } - - private subscribeToLoginModalEvents(): void { - this.loginModal.on( - web3authUi.LOGIN_MODAL_EVENTS.LOGIN, - async (params: { - adapter: web3authBase.WALLET_ADAPTER_TYPE; - loginParams: unknown; - }) => { - try { - await this.web3AuthInstance?.connectTo( - params.adapter, - params.loginParams, - ); - } catch (error) { - log.error( - `Error while connecting to adapter: ${params.adapter}`, - error, - ); - } - }, - ); - - this.loginModal.on(web3authUi.LOGIN_MODAL_EVENTS.DISCONNECT, async () => { - try { - await this.disconnect(); - } catch (error) { - log.error(`Error while disconnecting`, error); - } - }); - } } diff --git a/packages/connectors/src/index.ts b/packages/connectors/src/index.ts index c4088246a..468b60076 100644 --- a/packages/connectors/src/index.ts +++ b/packages/connectors/src/index.ts @@ -11,4 +11,3 @@ export * from './github'; export * from './discord'; export * from './twitch'; export * from './twitter'; -export * from './web3auth-modal'; diff --git a/packages/connectors/src/web3auth-modal.ts b/packages/connectors/src/web3auth-modal.ts deleted file mode 100644 index 34a165b03..000000000 --- a/packages/connectors/src/web3auth-modal.ts +++ /dev/null @@ -1,140 +0,0 @@ -import { CustodyType } from '@flair-sdk/common'; -import { - Chain, - normalizeChainId, - ProviderRpcError, - SwitchChainError, - UserRejectedRequestError, -} from '@wagmi/core'; -import * as web3authBase from '@web3auth/base'; -import LoginModal from '@web3auth/ui'; -import * as web3authUi from '@web3auth/ui'; -import { hexlify } from 'ethers/lib/utils.js'; - -import { ExtendedConnector } from './base/extended-connector'; -import { Web3AuthConnector } from './base/web3auth-core'; - -export class Web3AuthModalConnector - extends Web3AuthConnector - implements ExtendedConnector -{ - // @ts-ignore - name = 'Social Logins'; - icon = 'https://web3auth.io/images/w3a-L-Favicon-1.svg'; - available: boolean = true; - custodyType: CustodyType = CustodyType.MPC; - - async connect() { - return new Promise(async (resolve, reject) => { - setTimeout(() => { - // @ts-ignore - (this.loginModal as LoginModal).on( - web3authUi.LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, - (visibility) => { - if (!visibility) { - this.isAuthorized().then((authorized) => { - if (!authorized) { - reject(new Error('User closed modal')); - } - }); - } - }, - ); - }, 100); - - try { - await this.disconnect(); - } catch (e) {} - - try { - if ( - this.web3AuthInstance?.status !== web3authBase.ADAPTER_STATUS.READY - ) { - await this.web3AuthInstance?.init(); - } - } catch (e) {} - - return super - .connect() - .then(async (result) => { - const account = await this.getAccount(); - const id = await this.getChainId(); - - resolve({ - account, - provider: result.provider, - chain: { id, unsupported: await this.isChainUnsupported(id) }, - }); - }) - .catch((error) => { - reject(error); - }); - }); - } - - async switchChain(chainId: number): Promise { - const id = normalizeChainId(chainId); - - try { - try { - await this.disconnect(); - } catch (e) {} - - const tmp = new Web3AuthModalConnector({ - chains: this.chains, - options: { - ...this.options, - chainId: hexlify(id).toString(), - }, - }); - - this.web3AuthInstance = tmp.web3AuthInstance; - - // @ts-ignore - this.socialLoginAdapter = tmp.socialLoginAdapter; - - // @ts-ignore - this.loginModal = tmp.loginModal; - - // @ts-ignore - this.subscribeToLoginModalEvents(); - - try { - if ( - this.web3AuthInstance?.status !== web3authBase.ADAPTER_STATUS.READY - ) { - await this.web3AuthInstance?.init(); - } - } catch (e) {} - - await this.connect(); - - this.onChainChanged(id); - const provider = await this.getProvider(); - - if (provider?.on) { - provider.on('accountsChanged', this.onAccountsChanged.bind(this)); - //provider.on('chainChanged', this.onChainChanged.bind(this)); - provider.on('disconnect', this.onDisconnect.bind(this)); - } - - return ( - this.chains.find((x) => x.id === chainId) ?? { - id: chainId, - name: `Chain ${id}`, - network: `${id}`, - rpcUrls: { default: { http: [''] } }, - nativeCurrency: { name: 'Token', symbol: 'Token', decimals: 18 }, - } - ); - } catch (error) { - const message = - typeof error === 'string' - ? error - : (error as ProviderRpcError)?.message; - if (/user rejected request/i.test(message)) - throw new UserRejectedRequestError(error); - throw new SwitchChainError(error); - } - } -} diff --git a/packages/react/src/core/balance-ramp/resolvers/native-value.resolver.ts b/packages/react/src/core/balance-ramp/resolvers/native-value.resolver.ts index 14b9af8cb..e1f12b8c6 100644 --- a/packages/react/src/core/balance-ramp/resolvers/native-value.resolver.ts +++ b/packages/react/src/core/balance-ramp/resolvers/native-value.resolver.ts @@ -1,5 +1,4 @@ import { BigNumber } from 'ethers'; -import { keccak256 } from 'ethers/lib/utils.js'; import { BalanceResolver } from '../types'; import { calculateUniqueTransactionIdentifier } from '../utils'; diff --git a/packages/react/src/core/balance-ramp/services/balance-ramp.client.ts b/packages/react/src/core/balance-ramp/services/balance-ramp.client.ts index 5f813d12c..9fa29af9d 100644 --- a/packages/react/src/core/balance-ramp/services/balance-ramp.client.ts +++ b/packages/react/src/core/balance-ramp/services/balance-ramp.client.ts @@ -2,7 +2,6 @@ import { TransactionRequest, TransactionResponse, } from '@ethersproject/providers'; -import { Environment } from '@flair-sdk/common'; import axios from 'axios'; import { BigNumber, BigNumberish, constants, ethers, Signer } from 'ethers'; import { Deferrable } from 'ethers/lib/utils.js'; diff --git a/packages/react/src/core/wallet/components/ConnectButton.tsx b/packages/react/src/core/wallet/components/ConnectButton.tsx index def86707e..53114f999 100644 --- a/packages/react/src/core/wallet/components/ConnectButton.tsx +++ b/packages/react/src/core/wallet/components/ConnectButton.tsx @@ -89,6 +89,10 @@ export const ConnectButton = ({ setDialogOpen(false)} diff --git a/packages/react/src/core/wallet/components/WalletDropdown.tsx b/packages/react/src/core/wallet/components/WalletDropdown.tsx index 9bebb137e..8c1ecd2e2 100644 --- a/packages/react/src/core/wallet/components/WalletDropdown.tsx +++ b/packages/react/src/core/wallet/components/WalletDropdown.tsx @@ -1,12 +1,12 @@ import { classNames } from '@flair-sdk/common'; import { Menu, Transition } from '@headlessui/react'; import { ChevronDownIcon } from '@heroicons/react/solid/esm/index.js'; -import React, { Fragment } from 'react'; +import { Fragment } from 'react'; import { useCopyToClipboard } from 'react-use'; import { useAccount, useBalance, useNetwork } from 'wagmi'; import { BareComponentProps } from '../../../common'; -import { CryptoUnits, CryptoValue } from '../../crypto-currency'; +import { CryptoValue } from '../../crypto-currency'; import { DisconnectButton } from './DisconnectButton'; import { WalletComponentWrapper } from './WalletComponentWrapper'; import { WalletProfile, WalletProfileProps } from './WalletProfile'; diff --git a/packages/react/src/core/wallet/providers/wallet.tsx b/packages/react/src/core/wallet/providers/wallet.tsx index 99625dc00..1d106ca10 100644 --- a/packages/react/src/core/wallet/providers/wallet.tsx +++ b/packages/react/src/core/wallet/providers/wallet.tsx @@ -39,8 +39,11 @@ import { WalletConnectConnector } from 'wagmi/connectors/walletConnect'; import { useStickyState } from '../../../common/hooks/useStickyState.js'; import { isDarkMode } from '../../../common/utils/dark-mode'; import stylesheet from '../../../index.css'; -import { wrapWagmiClient } from '../../balance-ramp'; -import { FLAIR_ALCHEMY_API_KEY, FLAIR_INFURA_PROJECT_ID } from '../constants'; +import { wrapWagmiClient } from '../../balance-ramp/index.js'; +import { + FLAIR_ALCHEMY_API_KEY, + FLAIR_INFURA_PROJECT_ID, +} from '../constants/index.js'; export type Web3AuthOptions = Required< Partial, diff --git a/packages/react/src/modules/finance/tiered-sales/components/TieredSalesMintStatusBar.tsx b/packages/react/src/modules/finance/tiered-sales/components/TieredSalesMintStatusBar.tsx index d1c210867..151bfa966 100644 --- a/packages/react/src/modules/finance/tiered-sales/components/TieredSalesMintStatusBar.tsx +++ b/packages/react/src/modules/finance/tiered-sales/components/TieredSalesMintStatusBar.tsx @@ -3,7 +3,6 @@ import { useAccount } from 'wagmi'; import { IfChain } from '../../../../core'; import { Errors, Spinner, TransactionLink } from '../../../../core/ui'; import { useTieredSalesContext } from '../providers'; -import { TieredSalesIfWalletCanMint } from './TieredSalesIfWalletCanMint'; type Props = { className?: string; diff --git a/packages/react/src/modules/finance/tiered-sales/components/TieredSalesSelector.tsx b/packages/react/src/modules/finance/tiered-sales/components/TieredSalesSelector.tsx index 39f183a86..55f7f87bf 100644 --- a/packages/react/src/modules/finance/tiered-sales/components/TieredSalesSelector.tsx +++ b/packages/react/src/modules/finance/tiered-sales/components/TieredSalesSelector.tsx @@ -10,7 +10,6 @@ import { CryptoSymbol, CryptoValue, IfWalletConnected, - useDiamondContext, useRemoteJsonReader, } from '../../../../core'; import { NftTokenMetadata, useContractSymbol } from '../../../token';