@@ -3,18 +3,22 @@ import { ProviderRPCRequest } from '@/types/provider';
3
3
import { WindowPromise } from '@/libs/window-promise' ;
4
4
import AccountState from '../libs/accounts-state' ;
5
5
import { getCustomError } from '@/libs/error' ;
6
+ import openOnboard from '@/libs/utils/open-onboard' ;
7
+ import { throttle } from 'lodash' ;
8
+
6
9
import SolanaProvider from '..' ;
7
10
let isAccountAccessPending = false ;
11
+ const throttledOpenOnboard = throttle ( ( ) => openOnboard ( ) , 10000 ) ;
8
12
const pendingPromises : {
9
13
payload : ProviderRPCRequest ;
10
14
res : CallbackFunction ;
11
15
} [ ] = [ ] ;
12
- const method : MiddlewareFunction = function (
16
+ const method : MiddlewareFunction = async function (
13
17
this : SolanaProvider ,
14
18
payload : ProviderRPCRequest ,
15
19
res ,
16
20
next ,
17
- ) : void {
21
+ ) : Promise < void > {
18
22
if ( payload . method !== 'sol_connect' ) return next ( ) ;
19
23
else {
20
24
if ( isAccountAccessPending ) {
@@ -25,6 +29,7 @@ const method: MiddlewareFunction = function (
25
29
return ;
26
30
}
27
31
isAccountAccessPending = true ;
32
+ const isInitialized = await this . KeyRing . isInitialized ( ) ;
28
33
const handleRemainingPromises = ( ) => {
29
34
isAccountAccessPending = false ;
30
35
if ( pendingPromises . length ) {
@@ -38,6 +43,12 @@ const method: MiddlewareFunction = function (
38
43
) => {
39
44
if ( _payload . options && _payload . options . domain ) {
40
45
isAccountAccessPending = true ;
46
+ if ( ! isInitialized ) {
47
+ _res ( getCustomError ( 'Enkrypt not initialized' ) ) ;
48
+ throttledOpenOnboard ( ) ;
49
+ return handleRemainingPromises ( ) ;
50
+ }
51
+
41
52
const accountsState = new AccountState ( ) ;
42
53
accountsState
43
54
. getApprovedAddresses ( _payload . options . domain )
0 commit comments