11import { sha256 } from '@cosmjs/crypto' ;
22import { toUtf8 } from '@cosmjs/encoding' ;
3- import eccrypto , { Ecies } from '@toruslabs/eccrypto' ;
4- import { AuthAdapter , AuthLoginParams } from '@web3auth/auth-adapter ' ;
3+ import * as eccrypto from '@toruslabs/eccrypto' ;
4+ import { Ecies } from '@toruslabs/eccrypto ' ;
55import {
6- ADAPTER_STATUS ,
7- CHAIN_NAMESPACES ,
8- CustomChainConfig ,
6+ CONNECTOR_STATUS ,
97 SafeEventEmitterProvider ,
108 UX_MODE ,
11- WALLET_ADAPTERS ,
12- } from '@web3auth/base' ;
13- import { CommonPrivateKeyProvider } from '@web3auth/base-provider' ;
14- import { Web3AuthNoModal } from '@web3auth/no-modal' ;
9+ WALLET_CONNECTORS ,
10+ Web3Auth ,
11+ } from '@web3auth/modal' ;
1512
1613import {
1714 FromWorkerMessage ,
@@ -116,28 +113,11 @@ export const connectClientAndProvider = async (
116113 options : Web3AuthClientOptions ,
117114 { dontAttemptLogin = false } = { }
118115) : Promise < {
119- client : Web3AuthNoModal ;
116+ client : Web3Auth ;
120117 provider : SafeEventEmitterProvider | null ;
121118} > => {
122- const chainConfig : CustomChainConfig = {
123- chainId : 'other' ,
124- rpcTarget : 'other' ,
125- displayName : 'other' ,
126- blockExplorerUrl : 'other' ,
127- ticker : 'other' ,
128- tickerName : 'other' ,
129- ...options . client . chainConfig ,
130- chainNamespace : CHAIN_NAMESPACES . OTHER ,
131- } ;
132- const privateKeyProvider = new CommonPrivateKeyProvider ( {
133- config : {
134- chainConfig,
135- } ,
136- } ) ;
137- const client = new Web3AuthNoModal ( {
119+ const client = new Web3Auth ( {
138120 ...options . client ,
139- chainConfig,
140- privateKeyProvider,
141121 } ) ;
142122
143123 // Popups are blocked by default on mobile browsers, so use redirect. Popup is
@@ -157,27 +137,29 @@ export const connectClientAndProvider = async (
157137 ) ;
158138 }
159139
160- const mfaLevel = options . mfaLevel ?? 'default' ;
161- const authAdapter = new AuthAdapter ( {
162- adapterSettings : {
163- uxMode,
164- } ,
165- loginSettings : {
166- mfaLevel,
167- } ,
168- } ) ;
169- client . configureAdapter ( authAdapter ) ;
170-
171140 await client . init ( ) ;
172141
142+ // Wait up to 10 seconds for the client to be ready or connected.
143+ // This is necessary on v10 because init() does not wait for the session to
144+ // be restored.
145+ const timeout = 10000 ;
146+ const startTime = Date . now ( ) ;
147+ while (
148+ client . status !== CONNECTOR_STATUS . READY &&
149+ client . status !== CONNECTOR_STATUS . CONNECTED &&
150+ Date . now ( ) - startTime < timeout
151+ ) {
152+ await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
153+ }
154+
173155 let provider = client . connected ? client . provider : null ;
174156 if ( ! client . connected && ! dontAttemptLogin ) {
175157 try {
176158 const loginHint = options . getLoginHint ?.( ) ;
177- provider = await client . connectTo ( WALLET_ADAPTERS . AUTH , {
178- loginProvider : options . loginProvider ,
179- login_hint : loginHint ,
180- } as AuthLoginParams ) ;
159+ provider = await client . connectTo ( WALLET_CONNECTORS . AUTH , {
160+ authConnection : options . loginProvider ,
161+ loginHint : loginHint ,
162+ } ) ;
181163 } catch ( err ) {
182164 // Unnecessary error thrown during redirect, so log and ignore it.
183165 if (
@@ -194,7 +176,7 @@ export const connectClientAndProvider = async (
194176 }
195177
196178 if ( usingRedirect ) {
197- if ( client . status === ADAPTER_STATUS . CONNECTED ) {
179+ if ( client . status === CONNECTOR_STATUS . CONNECTED ) {
198180 // On successful connection from a redirect, remove the localStorage key
199181 // so we do not attempt to auto connect on the next page load.
200182 localStorage . removeItem ( WEB3AUTH_REDIRECT_AUTO_CONNECT_KEY ) ;
0 commit comments