@metamask/transaction-controller 63.1.0 → 63.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -1
- package/dist/TransactionController-method-action-types.cjs +1 -1
- package/dist/TransactionController-method-action-types.cjs.map +1 -1
- package/dist/TransactionController-method-action-types.d.cts +1 -1
- package/dist/TransactionController-method-action-types.d.mts +1 -1
- package/dist/TransactionController-method-action-types.mjs +1 -1
- package/dist/TransactionController-method-action-types.mjs.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.cjs +11 -2
- package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.mjs +11 -2
- package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [63.2.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Fix sentry issue about unsubscribe for event AccountActivityService:transactionUpdated called even if subscription is not done ([#8299](https://github.com/MetaMask/core/pull/8299))
|
|
15
|
+
|
|
10
16
|
## [63.1.0]
|
|
11
17
|
|
|
12
18
|
### Added
|
|
@@ -2265,7 +2271,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
2265
2271
|
|
|
2266
2272
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
2267
2273
|
|
|
2268
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@63.
|
|
2274
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@63.2.0...HEAD
|
|
2275
|
+
[63.2.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@63.1.0...@metamask/transaction-controller@63.2.0
|
|
2269
2276
|
[63.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@63.0.0...@metamask/transaction-controller@63.1.0
|
|
2270
2277
|
[63.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@62.22.0...@metamask/transaction-controller@63.0.0
|
|
2271
2278
|
[62.22.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@62.21.0...@metamask/transaction-controller@62.22.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionController-method-action-types.cjs","sourceRoot":"","sources":["../src/TransactionController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { TransactionController } from './TransactionController';\n\n/**\n * Handle new method data request.\n *\n * @param fourBytePrefix - The method prefix.\n * @param networkClientId - The ID of the network client used to fetch the method data.\n * @returns The method data object corresponding to the given signature prefix.\n */\nexport type TransactionControllerHandleMethodDataAction = {\n type: `TransactionController:handleMethodData`;\n handler: TransactionController['handleMethodData'];\n};\n\n/**\n * Add a batch of transactions to be submitted after approval.\n *\n * @param request - Request object containing the transactions to add.\n * @returns Result object containing the generated batch ID.\n */\nexport type TransactionControllerAddTransactionBatchAction = {\n type: `TransactionController:addTransactionBatch`;\n handler: TransactionController['addTransactionBatch'];\n};\n\n/**\n * Determine which chains support atomic batch transactions with the given account address.\n *\n * @param request - Request object containing the account address and other parameters.\n * @returns Result object containing the supported chains and related information.\n */\nexport type TransactionControllerIsAtomicBatchSupportedAction = {\n type: `TransactionController:isAtomicBatchSupported`;\n handler: TransactionController['isAtomicBatchSupported'];\n};\n\n/**\n * Add a new unapproved transaction to state. Parameters will be validated, a\n * unique transaction ID will be generated, and `gas` and `gasPrice` will be calculated\n * if not provided. A `<tx.id>:unapproved` hub event will be emitted once added.\n *\n * @param txParams - Standard parameters for an Ethereum transaction.\n * @param options - Additional options to control how the transaction is added.\n * @returns Object containing a promise resolving to the transaction hash if approved.\n */\nexport type TransactionControllerAddTransactionAction = {\n type: `TransactionController:addTransaction`;\n handler: TransactionController['addTransaction'];\n};\n\n/**\n * Starts polling for incoming transactions from the remote transaction source.\n */\nexport type TransactionControllerStartIncomingTransactionPollingAction = {\n type: `TransactionController:startIncomingTransactionPolling`;\n handler: TransactionController['startIncomingTransactionPolling'];\n};\n\n/**\n * Stops polling for incoming transactions from the remote transaction source.\n */\nexport type TransactionControllerStopIncomingTransactionPollingAction = {\n type: `TransactionController:stopIncomingTransactionPolling`;\n handler: TransactionController['stopIncomingTransactionPolling'];\n};\n\n/**\n * Update the incoming transactions by polling the remote transaction source.\n *\n * @param request - Request object.\n * @param request.tags - Additional tags to identify the source of the request.\n */\nexport type TransactionControllerUpdateIncomingTransactionsAction = {\n type: `TransactionController:updateIncomingTransactions`;\n handler: TransactionController['updateIncomingTransactions'];\n};\n\n/**\n * Attempts to cancel a transaction based on its ID by setting its status to \"rejected\"\n * and emitting a `<tx.id>:finished` hub event.\n *\n * @param transactionId - The ID of the transaction to cancel.\n * @param gasValues - The gas values to use for the cancellation transaction.\n * @param options - The options for the cancellation transaction.\n * @param options.actionId - Unique ID persisted on transaction metadata.\n * @param options.estimatedBaseFee - The estimated base fee of the transaction.\n */\nexport type TransactionControllerStopTransactionAction = {\n type: `TransactionController:stopTransaction`;\n handler: TransactionController['stopTransaction'];\n};\n\n/**\n * Attempts to speed up a transaction increasing transaction gasPrice by ten percent.\n *\n * @param transactionId - The ID of the transaction to speed up.\n * @param gasValues - The gas values to use for the speed up transaction.\n * @param options - The options for the speed up transaction.\n * @param options.actionId - Unique ID persisted on transaction metadata.\n * @param options.estimatedBaseFee - The estimated base fee of the transaction.\n */\nexport type TransactionControllerSpeedUpTransactionAction = {\n type: `TransactionController:speedUpTransaction`;\n handler: TransactionController['speedUpTransaction'];\n};\n\n/**\n * Estimates required gas for a given transaction.\n *\n * @param transaction - The transaction to estimate gas for.\n * @param networkClientId - The network client id to use for the estimate.\n * @param options - Additional options for the estimate.\n * @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager.\n * @returns The gas and gas price.\n */\nexport type TransactionControllerEstimateGasAction = {\n type: `TransactionController:estimateGas`;\n handler: TransactionController['estimateGas'];\n};\n\n/**\n * Estimates required gas for a batch of transactions.\n *\n * @param request - Request object.\n * @param request.chainId - Chain ID of the transactions.\n * @param request.from - Address of the sender.\n * @param request.transactions - Array of transactions within a batch request.\n * @returns Object containing the gas limit.\n */\nexport type TransactionControllerEstimateGasBatchAction = {\n type: `TransactionController:estimateGasBatch`;\n handler: TransactionController['estimateGasBatch'];\n};\n\n/**\n * Estimates required gas for a given transaction and add additional gas buffer with the given multiplier.\n *\n * @param transaction - The transaction params to estimate gas for.\n * @param multiplier - The multiplier to use for the gas buffer.\n * @param networkClientId - The network client id to use for the estimate.\n * @returns The buffered estimated gas and whether the estimation failed.\n */\nexport type TransactionControllerEstimateGasBufferedAction = {\n type: `TransactionController:estimateGasBuffered`;\n handler: TransactionController['estimateGasBuffered'];\n};\n\n/**\n * Updates an existing transaction in state.\n *\n * @param transactionMeta - The new transaction to store in state.\n * @param note - A note or update reason to be logged.\n */\nexport type TransactionControllerUpdateTransactionAction = {\n type: `TransactionController:updateTransaction`;\n handler: TransactionController['updateTransaction'];\n};\n\n/**\n * Adds external provided transaction to state as confirmed transaction.\n *\n * @param transactionMeta - TransactionMeta to add transactions.\n * @param transactionReceipt - TransactionReceipt of the external transaction.\n * @param baseFeePerGas - Base fee per gas of the external transaction.\n */\nexport type TransactionControllerConfirmExternalTransactionAction = {\n type: `TransactionController:confirmExternalTransaction`;\n handler: TransactionController['confirmExternalTransaction'];\n};\n\n/**\n * Acquires a nonce lock for the given address on the specified network,\n * ensuring that nonces are assigned sequentially without conflicts.\n *\n * @param address - The account address for which to acquire the nonce lock.\n * @param networkClientId - The ID of the network client to use.\n * @returns A promise that resolves to a nonce lock containing the next nonce and a release function.\n */\nexport type TransactionControllerGetNonceLockAction = {\n type: `TransactionController:getNonceLock`;\n handler: TransactionController['getNonceLock'];\n};\n\n/**\n * Updates the editable parameters of a transaction.\n *\n * @param txId - The ID of the transaction to update.\n * @param params - The editable parameters to update.\n * @param params.containerTypes - Container types applied to the parameters.\n * @param params.data - Data to pass with the transaction.\n * @param params.from - Address to send the transaction from.\n * @param params.gas - Maximum number of units of gas to use for the transaction.\n * @param params.gasPrice - Price per gas for legacy transactions.\n * @param params.maxFeePerGas - Maximum amount per gas to pay for the transaction, including the priority fee.\n * @param params.maxPriorityFeePerGas - Maximum amount per gas to give to validator as incentive.\n * @param params.updateType - Whether to update the transaction type. Defaults to `true`.\n * @param params.to - Address to send the transaction to.\n * @param params.value - Value associated with the transaction.\n * @returns The updated transaction metadata.\n */\nexport type TransactionControllerUpdateEditableParamsAction = {\n type: `TransactionController:updateEditableParams`;\n handler: TransactionController['updateEditableParams'];\n};\n\n/**\n * Update the isActive state of a transaction.\n *\n * @param transactionId - The ID of the transaction to update.\n * @param isActive - The active state.\n */\nexport type TransactionControllerSetTransactionActiveAction = {\n type: `TransactionController:setTransactionActive`;\n handler: TransactionController['setTransactionActive'];\n};\n\n/**\n * Signs and returns the raw transaction data for provided transaction params list.\n *\n * @param listOfTxParams - The list of transaction params to approve.\n * @param opts - Options bag.\n * @param opts.hasNonce - Whether the transactions already have a nonce.\n * @returns The raw transactions.\n */\nexport type TransactionControllerApproveTransactionsWithSameNonceAction = {\n type: `TransactionController:approveTransactionsWithSameNonce`;\n handler: TransactionController['approveTransactionsWithSameNonce'];\n};\n\n/**\n * Update a custodial transaction.\n *\n * @param request - The custodial transaction update request.\n *\n * @returns The updated transaction metadata.\n */\nexport type TransactionControllerUpdateCustodialTransactionAction = {\n type: `TransactionController:updateCustodialTransaction`;\n handler: TransactionController['updateCustodialTransaction'];\n};\n\n/**\n * Search transaction metadata for matching entries.\n *\n * @param opts - Options bag.\n * @param opts.initialList - The transactions to search. Defaults to the current state.\n * @param opts.limit - The maximum number of transactions to return. No limit by default.\n * @param opts.searchCriteria - An object containing values or functions for transaction properties to filter transactions with.\n * @returns An array of transactions matching the provided options.\n */\nexport type TransactionControllerGetTransactionsAction = {\n type: `TransactionController:getTransactions`;\n handler: TransactionController['getTransactions'];\n};\n\n/**\n * Estimates the gas fees for a transaction.\n *\n * @param args - The arguments for estimating gas fees.\n * @param args.transactionParams - The transaction parameters to estimate fees for.\n * @param args.chainId - The chain ID to use. If not provided, the network client ID is used to determine the chain.\n * @param args.networkClientId - The network client ID to use for the estimation.\n * @returns A promise that resolves to the estimated gas fee response.\n */\nexport type TransactionControllerEstimateGasFeeAction = {\n type: `TransactionController:estimateGasFee`;\n handler: TransactionController['estimateGasFee'];\n};\n\n/**\n * Determine the layer 1 gas fee for the given transaction parameters.\n *\n * @param request - The request object.\n * @param request.transactionParams - The transaction parameters to estimate the layer 1 gas fee for.\n * @param request.chainId - The ID of the chain where the transaction will be executed.\n * @param request.networkClientId - The ID of a specific network client to process the transaction.\n * @returns The layer 1 gas fee.\n */\nexport type TransactionControllerGetLayer1GasFeeAction = {\n type: `TransactionController:getLayer1GasFee`;\n handler: TransactionController['getLayer1GasFee'];\n};\n\n/**\n * Removes unapproved transactions from state.\n */\nexport type TransactionControllerClearUnapprovedTransactionsAction = {\n type: `TransactionController:clearUnapprovedTransactions`;\n handler: TransactionController['clearUnapprovedTransactions'];\n};\n\n/**\n * Stop the signing process for a specific transaction.\n * Throws an error causing the transaction status to be set to failed.\n *\n * @param transactionId - The ID of the transaction to stop signing.\n */\nexport type TransactionControllerAbortTransactionSigningAction = {\n type: `TransactionController:abortTransactionSigning`;\n handler: TransactionController['abortTransactionSigning'];\n};\n\n/**\n * Update the transaction data of a single nested transaction within an atomic batch transaction.\n *\n * @param options - The options bag.\n * @param options.transactionId - ID of the atomic batch transaction.\n * @param options.transactionIndex - Index of the nested transaction within the atomic batch transaction.\n * @param options.transactionData - New data to set for the nested transaction.\n * @returns The updated data for the atomic batch transaction.\n */\nexport type TransactionControllerUpdateAtomicBatchDataAction = {\n type: `TransactionController:updateAtomicBatchData`;\n handler: TransactionController['updateAtomicBatchData'];\n};\n\n/**\n * Emulate a new transaction.\n *\n * @param transactionId - The transaction ID.\n */\nexport type TransactionControllerEmulateNewTransactionAction = {\n type: `TransactionController:emulateNewTransaction`;\n handler: TransactionController['emulateNewTransaction'];\n};\n\n/**\n * Emulate a transaction update.\n *\n * @param transactionMeta - Transaction metadata.\n */\nexport type TransactionControllerEmulateTransactionUpdateAction = {\n type: `TransactionController:emulateTransactionUpdate`;\n handler: TransactionController['emulateTransactionUpdate'];\n};\n\n/**\n * Retrieve available gas fee tokens for a transaction.\n *\n * @param request - The request object containing transaction details.\n * @returns The list of available gas fee tokens.\n */\nexport type TransactionControllerGetGasFeeTokensAction = {\n type: `TransactionController:getGasFeeTokens`;\n handler: TransactionController['getGasFeeTokens'];\n};\n\n/**\n * Union of all TransactionController action types.\n */\nexport type TransactionControllerMethodActions =\n | TransactionControllerHandleMethodDataAction\n | TransactionControllerAddTransactionBatchAction\n | TransactionControllerIsAtomicBatchSupportedAction\n | TransactionControllerAddTransactionAction\n | TransactionControllerStartIncomingTransactionPollingAction\n | TransactionControllerStopIncomingTransactionPollingAction\n | TransactionControllerUpdateIncomingTransactionsAction\n | TransactionControllerStopTransactionAction\n | TransactionControllerSpeedUpTransactionAction\n | TransactionControllerEstimateGasAction\n | TransactionControllerEstimateGasBatchAction\n | TransactionControllerEstimateGasBufferedAction\n | TransactionControllerUpdateTransactionAction\n | TransactionControllerConfirmExternalTransactionAction\n | TransactionControllerGetNonceLockAction\n | TransactionControllerUpdateEditableParamsAction\n | TransactionControllerSetTransactionActiveAction\n | TransactionControllerApproveTransactionsWithSameNonceAction\n | TransactionControllerUpdateCustodialTransactionAction\n | TransactionControllerGetTransactionsAction\n | TransactionControllerEstimateGasFeeAction\n | TransactionControllerGetLayer1GasFeeAction\n | TransactionControllerClearUnapprovedTransactionsAction\n | TransactionControllerAbortTransactionSigningAction\n | TransactionControllerUpdateAtomicBatchDataAction\n | TransactionControllerEmulateNewTransactionAction\n | TransactionControllerEmulateTransactionUpdateAction\n | TransactionControllerGetGasFeeTokensAction;\n"]}
|
|
1
|
+
{"version":3,"file":"TransactionController-method-action-types.cjs","sourceRoot":"","sources":["../src/TransactionController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { TransactionController } from './TransactionController';\n\n/**\n * Handle new method data request.\n *\n * @param fourBytePrefix - The method prefix.\n * @param networkClientId - The ID of the network client used to fetch the method data.\n * @returns The method data object corresponding to the given signature prefix.\n */\nexport type TransactionControllerHandleMethodDataAction = {\n type: `TransactionController:handleMethodData`;\n handler: TransactionController['handleMethodData'];\n};\n\n/**\n * Add a batch of transactions to be submitted after approval.\n *\n * @param request - Request object containing the transactions to add.\n * @returns Result object containing the generated batch ID.\n */\nexport type TransactionControllerAddTransactionBatchAction = {\n type: `TransactionController:addTransactionBatch`;\n handler: TransactionController['addTransactionBatch'];\n};\n\n/**\n * Determine which chains support atomic batch transactions with the given account address.\n *\n * @param request - Request object containing the account address and other parameters.\n * @returns Result object containing the supported chains and related information.\n */\nexport type TransactionControllerIsAtomicBatchSupportedAction = {\n type: `TransactionController:isAtomicBatchSupported`;\n handler: TransactionController['isAtomicBatchSupported'];\n};\n\n/**\n * Add a new unapproved transaction to state. Parameters will be validated, a\n * unique transaction ID will be generated, and `gas` and `gasPrice` will be calculated\n * if not provided. A `<tx.id>:unapproved` hub event will be emitted once added.\n *\n * @param txParams - Standard parameters for an Ethereum transaction.\n * @param options - Additional options to control how the transaction is added.\n * @returns Object containing a promise resolving to the transaction hash if approved.\n */\nexport type TransactionControllerAddTransactionAction = {\n type: `TransactionController:addTransaction`;\n handler: TransactionController['addTransaction'];\n};\n\n/**\n * Starts polling for incoming transactions from the remote transaction source.\n */\nexport type TransactionControllerStartIncomingTransactionPollingAction = {\n type: `TransactionController:startIncomingTransactionPolling`;\n handler: TransactionController['startIncomingTransactionPolling'];\n};\n\n/**\n * Stops polling for incoming transactions from the remote transaction source.\n */\nexport type TransactionControllerStopIncomingTransactionPollingAction = {\n type: `TransactionController:stopIncomingTransactionPolling`;\n handler: TransactionController['stopIncomingTransactionPolling'];\n};\n\n/**\n * Update the incoming transactions by polling the remote transaction source.\n *\n * @param request - Request object.\n * @param request.tags - Additional tags to identify the source of the request.\n */\nexport type TransactionControllerUpdateIncomingTransactionsAction = {\n type: `TransactionController:updateIncomingTransactions`;\n handler: TransactionController['updateIncomingTransactions'];\n};\n\n/**\n * Attempts to cancel a transaction based on its ID by setting its status to \"rejected\"\n * and emitting a `<tx.id>:finished` hub event.\n *\n * @param transactionId - The ID of the transaction to cancel.\n * @param gasValues - The gas values to use for the cancellation transaction.\n * @param options - The options for the cancellation transaction.\n * @param options.actionId - Unique ID persisted on transaction metadata.\n * @param options.estimatedBaseFee - The estimated base fee of the transaction.\n */\nexport type TransactionControllerStopTransactionAction = {\n type: `TransactionController:stopTransaction`;\n handler: TransactionController['stopTransaction'];\n};\n\n/**\n * Attempts to speed up a transaction increasing transaction gasPrice by ten percent.\n *\n * @param transactionId - The ID of the transaction to speed up.\n * @param gasValues - The gas values to use for the speed up transaction.\n * @param options - The options for the speed up transaction.\n * @param options.actionId - Unique ID persisted on transaction metadata.\n * @param options.estimatedBaseFee - The estimated base fee of the transaction.\n */\nexport type TransactionControllerSpeedUpTransactionAction = {\n type: `TransactionController:speedUpTransaction`;\n handler: TransactionController['speedUpTransaction'];\n};\n\n/**\n * Estimates required gas for a given transaction.\n *\n * @param transaction - The transaction to estimate gas for.\n * @param networkClientId - The network client id to use for the estimate.\n * @param options - Additional options for the estimate.\n * @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager.\n * @returns The gas and gas price.\n */\nexport type TransactionControllerEstimateGasAction = {\n type: `TransactionController:estimateGas`;\n handler: TransactionController['estimateGas'];\n};\n\n/**\n * Estimates required gas for a batch of transactions.\n *\n * @param request - Request object.\n * @param request.chainId - Chain ID of the transactions.\n * @param request.from - Address of the sender.\n * @param request.transactions - Array of transactions within a batch request.\n * @returns Object containing the gas limit.\n */\nexport type TransactionControllerEstimateGasBatchAction = {\n type: `TransactionController:estimateGasBatch`;\n handler: TransactionController['estimateGasBatch'];\n};\n\n/**\n * Estimates required gas for a given transaction and add additional gas buffer with the given multiplier.\n *\n * @param transaction - The transaction params to estimate gas for.\n * @param multiplier - The multiplier to use for the gas buffer.\n * @param networkClientId - The network client id to use for the estimate.\n * @returns The buffered estimated gas and whether the estimation failed.\n */\nexport type TransactionControllerEstimateGasBufferedAction = {\n type: `TransactionController:estimateGasBuffered`;\n handler: TransactionController['estimateGasBuffered'];\n};\n\n/**\n * Updates an existing transaction in state.\n *\n * @param transactionMeta - The new transaction to store in state.\n * @param note - A note or update reason to be logged.\n */\nexport type TransactionControllerUpdateTransactionAction = {\n type: `TransactionController:updateTransaction`;\n handler: TransactionController['updateTransaction'];\n};\n\n/**\n * Adds external provided transaction to state as confirmed transaction.\n *\n * @param transactionMeta - TransactionMeta to add transactions.\n * @param transactionReceipt - TransactionReceipt of the external transaction.\n * @param baseFeePerGas - Base fee per gas of the external transaction.\n */\nexport type TransactionControllerConfirmExternalTransactionAction = {\n type: `TransactionController:confirmExternalTransaction`;\n handler: TransactionController['confirmExternalTransaction'];\n};\n\n/**\n * Acquires a nonce lock for the given address on the specified network,\n * ensuring that nonces are assigned sequentially without conflicts.\n *\n * @param address - The account address for which to acquire the nonce lock.\n * @param networkClientId - The ID of the network client to use.\n * @returns A promise that resolves to a nonce lock containing the next nonce and a release function.\n */\nexport type TransactionControllerGetNonceLockAction = {\n type: `TransactionController:getNonceLock`;\n handler: TransactionController['getNonceLock'];\n};\n\n/**\n * Updates the editable parameters of a transaction.\n *\n * @param txId - The ID of the transaction to update.\n * @param params - The editable parameters to update.\n * @param params.containerTypes - Container types applied to the parameters.\n * @param params.data - Data to pass with the transaction.\n * @param params.from - Address to send the transaction from.\n * @param params.gas - Maximum number of units of gas to use for the transaction.\n * @param params.gasPrice - Price per gas for legacy transactions.\n * @param params.maxFeePerGas - Maximum amount per gas to pay for the transaction, including the priority fee.\n * @param params.maxPriorityFeePerGas - Maximum amount per gas to give to validator as incentive.\n * @param params.updateType - Whether to update the transaction type. Defaults to `true`.\n * @param params.to - Address to send the transaction to.\n * @param params.value - Value associated with the transaction.\n * @returns The updated transaction metadata.\n */\nexport type TransactionControllerUpdateEditableParamsAction = {\n type: `TransactionController:updateEditableParams`;\n handler: TransactionController['updateEditableParams'];\n};\n\n/**\n * Update the isActive state of a transaction.\n *\n * @param transactionId - The ID of the transaction to update.\n * @param isActive - The active state.\n */\nexport type TransactionControllerSetTransactionActiveAction = {\n type: `TransactionController:setTransactionActive`;\n handler: TransactionController['setTransactionActive'];\n};\n\n/**\n * Signs and returns the raw transaction data for provided transaction params list.\n *\n * @param listOfTxParams - The list of transaction params to approve.\n * @param opts - Options bag.\n * @param opts.hasNonce - Whether the transactions already have a nonce.\n * @returns The raw transactions.\n */\nexport type TransactionControllerApproveTransactionsWithSameNonceAction = {\n type: `TransactionController:approveTransactionsWithSameNonce`;\n handler: TransactionController['approveTransactionsWithSameNonce'];\n};\n\n/**\n * Update a custodial transaction.\n *\n * @param request - The custodial transaction update request.\n *\n * @returns The updated transaction metadata.\n */\nexport type TransactionControllerUpdateCustodialTransactionAction = {\n type: `TransactionController:updateCustodialTransaction`;\n handler: TransactionController['updateCustodialTransaction'];\n};\n\n/**\n * Search transaction metadata for matching entries.\n *\n * @param opts - Options bag.\n * @param opts.initialList - The transactions to search. Defaults to the current state.\n * @param opts.limit - The maximum number of transactions to return. No limit by default.\n * @param opts.searchCriteria - An object containing values or functions for transaction properties to filter transactions with.\n * @returns An array of transactions matching the provided options.\n */\nexport type TransactionControllerGetTransactionsAction = {\n type: `TransactionController:getTransactions`;\n handler: TransactionController['getTransactions'];\n};\n\n/**\n * Estimates the gas fees for a transaction.\n *\n * @param args - The arguments for estimating gas fees.\n * @param args.transactionParams - The transaction parameters to estimate fees for.\n * @param args.chainId - The chain ID to use. If not provided, the network client ID is used to determine the chain.\n * @param args.networkClientId - The network client ID to use for the estimation.\n * @returns A promise that resolves to the estimated gas fee response.\n */\nexport type TransactionControllerEstimateGasFeeAction = {\n type: `TransactionController:estimateGasFee`;\n handler: TransactionController['estimateGasFee'];\n};\n\n/**\n * Determine the layer 1 gas fee for the given transaction parameters.\n *\n * @param request - The request object.\n * @param request.transactionParams - The transaction parameters to estimate the layer 1 gas fee for.\n * @param request.chainId - The ID of the chain where the transaction will be executed.\n * @param request.networkClientId - The ID of a specific network client to process the transaction.\n * @returns The layer 1 gas fee.\n */\nexport type TransactionControllerGetLayer1GasFeeAction = {\n type: `TransactionController:getLayer1GasFee`;\n handler: TransactionController['getLayer1GasFee'];\n};\n\n/**\n * Removes unapproved transactions from state.\n */\nexport type TransactionControllerClearUnapprovedTransactionsAction = {\n type: `TransactionController:clearUnapprovedTransactions`;\n handler: TransactionController['clearUnapprovedTransactions'];\n};\n\n/**\n * Stop the signing process for a specific transaction.\n * Throws an error causing the transaction status to be set to failed.\n *\n * @param transactionId - The ID of the transaction to stop signing.\n */\nexport type TransactionControllerAbortTransactionSigningAction = {\n type: `TransactionController:abortTransactionSigning`;\n handler: TransactionController['abortTransactionSigning'];\n};\n\n/**\n * Update the transaction data of a single nested transaction within an atomic batch transaction.\n *\n * @param options - The options bag.\n * @param options.transactionId - ID of the atomic batch transaction.\n * @param options.transactionIndex - Index of the nested transaction within the atomic batch transaction.\n * @param options.transactionData - New data to set for the nested transaction.\n * @returns The updated data for the atomic batch transaction.\n */\nexport type TransactionControllerUpdateAtomicBatchDataAction = {\n type: `TransactionController:updateAtomicBatchData`;\n handler: TransactionController['updateAtomicBatchData'];\n};\n\n/**\n * Emulate a new transaction.\n *\n * @param transactionId - The transaction ID.\n */\nexport type TransactionControllerEmulateNewTransactionAction = {\n type: `TransactionController:emulateNewTransaction`;\n handler: TransactionController['emulateNewTransaction'];\n};\n\n/**\n * Emulate a transaction update.\n *\n * @param transactionMeta - Transaction metadata.\n */\nexport type TransactionControllerEmulateTransactionUpdateAction = {\n type: `TransactionController:emulateTransactionUpdate`;\n handler: TransactionController['emulateTransactionUpdate'];\n};\n\n/**\n * Retrieve available gas fee tokens for a transaction.\n *\n * @param request - The request object containing transaction details.\n * @returns The list of available gas fee tokens.\n */\nexport type TransactionControllerGetGasFeeTokensAction = {\n type: `TransactionController:getGasFeeTokens`;\n handler: TransactionController['getGasFeeTokens'];\n};\n\n/**\n * Union of all TransactionController action types.\n */\nexport type TransactionControllerMethodActions =\n | TransactionControllerHandleMethodDataAction\n | TransactionControllerAddTransactionBatchAction\n | TransactionControllerIsAtomicBatchSupportedAction\n | TransactionControllerAddTransactionAction\n | TransactionControllerStartIncomingTransactionPollingAction\n | TransactionControllerStopIncomingTransactionPollingAction\n | TransactionControllerUpdateIncomingTransactionsAction\n | TransactionControllerStopTransactionAction\n | TransactionControllerSpeedUpTransactionAction\n | TransactionControllerEstimateGasAction\n | TransactionControllerEstimateGasBatchAction\n | TransactionControllerEstimateGasBufferedAction\n | TransactionControllerUpdateTransactionAction\n | TransactionControllerConfirmExternalTransactionAction\n | TransactionControllerGetNonceLockAction\n | TransactionControllerUpdateEditableParamsAction\n | TransactionControllerSetTransactionActiveAction\n | TransactionControllerApproveTransactionsWithSameNonceAction\n | TransactionControllerUpdateCustodialTransactionAction\n | TransactionControllerGetTransactionsAction\n | TransactionControllerEstimateGasFeeAction\n | TransactionControllerGetLayer1GasFeeAction\n | TransactionControllerClearUnapprovedTransactionsAction\n | TransactionControllerAbortTransactionSigningAction\n | TransactionControllerUpdateAtomicBatchDataAction\n | TransactionControllerEmulateNewTransactionAction\n | TransactionControllerEmulateTransactionUpdateAction\n | TransactionControllerGetGasFeeTokensAction;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionController-method-action-types.mjs","sourceRoot":"","sources":["../src/TransactionController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { TransactionController } from './TransactionController';\n\n/**\n * Handle new method data request.\n *\n * @param fourBytePrefix - The method prefix.\n * @param networkClientId - The ID of the network client used to fetch the method data.\n * @returns The method data object corresponding to the given signature prefix.\n */\nexport type TransactionControllerHandleMethodDataAction = {\n type: `TransactionController:handleMethodData`;\n handler: TransactionController['handleMethodData'];\n};\n\n/**\n * Add a batch of transactions to be submitted after approval.\n *\n * @param request - Request object containing the transactions to add.\n * @returns Result object containing the generated batch ID.\n */\nexport type TransactionControllerAddTransactionBatchAction = {\n type: `TransactionController:addTransactionBatch`;\n handler: TransactionController['addTransactionBatch'];\n};\n\n/**\n * Determine which chains support atomic batch transactions with the given account address.\n *\n * @param request - Request object containing the account address and other parameters.\n * @returns Result object containing the supported chains and related information.\n */\nexport type TransactionControllerIsAtomicBatchSupportedAction = {\n type: `TransactionController:isAtomicBatchSupported`;\n handler: TransactionController['isAtomicBatchSupported'];\n};\n\n/**\n * Add a new unapproved transaction to state. Parameters will be validated, a\n * unique transaction ID will be generated, and `gas` and `gasPrice` will be calculated\n * if not provided. A `<tx.id>:unapproved` hub event will be emitted once added.\n *\n * @param txParams - Standard parameters for an Ethereum transaction.\n * @param options - Additional options to control how the transaction is added.\n * @returns Object containing a promise resolving to the transaction hash if approved.\n */\nexport type TransactionControllerAddTransactionAction = {\n type: `TransactionController:addTransaction`;\n handler: TransactionController['addTransaction'];\n};\n\n/**\n * Starts polling for incoming transactions from the remote transaction source.\n */\nexport type TransactionControllerStartIncomingTransactionPollingAction = {\n type: `TransactionController:startIncomingTransactionPolling`;\n handler: TransactionController['startIncomingTransactionPolling'];\n};\n\n/**\n * Stops polling for incoming transactions from the remote transaction source.\n */\nexport type TransactionControllerStopIncomingTransactionPollingAction = {\n type: `TransactionController:stopIncomingTransactionPolling`;\n handler: TransactionController['stopIncomingTransactionPolling'];\n};\n\n/**\n * Update the incoming transactions by polling the remote transaction source.\n *\n * @param request - Request object.\n * @param request.tags - Additional tags to identify the source of the request.\n */\nexport type TransactionControllerUpdateIncomingTransactionsAction = {\n type: `TransactionController:updateIncomingTransactions`;\n handler: TransactionController['updateIncomingTransactions'];\n};\n\n/**\n * Attempts to cancel a transaction based on its ID by setting its status to \"rejected\"\n * and emitting a `<tx.id>:finished` hub event.\n *\n * @param transactionId - The ID of the transaction to cancel.\n * @param gasValues - The gas values to use for the cancellation transaction.\n * @param options - The options for the cancellation transaction.\n * @param options.actionId - Unique ID persisted on transaction metadata.\n * @param options.estimatedBaseFee - The estimated base fee of the transaction.\n */\nexport type TransactionControllerStopTransactionAction = {\n type: `TransactionController:stopTransaction`;\n handler: TransactionController['stopTransaction'];\n};\n\n/**\n * Attempts to speed up a transaction increasing transaction gasPrice by ten percent.\n *\n * @param transactionId - The ID of the transaction to speed up.\n * @param gasValues - The gas values to use for the speed up transaction.\n * @param options - The options for the speed up transaction.\n * @param options.actionId - Unique ID persisted on transaction metadata.\n * @param options.estimatedBaseFee - The estimated base fee of the transaction.\n */\nexport type TransactionControllerSpeedUpTransactionAction = {\n type: `TransactionController:speedUpTransaction`;\n handler: TransactionController['speedUpTransaction'];\n};\n\n/**\n * Estimates required gas for a given transaction.\n *\n * @param transaction - The transaction to estimate gas for.\n * @param networkClientId - The network client id to use for the estimate.\n * @param options - Additional options for the estimate.\n * @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager.\n * @returns The gas and gas price.\n */\nexport type TransactionControllerEstimateGasAction = {\n type: `TransactionController:estimateGas`;\n handler: TransactionController['estimateGas'];\n};\n\n/**\n * Estimates required gas for a batch of transactions.\n *\n * @param request - Request object.\n * @param request.chainId - Chain ID of the transactions.\n * @param request.from - Address of the sender.\n * @param request.transactions - Array of transactions within a batch request.\n * @returns Object containing the gas limit.\n */\nexport type TransactionControllerEstimateGasBatchAction = {\n type: `TransactionController:estimateGasBatch`;\n handler: TransactionController['estimateGasBatch'];\n};\n\n/**\n * Estimates required gas for a given transaction and add additional gas buffer with the given multiplier.\n *\n * @param transaction - The transaction params to estimate gas for.\n * @param multiplier - The multiplier to use for the gas buffer.\n * @param networkClientId - The network client id to use for the estimate.\n * @returns The buffered estimated gas and whether the estimation failed.\n */\nexport type TransactionControllerEstimateGasBufferedAction = {\n type: `TransactionController:estimateGasBuffered`;\n handler: TransactionController['estimateGasBuffered'];\n};\n\n/**\n * Updates an existing transaction in state.\n *\n * @param transactionMeta - The new transaction to store in state.\n * @param note - A note or update reason to be logged.\n */\nexport type TransactionControllerUpdateTransactionAction = {\n type: `TransactionController:updateTransaction`;\n handler: TransactionController['updateTransaction'];\n};\n\n/**\n * Adds external provided transaction to state as confirmed transaction.\n *\n * @param transactionMeta - TransactionMeta to add transactions.\n * @param transactionReceipt - TransactionReceipt of the external transaction.\n * @param baseFeePerGas - Base fee per gas of the external transaction.\n */\nexport type TransactionControllerConfirmExternalTransactionAction = {\n type: `TransactionController:confirmExternalTransaction`;\n handler: TransactionController['confirmExternalTransaction'];\n};\n\n/**\n * Acquires a nonce lock for the given address on the specified network,\n * ensuring that nonces are assigned sequentially without conflicts.\n *\n * @param address - The account address for which to acquire the nonce lock.\n * @param networkClientId - The ID of the network client to use.\n * @returns A promise that resolves to a nonce lock containing the next nonce and a release function.\n */\nexport type TransactionControllerGetNonceLockAction = {\n type: `TransactionController:getNonceLock`;\n handler: TransactionController['getNonceLock'];\n};\n\n/**\n * Updates the editable parameters of a transaction.\n *\n * @param txId - The ID of the transaction to update.\n * @param params - The editable parameters to update.\n * @param params.containerTypes - Container types applied to the parameters.\n * @param params.data - Data to pass with the transaction.\n * @param params.from - Address to send the transaction from.\n * @param params.gas - Maximum number of units of gas to use for the transaction.\n * @param params.gasPrice - Price per gas for legacy transactions.\n * @param params.maxFeePerGas - Maximum amount per gas to pay for the transaction, including the priority fee.\n * @param params.maxPriorityFeePerGas - Maximum amount per gas to give to validator as incentive.\n * @param params.updateType - Whether to update the transaction type. Defaults to `true`.\n * @param params.to - Address to send the transaction to.\n * @param params.value - Value associated with the transaction.\n * @returns The updated transaction metadata.\n */\nexport type TransactionControllerUpdateEditableParamsAction = {\n type: `TransactionController:updateEditableParams`;\n handler: TransactionController['updateEditableParams'];\n};\n\n/**\n * Update the isActive state of a transaction.\n *\n * @param transactionId - The ID of the transaction to update.\n * @param isActive - The active state.\n */\nexport type TransactionControllerSetTransactionActiveAction = {\n type: `TransactionController:setTransactionActive`;\n handler: TransactionController['setTransactionActive'];\n};\n\n/**\n * Signs and returns the raw transaction data for provided transaction params list.\n *\n * @param listOfTxParams - The list of transaction params to approve.\n * @param opts - Options bag.\n * @param opts.hasNonce - Whether the transactions already have a nonce.\n * @returns The raw transactions.\n */\nexport type TransactionControllerApproveTransactionsWithSameNonceAction = {\n type: `TransactionController:approveTransactionsWithSameNonce`;\n handler: TransactionController['approveTransactionsWithSameNonce'];\n};\n\n/**\n * Update a custodial transaction.\n *\n * @param request - The custodial transaction update request.\n *\n * @returns The updated transaction metadata.\n */\nexport type TransactionControllerUpdateCustodialTransactionAction = {\n type: `TransactionController:updateCustodialTransaction`;\n handler: TransactionController['updateCustodialTransaction'];\n};\n\n/**\n * Search transaction metadata for matching entries.\n *\n * @param opts - Options bag.\n * @param opts.initialList - The transactions to search. Defaults to the current state.\n * @param opts.limit - The maximum number of transactions to return. No limit by default.\n * @param opts.searchCriteria - An object containing values or functions for transaction properties to filter transactions with.\n * @returns An array of transactions matching the provided options.\n */\nexport type TransactionControllerGetTransactionsAction = {\n type: `TransactionController:getTransactions`;\n handler: TransactionController['getTransactions'];\n};\n\n/**\n * Estimates the gas fees for a transaction.\n *\n * @param args - The arguments for estimating gas fees.\n * @param args.transactionParams - The transaction parameters to estimate fees for.\n * @param args.chainId - The chain ID to use. If not provided, the network client ID is used to determine the chain.\n * @param args.networkClientId - The network client ID to use for the estimation.\n * @returns A promise that resolves to the estimated gas fee response.\n */\nexport type TransactionControllerEstimateGasFeeAction = {\n type: `TransactionController:estimateGasFee`;\n handler: TransactionController['estimateGasFee'];\n};\n\n/**\n * Determine the layer 1 gas fee for the given transaction parameters.\n *\n * @param request - The request object.\n * @param request.transactionParams - The transaction parameters to estimate the layer 1 gas fee for.\n * @param request.chainId - The ID of the chain where the transaction will be executed.\n * @param request.networkClientId - The ID of a specific network client to process the transaction.\n * @returns The layer 1 gas fee.\n */\nexport type TransactionControllerGetLayer1GasFeeAction = {\n type: `TransactionController:getLayer1GasFee`;\n handler: TransactionController['getLayer1GasFee'];\n};\n\n/**\n * Removes unapproved transactions from state.\n */\nexport type TransactionControllerClearUnapprovedTransactionsAction = {\n type: `TransactionController:clearUnapprovedTransactions`;\n handler: TransactionController['clearUnapprovedTransactions'];\n};\n\n/**\n * Stop the signing process for a specific transaction.\n * Throws an error causing the transaction status to be set to failed.\n *\n * @param transactionId - The ID of the transaction to stop signing.\n */\nexport type TransactionControllerAbortTransactionSigningAction = {\n type: `TransactionController:abortTransactionSigning`;\n handler: TransactionController['abortTransactionSigning'];\n};\n\n/**\n * Update the transaction data of a single nested transaction within an atomic batch transaction.\n *\n * @param options - The options bag.\n * @param options.transactionId - ID of the atomic batch transaction.\n * @param options.transactionIndex - Index of the nested transaction within the atomic batch transaction.\n * @param options.transactionData - New data to set for the nested transaction.\n * @returns The updated data for the atomic batch transaction.\n */\nexport type TransactionControllerUpdateAtomicBatchDataAction = {\n type: `TransactionController:updateAtomicBatchData`;\n handler: TransactionController['updateAtomicBatchData'];\n};\n\n/**\n * Emulate a new transaction.\n *\n * @param transactionId - The transaction ID.\n */\nexport type TransactionControllerEmulateNewTransactionAction = {\n type: `TransactionController:emulateNewTransaction`;\n handler: TransactionController['emulateNewTransaction'];\n};\n\n/**\n * Emulate a transaction update.\n *\n * @param transactionMeta - Transaction metadata.\n */\nexport type TransactionControllerEmulateTransactionUpdateAction = {\n type: `TransactionController:emulateTransactionUpdate`;\n handler: TransactionController['emulateTransactionUpdate'];\n};\n\n/**\n * Retrieve available gas fee tokens for a transaction.\n *\n * @param request - The request object containing transaction details.\n * @returns The list of available gas fee tokens.\n */\nexport type TransactionControllerGetGasFeeTokensAction = {\n type: `TransactionController:getGasFeeTokens`;\n handler: TransactionController['getGasFeeTokens'];\n};\n\n/**\n * Union of all TransactionController action types.\n */\nexport type TransactionControllerMethodActions =\n | TransactionControllerHandleMethodDataAction\n | TransactionControllerAddTransactionBatchAction\n | TransactionControllerIsAtomicBatchSupportedAction\n | TransactionControllerAddTransactionAction\n | TransactionControllerStartIncomingTransactionPollingAction\n | TransactionControllerStopIncomingTransactionPollingAction\n | TransactionControllerUpdateIncomingTransactionsAction\n | TransactionControllerStopTransactionAction\n | TransactionControllerSpeedUpTransactionAction\n | TransactionControllerEstimateGasAction\n | TransactionControllerEstimateGasBatchAction\n | TransactionControllerEstimateGasBufferedAction\n | TransactionControllerUpdateTransactionAction\n | TransactionControllerConfirmExternalTransactionAction\n | TransactionControllerGetNonceLockAction\n | TransactionControllerUpdateEditableParamsAction\n | TransactionControllerSetTransactionActiveAction\n | TransactionControllerApproveTransactionsWithSameNonceAction\n | TransactionControllerUpdateCustodialTransactionAction\n | TransactionControllerGetTransactionsAction\n | TransactionControllerEstimateGasFeeAction\n | TransactionControllerGetLayer1GasFeeAction\n | TransactionControllerClearUnapprovedTransactionsAction\n | TransactionControllerAbortTransactionSigningAction\n | TransactionControllerUpdateAtomicBatchDataAction\n | TransactionControllerEmulateNewTransactionAction\n | TransactionControllerEmulateTransactionUpdateAction\n | TransactionControllerGetGasFeeTokensAction;\n"]}
|
|
1
|
+
{"version":3,"file":"TransactionController-method-action-types.mjs","sourceRoot":"","sources":["../src/TransactionController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { TransactionController } from './TransactionController';\n\n/**\n * Handle new method data request.\n *\n * @param fourBytePrefix - The method prefix.\n * @param networkClientId - The ID of the network client used to fetch the method data.\n * @returns The method data object corresponding to the given signature prefix.\n */\nexport type TransactionControllerHandleMethodDataAction = {\n type: `TransactionController:handleMethodData`;\n handler: TransactionController['handleMethodData'];\n};\n\n/**\n * Add a batch of transactions to be submitted after approval.\n *\n * @param request - Request object containing the transactions to add.\n * @returns Result object containing the generated batch ID.\n */\nexport type TransactionControllerAddTransactionBatchAction = {\n type: `TransactionController:addTransactionBatch`;\n handler: TransactionController['addTransactionBatch'];\n};\n\n/**\n * Determine which chains support atomic batch transactions with the given account address.\n *\n * @param request - Request object containing the account address and other parameters.\n * @returns Result object containing the supported chains and related information.\n */\nexport type TransactionControllerIsAtomicBatchSupportedAction = {\n type: `TransactionController:isAtomicBatchSupported`;\n handler: TransactionController['isAtomicBatchSupported'];\n};\n\n/**\n * Add a new unapproved transaction to state. Parameters will be validated, a\n * unique transaction ID will be generated, and `gas` and `gasPrice` will be calculated\n * if not provided. A `<tx.id>:unapproved` hub event will be emitted once added.\n *\n * @param txParams - Standard parameters for an Ethereum transaction.\n * @param options - Additional options to control how the transaction is added.\n * @returns Object containing a promise resolving to the transaction hash if approved.\n */\nexport type TransactionControllerAddTransactionAction = {\n type: `TransactionController:addTransaction`;\n handler: TransactionController['addTransaction'];\n};\n\n/**\n * Starts polling for incoming transactions from the remote transaction source.\n */\nexport type TransactionControllerStartIncomingTransactionPollingAction = {\n type: `TransactionController:startIncomingTransactionPolling`;\n handler: TransactionController['startIncomingTransactionPolling'];\n};\n\n/**\n * Stops polling for incoming transactions from the remote transaction source.\n */\nexport type TransactionControllerStopIncomingTransactionPollingAction = {\n type: `TransactionController:stopIncomingTransactionPolling`;\n handler: TransactionController['stopIncomingTransactionPolling'];\n};\n\n/**\n * Update the incoming transactions by polling the remote transaction source.\n *\n * @param request - Request object.\n * @param request.tags - Additional tags to identify the source of the request.\n */\nexport type TransactionControllerUpdateIncomingTransactionsAction = {\n type: `TransactionController:updateIncomingTransactions`;\n handler: TransactionController['updateIncomingTransactions'];\n};\n\n/**\n * Attempts to cancel a transaction based on its ID by setting its status to \"rejected\"\n * and emitting a `<tx.id>:finished` hub event.\n *\n * @param transactionId - The ID of the transaction to cancel.\n * @param gasValues - The gas values to use for the cancellation transaction.\n * @param options - The options for the cancellation transaction.\n * @param options.actionId - Unique ID persisted on transaction metadata.\n * @param options.estimatedBaseFee - The estimated base fee of the transaction.\n */\nexport type TransactionControllerStopTransactionAction = {\n type: `TransactionController:stopTransaction`;\n handler: TransactionController['stopTransaction'];\n};\n\n/**\n * Attempts to speed up a transaction increasing transaction gasPrice by ten percent.\n *\n * @param transactionId - The ID of the transaction to speed up.\n * @param gasValues - The gas values to use for the speed up transaction.\n * @param options - The options for the speed up transaction.\n * @param options.actionId - Unique ID persisted on transaction metadata.\n * @param options.estimatedBaseFee - The estimated base fee of the transaction.\n */\nexport type TransactionControllerSpeedUpTransactionAction = {\n type: `TransactionController:speedUpTransaction`;\n handler: TransactionController['speedUpTransaction'];\n};\n\n/**\n * Estimates required gas for a given transaction.\n *\n * @param transaction - The transaction to estimate gas for.\n * @param networkClientId - The network client id to use for the estimate.\n * @param options - Additional options for the estimate.\n * @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager.\n * @returns The gas and gas price.\n */\nexport type TransactionControllerEstimateGasAction = {\n type: `TransactionController:estimateGas`;\n handler: TransactionController['estimateGas'];\n};\n\n/**\n * Estimates required gas for a batch of transactions.\n *\n * @param request - Request object.\n * @param request.chainId - Chain ID of the transactions.\n * @param request.from - Address of the sender.\n * @param request.transactions - Array of transactions within a batch request.\n * @returns Object containing the gas limit.\n */\nexport type TransactionControllerEstimateGasBatchAction = {\n type: `TransactionController:estimateGasBatch`;\n handler: TransactionController['estimateGasBatch'];\n};\n\n/**\n * Estimates required gas for a given transaction and add additional gas buffer with the given multiplier.\n *\n * @param transaction - The transaction params to estimate gas for.\n * @param multiplier - The multiplier to use for the gas buffer.\n * @param networkClientId - The network client id to use for the estimate.\n * @returns The buffered estimated gas and whether the estimation failed.\n */\nexport type TransactionControllerEstimateGasBufferedAction = {\n type: `TransactionController:estimateGasBuffered`;\n handler: TransactionController['estimateGasBuffered'];\n};\n\n/**\n * Updates an existing transaction in state.\n *\n * @param transactionMeta - The new transaction to store in state.\n * @param note - A note or update reason to be logged.\n */\nexport type TransactionControllerUpdateTransactionAction = {\n type: `TransactionController:updateTransaction`;\n handler: TransactionController['updateTransaction'];\n};\n\n/**\n * Adds external provided transaction to state as confirmed transaction.\n *\n * @param transactionMeta - TransactionMeta to add transactions.\n * @param transactionReceipt - TransactionReceipt of the external transaction.\n * @param baseFeePerGas - Base fee per gas of the external transaction.\n */\nexport type TransactionControllerConfirmExternalTransactionAction = {\n type: `TransactionController:confirmExternalTransaction`;\n handler: TransactionController['confirmExternalTransaction'];\n};\n\n/**\n * Acquires a nonce lock for the given address on the specified network,\n * ensuring that nonces are assigned sequentially without conflicts.\n *\n * @param address - The account address for which to acquire the nonce lock.\n * @param networkClientId - The ID of the network client to use.\n * @returns A promise that resolves to a nonce lock containing the next nonce and a release function.\n */\nexport type TransactionControllerGetNonceLockAction = {\n type: `TransactionController:getNonceLock`;\n handler: TransactionController['getNonceLock'];\n};\n\n/**\n * Updates the editable parameters of a transaction.\n *\n * @param txId - The ID of the transaction to update.\n * @param params - The editable parameters to update.\n * @param params.containerTypes - Container types applied to the parameters.\n * @param params.data - Data to pass with the transaction.\n * @param params.from - Address to send the transaction from.\n * @param params.gas - Maximum number of units of gas to use for the transaction.\n * @param params.gasPrice - Price per gas for legacy transactions.\n * @param params.maxFeePerGas - Maximum amount per gas to pay for the transaction, including the priority fee.\n * @param params.maxPriorityFeePerGas - Maximum amount per gas to give to validator as incentive.\n * @param params.updateType - Whether to update the transaction type. Defaults to `true`.\n * @param params.to - Address to send the transaction to.\n * @param params.value - Value associated with the transaction.\n * @returns The updated transaction metadata.\n */\nexport type TransactionControllerUpdateEditableParamsAction = {\n type: `TransactionController:updateEditableParams`;\n handler: TransactionController['updateEditableParams'];\n};\n\n/**\n * Update the isActive state of a transaction.\n *\n * @param transactionId - The ID of the transaction to update.\n * @param isActive - The active state.\n */\nexport type TransactionControllerSetTransactionActiveAction = {\n type: `TransactionController:setTransactionActive`;\n handler: TransactionController['setTransactionActive'];\n};\n\n/**\n * Signs and returns the raw transaction data for provided transaction params list.\n *\n * @param listOfTxParams - The list of transaction params to approve.\n * @param opts - Options bag.\n * @param opts.hasNonce - Whether the transactions already have a nonce.\n * @returns The raw transactions.\n */\nexport type TransactionControllerApproveTransactionsWithSameNonceAction = {\n type: `TransactionController:approveTransactionsWithSameNonce`;\n handler: TransactionController['approveTransactionsWithSameNonce'];\n};\n\n/**\n * Update a custodial transaction.\n *\n * @param request - The custodial transaction update request.\n *\n * @returns The updated transaction metadata.\n */\nexport type TransactionControllerUpdateCustodialTransactionAction = {\n type: `TransactionController:updateCustodialTransaction`;\n handler: TransactionController['updateCustodialTransaction'];\n};\n\n/**\n * Search transaction metadata for matching entries.\n *\n * @param opts - Options bag.\n * @param opts.initialList - The transactions to search. Defaults to the current state.\n * @param opts.limit - The maximum number of transactions to return. No limit by default.\n * @param opts.searchCriteria - An object containing values or functions for transaction properties to filter transactions with.\n * @returns An array of transactions matching the provided options.\n */\nexport type TransactionControllerGetTransactionsAction = {\n type: `TransactionController:getTransactions`;\n handler: TransactionController['getTransactions'];\n};\n\n/**\n * Estimates the gas fees for a transaction.\n *\n * @param args - The arguments for estimating gas fees.\n * @param args.transactionParams - The transaction parameters to estimate fees for.\n * @param args.chainId - The chain ID to use. If not provided, the network client ID is used to determine the chain.\n * @param args.networkClientId - The network client ID to use for the estimation.\n * @returns A promise that resolves to the estimated gas fee response.\n */\nexport type TransactionControllerEstimateGasFeeAction = {\n type: `TransactionController:estimateGasFee`;\n handler: TransactionController['estimateGasFee'];\n};\n\n/**\n * Determine the layer 1 gas fee for the given transaction parameters.\n *\n * @param request - The request object.\n * @param request.transactionParams - The transaction parameters to estimate the layer 1 gas fee for.\n * @param request.chainId - The ID of the chain where the transaction will be executed.\n * @param request.networkClientId - The ID of a specific network client to process the transaction.\n * @returns The layer 1 gas fee.\n */\nexport type TransactionControllerGetLayer1GasFeeAction = {\n type: `TransactionController:getLayer1GasFee`;\n handler: TransactionController['getLayer1GasFee'];\n};\n\n/**\n * Removes unapproved transactions from state.\n */\nexport type TransactionControllerClearUnapprovedTransactionsAction = {\n type: `TransactionController:clearUnapprovedTransactions`;\n handler: TransactionController['clearUnapprovedTransactions'];\n};\n\n/**\n * Stop the signing process for a specific transaction.\n * Throws an error causing the transaction status to be set to failed.\n *\n * @param transactionId - The ID of the transaction to stop signing.\n */\nexport type TransactionControllerAbortTransactionSigningAction = {\n type: `TransactionController:abortTransactionSigning`;\n handler: TransactionController['abortTransactionSigning'];\n};\n\n/**\n * Update the transaction data of a single nested transaction within an atomic batch transaction.\n *\n * @param options - The options bag.\n * @param options.transactionId - ID of the atomic batch transaction.\n * @param options.transactionIndex - Index of the nested transaction within the atomic batch transaction.\n * @param options.transactionData - New data to set for the nested transaction.\n * @returns The updated data for the atomic batch transaction.\n */\nexport type TransactionControllerUpdateAtomicBatchDataAction = {\n type: `TransactionController:updateAtomicBatchData`;\n handler: TransactionController['updateAtomicBatchData'];\n};\n\n/**\n * Emulate a new transaction.\n *\n * @param transactionId - The transaction ID.\n */\nexport type TransactionControllerEmulateNewTransactionAction = {\n type: `TransactionController:emulateNewTransaction`;\n handler: TransactionController['emulateNewTransaction'];\n};\n\n/**\n * Emulate a transaction update.\n *\n * @param transactionMeta - Transaction metadata.\n */\nexport type TransactionControllerEmulateTransactionUpdateAction = {\n type: `TransactionController:emulateTransactionUpdate`;\n handler: TransactionController['emulateTransactionUpdate'];\n};\n\n/**\n * Retrieve available gas fee tokens for a transaction.\n *\n * @param request - The request object containing transaction details.\n * @returns The list of available gas fee tokens.\n */\nexport type TransactionControllerGetGasFeeTokensAction = {\n type: `TransactionController:getGasFeeTokens`;\n handler: TransactionController['getGasFeeTokens'];\n};\n\n/**\n * Union of all TransactionController action types.\n */\nexport type TransactionControllerMethodActions =\n | TransactionControllerHandleMethodDataAction\n | TransactionControllerAddTransactionBatchAction\n | TransactionControllerIsAtomicBatchSupportedAction\n | TransactionControllerAddTransactionAction\n | TransactionControllerStartIncomingTransactionPollingAction\n | TransactionControllerStopIncomingTransactionPollingAction\n | TransactionControllerUpdateIncomingTransactionsAction\n | TransactionControllerStopTransactionAction\n | TransactionControllerSpeedUpTransactionAction\n | TransactionControllerEstimateGasAction\n | TransactionControllerEstimateGasBatchAction\n | TransactionControllerEstimateGasBufferedAction\n | TransactionControllerUpdateTransactionAction\n | TransactionControllerConfirmExternalTransactionAction\n | TransactionControllerGetNonceLockAction\n | TransactionControllerUpdateEditableParamsAction\n | TransactionControllerSetTransactionActiveAction\n | TransactionControllerApproveTransactionsWithSameNonceAction\n | TransactionControllerUpdateCustodialTransactionAction\n | TransactionControllerGetTransactionsAction\n | TransactionControllerEstimateGasFeeAction\n | TransactionControllerGetLayer1GasFeeAction\n | TransactionControllerClearUnapprovedTransactionsAction\n | TransactionControllerAbortTransactionSigningAction\n | TransactionControllerUpdateAtomicBatchDataAction\n | TransactionControllerEmulateNewTransactionAction\n | TransactionControllerEmulateTransactionUpdateAction\n | TransactionControllerGetGasFeeTokensAction;\n"]}
|
|
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
var _IncomingTransactionHelper_instances, _IncomingTransactionHelper_client, _IncomingTransactionHelper_getCurrentAccount, _IncomingTransactionHelper_getLocalTransactions, _IncomingTransactionHelper_includeTokenTransfers, _IncomingTransactionHelper_isEnabled, _IncomingTransactionHelper_isRunning, _IncomingTransactionHelper_isUpdating, _IncomingTransactionHelper_messenger, _IncomingTransactionHelper_remoteTransactionSource, _IncomingTransactionHelper_timeoutId, _IncomingTransactionHelper_trimTransactions, _IncomingTransactionHelper_updateTransactions, _IncomingTransactionHelper_useBackendWebSocketService, _IncomingTransactionHelper_chainsToPoll, _IncomingTransactionHelper_connectionStateChangedHandler, _IncomingTransactionHelper_transactionUpdatedHandler, _IncomingTransactionHelper_selectedAccountChangedHandler, _IncomingTransactionHelper_statusChangedHandler, _IncomingTransactionHelper_startPolling, _IncomingTransactionHelper_onConnectionStateChanged, _IncomingTransactionHelper_startTransactionHistoryRetrieval, _IncomingTransactionHelper_stopTransactionHistoryRetrieval, _IncomingTransactionHelper_onTransactionUpdated, _IncomingTransactionHelper_onSelectedAccountChanged, _IncomingTransactionHelper_onInterval, _IncomingTransactionHelper_sortTransactionsByTime, _IncomingTransactionHelper_canStart, _IncomingTransactionHelper_getInterval, _IncomingTransactionHelper_getTags, _IncomingTransactionHelper_onNetworkStatusChanged;
|
|
16
|
+
var _IncomingTransactionHelper_instances, _IncomingTransactionHelper_client, _IncomingTransactionHelper_getCurrentAccount, _IncomingTransactionHelper_getLocalTransactions, _IncomingTransactionHelper_includeTokenTransfers, _IncomingTransactionHelper_isEnabled, _IncomingTransactionHelper_isRunning, _IncomingTransactionHelper_isUpdating, _IncomingTransactionHelper_messenger, _IncomingTransactionHelper_remoteTransactionSource, _IncomingTransactionHelper_timeoutId, _IncomingTransactionHelper_trimTransactions, _IncomingTransactionHelper_isTransactionHistoryRetrievalActive, _IncomingTransactionHelper_updateTransactions, _IncomingTransactionHelper_useBackendWebSocketService, _IncomingTransactionHelper_chainsToPoll, _IncomingTransactionHelper_connectionStateChangedHandler, _IncomingTransactionHelper_transactionUpdatedHandler, _IncomingTransactionHelper_selectedAccountChangedHandler, _IncomingTransactionHelper_statusChangedHandler, _IncomingTransactionHelper_startPolling, _IncomingTransactionHelper_onConnectionStateChanged, _IncomingTransactionHelper_startTransactionHistoryRetrieval, _IncomingTransactionHelper_stopTransactionHistoryRetrieval, _IncomingTransactionHelper_onTransactionUpdated, _IncomingTransactionHelper_onSelectedAccountChanged, _IncomingTransactionHelper_onInterval, _IncomingTransactionHelper_sortTransactionsByTime, _IncomingTransactionHelper_canStart, _IncomingTransactionHelper_getInterval, _IncomingTransactionHelper_getTags, _IncomingTransactionHelper_onNetworkStatusChanged;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.IncomingTransactionHelper = exports.WebSocketState = void 0;
|
|
19
19
|
// This package purposefully relies on Node's EventEmitter module.
|
|
@@ -43,6 +43,7 @@ class IncomingTransactionHelper {
|
|
|
43
43
|
_IncomingTransactionHelper_remoteTransactionSource.set(this, void 0);
|
|
44
44
|
_IncomingTransactionHelper_timeoutId.set(this, void 0);
|
|
45
45
|
_IncomingTransactionHelper_trimTransactions.set(this, void 0);
|
|
46
|
+
_IncomingTransactionHelper_isTransactionHistoryRetrievalActive.set(this, false);
|
|
46
47
|
_IncomingTransactionHelper_updateTransactions.set(this, void 0);
|
|
47
48
|
_IncomingTransactionHelper_useBackendWebSocketService.set(this, void 0);
|
|
48
49
|
// Chains that need polling (start with all supported, remove as they come up)
|
|
@@ -151,7 +152,7 @@ class IncomingTransactionHelper {
|
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
exports.IncomingTransactionHelper = IncomingTransactionHelper;
|
|
154
|
-
_IncomingTransactionHelper_client = new WeakMap(), _IncomingTransactionHelper_getCurrentAccount = new WeakMap(), _IncomingTransactionHelper_getLocalTransactions = new WeakMap(), _IncomingTransactionHelper_includeTokenTransfers = new WeakMap(), _IncomingTransactionHelper_isEnabled = new WeakMap(), _IncomingTransactionHelper_isRunning = new WeakMap(), _IncomingTransactionHelper_isUpdating = new WeakMap(), _IncomingTransactionHelper_messenger = new WeakMap(), _IncomingTransactionHelper_remoteTransactionSource = new WeakMap(), _IncomingTransactionHelper_timeoutId = new WeakMap(), _IncomingTransactionHelper_trimTransactions = new WeakMap(), _IncomingTransactionHelper_updateTransactions = new WeakMap(), _IncomingTransactionHelper_useBackendWebSocketService = new WeakMap(), _IncomingTransactionHelper_chainsToPoll = new WeakMap(), _IncomingTransactionHelper_connectionStateChangedHandler = new WeakMap(), _IncomingTransactionHelper_transactionUpdatedHandler = new WeakMap(), _IncomingTransactionHelper_selectedAccountChangedHandler = new WeakMap(), _IncomingTransactionHelper_statusChangedHandler = new WeakMap(), _IncomingTransactionHelper_instances = new WeakSet(), _IncomingTransactionHelper_startPolling = function _IncomingTransactionHelper_startPolling(initialPolling = false) {
|
|
155
|
+
_IncomingTransactionHelper_client = new WeakMap(), _IncomingTransactionHelper_getCurrentAccount = new WeakMap(), _IncomingTransactionHelper_getLocalTransactions = new WeakMap(), _IncomingTransactionHelper_includeTokenTransfers = new WeakMap(), _IncomingTransactionHelper_isEnabled = new WeakMap(), _IncomingTransactionHelper_isRunning = new WeakMap(), _IncomingTransactionHelper_isUpdating = new WeakMap(), _IncomingTransactionHelper_messenger = new WeakMap(), _IncomingTransactionHelper_remoteTransactionSource = new WeakMap(), _IncomingTransactionHelper_timeoutId = new WeakMap(), _IncomingTransactionHelper_trimTransactions = new WeakMap(), _IncomingTransactionHelper_isTransactionHistoryRetrievalActive = new WeakMap(), _IncomingTransactionHelper_updateTransactions = new WeakMap(), _IncomingTransactionHelper_useBackendWebSocketService = new WeakMap(), _IncomingTransactionHelper_chainsToPoll = new WeakMap(), _IncomingTransactionHelper_connectionStateChangedHandler = new WeakMap(), _IncomingTransactionHelper_transactionUpdatedHandler = new WeakMap(), _IncomingTransactionHelper_selectedAccountChangedHandler = new WeakMap(), _IncomingTransactionHelper_statusChangedHandler = new WeakMap(), _IncomingTransactionHelper_instances = new WeakSet(), _IncomingTransactionHelper_startPolling = function _IncomingTransactionHelper_startPolling(initialPolling = false) {
|
|
155
156
|
if (__classPrivateFieldGet(this, _IncomingTransactionHelper_isRunning, "f")) {
|
|
156
157
|
return;
|
|
157
158
|
}
|
|
@@ -182,14 +183,22 @@ _IncomingTransactionHelper_client = new WeakMap(), _IncomingTransactionHelper_ge
|
|
|
182
183
|
if (!__classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_canStart).call(this)) {
|
|
183
184
|
return;
|
|
184
185
|
}
|
|
186
|
+
if (__classPrivateFieldGet(this, _IncomingTransactionHelper_isTransactionHistoryRetrievalActive, "f")) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
185
189
|
(0, logger_1.incomingTransactionsLogger)('Started transaction history retrieval (event-driven)');
|
|
190
|
+
__classPrivateFieldSet(this, _IncomingTransactionHelper_isTransactionHistoryRetrievalActive, true, "f");
|
|
186
191
|
this.update().catch((error) => {
|
|
187
192
|
(0, logger_1.incomingTransactionsLogger)('Initial update in transaction history retrieval failed', error);
|
|
188
193
|
});
|
|
189
194
|
__classPrivateFieldGet(this, _IncomingTransactionHelper_messenger, "f").subscribe('AccountActivityService:transactionUpdated', __classPrivateFieldGet(this, _IncomingTransactionHelper_transactionUpdatedHandler, "f"));
|
|
190
195
|
__classPrivateFieldGet(this, _IncomingTransactionHelper_messenger, "f").subscribe('AccountsController:selectedAccountChange', __classPrivateFieldGet(this, _IncomingTransactionHelper_selectedAccountChangedHandler, "f"));
|
|
191
196
|
}, _IncomingTransactionHelper_stopTransactionHistoryRetrieval = function _IncomingTransactionHelper_stopTransactionHistoryRetrieval() {
|
|
197
|
+
if (!__classPrivateFieldGet(this, _IncomingTransactionHelper_isTransactionHistoryRetrievalActive, "f")) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
192
200
|
(0, logger_1.incomingTransactionsLogger)('Stopped transaction history retrieval');
|
|
201
|
+
__classPrivateFieldSet(this, _IncomingTransactionHelper_isTransactionHistoryRetrievalActive, false, "f");
|
|
193
202
|
__classPrivateFieldGet(this, _IncomingTransactionHelper_messenger, "f").unsubscribe('AccountActivityService:transactionUpdated', __classPrivateFieldGet(this, _IncomingTransactionHelper_transactionUpdatedHandler, "f"));
|
|
194
203
|
__classPrivateFieldGet(this, _IncomingTransactionHelper_messenger, "f").unsubscribe('AccountsController:selectedAccountChange', __classPrivateFieldGet(this, _IncomingTransactionHelper_selectedAccountChangedHandler, "f"));
|
|
195
204
|
}, _IncomingTransactionHelper_onTransactionUpdated = function _IncomingTransactionHelper_onTransactionUpdated(transaction) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IncomingTransactionHelper.cjs","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAElC,iGAA2E;AAE3E,0CAA8D;AAE9D,8DAGgC;AAChC,8CAA4C;AAE5C,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,+CAA6B,CAAA;AAC/B,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB;AAmBD,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC,MAAa,yBAAyB;IA8DpC,YAAY,EACV,MAAM,EACN,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,GAanB;;QAjFQ,oDAAiB;QAEjB,+DAEP;QAEO,kEAA+C;QAE/C,mEAAiC;QAEjC,uDAA0B;QAEnC,uDAAoB;QAEpB,wDAAqB;QAEZ,uDAA2C;QAE3C,qEAAkD;QAE3D,uDAAqB;QAEZ,8DAEc;QAEd,gEAA8B;QAE9B,wEAAqC;QAE9C,8EAA8E;QACrE,kDAAuB,CAAC,GAAG,wDAAmB,CAAC,EAAC;QAEhD,mEAAiC,CACxC,cAAuC,EACjC,EAAE;YACR,uBAAA,IAAI,iGAA0B,MAA9B,IAAI,EAA2B,cAAc,CAAC,CAAC;QACjD,CAAC,EAAC;QAEO,+DAA6B,CACpC,WAAuC,EACjC,EAAE;YACR,uBAAA,IAAI,6FAAsB,MAA1B,IAAI,EAAuB,WAAW,CAAC,CAAC;QAC1C,CAAC,EAAC;QAEO,mEAAiC,GAAS,EA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nimport type {\n Transaction as AccountActivityTransaction,\n WebSocketConnectionInfo,\n} from '@metamask/core-backend';\nimport type { Hex } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { SUPPORTED_CHAIN_IDS } from './AccountsApiRemoteTransactionSource';\nimport type { TransactionControllerMessenger } from '..';\nimport { incomingTransactionsLogger as log } from '../logger';\nimport type { RemoteTransactionSource, TransactionMeta } from '../types';\nimport {\n getIncomingTransactionsPollingInterval,\n isIncomingTransactionsUseBackendWebSocketServiceEnabled,\n} from '../utils/feature-flags';\nimport { caip2ToHex } from '../utils/utils';\n\nexport enum WebSocketState {\n CONNECTED = 'connected',\n DISCONNECTED = 'disconnected',\n}\n\nexport type IncomingTransactionOptions = {\n /** Name of the client to include in requests. */\n client?: string;\n\n /** Whether to retrieve incoming token transfers. Defaults to false. */\n includeTokenTransfers?: boolean;\n\n /** Callback to determine if incoming transaction polling is enabled. */\n isEnabled?: () => boolean;\n\n /** @deprecated No longer used. */\n queryEntireHistory?: boolean;\n\n /** Whether to retrieve outgoing transactions. Defaults to false. */\n updateTransactions?: boolean;\n};\n\nconst TAG_POLLING = 'automatic-polling';\n\nexport class IncomingTransactionHelper {\n hub: EventEmitter;\n\n readonly #client?: string;\n\n readonly #getCurrentAccount: () => ReturnType<\n AccountsController['getSelectedAccount']\n >;\n\n readonly #getLocalTransactions: () => TransactionMeta[];\n\n readonly #includeTokenTransfers?: boolean;\n\n readonly #isEnabled: () => boolean;\n\n #isRunning: boolean;\n\n #isUpdating: boolean;\n\n readonly #messenger: TransactionControllerMessenger;\n\n readonly #remoteTransactionSource: RemoteTransactionSource;\n\n #timeoutId?: unknown;\n\n readonly #trimTransactions: (\n transactions: TransactionMeta[],\n ) => TransactionMeta[];\n\n readonly #updateTransactions?: boolean;\n\n readonly #useBackendWebSocketService: boolean;\n\n // Chains that need polling (start with all supported, remove as they come up)\n readonly #chainsToPoll: Hex[] = [...SUPPORTED_CHAIN_IDS];\n\n readonly #connectionStateChangedHandler = (\n connectionInfo: WebSocketConnectionInfo,\n ): void => {\n this.#onConnectionStateChanged(connectionInfo);\n };\n\n readonly #transactionUpdatedHandler = (\n transaction: AccountActivityTransaction,\n ): void => {\n this.#onTransactionUpdated(transaction);\n };\n\n readonly #selectedAccountChangedHandler = (): void => {\n this.#onSelectedAccountChanged();\n };\n\n readonly #statusChangedHandler = ({\n chainIds,\n status,\n }: {\n chainIds: string[];\n status: 'up' | 'down';\n }): void => {\n this.#onNetworkStatusChanged(chainIds, status);\n };\n\n constructor({\n client,\n getCurrentAccount,\n getLocalTransactions,\n includeTokenTransfers,\n isEnabled,\n messenger,\n remoteTransactionSource,\n trimTransactions,\n updateTransactions,\n }: {\n client?: string;\n getCurrentAccount: () => ReturnType<\n AccountsController['getSelectedAccount']\n >;\n getLocalTransactions: () => TransactionMeta[];\n includeTokenTransfers?: boolean;\n isEnabled?: () => boolean;\n messenger: TransactionControllerMessenger;\n remoteTransactionSource: RemoteTransactionSource;\n trimTransactions: (transactions: TransactionMeta[]) => TransactionMeta[];\n updateTransactions?: boolean;\n }) {\n this.hub = new EventEmitter();\n\n this.#client = client;\n this.#getCurrentAccount = getCurrentAccount;\n this.#getLocalTransactions = getLocalTransactions;\n this.#includeTokenTransfers = includeTokenTransfers;\n this.#isEnabled = isEnabled ?? ((): boolean => true);\n this.#isRunning = false;\n this.#isUpdating = false;\n this.#messenger = messenger;\n this.#remoteTransactionSource = remoteTransactionSource;\n this.#trimTransactions = trimTransactions;\n this.#updateTransactions = updateTransactions;\n this.#useBackendWebSocketService =\n isIncomingTransactionsUseBackendWebSocketServiceEnabled(messenger);\n\n if (this.#useBackendWebSocketService) {\n this.#messenger.subscribe(\n 'BackendWebSocketService:connectionStateChanged',\n this.#connectionStateChangedHandler,\n );\n\n this.#messenger.subscribe(\n 'AccountActivityService:statusChanged',\n this.#statusChangedHandler,\n );\n }\n }\n\n start(): void {\n // When websockets are disabled, allow normal polling (legacy mode)\n if (this.#useBackendWebSocketService) {\n return;\n }\n\n this.#startPolling(true);\n }\n\n #startPolling(initialPolling = false): void {\n if (this.#isRunning) {\n return;\n }\n\n if (!this.#canStart()) {\n return;\n }\n\n const interval = this.#getInterval();\n\n log('Started polling', {\n interval,\n });\n\n this.#isRunning = true;\n\n if (this.#isUpdating) {\n return;\n }\n\n this.#onInterval().catch((error) => {\n log(initialPolling ? 'Initial polling failed' : 'Polling failed', error);\n });\n }\n\n stop(): void {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId as number);\n }\n\n if (!this.#isRunning) {\n return;\n }\n\n this.#isRunning = false;\n\n log('Stopped polling');\n }\n\n #onConnectionStateChanged(connectionInfo: WebSocketConnectionInfo): void {\n if (connectionInfo.state === WebSocketState.CONNECTED) {\n log('WebSocket connected, starting enhanced mode');\n this.#startTransactionHistoryRetrieval();\n } else if (connectionInfo.state === WebSocketState.DISCONNECTED) {\n log('WebSocket disconnected, stopping enhanced mode');\n this.#stopTransactionHistoryRetrieval();\n }\n }\n\n #startTransactionHistoryRetrieval(): void {\n if (!this.#canStart()) {\n return;\n }\n\n log('Started transaction history retrieval (event-driven)');\n\n this.update().catch((error) => {\n log('Initial update in transaction history retrieval failed', error);\n });\n\n this.#messenger.subscribe(\n 'AccountActivityService:transactionUpdated',\n this.#transactionUpdatedHandler,\n );\n\n this.#messenger.subscribe(\n 'AccountsController:selectedAccountChange',\n this.#selectedAccountChangedHandler,\n );\n }\n\n #stopTransactionHistoryRetrieval(): void {\n log('Stopped transaction history retrieval');\n\n this.#messenger.unsubscribe(\n 'AccountActivityService:transactionUpdated',\n this.#transactionUpdatedHandler,\n );\n\n this.#messenger.unsubscribe(\n 'AccountsController:selectedAccountChange',\n this.#selectedAccountChangedHandler,\n );\n }\n\n #onTransactionUpdated(transaction: AccountActivityTransaction): void {\n log('Received relevant transaction update, triggering update', {\n txId: transaction.id,\n chain: transaction.chain,\n });\n\n this.update().catch((error) => {\n log('Update after transaction event failed', error);\n });\n }\n\n #onSelectedAccountChanged(): void {\n log('Selected account changed, triggering update');\n\n this.update().catch((error) => {\n log('Update after account change failed', error);\n });\n }\n\n async #onInterval(): Promise<void> {\n this.#isUpdating = true;\n\n try {\n // When websockets enabled, only poll chains that are not confirmed up\n const chainIds = this.#useBackendWebSocketService\n ? this.#chainsToPoll\n : undefined;\n await this.update({ chainIds, isInterval: true });\n } catch (error) {\n console.error('Error while checking incoming transactions', error);\n }\n\n this.#isUpdating = false;\n\n if (this.#isRunning) {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId as number);\n }\n\n this.#timeoutId = setTimeout(\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n () => this.#onInterval(),\n this.#getInterval(),\n );\n }\n }\n\n async update({\n chainIds,\n isInterval,\n tags,\n }: {\n chainIds?: Hex[];\n isInterval?: boolean;\n tags?: string[];\n } = {}): Promise<void> {\n const finalTags = this.#getTags(tags, isInterval);\n\n log('Checking for incoming transactions', {\n isInterval: Boolean(isInterval),\n tags: finalTags,\n });\n\n if (!this.#canStart()) {\n return;\n }\n\n const account = this.#getCurrentAccount();\n const includeTokenTransfers = this.#includeTokenTransfers ?? true;\n const updateTransactions = this.#updateTransactions ?? false;\n\n let remoteTransactions: TransactionMeta[] = [];\n\n try {\n remoteTransactions =\n await this.#remoteTransactionSource.fetchTransactions({\n address: account.address as Hex,\n chainIds,\n includeTokenTransfers,\n tags: finalTags,\n updateTransactions,\n });\n } catch (error: unknown) {\n log('Error while fetching remote transactions', error);\n return;\n }\n\n if (!remoteTransactions.length) {\n return;\n }\n\n this.#sortTransactionsByTime(remoteTransactions);\n\n log(\n 'Found potential transactions',\n remoteTransactions.length,\n remoteTransactions,\n );\n\n const localTransactions = this.#getLocalTransactions();\n\n const uniqueTransactions = remoteTransactions.filter(\n (tx) =>\n !localTransactions.some(\n (currentTx) =>\n currentTx.hash?.toLowerCase() === tx.hash?.toLowerCase() &&\n currentTx.txParams.from?.toLowerCase() ===\n tx.txParams.from?.toLowerCase() &&\n currentTx.type === tx.type,\n ),\n );\n\n if (!uniqueTransactions.length) {\n log('All transactions are already known');\n return;\n }\n\n log(\n 'Found unique transactions',\n uniqueTransactions.length,\n uniqueTransactions,\n );\n\n const trimmedTransactions = this.#trimTransactions([\n ...uniqueTransactions,\n ...localTransactions,\n ]);\n\n const uniqueTransactionIds = uniqueTransactions.map((tx) => tx.id);\n\n const newTransactions = trimmedTransactions.filter((tx) =>\n uniqueTransactionIds.includes(tx.id),\n );\n\n if (!newTransactions.length) {\n log('All unique transactions truncated due to limit');\n return;\n }\n\n log('Adding new transactions', newTransactions.length, newTransactions);\n\n this.hub.emit('transactions', newTransactions);\n }\n\n #sortTransactionsByTime(transactions: TransactionMeta[]): void {\n transactions.sort((a, b) => (a.time < b.time ? -1 : 1));\n }\n\n #canStart(): boolean {\n return this.#isEnabled();\n }\n\n #getInterval(): number {\n return getIncomingTransactionsPollingInterval(this.#messenger);\n }\n\n #getTags(\n requestTags: string[] | undefined,\n isInterval: boolean | undefined,\n ): string[] | undefined {\n const tags = [];\n\n if (this.#client) {\n tags.push(this.#client);\n }\n\n if (requestTags?.length) {\n tags.push(...requestTags);\n } else if (isInterval) {\n tags.push(TAG_POLLING);\n }\n\n return tags?.length ? tags : undefined;\n }\n\n #onNetworkStatusChanged(chainIds: string[], status: 'up' | 'down'): void {\n if (!this.#useBackendWebSocketService) {\n return;\n }\n\n let hasChanges = false;\n\n for (const caip2ChainId of chainIds) {\n const hexChainId = caip2ToHex(caip2ChainId);\n\n if (!hexChainId || !SUPPORTED_CHAIN_IDS.includes(hexChainId)) {\n log('Chain ID not recognized or not supported', {\n caip2ChainId,\n hexChainId,\n });\n continue;\n }\n\n if (status === 'up') {\n const index = this.#chainsToPoll.indexOf(hexChainId);\n if (index !== -1) {\n this.#chainsToPoll.splice(index, 1);\n hasChanges = true;\n log('Supported network came up, removed from polling list', {\n chainId: hexChainId,\n });\n }\n } else if (\n status === 'down' &&\n !this.#chainsToPoll.includes(hexChainId)\n ) {\n this.#chainsToPoll.push(hexChainId);\n hasChanges = true;\n log('Supported network went down, added to polling list', {\n chainId: hexChainId,\n });\n }\n }\n\n if (!hasChanges) {\n log('No changes to polling list', {\n chainsToPoll: this.#chainsToPoll,\n });\n return;\n }\n\n if (this.#chainsToPoll.length === 0) {\n log('Stopping fallback polling - all networks up');\n this.stop();\n } else {\n log('Starting fallback polling - some networks need polling', {\n chainsToPoll: this.#chainsToPoll,\n });\n this.#startPolling();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IncomingTransactionHelper.cjs","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAElC,iGAA2E;AAE3E,0CAA8D;AAE9D,8DAGgC;AAChC,8CAA4C;AAE5C,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,+CAA6B,CAAA;AAC/B,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB;AAmBD,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC,MAAa,yBAAyB;IAgEpC,YAAY,EACV,MAAM,EACN,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,GAanB;;QAnFQ,oDAAiB;QAEjB,+DAEP;QAEO,kEAA+C;QAE/C,mEAAiC;QAEjC,uDAA0B;QAEnC,uDAAoB;QAEpB,wDAAqB;QAEZ,uDAA2C;QAE3C,qEAAkD;QAE3D,uDAAqB;QAEZ,8DAEc;QAEvB,yEAAuC,KAAK,EAAC;QAEpC,gEAA8B;QAE9B,wEAAqC;QAE9C,8EAA8E;QACrE,kDAAuB,CAAC,GAAG,wDAAmB,CAAC,EAAC;QAEhD,mEAAiC,CACxC,cAAuC,EACjC,EAAE;YACR,uBAAA,IAAI,iGAA0B,MA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,IAAI,+CAAc;SACjC,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,IAAI,uBAAA,IAAI,+CAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpC,IAAA,mCAAG,EAAC,6CAA6C,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;SAAM,CAAC;QACN,IAAA,mCAAG,EAAC,wDAAwD,EAAE;YAC5D,YAAY,EAAE,uBAAA,IAAI,+CAAc;SACjC,CAAC,CAAC;QACH,uBAAA,IAAI,qFAAc,MAAlB,IAAI,CAAgB,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["import type { AccountsController } from '@metamask/accounts-controller';\nimport type {\n Transaction as AccountActivityTransaction,\n WebSocketConnectionInfo,\n} from '@metamask/core-backend';\nimport type { Hex } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { SUPPORTED_CHAIN_IDS } from './AccountsApiRemoteTransactionSource';\nimport type { TransactionControllerMessenger } from '..';\nimport { incomingTransactionsLogger as log } from '../logger';\nimport type { RemoteTransactionSource, TransactionMeta } from '../types';\nimport {\n getIncomingTransactionsPollingInterval,\n isIncomingTransactionsUseBackendWebSocketServiceEnabled,\n} from '../utils/feature-flags';\nimport { caip2ToHex } from '../utils/utils';\n\nexport enum WebSocketState {\n CONNECTED = 'connected',\n DISCONNECTED = 'disconnected',\n}\n\nexport type IncomingTransactionOptions = {\n /** Name of the client to include in requests. */\n client?: string;\n\n /** Whether to retrieve incoming token transfers. Defaults to false. */\n includeTokenTransfers?: boolean;\n\n /** Callback to determine if incoming transaction polling is enabled. */\n isEnabled?: () => boolean;\n\n /** @deprecated No longer used. */\n queryEntireHistory?: boolean;\n\n /** Whether to retrieve outgoing transactions. Defaults to false. */\n updateTransactions?: boolean;\n};\n\nconst TAG_POLLING = 'automatic-polling';\n\nexport class IncomingTransactionHelper {\n hub: EventEmitter;\n\n readonly #client?: string;\n\n readonly #getCurrentAccount: () => ReturnType<\n AccountsController['getSelectedAccount']\n >;\n\n readonly #getLocalTransactions: () => TransactionMeta[];\n\n readonly #includeTokenTransfers?: boolean;\n\n readonly #isEnabled: () => boolean;\n\n #isRunning: boolean;\n\n #isUpdating: boolean;\n\n readonly #messenger: TransactionControllerMessenger;\n\n readonly #remoteTransactionSource: RemoteTransactionSource;\n\n #timeoutId?: unknown;\n\n readonly #trimTransactions: (\n transactions: TransactionMeta[],\n ) => TransactionMeta[];\n\n #isTransactionHistoryRetrievalActive = false;\n\n readonly #updateTransactions?: boolean;\n\n readonly #useBackendWebSocketService: boolean;\n\n // Chains that need polling (start with all supported, remove as they come up)\n readonly #chainsToPoll: Hex[] = [...SUPPORTED_CHAIN_IDS];\n\n readonly #connectionStateChangedHandler = (\n connectionInfo: WebSocketConnectionInfo,\n ): void => {\n this.#onConnectionStateChanged(connectionInfo);\n };\n\n readonly #transactionUpdatedHandler = (\n transaction: AccountActivityTransaction,\n ): void => {\n this.#onTransactionUpdated(transaction);\n };\n\n readonly #selectedAccountChangedHandler = (): void => {\n this.#onSelectedAccountChanged();\n };\n\n readonly #statusChangedHandler = ({\n chainIds,\n status,\n }: {\n chainIds: string[];\n status: 'up' | 'down';\n }): void => {\n this.#onNetworkStatusChanged(chainIds, status);\n };\n\n constructor({\n client,\n getCurrentAccount,\n getLocalTransactions,\n includeTokenTransfers,\n isEnabled,\n messenger,\n remoteTransactionSource,\n trimTransactions,\n updateTransactions,\n }: {\n client?: string;\n getCurrentAccount: () => ReturnType<\n AccountsController['getSelectedAccount']\n >;\n getLocalTransactions: () => TransactionMeta[];\n includeTokenTransfers?: boolean;\n isEnabled?: () => boolean;\n messenger: TransactionControllerMessenger;\n remoteTransactionSource: RemoteTransactionSource;\n trimTransactions: (transactions: TransactionMeta[]) => TransactionMeta[];\n updateTransactions?: boolean;\n }) {\n this.hub = new EventEmitter();\n\n this.#client = client;\n this.#getCurrentAccount = getCurrentAccount;\n this.#getLocalTransactions = getLocalTransactions;\n this.#includeTokenTransfers = includeTokenTransfers;\n this.#isEnabled = isEnabled ?? ((): boolean => true);\n this.#isRunning = false;\n this.#isUpdating = false;\n this.#messenger = messenger;\n this.#remoteTransactionSource = remoteTransactionSource;\n this.#trimTransactions = trimTransactions;\n this.#updateTransactions = updateTransactions;\n this.#useBackendWebSocketService =\n isIncomingTransactionsUseBackendWebSocketServiceEnabled(messenger);\n\n if (this.#useBackendWebSocketService) {\n this.#messenger.subscribe(\n 'BackendWebSocketService:connectionStateChanged',\n this.#connectionStateChangedHandler,\n );\n\n this.#messenger.subscribe(\n 'AccountActivityService:statusChanged',\n this.#statusChangedHandler,\n );\n }\n }\n\n start(): void {\n // When websockets are disabled, allow normal polling (legacy mode)\n if (this.#useBackendWebSocketService) {\n return;\n }\n\n this.#startPolling(true);\n }\n\n #startPolling(initialPolling = false): void {\n if (this.#isRunning) {\n return;\n }\n\n if (!this.#canStart()) {\n return;\n }\n\n const interval = this.#getInterval();\n\n log('Started polling', {\n interval,\n });\n\n this.#isRunning = true;\n\n if (this.#isUpdating) {\n return;\n }\n\n this.#onInterval().catch((error) => {\n log(initialPolling ? 'Initial polling failed' : 'Polling failed', error);\n });\n }\n\n stop(): void {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId as number);\n }\n\n if (!this.#isRunning) {\n return;\n }\n\n this.#isRunning = false;\n\n log('Stopped polling');\n }\n\n #onConnectionStateChanged(connectionInfo: WebSocketConnectionInfo): void {\n if (connectionInfo.state === WebSocketState.CONNECTED) {\n log('WebSocket connected, starting enhanced mode');\n this.#startTransactionHistoryRetrieval();\n } else if (connectionInfo.state === WebSocketState.DISCONNECTED) {\n log('WebSocket disconnected, stopping enhanced mode');\n this.#stopTransactionHistoryRetrieval();\n }\n }\n\n #startTransactionHistoryRetrieval(): void {\n if (!this.#canStart()) {\n return;\n }\n\n if (this.#isTransactionHistoryRetrievalActive) {\n return;\n }\n\n log('Started transaction history retrieval (event-driven)');\n\n this.#isTransactionHistoryRetrievalActive = true;\n\n this.update().catch((error) => {\n log('Initial update in transaction history retrieval failed', error);\n });\n\n this.#messenger.subscribe(\n 'AccountActivityService:transactionUpdated',\n this.#transactionUpdatedHandler,\n );\n\n this.#messenger.subscribe(\n 'AccountsController:selectedAccountChange',\n this.#selectedAccountChangedHandler,\n );\n }\n\n #stopTransactionHistoryRetrieval(): void {\n if (!this.#isTransactionHistoryRetrievalActive) {\n return;\n }\n\n log('Stopped transaction history retrieval');\n\n this.#isTransactionHistoryRetrievalActive = false;\n\n this.#messenger.unsubscribe(\n 'AccountActivityService:transactionUpdated',\n this.#transactionUpdatedHandler,\n );\n\n this.#messenger.unsubscribe(\n 'AccountsController:selectedAccountChange',\n this.#selectedAccountChangedHandler,\n );\n }\n\n #onTransactionUpdated(transaction: AccountActivityTransaction): void {\n log('Received relevant transaction update, triggering update', {\n txId: transaction.id,\n chain: transaction.chain,\n });\n\n this.update().catch((error) => {\n log('Update after transaction event failed', error);\n });\n }\n\n #onSelectedAccountChanged(): void {\n log('Selected account changed, triggering update');\n\n this.update().catch((error) => {\n log('Update after account change failed', error);\n });\n }\n\n async #onInterval(): Promise<void> {\n this.#isUpdating = true;\n\n try {\n // When websockets enabled, only poll chains that are not confirmed up\n const chainIds = this.#useBackendWebSocketService\n ? this.#chainsToPoll\n : undefined;\n await this.update({ chainIds, isInterval: true });\n } catch (error) {\n console.error('Error while checking incoming transactions', error);\n }\n\n this.#isUpdating = false;\n\n if (this.#isRunning) {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId as number);\n }\n\n this.#timeoutId = setTimeout(\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n () => this.#onInterval(),\n this.#getInterval(),\n );\n }\n }\n\n async update({\n chainIds,\n isInterval,\n tags,\n }: {\n chainIds?: Hex[];\n isInterval?: boolean;\n tags?: string[];\n } = {}): Promise<void> {\n const finalTags = this.#getTags(tags, isInterval);\n\n log('Checking for incoming transactions', {\n isInterval: Boolean(isInterval),\n tags: finalTags,\n });\n\n if (!this.#canStart()) {\n return;\n }\n\n const account = this.#getCurrentAccount();\n const includeTokenTransfers = this.#includeTokenTransfers ?? true;\n const updateTransactions = this.#updateTransactions ?? false;\n\n let remoteTransactions: TransactionMeta[] = [];\n\n try {\n remoteTransactions =\n await this.#remoteTransactionSource.fetchTransactions({\n address: account.address as Hex,\n chainIds,\n includeTokenTransfers,\n tags: finalTags,\n updateTransactions,\n });\n } catch (error: unknown) {\n log('Error while fetching remote transactions', error);\n return;\n }\n\n if (!remoteTransactions.length) {\n return;\n }\n\n this.#sortTransactionsByTime(remoteTransactions);\n\n log(\n 'Found potential transactions',\n remoteTransactions.length,\n remoteTransactions,\n );\n\n const localTransactions = this.#getLocalTransactions();\n\n const uniqueTransactions = remoteTransactions.filter(\n (tx) =>\n !localTransactions.some(\n (currentTx) =>\n currentTx.hash?.toLowerCase() === tx.hash?.toLowerCase() &&\n currentTx.txParams.from?.toLowerCase() ===\n tx.txParams.from?.toLowerCase() &&\n currentTx.type === tx.type,\n ),\n );\n\n if (!uniqueTransactions.length) {\n log('All transactions are already known');\n return;\n }\n\n log(\n 'Found unique transactions',\n uniqueTransactions.length,\n uniqueTransactions,\n );\n\n const trimmedTransactions = this.#trimTransactions([\n ...uniqueTransactions,\n ...localTransactions,\n ]);\n\n const uniqueTransactionIds = uniqueTransactions.map((tx) => tx.id);\n\n const newTransactions = trimmedTransactions.filter((tx) =>\n uniqueTransactionIds.includes(tx.id),\n );\n\n if (!newTransactions.length) {\n log('All unique transactions truncated due to limit');\n return;\n }\n\n log('Adding new transactions', newTransactions.length, newTransactions);\n\n this.hub.emit('transactions', newTransactions);\n }\n\n #sortTransactionsByTime(transactions: TransactionMeta[]): void {\n transactions.sort((a, b) => (a.time < b.time ? -1 : 1));\n }\n\n #canStart(): boolean {\n return this.#isEnabled();\n }\n\n #getInterval(): number {\n return getIncomingTransactionsPollingInterval(this.#messenger);\n }\n\n #getTags(\n requestTags: string[] | undefined,\n isInterval: boolean | undefined,\n ): string[] | undefined {\n const tags = [];\n\n if (this.#client) {\n tags.push(this.#client);\n }\n\n if (requestTags?.length) {\n tags.push(...requestTags);\n } else if (isInterval) {\n tags.push(TAG_POLLING);\n }\n\n return tags?.length ? tags : undefined;\n }\n\n #onNetworkStatusChanged(chainIds: string[], status: 'up' | 'down'): void {\n if (!this.#useBackendWebSocketService) {\n return;\n }\n\n let hasChanges = false;\n\n for (const caip2ChainId of chainIds) {\n const hexChainId = caip2ToHex(caip2ChainId);\n\n if (!hexChainId || !SUPPORTED_CHAIN_IDS.includes(hexChainId)) {\n log('Chain ID not recognized or not supported', {\n caip2ChainId,\n hexChainId,\n });\n continue;\n }\n\n if (status === 'up') {\n const index = this.#chainsToPoll.indexOf(hexChainId);\n if (index !== -1) {\n this.#chainsToPoll.splice(index, 1);\n hasChanges = true;\n log('Supported network came up, removed from polling list', {\n chainId: hexChainId,\n });\n }\n } else if (\n status === 'down' &&\n !this.#chainsToPoll.includes(hexChainId)\n ) {\n this.#chainsToPoll.push(hexChainId);\n hasChanges = true;\n log('Supported network went down, added to polling list', {\n chainId: hexChainId,\n });\n }\n }\n\n if (!hasChanges) {\n log('No changes to polling list', {\n chainsToPoll: this.#chainsToPoll,\n });\n return;\n }\n\n if (this.#chainsToPoll.length === 0) {\n log('Stopping fallback polling - all networks up');\n this.stop();\n } else {\n log('Starting fallback polling - some networks need polling', {\n chainsToPoll: this.#chainsToPoll,\n });\n this.#startPolling();\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IncomingTransactionHelper.d.cts","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sCAAsC;AAKxE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAAE,8BAA8B,EAAE,qBAAW;AAEzD,OAA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E,YAAY,CAAC;gBA+DN,EACV,MAAM,EACN,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,GACnB,EAAE;QACD,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,iBAAiB,EAAE,MAAM,UAAU,CACjC,kBAAkB,CAAC,oBAAoB,CAAC,CACzC,CAAC;QACF,oBAAoB,EAAE,MAAM,eAAe,EAAE,CAAC;QAC9C,qBAAqB,CAAC,EAAE,OAAO,CAAC;QAChC,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC;QAC1B,SAAS,EAAE,8BAA8B,CAAC;QAC1C,uBAAuB,EAAE,uBAAuB,CAAC;QACjD,gBAAgB,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,CAAC;QACzE,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B;IA8BD,KAAK,IAAI,IAAI;IAmCb,IAAI,IAAI,IAAI;IAuHN,MAAM,CAAC,EACX,QAAQ,EACR,UAAU,EACV,IAAI,GACL,GAAE;QACD,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;QACjB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;KACZ,GAAG,OAAO,CAAC,IAAI,CAAC;CAgLvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IncomingTransactionHelper.d.mts","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sCAAsC;AAKxE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAAE,8BAA8B,EAAE,qBAAW;AAEzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,qBAAiB;AAOzE,oBAAY,cAAc;IACxB,SAAS,cAAc;IACvB,YAAY,iBAAiB;CAC9B;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,uEAAuE;IACvE,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC,wEAAwE;IACxE,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC;IAE1B,kCAAkC;IAClC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,oEAAoE;IACpE,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAIF,qBAAa,yBAAyB;;IACpC,GAAG,EAAE,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"IncomingTransactionHelper.d.mts","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sCAAsC;AAKxE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAAE,8BAA8B,EAAE,qBAAW;AAEzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,qBAAiB;AAOzE,oBAAY,cAAc;IACxB,SAAS,cAAc;IACvB,YAAY,iBAAiB;CAC9B;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,uEAAuE;IACvE,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC,wEAAwE;IACxE,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC;IAE1B,kCAAkC;IAClC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,oEAAoE;IACpE,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAIF,qBAAa,yBAAyB;;IACpC,GAAG,EAAE,YAAY,CAAC;gBA+DN,EACV,MAAM,EACN,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,GACnB,EAAE;QACD,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,iBAAiB,EAAE,MAAM,UAAU,CACjC,kBAAkB,CAAC,oBAAoB,CAAC,CACzC,CAAC;QACF,oBAAoB,EAAE,MAAM,eAAe,EAAE,CAAC;QAC9C,qBAAqB,CAAC,EAAE,OAAO,CAAC;QAChC,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC;QAC1B,SAAS,EAAE,8BAA8B,CAAC;QAC1C,uBAAuB,EAAE,uBAAuB,CAAC;QACjD,gBAAgB,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,CAAC;QACzE,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B;IA8BD,KAAK,IAAI,IAAI;IAmCb,IAAI,IAAI,IAAI;IAuHN,MAAM,CAAC,EACX,QAAQ,EACR,UAAU,EACV,IAAI,GACL,GAAE;QACD,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;QACjB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;KACZ,GAAG,OAAO,CAAC,IAAI,CAAC;CAgLvB"}
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _IncomingTransactionHelper_instances, _IncomingTransactionHelper_client, _IncomingTransactionHelper_getCurrentAccount, _IncomingTransactionHelper_getLocalTransactions, _IncomingTransactionHelper_includeTokenTransfers, _IncomingTransactionHelper_isEnabled, _IncomingTransactionHelper_isRunning, _IncomingTransactionHelper_isUpdating, _IncomingTransactionHelper_messenger, _IncomingTransactionHelper_remoteTransactionSource, _IncomingTransactionHelper_timeoutId, _IncomingTransactionHelper_trimTransactions, _IncomingTransactionHelper_updateTransactions, _IncomingTransactionHelper_useBackendWebSocketService, _IncomingTransactionHelper_chainsToPoll, _IncomingTransactionHelper_connectionStateChangedHandler, _IncomingTransactionHelper_transactionUpdatedHandler, _IncomingTransactionHelper_selectedAccountChangedHandler, _IncomingTransactionHelper_statusChangedHandler, _IncomingTransactionHelper_startPolling, _IncomingTransactionHelper_onConnectionStateChanged, _IncomingTransactionHelper_startTransactionHistoryRetrieval, _IncomingTransactionHelper_stopTransactionHistoryRetrieval, _IncomingTransactionHelper_onTransactionUpdated, _IncomingTransactionHelper_onSelectedAccountChanged, _IncomingTransactionHelper_onInterval, _IncomingTransactionHelper_sortTransactionsByTime, _IncomingTransactionHelper_canStart, _IncomingTransactionHelper_getInterval, _IncomingTransactionHelper_getTags, _IncomingTransactionHelper_onNetworkStatusChanged;
|
|
12
|
+
var _IncomingTransactionHelper_instances, _IncomingTransactionHelper_client, _IncomingTransactionHelper_getCurrentAccount, _IncomingTransactionHelper_getLocalTransactions, _IncomingTransactionHelper_includeTokenTransfers, _IncomingTransactionHelper_isEnabled, _IncomingTransactionHelper_isRunning, _IncomingTransactionHelper_isUpdating, _IncomingTransactionHelper_messenger, _IncomingTransactionHelper_remoteTransactionSource, _IncomingTransactionHelper_timeoutId, _IncomingTransactionHelper_trimTransactions, _IncomingTransactionHelper_isTransactionHistoryRetrievalActive, _IncomingTransactionHelper_updateTransactions, _IncomingTransactionHelper_useBackendWebSocketService, _IncomingTransactionHelper_chainsToPoll, _IncomingTransactionHelper_connectionStateChangedHandler, _IncomingTransactionHelper_transactionUpdatedHandler, _IncomingTransactionHelper_selectedAccountChangedHandler, _IncomingTransactionHelper_statusChangedHandler, _IncomingTransactionHelper_startPolling, _IncomingTransactionHelper_onConnectionStateChanged, _IncomingTransactionHelper_startTransactionHistoryRetrieval, _IncomingTransactionHelper_stopTransactionHistoryRetrieval, _IncomingTransactionHelper_onTransactionUpdated, _IncomingTransactionHelper_onSelectedAccountChanged, _IncomingTransactionHelper_onInterval, _IncomingTransactionHelper_sortTransactionsByTime, _IncomingTransactionHelper_canStart, _IncomingTransactionHelper_getInterval, _IncomingTransactionHelper_getTags, _IncomingTransactionHelper_onNetworkStatusChanged;
|
|
13
13
|
// This package purposefully relies on Node's EventEmitter module.
|
|
14
14
|
// eslint-disable-next-line import-x/no-nodejs-modules
|
|
15
15
|
import EventEmitter from "events";
|
|
@@ -37,6 +37,7 @@ export class IncomingTransactionHelper {
|
|
|
37
37
|
_IncomingTransactionHelper_remoteTransactionSource.set(this, void 0);
|
|
38
38
|
_IncomingTransactionHelper_timeoutId.set(this, void 0);
|
|
39
39
|
_IncomingTransactionHelper_trimTransactions.set(this, void 0);
|
|
40
|
+
_IncomingTransactionHelper_isTransactionHistoryRetrievalActive.set(this, false);
|
|
40
41
|
_IncomingTransactionHelper_updateTransactions.set(this, void 0);
|
|
41
42
|
_IncomingTransactionHelper_useBackendWebSocketService.set(this, void 0);
|
|
42
43
|
// Chains that need polling (start with all supported, remove as they come up)
|
|
@@ -144,7 +145,7 @@ export class IncomingTransactionHelper {
|
|
|
144
145
|
this.hub.emit('transactions', newTransactions);
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
|
-
_IncomingTransactionHelper_client = new WeakMap(), _IncomingTransactionHelper_getCurrentAccount = new WeakMap(), _IncomingTransactionHelper_getLocalTransactions = new WeakMap(), _IncomingTransactionHelper_includeTokenTransfers = new WeakMap(), _IncomingTransactionHelper_isEnabled = new WeakMap(), _IncomingTransactionHelper_isRunning = new WeakMap(), _IncomingTransactionHelper_isUpdating = new WeakMap(), _IncomingTransactionHelper_messenger = new WeakMap(), _IncomingTransactionHelper_remoteTransactionSource = new WeakMap(), _IncomingTransactionHelper_timeoutId = new WeakMap(), _IncomingTransactionHelper_trimTransactions = new WeakMap(), _IncomingTransactionHelper_updateTransactions = new WeakMap(), _IncomingTransactionHelper_useBackendWebSocketService = new WeakMap(), _IncomingTransactionHelper_chainsToPoll = new WeakMap(), _IncomingTransactionHelper_connectionStateChangedHandler = new WeakMap(), _IncomingTransactionHelper_transactionUpdatedHandler = new WeakMap(), _IncomingTransactionHelper_selectedAccountChangedHandler = new WeakMap(), _IncomingTransactionHelper_statusChangedHandler = new WeakMap(), _IncomingTransactionHelper_instances = new WeakSet(), _IncomingTransactionHelper_startPolling = function _IncomingTransactionHelper_startPolling(initialPolling = false) {
|
|
148
|
+
_IncomingTransactionHelper_client = new WeakMap(), _IncomingTransactionHelper_getCurrentAccount = new WeakMap(), _IncomingTransactionHelper_getLocalTransactions = new WeakMap(), _IncomingTransactionHelper_includeTokenTransfers = new WeakMap(), _IncomingTransactionHelper_isEnabled = new WeakMap(), _IncomingTransactionHelper_isRunning = new WeakMap(), _IncomingTransactionHelper_isUpdating = new WeakMap(), _IncomingTransactionHelper_messenger = new WeakMap(), _IncomingTransactionHelper_remoteTransactionSource = new WeakMap(), _IncomingTransactionHelper_timeoutId = new WeakMap(), _IncomingTransactionHelper_trimTransactions = new WeakMap(), _IncomingTransactionHelper_isTransactionHistoryRetrievalActive = new WeakMap(), _IncomingTransactionHelper_updateTransactions = new WeakMap(), _IncomingTransactionHelper_useBackendWebSocketService = new WeakMap(), _IncomingTransactionHelper_chainsToPoll = new WeakMap(), _IncomingTransactionHelper_connectionStateChangedHandler = new WeakMap(), _IncomingTransactionHelper_transactionUpdatedHandler = new WeakMap(), _IncomingTransactionHelper_selectedAccountChangedHandler = new WeakMap(), _IncomingTransactionHelper_statusChangedHandler = new WeakMap(), _IncomingTransactionHelper_instances = new WeakSet(), _IncomingTransactionHelper_startPolling = function _IncomingTransactionHelper_startPolling(initialPolling = false) {
|
|
148
149
|
if (__classPrivateFieldGet(this, _IncomingTransactionHelper_isRunning, "f")) {
|
|
149
150
|
return;
|
|
150
151
|
}
|
|
@@ -175,14 +176,22 @@ _IncomingTransactionHelper_client = new WeakMap(), _IncomingTransactionHelper_ge
|
|
|
175
176
|
if (!__classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_canStart).call(this)) {
|
|
176
177
|
return;
|
|
177
178
|
}
|
|
179
|
+
if (__classPrivateFieldGet(this, _IncomingTransactionHelper_isTransactionHistoryRetrievalActive, "f")) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
178
182
|
log('Started transaction history retrieval (event-driven)');
|
|
183
|
+
__classPrivateFieldSet(this, _IncomingTransactionHelper_isTransactionHistoryRetrievalActive, true, "f");
|
|
179
184
|
this.update().catch((error) => {
|
|
180
185
|
log('Initial update in transaction history retrieval failed', error);
|
|
181
186
|
});
|
|
182
187
|
__classPrivateFieldGet(this, _IncomingTransactionHelper_messenger, "f").subscribe('AccountActivityService:transactionUpdated', __classPrivateFieldGet(this, _IncomingTransactionHelper_transactionUpdatedHandler, "f"));
|
|
183
188
|
__classPrivateFieldGet(this, _IncomingTransactionHelper_messenger, "f").subscribe('AccountsController:selectedAccountChange', __classPrivateFieldGet(this, _IncomingTransactionHelper_selectedAccountChangedHandler, "f"));
|
|
184
189
|
}, _IncomingTransactionHelper_stopTransactionHistoryRetrieval = function _IncomingTransactionHelper_stopTransactionHistoryRetrieval() {
|
|
190
|
+
if (!__classPrivateFieldGet(this, _IncomingTransactionHelper_isTransactionHistoryRetrievalActive, "f")) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
185
193
|
log('Stopped transaction history retrieval');
|
|
194
|
+
__classPrivateFieldSet(this, _IncomingTransactionHelper_isTransactionHistoryRetrievalActive, false, "f");
|
|
186
195
|
__classPrivateFieldGet(this, _IncomingTransactionHelper_messenger, "f").unsubscribe('AccountActivityService:transactionUpdated', __classPrivateFieldGet(this, _IncomingTransactionHelper_transactionUpdatedHandler, "f"));
|
|
187
196
|
__classPrivateFieldGet(this, _IncomingTransactionHelper_messenger, "f").unsubscribe('AccountsController:selectedAccountChange', __classPrivateFieldGet(this, _IncomingTransactionHelper_selectedAccountChangedHandler, "f"));
|
|
188
197
|
}, _IncomingTransactionHelper_onTransactionUpdated = function _IncomingTransactionHelper_onTransactionUpdated(transaction) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IncomingTransactionHelper.mjs","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,YAAY,eAAe;AAElC,OAAO,EAAE,mBAAmB,EAAE,iDAA6C;AAE3E,OAAO,EAAE,0BAA0B,IAAI,GAAG,EAAE,sBAAkB;AAE9D,OAAO,EACL,sCAAsC,EACtC,uDAAuD,EACxD,mCAA+B;AAChC,OAAO,EAAE,UAAU,EAAE,2BAAuB;AAE5C,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,+CAA6B,CAAA;AAC/B,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AAmBD,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC,MAAM,OAAO,yBAAyB;IA8DpC,YAAY,EACV,MAAM,EACN,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,GAanB;;QAjFQ,oDAAiB;QAEjB,+DAEP;QAEO,kEAA+C;QAE/C,mEAAiC;QAEjC,uDAA0B;QAEnC,uDAAoB;QAEpB,wDAAqB;QAEZ,uDAA2C;QAE3C,qEAAkD;QAE3D,uDAAqB;QAEZ,8DAEc;QAEd,gEAA8B;QAE9B,wEAAqC;QAE9C,8EAA8E;QACrE,kDAAuB,CAAC,GAAG,mBAAmB,CAAC,EAAC;QAEhD,mEAAiC,CACxC,cAAuC,EACjC,EAAE;YACR,uBAAA,IAAI,iGAA0B,MAA9B,IAAI,EAA2B,cAAc,CAAC,CAAC;QACjD,CAAC,EAAC;QAEO,+DAA6B,CACpC,WAAuC,EAC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,KAAK,GAAG,uBAAA,IAAI,+CAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YACrD,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;gBACjB,uBAAA,IAAI,+CAAc,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBACpC,UAAU,GAAG,IAAI,CAAC;gBAClB,GAAG,CAAC,sDAAsD,EAAE;oBAC1D,OAAO,EAAE,UAAU;iBACpB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;aAAM,IACL,MAAM,KAAK,MAAM;YACjB,CAAC,uBAAA,IAAI,+CAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,EACxC,CAAC;YACD,uBAAA,IAAI,+CAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACpC,UAAU,GAAG,IAAI,CAAC;YAClB,GAAG,CAAC,oDAAoD,EAAE;gBACxD,OAAO,EAAE,UAAU;aACpB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,GAAG,CAAC,4BAA4B,EAAE;YAChC,YAAY,EAAE,uBAAA,IAAI,+CAAc;SACjC,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,IAAI,uBAAA,IAAI,+CAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpC,GAAG,CAAC,6CAA6C,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,wDAAwD,EAAE;YAC5D,YAAY,EAAE,uBAAA,IAAI,+CAAc;SACjC,CAAC,CAAC;QACH,uBAAA,IAAI,qFAAc,MAAlB,IAAI,CAAgB,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["import type { AccountsController } from '@metamask/accounts-controller';\nimport type {\n Transaction as AccountActivityTransaction,\n WebSocketConnectionInfo,\n} from '@metamask/core-backend';\nimport type { Hex } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { SUPPORTED_CHAIN_IDS } from './AccountsApiRemoteTransactionSource';\nimport type { TransactionControllerMessenger } from '..';\nimport { incomingTransactionsLogger as log } from '../logger';\nimport type { RemoteTransactionSource, TransactionMeta } from '../types';\nimport {\n getIncomingTransactionsPollingInterval,\n isIncomingTransactionsUseBackendWebSocketServiceEnabled,\n} from '../utils/feature-flags';\nimport { caip2ToHex } from '../utils/utils';\n\nexport enum WebSocketState {\n CONNECTED = 'connected',\n DISCONNECTED = 'disconnected',\n}\n\nexport type IncomingTransactionOptions = {\n /** Name of the client to include in requests. */\n client?: string;\n\n /** Whether to retrieve incoming token transfers. Defaults to false. */\n includeTokenTransfers?: boolean;\n\n /** Callback to determine if incoming transaction polling is enabled. */\n isEnabled?: () => boolean;\n\n /** @deprecated No longer used. */\n queryEntireHistory?: boolean;\n\n /** Whether to retrieve outgoing transactions. Defaults to false. */\n updateTransactions?: boolean;\n};\n\nconst TAG_POLLING = 'automatic-polling';\n\nexport class IncomingTransactionHelper {\n hub: EventEmitter;\n\n readonly #client?: string;\n\n readonly #getCurrentAccount: () => ReturnType<\n AccountsController['getSelectedAccount']\n >;\n\n readonly #getLocalTransactions: () => TransactionMeta[];\n\n readonly #includeTokenTransfers?: boolean;\n\n readonly #isEnabled: () => boolean;\n\n #isRunning: boolean;\n\n #isUpdating: boolean;\n\n readonly #messenger: TransactionControllerMessenger;\n\n readonly #remoteTransactionSource: RemoteTransactionSource;\n\n #timeoutId?: unknown;\n\n readonly #trimTransactions: (\n transactions: TransactionMeta[],\n ) => TransactionMeta[];\n\n readonly #updateTransactions?: boolean;\n\n readonly #useBackendWebSocketService: boolean;\n\n // Chains that need polling (start with all supported, remove as they come up)\n readonly #chainsToPoll: Hex[] = [...SUPPORTED_CHAIN_IDS];\n\n readonly #connectionStateChangedHandler = (\n connectionInfo: WebSocketConnectionInfo,\n ): void => {\n this.#onConnectionStateChanged(connectionInfo);\n };\n\n readonly #transactionUpdatedHandler = (\n transaction: AccountActivityTransaction,\n ): void => {\n this.#onTransactionUpdated(transaction);\n };\n\n readonly #selectedAccountChangedHandler = (): void => {\n this.#onSelectedAccountChanged();\n };\n\n readonly #statusChangedHandler = ({\n chainIds,\n status,\n }: {\n chainIds: string[];\n status: 'up' | 'down';\n }): void => {\n this.#onNetworkStatusChanged(chainIds, status);\n };\n\n constructor({\n client,\n getCurrentAccount,\n getLocalTransactions,\n includeTokenTransfers,\n isEnabled,\n messenger,\n remoteTransactionSource,\n trimTransactions,\n updateTransactions,\n }: {\n client?: string;\n getCurrentAccount: () => ReturnType<\n AccountsController['getSelectedAccount']\n >;\n getLocalTransactions: () => TransactionMeta[];\n includeTokenTransfers?: boolean;\n isEnabled?: () => boolean;\n messenger: TransactionControllerMessenger;\n remoteTransactionSource: RemoteTransactionSource;\n trimTransactions: (transactions: TransactionMeta[]) => TransactionMeta[];\n updateTransactions?: boolean;\n }) {\n this.hub = new EventEmitter();\n\n this.#client = client;\n this.#getCurrentAccount = getCurrentAccount;\n this.#getLocalTransactions = getLocalTransactions;\n this.#includeTokenTransfers = includeTokenTransfers;\n this.#isEnabled = isEnabled ?? ((): boolean => true);\n this.#isRunning = false;\n this.#isUpdating = false;\n this.#messenger = messenger;\n this.#remoteTransactionSource = remoteTransactionSource;\n this.#trimTransactions = trimTransactions;\n this.#updateTransactions = updateTransactions;\n this.#useBackendWebSocketService =\n isIncomingTransactionsUseBackendWebSocketServiceEnabled(messenger);\n\n if (this.#useBackendWebSocketService) {\n this.#messenger.subscribe(\n 'BackendWebSocketService:connectionStateChanged',\n this.#connectionStateChangedHandler,\n );\n\n this.#messenger.subscribe(\n 'AccountActivityService:statusChanged',\n this.#statusChangedHandler,\n );\n }\n }\n\n start(): void {\n // When websockets are disabled, allow normal polling (legacy mode)\n if (this.#useBackendWebSocketService) {\n return;\n }\n\n this.#startPolling(true);\n }\n\n #startPolling(initialPolling = false): void {\n if (this.#isRunning) {\n return;\n }\n\n if (!this.#canStart()) {\n return;\n }\n\n const interval = this.#getInterval();\n\n log('Started polling', {\n interval,\n });\n\n this.#isRunning = true;\n\n if (this.#isUpdating) {\n return;\n }\n\n this.#onInterval().catch((error) => {\n log(initialPolling ? 'Initial polling failed' : 'Polling failed', error);\n });\n }\n\n stop(): void {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId as number);\n }\n\n if (!this.#isRunning) {\n return;\n }\n\n this.#isRunning = false;\n\n log('Stopped polling');\n }\n\n #onConnectionStateChanged(connectionInfo: WebSocketConnectionInfo): void {\n if (connectionInfo.state === WebSocketState.CONNECTED) {\n log('WebSocket connected, starting enhanced mode');\n this.#startTransactionHistoryRetrieval();\n } else if (connectionInfo.state === WebSocketState.DISCONNECTED) {\n log('WebSocket disconnected, stopping enhanced mode');\n this.#stopTransactionHistoryRetrieval();\n }\n }\n\n #startTransactionHistoryRetrieval(): void {\n if (!this.#canStart()) {\n return;\n }\n\n log('Started transaction history retrieval (event-driven)');\n\n this.update().catch((error) => {\n log('Initial update in transaction history retrieval failed', error);\n });\n\n this.#messenger.subscribe(\n 'AccountActivityService:transactionUpdated',\n this.#transactionUpdatedHandler,\n );\n\n this.#messenger.subscribe(\n 'AccountsController:selectedAccountChange',\n this.#selectedAccountChangedHandler,\n );\n }\n\n #stopTransactionHistoryRetrieval(): void {\n log('Stopped transaction history retrieval');\n\n this.#messenger.unsubscribe(\n 'AccountActivityService:transactionUpdated',\n this.#transactionUpdatedHandler,\n );\n\n this.#messenger.unsubscribe(\n 'AccountsController:selectedAccountChange',\n this.#selectedAccountChangedHandler,\n );\n }\n\n #onTransactionUpdated(transaction: AccountActivityTransaction): void {\n log('Received relevant transaction update, triggering update', {\n txId: transaction.id,\n chain: transaction.chain,\n });\n\n this.update().catch((error) => {\n log('Update after transaction event failed', error);\n });\n }\n\n #onSelectedAccountChanged(): void {\n log('Selected account changed, triggering update');\n\n this.update().catch((error) => {\n log('Update after account change failed', error);\n });\n }\n\n async #onInterval(): Promise<void> {\n this.#isUpdating = true;\n\n try {\n // When websockets enabled, only poll chains that are not confirmed up\n const chainIds = this.#useBackendWebSocketService\n ? this.#chainsToPoll\n : undefined;\n await this.update({ chainIds, isInterval: true });\n } catch (error) {\n console.error('Error while checking incoming transactions', error);\n }\n\n this.#isUpdating = false;\n\n if (this.#isRunning) {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId as number);\n }\n\n this.#timeoutId = setTimeout(\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n () => this.#onInterval(),\n this.#getInterval(),\n );\n }\n }\n\n async update({\n chainIds,\n isInterval,\n tags,\n }: {\n chainIds?: Hex[];\n isInterval?: boolean;\n tags?: string[];\n } = {}): Promise<void> {\n const finalTags = this.#getTags(tags, isInterval);\n\n log('Checking for incoming transactions', {\n isInterval: Boolean(isInterval),\n tags: finalTags,\n });\n\n if (!this.#canStart()) {\n return;\n }\n\n const account = this.#getCurrentAccount();\n const includeTokenTransfers = this.#includeTokenTransfers ?? true;\n const updateTransactions = this.#updateTransactions ?? false;\n\n let remoteTransactions: TransactionMeta[] = [];\n\n try {\n remoteTransactions =\n await this.#remoteTransactionSource.fetchTransactions({\n address: account.address as Hex,\n chainIds,\n includeTokenTransfers,\n tags: finalTags,\n updateTransactions,\n });\n } catch (error: unknown) {\n log('Error while fetching remote transactions', error);\n return;\n }\n\n if (!remoteTransactions.length) {\n return;\n }\n\n this.#sortTransactionsByTime(remoteTransactions);\n\n log(\n 'Found potential transactions',\n remoteTransactions.length,\n remoteTransactions,\n );\n\n const localTransactions = this.#getLocalTransactions();\n\n const uniqueTransactions = remoteTransactions.filter(\n (tx) =>\n !localTransactions.some(\n (currentTx) =>\n currentTx.hash?.toLowerCase() === tx.hash?.toLowerCase() &&\n currentTx.txParams.from?.toLowerCase() ===\n tx.txParams.from?.toLowerCase() &&\n currentTx.type === tx.type,\n ),\n );\n\n if (!uniqueTransactions.length) {\n log('All transactions are already known');\n return;\n }\n\n log(\n 'Found unique transactions',\n uniqueTransactions.length,\n uniqueTransactions,\n );\n\n const trimmedTransactions = this.#trimTransactions([\n ...uniqueTransactions,\n ...localTransactions,\n ]);\n\n const uniqueTransactionIds = uniqueTransactions.map((tx) => tx.id);\n\n const newTransactions = trimmedTransactions.filter((tx) =>\n uniqueTransactionIds.includes(tx.id),\n );\n\n if (!newTransactions.length) {\n log('All unique transactions truncated due to limit');\n return;\n }\n\n log('Adding new transactions', newTransactions.length, newTransactions);\n\n this.hub.emit('transactions', newTransactions);\n }\n\n #sortTransactionsByTime(transactions: TransactionMeta[]): void {\n transactions.sort((a, b) => (a.time < b.time ? -1 : 1));\n }\n\n #canStart(): boolean {\n return this.#isEnabled();\n }\n\n #getInterval(): number {\n return getIncomingTransactionsPollingInterval(this.#messenger);\n }\n\n #getTags(\n requestTags: string[] | undefined,\n isInterval: boolean | undefined,\n ): string[] | undefined {\n const tags = [];\n\n if (this.#client) {\n tags.push(this.#client);\n }\n\n if (requestTags?.length) {\n tags.push(...requestTags);\n } else if (isInterval) {\n tags.push(TAG_POLLING);\n }\n\n return tags?.length ? tags : undefined;\n }\n\n #onNetworkStatusChanged(chainIds: string[], status: 'up' | 'down'): void {\n if (!this.#useBackendWebSocketService) {\n return;\n }\n\n let hasChanges = false;\n\n for (const caip2ChainId of chainIds) {\n const hexChainId = caip2ToHex(caip2ChainId);\n\n if (!hexChainId || !SUPPORTED_CHAIN_IDS.includes(hexChainId)) {\n log('Chain ID not recognized or not supported', {\n caip2ChainId,\n hexChainId,\n });\n continue;\n }\n\n if (status === 'up') {\n const index = this.#chainsToPoll.indexOf(hexChainId);\n if (index !== -1) {\n this.#chainsToPoll.splice(index, 1);\n hasChanges = true;\n log('Supported network came up, removed from polling list', {\n chainId: hexChainId,\n });\n }\n } else if (\n status === 'down' &&\n !this.#chainsToPoll.includes(hexChainId)\n ) {\n this.#chainsToPoll.push(hexChainId);\n hasChanges = true;\n log('Supported network went down, added to polling list', {\n chainId: hexChainId,\n });\n }\n }\n\n if (!hasChanges) {\n log('No changes to polling list', {\n chainsToPoll: this.#chainsToPoll,\n });\n return;\n }\n\n if (this.#chainsToPoll.length === 0) {\n log('Stopping fallback polling - all networks up');\n this.stop();\n } else {\n log('Starting fallback polling - some networks need polling', {\n chainsToPoll: this.#chainsToPoll,\n });\n this.#startPolling();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IncomingTransactionHelper.mjs","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,YAAY,eAAe;AAElC,OAAO,EAAE,mBAAmB,EAAE,iDAA6C;AAE3E,OAAO,EAAE,0BAA0B,IAAI,GAAG,EAAE,sBAAkB;AAE9D,OAAO,EACL,sCAAsC,EACtC,uDAAuD,EACxD,mCAA+B;AAChC,OAAO,EAAE,UAAU,EAAE,2BAAuB;AAE5C,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,+CAA6B,CAAA;AAC/B,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AAmBD,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC,MAAM,OAAO,yBAAyB;IAgEpC,YAAY,EACV,MAAM,EACN,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,GAanB;;QAnFQ,oDAAiB;QAEjB,+DAEP;QAEO,kEAA+C;QAE/C,mEAAiC;QAEjC,uDAA0B;QAEnC,uDAAoB;QAEpB,wDAAqB;QAEZ,uDAA2C;QAE3C,qEAAkD;QAE3D,uDAAqB;QAEZ,8DAEc;QAEvB,yEAAuC,KAAK,EAAC;QAEpC,gEAA8B;QAE9B,wEAAqC;QAE9C,8EAA8E;QACrE,kDAAuB,CAAC,GAAG,mBAAmB,CAAC,EAAC;QAEhD,mEAAiC,CACxC,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,CAAC;QACnD,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,wDAAwD,EAAE;YAC5D,YAAY,EAAE,uBAAA,IAAI,+CAAc;SACjC,CAAC,CAAC;QACH,uBAAA,IAAI,qFAAc,MAAlB,IAAI,CAAgB,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["import type { AccountsController } from '@metamask/accounts-controller';\nimport type {\n Transaction as AccountActivityTransaction,\n WebSocketConnectionInfo,\n} from '@metamask/core-backend';\nimport type { Hex } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { SUPPORTED_CHAIN_IDS } from './AccountsApiRemoteTransactionSource';\nimport type { TransactionControllerMessenger } from '..';\nimport { incomingTransactionsLogger as log } from '../logger';\nimport type { RemoteTransactionSource, TransactionMeta } from '../types';\nimport {\n getIncomingTransactionsPollingInterval,\n isIncomingTransactionsUseBackendWebSocketServiceEnabled,\n} from '../utils/feature-flags';\nimport { caip2ToHex } from '../utils/utils';\n\nexport enum WebSocketState {\n CONNECTED = 'connected',\n DISCONNECTED = 'disconnected',\n}\n\nexport type IncomingTransactionOptions = {\n /** Name of the client to include in requests. */\n client?: string;\n\n /** Whether to retrieve incoming token transfers. Defaults to false. */\n includeTokenTransfers?: boolean;\n\n /** Callback to determine if incoming transaction polling is enabled. */\n isEnabled?: () => boolean;\n\n /** @deprecated No longer used. */\n queryEntireHistory?: boolean;\n\n /** Whether to retrieve outgoing transactions. Defaults to false. */\n updateTransactions?: boolean;\n};\n\nconst TAG_POLLING = 'automatic-polling';\n\nexport class IncomingTransactionHelper {\n hub: EventEmitter;\n\n readonly #client?: string;\n\n readonly #getCurrentAccount: () => ReturnType<\n AccountsController['getSelectedAccount']\n >;\n\n readonly #getLocalTransactions: () => TransactionMeta[];\n\n readonly #includeTokenTransfers?: boolean;\n\n readonly #isEnabled: () => boolean;\n\n #isRunning: boolean;\n\n #isUpdating: boolean;\n\n readonly #messenger: TransactionControllerMessenger;\n\n readonly #remoteTransactionSource: RemoteTransactionSource;\n\n #timeoutId?: unknown;\n\n readonly #trimTransactions: (\n transactions: TransactionMeta[],\n ) => TransactionMeta[];\n\n #isTransactionHistoryRetrievalActive = false;\n\n readonly #updateTransactions?: boolean;\n\n readonly #useBackendWebSocketService: boolean;\n\n // Chains that need polling (start with all supported, remove as they come up)\n readonly #chainsToPoll: Hex[] = [...SUPPORTED_CHAIN_IDS];\n\n readonly #connectionStateChangedHandler = (\n connectionInfo: WebSocketConnectionInfo,\n ): void => {\n this.#onConnectionStateChanged(connectionInfo);\n };\n\n readonly #transactionUpdatedHandler = (\n transaction: AccountActivityTransaction,\n ): void => {\n this.#onTransactionUpdated(transaction);\n };\n\n readonly #selectedAccountChangedHandler = (): void => {\n this.#onSelectedAccountChanged();\n };\n\n readonly #statusChangedHandler = ({\n chainIds,\n status,\n }: {\n chainIds: string[];\n status: 'up' | 'down';\n }): void => {\n this.#onNetworkStatusChanged(chainIds, status);\n };\n\n constructor({\n client,\n getCurrentAccount,\n getLocalTransactions,\n includeTokenTransfers,\n isEnabled,\n messenger,\n remoteTransactionSource,\n trimTransactions,\n updateTransactions,\n }: {\n client?: string;\n getCurrentAccount: () => ReturnType<\n AccountsController['getSelectedAccount']\n >;\n getLocalTransactions: () => TransactionMeta[];\n includeTokenTransfers?: boolean;\n isEnabled?: () => boolean;\n messenger: TransactionControllerMessenger;\n remoteTransactionSource: RemoteTransactionSource;\n trimTransactions: (transactions: TransactionMeta[]) => TransactionMeta[];\n updateTransactions?: boolean;\n }) {\n this.hub = new EventEmitter();\n\n this.#client = client;\n this.#getCurrentAccount = getCurrentAccount;\n this.#getLocalTransactions = getLocalTransactions;\n this.#includeTokenTransfers = includeTokenTransfers;\n this.#isEnabled = isEnabled ?? ((): boolean => true);\n this.#isRunning = false;\n this.#isUpdating = false;\n this.#messenger = messenger;\n this.#remoteTransactionSource = remoteTransactionSource;\n this.#trimTransactions = trimTransactions;\n this.#updateTransactions = updateTransactions;\n this.#useBackendWebSocketService =\n isIncomingTransactionsUseBackendWebSocketServiceEnabled(messenger);\n\n if (this.#useBackendWebSocketService) {\n this.#messenger.subscribe(\n 'BackendWebSocketService:connectionStateChanged',\n this.#connectionStateChangedHandler,\n );\n\n this.#messenger.subscribe(\n 'AccountActivityService:statusChanged',\n this.#statusChangedHandler,\n );\n }\n }\n\n start(): void {\n // When websockets are disabled, allow normal polling (legacy mode)\n if (this.#useBackendWebSocketService) {\n return;\n }\n\n this.#startPolling(true);\n }\n\n #startPolling(initialPolling = false): void {\n if (this.#isRunning) {\n return;\n }\n\n if (!this.#canStart()) {\n return;\n }\n\n const interval = this.#getInterval();\n\n log('Started polling', {\n interval,\n });\n\n this.#isRunning = true;\n\n if (this.#isUpdating) {\n return;\n }\n\n this.#onInterval().catch((error) => {\n log(initialPolling ? 'Initial polling failed' : 'Polling failed', error);\n });\n }\n\n stop(): void {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId as number);\n }\n\n if (!this.#isRunning) {\n return;\n }\n\n this.#isRunning = false;\n\n log('Stopped polling');\n }\n\n #onConnectionStateChanged(connectionInfo: WebSocketConnectionInfo): void {\n if (connectionInfo.state === WebSocketState.CONNECTED) {\n log('WebSocket connected, starting enhanced mode');\n this.#startTransactionHistoryRetrieval();\n } else if (connectionInfo.state === WebSocketState.DISCONNECTED) {\n log('WebSocket disconnected, stopping enhanced mode');\n this.#stopTransactionHistoryRetrieval();\n }\n }\n\n #startTransactionHistoryRetrieval(): void {\n if (!this.#canStart()) {\n return;\n }\n\n if (this.#isTransactionHistoryRetrievalActive) {\n return;\n }\n\n log('Started transaction history retrieval (event-driven)');\n\n this.#isTransactionHistoryRetrievalActive = true;\n\n this.update().catch((error) => {\n log('Initial update in transaction history retrieval failed', error);\n });\n\n this.#messenger.subscribe(\n 'AccountActivityService:transactionUpdated',\n this.#transactionUpdatedHandler,\n );\n\n this.#messenger.subscribe(\n 'AccountsController:selectedAccountChange',\n this.#selectedAccountChangedHandler,\n );\n }\n\n #stopTransactionHistoryRetrieval(): void {\n if (!this.#isTransactionHistoryRetrievalActive) {\n return;\n }\n\n log('Stopped transaction history retrieval');\n\n this.#isTransactionHistoryRetrievalActive = false;\n\n this.#messenger.unsubscribe(\n 'AccountActivityService:transactionUpdated',\n this.#transactionUpdatedHandler,\n );\n\n this.#messenger.unsubscribe(\n 'AccountsController:selectedAccountChange',\n this.#selectedAccountChangedHandler,\n );\n }\n\n #onTransactionUpdated(transaction: AccountActivityTransaction): void {\n log('Received relevant transaction update, triggering update', {\n txId: transaction.id,\n chain: transaction.chain,\n });\n\n this.update().catch((error) => {\n log('Update after transaction event failed', error);\n });\n }\n\n #onSelectedAccountChanged(): void {\n log('Selected account changed, triggering update');\n\n this.update().catch((error) => {\n log('Update after account change failed', error);\n });\n }\n\n async #onInterval(): Promise<void> {\n this.#isUpdating = true;\n\n try {\n // When websockets enabled, only poll chains that are not confirmed up\n const chainIds = this.#useBackendWebSocketService\n ? this.#chainsToPoll\n : undefined;\n await this.update({ chainIds, isInterval: true });\n } catch (error) {\n console.error('Error while checking incoming transactions', error);\n }\n\n this.#isUpdating = false;\n\n if (this.#isRunning) {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId as number);\n }\n\n this.#timeoutId = setTimeout(\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n () => this.#onInterval(),\n this.#getInterval(),\n );\n }\n }\n\n async update({\n chainIds,\n isInterval,\n tags,\n }: {\n chainIds?: Hex[];\n isInterval?: boolean;\n tags?: string[];\n } = {}): Promise<void> {\n const finalTags = this.#getTags(tags, isInterval);\n\n log('Checking for incoming transactions', {\n isInterval: Boolean(isInterval),\n tags: finalTags,\n });\n\n if (!this.#canStart()) {\n return;\n }\n\n const account = this.#getCurrentAccount();\n const includeTokenTransfers = this.#includeTokenTransfers ?? true;\n const updateTransactions = this.#updateTransactions ?? false;\n\n let remoteTransactions: TransactionMeta[] = [];\n\n try {\n remoteTransactions =\n await this.#remoteTransactionSource.fetchTransactions({\n address: account.address as Hex,\n chainIds,\n includeTokenTransfers,\n tags: finalTags,\n updateTransactions,\n });\n } catch (error: unknown) {\n log('Error while fetching remote transactions', error);\n return;\n }\n\n if (!remoteTransactions.length) {\n return;\n }\n\n this.#sortTransactionsByTime(remoteTransactions);\n\n log(\n 'Found potential transactions',\n remoteTransactions.length,\n remoteTransactions,\n );\n\n const localTransactions = this.#getLocalTransactions();\n\n const uniqueTransactions = remoteTransactions.filter(\n (tx) =>\n !localTransactions.some(\n (currentTx) =>\n currentTx.hash?.toLowerCase() === tx.hash?.toLowerCase() &&\n currentTx.txParams.from?.toLowerCase() ===\n tx.txParams.from?.toLowerCase() &&\n currentTx.type === tx.type,\n ),\n );\n\n if (!uniqueTransactions.length) {\n log('All transactions are already known');\n return;\n }\n\n log(\n 'Found unique transactions',\n uniqueTransactions.length,\n uniqueTransactions,\n );\n\n const trimmedTransactions = this.#trimTransactions([\n ...uniqueTransactions,\n ...localTransactions,\n ]);\n\n const uniqueTransactionIds = uniqueTransactions.map((tx) => tx.id);\n\n const newTransactions = trimmedTransactions.filter((tx) =>\n uniqueTransactionIds.includes(tx.id),\n );\n\n if (!newTransactions.length) {\n log('All unique transactions truncated due to limit');\n return;\n }\n\n log('Adding new transactions', newTransactions.length, newTransactions);\n\n this.hub.emit('transactions', newTransactions);\n }\n\n #sortTransactionsByTime(transactions: TransactionMeta[]): void {\n transactions.sort((a, b) => (a.time < b.time ? -1 : 1));\n }\n\n #canStart(): boolean {\n return this.#isEnabled();\n }\n\n #getInterval(): number {\n return getIncomingTransactionsPollingInterval(this.#messenger);\n }\n\n #getTags(\n requestTags: string[] | undefined,\n isInterval: boolean | undefined,\n ): string[] | undefined {\n const tags = [];\n\n if (this.#client) {\n tags.push(this.#client);\n }\n\n if (requestTags?.length) {\n tags.push(...requestTags);\n } else if (isInterval) {\n tags.push(TAG_POLLING);\n }\n\n return tags?.length ? tags : undefined;\n }\n\n #onNetworkStatusChanged(chainIds: string[], status: 'up' | 'down'): void {\n if (!this.#useBackendWebSocketService) {\n return;\n }\n\n let hasChanges = false;\n\n for (const caip2ChainId of chainIds) {\n const hexChainId = caip2ToHex(caip2ChainId);\n\n if (!hexChainId || !SUPPORTED_CHAIN_IDS.includes(hexChainId)) {\n log('Chain ID not recognized or not supported', {\n caip2ChainId,\n hexChainId,\n });\n continue;\n }\n\n if (status === 'up') {\n const index = this.#chainsToPoll.indexOf(hexChainId);\n if (index !== -1) {\n this.#chainsToPoll.splice(index, 1);\n hasChanges = true;\n log('Supported network came up, removed from polling list', {\n chainId: hexChainId,\n });\n }\n } else if (\n status === 'down' &&\n !this.#chainsToPoll.includes(hexChainId)\n ) {\n this.#chainsToPoll.push(hexChainId);\n hasChanges = true;\n log('Supported network went down, added to polling list', {\n chainId: hexChainId,\n });\n }\n }\n\n if (!hasChanges) {\n log('No changes to polling list', {\n chainsToPoll: this.#chainsToPoll,\n });\n return;\n }\n\n if (this.#chainsToPoll.length === 0) {\n log('Stopping fallback polling - all networks up');\n this.stop();\n } else {\n log('Starting fallback polling - some networks need polling', {\n chainsToPoll: this.#chainsToPoll,\n });\n this.#startPolling();\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/transaction-controller",
|
|
3
|
-
"version": "63.
|
|
3
|
+
"version": "63.2.0",
|
|
4
4
|
"description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|