Skip to content

Commit

Permalink
fix: Add feature flag for social login
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Nov 8, 2023
1 parent 8e2d324 commit 9c15c8c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
20 changes: 14 additions & 6 deletions src/components/common/ConnectWallet/WalletDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useHasFeature } from '@/hooks/useChains'
import { FEATURES } from '@/utils/chains'
import { Box, Divider, SvgIcon, Typography } from '@mui/material'
import type { ReactElement } from 'react'

Expand All @@ -6,6 +8,8 @@ import SocialSigner from '@/components/common/SocialSigner'
import WalletLogin from '@/components/welcome/WelcomeLogin/WalletLogin'

const WalletDetails = ({ onConnect }: { onConnect: () => void }): ReactElement => {
const isSocialLoginEnabled = useHasFeature(FEATURES.SOCIAL_LOGIN)

return (
<>
<Box my={1}>
Expand All @@ -16,13 +20,17 @@ const WalletDetails = ({ onConnect }: { onConnect: () => void }): ReactElement =

<WalletLogin onLogin={onConnect} />

<Divider sx={{ width: '100%' }}>
<Typography color="text.secondary" fontWeight={700} variant="overline">
or
</Typography>
</Divider>
{isSocialLoginEnabled && (
<>
<Divider sx={{ width: '100%' }}>
<Typography color="text.secondary" fontWeight={700} variant="overline">
or
</Typography>
</Divider>

<SocialSigner onRequirePassword={onConnect} />
<SocialSigner onRequirePassword={onConnect} />
</>
)}
</>
)
}
Expand Down
19 changes: 13 additions & 6 deletions src/components/welcome/WelcomeLogin/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import SocialSigner from '@/components/common/SocialSigner'
import { AppRoutes } from '@/config/routes'
import { useHasFeature } from '@/hooks/useChains'
import { FEATURES } from '@/utils/chains'
import { Paper, SvgIcon, Typography, Divider, Link, Box } from '@mui/material'
import SafeLogo from '@/public/images/logo-text.svg'
import css from './styles.module.css'
Expand All @@ -11,6 +13,7 @@ import { trackEvent } from '@/services/analytics'

const WelcomeLogin = () => {
const router = useRouter()
const isSocialLoginEnabled = useHasFeature(FEATURES.SOCIAL_LOGIN)

const continueToCreation = () => {
trackEvent(CREATE_SAFE_EVENTS.OPEN_SAFE_CREATION)
Expand All @@ -29,13 +32,17 @@ const WelcomeLogin = () => {
</Typography>
<WalletLogin onLogin={continueToCreation} />

<Divider sx={{ mt: 2, mb: 2, width: '100%' }}>
<Typography color="text.secondary" fontWeight={700} variant="overline">
or
</Typography>
</Divider>
{isSocialLoginEnabled && (
<>
<Divider sx={{ mt: 2, mb: 2, width: '100%' }}>
<Typography color="text.secondary" fontWeight={700} variant="overline">
or
</Typography>
</Divider>

<SocialSigner onLogin={continueToCreation} />
<SocialSigner onLogin={continueToCreation} />
</>
)}

<Typography mt={2} textAlign="center">
Already have a Safe Account?
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/wallets/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const WALLET_MODULES: { [key in WALLET_KEYS]: (chain: ChainInfo) => WalletInit }
[WALLET_KEYS.WALLETCONNECT_V2]: (chain) => walletConnectV2(chain),
[WALLET_KEYS.COINBASE]: () => coinbaseModule({ darkMode: prefersDarkMode() }),
[WALLET_KEYS.PAIRING]: () => pairingModule(),
[WALLET_KEYS.SOCIAL]: () => MpcModule(),
[WALLET_KEYS.SOCIAL]: (chain) => MpcModule(chain),
[WALLET_KEYS.LEDGER]: () => ledgerModule(),
[WALLET_KEYS.TREZOR]: () => trezorModule({ appUrl: TREZOR_APP_URL, email: TREZOR_EMAIL }),
[WALLET_KEYS.KEYSTONE]: () => keystoneModule(),
Expand Down
6 changes: 5 additions & 1 deletion src/services/mpc/SocialLoginModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { _getMPCCoreKitInstance } from '@/hooks/wallets/mpc/useMPC'
import { getSocialWalletService } from '@/hooks/wallets/mpc/useSocialWallet'
import { getWeb3ReadOnly } from '@/hooks/wallets/web3'
import * as PasswordRecoveryModal from '@/services/mpc/PasswordRecoveryModal'
import { FEATURES, hasFeature } from '@/utils/chains'
import { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'

Check failure on line 6 in src/services/mpc/SocialLoginModule.ts

View workflow job for this annotation

GitHub Actions / ESLint Results

@typescript-eslint/consistent-type-imports

All imports in the declaration are only used as types. Use `import type`.
import { type WalletInit, ProviderRpcError } from '@web3-onboard/common'
import { type EIP1193Provider } from '@web3-onboard/core'
import { COREKIT_STATUS } from '@web3auth/mpc-core-kit'
Expand Down Expand Up @@ -40,7 +42,9 @@ const getConnectedAccounts = async () => {
*
* @returns Custom Onboard MpcModule
*/
function MpcModule(): WalletInit {
function MpcModule(chain: ChainInfo): WalletInit {
if (!hasFeature(chain, FEATURES.SOCIAL_LOGIN)) return () => null

return () => {
return {
label: ONBOARD_MPC_MODULE_LABEL,
Expand Down
13 changes: 10 additions & 3 deletions src/services/mpc/__tests__/module.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { chainBuilder } from '@/tests/builders/chains'
import * as feature from '@/utils/chains'
import MpcModule, { ONBOARD_MPC_MODULE_LABEL } from '../SocialLoginModule'
import { type WalletModule } from '@web3-onboard/common'

import * as web3 from '@/hooks/wallets/web3'
import * as useMPC from '@/hooks/wallets/mpc/useMPC'
import { hexZeroPad } from 'ethers/lib/utils'

const mockChain = chainBuilder().build()

describe('MPC Onboard module', () => {
beforeAll(() => {
jest.spyOn(feature, 'hasFeature').mockReturnValue(true)
})
it('should return correct metadata', async () => {
const mpcModule = MpcModule()({
const mpcModule = MpcModule(mockChain)({
device: {
browser: {
name: 'Firefox',
Expand Down Expand Up @@ -42,7 +49,7 @@ describe('MPC Onboard module', () => {
} as any
})

const mpcModule = MpcModule()({
const mpcModule = MpcModule(mockChain)({
device: {
browser: {
name: 'Firefox',
Expand Down Expand Up @@ -93,7 +100,7 @@ describe('MPC Onboard module', () => {
} as any
})

const mpcModule = MpcModule()({
const mpcModule = MpcModule(mockChain)({
device: {
browser: {
name: 'Firefox',
Expand Down
1 change: 1 addition & 0 deletions src/utils/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum FEATURES {
RISK_MITIGATION = 'RISK_MITIGATION',
PUSH_NOTIFICATIONS = 'PUSH_NOTIFICATIONS',
NATIVE_WALLETCONNECT = 'NATIVE_WALLETCONNECT',
SOCIAL_LOGIN = 'SOCIAL_LOGIN',
}

export const hasFeature = (chain: ChainInfo, feature: FEATURES): boolean => {
Expand Down

0 comments on commit 9c15c8c

Please sign in to comment.