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 6, 2023
1 parent 0ef2875 commit 2880e46
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
33 changes: 20 additions & 13 deletions dapp/src/components/Modals/ConnectWalletModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,34 @@ import {
ModalFooter,
ModalHeader,
VStack,
Text,
} from "@chakra-ui/react"
import { useRequestBitcoinAccount } from "../../hooks"
import BaseModal from "./BaseModal"
import ConnectBTCAccount from "../../static/images/ConnectBTCAccount.png"
import { TextLg, TextMd } from "../Typography"
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">
<TextLg>Bitcoin account not installed</TextLg>
{currency.name} account not installed
</ModalHeader>
<ModalBody mt={6}>
<VStack spacing={12}>
<Image src={ConnectBTCAccount} />
<TextMd textAlign="center">
Bitcoin account is required to make transactions for depositing and
staking your BTC.
</TextMd>
<ModalBody>
<VStack spacing={12} mt={8}>
<Image src={image} />
<Text textAlign="center">
{currency.name} account is required to make transactions
for depositing and staking your {currency.symbol}.
</Text>
</VStack>
</ModalBody>
<ModalFooter>
Expand Down
27 changes: 24 additions & 3 deletions dapp/src/components/Staking/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
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 { HEADER_HEIGHT } from "../Header"
import Sidebar from "../Sidebar"
import StakeModal from "../Modals/StakeModal"
import { BITCOIN, ETHEREUM } from "../../constants"
import ConnectBTCAccount from "../../static/images/ConnectBTCAccount.png"
import ConnectETHAccount from "../../static/images/ConnectETHAccount.png"

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
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 2880e46

Please sign in to comment.