Skip to content

Commit 9075f5c

Browse files
committed
Refactor: Rename transactionHash to hash
1 parent 3c32e01 commit 9075f5c

File tree

8 files changed

+38
-46
lines changed

8 files changed

+38
-46
lines changed

packages/transaction-controller/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = merge(baseConfig, {
1919
global: {
2020
branches: 83.91,
2121
functions: 92.68,
22-
lines: 95.35,
22+
lines: 95.34,
2323
statements: 95.46,
2424
},
2525
},

packages/transaction-controller/src/EtherscanRemoteTransactionSource.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const EXPECTED_NORMALISED_TRANSACTION_BASE = {
102102
to: ETHERSCAN_TRANSACTION_SUCCESS_MOCK.to,
103103
value: '0xb1a2bc2ec50000',
104104
},
105-
transactionHash: ETHERSCAN_TRANSACTION_SUCCESS_MOCK.hash,
105+
hash: ETHERSCAN_TRANSACTION_SUCCESS_MOCK.hash,
106106
verifiedOnBlockchain: false,
107107
};
108108

packages/transaction-controller/src/EtherscanRemoteTransactionSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class EtherscanRemoteTransactionSource
154154
to: txMeta.to,
155155
value: BNToHex(new BN(txMeta.value)),
156156
},
157-
transactionHash: txMeta.hash,
157+
hash: txMeta.hash,
158158
verifiedOnBlockchain: false,
159159
};
160160
}

packages/transaction-controller/src/IncomingTransactionHelper.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ const TRANSACTION_MOCK: TransactionMeta = {
4848
status: TransactionStatus.submitted,
4949
time: 0,
5050
transaction: { to: '0x1', gasUsed: '0x1' },
51-
transactionHash: '0x1',
51+
hash: '0x1',
5252
} as unknown as TransactionMeta;
5353

5454
const TRANSACTION_MOCK_2: TransactionMeta = {
5555
blockNumber: '234',
5656
chainId: '0x1',
5757
time: 1,
5858
transaction: { to: '0x1' },
59-
transactionHash: '0x2',
59+
hash: '0x2',
6060
} as unknown as TransactionMeta;
6161

6262
const createRemoteTransactionSourceMock = (

packages/transaction-controller/src/IncomingTransactionHelper.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,7 @@ export class IncomingTransactionHelper {
178178
localTxs: TransactionMeta[],
179179
): TransactionMeta[] {
180180
return remoteTxs.filter(
181-
(tx) =>
182-
!localTxs.some(
183-
({ transactionHash }) => transactionHash === tx.transactionHash,
184-
),
181+
(tx) => !localTxs.some(({ hash }) => hash === tx.hash),
185182
);
186183
}
187184

@@ -192,7 +189,7 @@ export class IncomingTransactionHelper {
192189
return remoteTxs.filter((remoteTx) =>
193190
localTxs.some(
194191
(localTx) =>
195-
remoteTx.transactionHash === localTx.transactionHash &&
192+
remoteTx.hash === localTx.hash &&
196193
this.#isTransactionOutdated(remoteTx, localTx),
197194
),
198195
);

packages/transaction-controller/src/TransactionController.test.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ jest.mock('@metamask/eth-query', () =>
8484
},
8585
getTransactionByHash: (_hash: string, callback: any) => {
8686
const txs: any = [
87-
{ transactionHash: '1337', blockNumber: '0x1' },
88-
{ transactionHash: '1338', blockNumber: null },
87+
{ hash: '1337', blockNumber: '0x1' },
88+
{ hash: '1338', blockNumber: null },
8989
];
90-
const tx: any = txs.find(
91-
(element: any) => element.transactionHash === _hash,
92-
);
90+
const tx: any = txs.find((element: any) => element.hash === _hash);
9391
callback(undefined, tx);
9492
},
9593
getTransactionCount: (_from: any, _to: any, callback: any) => {
@@ -101,22 +99,20 @@ jest.mock('@metamask/eth-query', () =>
10199
getTransactionReceipt: (_hash: any, callback: any) => {
102100
const txs: any = [
103101
{
104-
transactionHash: '1337',
102+
hash: '1337',
105103
gasUsed: '0x5208',
106104
status: '0x1',
107105
transactionIndex: 1337,
108106
blockHash: '1337',
109107
},
110108
{
111-
transactionHash: '1111',
109+
hash: '1111',
112110
gasUsed: '0x1108',
113111
status: '0x0',
114112
transactionIndex: 1111,
115113
},
116114
];
117-
const tx: any = txs.find(
118-
(element: any) => element.transactionHash === _hash,
119-
);
115+
const tx: any = txs.find((element: any) => element.hash === _hash);
120116
callback(undefined, tx);
121117
},
122118
getBlockByHash: (_blockHash: any, callback: any) => {
@@ -401,7 +397,7 @@ const TRANSACTION_META_MOCK = {
401397
transaction: {
402398
from: ACCOUNT_MOCK,
403399
},
404-
transactionHash: '0x1',
400+
hash: '0x1',
405401
time: 123456789,
406402
} as TransactionMeta;
407403

@@ -410,7 +406,7 @@ const TRANSACTION_META_2_MOCK = {
410406
transaction: {
411407
from: '0x3',
412408
},
413-
transactionHash: '0x2',
409+
hash: '0x2',
414410
time: 987654321,
415411
} as TransactionMeta;
416412

@@ -1174,7 +1170,7 @@ describe('TransactionController', () => {
11741170
id: 'foo',
11751171
networkID: '5',
11761172
status: TransactionStatus.submitted,
1177-
transactionHash: '1337',
1173+
hash: '1337',
11781174
} as any);
11791175

11801176
controller.wipeTransactions();
@@ -1255,7 +1251,7 @@ describe('TransactionController', () => {
12551251
networkID: '5',
12561252
chainId: toHex(5),
12571253
status: TransactionStatus.submitted,
1258-
transactionHash: '1337',
1254+
hash: '1337',
12591255
} as any);
12601256

12611257
controller.state.transactions.push({} as any);
@@ -1280,7 +1276,7 @@ describe('TransactionController', () => {
12801276
id: 'foo',
12811277
networkID: '5',
12821278
status: TransactionStatus.submitted,
1283-
transactionHash: '1337',
1279+
hash: '1337',
12841280
} as any);
12851281

12861282
controller.state.transactions.push({} as any);
@@ -1303,7 +1299,7 @@ describe('TransactionController', () => {
13031299
id: 'foo',
13041300
networkID: '5',
13051301
status: TransactionStatus.submitted,
1306-
transactionHash: '1338',
1302+
hash: '1338',
13071303
} as any);
13081304

13091305
await controller.queryTransactionStatuses();
@@ -1321,7 +1317,7 @@ describe('TransactionController', () => {
13211317
networkID: '5',
13221318
chainId: toHex(5),
13231319
status: TransactionStatus.confirmed,
1324-
transactionHash: '1337',
1320+
hash: '1337',
13251321
verifiedOnBlockchain: false,
13261322
transaction: {
13271323
gasUsed: undefined,
@@ -1527,14 +1523,14 @@ describe('TransactionController', () => {
15271523
id: 'mocked',
15281524
networkID: '5',
15291525
status: TransactionStatus.unapproved,
1530-
transactionHash: '1337',
1526+
hash: '1337',
15311527
};
15321528
const controller = newController();
15331529
controller.state.transactions.push(transaction as any);
15341530
controller.state.transactions.push({
15351531
...transaction,
15361532
id: 'mocked1',
1537-
transactionHash: '1338',
1533+
hash: '1338',
15381534
} as any);
15391535

15401536
controller.initApprovals();

packages/transaction-controller/src/TransactionController.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -670,14 +670,14 @@ export class TransactionController extends BaseController<
670670
transactionMeta.transaction.from,
671671
);
672672
const rawTransaction = bufferToHex(signedTx.serialize());
673-
const transactionHash = await query(this.ethQuery, 'sendRawTransaction', [
673+
const hash = await query(this.ethQuery, 'sendRawTransaction', [
674674
rawTransaction,
675675
]);
676676
const baseTransactionMeta = {
677677
...transactionMeta,
678678
id: random(),
679679
time: Date.now(),
680-
transactionHash,
680+
hash,
681681
};
682682
const newTransactionMeta =
683683
newMaxFeePerGas && newMaxPriorityFeePerGas
@@ -945,7 +945,7 @@ export class TransactionController extends BaseController<
945945

946946
case TransactionStatus.submitted:
947947
resultCallbacks?.success();
948-
return finalMeta.transactionHash as string;
948+
return finalMeta.hash as string;
949949

950950
default:
951951
const internalError = ethErrors.rpc.internal(
@@ -1036,10 +1036,10 @@ export class TransactionController extends BaseController<
10361036

10371037
transactionMeta.rawTransaction = rawTransaction;
10381038
this.updateTransaction(transactionMeta);
1039-
const transactionHash = await query(this.ethQuery, 'sendRawTransaction', [
1039+
const hash = await query(this.ethQuery, 'sendRawTransaction', [
10401040
rawTransaction,
10411041
]);
1042-
transactionMeta.transactionHash = transactionHash;
1042+
transactionMeta.hash = hash;
10431043
transactionMeta.status = TransactionStatus.submitted;
10441044
this.updateTransaction(transactionMeta);
10451045
this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);
@@ -1155,11 +1155,11 @@ export class TransactionController extends BaseController<
11551155
private async blockchainTransactionStateReconciler(
11561156
meta: TransactionMeta,
11571157
): Promise<[TransactionMeta, boolean]> {
1158-
const { status, transactionHash } = meta;
1158+
const { status, hash } = meta;
11591159
switch (status) {
11601160
case TransactionStatus.confirmed:
11611161
const txReceipt = await query(this.ethQuery, 'getTransactionReceipt', [
1162-
transactionHash,
1162+
hash,
11631163
]);
11641164

11651165
if (!txReceipt) {
@@ -1189,12 +1189,12 @@ export class TransactionController extends BaseController<
11891189
return [meta, true];
11901190
case TransactionStatus.submitted:
11911191
const txObj = await query(this.ethQuery, 'getTransactionByHash', [
1192-
transactionHash,
1192+
hash,
11931193
]);
11941194

11951195
if (!txObj) {
11961196
const receiptShowsFailedStatus =
1197-
await this.checkTxReceiptStatusIsFailed(transactionHash);
1197+
await this.checkTxReceiptStatusIsFailed(hash);
11981198

11991199
// Case the txObj is evaluated as false, a second check will
12001200
// determine if the tx failed or it is pending or confirmed
@@ -1351,8 +1351,7 @@ export class TransactionController extends BaseController<
13511351
...added,
13521352
...currentTransactions.map((originalTransaction) => {
13531353
const updatedTransaction = updated.find(
1354-
({ transactionHash }) =>
1355-
transactionHash === originalTransaction.transactionHash,
1354+
({ hash }) => hash === originalTransaction.hash,
13561355
);
13571356

13581357
return updatedTransaction ?? originalTransaction;

packages/transaction-controller/src/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ type TransactionMetaBase = {
4444
deviceConfirmedOn?: WalletDevice;
4545

4646
/**
47-
* Generated UUID associated with this transaction.
47+
* Hash of a successful transaction.
48+
*/
49+
hash?: string;
50+
51+
/**
52+
* Transaction ID.
4853
*/
4954
id: string;
5055

@@ -83,11 +88,6 @@ type TransactionMetaBase = {
8388
*/
8489
transaction: Transaction;
8590

86-
/**
87-
* Hash of a successful transaction.
88-
*/
89-
transactionHash?: string;
90-
9191
/**
9292
* Additional transfer information.
9393
*/

0 commit comments

Comments
 (0)