forked from MetaMask/metamask-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add token autodetect modal (MetaMask#24281)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Add in recommended auto token enablement button in new Extension app update, once we enable auto token detection by default for new users, for existing users, we need to get them to turn on auto token detection as well. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24281?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. you are an existing user and you have token autodetection off 2. once the upgrade will be done , you should see the modal below right after what's new pop up 3. if you have it of and you decide to disable , you should see the pop up once ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** No Modal was displayed ### **After** Existing users with toggle off https://github.com/MetaMask/metamask-extension/assets/26223211/2ff49f38-e652-4287-9b0a-a7092b8a1812 Users with toggle on and want to disable it ( the modal should be displayed once ) https://github.com/MetaMask/metamask-extension/assets/26223211/4438312f-cbb3-47f1-bc80-d1158b73e66a ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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.
- Loading branch information
Showing
30 changed files
with
448 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './smart-transactions'; | ||
export * from './feature-flags'; | ||
export * from './token-auto-detect'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { getUseTokenDetection } from '../../../ui/selectors/selectors'; | ||
|
||
type TokenAutoDetectionMetaMaskState = { | ||
metamask: { | ||
preferences: { | ||
showTokenAutodetectModal: boolean | null; | ||
}; | ||
showTokenAutodetectModalOnUpgrade: boolean | null; | ||
}; | ||
}; | ||
|
||
export const getShowTokenAutodetectModal = ( | ||
state: TokenAutoDetectionMetaMaskState, | ||
): boolean | null => { | ||
return state.metamask.preferences?.showTokenAutodetectModal; | ||
}; | ||
|
||
export const getIsShowTokenAutodetectModal = ( | ||
state: TokenAutoDetectionMetaMaskState, | ||
) => { | ||
// Upgrade case | ||
if (state.metamask.showTokenAutodetectModalOnUpgrade === null) { | ||
return ( | ||
!getUseTokenDetection(state) && | ||
state.metamask.showTokenAutodetectModalOnUpgrade === null | ||
); | ||
} | ||
|
||
return ( | ||
!getUseTokenDetection(state) && getShowTokenAutodetectModal(state) === null | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
ui/components/app/auto-detect-token/auto-detect-token-modal.test.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import testData from '../../../../.storybook/test-data'; | ||
import configureStore from '../../../store/store'; | ||
import AutoDetectTokenModal from './auto-detect-token-modal'; | ||
|
||
const customData = { | ||
...testData, | ||
metamask: { | ||
...testData.metamask, | ||
currentCurrency: 'USD', | ||
intlLocale: 'en-US', | ||
}, | ||
}; | ||
const customStore = configureStore(customData); | ||
|
||
export default { | ||
title: 'Components/App/AutoDetectTokenModal', | ||
component: AutoDetectTokenModal, | ||
decorators: [ | ||
(Story) => ( | ||
<Provider store={customStore}> | ||
<Story /> | ||
</Provider> | ||
), | ||
], | ||
argTypes: { | ||
isOpen: { | ||
control: 'boolean', | ||
}, | ||
onClose: { action: 'onClose' }, | ||
}, | ||
args: { | ||
isOpen: true, | ||
}, | ||
}; | ||
|
||
const Template = (args) => <AutoDetectTokenModal {...args} />; | ||
|
||
export const ModalOpen = Template.bind({}); | ||
ModalOpen.args = { | ||
isOpen: true, | ||
}; | ||
|
||
export const ModalClosed = Template.bind({}); | ||
ModalClosed.args = { | ||
isOpen: false, | ||
}; |
Oops, something went wrong.