Skip to content

Commit

Permalink
Connect wallet with ledger live app
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosiorowska committed Nov 15, 2023
1 parent bb6124d commit 788b92b
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 6 deletions.
1 change: 1 addition & 0 deletions dapp/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_USE_TESTNET=true
2 changes: 1 addition & 1 deletion dapp/manifest-ledger-live-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"en": "Bitcoin Liquid Staking"
}
},
"permissions": [],
"permissions": ["account.request"],
"domains": [
"http://*"
]
Expand Down
7 changes: 4 additions & 3 deletions dapp/src/DApp.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import React from "react"
import { ChakraProvider, Button, Box } from "@chakra-ui/react"
import { ChakraProvider, Box } from "@chakra-ui/react"
import { useEmbedFeatureFlag, useDetectThemeMode } from "./hooks"
import { LedgerWalletAPIProvider } from "./providers"
import { getThemeConfig } from "./theme/utils/utils"
import theme from "./theme/index"
import Navbar from "./components/Navbar"

function DAppContent() {
const { isEmbed } = useEmbedFeatureFlag()
let header = "Acre dApp"
if (isEmbed === "true") header = "Ledger live - Acre dApp"

return (
<Box p={4}>
<Box>
<Navbar />
<h1>{header}</h1>
<Button>Test button</Button>
</Box>
)
}
Expand Down
16 changes: 16 additions & 0 deletions dapp/src/assets/bitcoin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions dapp/src/assets/info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions dapp/src/components/Navbar/AccountInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from "react"
import { Box, Button, Image, Text } from "@chakra-ui/react"
import { useRequestAccount } from "@ledgerhq/wallet-api-client-react"
import BitcoinIcon from "../../assets/bitcoin.svg"
import InfoIcon from "../../assets/info.svg"
import { truncateAddress } from "../../utils"
import { BITCOIN, CURRENCY_ID_BITCOIN } from "../../constants"

export default function AccountInfo() {
const { account, requestAccount } = useRequestAccount()

const requestBitcoinAccount = async () => {
await requestAccount({ currencyIds: [CURRENCY_ID_BITCOIN] })
}

return (
<Box display="flex" alignItems="center" gap="4">
<Box display="flex" gap="2">
<Text>Balance</Text>
<Text as="b">{!account ? "0.00" : account.balance.toString()}</Text>
<Text>{BITCOIN.token}</Text>
</Box>
<Button
variant="outline"
leftIcon={<Image src={BitcoinIcon} />}
rightIcon={!account ? <Image src={InfoIcon} /> : undefined}
onClick={requestBitcoinAccount}
>
{account ? truncateAddress(account.address) : "Not connected"}
</Button>
</Box>
)
}
11 changes: 11 additions & 0 deletions dapp/src/components/Navbar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react"
import { Box } from "@chakra-ui/react"
import AccountInfo from "./AccountInfo"

export default function Navbar() {
return (
<Box p={4} display="flex" justifyContent="end">
<AccountInfo />
</Box>
)
}
7 changes: 7 additions & 0 deletions dapp/src/constants/chains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const BITCOIN = {
name: "Bitcoin",
token: "BTC",
}

export const CURRENCY_ID_BITCOIN =
import.meta.env.VITE_USE_TESTNET === "true" ? "bitcoin_testnet" : "bitcoin"
1 change: 1 addition & 0 deletions dapp/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./local-storage"
export * from "./chains"
9 changes: 8 additions & 1 deletion dapp/src/theme/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ import { mode } from "@chakra-ui/theme-tools"
import type { StyleFunctionProps } from "@chakra-ui/styled-system"

const Button = {
baseStyle: {
rounded: "none",
},
variants: {
solid: (props: StyleFunctionProps) => ({
backgroundColor: mode("black", "purple")(props),
backgroundColor: mode("black", "black")(props),
color: "white",
}),
outline: (props: StyleFunctionProps) => ({
color: mode("black", "black")(props),
borderColor: "black",
}),
},
}

Expand Down
11 changes: 10 additions & 1 deletion dapp/src/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { extendTheme } from "@chakra-ui/react"
import { StyleFunctionProps, extendTheme } from "@chakra-ui/react"
import { mode } from "@chakra-ui/theme-tools"
import Button from "./Button"
import { colors } from "./utils/index"

export const defaultTheme = {
colors,
styles: {
global: (props: StyleFunctionProps) => ({
"html, body, #root, #root > div": {
backgroundColor: mode("grey", "grey")(props),
minHeight: "100vh",
},
}),
},
components: {
Button,
},
Expand Down
2 changes: 2 additions & 0 deletions dapp/src/theme/utils/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export const colors = {
white: "#FFF",
black: "#000",
purple: "#7D00FF",
grey: "#ECECEC",
darkGrey: "#37393C",
}
4 changes: 4 additions & 0 deletions dapp/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line import/prefer-default-export
export function truncateAddress(address: string): string {
return `${address.slice(0, 6)}${address.slice(-5)}`
}

0 comments on commit 788b92b

Please sign in to comment.