-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: #351 This PR integrates with the OrangeKit SDK to predict the depositor owner Ethereum address based on user's Bitcoin address. We want to transition to Bitcoin native experience in the SDK as well so we should operate on the bitcoin addresses only and hide the Ethereum integration under the hood. In the future, we will update the other function parameters to accept Bitcoin addresses instead of Ethereum. Here we also introduce the `BitcoinProvider` interface which defines the `getAddress` method. We should rely on the `BitcoinProvider` implementation to get the Bitcoin address because different wallets use different strategies. For example, in Ledger Live the address is "renewed" each time funds are received in order to allow some privacy. In this case, relying only on the Bitcoin address, the user would create deposits for different Ethereum addresses each time the Bitcoin address was renewed. Therefore, we implement the `BitcoinProvider` for Ledger Live Wallet API that it awalys returns the same Bitcoin address based on the extended public key (`xpub`). The Ledger Live Wallet API increments the `index` in the derivation path each time funds are received(`m/x'/0'/0'/0/0`; `m/x'/0'/0'/0/1`; `m/x'/0'/0'/0/2` ...), so to get the same address we need to derive a single address from a given extended public key - an address under the `m/x'/0'/0'/0/0` path. Thanks to this we can create a deposit for the same Ethereum address even if Ledger Live renewed the Bitcoin address.
- Loading branch information
Showing
43 changed files
with
1,077 additions
and
551 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
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
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
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
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
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
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
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
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
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
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
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,19 +1,24 @@ | ||
import { useEffect } from "react" | ||
import { ETHEREUM_NETWORK } from "#/constants" | ||
import { BITCOIN_NETWORK } from "#/constants" | ||
import { logPromiseFailure } from "#/utils" | ||
import { useAcreContext } from "#/acre-react/hooks" | ||
import { LedgerLiveWalletApiBitcoinProvider } from "@acre-btc/sdk/dist/src/lib/bitcoin/providers" | ||
import { useWalletContext } from "../useWalletContext" | ||
|
||
export function useInitializeAcreSdk() { | ||
const { ethAccount } = useWalletContext() | ||
const { btcAccount } = useWalletContext() | ||
const { init } = useAcreContext() | ||
|
||
useEffect(() => { | ||
if (!ethAccount?.address) return | ||
if (!btcAccount?.id) return | ||
|
||
const initSDK = async (ethAddress: string) => { | ||
await init(ethAddress, ETHEREUM_NETWORK) | ||
const initSDK = async (bitcoinAccountId: string) => { | ||
const bitcoinProvider = await LedgerLiveWalletApiBitcoinProvider.init( | ||
bitcoinAccountId, | ||
BITCOIN_NETWORK, | ||
) | ||
await init(bitcoinProvider) | ||
} | ||
logPromiseFailure(initSDK(ethAccount.address)) | ||
}, [ethAccount?.address, init]) | ||
logPromiseFailure(initSDK(btcAccount.id)) | ||
}, [btcAccount?.id, init]) | ||
} |
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,6 +1,5 @@ | ||
import { useShowWalletErrorToast } from "./useShowWalletErrorToast" | ||
|
||
export function useInitGlobalToasts() { | ||
useShowWalletErrorToast("ethereum") | ||
useShowWalletErrorToast("bitcoin") | ||
} |
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
This file was deleted.
Oops, something went wrong.
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,18 +1,25 @@ | ||
import { useMemo } from "react" | ||
import { ZeroAddress } from "ethers" | ||
import { useWalletContext } from "./useWalletContext" | ||
import { useRequestBitcoinAccount } from "./useRequestBitcoinAccount" | ||
import { useRequestEthereumAccount } from "./useRequestEthereumAccount" | ||
|
||
export function useWallet() { | ||
const { btcAccount, ethAccount } = useWalletContext() | ||
const { btcAccount, ethAccount, setEthAccount } = useWalletContext() | ||
const { requestAccount: requestBitcoinAccount } = useRequestBitcoinAccount() | ||
const { requestAccount: requestEthereumAccount } = useRequestEthereumAccount() | ||
|
||
return useMemo( | ||
() => ({ | ||
bitcoin: { account: btcAccount, requestAccount: requestBitcoinAccount }, | ||
ethereum: { account: ethAccount, requestAccount: requestEthereumAccount }, | ||
bitcoin: { | ||
account: btcAccount, | ||
requestAccount: async () => { | ||
await requestBitcoinAccount() | ||
// TODO: Temporary solution - we do not need the eth account and we | ||
// want to create the Acre SDK w/o passing the Ethereum Account. | ||
setEthAccount(ZeroAddress) | ||
}, | ||
}, | ||
ethereum: { account: ethAccount }, | ||
}), | ||
[btcAccount, requestBitcoinAccount, ethAccount, requestEthereumAccount], | ||
[btcAccount, requestBitcoinAccount, ethAccount, setEthAccount], | ||
) | ||
} |
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.