Skip to content

Commit

Permalink
Move to useSocialWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Nov 3, 2023
1 parent 730ca34 commit a73086f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
24 changes: 24 additions & 0 deletions src/hooks/wallets/mpc/useSocialWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ import useMpc from './useMPC'

const { getStore, setStore, useStore } = new ExternalStore<ISocialWalletService>()

// Listen to onboard modal open and hide the social login button
const hideOnboardButton = () => {
const onboardRoot = document.querySelector('onboard-v2')?.shadowRoot
if (!onboardRoot) return

const hideSocialLoginButton = () => {
const walletButtons = onboardRoot.querySelectorAll('.wallet-button-container') || []
const socialButton = Array.from(walletButtons).find((el) => el.textContent?.includes(ONBOARD_MPC_MODULE_LABEL))
socialButton?.remove()
}

const observer = new MutationObserver(hideSocialLoginButton)
observer.observe(onboardRoot, { childList: true })

return () => observer.disconnect()
}

export const useInitSocialWallet = () => {
const mpcCoreKit = useMpc()
const onboard = useOnboard()
Expand Down Expand Up @@ -54,6 +71,13 @@ export const useInitSocialWallet = () => {
setStore(new SocialWalletService(mpcCoreKit))
}
}, [mpcCoreKit])

// Hide social login when onboard pops up
// @FIXME the button should work but atm it doesn't
useEffect(() => {
if (!onboard) return
return hideOnboardButton()
}, [onboard])
}

export const getSocialWalletService = getStore
Expand Down
21 changes: 0 additions & 21 deletions src/hooks/wallets/useOnboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ const isMobile = () => /iPhone|iPad|iPod|Android/i.test(navigator.userAgent)
// Detect injected wallet
const hasInjectedWallet = () => typeof window !== 'undefined' && !!window?.ethereum

// Hide the Social login button
const hideSocialLoginButton = (onboardRoot: ShadowRoot) => {
const walletButtons = onboardRoot.querySelectorAll('.wallet-button-container') || []
const socialButton = Array.from(walletButtons).find((el) => el.textContent?.includes(ONBOARD_MPC_MODULE_LABEL))
socialButton?.remove()
}

// `connectWallet` is called when connecting/switching wallets and on pairing `connect` event (when prev. session connects)
// This re-entrant lock prevents multiple `connectWallet`/tracking calls that would otherwise occur for pairing module
let isConnecting = false
Expand Down Expand Up @@ -209,20 +202,6 @@ export const useInitOnboard = () => {
walletSubscription.unsubscribe()
}
}, [onboard])

// Hide social login when onboard pops up
useEffect(() => {
if (!onboard) return
const onboardRoot = document.querySelector('onboard-v2')?.shadowRoot
if (!onboardRoot) return

const observer = new MutationObserver(() => hideSocialLoginButton(onboardRoot))
observer.observe(onboardRoot, { childList: true })

return () => {
observer.disconnect()
}
}, [onboard])
}

export default useStore

0 comments on commit a73086f

Please sign in to comment.