Skip to content

Commit 9eebebf

Browse files
committed
feat(silent mode): support silent mode
1 parent d16527d commit 9eebebf

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/interface/provider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export interface IIframeOptions {
8989
| 'exit_accounts'
9090
| 'logout'
9191
waitResult?: boolean
92+
silence?: boolean
9293
}
9394

9495
export interface IIframeData {

src/provider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ export class Provider implements IProvider {
231231
chainId: this.chainId,
232232
params: params ? JSON.stringify(params) : '',
233233
authType: 'exit_accounts',
234+
silence: true,
234235
},
235236
this
236237
)
@@ -253,6 +254,7 @@ export class Provider implements IProvider {
253254
chainId: this.chainId,
254255
params: params ? JSON.stringify(params) : '',
255256
authType: 'logout',
257+
silence: true,
256258
},
257259
this
258260
)

src/utils/common.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@ export const isObject = (obj: unknown) => {
7777

7878
const closeIframe = (root: HTMLDivElement) => {
7979
console.debug('[AnyWeb]', 'closeIframe', root.style)
80-
setTimeout(() => {
81-
setBodyScrollable()
82-
root.style.display = 'none'
83-
}, 100)
80+
setBodyScrollable()
81+
root.style.display = 'none'
8482
}
8583
export const sendMessageToApp = ({
8684
data,
@@ -207,7 +205,8 @@ export const createIframe = async (url: string) => {
207205

208206
export const getIframe = async (
209207
url: string,
210-
onClose: () => void
208+
onClose: () => void,
209+
silence = false
211210
): Promise<() => void> => {
212211
if (
213212
!(
@@ -226,13 +225,15 @@ export const getIframe = async (
226225
},
227226
})
228227
const mask = document.getElementById('anyweb-iframe-mask') as HTMLDivElement
229-
setTimeout(() => {
228+
if (!silence) {
230229
mask.style.display = 'block'
231230
setBodyNonScrollable()
232-
}, 100)
231+
}
233232
return () => {
234233
onClose()
235-
closeIframe(mask)
234+
if (!silence) {
235+
closeIframe(mask)
236+
}
236237
}
237238
}
238239

@@ -245,6 +246,7 @@ export const callIframe = async (
245246
scopes = [],
246247
authType,
247248
waitResult = true,
249+
silence = false,
248250
}: IIframeOptions,
249251
provider: Provider
250252
) => {
@@ -261,7 +263,8 @@ export const callIframe = async (
261263
if (timer) {
262264
clearTimeout(timer)
263265
}
264-
}
266+
},
267+
silence
265268
)
266269
const timer = setTimeout(() => {
267270
close()
@@ -320,7 +323,8 @@ export const callIframe = async (
320323
)}&chainId=${chainId}&params=${params}&scopes=${JSON.stringify(scopes)}`,
321324
() => {
322325
return
323-
}
326+
},
327+
silence
324328
)
325329
return 'ok'
326330
}

0 commit comments

Comments
 (0)