-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding getSequenceWaas function * Fix email auth * v2.10.1
- Loading branch information
1 parent
89ec786
commit c704334
Showing
14 changed files
with
281 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# @0xsequence/kit | ||
|
||
## 2.10.1 | ||
|
||
### Patch Changes | ||
|
||
- Fixing email auth | ||
|
||
## 2.10.0 | ||
|
||
### Minor Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
packages/kit/src/components/ConnectButton/ConnectButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
import { Box, Card, EmailIcon, Tooltip, useTheme } from '@0xsequence/design-system' | ||
import { GoogleLogin } from '@react-oauth/google' | ||
import { useEffect, useState } from 'react' | ||
import { appleAuthHelpers } from 'react-apple-signin-auth' | ||
|
||
import { LocalStorageKey } from '../../constants' | ||
import { useStorage, useStorageItem } from '../../hooks/useStorage' | ||
import { ExtendedConnector, WalletProperties } from '../../types' | ||
|
||
const BUTTON_SIZE = '14' | ||
const ICON_SIZE = '10' | ||
|
||
const getLogo = (theme: any, walletProps: WalletProperties) => | ||
theme === 'dark' | ||
? walletProps.logoDark || walletProps.monochromeLogoDark | ||
: walletProps.logoLight || walletProps.monochromeLogoLight | ||
|
||
interface ConnectButtonProps { | ||
connector: ExtendedConnector | ||
label?: string | ||
onConnect: (connector: ExtendedConnector) => void | ||
} | ||
|
||
export const ConnectButton = (props: ConnectButtonProps) => { | ||
const { connector, label, onConnect } = props | ||
const { theme } = useTheme() | ||
const walletProps = connector._wallet | ||
|
||
const Logo = getLogo(theme, walletProps) | ||
|
||
return ( | ||
<Tooltip message={label || walletProps.name}> | ||
<Card | ||
clickable | ||
width={BUTTON_SIZE} | ||
height={BUTTON_SIZE} | ||
padding="2" | ||
borderRadius="xs" | ||
justifyContent="center" | ||
alignItems="center" | ||
onClick={() => onConnect(connector)} | ||
> | ||
<Box as={Logo} width={ICON_SIZE} height={ICON_SIZE} /> | ||
</Card> | ||
</Tooltip> | ||
) | ||
} | ||
|
||
export const GoogleWaasConnectButton = (props: ConnectButtonProps) => { | ||
const { connector, onConnect } = props | ||
const storage = useStorage() | ||
const { data: sessionHash, isPending: isPendingNonce } = useStorageItem(LocalStorageKey.WaasSessionHash) | ||
const [enableGoogleTooltip, setEnableGoogleTooltip] = useState(false) | ||
const { theme } = useTheme() | ||
const walletProps = connector._wallet | ||
|
||
const Logo = getLogo(theme, walletProps) | ||
|
||
useEffect(() => { | ||
setTimeout(() => { | ||
setEnableGoogleTooltip(true) | ||
}, 300) | ||
}) | ||
|
||
return !isPendingNonce ? ( | ||
<Tooltip message="Google" disabled={!enableGoogleTooltip}> | ||
<Card | ||
clickable | ||
background="transparent" | ||
borderRadius="xs" | ||
padding="0" | ||
width={BUTTON_SIZE} | ||
height={BUTTON_SIZE} | ||
position="relative" | ||
> | ||
<Box | ||
width="full" | ||
height="full" | ||
overflow="hidden" | ||
borderRadius="sm" | ||
alignItems="center" | ||
justifyContent="center" | ||
style={{ opacity: 0.0000001, transform: 'scale(1.4)' }} | ||
> | ||
<GoogleLogin | ||
type="icon" | ||
size="large" | ||
width="56" | ||
nonce={sessionHash} | ||
onSuccess={credentialResponse => { | ||
if (credentialResponse.credential) { | ||
storage?.setItem(LocalStorageKey.WaasGoogleIdToken, credentialResponse.credential) | ||
onConnect(connector) | ||
} | ||
}} | ||
onError={() => { | ||
console.log('Login Failed') | ||
}} | ||
/> | ||
</Box> | ||
<Box | ||
background="backgroundSecondary" | ||
borderRadius="xs" | ||
display="flex" | ||
justifyContent="center" | ||
alignItems="center" | ||
position="absolute" | ||
pointerEvents="none" | ||
width="full" | ||
height="full" | ||
top="0" | ||
right="0" | ||
> | ||
<Box as={Logo} width={ICON_SIZE} height={ICON_SIZE} /> | ||
</Box> | ||
</Card> | ||
</Tooltip> | ||
) : null | ||
} | ||
|
||
export const AppleWaasConnectButton = (props: ConnectButtonProps) => { | ||
const { connector, onConnect } = props | ||
const storage = useStorage() | ||
const { data: sessionHash, isPending: isPendingNonce } = useStorageItem(LocalStorageKey.WaasSessionHash) | ||
const { data: appleClientId } = useStorageItem(LocalStorageKey.WaasAppleClientID) | ||
const { data: appleRedirectUri } = useStorageItem(LocalStorageKey.WaasAppleRedirectURI) | ||
|
||
return !isPendingNonce && appleClientId && appleRedirectUri ? ( | ||
<ConnectButton | ||
connector={connector} | ||
onConnect={() => { | ||
appleAuthHelpers.signIn({ | ||
authOptions: { | ||
clientId: appleClientId, | ||
redirectURI: appleRedirectUri, | ||
nonce: sessionHash, | ||
scope: 'openid email', | ||
usePopup: true | ||
}, | ||
onSuccess: (response: any) => { | ||
if (response.authorization?.id_token) { | ||
storage?.setItem(LocalStorageKey.WaasAppleIdToken, response.authorization.id_token) | ||
onConnect(connector) | ||
} else { | ||
console.log('Apple login error: No id_token found') | ||
} | ||
}, | ||
onError: (error: any) => console.error(error) | ||
}) | ||
}} | ||
/> | ||
) : null | ||
} | ||
|
||
interface EmailConnectButtonProps { | ||
onClick: () => void | ||
} | ||
|
||
export const EmailConnectButton = (props: EmailConnectButtonProps) => { | ||
const { onClick } = props | ||
|
||
return ( | ||
<Tooltip message={'Email'}> | ||
<Card | ||
clickable | ||
width={BUTTON_SIZE} | ||
height={BUTTON_SIZE} | ||
padding="2" | ||
borderRadius="xs" | ||
justifyContent="center" | ||
alignItems="center" | ||
onClick={onClick} | ||
> | ||
<EmailIcon size="xl" color="text100" /> | ||
</Card> | ||
</Tooltip> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ConnectButton, GoogleWaasConnectButton, AppleWaasConnectButton, EmailConnectButton } from './ConnectButton' |
Oops, something went wrong.