Skip to content

Conversation

ameerul-deriv
Copy link
Contributor

@ameerul-deriv ameerul-deriv commented Apr 15, 2024

Changes:

Please provide a summary of the change.

  • Refactored useAdvertiserInfo Hook
  • Updated test cases related to useAdvertiserInfo
  • Fixed typescript errors, reduced it from 260 to 202
  • Fixed minor issues related to Joined Date and if user is online in chat screen
  • Added provider to store user's advertiser info state
  • Removed api calls for when user is not an advertiser

Screenshots:

Please provide some screenshots of the change.

useAdvertiserInfo.localstorage.mov

Screenshot 2024-04-15 at 4 48 11 PM
Screenshot 2024-04-16 at 10 32 18 AM
Screenshot 2024-04-16 at 10 32 43 AM
Screenshot 2024-04-16 at 10 33 24 AM
Screenshot 2024-04-16 at 10 34 00 AM
Screenshot 2024-04-16 at 10 34 43 AM
Screenshot 2024-04-16 at 10 34 55 AM
Screenshot 2024-04-18 at 5 35 07 PM
Screenshot 2024-04-18 at 5 54 10 PM
Screenshot 2024-04-18 at 6 01 02 PM

Copy link

vercel bot commented Apr 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
deriv-app ✅ Ready (Inspect) Visit Preview Apr 19, 2024 2:03am

@coveralls
Copy link

coveralls commented Apr 15, 2024

Coverage Status

coverage: 40.15% (+0.03%) from 40.123%
when pulling a8ac231 on ameerul-deriv:FEQ-1969-refactor-use-advertiser-info
into b03d95e on binary-com:master.

Copy link
Contributor

github-actions bot commented Apr 15, 2024

A production App ID was automatically generated for this PR. (log)

Click here to copy & paste above information.
- **PR**: [https://github.com/binary-com/deriv-app/pull/14611](https://github.com/binary-com/deriv-app/pull/14611)
- **URLs**:
    - **w/ App ID + Server**: https://deriv-app-git-fork-ameerul-deriv-feq-1969-refactor-use-a-cfc209.binary.sx?qa_server=red.derivws.com&app_id=31229
    - **Original**: https://deriv-app-git-fork-ameerul-deriv-feq-1969-refactor-use-a-cfc209.binary.sx
- **App ID**: `31229`

Copy link
Contributor

github-actions bot commented Apr 15, 2024

🚨 Lighthouse report for the changes in this PR:

Category Score
🔺 Performance 30
🟢 Accessibility 90
🟢 Best practices 92
🟧 SEO 73
🟧 PWA 78

Lighthouse ran with https://deriv-app-git-fork-ameerul-deriv-feq-1969-refactor-use-a-cfc209.binary.sx/

<OnlineStatusIcon isOnline={!!isOnline} isRelative size='0.8em' />
<OnlineStatusLabel
isOnline={!!isOnline}
lastOnlineTime={lastOnlineTime === null ? undefined : lastOnlineTime}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the type is number | null | undefined and the function in OnlineStatusLabel, getLastOnlineLabel prop lastOnlineTime can be undefined but doesn't take null. If undefined, it will return a default string, so we shouldn't do lastOnlineTime ?? 0 to return a default value.

sendbirdServiceToken?.app_id &&
advertiserInfo?.chat_user_id
) {
if (isSuccessSendbirdServiceToken && sendbirdServiceToken?.app_id && advertiserInfo?.chat_user_id) {
Copy link
Contributor Author

@ameerul-deriv ameerul-deriv Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to check for isSubscribed, since checking for advertiserInfo.chat_user_id is already enough

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
8.6% Duplication on New Code

See analysis details on SonarCloud

* Custom hook to access the current logged in user's advertiser info state.
* @returns {TContextValue} The current logged in user's advertiser info state.
*/
export const useAdvertiserInfoState = (): TContextValue => useContext(AdvertiserInfoStateContext);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the state isn't cached or stored locally to the useGetInfo hook, the state will always be returned as the default values, which will affect how we try to get these states when trying to access it in different components when calling the hook.

Because we need to know the state of the current logged in user, in a lot of different components, especially to determine if the user is an advertiser or not by checking for AdvertiserNotFound error, it is necessary to have this provider.

Comment on lines +36 to +48
useEffect(() => {
if (isSuccess) {
subscribeAdvertiserInfo();
}
}, [isSuccess, subscribeAdvertiserInfo]);

// Need this to subscribe to advertiser info after user has created an advertiser.
// setHasCreatedAdvertiser is triggered inside of NicknameModal.
useEffect(() => {
if (isSuccess && hasCreatedAdvertiser) {
subscribeAdvertiserInfo();
}
}, [hasCreatedAdvertiser, isSuccess, subscribeAdvertiserInfo]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the user has not added their nickname yet, and are already POA + POI verified, the error from p2p_advertiser_info api endpoint will return AdvertiserNotFound. Because of this, the first useEffect's subscribe function will try to subscribe, but then it will fail. So the second useEffect is a must as when the user creates their account for p2p, we will trigger the above state hasCreatedAdvertiser to subscribe to the newly created user.

Prior we would use invalidation, but we can't do that for useSubscription

Copy link
Contributor

github-actions bot commented Apr 19, 2024

Generating Lighthouse report...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants