Skip to content

Commit ae705a2

Browse files
feat(keyring-api): add token:disapprove transaction type + new optional details.typeLabel (#568)
<!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? Are there any issues or other links reviewers should consult to understand this pull request better? For instance: * Fixes #12345 * See: #67890 --> ## Examples <!-- Are there any examples of this change being used in another repository? When considering changes to the MetaMask module template, it's strongly preferred that the change be experimented with in another repository first. This gives reviewers a better sense of how the change works, making it less likely the change will need to be reverted or adjusted later. --> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Additive, backward-compatible schema and enum extensions with validation tests only; no auth or runtime behavior changes. > > **Overview** > Extends the Keyring API **transaction** model so snaps and clients can classify token revocations and show richer activity labels. > > Adds **`TransactionType.TokenDisapprove`** (`token:disapprove`) alongside the existing `token:approve` type, and wires it into **`TransactionStruct`** validation so listed transactions can use the new type. > > Adds an optional **`details.typeLabel`** string on **`TransactionDetailsStruct`** for custom UI copy (e.g. “Revoke USDC approval”) without changing the canonical `type`. Tests cover valid/invalid `typeLabel` and combined `details` fields; the changelog documents both additions. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 98aaf02. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent cb8bea8 commit ae705a2

3 files changed

Lines changed: 55 additions & 3 deletions

File tree

packages/keyring-api/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `TransactionType.TokenDisapprove` for token disapproval transactions ([#568](https://github.com/MetaMask/accounts/pull/568))
13+
- Add optional `TransactionDetails.typeLabel` ([#568](https://github.com/MetaMask/accounts/pull/568))
14+
- This can be used to display a custom label regarding the transaction type.
15+
1016
## [23.2.0]
1117

1218
### Added

packages/keyring-api/src/api/transaction.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ describe('TransactionStruct', () => {
4646
},
4747
expected: true,
4848
},
49+
// With typeLabel
50+
{
51+
transaction: {
52+
...baseTransaction,
53+
details: { typeLabel: 'Revoke USDC approval' },
54+
},
55+
expected: true,
56+
},
57+
// With all details fields
58+
{
59+
transaction: {
60+
...baseTransaction,
61+
details: {
62+
origin: 'metamask',
63+
securityAlertResponse: 'Benign',
64+
typeLabel: 'Some label',
65+
},
66+
},
67+
expected: true,
68+
},
4969
// All valid securityAlertResponse values
5070
{
5171
transaction: {
@@ -76,6 +96,14 @@ describe('TransactionStruct', () => {
7696
},
7797
expected: false,
7898
},
99+
// Invalid typeLabel
100+
{
101+
transaction: {
102+
...baseTransaction,
103+
details: { typeLabel: 123 },
104+
},
105+
expected: false,
106+
},
79107
])(
80108
'returns $expected for is($transaction, TransactionStruct)',
81109
({ transaction, expected }) => {

packages/keyring-api/src/api/transaction.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ export enum TransactionType {
170170
*/
171171
TokenApprove = 'token:approve',
172172

173+
/**
174+
* Represents a token disapproval transaction.
175+
*/
176+
TokenDisapprove = 'token:disapprove',
177+
173178
/**
174179
* The transaction type is unknown. It's not possible to determine the
175180
* transaction type based on the information available.
@@ -215,6 +220,13 @@ export enum SecurityAlertResponse {
215220
* securityAlertResponse: 'Warning',
216221
* }
217222
* ```
223+
*
224+
* @example
225+
* ```ts
226+
* {
227+
* typeLabel: 'Some label',
228+
* }
229+
* ```
218230
*/
219231
export const TransactionDetailsStruct = object({
220232
/**
@@ -236,6 +248,11 @@ export const TransactionDetailsStruct = object({
236248
`${SecurityAlertResponse.Malicious}`,
237249
]),
238250
),
251+
252+
/**
253+
* Optional transaction type label (for UI display purposes).
254+
*/
255+
typeLabel: exactOptional(string()),
239256
});
240257

241258
/**
@@ -361,6 +378,7 @@ export const TransactionStruct = object({
361378
`${TransactionType.StakeDeposit}`,
362379
`${TransactionType.StakeWithdraw}`,
363380
`${TransactionType.TokenApprove}`,
381+
`${TransactionType.TokenDisapprove}`,
364382
`${TransactionType.Unknown}`,
365383
]),
366384

@@ -390,9 +408,9 @@ export const TransactionStruct = object({
390408
/**
391409
* Additional transaction details {@see TransactionDetailsStruct}.
392410
*
393-
* Contains contextual information about the transaction such as its origin and
394-
* security assessment. This field is optional and may not be present for all
395-
* transactions.
411+
* Contains contextual information about the transaction such as its origin,
412+
* security assessment, and optional `typeLabel`. This field is optional and
413+
* may not be present for all transactions.
396414
*/
397415
details: exactOptional(TransactionDetailsStruct),
398416
});

0 commit comments

Comments
 (0)