Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type {
} from './TransactionController';
import { TransactionController, HARDFORK } from './TransactionController';
import type { TransactionMeta } from './types';
import { TransactionStatus } from './types';
import { WalletDevice, TransactionStatus } from './types';
import { ESTIMATE_GAS_ERROR } from './utils';
import { FakeBlockTracker } from '../../../tests/fake-block-tracker';
import { mockNetwork } from '../../../tests/mock-network';
Expand Down Expand Up @@ -654,10 +654,19 @@ describe('TransactionController', () => {
it('adds unapproved transaction to state', async () => {
const controller = newController();

await controller.addTransaction({
from: ACCOUNT_MOCK,
to: ACCOUNT_MOCK,
});
const mockDeviceConfirmedOn = WalletDevice.OTHER;
const mockOrigin = 'origin';

await controller.addTransaction(
{
from: ACCOUNT_MOCK,
to: ACCOUNT_MOCK,
},
{
deviceConfirmedOn: mockDeviceConfirmedOn,
origin: mockOrigin,
},
);

expect(controller.state.transactions[0].transaction.from).toBe(
ACCOUNT_MOCK,
Expand All @@ -668,6 +677,10 @@ describe('TransactionController', () => {
expect(controller.state.transactions[0].chainId).toBe(
MOCK_NETWORK.state.providerConfig.chainId,
);
expect(controller.state.transactions[0].deviceConfirmedOn).toBe(
mockDeviceConfirmedOn,
);
expect(controller.state.transactions[0].origin).toBe(mockOrigin);
expect(controller.state.transactions[0].status).toBe(
TransactionStatus.unapproved,
);
Expand Down
14 changes: 10 additions & 4 deletions packages/transaction-controller/src/TransactionController.ts
Comment thread
matthewwalsh0 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,20 @@ export class TransactionController extends BaseController<
* if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.
*
* @param transaction - The transaction object to add.
* @param origin - The domain origin to append to the generated TransactionMeta.
* @param deviceConfirmedOn - An enum to indicate what device the transaction was confirmed to append to the generated TransactionMeta.
* @param opts - Additional options to control how the transaction is added.
* @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
* @param opts.origin - The origin of the transaction request, such as a dApp hostname.
* @returns Object containing a promise resolving to the transaction hash if approved.
*/
async addTransaction(
transaction: Transaction,
origin?: string,
deviceConfirmedOn?: WalletDevice,
{
deviceConfirmedOn,
origin,
}: {
deviceConfirmedOn?: WalletDevice;
origin?: string;
} = {},
): Promise<Result> {
const { providerConfig, networkId } = this.getNetworkState();
const { transactions } = this.state;
Expand Down