@@ -3,18 +3,22 @@ import { ProviderRPCRequest } from '@/types/provider';
33import { WindowPromise } from '@/libs/window-promise' ;
44import AccountState from '../libs/accounts-state' ;
55import { getCustomError } from '@/libs/error' ;
6+ import openOnboard from '@/libs/utils/open-onboard' ;
7+ import { throttle } from 'lodash' ;
8+
69import SolanaProvider from '..' ;
710let isAccountAccessPending = false ;
11+ const throttledOpenOnboard = throttle ( ( ) => openOnboard ( ) , 10000 ) ;
812const pendingPromises : {
913 payload : ProviderRPCRequest ;
1014 res : CallbackFunction ;
1115} [ ] = [ ] ;
12- const method : MiddlewareFunction = function (
16+ const method : MiddlewareFunction = async function (
1317 this : SolanaProvider ,
1418 payload : ProviderRPCRequest ,
1519 res ,
1620 next ,
17- ) : void {
21+ ) : Promise < void > {
1822 if ( payload . method !== 'sol_connect' ) return next ( ) ;
1923 else {
2024 if ( isAccountAccessPending ) {
@@ -25,6 +29,7 @@ const method: MiddlewareFunction = function (
2529 return ;
2630 }
2731 isAccountAccessPending = true ;
32+ const isInitialized = await this . KeyRing . isInitialized ( ) ;
2833 const handleRemainingPromises = ( ) => {
2934 isAccountAccessPending = false ;
3035 if ( pendingPromises . length ) {
@@ -38,6 +43,12 @@ const method: MiddlewareFunction = function (
3843 ) => {
3944 if ( _payload . options && _payload . options . domain ) {
4045 isAccountAccessPending = true ;
46+ if ( ! isInitialized ) {
47+ _res ( getCustomError ( 'Enkrypt not initialized' ) ) ;
48+ throttledOpenOnboard ( ) ;
49+ return handleRemainingPromises ( ) ;
50+ }
51+
4152 const accountsState = new AccountState ( ) ;
4253 accountsState
4354 . getApprovedAddresses ( _payload . options . domain )
0 commit comments