Skip to content

Commit 2f91490

Browse files
committed
fix(rolling penetration): fixed rolling penetration when open the iframe second time
1 parent 72ab657 commit 2f91490

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

src/interface/provider.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,12 @@ export interface IProviderMessage {
7171
readonly type: string
7272
readonly data: unknown
7373
}
74+
75+
export interface IIframeOptions {
76+
appId: string
77+
params: string
78+
chainId: string
79+
scope?: number[]
80+
authType?: 'account' | 'createContract' | 'callContract' | 'createTransaction'
81+
waitResult?: boolean
82+
}

src/utils/common.ts

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import * as forge from 'node-forge'
66
import axios from 'axios'
77
import { API_BASE_URL, BASE_URL } from '../config'
8-
import { IAuthResult } from '../interface/provider'
8+
import { IAuthResult, IIframeOptions } from '../interface/provider'
99
import { 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-
3728
const 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+
6460
export 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}&params=${params}&scope=${JSON.stringify(scope)}`,

0 commit comments

Comments
 (0)