Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove global network from transaction controller #28449

Merged
Merged
2 changes: 1 addition & 1 deletion app/scripts/controllers/mmi-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export class MMIController {
}
}

const txList = this.txStateManager.getTransactions({}, [], false); // Includes all transactions, but we are looping through keyrings. Currently filtering is done in updateCustodianTransactions :-/
const txList = this.txStateManager.getTransactions(); // Includes all transactions, but we are looping through keyrings. Currently filtering is done in updateCustodianTransactions :-/

try {
updateCustodianTransactions({
Expand Down
1 change: 1 addition & 0 deletions app/scripts/lib/transaction/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ describe('Transaction metrics', () => {
type: TransactionType.simpleSend,
origin: ORIGIN_METAMASK,
chainId: mockChainId,
networkClientId: 'testNetworkClientId',
time: 1624408066355,
defaultGasEstimates: {
gas: '0x7b0d',
Expand Down
1 change: 1 addition & 0 deletions app/scripts/lib/transaction/smart-transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ function withRequest<ReturnValue>(
},
type: TransactionType.simpleSend,
chainId: CHAIN_IDS.MAINNET,
networkClientId: 'testNetworkClientId',
time: 1624408066355,
defaultGasEstimates: {
gas: '0x7b0d',
Expand Down
39 changes: 1 addition & 38 deletions app/scripts/lib/transaction/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const TRANSACTION_PARAMS_MOCK: TransactionParams = {

const TRANSACTION_OPTIONS_MOCK: AddTransactionOptions = {
actionId: 'mockActionId',
networkClientId: 'mockNetworkClientId',
origin: 'mockOrigin',
requireApproval: false,
type: TransactionType.simpleSend,
Expand Down Expand Up @@ -151,23 +152,6 @@ describe('Transaction Utils', () => {
});
});

it('adds transaction with networkClientId if process.env.TRANSACTION_MULTICHAIN is set', async () => {
process.env.TRANSACTION_MULTICHAIN = '1';

await addTransaction(request);

expect(
request.transactionController.addTransaction,
).toHaveBeenCalledTimes(1);
expect(
request.transactionController.addTransaction,
).toHaveBeenCalledWith(TRANSACTION_PARAMS_MOCK, {
...TRANSACTION_OPTIONS_MOCK,
networkClientId: 'mockNetworkClientId',
});
process.env.TRANSACTION_MULTICHAIN = '';
});

it('returns transaction meta', async () => {
const transactionMeta = await addTransaction(request);
expect(transactionMeta).toStrictEqual(TRANSACTION_META_MOCK);
Expand Down Expand Up @@ -541,27 +525,6 @@ describe('Transaction Utils', () => {
});
});

it('adds transaction with networkClientId if process.env.TRANSACTION_MULTICHAIN is set', async () => {
process.env.TRANSACTION_MULTICHAIN = '1';

await addDappTransaction(dappRequest);

expect(
request.transactionController.addTransaction,
).toHaveBeenCalledTimes(1);
expect(
request.transactionController.addTransaction,
).toHaveBeenCalledWith(TRANSACTION_PARAMS_MOCK, {
...TRANSACTION_OPTIONS_MOCK,
networkClientId: 'mockNetworkClientId',
method: DAPP_REQUEST_MOCK.method,
requireApproval: true,
securityAlertResponse: DAPP_REQUEST_MOCK.securityAlertResponse,
type: undefined,
});
process.env.TRANSACTION_MULTICHAIN = '';
});

it('returns transaction hash', async () => {
const transactionHash = await addDappTransaction(dappRequest);
expect(transactionHash).toStrictEqual(TRANSACTION_META_MOCK.hash);
Expand Down
7 changes: 4 additions & 3 deletions app/scripts/lib/transaction/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type BaseAddTransactionRequest = {
};

type FinalAddTransactionRequest = BaseAddTransactionRequest & {
transactionOptions: AddTransactionOptions;
transactionOptions: Partial<AddTransactionOptions>;
};

export type AddTransactionRequest = FinalAddTransactionRequest & {
Expand All @@ -66,7 +66,7 @@ export async function addDappTransaction(
const { id: actionId, method, origin } = dappRequest;
const { securityAlertResponse, traceContext } = dappRequest;

const transactionOptions: AddTransactionOptions = {
const transactionOptions: Partial<AddTransactionOptions> = {
actionId,
method,
origin,
Expand Down Expand Up @@ -143,10 +143,11 @@ async function addTransactionWithController(
transactionParams,
networkClientId,
} = request;

const { result, transactionMeta } =
await transactionController.addTransaction(transactionParams, {
...transactionOptions,
...(process.env.TRANSACTION_MULTICHAIN ? { networkClientId } : {}),
networkClientId,
});

return {
Expand Down
Loading
Loading