55import * as forge from 'node-forge'
66import axios from 'axios'
77import { API_BASE_URL , BASE_URL } from '../config'
8- import { IAuthResult } from '../interface/provider'
8+ import { IAuthResult , IIframeOptions } from '../interface/provider'
99import { Provider } from '../provider'
1010
1111/**
@@ -25,15 +25,6 @@ export function sha512(str: string) {
2525 return md . digest ( ) . toHex ( )
2626}
2727
28- export interface IIframeOptions {
29- appId : string
30- params : string
31- chainId : string
32- scope ?: number [ ]
33- authType ?: 'account' | 'createContract' | 'callContract' | 'createTransaction'
34- waitResult ?: boolean
35- }
36-
3728const setBodyNonScrollable = ( ) => {
3829 document . body . style . overflow = 'hidden'
3930 const scrollTop =
@@ -61,13 +52,15 @@ const setBodyScrollable = () => {
6152 } )
6253}
6354
55+ const closeIframe = ( root : HTMLDivElement ) => {
56+ setBodyScrollable ( )
57+ root . style . display = 'none'
58+ }
59+
6460export const getIframe = async (
6561 url : string ,
6662 onClose : ( ) => void
67- ) : Promise < {
68- root : HTMLDivElement
69- close : ( ) => void
70- } > => {
63+ ) : Promise < ( ) => void > => {
7164 if (
7265 document . getElementById ( 'anyweb-iframe-mask' ) &&
7366 document . getElementById ( 'anyweb-iframe' )
@@ -76,12 +69,10 @@ export const getIframe = async (
7669 const iframe = document . getElementById ( 'anyweb-iframe' ) as HTMLIFrameElement
7770 iframe . setAttribute ( 'src' , url )
7871 mask . style . display = 'block'
79- return {
80- root : document . getElementById ( 'anyweb-iframe-mask' ) as HTMLDivElement ,
81- close : ( ) => {
82- onClose ( )
83- mask . style . display = 'none'
84- } ,
72+ setBodyNonScrollable ( )
73+ return ( ) => {
74+ onClose ( )
75+ closeIframe ( mask )
8576 }
8677 }
8778 const mask = document . createElement ( 'div' )
@@ -176,13 +167,9 @@ export const getIframe = async (
176167 document . body . appendChild ( style )
177168 setBodyNonScrollable ( )
178169 document . body . insertBefore ( mask , document . body . firstElementChild )
179- return {
180- root : mask ,
181- close : ( ) => {
182- setBodyScrollable ( )
183- onClose ( )
184- mask . style . display = 'none'
185- } ,
170+ return ( ) => {
171+ onClose ( )
172+ closeIframe ( mask )
186173 }
187174}
188175
@@ -214,7 +201,7 @@ export const callIframe = async (
214201 if ( waitResult ) {
215202 return new Promise < unknown > ( async ( resolve , reject ) => {
216203 let timer : NodeJS . Timeout | undefined = undefined
217- const { close } = await getIframe (
204+ const close = await getIframe (
218205 `${ BASE_URL } ${ path } ?appId=${ appId } &authType=${ authType } &serialNumber=${ serialNumber } &hash=${ hash } &random=${ Math . floor (
219206 Math . random ( ) * 1000
220207 ) } &chainId=${ chainId } ¶ms=${ params } &scope=${ JSON . stringify ( scope ) } `,
0 commit comments