@@ -95,19 +95,38 @@ export const sendMessageToApp = ({
9595 if ( ! iframe ) {
9696 return
9797 }
98- iframe . contentWindow &&
99- iframe . contentWindow . postMessage (
98+ sendMessage ( iframe . contentWindow , { data, type, success, code } )
99+ }
100+
101+ export const sendMessage = (
102+ localWindow : any ,
103+ { data, type, success = true , code = 0 , message } : IIframeData
104+ ) => {
105+ console . log (
106+ '[AnyWeb] sendMessage' ,
107+ data ,
108+ type ,
109+ success ,
110+ code ,
111+ message ,
112+ localWindow
113+ )
114+ return (
115+ localWindow &&
116+ localWindow . postMessage (
100117 {
101118 data : {
102119 data,
103120 type,
104121 success,
105122 code,
123+ message,
106124 } ,
107125 type : 'anyweb' ,
108126 } ,
109127 '*'
110128 )
129+ )
111130}
112131
113132export const createIframe = async (
@@ -216,19 +235,21 @@ export const createIframe = async (
216235 // setBodyScrollable()
217236
218237 button . onclick = ( ) => {
219- closeIframe ( mask )
220-
221- throw new ProviderRpcError (
222- ProviderErrorCode . Unauthorized ,
223- 'User canceled the operation'
224- )
238+ window &&
239+ sendMessage ( window , {
240+ data : { } ,
241+ type : 'callback' ,
242+ message : 'User canceled the operation' ,
243+ code : ProviderErrorCode . Unauthorized ,
244+ success : false ,
245+ } )
225246 }
226247}
227248
228249export const getIframe = async (
229250 method : IMethodType ,
230251 appUrl : string ,
231- pararms : Record < any , any > ,
252+ params : Record < any , any > ,
232253 onClose : ( ) => void ,
233254 silence = false ,
234255 logger ?: ConsoleLike
@@ -245,7 +266,7 @@ export const getIframe = async (
245266 sendMessageToApp ( {
246267 type : 'event' ,
247268 data : {
248- params : { ...pararms , version : config . version } ,
269+ params : { ...params , version : config . version } ,
249270 method : method ,
250271 } ,
251272 code : 0 ,
0 commit comments