Skip to content

Commit

Permalink
Return type of transaction if legacy (#1713)
Browse files Browse the repository at this point in the history
## 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?
-->

Including [1672](#1672) to core
main repo.

## 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?

For example:

* Fixes #12345
* Related to #67890
-->

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/transaction-controller`

- **ADDED**: Includ `transaction?.type` when normalising transaction.

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
  • Loading branch information
blackdevelopa authored and MajorLift committed Oct 11, 2023
1 parent d36d551 commit 8de582d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
6 changes: 6 additions & 0 deletions packages/transaction-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ export interface TransactionParams {
* Value associated with this transaction.
*/
value?: string;

/**
* Type of transaction.
* 0x0 indicates a legacy transaction.
*/
type?: string;
}

/**
Expand Down
51 changes: 38 additions & 13 deletions packages/transaction-controller/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ describe('utils', () => {
jest.clearAllMocks();
});

it('normalizeTxParams', () => {
const normalized = util.normalizeTxParams({
describe('normalizeTxParams', () => {
const commonInput = {
data: 'data',
from: 'FROM',
gas: 'gas',
Expand All @@ -31,18 +31,43 @@ describe('utils', () => {
maxFeePerGas: 'maxFeePerGas',
maxPriorityFeePerGas: 'maxPriorityFeePerGas',
estimatedBaseFee: 'estimatedBaseFee',
};

it('normalizeTransaction', () => {
const normalized = util.normalizeTxParams({
...commonInput,
});
expect(normalized).toStrictEqual({
data: '0xdata',
from: '0xfrom',
gas: '0xgas',
gasPrice: '0xgasPrice',
nonce: '0xnonce',
to: '0xto',
value: '0xvalue',
maxFeePerGas: '0xmaxFeePerGas',
maxPriorityFeePerGas: '0xmaxPriorityFeePerGas',
estimatedBaseFee: '0xestimatedBaseFee',
});
});
expect(normalized).toStrictEqual({
data: '0xdata',
from: '0xfrom',
gas: '0xgas',
gasPrice: '0xgasPrice',
nonce: '0xnonce',
to: '0xto',
value: '0xvalue',
maxFeePerGas: '0xmaxFeePerGas',
maxPriorityFeePerGas: '0xmaxPriorityFeePerGas',
estimatedBaseFee: '0xestimatedBaseFee',
it('normalizeTransaction if type is zero', () => {
const normalized = util.normalizeTxParams({
...commonInput,
type: '0x0',
});
expect(normalized).toStrictEqual({
data: '0xdata',
from: '0xfrom',
gas: '0xgas',
gasPrice: '0xgasPrice',
nonce: '0xnonce',
to: '0xto',
value: '0xvalue',
maxFeePerGas: '0xmaxFeePerGas',
maxPriorityFeePerGas: '0xmaxPriorityFeePerGas',
estimatedBaseFee: '0xestimatedBaseFee',
type: '0x0',
});
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/transaction-controller/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const NORMALIZERS: { [param in keyof TransactionParams]: any } = {
addHexPrefix(maxPriorityFeePerGas),
estimatedBaseFee: (maxPriorityFeePerGas: string) =>
addHexPrefix(maxPriorityFeePerGas),
type: (type: string) => (type === '0x0' ? '0x0' : undefined),
};

/**
Expand Down

0 comments on commit 8de582d

Please sign in to comment.