Skip to content

Commit a44b12f

Browse files
authored
feat: added 'updatedAt' field to claimDraft (#7523)
## Explanation <!-- 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 changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs) - [x] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds an `updatedAt` timestamp to claim drafts and updates it on create/update, with tests and changelog updated. > > - **Claims Controller**: > - **Types**: Include `updatedAt` in `ClaimDraft` (`packages/claims-controller/src/types.ts`). > - **Logic**: `saveOrUpdateClaimDraft` now sets `updatedAt` on create and refreshes it on updates; return value includes `updatedAt` (`packages/claims-controller/src/ClaimsController.ts`). > - **Tests**: Update draft tests to expect `updatedAt` (`packages/claims-controller/src/ClaimsController.test.ts`). > - **Docs**: > - Update changelog to note `updatedAt` addition (`packages/claims-controller/CHANGELOG.md`). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 23cae10. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 4dd1d2b commit a44b12f

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

packages/claims-controller/CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added `updatedAt` field to the claims draft. ([#7523](https://github.com/MetaMask/core/pull/7523))
13+
1014
## [0.3.0]
1115

1216
### Added

packages/claims-controller/src/ClaimsController.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ describe('ClaimsController', () => {
265265
impactedTxHash: '0x123',
266266
reimbursementWalletAddress: '0x456',
267267
description: 'test description',
268+
updatedAt: '2025-12-17T06:10:32.213Z',
268269
};
269270
const MOCK_CLAIM_DRAFTS: ClaimDraft[] = [
270271
{
@@ -275,6 +276,7 @@ describe('ClaimsController', () => {
275276
impactedTxHash: '0x123',
276277
reimbursementWalletAddress: '0x456',
277278
description: 'test description',
279+
updatedAt: '2025-12-17T06:10:32.213Z',
278280
},
279281
{
280282
draftId: 'mock-draft-2',
@@ -284,6 +286,7 @@ describe('ClaimsController', () => {
284286
impactedTxHash: '0x789',
285287
reimbursementWalletAddress: '0x012',
286288
description: 'test description 2',
289+
updatedAt: '2025-12-17T06:10:32.213Z',
287290
},
288291
];
289292

@@ -295,7 +298,10 @@ describe('ClaimsController', () => {
295298
expect(updatedState).not.toBe(initialState);
296299
expect(updatedState.drafts).toHaveLength(1);
297300
expect(updatedState.drafts[0].draftId).toBeDefined();
298-
expect(updatedState.drafts[0]).toMatchObject(MOCK_DRAFT);
301+
expect(updatedState.drafts[0]).toMatchObject({
302+
...MOCK_DRAFT,
303+
updatedAt: expect.any(String),
304+
});
299305
expect(updatedState.drafts[0].draftId).toBeDefined();
300306
});
301307
});

packages/claims-controller/src/ClaimsController.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,19 @@ export class ClaimsController extends BaseController<
232232
);
233233

234234
if (isExistingDraft) {
235+
const updatedAt = new Date().toISOString();
235236
this.update((state) => {
236237
state.drafts = state.drafts.map((existingDraft) =>
237238
existingDraft.draftId === draft.draftId
238-
? { ...existingDraft, ...draft }
239+
? {
240+
...existingDraft,
241+
...draft,
242+
updatedAt,
243+
}
239244
: existingDraft,
240245
);
241246
});
242-
return draft as ClaimDraft;
247+
return { ...draft, updatedAt } as ClaimDraft;
243248
}
244249

245250
// generate a new draft id, name and add it to the state
@@ -248,6 +253,7 @@ export class ClaimsController extends BaseController<
248253
const newDraft: ClaimDraft = {
249254
...draft,
250255
draftId,
256+
updatedAt: new Date().toISOString(),
251257
};
252258

253259
this.update((state) => {

packages/claims-controller/src/types.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@ export type Claim = {
5151
export type ClaimDraft = Partial<
5252
Omit<
5353
Claim,
54-
| 'id'
55-
| 'shortId'
56-
| 'createdAt'
57-
| 'updatedAt'
58-
| 'intercomId'
59-
| 'status'
60-
| 'attachments'
54+
'id' | 'shortId' | 'createdAt' | 'intercomId' | 'status' | 'attachments'
6155
>
6256
> & {
6357
/**

0 commit comments

Comments
 (0)