From 4178882fa06e941ce17ebdd687b9bf4e6d20fff3 Mon Sep 17 00:00:00 2001 From: Or Date: Thu, 1 Feb 2024 19:18:55 +0200 Subject: [PATCH 1/8] Send switch demand source config --- .../Locomotion/src/context/user/index.tsx | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/examples/client/Locomotion/src/context/user/index.tsx b/examples/client/Locomotion/src/context/user/index.tsx index 8e4e9505e..a984bc925 100644 --- a/examples/client/Locomotion/src/context/user/index.tsx +++ b/examples/client/Locomotion/src/context/user/index.tsx @@ -175,24 +175,40 @@ const UserContextProvider = ({ children }: { children: any }) => { const onLogin = async (phoneNumber: string, channel = 'sms') => { const demandSourceId = await AppSettings.getOperationId(); - await loginApi({ + const switchDemandSource = Config.SWITCH_DEMAND_SOURCE === 'true'; + const response = await loginApi({ phoneNumber, channel, demandSourceId, + switchDemandSource }); + console.log('onLogin', response, switchDemandSource); + if (switchDemandSource && response.demandSourceId && + response.demandSourceId !== demandSourceId) { + await AppSettings.setSettings({ + OPERATION_ID: response.demandSourceId + }); + } // successful login - delete captcha token await StorageService.delete('captchaToken'); }; const onVert = async (code: string) => { const demandSourceId = await AppSettings.getOperationId(); + const switchDemandSource = Config.SWITCH_DEMAND_SOURCE === 'true'; try { const vertResponse = await loginVert({ phoneNumber: user?.phoneNumber, code, demandSourceId, + switchDemandSource }); - + console.log('onVert', vertResponse, switchDemandSource); + if (switchDemandSource && vertResponse.demandSourceId !== demandSourceId) { + await AppSettings.setSettings({ + OPERATION_ID: vertResponse.demandSourceId + }); + } if (vertResponse.status !== 'OK' || !vertResponse.refreshToken || !vertResponse.accessToken) { console.log('Bad vert with response', vertResponse); return false; From c5ecd2a411c684c22d31bbd88ddf3b5310083a06 Mon Sep 17 00:00:00 2001 From: Or Date: Sun, 4 Feb 2024 11:24:17 +0200 Subject: [PATCH 2/8] wip --- .../client/Locomotion/src/context/user/index.tsx | 14 ++------------ .../client/Locomotion/src/services/app-settings.js | 1 + 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/examples/client/Locomotion/src/context/user/index.tsx b/examples/client/Locomotion/src/context/user/index.tsx index a984bc925..303b076fe 100644 --- a/examples/client/Locomotion/src/context/user/index.tsx +++ b/examples/client/Locomotion/src/context/user/index.tsx @@ -182,12 +182,9 @@ const UserContextProvider = ({ children }: { children: any }) => { demandSourceId, switchDemandSource }); - console.log('onLogin', response, switchDemandSource); if (switchDemandSource && response.demandSourceId && response.demandSourceId !== demandSourceId) { - await AppSettings.setSettings({ - OPERATION_ID: response.demandSourceId - }); + await AppSettings.setOperationId(response.demandSourceId); } // successful login - delete captcha token await StorageService.delete('captchaToken'); @@ -195,20 +192,13 @@ const UserContextProvider = ({ children }: { children: any }) => { const onVert = async (code: string) => { const demandSourceId = await AppSettings.getOperationId(); - const switchDemandSource = Config.SWITCH_DEMAND_SOURCE === 'true'; try { const vertResponse = await loginVert({ phoneNumber: user?.phoneNumber, code, demandSourceId, - switchDemandSource }); - console.log('onVert', vertResponse, switchDemandSource); - if (switchDemandSource && vertResponse.demandSourceId !== demandSourceId) { - await AppSettings.setSettings({ - OPERATION_ID: vertResponse.demandSourceId - }); - } + if (vertResponse.status !== 'OK' || !vertResponse.refreshToken || !vertResponse.accessToken) { console.log('Bad vert with response', vertResponse); return false; diff --git a/examples/client/Locomotion/src/services/app-settings.js b/examples/client/Locomotion/src/services/app-settings.js index 0dc4cef38..05ac417e5 100644 --- a/examples/client/Locomotion/src/services/app-settings.js +++ b/examples/client/Locomotion/src/services/app-settings.js @@ -31,6 +31,7 @@ const AppSettings = { }, }); }, + setOperationId: async (newOperationId) => AppSettings.setSettings({ operationId: newOperationId }), destroy: async () => Storage.clear(), }; From dbd35da0d33db700c14e7aed6791f6470a280ffd Mon Sep 17 00:00:00 2001 From: Or Date: Sun, 4 Feb 2024 11:37:30 +0200 Subject: [PATCH 3/8] fix linter --- examples/client/Locomotion/src/services/app-settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/client/Locomotion/src/services/app-settings.js b/examples/client/Locomotion/src/services/app-settings.js index 05ac417e5..13e1a922e 100644 --- a/examples/client/Locomotion/src/services/app-settings.js +++ b/examples/client/Locomotion/src/services/app-settings.js @@ -31,7 +31,7 @@ const AppSettings = { }, }); }, - setOperationId: async (newOperationId) => AppSettings.setSettings({ operationId: newOperationId }), + setOperationId: async newOperationId => AppSettings.setSettings({ operationId: newOperationId }), destroy: async () => Storage.clear(), }; From f5ce3aaebee60ff9ec3385359bd6aaabde4c2758 Mon Sep 17 00:00:00 2001 From: Or Date: Sun, 4 Feb 2024 11:41:16 +0200 Subject: [PATCH 4/8] fix linter --- examples/client/Locomotion/src/context/user/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/client/Locomotion/src/context/user/index.tsx b/examples/client/Locomotion/src/context/user/index.tsx index 303b076fe..6bf7ffe29 100644 --- a/examples/client/Locomotion/src/context/user/index.tsx +++ b/examples/client/Locomotion/src/context/user/index.tsx @@ -180,7 +180,7 @@ const UserContextProvider = ({ children }: { children: any }) => { phoneNumber, channel, demandSourceId, - switchDemandSource + switchDemandSource, }); if (switchDemandSource && response.demandSourceId && response.demandSourceId !== demandSourceId) { From 2691ac8dad98d1756e55564a585888092307935a Mon Sep 17 00:00:00 2001 From: Or Date: Sun, 4 Feb 2024 11:47:49 +0200 Subject: [PATCH 5/8] fix linter --- examples/client/Locomotion/src/context/user/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/client/Locomotion/src/context/user/index.tsx b/examples/client/Locomotion/src/context/user/index.tsx index 6bf7ffe29..19503a043 100644 --- a/examples/client/Locomotion/src/context/user/index.tsx +++ b/examples/client/Locomotion/src/context/user/index.tsx @@ -182,8 +182,8 @@ const UserContextProvider = ({ children }: { children: any }) => { demandSourceId, switchDemandSource, }); - if (switchDemandSource && response.demandSourceId && - response.demandSourceId !== demandSourceId) { + if (switchDemandSource && response.demandSourceId + && response.demandSourceId !== demandSourceId) { await AppSettings.setOperationId(response.demandSourceId); } // successful login - delete captcha token From bb9e970eacc5ae26b171bf15b241a52b82b4e3e6 Mon Sep 17 00:00:00 2001 From: Or Date: Sun, 4 Feb 2024 17:09:34 +0200 Subject: [PATCH 6/8] wip --- .../Locomotion/src/context/user/index.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/client/Locomotion/src/context/user/index.tsx b/examples/client/Locomotion/src/context/user/index.tsx index 19503a043..ea9858e3b 100644 --- a/examples/client/Locomotion/src/context/user/index.tsx +++ b/examples/client/Locomotion/src/context/user/index.tsx @@ -173,18 +173,26 @@ const UserContextProvider = ({ children }: { children: any }) => { return vertResponse.status === 'OK'; }; + const getAllowedDemandSourceIds = () => { + if (!Config.ALLOWED_DEMAND_SOURCE_IDS) { + return []; + } + const allowedDemandSourceIds = JSON.parse(Config.ALLOWED_DEMAND_SOURCE_IDS); + return Array.isArray(allowedDemandSourceIds) ? allowedDemandSourceIds : []; + } + const onLogin = async (phoneNumber: string, channel = 'sms') => { const demandSourceId = await AppSettings.getOperationId(); - const switchDemandSource = Config.SWITCH_DEMAND_SOURCE === 'true'; + const allowedDemandSourceIds = getAllowedDemandSourceIds(); const response = await loginApi({ phoneNumber, channel, demandSourceId, - switchDemandSource, + allowedDemandSourceIds, }); - if (switchDemandSource && response.demandSourceId - && response.demandSourceId !== demandSourceId) { - await AppSettings.setOperationId(response.demandSourceId); + const { selectedDemandSourceId } = response; + if (allowedDemandSourceIds.length > 0 && selectedDemandSourceId && selectedDemandSourceId !== demandSourceId) { + await AppSettings.setOperationId(selectedDemandSourceId); } // successful login - delete captcha token await StorageService.delete('captchaToken'); From c32d22d2ac076964e34ba504f8f80d9bda2a6548 Mon Sep 17 00:00:00 2001 From: Or Date: Sun, 4 Feb 2024 17:10:59 +0200 Subject: [PATCH 7/8] Whitelist of demand source ids --- examples/client/Locomotion/src/context/user/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/client/Locomotion/src/context/user/index.tsx b/examples/client/Locomotion/src/context/user/index.tsx index ea9858e3b..429701670 100644 --- a/examples/client/Locomotion/src/context/user/index.tsx +++ b/examples/client/Locomotion/src/context/user/index.tsx @@ -179,7 +179,7 @@ const UserContextProvider = ({ children }: { children: any }) => { } const allowedDemandSourceIds = JSON.parse(Config.ALLOWED_DEMAND_SOURCE_IDS); return Array.isArray(allowedDemandSourceIds) ? allowedDemandSourceIds : []; - } + }; const onLogin = async (phoneNumber: string, channel = 'sms') => { const demandSourceId = await AppSettings.getOperationId(); From fcbad9a554ffe8af5c78e2b08a6ca17e27afdfa6 Mon Sep 17 00:00:00 2001 From: Or Date: Mon, 5 Feb 2024 15:27:12 +0200 Subject: [PATCH 8/8] try catch + mixpanel --- .../client/Locomotion/src/context/user/index.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/examples/client/Locomotion/src/context/user/index.tsx b/examples/client/Locomotion/src/context/user/index.tsx index 429701670..965608a83 100644 --- a/examples/client/Locomotion/src/context/user/index.tsx +++ b/examples/client/Locomotion/src/context/user/index.tsx @@ -173,12 +173,17 @@ const UserContextProvider = ({ children }: { children: any }) => { return vertResponse.status === 'OK'; }; - const getAllowedDemandSourceIds = () => { - if (!Config.ALLOWED_DEMAND_SOURCE_IDS) { + const getAllowedDemandSourceIds = (): string[] => { + try { + if (!Config.ALLOWED_DEMAND_SOURCE_IDS) { + return []; + } + const allowedDemandSourceIds = JSON.parse(Config.ALLOWED_DEMAND_SOURCE_IDS); + return Array.isArray(allowedDemandSourceIds) ? allowedDemandSourceIds : []; + } catch (error) { + Mixpanel.setEvent('Invalid ALLOWED_DEMAND_SOURCE_IDS', { allowedDemandSourceIds: Config.ALLOWED_DEMAND_SOURCE_IDS }); return []; } - const allowedDemandSourceIds = JSON.parse(Config.ALLOWED_DEMAND_SOURCE_IDS); - return Array.isArray(allowedDemandSourceIds) ? allowedDemandSourceIds : []; }; const onLogin = async (phoneNumber: string, channel = 'sms') => {