-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[Refactor] SetNameValuePair
#9677
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
Changes from all commits
8679228
50840cf
9c5a656
471a8ea
6977763
2b7af34
20db056
883f74c
03f22e1
f4a669b
d2ad164
08b420d
90ddc6b
dcd38a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -734,6 +734,7 @@ const CONST = { | |
| ONYX: { | ||
| METHOD: { | ||
| MERGE: 'merge', | ||
| SET: 'set', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,6 @@ import * as Pusher from '../Pusher/pusher'; | |
| import Log from '../Log'; | ||
| import NetworkConnection from '../NetworkConnection'; | ||
| import redirectToSignIn from './SignInRedirect'; | ||
| import NameValuePair from './NameValuePair'; | ||
| import Growl from '../Growl'; | ||
| import * as Localize from '../Localize'; | ||
| import * as CloseAccountActions from './CloseAccount'; | ||
|
|
@@ -267,6 +266,40 @@ function isBlockedFromConcierge(blockedFromConcierge) { | |
| return moment().isBefore(moment(blockedFromConcierge.expiresAt), 'day'); | ||
| } | ||
|
|
||
| /** | ||
| * Adds a paypal.me address for the user | ||
| * | ||
| * @param {String} address | ||
| */ | ||
| function addPaypalMeAddress(address) { | ||
| const optimisticData = [ | ||
| { | ||
| onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
| key: ONYXKEYS.NVP_PAYPAL_ME_ADDRESS, | ||
| value: address, | ||
| }, | ||
| ]; | ||
| API.write('AddPaypalMeAddress', { | ||
| value: address, | ||
| }, {optimisticData}); | ||
| } | ||
|
|
||
| /** | ||
| * Deletes a paypal.me address for the user | ||
| * | ||
| */ | ||
| function deletePaypalMeAddress() { | ||
| const optimisticData = [ | ||
| { | ||
| onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
| key: ONYXKEYS.NVP_PAYPAL_ME_ADDRESS, | ||
| value: '', | ||
| }, | ||
| ]; | ||
| API.write('DeletePaypalMeAddress', {}, {optimisticData}); | ||
|
Contributor
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. even if there is no value it feels weird to have this in a single line, unless linter asks it to be like this I would have in multiple lines
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. At first it was on multiple lines and it got strange too. What's your suggestion? ? |
||
| Growl.show(Localize.translateLocal('paymentsPage.deletePayPalSuccess'), CONST.GROWL.SUCCESS, 3000); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize our pusher subscription to listen for user changes | ||
| */ | ||
|
|
@@ -351,16 +384,51 @@ function subscribeToExpensifyCardUpdates() { | |
| * Sync preferredSkinTone with Onyx and Server | ||
| * @param {String} skinTone | ||
| */ | ||
| function setPreferredSkinTone(skinTone) { | ||
| NameValuePair.set(CONST.NVP.PREFERRED_EMOJI_SKIN_TONE, skinTone, ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE); | ||
| function updatePreferredSkinTone(skinTone) { | ||
| const optimisticData = [ | ||
| { | ||
| onyxMethod: CONST.ONYX.METHOD.SET, | ||
| key: ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, | ||
| value: skinTone, | ||
| }, | ||
| ]; | ||
| API.write('UpdatePreferredEmojiSkinTone', { | ||
| value: skinTone, | ||
| }, {optimisticData}); | ||
| } | ||
|
|
||
| /** | ||
| * Sync frequentlyUsedEmojis with Onyx and Server | ||
| * @param {Object[]} frequentlyUsedEmojis | ||
| */ | ||
| function setFrequentlyUsedEmojis(frequentlyUsedEmojis) { | ||
| NameValuePair.set(CONST.NVP.FREQUENTLY_USED_EMOJIS, frequentlyUsedEmojis, ONYXKEYS.FREQUENTLY_USED_EMOJIS); | ||
| function updateFrequentlyUsedEmojis(frequentlyUsedEmojis) { | ||
| const optimisticData = [ | ||
| { | ||
| onyxMethod: CONST.ONYX.METHOD.SET, | ||
| key: ONYXKEYS.FREQUENTLY_USED_EMOJIS, | ||
| value: frequentlyUsedEmojis, | ||
| }, | ||
| ]; | ||
| API.write('UpdateFrequentlyUsedEmojis', { | ||
| value: JSON.stringify(frequentlyUsedEmojis), | ||
| }, {optimisticData}); | ||
| } | ||
|
|
||
| /** | ||
| * Sync user chat priority mode with Onyx and Server | ||
| * @param {String} mode | ||
| */ | ||
| function updateChatPriorityMode(mode) { | ||
| const optimisticData = [ | ||
| { | ||
| onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
| key: ONYXKEYS.NVP_PRIORITY_MODE, | ||
| value: mode, | ||
| }, | ||
| ]; | ||
| API.write('UpdateChatPriorityMode', { | ||
| value: mode, | ||
| }, {optimisticData}); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -422,12 +490,15 @@ export { | |
| validateLogin, | ||
| isBlockedFromConcierge, | ||
| subscribeToUserEvents, | ||
| setPreferredSkinTone, | ||
| updatePreferredSkinTone, | ||
| setShouldUseSecureStaging, | ||
| clearUserErrorMessage, | ||
| subscribeToExpensifyCardUpdates, | ||
| setFrequentlyUsedEmojis, | ||
| updateFrequentlyUsedEmojis, | ||
| joinScreenShare, | ||
| clearScreenShareRequest, | ||
| generateStatementPDF, | ||
| deletePaypalMeAddress, | ||
| addPaypalMeAddress, | ||
| updateChatPriorityMode, | ||
| }; | ||
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'm actually curious why we are double storing the paypalme address... ?
App/src/libs/actions/PersonalDetails.js
Lines 100 to 111 in 13d2766
I think maybe we would just refer to
personalDetails[currentUserEmail].payPalMeAddresseverywhere. I don't have the full context on why we are storing this in two places.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.
Maybe we can combine them (also maybe makes sense to do this in a follow-up though - not sure)
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 also agree that this should be a follow up. Considering we have Paypal as part of the payment methods, we shouldn't be calling "UpdatePersonalDetails" from that screen. we can unify it, but we need to decide where it's going to be the better place.