Skip to content

Commit

Permalink
feature: Tomo dual wallet (#225)
Browse files Browse the repository at this point in the history
* feat: tomo dual wallet
  • Loading branch information
gbarkhatov authored Oct 23, 2024
1 parent e4305d6 commit aeb90ce
Show file tree
Hide file tree
Showing 49 changed files with 2,654 additions and 3,803 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
10 changes: 5 additions & 5 deletions docs/WalletIntegration.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const DEFAULT_INSCRIPTION_LIMIT = 100;
* Provides methods for connecting to a wallet, retrieving wallet information, signing transactions, and more.
*/

export abstract class WalletProvider {
export abstract class BTCWalletProvider {
/**
* Connects to the wallet and returns the instance of the wallet provider.
* Currently only supports "native segwit" and "taproot" address types.
Expand Down Expand Up @@ -189,7 +189,7 @@ instance of it under the `window.btcwallet` global object when the Babylon dApp
is loaded.

```ts
class MobileAppWallet extends WalletProvider {
class MobileAppWallet extends BTCWalletProvider {
...
Interface Methods definitions
...
Expand All @@ -211,7 +211,7 @@ are implemented using external calls to the mempool.space API as they are not
provided out of the box from the wallet exposed methods.

```ts
import { WalletProvider, Network, Fees, UTXO } from "../wallet_provider";
import { BTCWalletProvider, Network, Fees, UTXO } from "../btc_wallet_provider";
import {
getAddressBalance,
getTipHeight,
Expand All @@ -225,7 +225,7 @@ type OKXWalletInfo = {
address: string;
};

export class OKXWallet extends WalletProvider {
export class OKXWallet extends BTCWalletProvider {
private okxWalletInfo: OKXWalletInfo | undefined;

constructor() {
Expand Down Expand Up @@ -392,7 +392,7 @@ export class OKXWallet extends WalletProvider {
As a reference, we provide the mempool.space retrieval methods that we used below:

```ts
import { Fees, UTXO } from "./wallet/wallet_provider";
import { Fees, UTXO } from "./wallet/btc_wallet_provider";

/*
URL Construction methods
Expand Down
3,532 changes: 2,047 additions & 1,485 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"node": "22.3.0"
},
"dependencies": {
"@babylonlabs-io/btc-staking-ts": "0.3.0",
"@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3",
"@bitcoinerlab/secp256k1": "^1.1.1",
"@keystonehq/animated-qr": "^0.8.6",
Expand All @@ -33,10 +34,10 @@
"@scure/bip32": "^1.4.0",
"@tanstack/react-query": "^5.28.14",
"@tanstack/react-query-next-experimental": "^5.28.14",
"@tomo-inc/wallet-connect-sdk": "0.2.4",
"@uidotdev/usehooks": "^2.4.1",
"axios": "^1.7.4",
"bitcoinjs-lib": "6.1.5",
"@babylonlabs-io/btc-staking-ts": "0.3.0",
"date-fns": "^3.6.0",
"decimal.js-light": "^2.5.1",
"framer-motion": "^11.1.9",
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/postFilterOrdinals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { chunkArray } from "@/utils/chunkArray";
import { UTXO } from "@/utils/wallet/wallet_provider";
import { UTXO } from "@/utils/wallet/btc_wallet_provider";

import { apiWrapper } from "./apiWrapper";

Expand Down
29 changes: 0 additions & 29 deletions src/app/common/utils/psbt.ts

This file was deleted.

32 changes: 7 additions & 25 deletions src/app/components/Delegations/Delegations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import { useEffect, useMemo, useState } from "react";
import InfiniteScroll from "react-infinite-scroll-component";
import { useLocalStorage } from "usehooks-ts";

import {
signPsbtTransaction,
SignPsbtTransaction,
} from "@/app/common/utils/psbt";
import { LoadingTableList } from "@/app/components/Loading/Loading";
import { DelegationsPointsProvider } from "@/app/context/api/DelegationsPointsProvider";
import { useError } from "@/app/context/Error/ErrorContext";
import { useWallet } from "@/app/context/wallet/WalletProvider";
import { useBTCWallet } from "@/app/context/wallet/BTCWalletProvider";
import { useDelegations } from "@/app/hooks/api/useDelegations";
import { useHealthCheck } from "@/app/hooks/useHealthCheck";
import { useAppState } from "@/app/state";
Expand All @@ -26,7 +22,6 @@ import { signUnbondingTx } from "@/utils/delegations/signUnbondingTx";
import { signWithdrawalTx } from "@/utils/delegations/signWithdrawalTx";
import { getIntermediateDelegationsLocalStorageKey } from "@/utils/local_storage/getIntermediateDelegationsLocalStorageKey";
import { toLocalStorageIntermediateDelegation } from "@/utils/local_storage/toLocalStorageIntermediateDelegation";
import { WalletProvider } from "@/utils/wallet/wallet_provider";

import {
MODE,
Expand All @@ -40,15 +35,9 @@ import { Delegation } from "./Delegation";
export const Delegations = () => {
const { currentVersion } = useAppState();
const { data: delegationsAPI } = useDelegations();
const {
walletProvider: btcWallet,
address,
publicKeyNoCoord,
connected,
network,
} = useWallet();
const { address, publicKeyNoCoord, connected, network } = useBTCWallet();

if (!btcWallet || !delegationsAPI || !currentVersion || !network) {
if (!connected || !delegationsAPI || !currentVersion || !network) {
return;
}

Expand All @@ -63,9 +52,6 @@ export const Delegations = () => {
<DelegationsContent
delegationsAPI={delegationsAPI.delegations}
globalParamsVersion={currentVersion}
signPsbtTx={signPsbtTransaction(btcWallet)}
pushTx={btcWallet.pushTx}
getNetworkFees={btcWallet.getNetworkFees}
address={address}
btcWalletNetwork={network}
publicKeyNoCoord={publicKeyNoCoord}
Expand All @@ -82,18 +68,12 @@ interface DelegationsContentProps {
publicKeyNoCoord: string;
btcWalletNetwork: networks.Network;
address: string;
signPsbtTx: SignPsbtTransaction;
pushTx: WalletProvider["pushTx"];
getNetworkFees: WalletProvider["getNetworkFees"];
isWalletConnected: boolean;
}

const DelegationsContent: React.FC<DelegationsContentProps> = ({
delegationsAPI,
globalParamsVersion,
signPsbtTx,
pushTx,
getNetworkFees,
address,
btcWalletNetwork,
publicKeyNoCoord,
Expand All @@ -111,6 +91,8 @@ const DelegationsContent: React.FC<DelegationsContentProps> = ({
isLoading,
} = useDelegationState();

const { signPsbt, getNetworkFees, pushTx } = useBTCWallet();

const delegation = useMemo(
() =>
delegationsAPI.find((delegation) => delegation.stakingTxHashHex === txID),
Expand Down Expand Up @@ -177,7 +159,7 @@ const DelegationsContent: React.FC<DelegationsContentProps> = ({
delegationsAPI,
publicKeyNoCoord,
btcWalletNetwork,
signPsbtTx,
signPsbt,
);
// Update the local state with the new intermediate delegation
updateLocalStorage(delegation, DelegationState.INTERMEDIATE_UNBONDING);
Expand Down Expand Up @@ -209,7 +191,7 @@ const DelegationsContent: React.FC<DelegationsContentProps> = ({
delegationsAPI,
publicKeyNoCoord,
btcWalletNetwork,
signPsbtTx,
signPsbt,
address,
getNetworkFees,
pushTx,
Expand Down
6 changes: 4 additions & 2 deletions src/app/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useWallet } from "@/app/context/wallet/WalletProvider";
import { useBTCWallet } from "@/app/context/wallet/BTCWalletProvider";
import { useWalletConnection } from "@/app/context/wallet/WalletConnectionProvider";
import { useAppState } from "@/app/state";
import { shouldDisplayTestingMsg } from "@/config";

Expand All @@ -9,7 +10,8 @@ import { TestingInfo } from "../TestingInfo/TestingInfo";
import { ThemeToggle } from "../ThemeToggle/ThemeToggle";

export const Header = () => {
const { address, open, disconnect } = useWallet();
const { disconnect, open } = useWalletConnection();
const { address } = useBTCWallet();
const { totalBalance, isLoading: loading } = useAppState();

return (
Expand Down
Loading

0 comments on commit aeb90ce

Please sign in to comment.