-
-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,114 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@metamask/test-dapp", | ||
"version": "8.7.0", | ||
"version": "8.8.0", | ||
"description": "A simple dapp used in MetaMask e2e tests.", | ||
"engines": { | ||
"node": ">= 18.0.0" | ||
|
@@ -41,8 +41,12 @@ | |
"@metamask/auto-changelog": "^2.5.0", | ||
"@metamask/eslint-config": "^6.0.0", | ||
"@metamask/eslint-config-nodejs": "^6.0.0", | ||
"@metamask/eth-sig-util": "^7.0.1", | ||
"@metamask/onboarding": "^1.0.0", | ||
"@metamask/sdk": "^0.18.6", | ||
"@openzeppelin/contracts": "4.9.6", | ||
"@walletconnect/modal": "^2.6.2", | ||
"@web3modal/ethers5": "^3.2.0", | ||
"assert": "^2.1.0", | ||
"base64-sol": "1.1.0", | ||
"clean-webpack-plugin": "^4.0.0", | ||
|
@@ -52,10 +56,7 @@ | |
"eslint-plugin-import": "^2.23.4", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"eth-sig-util": "^2.5.3", | ||
"ethereumjs-util": "^5.1.1", | ||
"@web3modal/ethers5": "^3.2.0", | ||
"@walletconnect/modal": "^2.6.2", | ||
"ethers": "5.7.2", | ||
"gh-pages": "^5.0.0", | ||
"prettier": "^2.3.1", | ||
|
@@ -74,7 +75,11 @@ | |
"@web3modal/ethers5>@coinbase/wallet-sdk>@solana/web3.js>bigint-buffer": false, | ||
"@web3modal/ethers5>@coinbase/wallet-sdk>keccak": false, | ||
"webpack-dev-server>ws>bufferutil": false, | ||
"webpack-dev-server>ws>utf-8-validate": false | ||
"webpack-dev-server>ws>utf-8-validate": false, | ||
"@metamask/sdk>@metamask/sdk-communication-layer>bufferutil": false, | ||
"@metamask/sdk>@metamask/sdk-communication-layer>utf-8-validate": false, | ||
"@metamask/sdk>eciesjs>secp256k1": false, | ||
"@web3modal/ethers5>@coinbase/wallet-sdk>@solana/web3.js>rpc-websockets>utf-8-validate": false | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { MetaMaskSDK } from '@metamask/sdk'; | ||
import { createWeb3Modal, defaultConfig } from '@web3modal/ethers5'; | ||
import { | ||
handleNewAccounts, | ||
handleNewProviderDetail, | ||
removeProviderDetail, | ||
setActiveProviderDetail, | ||
updateFormElements, | ||
updateSdkConnectionState, | ||
updateWalletConnectState, | ||
} from '.'; | ||
|
||
const dappMetadata = { | ||
name: 'E2e Test Dapp', | ||
description: 'This is the E2e Test Dapp', | ||
url: 'https://metamask.github.io/test-dapp/', | ||
}; | ||
|
||
const sdk = new MetaMaskSDK({ dappMetadata }); | ||
|
||
export const walletConnect = createWeb3Modal({ | ||
ethersConfig: defaultConfig({ metadata: dappMetadata }), | ||
projectId: 'e6360eaee594162688065f1c70c863b7', // test id | ||
}); | ||
|
||
function _setProviderDetail(provider, name, uuid) { | ||
const providerDetail = { | ||
info: { | ||
uuid, | ||
name, | ||
icon: `./${name}.svg`, | ||
rdns: 'io.metamask', | ||
}, | ||
provider, | ||
}; | ||
return providerDetail; | ||
} | ||
|
||
export async function handleSdkConnect(name, button, isConnected) { | ||
if (isConnected) { | ||
handleNewAccounts([]); | ||
updateFormElements(); | ||
updateSdkConnectionState(false); | ||
removeProviderDetail(name); | ||
sdk.terminate(); | ||
button.innerText = 'Sdk Connect'; | ||
button.classList.add('btn-primary'); | ||
button.classList.remove('btn-danger'); | ||
} else { | ||
await sdk.connect(); | ||
const provider = sdk.getProvider(); | ||
const uuid = sdk.getChannelId(); | ||
const providerDetail = _setProviderDetail(provider, name, uuid); | ||
setActiveProviderDetail(providerDetail); | ||
handleNewProviderDetail(providerDetail); | ||
updateSdkConnectionState(true); | ||
button.innerText = 'Sdk Connect - Disconnect'; | ||
button.classList.remove('btn-primary'); | ||
button.classList.add('btn-danger'); | ||
|
||
updateFormElements(); | ||
|
||
try { | ||
const newAccounts = await provider.request({ | ||
method: 'eth_accounts', | ||
}); | ||
handleNewAccounts(newAccounts); | ||
} catch (err) { | ||
console.error('Error on init when getting accounts', err); | ||
} | ||
} | ||
} | ||
|
||
export async function handleWalletConnect(name, button, isConnected) { | ||
if (isConnected) { | ||
handleNewAccounts([]); | ||
updateFormElements(); | ||
updateWalletConnectState(false); | ||
removeProviderDetail(name); | ||
button.innerText = 'Wallet Connect'; | ||
button.classList.add('btn-primary'); | ||
button.classList.remove('btn-danger'); | ||
} else { | ||
const { provider } = walletConnect.getWalletProvider(); | ||
const uuid = provider.signer.uri; | ||
const providerDetail = _setProviderDetail(provider, name, uuid); | ||
setActiveProviderDetail(providerDetail); | ||
handleNewProviderDetail(providerDetail); | ||
updateWalletConnectState(true); | ||
button.innerText = 'Wallet Connect - Disconnect'; | ||
button.classList.remove('btn-primary'); | ||
button.classList.add('btn-danger'); | ||
|
||
updateFormElements(); | ||
|
||
try { | ||
const newAccounts = await provider.request({ | ||
method: 'eth_accounts', | ||
}); | ||
handleNewAccounts(newAccounts); | ||
} catch (err) { | ||
console.error('Error on init when getting accounts', err); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.