-
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.
feat: add and switch accounts (#2220)
- Loading branch information
Showing
17 changed files
with
313 additions
and
113 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
5 changes: 4 additions & 1 deletion
5
web-components/src/components/header/components/UserMenuItem.types.ts
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 +1,4 @@ | ||
export type OnProfileClickType = (isSelected: boolean) => void; | ||
export type OnProfileClickType = ( | ||
accountId: string, | ||
isSelected: boolean, | ||
) => Promise<void>; |
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
117 changes: 117 additions & 0 deletions
117
web-marketplace/src/components/organisms/LoginFlow/LoginFlow.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,117 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useAtom, useSetAtom } from 'jotai'; | ||
import { postData } from 'utils/fetch/postData'; | ||
|
||
import { EmailConfirmationModal } from 'web-components/lib/components/modal/EmailConfirmationModal/EmailConfirmationModal'; | ||
|
||
import { apiUri } from 'lib/apiUri'; | ||
import { errorBannerTextAtom } from 'lib/atoms/error.atoms'; | ||
import { isWaitingForSigningAtom } from 'lib/atoms/tx.atoms'; | ||
import { getCsrfTokenQuery } from 'lib/queries/react-query/registry-server/getCsrfTokenQuery/getCsrfTokenQuery'; | ||
import { useWallet } from 'lib/wallet/wallet'; | ||
|
||
import { | ||
EMAIL_CONFIRMATION_CANCEL, | ||
EMAIL_CONFIRMATION_SUBMIT, | ||
RESEND_BUTTON_TEXT, | ||
RESEND_TEXT, | ||
socialProviders, | ||
} from '../LoginButton/LoginButton.constants'; | ||
import { MobileSigningModal } from '../LoginButton/LoginButton.SigningModal'; | ||
import { LoginModal } from '../LoginModal/LoginModal'; | ||
import { LoginModalState, LoginProvider } from '../LoginModal/LoginModal.types'; | ||
import { useEmailConfirmationData } from './hooks/useEmailConfirmationData'; | ||
|
||
type Props = { | ||
isModalOpen: boolean; | ||
onModalClose: () => void; | ||
wallets: LoginProvider[]; | ||
modalState: LoginModalState; | ||
qrCodeUri?: string; | ||
connecting: boolean; | ||
}; | ||
|
||
const LoginFlow = ({ | ||
isModalOpen, | ||
onModalClose, | ||
wallets, | ||
modalState, | ||
qrCodeUri, | ||
connecting, | ||
}: Props) => { | ||
const { walletConnectUri } = useWallet(); | ||
const { | ||
isConfirmationModalOpen, | ||
email, | ||
emailModalError, | ||
onConfirmationModalClose, | ||
onMailCodeChange, | ||
onResendPasscode, | ||
setIsConfirmationModalOpen, | ||
setEmail, | ||
} = useEmailConfirmationData(); | ||
const [isWaitingForSigning, setIsWaitingForSigningAtom] = useAtom( | ||
isWaitingForSigningAtom, | ||
); | ||
const { data: token } = useQuery(getCsrfTokenQuery({})); | ||
const setErrorBannerTextAtom = useSetAtom(errorBannerTextAtom); | ||
|
||
return ( | ||
<> | ||
<LoginModal | ||
open={isModalOpen} | ||
onClose={onModalClose} | ||
wallets={wallets} | ||
socialProviders={socialProviders} | ||
onEmailSubmit={async ({ email }) => { | ||
if (token) { | ||
try { | ||
setEmail(email); | ||
await postData({ | ||
url: `${apiUri}/marketplace/v1/auth/passcode`, | ||
data: { | ||
email, | ||
}, | ||
token, | ||
}); | ||
onModalClose(); | ||
setIsConfirmationModalOpen(true); | ||
} catch (e) { | ||
setErrorBannerTextAtom(String(e)); | ||
} | ||
} | ||
}} | ||
state={modalState} | ||
qrCodeUri={qrCodeUri} | ||
connecting={connecting} | ||
/> | ||
<EmailConfirmationModal | ||
resendText={RESEND_TEXT} | ||
resendButtonLink={{ | ||
text: RESEND_BUTTON_TEXT, | ||
onClick: onResendPasscode, | ||
}} | ||
cancelButton={{ | ||
text: EMAIL_CONFIRMATION_CANCEL, | ||
onClick: onConfirmationModalClose, | ||
}} | ||
signInButton={{ | ||
text: EMAIL_CONFIRMATION_SUBMIT, | ||
disabled: true, | ||
onClick: () => void 0, | ||
}} | ||
mailLink={{ text: email, href: '#' }} | ||
onClose={onConfirmationModalClose} | ||
open={isConfirmationModalOpen} | ||
error={emailModalError} | ||
onCodeChange={onMailCodeChange} | ||
/> | ||
<MobileSigningModal | ||
isOpen={isWaitingForSigning && !!walletConnectUri} | ||
onClose={() => setIsWaitingForSigningAtom(false)} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export { LoginFlow }; |
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
Oops, something went wrong.