-
-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Re-simulate focused transactions every 3000 ms #5189
base: main
Are you sure you want to change the base?
Conversation
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
f159aea
to
ea69888
Compare
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@@ -1857,6 +1871,29 @@ export class TransactionController extends BaseController< | |||
return this.getTransaction(txId); | |||
} | |||
|
|||
/** | |||
* Update the isFocus state of a transaction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a new empty line after this to satisfy lint:
* Update the isFocus state of a transaction. | |
* Update the isFocus state of a transaction. | |
} | ||
}; | ||
|
||
const intervalId = setInterval(listener, RESIMULATE_INTERVAL_MS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is producing a lint warning because setInterval
does not await the promise. Perhaps that is intentional and so we need to disable the rule?
const intervalId = setInterval(listener, RESIMULATE_INTERVAL_MS); | |
// eslint-disable-next-line @typescript-eslint/no-misused-promises | |
const intervalId = setInterval(listener, RESIMULATE_INTERVAL_MS); |
updateSimulationData: (transactionMeta: TransactionMeta) => void; | ||
}; | ||
|
||
export class ResimulateHelper { | ||
// Map of transactionId <=> isActive | ||
readonly #activeResimulations: Map<string, boolean> = new Map(); | ||
|
||
// Map of transactionId <=> intervalId | ||
readonly #intervalIds: Map<string, NodeJS.Timeout> = new Map(); | ||
|
||
readonly #getTransactions: () => TransactionMeta[]; | ||
|
||
readonly #updateSimulationData: (transactionMeta: TransactionMeta) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does updateSimulationData
need to expect a function that returns a Promise?
updateSimulationData: (transactionMeta: TransactionMeta) => void; | |
}; | |
export class ResimulateHelper { | |
// Map of transactionId <=> isActive | |
readonly #activeResimulations: Map<string, boolean> = new Map(); | |
// Map of transactionId <=> intervalId | |
readonly #intervalIds: Map<string, NodeJS.Timeout> = new Map(); | |
readonly #getTransactions: () => TransactionMeta[]; | |
readonly #updateSimulationData: (transactionMeta: TransactionMeta) => void; | |
updateSimulationData: (transactionMeta: TransactionMeta) => Promise<void>; | |
}; | |
export class ResimulateHelper { | |
// Map of transactionId <=> isActive | |
readonly #activeResimulations: Map<string, boolean> = new Map(); | |
// Map of transactionId <=> intervalId | |
readonly #intervalIds: Map<string, NodeJS.Timeout> = new Map(); | |
readonly #getTransactions: () => TransactionMeta[]; | |
readonly #updateSimulationData: (transactionMeta: TransactionMeta) => Promise<void>; |
@@ -86,7 +86,7 @@ import { | |||
getTransactionLayer1GasFee, | |||
updateTransactionLayer1GasFee, | |||
} from './utils/layer1-gas-fee-flow'; | |||
import { shouldResimulate } from './utils/resimulate'; | |||
import { shouldResimulate } from './helpers/ResimulateHelper'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to keep the list of imports sorted and satisfy lint, this line should be moved up to go below the following line:
import { PendingTransactionTracker } from './helpers/PendingTransactionTracker';
Explanation
This PR adds
ResimulateHelper
, which focuses ontransactionMeta.isFocused
property and re-simulates transaction depending on that value.In order to capsulate re-simulation logic, this PR also relocates other utility functions under the new created
ResimulationHelper.ts
file.References
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/3922
Extension PR: MetaMask/metamask-extension#29878
Changelog
@metamask/transaction-controller
isFocused
property ontransactionMeta
isFocused
property is expected to set by client.isFocused
istrue
.updateTransactionFocus
function to update theisFocused
property ontransactionMeta
.Checklist