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: enable preview token #27809

Merged
merged 10 commits into from
Oct 23, 2024
7 changes: 6 additions & 1 deletion ui/hooks/metamask-notifications/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ export function useListNotifications(): {
setLoading(true);
setError(null);

const urlParams = new URLSearchParams(window.location.search);
const previewToken = urlParams.get('previewToken');

try {
const data = await dispatch(fetchAndUpdateMetamaskNotifications());
const data = await dispatch(
fetchAndUpdateMetamaskNotifications(previewToken ?? undefined),
);
setNotificationsData(data as unknown as Notification[]);
return data as unknown as Notification[];
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions ui/store/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,7 @@ describe('Actions', () => {

const fetchAndUpdateMetamaskNotificationsStub = sinon
.stub()
.callsFake((cb) => cb());
.callsFake((_, cb) => cb());
const forceUpdateMetamaskStateStub = sinon.stub().callsFake((cb) => cb());

background.getApi.returns({
Expand All @@ -2280,7 +2280,7 @@ describe('Actions', () => {

const fetchAndUpdateMetamaskNotificationsStub = sinon
.stub()
.callsFake((cb) => cb(error));
.callsFake((_, cb) => cb(error));
const forceUpdateMetamaskStateStub = sinon
.stub()
.callsFake((cb) => cb(error));
Expand Down
14 changes: 6 additions & 8 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5423,22 +5423,20 @@ export function updateOnChainTriggersByAccount(
/**
* Fetches and updates MetaMask notifications.
*
* This function sends a request to the background script to fetch the latest notifications and update the state accordingly.
* Upon success, it dispatches an action with type `FETCH_AND_UPDATE_METAMASK_NOTIFICATIONS` to update the Redux state.
* This function sends a request to the background script to fetch the latest notifications.
* If the operation encounters an error, it logs the error message and rethrows the error to ensure it is handled appropriately.
*
* @param previewToken - Optional preview token for fetching draft feature announcements.
* @returns A thunk action that, when dispatched, attempts to fetch and update MetaMask notifications.
*/
export function fetchAndUpdateMetamaskNotifications(): ThunkAction<
void,
MetaMaskReduxState,
unknown,
AnyAction
> {
export function fetchAndUpdateMetamaskNotifications(
previewToken?: string,
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
return async () => {
try {
const response = await submitRequestToBackground(
'fetchAndUpdateMetamaskNotifications',
[previewToken],
);
return response;
} catch (error) {
Expand Down