Skip to content

Commit

Permalink
Make sure all needed accounts are connected
Browse files Browse the repository at this point in the history
After clicking on the stake button, if the user has no accounts connected, should see special modals with connection options.
  • Loading branch information
kkosiorowska committed Dec 5, 2023
1 parent 2aede4f commit a4d7e10
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
23 changes: 15 additions & 8 deletions dapp/src/components/Modals/ConnectWalletModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,31 @@ import {
VStack,
Text,
} from "@chakra-ui/react"
import { useRequestBitcoinAccount } from "../../hooks"
import BaseModal from "./BaseModal"
import ConnectBTCAccount from "../../static/images/ConnectBTCAccount.png"
import { Currency, RequestAccountParams } from "../../types"

export default function ConnectWalletModal() {
const { requestAccount } = useRequestBitcoinAccount()
type ConnectWalletModalProps = {
currency: Currency
image: string
requestAccount: (...params: RequestAccountParams) => Promise<void>
}

export default function ConnectWalletModal({
currency,
image,
requestAccount,
}: ConnectWalletModalProps) {
return (
<BaseModal>
<ModalHeader textAlign="center">
Bitcoin account not installed
{`${currency.name} account not installed`}
</ModalHeader>
<ModalBody>
<VStack spacing={12} mt={8}>
<Image src={ConnectBTCAccount} />
<Image src={image} />
<Text textAlign="center">
Bitcoin account is required to make transactions for depositing and
staking your BTC.
{`${currency.name} account is required to make transactions
for depositing and staking your ${currency.symbol} .`}
</Text>
</VStack>
</ModalBody>
Expand Down
32 changes: 29 additions & 3 deletions dapp/src/components/Staking/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
import React from "react"
import ConnectWalletModal from "../Modals/ConnectWalletModal"
import StakingOverviewModal from "../Modals/StakingOverviewModal"
import { useStakingFlowContext, useWalletContext } from "../../hooks"
import {
useRequestBitcoinAccount,
useRequestEthereumAccount,
useStakingFlowContext,
useWalletContext,
} from "../../hooks"
import ModalOverlay from "../ModalOverlay"
import StakeModal from "../Modals/StakeModal"
import Sidebar from "../Sidebar"
import { CONNECT_WALLET_HEIGHT } from "../Navbar"
import SignMessageModal from "../Modals/SignMessageModal"
import { BITCOIN, ETHEREUM } from "../../constants"
import ConnectBTCAccount from "../../static/images/ConnectBTCAccount.png"
import ConnectETHAccount from "../../static/images/ConnectETHAccount.png"

const MARGIN_TOP = `calc(${CONNECT_WALLET_HEIGHT}px + 3rem)`

function Modal() {
const { modalType } = useStakingFlowContext()
const { btcAccount } = useWalletContext()
const { btcAccount, ethAccount } = useWalletContext()
const { requestAccount: requestBitcoinAccount } = useRequestBitcoinAccount()
const { requestAccount: requestEthereumAccount } = useRequestEthereumAccount()

if (!modalType) return null

if (!btcAccount) return <ConnectWalletModal />
if (!btcAccount)
return (
<ConnectWalletModal
currency={BITCOIN}
image={ConnectBTCAccount}
requestAccount={requestBitcoinAccount}
/>
)

if (!ethAccount)
return (
<ConnectWalletModal
currency={ETHEREUM}
image={ConnectETHAccount}
requestAccount={requestEthereumAccount}
/>
)

if (modalType === "overview") return <StakingOverviewModal />

Expand Down
6 changes: 3 additions & 3 deletions dapp/src/hooks/useRequestEthereumAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { UseRequestAccountReturn } from "../types"
import { WalletContext } from "../contexts"

export function useRequestEthereumAccount(): UseRequestAccountReturn {
const walletContext = useContext(WalletContext)
const { setEthAccount } = useContext(WalletContext)
const { account, requestAccount } = useRequestAccount()

useEffect(() => {
walletContext?.setEthAccount(account || undefined)
}, [account, walletContext])
setEthAccount(account || undefined)
}, [account, setEthAccount])

const requestEthereumAccount = useCallback(async () => {
await requestAccount({ currencyIds: [CURRENCY_ID_ETHEREUM] })
Expand Down
Binary file added dapp/src/static/images/ConnectETHAccount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion dapp/src/types/ledger-live-app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { WalletAPIClient } from "@ledgerhq/wallet-api-client"

type RequestAccountParams = Parameters<WalletAPIClient["account"]["request"]>
export type RequestAccountParams = Parameters<
WalletAPIClient["account"]["request"]
>

export type UseRequestAccountReturn = {
requestAccount: (...params: RequestAccountParams) => Promise<void>
Expand Down

0 comments on commit a4d7e10

Please sign in to comment.