-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Remove Onyx.connect() for the key: ONYXKEYS.ACCOUNT in src/libs/actions/Delegate.ts #68979
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
24214de
pass delegatedAccess as prop
allgandalf 035d231
update prop passing in functions
allgandalf d30a626
fix changed files ESlint
allgandalf 779feb1
add delegate tests
allgandalf 84e7c28
fix eslint
allgandalf 8ed25b7
Merge branch 'Expensify:main' into fix/66493
allgandalf 23442a6
update package json warning
allgandalf d75b74b
Merge branch 'main' into fix/66493
allgandalf 8ca10c5
extract type
allgandalf b08f983
update reviewer suggestion
allgandalf bbcbfff
Apply suggestion from @ikevin127
allgandalf e880c90
Apply suggestion from @ikevin127
allgandalf 165b76e
Apply suggestion from @allgandalf
allgandalf 25457d9
fix imports
allgandalf 43f5f5a
fix type error
allgandalf a4a6896
Merge branch 'main' into fix/66493
allgandalf 621a6ea
fix update delegate role
allgandalf e522212
Merge branch 'Expensify:main' into fix/66493
allgandalf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,7 +1,9 @@ | ||
| import Onyx from 'react-native-onyx'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import CONFIG from '@src/CONFIG'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Account} from '@src/types/onyx'; | ||
| import type Response from '@src/types/onyx/Response'; | ||
| import {isConnectedAsDelegate, restoreDelegateSession} from './actions/Delegate'; | ||
| import updateSessionAuthTokens from './actions/Session/updateSessionAuthTokens'; | ||
|
|
@@ -43,6 +45,16 @@ Onyx.connectWithoutView({ | |
| }, | ||
| }); | ||
|
|
||
| let account: OnyxEntry<Account>; | ||
| // Authentication lib is not connected to any changes on the UI | ||
| // So it is okay to use connectWithoutView here. | ||
| Onyx.connectWithoutView({ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ikevin127 , please check this thread for more info: https://new.expensify.com//r/5512877217123728/7684504551749862656 We decided to use |
||
| key: ONYXKEYS.ACCOUNT, | ||
| callback: (value) => { | ||
| account = value; | ||
| }, | ||
| }); | ||
|
|
||
| function Authenticate(parameters: Parameters): Promise<Response | void> { | ||
| const commandName = 'Authenticate'; | ||
|
|
||
|
|
@@ -154,7 +166,7 @@ function reauthenticate(command = ''): Promise<boolean> { | |
|
|
||
| // If we reauthenticate due to an expired delegate token, restore the delegate's original account. | ||
| // This is because the credentials used to reauthenticate were for the delegate's original account, and not for the account they were connected as. | ||
| if (isConnectedAsDelegate()) { | ||
| if (isConnectedAsDelegate({delegatedAccess: account?.delegatedAccess})) { | ||
| Log.info('Reauthenticate while connected as a delegate. Restoring original account.'); | ||
| restoreDelegateSession(response); | ||
| return true; | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
NAB: 🟡 Potential silent no-op when
delegatedAccessis not yet available:account?.delegatedAccessisundefined(e.g., early in app startup),connect()returns early by design and nothing happens. From the user perspective: taps “Switch account” do nothing without feedback.disabledtocreateBaseMenuItem:badgeText: translate('delegate.role', {role}), + disabled: !!account?.delegatedAccess, onSelected: () => {Uh oh!
There was an error while loading. Please reload this page.
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.
@ikevin127 AFAIK, we don't have the switcher shown on the UI unless we have
accountobject present, please correct me if i am wrong