Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
beilunyang authored Jun 11, 2024
2 parents eda447c + 4591f29 commit 0377e70
Show file tree
Hide file tree
Showing 9 changed files with 1,114 additions and 396 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [8.8.0]
### Added
- Add json RPC result text area ([#334](https://github.com/MetaMask/test-dapp/pull/334))
- Add token contract addresses and consolidate names ([#332](https://github.com/MetaMask/test-dapp/pull/332))
- Add SDK support ([#331](https://github.com/MetaMask/test-dapp/pull/331))
- Add Blockaid bypass for send value without 0x prefix ([#329](https://github.com/MetaMask/test-dapp/pull/329))
- Add malicious deeplinks, bypasses and reorg ([#328](https://github.com/MetaMask/test-dapp/pull/328))

### Changed
- Change `eth-sig-util` to `@metamask/eth-sig-util` ([#286](https://github.com/MetaMask/test-dapp/pull/286))

## [8.7.0]
### Added
- Add support for Send EIP1559 tx's without suggested gas values ([#320](https://github.com/MetaMask/test-dapp/pull/320))
Expand Down Expand Up @@ -178,7 +189,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix repository standardization issues ([#118](https://github.com/MetaMask/test-dapp/pull/118))
- Fix addEthereumChain button disable logic ([#93](https://github.com/MetaMask/test-dapp/pull/93))

[Unreleased]: https://github.com/MetaMask/test-dapp/compare/v8.7.0...HEAD
[Unreleased]: https://github.com/MetaMask/test-dapp/compare/v8.8.0...HEAD
[8.8.0]: https://github.com/MetaMask/test-dapp/compare/v8.7.0...v8.8.0
[8.7.0]: https://github.com/MetaMask/test-dapp/compare/v8.6.0...v8.7.0
[8.6.0]: https://github.com/MetaMask/test-dapp/compare/v8.5.0...v8.6.0
[8.5.0]: https://github.com/MetaMask/test-dapp/compare/v8.4.0...v8.5.0
Expand Down
15 changes: 10 additions & 5 deletions package.json
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"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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]"
Expand Down
105 changes: 105 additions & 0 deletions src/connections.js
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);
}
}
}
6 changes: 6 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ section {
margin: 20px 0 20px 0;
}

textarea {
height: auto;
width: 100%;
max-width: 100%;
}

.info-text {
font-size: 1.1em;
}
Expand Down
60 changes: 44 additions & 16 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ <h3 class="card-title">
<div class="card">
<div class="card-body">
<h4 class="card-title">
Basic Actions
Connect Actions
</h4>

<button
Expand All @@ -135,10 +135,17 @@ <h4 class="card-title">

<button
class="btn btn-primary btn-lg btn-block mb-3"
id="open-connect-modal"
id="walletConnect"
>
Wallet Connect
</button>
<button
class="btn btn-primary btn-lg btn-block mb-3"
id="sdkConnect"
>
SDK Connect
</button>
<hr />
<button
class="btn btn-primary btn-lg btn-block mb-3"
id="getAccounts"
Expand All @@ -152,11 +159,6 @@ <h4 class="card-title">
</div>
</div>
</div>
</div>
</section>

<section>
<div class="row d-flex justify-content-center">
<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12">
<div class="card">
<div class="card-body">
Expand Down Expand Up @@ -329,11 +331,11 @@ <h4 class="card-title">
<div class="card full-width">
<div class="card-body">
<h4 class="card-title">
Send Tokens
ERC 20
</h4>

<p class="info-text alert alert-success">
Token(s): <span id="tokenAddresses"></span>
Token(s): <span id="erc20TokenAddresses"></span>
</p>

<div class="form-group">
Expand Down Expand Up @@ -372,7 +374,7 @@ <h4 class="card-title">
Transfer Tokens
</button>

<a
<a
id="transferTokensDeeplink"
>
<button
Expand Down Expand Up @@ -484,7 +486,7 @@ <h4 class="card-title">
</button>

<p class="info-text alert alert-secondary">
Token methods result: <span id="tokenMethodsResult"></span>
ERC 20 methods result: <span id="tokenMethodsResult"></span>
</p>
</div>
</div>
Expand All @@ -495,9 +497,13 @@ <h4 class="card-title">
<div class="card full-width">
<div class="card-body">
<h4 class="card-title">
NFTs
ERC 721
</h4>

<p class="info-text alert alert-success">
Token(s): <span id="erc721TokenAddresses"></span>
</p>

<button
class="btn btn-primary btn-lg btn-block mb-3"
id="deployNFTsButton"
Expand Down Expand Up @@ -620,7 +626,7 @@ <h4 class="card-title">
</div>

<p class="info-text alert alert-secondary">
NFTs: <span id="nftsStatus"></span>
ERC 721 methods result: <span id="nftsStatus"></span>
</p>
</div>
</div>
Expand All @@ -634,6 +640,10 @@ <h4 class="card-title">
ERC 1155
</h4>

<p class="info-text alert alert-success">
Token(s): <span id="erc1155TokenAddresses"></span>
</p>

<button
class="btn btn-primary btn-lg btn-block mb-3"
id="deployERC1155Button"
Expand Down Expand Up @@ -743,7 +753,7 @@ <h4 class="card-title">
</div>

<p class="info-text alert alert-secondary">
ERC 1155: <span id="erc1155Status"></span>
ERC 1155 methods results: <span id="erc1155Status"></span>
</p>
</div>
</div>
Expand Down Expand Up @@ -1457,8 +1467,18 @@ <h4>
</section>
<section>
<div class="row d-flex justify-content-center">
<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12">
<div class="card">
<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12 d-flex align-items-stretch">
<div class="card full-width">
<div class="card-body">
<h4 class="card-title">
JSON RPC Result
</h4>
<textarea name="json-rpc-response" id="json-rpc-response" rows="5"></textarea>
</div>
</div>
</div>
<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12 d-flex align-items-stretch">
<div class="card full-width">
<div class="card-body">
<h4 class="card-title">
Ethereum Chain Interactions
Expand All @@ -1480,6 +1500,14 @@ <h4 class="card-title">
</div>
</div>
</div>
<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12 d-flex align-items-stretch">
<div class="card full-width">
<div class="card-body">
<h4 class="card-title">
</h4>
</div>
</div>
</div>
</div>
</section>
<section>
Expand Down
Loading

0 comments on commit 0377e70

Please sign in to comment.