Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add power users survey support #27361

Merged
merged 60 commits into from
Oct 3, 2024
Merged

feat: add power users survey support #27361

merged 60 commits into from
Oct 3, 2024

Conversation

jonybur
Copy link
Contributor

@jonybur jonybur commented Sep 24, 2024

Description

2.mp4

Open in GitHub Codespaces

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/3259

Manual testing steps

  1. Show toast
    WHEN Popup is shown << Toast should not be shown on Notification, i.e. Confirmation screen
    AND User is logged in
    AND API is called with hashed user id
    AND API returns PowerUser (true)
    THEN Toast is shown

  2. Open survey
    WHEN User clicks on survey link
    THEN Open url
    AND Close toast

  3. Close toast
    WHEN User clicks close icon
    THEN Close toast and don't show again

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@jonybur
Copy link
Contributor Author

jonybur commented Sep 24, 2024

This only happen for the account that is logged in when opening the app. We should probably store:

{ [account_address]: lastSurveyId, (...) }

return;
}

const surveyId = 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is set to 1, we should remove this

Copy link

@andreahaku andreahaku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a very few minor comments. Good job and I'm taking it as a referral for the task I'm working on ;) thanks

ui/components/ui/survey-toast/survey-toast.tsx Outdated Show resolved Hide resolved
const internalAccount = useSelector(getSelectedInternalAccount);

useEffect(() => {
if (!basicFunctionality || !internalAccount?.address) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to do this request if participateInMetaMetrics is off? I don't think so but we should check with Hester.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task says that if participateInMetametrics would affect the tracking, not the survey; I'll check with Hester though.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonybur we would not show the survey if participateInMetaMetrics is off. We would not have the MMID to check if the survey should be shown. On the ticket I described an ambiguous "Handle case where user has not opted into MetaMetrics and does not have a MetaMetrics ID". We should ensure that not getting an MMID results in a bug. Probably best way to do that is to first check if the user has participateInMetaMetrics ON.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added a new case where the survey is not fetched if participateInMetametrics is off

@@ -0,0 +1,113 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create an E2E with a mocked API endpoint to ensure the survey displays when it should.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it as a unit test, that mocks the return value and checks that the toast is rendered/not rendered

@jonybur jonybur added the DO-NOT-MERGE Pull requests that should not be merged label Sep 25, 2024
@jonybur jonybur marked this pull request as ready for review September 25, 2024 11:46
@jonybur jonybur requested a review from a team as a code owner September 25, 2024 11:46
@jonybur jonybur requested a review from darkwing September 25, 2024 11:56
@metamaskbot
Copy link
Collaborator

Builds ready [2c3338d]
Page Load Metrics (1890 ± 133 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint33528361813433208
domContentLoaded162227171871254122
load163928631890276133
domInteractive18116412110
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 160 Bytes (0.00%)
  • ui: 4.73 KiB (0.06%)
  • common: 254 Bytes (0.00%)

`${ACCOUNTS_PROD_API_BASE_URL}/v1/users/fake-metrics-id/surveys`,
`${ACCOUNTS_PROD_API_BASE_URL}/v1/users/fake-metrics-fd20/surveys`,
`${ACCOUNTS_PROD_API_BASE_URL}/v1/users/test-metrics-id/surveys`,
`${ACCOUNTS_PROD_API_BASE_URL}/v1/users/invalid-metrics-id/surveys`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do it so that any calls to /v1/users/:any-metrics-id/surveys returns:

{
  statusCode: 200,
  json: {
    userId: '0x123',
    surveys: {},
  }
}

andreahaku
andreahaku previously approved these changes Oct 2, 2024
Copy link

@andreahaku andreahaku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@metamaskbot
Copy link
Collaborator

Builds ready [a7b9f4b]
Page Load Metrics (1828 ± 55 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint22221021681458220
domContentLoaded15762081180011455
load15792086182811555
domInteractive19236595225
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 160 Bytes (0.00%)
  • ui: 4.72 KiB (0.06%)
  • common: 254 Bytes (0.00%)

Copy link

@andreahaku andreahaku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@EtherWizard33
Copy link

really like the usage of given-when-then in the manual steps, if I would suggest a small improvement for added clarity, would be to use 'given' as well, something like this:

  1. Show Toast

    • Given the user is logged in, and the API has been called with a hashed user ID.
    • And the API returns PowerUser status as true.
    • When a popup is displayed.
    • Then show a toast notification.
    • And ensure the toast notification is not displayed on the notification or confirmation screen.
  2. Open Survey

    • Given a toast notification is currently displayed.
    • When the user clicks on the survey link within the toast.
    • Then open the survey URL in a new window/tab.
    • And close the toast notification.
  3. Close Toast

    • When the user clicks the close icon on the toast notification.
    • Then close the toast notification.
    • And ensure the toast notification does not show again.

_survey.id <= lastViewedUserSurvey
) {
return;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You can improve the readability and efficiency of this code by simplifying the condition. Instead of checking if the object keys length is zero, you can directly check if the survey is falsy or if the survey ID is less than or equal to the last viewed survey ID.

if (!_survey?.id || _survey.id <= lastViewedUserSurvey) { return; }


const controller = new AbortController();

const fetchSurvey = async () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can useCallback for fetchSurvey
const fetchSurvey = useCallback(async () => { ... }, [ internalAccount?.address, lastViewedUserSurvey, basicFunctionality, metaMetricsId, fetchSurvey, ]);

@metamaskbot
Copy link
Collaborator

Builds ready [4e8c2c8]
Page Load Metrics (1703 ± 72 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint14992286170716680
domContentLoaded14852093167813665
load14932171170315072
domInteractive227239157
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 160 Bytes (0.00%)
  • ui: 4.72 KiB (0.06%)
  • common: 261 Bytes (0.00%)

Copy link

sonarqubecloud bot commented Oct 3, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [4e8c2c8]
Page Load Metrics (1703 ± 72 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint14992286170716680
domContentLoaded14852093167813665
load14932171170315072
domInteractive227239157
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 160 Bytes (0.00%)
  • ui: 4.72 KiB (0.06%)
  • common: 261 Bytes (0.00%)

@jonybur jonybur enabled auto-merge October 3, 2024 00:45
@metamaskbot
Copy link
Collaborator

Builds ready [887de62]
Page Load Metrics (1720 ± 62 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint16032250172714469
domContentLoaded15962076169711153
load16082128172012962
domInteractive258441189
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 160 Bytes (0.00%)
  • ui: 4.72 KiB (0.06%)
  • common: 261 Bytes (0.00%)

Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving on behalf of privacy reviewers. The api request for the survey is only made if the user is opted into basic functionality and metametrics

@jonybur jonybur added this pull request to the merge queue Oct 3, 2024
Merged via the queue into develop with commit cf22b67 Oct 3, 2024
77 checks passed
@jonybur jonybur deleted the jb-power-users branch October 3, 2024 14:00
@github-actions github-actions bot locked and limited conversation to collaborators Oct 3, 2024
@metamaskbot metamaskbot added the release-12.6.0 Issue or pull request that will be included in release 12.6.0 label Oct 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.6.0 Issue or pull request that will be included in release 12.6.0 team-wallet-ux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants