Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ledger Live App #655

Merged
merged 71 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
e476476
Create `useEmbedFeatureFlag` hook
michalsmiarowski Oct 31, 2023
a69c707
Make only tBTC section available
michalsmiarowski Oct 31, 2023
5155964
Hide sidebar
michalsmiarowski Oct 31, 2023
a7f76ed
Create LedgerLiveAppManager class
michalsmiarowski Nov 1, 2023
8b066bb
Put ledgerLiveAppManager inside threshold-ts lib
michalsmiarowski Nov 1, 2023
e9645da
Add possibility to connect ledger ethereum account
michalsmiarowski Nov 1, 2023
8bcd830
Fix minting flow not siplaying for connected users
michalsmiarowski Nov 1, 2023
b6c1814
Assign eth address from the store to the form
michalsmiarowski Nov 1, 2023
f13fb80
Make `account` property private in ledger signer
michalsmiarowski Nov 1, 2023
4f8266f
Create LedgerLiveAppBitcoinManager
michalsmiarowski Nov 1, 2023
b059feb
Change name for `LedgerLiveEthereumSigner` class
michalsmiarowski Nov 1, 2023
62d0f96
Make two separate hooks for bitcoin and ethereum
michalsmiarowski Nov 1, 2023
100b0c6
Make it possible to connect bitcoin account
michalsmiarowski Nov 1, 2023
dad6a2e
Rewamp (1) - install wallet-connect-client-react
michalsmiarowski Nov 2, 2023
b222469
Rewamp (2) - TransportProvider
michalsmiarowski Nov 2, 2023
edf9afd
Rewamp (3) - LedgerLiveAppContext
michalsmiarowski Nov 2, 2023
7b5105e
Rewamp (4) - use ledger's wallet api for react
michalsmiarowski Nov 2, 2023
46344d7
Rewamp (5) - create `useIsActive` hook
michalsmiarowski Nov 2, 2023
e50f783
Add the possibility to upload JSON file
michalsmiarowski Nov 2, 2023
7d6d897
Refactor useEffect inside useRequestAccount hooks
michalsmiarowski Nov 2, 2023
ad0c843
Store Account object in Ledger Live App Context
michalsmiarowski Nov 2, 2023
95acc74
Allow sending bitcoins to deposit address
michalsmiarowski Nov 3, 2023
efe582f
Add `bignumber.js` to package.json
michalsmiarowski Nov 3, 2023
5d4be01
Change Signer class that LedgerSigner extends from
michalsmiarowski Nov 3, 2023
4051270
Pass ledgerLiveAppEhereumSigner to Threshold lib
michalsmiarowski Nov 3, 2023
3f5d279
Install tbtc-v2.ts SDK as a separate package
michalsmiarowski Nov 3, 2023
168aaed
Implement minting flow with SDK v2
michalsmiarowski Nov 6, 2023
a35eeaf
Implement Resume Deposit with SDK v2
michalsmiarowski Nov 6, 2023
ef13ab8
Implement reveal deposit for ledger live app
michalsmiarowski Nov 6, 2023
39e589c
Fix fetching Bridge Activity in Ledger Live App
michalsmiarowski Nov 6, 2023
234fda3
Fix `no ongoingRequest` error
michalsmiarowski Nov 6, 2023
46afb9b
Fix minting success page redirect
michalsmiarowski Nov 6, 2023
d04a69a
Disconnect transport when requesting eth account
michalsmiarowski Nov 7, 2023
947c8a5
Handle async SDK initialization
michalsmiarowski Nov 7, 2023
7b86fba
Fix fetching token amount in Ledger Live App
michalsmiarowski Nov 7, 2023
9a44303
Fix Connect Wallet submit button for Ledger Live
michalsmiarowski Nov 7, 2023
efef52d
Return prefixed tx hash when revealing a deposit
michalsmiarowski Nov 7, 2023
1fe279f
Implement unminting flow with SDK v1
michalsmiarowski Nov 7, 2023
ff28f60
Fix building a redemption link
michalsmiarowski Nov 7, 2023
ae7804d
Add manifest.json file for Ledger Live App
michalsmiarowski Nov 7, 2023
fb0c3a2
Display Continue mint button only for Live App
michalsmiarowski Nov 8, 2023
15617dd
Add a posisbility to send exact amount of BTC
michalsmiarowski Nov 8, 2023
4d6d4e1
Improve data loading after connecting account
michalsmiarowski Nov 8, 2023
fa1aad0
Trigger loading state for step 2 ASAP
michalsmiarowski Nov 9, 2023
bf3c3e3
Merge branch 'main' into ledger-live-app
michalsmiarowski Nov 22, 2023
bfffe4f
Improve passing Ledger Live signer to threshold-ts
michalsmiarowski Nov 23, 2023
c0db65b
Simplify contexts
michalsmiarowski Nov 23, 2023
ceec2f1
Use ledger live app signer from tbtc-v2.ts
michalsmiarowski Nov 27, 2023
bf790b6
Fix disconnecting account for ledger live app
michalsmiarowski Nov 27, 2023
b91165a
Improve `useInitializeTbtcSdk` hook
michalsmiarowski Nov 27, 2023
ac67427
Fix unmint page throwing error
michalsmiarowski Nov 27, 2023
1749ac5
Use proper currency Id based on supportedChainId
michalsmiarowski Nov 27, 2023
1de4b84
Remove unnecessary TODOs
michalsmiarowski Nov 27, 2023
df20497
Fix `useGetBlock` hook
michalsmiarowski Nov 27, 2023
d8c4335
Fix tbtc balance not displaying in Ledger Live App
michalsmiarowski Nov 27, 2023
e3bcd82
Remove `useSendLedgerLiveAppTransactionFromFn`
michalsmiarowski Nov 28, 2023
e0ade29
Rename `useEmbedFeatureFlag` hook
michalsmiarowski Nov 28, 2023
a65ca81
Improve manifest
michalsmiarowski Dec 8, 2023
03fc8c4
Move looking for `embed` param to the hook
michalsmiarowski Dec 8, 2023
af42575
Clean `useIsActive()` call in TokenBalance.tsx
michalsmiarowski Dec 8, 2023
f65103a
Remove unnecessary comment
michalsmiarowski Dec 8, 2023
1958cfa
Use url for the icon in manifest
michalsmiarowski Dec 8, 2023
683115e
Improve useEffect for dispatchin ledger account
michalsmiarowski Dec 8, 2023
84a6bf7
Create `useConnectWallet` hook
michalsmiarowski Dec 8, 2023
6903e90
Detect properly if application is embed
michalsmiarowski Dec 13, 2023
790c240
Remove embed param from "homepageUrl" in manifest
michalsmiarowski Dec 13, 2023
aa77615
Improve code in Navbar component
michalsmiarowski Dec 13, 2023
2e5ce7d
Use chainId from `useIsActive` hook
michalsmiarowski Dec 13, 2023
f90bfc8
Merge branch 'main' into ledger-live-app
michalsmiarowski Dec 13, 2023
c0a6e36
Remove unnecessary change in import order
michalsmiarowski Dec 13, 2023
a993ab7
Extract send bitcoins form to separate file
michalsmiarowski Dec 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions manifest-ledger-live-app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"id": "threshold",
"name": "Threshold",
"url": "http://localhost:3000?embed=true",
"homepageUrl": "http://localhost:3000",
"icon": "https://dashboard.threshold.network/favicon-T.png",
"platform": "all",
"apiVersion": "2.0.0",
"manifestVersion": "1",
"branch": "stable",
"categories": ["tbtc", "bitocin", "bridge"],
"currencies": ["bitcoin", "ethereum", "bitcoin_testnet", "ethereum_goerli"],
"content": {
"shortDescription": {
"en": "Threshold's tBTC is a truly decentralized bridge between Bitcoin and Ethereum."
},
"description": {
"en": "tBTC is Threshold’s decentralized bridge to bring BTC to the Ethereum network; the only permissionless solution on the market today. Bridge your Bitcoin to Ethereum in a secure and trustless way to participate in DeFi."
}
},
"permissions": [
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
"account.list",
"account.receive",
"account.request",
"currency.list",
"device.close",
"device.exchange",
"device.transport",
"message.sign",
"transaction.sign",
"transaction.signAndBroadcast",
"storage.set",
"storage.get",
"bitcoin.getXPub",
"wallet.capabilities",
"wallet.userId",
"wallet.info"
],
"domains": ["https://*", "wss://*"]
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"@keep-network/tbtc": "development",
"@keep-network/tbtc-v2.ts": "^2.3.0",
"@ledgerhq/connect-kit-loader": "^1.1.2",
"@ledgerhq/wallet-api-client": "^1.2.0",
"@ledgerhq/wallet-api-client-react": "^1.1.1",
"@reduxjs/toolkit": "^1.6.1",
"@rehooks/local-storage": "^2.4.4",
"@sentry/react": "^7.33.0",
Expand All @@ -44,6 +46,7 @@
"@web3-react/types": "^6.0.7",
"@web3-react/walletlink-connector": "^6.2.13",
"axios": "^0.24.0",
"bignumber.js": "^9.1.2",
"bitcoin-address-validation": "^2.2.1",
"crypto-js": "^4.1.1",
"ethereum-blockies-base64": "^1.0.2",
Expand Down
43 changes: 27 additions & 16 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { useCheckBonusEligibility } from "./hooks/useCheckBonusEligibility"
import { useFetchStakingRewards } from "./hooks/useFetchStakingRewards"
import { isSameETHAddress } from "./web3/utils"
import { ThresholdProvider } from "./contexts/ThresholdContext"
import { LedgerLiveAppProvider } from "./contexts/LedgerLiveAppContext"
import {
useSubscribeToAuthorizationIncreasedEvent,
useSubscribeToAuthorizationDecreaseApprovedEvent,
Expand All @@ -58,6 +59,9 @@ import {
useSubscribeToRedemptionRequestedEvent,
} from "./hooks/tbtc"
import { useSentry } from "./hooks/sentry"
import { useIsEmbed } from "./hooks/useIsEmbed"
import TBTC from "./pages/tBTC"
import { useDetectIfEmbed } from "./hooks/useDetectIfEmbed"

const Web3EventHandlerComponent = () => {
useSubscribeToVendingMachineContractEvents()
Expand Down Expand Up @@ -170,6 +174,7 @@ const AppBody = () => {
dispatch(fetchETHPriceUSD())
}, [dispatch])

useDetectIfEmbed()
usePosthog()
useCheckBonusEligibility()
useFetchStakingRewards()
Expand All @@ -180,12 +185,13 @@ const AppBody = () => {
}

const Layout = () => {
const { isEmbed } = useIsEmbed()
return (
<Box display="flex">
<Sidebar />
{!isEmbed && <Sidebar />}
<Box
// 100% - 80px is to account for the sidebar
w={{ base: "100%", md: "calc(100% - 80px)" }}
w={{ base: "100%", md: isEmbed ? "100%" : "calc(100% - 80px)" }}
bg={useColorModeValue("transparent", "gray.900")}
>
<Navbar />
Expand All @@ -199,12 +205,15 @@ const Layout = () => {
}

const Routing = () => {
const { isEmbed } = useIsEmbed()
const finalPages = isEmbed ? [TBTC] : pages
const to = isEmbed ? "tBTC" : "overview"
return (
<Routes>
<Route path="*" element={<Layout />}>
<Route index element={<Navigate to="overview" />} />
{pages.map(renderPageComponent)}
<Route path="*" element={<Navigate to="overview" />} />
<Route index element={<Navigate to={to} />} />
{finalPages.map(renderPageComponent)}
<Route path="*" element={<Navigate to={to} />} />
</Route>
</Routes>
)
Expand Down Expand Up @@ -248,17 +257,19 @@ const App: FC = () => {
return (
<Router basename={`${process.env.PUBLIC_URL}`}>
<Web3ReactProvider getLibrary={getLibrary}>
<ThresholdProvider>
<ReduxProvider store={reduxStore}>
<ChakraProvider theme={theme}>
<TokenContextProvider>
<Web3EventHandlerComponent />
<ModalRoot />
<AppBody />
</TokenContextProvider>
</ChakraProvider>
</ReduxProvider>
</ThresholdProvider>
<LedgerLiveAppProvider>
<ThresholdProvider>
<ReduxProvider store={reduxStore}>
<ChakraProvider theme={theme}>
<TokenContextProvider>
<Web3EventHandlerComponent />
<ModalRoot />
<AppBody />
</TokenContextProvider>
</ChakraProvider>
</ReduxProvider>
</ThresholdProvider>
</LedgerLiveAppProvider>
</Web3ReactProvider>
</Router>
)
Expand Down
4 changes: 2 additions & 2 deletions src/components/Modal/tBTC/InitiateUnminting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ModalHeader,
Skeleton,
} from "@threshold-network/components"
import { useWeb3React } from "@web3-react/core"
import { useIsActive } from "../../../hooks/useIsActive"
import { FC } from "react"
import { useNavigate } from "react-router-dom"
import { useThreshold } from "../../../contexts/ThresholdContext"
Expand Down Expand Up @@ -43,7 +43,7 @@ const InitiateUnmintingBase: FC<InitiateUnmintingProps> = ({
btcAddress,
}) => {
const navigate = useNavigate()
const { account } = useWeb3React()
const { account } = useIsActive()
const { estimatedBTCAmount, thresholdNetworkFee } =
useRedemptionEstimatedFees(unmintAmount)
const threshold = useThreshold()
Expand Down
32 changes: 24 additions & 8 deletions src/components/Navbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import { FC } from "react"
import { useWeb3React } from "@web3-react/core"
import { useModal } from "../../hooks/useModal"
import { FC, useEffect } from "react"
import NavbarComponent from "./NavbarComponent"
import { ModalType } from "../../enums"
import { useAppDispatch } from "../../hooks/store"
import { walletConnected } from "../../store/account"
import { useRequestEthereumAccount } from "../../hooks/ledger-live-app"
import { useIsActive } from "../../hooks/useIsActive"
import { useConnectWallet } from "../../hooks/useConnectWallet"

const Navbar: FC = () => {
const { openModal } = useModal()
const { account, active, chainId, deactivate } = useWeb3React()
const openWalletModal = () => openModal(ModalType.SelectWallet)
const { isActive, account, chainId, deactivate } = useIsActive()
const dispatch = useAppDispatch()
const connectWallet = useConnectWallet()

const { account: ledgerLiveAccount, requestAccount } =
useRequestEthereumAccount()
const ledgerLiveAccountAddress = ledgerLiveAccount?.address

const openWalletModal = () => {
connectWallet()
}

useEffect(() => {
if (ledgerLiveAccountAddress) {
dispatch(walletConnected(ledgerLiveAccountAddress))
}
}, [ledgerLiveAccountAddress, dispatch])

return (
<NavbarComponent
{...{
active,
active: isActive,
account,
chainId,
openWalletModal,
Expand Down
19 changes: 11 additions & 8 deletions src/components/SubmitTxButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { FC } from "react"
import { FC } from "react"
import { Button, ButtonProps } from "@chakra-ui/react"
import { ModalType } from "../enums"
import { useWeb3React } from "@web3-react/core"
import { useModal } from "../hooks/useModal"
import { useIsActive } from "../hooks/useIsActive"
import { useIsTbtcSdkInitializing } from "../contexts/ThresholdContext"
import { useConnectWallet } from "../hooks/useConnectWallet"

interface Props extends ButtonProps {
onSubmit?: () => void
Expand All @@ -15,11 +14,15 @@ const SubmitTxButton: FC<Props> = ({
submitText = "Upgrade",
...buttonProps
}) => {
const { active } = useWeb3React()
const { openModal } = useModal()
const { isActive } = useIsActive()
const { isSdkInitializedWithSigner } = useIsTbtcSdkInitializing()
const connectWallet = useConnectWallet()

if (active && isSdkInitializedWithSigner) {
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
const onConnectWalletClick = () => {
connectWallet()
}

if (isActive && isSdkInitializedWithSigner) {
return (
<Button mt={6} isFullWidth onClick={onSubmit} {...buttonProps}>
{submitText}
Expand All @@ -31,7 +34,7 @@ const SubmitTxButton: FC<Props> = ({
<Button
mt={6}
isFullWidth
onClick={() => openModal(ModalType.SelectWallet)}
onClick={onConnectWalletClick}
{...buttonProps}
type="button"
isDisabled={false}
Expand Down
5 changes: 2 additions & 3 deletions src/components/TokenBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
BoxProps,
Icon,
} from "@threshold-network/components"
import { useWeb3React } from "@web3-react/core"
import { formatTokenAmount } from "../utils/formatAmount"
import tokenIconMap, { TokenIcon } from "../static/icons/tokenIconMap"
import { useIsActive } from "../hooks/useIsActive"

export interface TokenBalanceProps {
tokenAmount: string | number
Expand Down Expand Up @@ -95,8 +95,7 @@ const TokenBalance: FC<TokenBalanceProps & TextProps> = ({
withHigherPrecision = false,
...restProps
}) => {
const { active } = useWeb3React()
const shouldRenderTokenAmount = active
const { isActive: shouldRenderTokenAmount } = useIsActive()

const _tokenAmount = useMemo(() => {
return formatTokenAmount(tokenAmount || 0, tokenFormat, tokenDecimals)
Expand Down
18 changes: 7 additions & 11 deletions src/components/TokenBalanceInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface TokenBalanceInputProps
hasError?: boolean
errorMsgText?: string | JSX.Element
helperText?: string | JSX.Element
tokenDecimals?: number
}

const TokenBalanceInput: FC<TokenBalanceInputProps> = ({
Expand All @@ -42,6 +43,7 @@ const TokenBalanceInput: FC<TokenBalanceInputProps> = ({
errorMsgText,
helperText,
hasError = false,
tokenDecimals = web3Constants.STANDARD_ERC20_DECIMALS,
...inputProps
}) => {
const inputRef = useRef<HTMLInputElement>()
Expand All @@ -64,24 +66,18 @@ const TokenBalanceInput: FC<TokenBalanceInputProps> = ({
const setToMax = () => {
let remainder = Zero
const { decimalScale } = inputProps
if (
decimalScale &&
decimalScale > 0 &&
decimalScale < web3Constants.STANDARD_ERC20_DECIMALS
) {
if (decimalScale && decimalScale > 0 && decimalScale < tokenDecimals) {
remainder = BigNumber.from(max).mod(
BigNumber.from(10).pow(
web3Constants.STANDARD_ERC20_DECIMALS - decimalScale
)
BigNumber.from(10).pow(tokenDecimals - decimalScale)
)
}
_setAmount(formatUnits(BigNumber.from(max).sub(remainder)))
_setAmount(formatUnits(BigNumber.from(max).sub(remainder), tokenDecimals))
setAmount(valueRef.current)
}

const _setAmount = (value: string | number) => {
valueRef.current = value
? parseUnits(value.toString()).toString()
? parseUnits(value.toString(), tokenDecimals).toString()
: undefined
}

Expand All @@ -106,7 +102,7 @@ const TokenBalanceInput: FC<TokenBalanceInputProps> = ({
onValueChange={(values: NumberFormatInputValues) =>
_setAmount(values.value)
}
value={amount ? formatUnits(amount) : undefined}
value={amount ? formatUnits(amount, tokenDecimals) : undefined}
onChange={() => {
setAmount(valueRef.current)
}}
Expand Down
4 changes: 2 additions & 2 deletions src/components/tBTC/BridgeActivity.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FC, createContext, useContext, ReactElement } from "react"
import { useWeb3React } from "@web3-react/core"
import {
Badge,
BodyMd,
Expand Down Expand Up @@ -27,6 +26,7 @@ import { InlineTokenBalance } from "../TokenBalance"
import Link from "../Link"
import { OutlineListItem } from "../OutlineListItem"
import { RedemptionDetailsLinkBuilder } from "../../utils/tBTC"
import { useIsActive } from "../../hooks/useIsActive"

export type BridgeActivityProps = {
data: BridgeActivityType[]
Expand Down Expand Up @@ -105,7 +105,7 @@ const ActivityItem: FC<BridgeActivityType> = ({
additionalData,
txHash,
}) => {
const { account } = useWeb3React()
const { account } = useIsActive()

const link =
bridgeProcess === "unmint"
Expand Down
Loading
Loading