Skip to content

Commit

Permalink
Cherry-pick: feat: post-MVP updates for Smart Transactions (#24340) (#…
Browse files Browse the repository at this point in the history
…24408)

## **Description**

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

## **Related issues**

Fixes:

## **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] -->

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.

---------

Co-authored-by: MetaMask Bot <[email protected]>
  • Loading branch information
dan437 and metamaskbot authored May 7, 2024
1 parent 030bc87 commit 28210d2
Show file tree
Hide file tree
Showing 25 changed files with 651 additions and 572 deletions.
2 changes: 1 addition & 1 deletion app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions app/scripts/lib/notification-manager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import EventEmitter from '@metamask/safe-event-emitter';
import ExtensionPlatform from '../platforms/extension';

const NOTIFICATION_HEIGHT = 620;
const NOTIFICATION_WIDTH = 360;
import {
NOTIFICATION_HEIGHT,
NOTIFICATION_WIDTH,
} from '../../../shared/constants/notifications';

export const NOTIFICATION_MANAGER_EVENTS = {
POPUP_CLOSED: 'onPopupClosed',
Expand Down
17 changes: 17 additions & 0 deletions app/scripts/lib/transaction/smart-transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ describe('submitSmartTransactionHook', () => {
expect(result).toEqual({ transactionHash: undefined });
});

it('falls back to regular transaction submit if /getFees throws an error', async () => {
const request: SubmitSmartTransactionRequestMocked = createRequest();
jest
.spyOn(request.smartTransactionsController, 'getFees')
.mockImplementation(() => {
throw new Error('Backend call to /getFees failed');
});
const result = await submitSmartTransactionHook(request);
expect(request.controllerMessenger.call).toHaveBeenCalledWith(
'ApprovalController:endFlow',
{
id: 'approvalId',
},
);
expect(result).toEqual({ transactionHash: undefined });
});

it('returns a txHash asap if the feature flag requires it', async () => {
const request: SubmitSmartTransactionRequestMocked = createRequest();
request.featureFlags.smartTransactions.returnTxHashAsap = true;
Expand Down
12 changes: 11 additions & 1 deletion app/scripts/lib/transaction/smart-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,21 @@ class SmartTransactionHook {
'ApprovalController:startFlow',
);
this.#approvalFlowId = approvalFlowId;
let getFeesResponse;
try {
const getFeesResponse = await this.#smartTransactionsController.getFees(
getFeesResponse = await this.#smartTransactionsController.getFees(
{ ...this.#txParams, chainId: this.#chainId },
undefined,
);
} catch (error) {
log.error(
'Error in smart transaction publish hook, falling back to regular transaction submission',
error,
);
this.#onApproveOrReject();
return useRegularTransactionSubmit; // Fallback to regular transaction submission.
}
try {
const submitTransactionResponse = await this.#signAndSubmitTransactions({
getFeesResponse,
});
Expand Down
11 changes: 8 additions & 3 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ import {
TEST_NETWORK_TICKER_MAP,
NetworkStatus,
} from '../../shared/constants/network';
import { ALLOWED_SMART_TRANSACTIONS_CHAIN_IDS } from '../../shared/constants/smartTransactions';
import { getAllowedSmartTransactionsChainIds } from '../../shared/constants/smartTransactions';

import {
HardwareDeviceNames,
LedgerTransportTypes,
Expand Down Expand Up @@ -1847,7 +1848,7 @@ export default class MetamaskController extends EventEmitter {
),
},
{
supportedChainIds: ALLOWED_SMART_TRANSACTIONS_CHAIN_IDS,
supportedChainIds: getAllowedSmartTransactionsChainIds(),
},
initState.SmartTransactionsController,
);
Expand Down Expand Up @@ -4283,7 +4284,11 @@ export default class MetamaskController extends EventEmitter {
async resetAccount() {
const selectedAddress =
this.accountsController.getSelectedAccount().address;
this.txController.wipeTransactions(true, selectedAddress);
this.txController.wipeTransactions(false, selectedAddress);
this.smartTransactionsController.wipeSmartTransactions({
address: selectedAddress,
ignoreNetwork: false,
});
this.networkController.resetConnection();

return selectedAddress;
Expand Down
15 changes: 14 additions & 1 deletion app/scripts/metamask-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,15 +1033,28 @@ describe('MetaMaskController', () => {
.mockReturnValue({ address: selectedAddressMock });

jest.spyOn(metamaskController.txController, 'wipeTransactions');
jest.spyOn(
metamaskController.smartTransactionsController,
'wipeSmartTransactions',
);

await metamaskController.resetAccount();

expect(
metamaskController.txController.wipeTransactions,
).toHaveBeenCalledTimes(1);
expect(
metamaskController.smartTransactionsController.wipeSmartTransactions,
).toHaveBeenCalledTimes(1);
expect(
metamaskController.txController.wipeTransactions,
).toHaveBeenCalledWith(true, selectedAddressMock);
).toHaveBeenCalledWith(false, selectedAddressMock);
expect(
metamaskController.smartTransactionsController.wipeSmartTransactions,
).toHaveBeenCalledWith({
address: selectedAddressMock,
ignoreNetwork: false,
});
});
});

Expand Down
Loading

0 comments on commit 28210d2

Please sign in to comment.