Skip to content

Commit

Permalink
fix: fix error when clicking on asset (#10477)
Browse files Browse the repository at this point in the history
## **Description**

fixes:  TypeError: `Cannot assign to read-only property.`

This error occurs when user trying to navigate to Asset page (See before
Video).

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to Tokens page
2. Click on any token
3. You should not see an error and you should be successfully redirected
to asset page
## **Screenshots/Recordings**

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

### **Before**

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


https://github.com/user-attachments/assets/2e38fad9-b106-47a7-8902-4413b8edc444


### **After**

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



https://github.com/user-attachments/assets/eb76a40d-240c-4dde-8602-de4cc83539a0




## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.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-mobile/blob/main/.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: tommasini <[email protected]>
  • Loading branch information
sahar-fehri and tommasini authored Aug 1, 2024
1 parent 0c2befd commit 72ce8e1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
36 changes: 36 additions & 0 deletions app/util/activity/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,42 @@ describe('Activity utils :: sortTransactions', () => {
const sortedTxs = sortTransactions(unsortedTxs);
expect(sortedTxs).toEqual(expectedSortedTxs);
});

it('should return correct data when its already sorted', () => {
const unsortedTxs = [
{ id: 'a1', time: 1645406937199 },
{ id: 'a2', time: 1645322223255 },
{ id: 'a3', time: 1645104692826 },
];

const expectedSortedTxs = [
{ id: 'a1', time: 1645406937199 },
{ id: 'a2', time: 1645322223255 },
{ id: 'a3', time: 1645104692826 },
];

const sortedTxs = sortTransactions(unsortedTxs);
expect(sortedTxs).toEqual(expectedSortedTxs);
});

it('should return same array if timestamp is equal', () => {
const unsortedTxs = [
{ id: 'a1', time: 1645406937199 },
{ id: 'a2', time: 1645406937199 },
{ id: 'a3', time: 1645406937199 },
{ id: 'a4', time: 1645406937199 },
];

const expectedSortedTxs = [
{ id: 'a1', time: 1645406937199 },
{ id: 'a2', time: 1645406937199 },
{ id: 'a3', time: 1645406937199 },
{ id: 'a4', time: 1645406937199 },
];

const sortedTxs = sortTransactions(unsortedTxs);
expect(sortedTxs).toEqual(expectedSortedTxs);
});
});

describe('Activity utils :: filterByAddressAndNetwork', () => {
Expand Down
6 changes: 5 additions & 1 deletion app/util/activity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ export const isFromCurrentChain = (
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const sortTransactions = (transactions: any[]): any[] =>
transactions.sort((a, b) => (a.time > b.time ? -1 : b.time > a.time ? 1 : 0));
[...transactions].sort((a, b) => {
if (a.time > b.time) return -1;
if (a.time < b.time) return 1;
return 0;
});

/**
* Filter based on the following conditions:
Expand Down

0 comments on commit 72ce8e1

Please sign in to comment.