Skip to content

Commit

Permalink
:fix social bug bash (#2353)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvoskamp authored Jun 3, 2024
1 parent 37eaa3f commit cde6b41
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
3 changes: 3 additions & 0 deletions apps/laboratory/src/pages/library/ethers-all.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const modal = createWeb3Modal({
defaultChainId: 1,
rpcUrl: 'https://cloudflare-eth.com',
enableEmail: true,
auth: {
socials: ['google', 'x', 'discord', 'apple', 'github']
},
coinbasePreference: 'smartWalletOnly'
}),
chains: EthersConstants.chains,
Expand Down
31 changes: 22 additions & 9 deletions packages/scaffold/src/partials/w3m-account-auth-button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import {

@customElement('w3m-account-auth-button')
export class W3mAccountAuthButton extends LitElement {
// -- Members ------------------------------------------- //
private socialProvider = StorageUtil.getConnectedSocialProvider() as SocialProvider | null

private socialUsername = StorageUtil.getConnectedSocialUsername()

// -- Render -------------------------------------------- //
public override render() {
const type = StorageUtil.getConnectedConnector()
Expand All @@ -22,23 +27,19 @@ export class W3mAccountAuthButton extends LitElement {
}
const email = authConnector.provider.getEmail() ?? ''

const socialProvider = StorageUtil.getConnectedSocialProvider() as SocialProvider | null

const socialUsername = StorageUtil.getConnectedSocialUsername()

return html`
<wui-list-item
variant="icon"
iconVariant="overlay"
icon=${socialProvider ?? 'mail'}
iconSize=${socialProvider ? 'xxl' : 'sm'}
icon=${this.socialProvider ?? 'mail'}
iconSize=${this.socialProvider ? 'xxl' : 'sm'}
data-testid="w3m-account-email-update"
?chevron=${!socialProvider}
?chevron=${!this.socialProvider}
@click=${() => {
this.onGoToUpdateEmail(email, socialProvider)
this.onGoToUpdateEmail(email, this.socialProvider)
}}
>
<wui-text variant="paragraph-500" color="fg-100">${socialUsername ?? email}</wui-text>
<wui-text variant="paragraph-500" color="fg-100">${this.getAuthName(email)}</wui-text>
</wui-list-item>
`
}
Expand All @@ -49,6 +50,18 @@ export class W3mAccountAuthButton extends LitElement {
RouterController.push('UpdateEmailWallet', { email })
}
}

private getAuthName(email: string) {
if (this.socialUsername) {
if (this.socialProvider === 'discord' && this.socialUsername.endsWith('0')) {
return this.socialUsername.slice(0, -1)
}

return this.socialUsername
}

return email.length > 30 ? `${email.slice(0, -3)}...` : email
}
}

declare global {
Expand Down
35 changes: 27 additions & 8 deletions packages/scaffold/src/partials/w3m-social-login-widget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class W3mSocialLoginWidget extends LitElement {
// -- Members ------------------------------------------- //
private unsubscribe: (() => void)[] = []

private desktopWindow?: Window | null

private mobileWindow?: Window | null

// -- State & Properties -------------------------------- //
@state() private connectors = ConnectorController.state.connectors

Expand Down Expand Up @@ -142,24 +146,39 @@ export class W3mSocialLoginWidget extends LitElement {
}

async onSocialClick(socialProvider?: SocialProvider) {
if (socialProvider) {
AccountController.setSocialProvider(socialProvider)
}
const authConnector = ConnectorController.getAuthConnector()
if (CoreHelperUtil.isMobile()) {
this.mobileWindow = CoreHelperUtil.returnOpenHref(
'',
'popupWindow',
'width=600,height=800,scrollbars=yes'
)
}

try {
if (authConnector && socialProvider) {
const { uri } = await authConnector.provider.getSocialRedirectUri({
provider: socialProvider
})
AccountController.setSocialProvider(socialProvider)
// Window.open doesn't work on ios withing an async function, wrapping it in a setTimeout fixes this
setTimeout(() => {
const newWindow = CoreHelperUtil.returnOpenHref(

if (!CoreHelperUtil.isMobile()) {
this.desktopWindow = CoreHelperUtil.returnOpenHref(
uri,
'popupWindow',
'width=600,height=800,scrollbars=yes'
)
if (newWindow) {
AccountController.setSocialWindow(newWindow)
}
})
}
if (this.desktopWindow && uri) {
AccountController.setSocialWindow(this.desktopWindow)
} else if (this.mobileWindow && uri) {
this.mobileWindow.location.href = uri
AccountController.setSocialWindow(this.mobileWindow)
} else {
throw new Error('Something went wrong')
}

RouterController.push('ConnectingSocial')
}
Expand Down

0 comments on commit cde6b41

Please sign in to comment.