-
-
Notifications
You must be signed in to change notification settings - Fork 187
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: Add firstTimeInteraction
to transactionMeta
#4895
base: main
Are you sure you want to change the base?
feat: Add firstTimeInteraction
to transactionMeta
#4895
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.
|
…ess-for-the-first-time
@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.
|
import { FirstTimeInteractionError } from '../errors'; | ||
import { projectLogger } from '../logger'; | ||
|
||
export const BASE_URL = 'https://accounts.api.cx.metamask.io'; |
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.
Should the name of this file reflect the API itself so accounts-api.ts
?
I've also added this same util (for a different endpoint) for the ongoing incoming transactions refactor, so should we match the name and location to simplify the merge?
): Promise<FirstTimeInteractionResponse> { | ||
const url = await getFirstTimeInteractionUrl(request); | ||
|
||
log('Sending request', url, request); |
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.
As we'll use additional endpoints for incoming transactions, should we keep logs more specific so Sending first time request
?
if (responseJson.error) { | ||
const { message, code } = responseJson.error; | ||
|
||
if (message === FAILED_TO_PARSE_MESSAGE) { |
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.
Is there an error code we could use instead to keep it less coupled?
if (responseJson.error) { | ||
const { message, code } = responseJson.error; | ||
|
||
if (message === FAILED_TO_PARSE_MESSAGE) { |
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.
Should we add a comment to clarify why we can assume this specific error means it's a first time interaction?
|
||
return { | ||
isFirstTimeInteraction: | ||
responseJson?.count === 0 || responseJson?.count === undefined, |
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.
Will the second condition mean we return true
if there is no response JSON at all?
log('Sending request', url, request); | ||
|
||
const response = await fetch(url, { | ||
method: 'GET', |
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.
I can't find the name currently, but there is a specific header we should use so the API team can track the source of the requests.
let firstTimeInteractionResponse: FirstTimeInteractionResponse; | ||
|
||
try { | ||
validateFirstTimeInteraction(request); |
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.
The params are validated when we first add the transaction in addTransaction
, so why do we need to validate an object generated internally?
@@ -3614,6 +3627,73 @@ export class TransactionController extends BaseController< | |||
return transactionMeta; | |||
} | |||
|
|||
async #updateFirstInteraction( |
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.
I don't think we should do anything now, but if these API usages grow, we could standardise this pattern to reduce some duplication.
/** | ||
* Whether the transaction is the first time interaction. | ||
*/ | ||
firstTimeInteraction?: boolean; |
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.
Do we also need a firstTimeInteractionLoading
property so the UI can more easily differentiate loading and disabled?
|
||
firstTimeInteractionResponse = await this.#trace( | ||
{ name: 'FirstTimeInteraction', parentContext: traceContext }, | ||
() => getFirstTimeInteraction(request), |
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.
Do we need a toggle to disable this or is that a future ticket?
At what point is it easier to provide a single isExternalApiDisabled
callback?
Explanation
This PR adds
firstTimeInteraction
totransactionMeta
by callinghttps://primitives.api.cx.metamask.io/
APIrelationships
endpoint.For more information please see docs here: https://primitives.api.cx.metamask.io/docs#/Account%20%7C%20Relationships/IndexedChainDataAPIController_getAccountAddressRelationship
References
Related to: https://github.com/MetaMask/MetaMask-planning/issues/3040
Changelog
@metamask/transaction-controller
firstTimeInteraction
totransactionMeta
https://primitives.api.cx.metamask.io
relationships
endpoint.Checklist