Skip to content

Commit

Permalink
feat: Update transaction controller to v8.0.1 (#8866)
Browse files Browse the repository at this point in the history
## **Description**
 This PR aims to update the transaction controller to version 8.0.1.
 
The Approval Controller was also updated on this PR to the version of
3.5.0 and approval controller patched was updated.

All the changes are present in this core branch for easy review:
patch/mobile-transaction-controller-8-0-1

## **Related issues**

Fixes:

## **Manual testing steps**

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

## **Screenshots/Recordings**

transactions: https://recordit.co/mpcRkPQElC
sign: http://recordit.co/yPI78aEozu

### **Before**

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

### **After**

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

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained what problem this PR is solving and how it
is solved.
- [ ] I've linked related issues
- [ ] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] 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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **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
tommasini committed Mar 7, 2024
1 parent 9cf7630 commit 814e37d
Show file tree
Hide file tree
Showing 8 changed files with 2,920 additions and 4,161 deletions.
4 changes: 4 additions & 0 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,8 @@ class Engine {
blockTracker:
networkController.getProviderAndBlockTracker().blockTracker,
getGasFeeEstimates: () => gasFeeController.fetchGasFeeEstimates(),
// @ts-expect-error network controller will be updated on this PR: https://github.com/MetaMask/metamask-mobile/pull/8812 and this type error will be addressed
// This is not a blocker because gas fee controller does not need ticker to be defined
getNetworkState: () => networkController.state,
getSelectedAddress: () => preferencesController.state.selectedAddress,
incomingTransactions: {
Expand Down Expand Up @@ -1034,6 +1036,8 @@ class Engine {
onNetworkStateChange: (listener) =>
this.controllerMessenger.subscribe(
AppConstants.NETWORK_STATE_CHANGE_EVENT,
// @ts-expect-error network controller will be updated on this PR: https://github.com/MetaMask/metamask-mobile/pull/8812 and this type error will be addressed
// This is not a blocker because gas fee controller does not need ticker to be defined
listener,
),
// @ts-expect-error at this point in time the provider will be defined by the `networkController.initializeProvider`
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
"react-native-level-fs/**/bl": "^1.2.3",
"react-native-level-fs/levelup/semver": "^5.7.2",
"@metamask/contract-metadata": "^2.1.0",
"@metamask/approval-controller": "3.4.0",
"@exodus/react-native-payments/validator": "^13.7.0",
"**/minimist": "1.2.6",
"react-native-svg-asset-plugin/sharp": "^0.30.5",
Expand All @@ -139,7 +138,7 @@
"@keystonehq/ur-decoder": "^0.6.1",
"@ledgerhq/react-native-hw-transport-ble": "^6.29.5",
"@metamask/address-book-controller": "^3.0.0",
"@metamask/approval-controller": "^3.4.0",
"@metamask/approval-controller": "3.5.0",
"@metamask/assets-controllers": "^10.0.0",
"@metamask/base-controller": "^4.1.1",
"@metamask/composable-controller": "^3.0.0",
Expand Down Expand Up @@ -169,7 +168,7 @@
"@metamask/snaps-utils": "^6.0.0",
"@metamask/swappable-obj-proxy": "^2.1.0",
"@metamask/swaps-controller": "^6.9.3",
"@metamask/transaction-controller": "7.1.0",
"@metamask/transaction-controller": "8.0.1",
"@metamask/utils": "^8.1.0",
"@ngraveio/bc-ur": "^1.1.6",
"@react-native-async-storage/async-storage": "1.17.10",
Expand Down
112 changes: 0 additions & 112 deletions patches/@metamask+approval-controller+3.4.0.patch

This file was deleted.

94 changes: 94 additions & 0 deletions patches/@metamask+approval-controller+3.5.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts b/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts
index 32f61cb..4e4d7a1 100644
--- a/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts
+++ b/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts
@@ -99,6 +99,12 @@ export declare type AcceptOptions = {
* If false or unspecified, the promise will resolve immediately.
*/
waitForResult?: boolean;
+ /**
+ * Whether to delete the approval request after a result callback is called.
+ * If false or unspecified, the approval request will be deleted immediately.
+ * Ignored if `waitForResult` is false or unspecified.
+ */
+ deleteAfterResult?: boolean;
};
export declare type StartFlowOptions = OptionalField<ApprovalFlow, 'id' | 'loadingText'>;
export declare type EndFlowOptions = Pick<ApprovalFlow, 'id'>;
diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.js b/node_modules/@metamask/approval-controller/dist/ApprovalController.js
index 3709ab3..43c8bb9 100644
--- a/node_modules/@metamask/approval-controller/dist/ApprovalController.js
+++ b/node_modules/@metamask/approval-controller/dist/ApprovalController.js
@@ -19,7 +19,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
-var _ApprovalController_instances, _ApprovalController_approvals, _ApprovalController_origins, _ApprovalController_showApprovalRequest, _ApprovalController_typesExcludedFromRateLimiting, _ApprovalController_add, _ApprovalController_validateAddParams, _ApprovalController_addPendingApprovalOrigin, _ApprovalController_addToStore, _ApprovalController_delete, _ApprovalController_deleteApprovalAndGetCallbacks, _ApprovalController_result;
+var _ApprovalController_instances, _ApprovalController_approvals, _ApprovalController_origins, _ApprovalController_showApprovalRequest, _ApprovalController_typesExcludedFromRateLimiting, _ApprovalController_add, _ApprovalController_validateAddParams, _ApprovalController_addPendingApprovalOrigin, _ApprovalController_addToStore, _ApprovalController_delete, _ApprovalController_getCallbacks, _ApprovalController_result;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApprovalController = exports.APPROVAL_TYPE_RESULT_SUCCESS = exports.APPROVAL_TYPE_RESULT_ERROR = exports.ORIGIN_METAMASK = void 0;
const base_controller_1 = require("@metamask/base-controller");
@@ -227,7 +227,12 @@ class ApprovalController extends base_controller_1.BaseControllerV2 {
accept(id, value, options) {
// Safe to cast as the delete method below will throw if the ID is not found
const approval = this.get(id);
- const requestPromise = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_deleteApprovalAndGetCallbacks).call(this, id);
+ const requestPromise = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_getCallbacks).call(this, id);
+ let requestDeleted = false;
+ if (!(options === null || options === void 0 ? void 0 : options.deleteAfterResult) || !options.waitForResult) {
+ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_delete).call(this, id);
+ requestDeleted = true;
+ }
return new Promise((resolve, reject) => {
const resultCallbacks = {
success: (acceptValue) => resolve({ value: acceptValue }),
@@ -245,6 +250,10 @@ class ApprovalController extends base_controller_1.BaseControllerV2 {
if (!(options === null || options === void 0 ? void 0 : options.waitForResult)) {
resolve({ value: undefined });
}
+ }).finally(() => {
+ if (!requestDeleted) {
+ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_delete).call(this, id);
+ }
});
}
/**
@@ -255,7 +264,9 @@ class ApprovalController extends base_controller_1.BaseControllerV2 {
* @param error - The error to reject the approval promise with.
*/
reject(id, error) {
- __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_deleteApprovalAndGetCallbacks).call(this, id).reject(error);
+ const callbacks = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_getCallbacks).call(this, id);
+ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_delete).call(this, id);
+ callbacks.reject(error);
}
/**
* Rejects and deletes all approval requests.
@@ -441,10 +452,10 @@ _ApprovalController_approvals = new WeakMap(), _ApprovalController_origins = new
draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length;
});
}, _ApprovalController_delete = function _ApprovalController_delete(id) {
+ if (!__classPrivateFieldGet(this, _ApprovalController_approvals, "f").has(id)) {
+ throw new errors_1.ApprovalRequestNotFoundError(id);
+ }
__classPrivateFieldGet(this, _ApprovalController_approvals, "f").delete(id);
- // This method is only called after verifying that the approval with the
- // specified id exists.
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const { origin, type } = this.state.pendingApprovals[id];
const originMap = __classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin);
const originTotalCount = this.getApprovalCount({ origin });
@@ -459,12 +470,11 @@ _ApprovalController_approvals = new WeakMap(), _ApprovalController_origins = new
delete draftState.pendingApprovals[id];
draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length;
});
-}, _ApprovalController_deleteApprovalAndGetCallbacks = function _ApprovalController_deleteApprovalAndGetCallbacks(id) {
+ }, _ApprovalController_getCallbacks = function _ApprovalController_getCallbacks(id) {
const callbacks = __classPrivateFieldGet(this, _ApprovalController_approvals, "f").get(id);
if (!callbacks) {
throw new errors_1.ApprovalRequestNotFoundError(id);
}
- __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_delete).call(this, id);
return callbacks;
}, _ApprovalController_result = function _ApprovalController_result(type, opts, requestData) {
return __awaiter(this, void 0, void 0, function* () {
Loading

0 comments on commit 814e37d

Please sign in to comment.