forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wallet-ext: add zkLogin 2fa modal (MystenLabs#13958)
## Description for every zkLogin account show a modal to the user to enable 2fa https://github.com/MystenLabs/sui/assets/10210143/d1b0f165-c9b6-4b30-9d6b-26d43d924906 closes [APPS-1746](https://mysten.atlassian.net/browse/APPS-1746) ## Test Plan How did you test the new or updated feature? --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
- Loading branch information
1 parent
4904e8d
commit 5130ade
Showing
9 changed files
with
132 additions
and
5 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
86 changes: 86 additions & 0 deletions
86
apps/wallet/src/ui/app/components/accounts/ZkLoginAccountWaringModal.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,86 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { zkProviderDataMap, type ZkProvider } from '_src/background/accounts/zk/providers'; | ||
import { isZkAccountSerializedUI } from '_src/background/accounts/zk/ZkAccount'; | ||
import { type MethodPayload } from '_src/shared/messaging/messages/payloads/MethodPayload'; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
} from '_src/ui/app/shared/Dialog'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import toast from 'react-hot-toast'; | ||
|
||
import { useActiveAccount } from '../../hooks/useActiveAccount'; | ||
import { useBackgroundClient } from '../../hooks/useBackgroundClient'; | ||
import { Button } from '../../shared/ButtonUI'; | ||
import { Link } from '../../shared/Link'; | ||
|
||
const providerToName: Record<ZkProvider, string> = { | ||
google: 'Google', | ||
facebook: 'Facebook', | ||
twitch: 'Twitch', | ||
}; | ||
|
||
export function ZkLoginAccountWarningModal() { | ||
const activeAccount = useActiveAccount(); | ||
const backgroundClient = useBackgroundClient(); | ||
const warningMutation = useMutation({ | ||
mutationKey: ['acknowledge-zk-login-warning'], | ||
mutationFn: (args: MethodPayload<'acknowledgeZkLoginWarning'>['args']) => | ||
backgroundClient.acknowledgeZkLoginWarning(args), | ||
}); | ||
if ( | ||
activeAccount && | ||
isZkAccountSerializedUI(activeAccount) && | ||
!activeAccount.warningAcknowledged | ||
) { | ||
const providerData = zkProviderDataMap[activeAccount.provider]; | ||
return ( | ||
<Dialog open> | ||
<DialogContent onPointerDownOutside={(e) => e.preventDefault()} background="avocado"> | ||
<DialogHeader> | ||
<DialogTitle className="text-hero-darkest"> | ||
<div>Turn on 2FA.</div> | ||
<div>Protect Your Assets.</div> | ||
</DialogTitle> | ||
</DialogHeader> | ||
<DialogDescription className="text-center text-steel-darker"> | ||
Your {providerToName[activeAccount.provider]} Account now gives access to your Sui | ||
Wallet. To help safeguard your assets, we strongly recommend you enable 2FA. | ||
{providerData.mfaLink ? ( | ||
<> | ||
{' '} | ||
<span className="inline-block"> | ||
<Link color="heroDark" href={providerData.mfaLink} text="Visit this link" /> | ||
</span>{' '} | ||
to find out how to set this up. | ||
</> | ||
) : null} | ||
</DialogDescription> | ||
<DialogFooter> | ||
<Button | ||
text="I understand" | ||
loading={warningMutation.isLoading} | ||
onClick={() => | ||
warningMutation.mutate( | ||
{ accountID: activeAccount.id }, | ||
{ | ||
onError: (e) => { | ||
toast.error((e as Error)?.message || 'Something went wrong'); | ||
}, | ||
}, | ||
) | ||
} | ||
/> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} | ||
return null; | ||
} |
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