-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add wallet select mode (#2613)
* feat: add wallet select mode * fix: query params
- Loading branch information
Showing
7 changed files
with
144 additions
and
32 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
28 changes: 17 additions & 11 deletions
28
infra/rooch-portal-v2/src/layouts/components/account-button.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 |
---|---|---|
@@ -1,27 +1,33 @@ | ||
import type { IconButtonProps } from '@mui/material/IconButton'; | ||
|
||
import { useWallets, useConnectWallet } from '@roochnetwork/rooch-sdk-kit'; | ||
import { useState } from 'react'; | ||
|
||
import { Button } from '@mui/material'; | ||
|
||
import WalletSelectModal from './wallet-select-modal'; | ||
|
||
export type AccountButtonProps = IconButtonProps & { | ||
open: boolean; | ||
photoURL: string; | ||
displayName: string; | ||
}; | ||
|
||
export function AccountButton() { | ||
const wallets = useWallets(); | ||
const { mutateAsync: connectWallet } = useConnectWallet(); | ||
const [showWalletSelectModal, setShowWalletSelectModal] = useState(false); | ||
|
||
return ( | ||
<Button | ||
variant="outlined" | ||
onClick={async () => { | ||
await connectWallet({ wallet: wallets[0] }); | ||
}} | ||
> | ||
Connect Wallet | ||
</Button> | ||
<> | ||
<Button | ||
variant="outlined" | ||
onClick={() => { | ||
setShowWalletSelectModal(true); | ||
}} | ||
> | ||
Connect Wallet | ||
</Button> | ||
{showWalletSelectModal && ( | ||
<WalletSelectModal onSelect={() => setShowWalletSelectModal(false)} /> | ||
)} | ||
</> | ||
); | ||
} |
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
47 changes: 47 additions & 0 deletions
47
infra/rooch-portal-v2/src/layouts/components/wallet-button.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,47 @@ | ||
import type { Wallet } from '@roochnetwork/rooch-sdk-kit'; | ||
|
||
import { useState, useEffect } from 'react'; | ||
import { useConnectWallet } from '@roochnetwork/rooch-sdk-kit'; | ||
|
||
import { Stack, Button, CircularProgress } from '@mui/material'; | ||
|
||
export default function WalletButton({ | ||
wallet, | ||
onSelect, | ||
}: { | ||
wallet: Wallet; | ||
onSelect: () => void; | ||
}) { | ||
const { mutateAsync: connectWallet } = useConnectWallet(); | ||
|
||
const [walletInstalled, setWalletInstalled] = useState(false); | ||
const [checkingInstall, setCheckingInstall] = useState(false); | ||
|
||
useEffect(() => { | ||
async function checkWalletInstalled() { | ||
setCheckingInstall(true); | ||
const installed = await wallet.checkInstalled(); | ||
setWalletInstalled(installed); | ||
setCheckingInstall(false); | ||
} | ||
checkWalletInstalled(); | ||
}, [wallet]); | ||
|
||
return ( | ||
<Button | ||
disabled={walletInstalled === false || checkingInstall} | ||
onClick={async () => { | ||
await connectWallet({ wallet }); | ||
onSelect(); | ||
}} | ||
> | ||
<Stack direction="row" spacing={1.5} alignItems="center"> | ||
<Stack> | ||
<img src={wallet.getIcon()} width="36px" alt="" /> | ||
</Stack> | ||
<Stack>{wallet.getName()}</Stack> | ||
<Stack>{checkingInstall && <CircularProgress size={24} color="info" />}</Stack> | ||
</Stack> | ||
</Button> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
infra/rooch-portal-v2/src/layouts/components/wallet-select-modal.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,33 @@ | ||
import { useWallets } from '@roochnetwork/rooch-sdk-kit'; | ||
|
||
import { Stack, Dialog, DialogTitle, DialogContent } from '@mui/material'; | ||
|
||
import WalletButton from './wallet-button'; | ||
|
||
export default function WalletSelectModal({ onSelect }: { onSelect: () => void }) { | ||
const wallets = useWallets(); | ||
|
||
return ( | ||
<Dialog | ||
open | ||
onClose={() => { | ||
onSelect(); | ||
}} | ||
> | ||
<DialogTitle sx={{ pb: 2 }}>Select wallet</DialogTitle> | ||
|
||
<DialogContent | ||
sx={{ | ||
width: '480px', | ||
overflow: 'unset', | ||
}} | ||
> | ||
<Stack justifyContent="center" spacing={2} direction="column" sx={{ pt: 1, pb: 4 }}> | ||
{wallets.slice(0, 3).map((w) => ( | ||
<WalletButton key={w.getName()} wallet={w} onSelect={onSelect} /> | ||
))} | ||
</Stack> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.