Skip to content

Commit e5a6484

Browse files
committed
fix(close button error): fix the error of close button
1 parent b6badfa commit e5a6484

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

example/basic-dapp/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
<header>
4848
Connect
4949
</header>
50+
<label>手机号
51+
<input type="text" id=
52+
"phone_input" placeholder="预填手机号">
53+
</label>
5054
<button id="connect">Connect
5155
Wallet
5256
</button>

example/basic-dapp/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ async function walletInitialized() {
656656
const gatewayTestButton = getElement('gateway_test')
657657
const importAddressButton = getElement('import_address_button')
658658
const importAddressInput = getElement('import_address_input')
659+
const phoneInput = getElement('phone_input')
659660
const importAddressNameInput = getElement('import_address_name_input')
660661
const identifyButton = getElement('identify_button')
661662
const checkLoginButton = getElement('checklogin_button')
@@ -759,6 +760,7 @@ async function walletInitialized() {
759760
{
760761
availableNetwork: [1, 1029],
761762
scopes: ['baseInfo', 'identity'],
763+
phone: phoneInput.value,
762764
},
763765
],
764766
})

src/utils/common.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

113132
export 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

228249
export 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

Comments
 (0)