Skip to content

Commit 07adba5

Browse files
Use transactions array in frontend (#20523)
Send the entire transactions array to the frontend rather than currentNetworkTxList and unapprovedTxs.
1 parent 6ee90ac commit 07adba5

File tree

50 files changed

+415
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+415
-375
lines changed

.storybook/test-data.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const state = {
2727
image: {
2828
src: 'images/global-menu-block-explorer.svg',
2929
},
30-
}
30+
},
3131
},
3232
tokenList: {
3333
'0x514910771af9ca656af840dff83e8264ecf986ca': {
@@ -314,8 +314,8 @@ const state = {
314314
address: '0x9d0ba4ddac06032527b140912ec808ab9451b788',
315315
},
316316
},
317-
unapprovedTxs: {
318-
3111025347726181: {
317+
transactions: [
318+
{
319319
id: 3111025347726181,
320320
time: 1620710815484,
321321
status: 'unapproved',
@@ -365,7 +365,7 @@ const state = {
365365
],
366366
],
367367
},
368-
},
368+
],
369369
addressBook: {
370370
undefined: {
371371
0: {
@@ -574,7 +574,7 @@ const state = {
574574
},
575575
},
576576
currentBlockGasLimit: '0x793af4',
577-
currentNetworkTxList: [
577+
transactions: [
578578
{
579579
chainId: '0x38',
580580
dappSuggestedGasFees: null,

app/scripts/background.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ browser.runtime.onConnectExternal.addListener(async (...args) => {
218218
* @property {boolean} isAccountMenuOpen - Represents whether the main account selection UI is currently displayed.
219219
* @property {boolean} isNetworkMenuOpen - Represents whether the main network selection UI is currently displayed.
220220
* @property {object} identities - An object matching lower-case hex addresses to Identity objects with "address" and "name" (nickname) keys.
221-
* @property {object} unapprovedTxs - An object mapping transaction hashes to unapproved transactions.
222221
* @property {object} networkConfigurations - A list of network configurations, containing RPC provider details (eg chainId, rpcUrl, rpcPreferences).
223222
* @property {Array} addressBook - A list of previously sent to addresses.
224223
* @property {object} contractExchangeRates - Info about current token prices.
@@ -235,7 +234,6 @@ browser.runtime.onConnectExternal.addListener(async (...args) => {
235234
* @property {string} networkStatus - Either "unknown", "available", "unavailable", or "blocked", depending on the status of the currently selected network.
236235
* @property {object} accounts - An object mapping lower-case hex addresses to objects with "balance" and "address" keys, both storing hex string values.
237236
* @property {hex} currentBlockGasLimit - The most recently seen block gas limit, in a lower case hex prefixed string.
238-
* @property {TransactionMeta[]} currentNetworkTxList - An array of transactions associated with the currently selected network.
239237
* @property {object} unapprovedMsgs - An object of messages pending approval, mapping a unique ID to the options.
240238
* @property {number} unapprovedMsgCount - The number of messages in unapprovedMsgs.
241239
* @property {object} unapprovedPersonalMsgs - An object of messages pending approval, mapping a unique ID to the options.

app/scripts/controllers/transactions/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export default class TransactionController extends EventEmitter {
229229
isEnabled: () =>
230230
Boolean(
231231
this.preferencesStore.getState().incomingTransactionsPreferences?.[
232-
this._getChainId()
232+
this._getCurrentChainId()
233233
] && this._hasCompletedOnboarding(),
234234
),
235235
lastFetchedBlockNumbers: opts.initState?.lastFetchedBlockNumbers || {},
@@ -2135,16 +2135,12 @@ export default class TransactionController extends EventEmitter {
21352135
* Updates the memStore in transaction controller
21362136
*/
21372137
_updateMemstore() {
2138-
const { transactions } = this.store.getState();
2139-
const unapprovedTxs = this.txStateManager.getUnapprovedTxList();
2140-
2141-
const currentNetworkTxList = this.txStateManager.getTransactions({
2138+
const transactions = this.getTransactions({
2139+
filterToCurrentNetwork: false,
21422140
limit: MAX_MEMSTORE_TX_LIST_SIZE,
21432141
});
21442142

21452143
this.memStore.updateState({
2146-
unapprovedTxs,
2147-
currentNetworkTxList,
21482144
transactions,
21492145
});
21502146
}

app/scripts/controllers/transactions/index.test.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ const TRANSACTION_META_MOCK = {
5656
hash: '0x1',
5757
id: 1,
5858
status: TransactionStatus.confirmed,
59-
transaction: {
59+
time: 123456789,
60+
txParams: {
6061
from: VALID_ADDRESS,
6162
},
62-
time: 123456789,
6363
};
6464

6565
async function flushPromises() {
@@ -186,21 +186,10 @@ describe('Transaction Controller', function () {
186186
it('should return a state object with the right keys and data types', function () {
187187
const exposedState = txController.getState();
188188
assert.ok(
189-
'unapprovedTxs' in exposedState,
190-
'state should have the key unapprovedTxs',
191-
);
192-
assert.ok(
193-
'currentNetworkTxList' in exposedState,
194-
'state should have the key currentNetworkTxList',
195-
);
196-
assert.ok(
197-
typeof exposedState?.unapprovedTxs === 'object',
198-
'should be an object',
199-
);
200-
assert.ok(
201-
Array.isArray(exposedState.currentNetworkTxList),
202-
'should be an array',
189+
'transactions' in exposedState,
190+
'state should have the key transactions',
203191
);
192+
assert.ok(Array.isArray(exposedState.transactions), 'should be an array');
204193
});
205194
});
206195

app/scripts/lib/setupSentry.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,11 @@ export const SENTRY_BACKGROUND_STATE = {
283283
tokens: false,
284284
},
285285
TransactionController: {
286-
currentNetworkTxList: false,
287286
transactions: false,
288287
lastFetchedBlockNumbers: false,
289288
},
290289
TxController: {
291-
currentNetworkTxList: false,
292290
transactions: false,
293-
unapprovedTxs: false,
294291
},
295292
};
296293

test/data/mock-send-state.json

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -180,57 +180,6 @@
180180
}
181181
},
182182
"cachedBalances": {},
183-
"incomingTransactions": {},
184-
"unapprovedTxs": {
185-
"8393540981007587": {
186-
"id": 8393540981007587,
187-
"time": 1536268017676,
188-
"status": "unapproved",
189-
"metamaskNetworkId": "4",
190-
"loadingDefaults": false,
191-
"txParams": {
192-
"from": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
193-
"to": "0xc42edfcc21ed14dda456aa0756c153f7985d8813",
194-
"value": "0x0",
195-
"gas": "0x5208",
196-
"gasPrice": "0x3b9aca00"
197-
},
198-
"history": [
199-
{
200-
"id": 8393540981007587,
201-
"time": 1536268017676,
202-
"status": "unapproved",
203-
"metamaskNetworkId": "4",
204-
"loadingDefaults": true,
205-
"txParams": {
206-
"from": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
207-
"to": "0xc42edfcc21ed14dda456aa0756c153f7985d8813",
208-
"value": "0x0",
209-
"gas": "0x5208",
210-
"gasPrice": "0x3b9aca00"
211-
}
212-
},
213-
[
214-
{
215-
"op": "replace",
216-
"path": "/loadingDefaults",
217-
"value": false,
218-
"timestamp": 1536268017685
219-
}
220-
],
221-
[
222-
{
223-
"op": "add",
224-
"path": "/origin",
225-
"value": "MetaMask",
226-
"note": "#newUnapprovedTransaction - adding the origin",
227-
"timestamp": 1536268017686
228-
}
229-
]
230-
],
231-
"origin": "MetaMask"
232-
}
233-
},
234183
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
235184
"accounts": {
236185
"0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc": {
@@ -347,7 +296,55 @@
347296
"occurrences": 12
348297
}
349298
},
350-
"currentNetworkTxList": [
299+
"transactions": [
300+
{
301+
"id": 8393540981007587,
302+
"time": 1536268017676,
303+
"status": "unapproved",
304+
"metamaskNetworkId": "4",
305+
"loadingDefaults": false,
306+
"txParams": {
307+
"from": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
308+
"to": "0xc42edfcc21ed14dda456aa0756c153f7985d8813",
309+
"value": "0x0",
310+
"gas": "0x5208",
311+
"gasPrice": "0x3b9aca00"
312+
},
313+
"history": [
314+
{
315+
"id": 8393540981007587,
316+
"time": 1536268017676,
317+
"status": "unapproved",
318+
"metamaskNetworkId": "4",
319+
"loadingDefaults": true,
320+
"txParams": {
321+
"from": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
322+
"to": "0xc42edfcc21ed14dda456aa0756c153f7985d8813",
323+
"value": "0x0",
324+
"gas": "0x5208",
325+
"gasPrice": "0x3b9aca00"
326+
}
327+
},
328+
[
329+
{
330+
"op": "replace",
331+
"path": "/loadingDefaults",
332+
"value": false,
333+
"timestamp": 1536268017685
334+
}
335+
],
336+
[
337+
{
338+
"op": "add",
339+
"path": "/origin",
340+
"value": "MetaMask",
341+
"note": "#newUnapprovedTransaction - adding the origin",
342+
"timestamp": 1536268017686
343+
}
344+
]
345+
],
346+
"origin": "MetaMask"
347+
},
351348
{
352349
"id": 3387511061307736,
353350
"time": 1528133130531,

test/data/mock-state.json

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -227,59 +227,6 @@
227227
"0xaa36a7": true,
228228
"0xe704": true
229229
},
230-
231-
"unapprovedTxs": {
232-
"8393540981007587": {
233-
"chainId": "0x5",
234-
"id": 8393540981007587,
235-
"time": 1536268017676,
236-
"status": "unapproved",
237-
"metamaskNetworkId": "4",
238-
"loadingDefaults": false,
239-
"txParams": {
240-
"data": "0xa9059cbb000000000000000000000000b19ac54efa18cc3a14a5b821bfec73d284bf0c5e0000000000000000000000000000000000000000000000003782dace9d900000",
241-
"from": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
242-
"to": "0xc42edfcc21ed14dda456aa0756c153f7985d8813",
243-
"value": "0x0",
244-
"gas": "0x5208",
245-
"gasPrice": "0x3b9aca00"
246-
},
247-
"history": [
248-
{
249-
"id": 8393540981007587,
250-
"time": 1536268017676,
251-
"status": "unapproved",
252-
"metamaskNetworkId": "4",
253-
"loadingDefaults": true,
254-
"txParams": {
255-
"from": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
256-
"to": "0xc42edfcc21ed14dda456aa0756c153f7985d8813",
257-
"value": "0x0",
258-
"gas": "0x5208",
259-
"gasPrice": "0x3b9aca00"
260-
}
261-
},
262-
[
263-
{
264-
"op": "replace",
265-
"path": "/loadingDefaults",
266-
"value": false,
267-
"timestamp": 1536268017685
268-
}
269-
],
270-
[
271-
{
272-
"op": "add",
273-
"path": "/origin",
274-
"value": "MetaMask",
275-
"note": "#newUnapprovedTransaction - adding the origin",
276-
"timestamp": 1536268017686
277-
}
278-
]
279-
],
280-
"origin": "metamask"
281-
}
282-
},
283230
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
284231
"accounts": {
285232
"0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc": {
@@ -643,7 +590,57 @@
643590
"occurrences": 12
644591
}
645592
},
646-
"currentNetworkTxList": [
593+
"transactions": [
594+
{
595+
"chainId": "0x5",
596+
"id": 8393540981007587,
597+
"time": 1536268017676,
598+
"status": "unapproved",
599+
"metamaskNetworkId": "4",
600+
"loadingDefaults": false,
601+
"txParams": {
602+
"data": "0xa9059cbb000000000000000000000000b19ac54efa18cc3a14a5b821bfec73d284bf0c5e0000000000000000000000000000000000000000000000003782dace9d900000",
603+
"from": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
604+
"to": "0xc42edfcc21ed14dda456aa0756c153f7985d8813",
605+
"value": "0x0",
606+
"gas": "0x5208",
607+
"gasPrice": "0x3b9aca00"
608+
},
609+
"history": [
610+
{
611+
"id": 8393540981007587,
612+
"time": 1536268017676,
613+
"status": "unapproved",
614+
"metamaskNetworkId": "4",
615+
"loadingDefaults": true,
616+
"txParams": {
617+
"from": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
618+
"to": "0xc42edfcc21ed14dda456aa0756c153f7985d8813",
619+
"value": "0x0",
620+
"gas": "0x5208",
621+
"gasPrice": "0x3b9aca00"
622+
}
623+
},
624+
[
625+
{
626+
"op": "replace",
627+
"path": "/loadingDefaults",
628+
"value": false,
629+
"timestamp": 1536268017685
630+
}
631+
],
632+
[
633+
{
634+
"op": "add",
635+
"path": "/origin",
636+
"value": "MetaMask",
637+
"note": "#newUnapprovedTransaction - adding the origin",
638+
"timestamp": 1536268017686
639+
}
640+
]
641+
],
642+
"origin": "metamask"
643+
},
647644
{
648645
"id": 3387511061307736,
649646
"time": 1528133130531,

test/e2e/tests/state-snapshots/errors-after-init-opt-in-background-state.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@
218218
"allDetectedTokens": {}
219219
},
220220
"TxController": {
221-
"unapprovedTxs": "object",
222-
"currentNetworkTxList": "object",
223221
"transactions": "object"
224222
}
225223
}

test/e2e/tests/state-snapshots/errors-after-init-opt-in-ui-state.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"isAccountMenuOpen": false,
1414
"isNetworkMenuOpen": false,
1515
"identities": "object",
16-
"unapprovedTxs": "object",
1716
"networkConfigurations": "object",
1817
"addressBook": "object",
1918
"contractExchangeRates": "object",
@@ -153,7 +152,6 @@
153152
"lastUpdated": "object",
154153
"notifications": "object",
155154
"accounts": "object",
156-
"currentNetworkTxList": "object",
157155
"transactions": "object",
158156
"unapprovedDecryptMsgs": "object",
159157
"unapprovedDecryptMsgCount": 0,

0 commit comments

Comments
 (0)