Skip to content
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

fix: Add social login feature toggle from config service #2635

Merged
merged 4 commits into from
Oct 18, 2023

Conversation

usame-algan
Copy link
Member

@usame-algan usame-algan commented Oct 16, 2023

What it solves

Resolves #2458

How this PR fixes it

  • Only shows social login in the onboard modal if its enabled in the config service
  • The info message now displays all supported chains depending on the config service
  • If the user is connected with a different wallet, the social login button will no longer show a connected state

How to test it

  1. Open the welcome page on goerli staging CGW
  2. Connect via Google
  3. Connect to a different wallet either through the main button or the "Switch Wallet" button
  4. Observe the Google button on the welcome page says "Continue with Google"
  5. Switch to Polygon
  6. Observe an info message saying that social login is only supported on Goerli
  7. Open the Onboard modal
  8. Observe no Social Login option

Screenshots

Screenshot 2023-10-16 at 11 55 29 Screenshot 2023-10-16 at 11 56 45 Screenshot 2023-10-16 at 11 57 06

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

@github-actions
Copy link

github-actions bot commented Oct 16, 2023

Branch preview

✅ Deploy successful!

https://feature_toggle--walletweb.review-wallet-web.5afe.dev

@usame-algan usame-algan requested a review from schmanu October 16, 2023 09:57
@github-actions
Copy link

github-actions bot commented Oct 16, 2023

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

Comment on lines 121 to 126
{supportedChains.map((chain, idx) => (
<>
{chain}
{idx < supportedChains.length - 1 && ', '}
</>
))}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{supportedChains.map((chain, idx) => (
<>
{chain}
{idx < supportedChains.length - 1 && ', '}
</>
))}
{supportedChains.join(', ')}

Comment on lines 18 to 24
return chains.reduce((result: string[], currentChain) => {
if (CGW_NAMES.SOCIAL_LOGIN && !currentChain.disabledWallets.includes(CGW_NAMES.SOCIAL_LOGIN)) {
result.push(currentChain.chainName)
}
return result
}, [])
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I feel like this is a bit simpler to read

Suggested change
return chains.reduce((result: string[], currentChain) => {
if (CGW_NAMES.SOCIAL_LOGIN && !currentChain.disabledWallets.includes(CGW_NAMES.SOCIAL_LOGIN)) {
result.push(currentChain.chainName)
}
return result
}, [])
}
const filteredChains = chains.filter((chain) => CGW_NAMES.SOCIAL_LOGIN && !currentChain.disabledWallets.includes(CGW_NAMES.SOCIAL_LOGIN))
return filteredChains.map((chainConfig) => chainConfig.chainName)

const useGetSupportedChains = () => {
const chains = useChains()

return _getSupportedChains(chains.configs)
Copy link
Member

Choose a reason for hiding this comment

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

Should we memoize this to reduce re-renders?

const MPCLogin = ({ onLogin }: { onLogin?: () => void }) => {
export const _getSupportedChains = (chains: ChainInfo[]) => {
return chains.reduce((result: string[], currentChain) => {
if (CGW_NAMES.SOCIAL_LOGIN && !currentChain.disabledWallets.includes(CGW_NAMES.SOCIAL_LOGIN)) {
Copy link
Member

Choose a reason for hiding this comment

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

Do you know why we type the mapped type of CGW_NAMES as string | undefined?

Can it really be undefined?
Should we refactor it as

export const CGW_NAMES = {
  [WALLET_KEYS.INJECTED]: 'detectedwallet',
  [WALLET_KEYS.WALLETCONNECT_V2]: 'walletConnect_v2',
  [WALLET_KEYS.COINBASE]: 'coinbase',
  [WALLET_KEYS.PAIRING]: 'safeMobile',
  [WALLET_KEYS.SOCIAL]: 'socialLogin',
  [WALLET_KEYS.LEDGER]: 'ledger',
  [WALLET_KEYS.TREZOR]: 'trezor',
  [WALLET_KEYS.KEYSTONE]: 'keystone',
} as const

Or am I missing something about this mapping?

Copy link
Member Author

@usame-algan usame-algan Oct 17, 2023

Choose a reason for hiding this comment

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

I was also wondering about that. The only reason I can see is that the WALLET_MODULES and CGW_NAMES should be coupled but currently are not so it could happen that we try to access a key in CGW_NAMES that doesn't exist. I will add a TODO to tackle this as a separate refactor.

it('returns chain names where social login is enabled', () => {
const mockEthereumChain = { chainId: '1', chainName: 'Ethereum', disabledWallets: ['socialLogin'] } as ChainInfo
const mockGnosisChain = { chainId: '100', chainName: 'Gnosis Chain', disabledWallets: ['Coinbase'] } as ChainInfo
const mockGoerliChain = { chainId: '5', chainName: 'Goerli', disabledWallets: ['TallyHo'] } as ChainInfo
Copy link
Member

Choose a reason for hiding this comment

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

Nit: If we leave it empty we test that it also works if no wallets are disabled.

Suggested change
const mockGoerliChain = { chainId: '5', chainName: 'Goerli', disabledWallets: ['TallyHo'] } as ChainInfo
const mockGoerliChain = { chainId: '5', chainName: 'Goerli', disabledWallets: [] } as ChainInfo

@usame-algan usame-algan requested a review from schmanu October 17, 2023 10:38
@github-actions
Copy link

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
74.59% (-0.11% 🔻)
9262/12417
🔴 Branches
48.75% (-0.1% 🔻)
1865/3826
🔴 Functions
56.38% (-0.28% 🔻)
1360/2412
🟡 Lines
76.16% (-0.08% 🔻)
8372/10993
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🔴
... / wallets.ts
42.59% 0% 10% 48.84%

Test suite run success

988 tests passing in 139 suites.

Report generated by 🧪jest coverage report action from 8fa8f9d

@usame-algan usame-algan merged commit 2747747 into web3authcoresdk Oct 18, 2023
7 of 8 checks passed
@usame-algan usame-algan deleted the feature-toggle branch October 18, 2023 07:21
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants