Skip to content

Commit

Permalink
feat: NFT token transfer (#27955)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Implements token transfer confirmation for ERC721 and ERC1155 tokens, in
the cases where they are wallet initiated and dApp initiated. Includes
e2e tests.

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27955?quickstart=1)

## **Related issues**

Fixes: MetaMask/MetaMask-planning#3018
MetaMask/MetaMask-planning#3019

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

<img width="360" alt="Screenshot 2024-10-18 at 12 46 52"
src="https://github.com/user-attachments/assets/1f9a7116-62b3-4824-bcf0-500c715fc77b">


## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
pedronfigueiredo authored Oct 24, 2024
1 parent da377be commit cbfd131
Show file tree
Hide file tree
Showing 17 changed files with 1,077 additions and 13 deletions.
13 changes: 13 additions & 0 deletions test/e2e/page-objects/pages/homepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class HomePage {
private readonly activityTab =
'[data-testid="account-overview__activity-tab"]';

private readonly nftTab = '[data-testid="account-overview__nfts-tab"]';

private readonly nftIconOnActivityList = '[data-testid="nft-item"]';

private readonly balance = '[data-testid="eth-overview__primary-currency"]';

private readonly basicFunctionalityOffWarningMessage = {
Expand Down Expand Up @@ -72,6 +76,15 @@ class HomePage {
await this.driver.waitForSelector(this.basicFunctionalityOffWarningMessage);
}

async goToNFTList(): Promise<void> {
console.log(`Open NFT tab on homepage`);
await this.driver.clickElement(this.nftTab);
}

async clickNFTIconOnActivityList() {
await this.driver.clickElement(this.nftIconOnActivityList);
}

/**
* This function checks if the specified number of confirmed transactions are displayed in the activity list on homepage.
* It waits up to 10 seconds for the expected number of confirmed transactions to be visible.
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/page-objects/pages/nft-details-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Driver } from '../../webdriver/driver';

class NFTDetailsPage {
private driver: Driver;

private readonly nftSendButton = '[data-testid="nft-send-button"]';

constructor(driver: Driver) {
this.driver = driver;
}

async clickNFTSendButton() {
await this.driver.clickElement(this.nftSendButton);
}
}

export default NFTDetailsPage;
7 changes: 7 additions & 0 deletions test/e2e/page-objects/pages/send/send-token-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class SendTokenPage {

private inputAmount: string;

private inputNFTAmount: string;

private scanButton: string;

private continueButton: object;
Expand All @@ -26,6 +28,7 @@ class SendTokenPage {
constructor(driver: Driver) {
this.driver = driver;
this.inputAmount = '[data-testid="currency-input"]';
this.inputNFTAmount = '[data-testid="nft-input"]';
this.inputRecipient = '[data-testid="ens-input"]';
this.scanButton = '[data-testid="ens-qr-scan-button"]';
this.ensResolvedName =
Expand Down Expand Up @@ -79,6 +82,10 @@ class SendTokenPage {
);
}

async fillNFTAmount(amount: string) {
await this.driver.pasteIntoField(this.inputNFTAmount, amount);
}

async goToNextScreen(): Promise<void> {
await this.driver.clickElement(this.continueButton);
}
Expand Down
36 changes: 36 additions & 0 deletions test/e2e/page-objects/pages/test-dapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ class TestDapp {
tag: 'button',
};

private readonly erc721MintButton = '#mintButton';

private readonly erc721TransferFromButton = '#transferFromButton';

private readonly erc1155TokenIDInput = '#batchMintTokenIds';

private readonly erc1155TokenAmountInput = '#batchMintIdAmounts';

private readonly erc1155MintButton = '#batchMintButton';

private readonly erc1155WatchButton = '#watchAssetButton';

private readonly erc1155RevokeSetApprovalForAllButton =
'#revokeERC1155Button';

Expand Down Expand Up @@ -174,6 +186,30 @@ class TestDapp {
});
}

async clickERC721MintButton() {
await this.driver.clickElement(this.erc721MintButton);
}

async clickERC721TransferFromButton() {
await this.driver.clickElement(this.erc721TransferFromButton);
}

async fillERC1155TokenID(tokenID: string) {
await this.driver.pasteIntoField(this.erc1155TokenIDInput, tokenID);
}

async fillERC1155TokenAmount(amount: string) {
await this.driver.pasteIntoField(this.erc1155TokenAmountInput, amount);
}

async clickERC1155MintButton() {
await this.driver.clickElement(this.erc1155MintButton);
}

async clickERC1155WatchButton() {
await this.driver.clickElement(this.erc1155WatchButton);
}

async clickERC721SetApprovalForAllButton() {
await this.driver.clickElement(this.erc721SetApprovalForAllButton);
}
Expand Down
Loading

0 comments on commit cbfd131

Please sign in to comment.