@@ -152,60 +152,60 @@ class Provider {
152152 */
153153 // eslint-disable-next-line @typescript-eslint/no-explicit-any
154154 rawRequest ( method , params ) {
155- var _a , _b , _c , _d , _e , _f ;
155+ var _a , _b , _c , _d , _e , _f , _g ;
156156 return __awaiter ( this , void 0 , void 0 , function * ( ) {
157157 if ( ! Provider . ready ) {
158158 throw new common_1 . ProviderRpcError ( common_1 . ProviderErrorCode . SDKNotReady , "Provider is not ready, please use on('ready', callback) to listen to ready event" ) ;
159159 }
160- switch ( method ) {
161- case 'cfx_requestAccounts' :
162- return this . rawRequest ( 'cfx_accounts' ) ;
163- case 'cfx_accounts' :
164- ( _a = this . logger ) === null || _a === void 0 ? void 0 : _a . debug ( '[AnyWeb]' , { params } ) ;
165- const scopes = params [ 0 ] . scopes ;
166- let result ;
167- try {
168- result = ( yield ( 0 , common_1 . callIframe ) ( 'pages/dapp/auth' , {
169- appId : this . appId ,
170- params : params ? JSON . stringify ( params [ 0 ] ) : '' ,
171- chainId : this . chainId ,
172- authType : 'check_auth' ,
173- scopes : scopes ,
174- silence : true ,
175- } , this ) ) ;
176- ( _b = this . logger ) === null || _b === void 0 ? void 0 : _b . debug ( '[AnyWeb]' , 'silent auth result' , result ) ;
177- }
178- catch ( e ) {
179- ( _c = this . logger ) === null || _c === void 0 ? void 0 : _c . debug ( '[AnyWeb]' , 'need to auth' , e ) ;
180- result = ( yield ( 0 , common_1 . callIframe ) ( 'pages/dapp/ auth', {
181- appId : this . appId ,
182- params : params ? JSON . stringify ( params [ 0 ] ) : '' ,
183- chainId : this . chainId ,
184- authType : 'account' ,
185- scopes : scopes ,
186- } , this ) ) ;
187- }
188- result . scopes = scopes ;
189- this . events . onAccountsChanged &&
190- this . events . onAccountsChanged ( result . address ) ;
191- this . events . onChainChanged &&
192- this . events . onChainChanged ( String ( result . chainId ) ) ;
193- this . events . onNetworkChanged &&
194- this . events . onNetworkChanged ( String ( result . networkId ) ) ;
195- if ( scopes . length > 0 ) {
196- return {
197- address : result . address ,
198- code : result . code ,
199- scopes : scopes ,
200- chainId : result . chainId ,
201- networkId : result . networkId ,
202- } ;
203- }
204- else {
205- return false ;
206- }
207- case 'cfx_sendTransaction' :
208- try {
160+ try {
161+ switch ( method ) {
162+ case 'cfx_requestAccounts' :
163+ return this . rawRequest ( 'cfx_accounts' ) ;
164+ case 'cfx_accounts' :
165+ ( _a = this . logger ) === null || _a === void 0 ? void 0 : _a . debug ( '[AnyWeb]' , { params } ) ;
166+ const scopes = params [ 0 ] . scopes ;
167+ let result ;
168+ try {
169+ result = ( yield ( 0 , common_1 . callIframe ) ( 'pages/dapp/auth' , {
170+ appId : this . appId ,
171+ params : params ? JSON . stringify ( params [ 0 ] ) : '' ,
172+ chainId : this . chainId ,
173+ authType : 'check_auth' ,
174+ scopes : scopes ,
175+ silence : true ,
176+ } , this ) ) ;
177+ ( _b = this . logger ) === null || _b === void 0 ? void 0 : _b . debug ( '[AnyWeb]' , 'silent auth result' , result ) ;
178+ }
179+ catch ( e ) {
180+ ( _c = this . logger ) === null || _c === void 0 ? void 0 : _c . debug ( '[AnyWeb]' , 'need to auth', e ) ;
181+ result = ( yield ( 0 , common_1 . callIframe ) ( 'pages/dapp/auth' , {
182+ appId : this . appId ,
183+ params : params ? JSON . stringify ( params [ 0 ] ) : '' ,
184+ chainId : this . chainId ,
185+ authType : 'account' ,
186+ scopes : scopes ,
187+ } , this ) ) ;
188+ }
189+ result . scopes = scopes ;
190+ this . events . onAccountsChanged &&
191+ this . events . onAccountsChanged ( result . address ) ;
192+ this . events . onChainChanged &&
193+ this . events . onChainChanged ( String ( result . chainId ) ) ;
194+ this . events . onNetworkChanged &&
195+ this . events . onNetworkChanged ( String ( result . networkId ) ) ;
196+ if ( scopes . length > 0 ) {
197+ return {
198+ address : result . address ,
199+ code : result . code ,
200+ scopes : scopes ,
201+ chainId : result . chainId ,
202+ networkId : result . networkId ,
203+ } ;
204+ }
205+ else {
206+ return false ;
207+ }
208+ case 'cfx_sendTransaction' :
209209 let authType ;
210210 const payload = params [ 0 ] ;
211211 const to = payload . to ;
@@ -218,7 +218,6 @@ class Provider {
218218 else {
219219 authType = 'createContract' ;
220220 }
221- // createContract
222221 return yield ( 0 , common_1 . callIframe ) ( 'pages/dapp/auth' , {
223222 appId : this . appId ,
224223 chainId : this . chainId ,
@@ -230,86 +229,88 @@ class Provider {
230229 : '' ,
231230 authType : authType ,
232231 } , this ) ;
233- }
234- catch ( e ) {
235- throw new common_1 . ProviderRpcError ( common_1 . ProviderErrorCode . SendTransactionError , 'Error to sendTransaction: ' + e ) ;
236- }
237- case 'anyweb_importAccount' :
238- try {
232+ case 'anyweb_importAccount' :
239233 return yield ( 0 , common_1 . callIframe ) ( 'pages/dapp/auth' , {
240234 appId : this . appId ,
241235 chainId : this . chainId ,
242236 params : params ? JSON . stringify ( params [ 0 ] ) : JSON . stringify ( { } ) ,
243237 authType : 'importAccount' ,
244238 } , this ) ;
245- }
246- catch ( e ) {
247- throw new common_1 . ProviderRpcError ( common_1 . ProviderErrorCode . ImportAddressError , 'Error to import Address: ' + e ) ;
248- }
249- case 'anyweb_version' :
250- return package_json_1 . default . version ;
251- case 'anyweb_home' :
252- return yield ( 0 , common_1 . callIframe ) ( 'pages/index/home' , {
253- appId : this . appId ,
254- chainId : this . chainId ,
255- params : params ? JSON . stringify ( params ) : '' ,
256- waitResult : false ,
257- } , this ) ;
258- case 'exit_accounts' :
259- return yield ( 0 , common_1 . callIframe ) ( 'pages/dapp/auth' , {
260- appId : this . appId ,
261- chainId : this . chainId ,
262- params : params ? JSON . stringify ( params ) : '' ,
263- authType : 'exit_accounts' ,
264- silence : true ,
265- } , this ) ;
266- case 'anyweb_identify' :
267- let identifyResult ;
268- try {
269- identifyResult = yield ( 0 , common_1 . callIframe ) ( 'pages/user/identify' , {
239+ case 'anyweb_version' :
240+ return package_json_1 . default . version ;
241+ case 'anyweb_home' :
242+ return yield ( 0 , common_1 . callIframe ) ( 'pages/index/home' , {
270243 appId : this . appId ,
271244 chainId : this . chainId ,
272245 params : params ? JSON . stringify ( params ) : '' ,
273- authType : 'check_identify' ,
274- silence : true ,
246+ waitResult : false ,
275247 } , this ) ;
276- ( _d = this . logger ) === null || _d === void 0 ? void 0 : _d . debug ( '[AnyWeb]' , 'Check identify result' , identifyResult ) ;
277- }
278- catch ( e ) {
279- ( _e = this . logger ) === null || _e === void 0 ? void 0 : _e . debug ( '[AnyWeb]' , 'need to identify' , e ) ;
280- identifyResult = yield ( 0 , common_1 . callIframe ) ( 'pages/user/identify' , {
248+ case 'exit_accounts' :
249+ return this . rawRequest ( 'anyweb_revoke' , params ) ;
250+ case 'anyweb_revoke' :
251+ return yield ( 0 , common_1 . callIframe ) ( 'pages/dapp/auth' , {
281252 appId : this . appId ,
282253 chainId : this . chainId ,
283254 params : params ? JSON . stringify ( params ) : '' ,
284- authType : 'identify' ,
255+ authType : 'exit_accounts' ,
256+ silence : true ,
285257 } , this ) ;
286- }
287- return identifyResult ;
288- case 'anyweb_logout' :
289- // Logout the account of AnyWeb
290- return yield ( 0 , common_1 . callIframe ) ( 'pages/dapp/auth' , {
291- appId : this . appId ,
292- chainId : this . chainId ,
293- params : params ? JSON . stringify ( params ) : '' ,
294- authType : 'logout' ,
295- silence : true ,
296- } , this ) ;
297- case 'anyweb_loginstate' :
298- try {
258+ case 'anyweb_identify' :
259+ let identifyResult ;
260+ try {
261+ identifyResult = yield ( 0 , common_1 . callIframe ) ( 'pages/user/identify' , {
262+ appId : this . appId ,
263+ chainId : this . chainId ,
264+ params : params ? JSON . stringify ( params ) : '' ,
265+ authType : 'check_identify' ,
266+ silence : true ,
267+ } , this ) ;
268+ ( _d = this . logger ) === null || _d === void 0 ? void 0 : _d . debug ( '[AnyWeb]' , 'Check identify result' , identifyResult ) ;
269+ }
270+ catch ( e ) {
271+ ( _e = this . logger ) === null || _e === void 0 ? void 0 : _e . debug ( '[AnyWeb]' , 'need to identify' , e ) ;
272+ identifyResult = yield ( 0 , common_1 . callIframe ) ( 'pages/user/identify' , {
273+ appId : this . appId ,
274+ chainId : this . chainId ,
275+ params : params ? JSON . stringify ( params ) : '' ,
276+ authType : 'identify' ,
277+ } , this ) ;
278+ }
279+ return identifyResult ;
280+ case 'anyweb_logout' :
281+ // Logout the account of AnyWeb
299282 return yield ( 0 , common_1 . callIframe ) ( 'pages/dapp/auth' , {
300283 appId : this . appId ,
301- params : '' ,
302284 chainId : this . chainId ,
303- authType : 'check_login' ,
285+ params : params ? JSON . stringify ( params ) : '' ,
286+ authType : 'logout' ,
304287 silence : true ,
305288 } , this ) ;
306- }
307- catch ( e ) {
308- ( _f = this . logger ) === null || _f === void 0 ? void 0 : _f . debug ( '[AnyWeb]' , 'need to login' , e ) ;
309- return false ;
310- }
311- default :
312- throw new common_1 . ProviderRpcError ( common_1 . ProviderErrorCode . UnsupportedMethod , 'Unsupported Method: ' + method ) ;
289+ case 'anyweb_loginstate' :
290+ try {
291+ return yield ( 0 , common_1 . callIframe ) ( 'pages/dapp/auth' , {
292+ appId : this . appId ,
293+ params : '' ,
294+ chainId : this . chainId ,
295+ authType : 'check_login' ,
296+ silence : true ,
297+ } , this ) ;
298+ }
299+ catch ( e ) {
300+ ( _f = this . logger ) === null || _f === void 0 ? void 0 : _f . debug ( '[AnyWeb]' , 'need to login' , e ) ;
301+ return false ;
302+ }
303+ default :
304+ throw new common_1 . ProviderRpcError ( common_1 . ProviderErrorCode . UnsupportedMethod , 'Unsupported Method: ' + method ) ;
305+ }
306+ }
307+ catch ( e ) {
308+ // const codeList = {
309+ // cfx_sendTransaction: ProviderErrorCode.SendTransactionError,
310+ // anyweb_importAccount: ProviderErrorCode.ImportAddressError,
311+ // }
312+ ( _g = this . logger ) === null || _g === void 0 ? void 0 : _g . info ( `Error when handler request '${ method } '!` ) ;
313+ throw new common_1 . ProviderRpcError ( common_1 . ProviderErrorCode . RequestError , ( 0 , common_1 . isObject ) ( e ) && 'message' in e ? e . message : e , ( 0 , common_1 . isObject ) ( e ) && 'data' in e ? e . data : { } ) ;
313314 }
314315 } ) ;
315316 }
0 commit comments