Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/connections.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { MetaMaskSDK } from '@metamask/sdk';
import globalContext, {
handleNewAccounts,
handleNewProviderDetail,
Expand All @@ -18,8 +17,6 @@
// eslint-disable-next-line require-unicode-regexp
const isAndroid = /Android/i.test(navigator.userAgent);

const sdk = new MetaMaskSDK({ dappMetadata });

export const initializeWeb3Modal = () => {
if (!isAndroid) {
try {
Expand Down Expand Up @@ -63,14 +60,14 @@
updateFormElements();
updateSdkConnectionState(false);
removeProviderDetail(name);
await sdk.terminate();

Check failure on line 63 in src/connections.js

View workflow job for this annotation

GitHub Actions / Build, Lint, and Test (20.x)

'sdk' is not defined

Check failure on line 63 in src/connections.js

View workflow job for this annotation

GitHub Actions / Build, Lint, and Test (18.x)

'sdk' is not defined
button.innerText = 'Sdk Connect';
button.classList.add('btn-primary');
button.classList.remove('btn-danger');
} else {
await sdk.connect();

Check failure on line 68 in src/connections.js

View workflow job for this annotation

GitHub Actions / Build, Lint, and Test (20.x)

'sdk' is not defined

Check failure on line 68 in src/connections.js

View workflow job for this annotation

GitHub Actions / Build, Lint, and Test (18.x)

'sdk' is not defined
const provider = sdk.getProvider();

Check failure on line 69 in src/connections.js

View workflow job for this annotation

GitHub Actions / Build, Lint, and Test (20.x)

'sdk' is not defined

Check failure on line 69 in src/connections.js

View workflow job for this annotation

GitHub Actions / Build, Lint, and Test (18.x)

'sdk' is not defined
const uuid = sdk.getChannelId();

Check failure on line 70 in src/connections.js

View workflow job for this annotation

GitHub Actions / Build, Lint, and Test (20.x)

'sdk' is not defined

Check failure on line 70 in src/connections.js

View workflow job for this annotation

GitHub Actions / Build, Lint, and Test (18.x)

'sdk' is not defined
const providerDetail = _setProviderDetail(provider, name, uuid);
await setActiveProviderDetail(providerDetail);
handleNewProviderDetail(providerDetail);
Expand Down
4 changes: 4 additions & 0 deletions src/iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<body style="margin:0px;padding:0px;overflow:hidden">
iFrame
<iframe src="index.html" frameborder="0" style="overflow:hidden;height:100%;width:100%" height="100%" width="100%"></iframe>
</body>
3 changes: 2 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ <h3 class="card-title">
<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12">
<p class="info-text alert alert-success">
Accounts: <span id="accounts"></span>
IsIabIframe: <span id="hello"></span>
</p>
</div>
</div>
Expand All @@ -119,4 +120,4 @@ <h3 class="card-title">

<script src="main.js" defer></script>
</body>
</html>
</html>
15 changes: 13 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,18 @@
}

const detectEip6963 = () => {
window.addEventListener('eip6963:announceProvider', (event) => {
// Modify here
const currentNetworkName = document.getElementById('hello');
currentNetworkName.textContent = JSON.stringify(!window.ethereum && Boolean(window.parent.ethereum));

Check failure on line 277 in src/index.js

View workflow job for this annotation

GitHub Actions / Build, Lint, and Test (20.x)

Replace `!window.ethereum·&&·Boolean(window.parent.ethereum)` with `⏎····!window.ethereum·&&·Boolean(window.parent.ethereum),⏎··`

Check failure on line 277 in src/index.js

View workflow job for this annotation

GitHub Actions / Build, Lint, and Test (18.x)

Replace `!window.ethereum·&&·Boolean(window.parent.ethereum)` with `⏎····!window.ethereum·&&·Boolean(window.parent.ethereum),⏎··`
setTimeout(async () => {
try {
currentNetworkName.textContent = await window.parent.ethereum.request({method: 'eth_requestAccounts'})

Check failure on line 280 in src/index.js

View workflow job for this annotation

GitHub Actions / Build, Lint, and Test (20.x)

Replace `method:·'eth_requestAccounts'})` with `⏎········method:·'eth_requestAccounts',⏎······});`

Check failure on line 280 in src/index.js

View workflow job for this annotation

GitHub Actions / Build, Lint, and Test (18.x)

Replace `method:·'eth_requestAccounts'})` with `⏎········method:·'eth_requestAccounts',⏎······});`
} catch (error) {
currentNetworkName.textContent = error.message;
}
}, 5000);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Inconsistent Error Handling in Ethereum Access

Directly accessing window.parent.ethereum lacks error handling, which can lead to issues like cross-origin errors in iframes or if window.parent.ethereum is undefined. This is inconsistent with the try-catch block used in the subsequent setTimeout call.

Fix in Cursor Fix in Web


window.parent.addEventListener('eip6963:announceProvider', (event) => {
if (event.detail.info.uuid) {
eip6963Warning.hidden = true;
eip6963Section.hidden = false;
Expand All @@ -281,7 +292,7 @@
}
});

window.dispatchEvent(new Event('eip6963:requestProvider'));
window.parent.dispatchEvent(new Event('eip6963:requestProvider'));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Iframe Detection Alters UI and EIP-6963 Behavior

Debugging code was accidentally committed, adding "IsIabIframe:" text and dynamic iframe detection results to the UI's accounts section. This also modifies the detectEip6963 function to perform iframe testing and eth_requestAccounts calls on window.parent.ethereum, changing its intended EIP-6963 detection behavior.

Additional Locations (1)

Fix in Cursor Fix in Web

};

export const setActiveProviderDetail = async (providerDetail) => {
Expand Down
Loading