Skip to content

Commit

Permalink
bump wallet connect, adjust tomo methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gbarkhatov committed Dec 17, 2024
1 parent 84d1075 commit 0a20cc8
Show file tree
Hide file tree
Showing 9 changed files with 3,631 additions and 425 deletions.
3,980 changes: 3,600 additions & 380 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dependencies": {
"@babylonlabs-io/babylon-proto-ts": "0.0.3-canary.5",
"@babylonlabs-io/bbn-core-ui": "^0.6.1",
"@babylonlabs-io/bbn-wallet-connect": "^0.1.18",
"@babylonlabs-io/bbn-wallet-connect": "^0.1.21",
"@babylonlabs-io/btc-staking-ts": "0.4.0-canary.5",
"@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3",
"@bitcoinerlab/secp256k1": "^1.1.1",
Expand All @@ -36,7 +36,7 @@
"@sentry/nextjs": "^8.30.0",
"@tanstack/react-query": "^5.28.14",
"@tanstack/react-query-next-experimental": "^5.28.14",
"@tomo-inc/wallet-connect-sdk": "^0.3.5",
"@tomo-inc/wallet-connect-sdk": "^0.3.6",
"@uidotdev/usehooks": "^2.4.1",
"axios": "^1.7.4",
"bitcoinjs-lib": "6.1.5",
Expand Down
13 changes: 4 additions & 9 deletions src/app/context/tomo/BBNConnector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ const createProvider = (provider: CosmosProvider): IBBNProvider => {
return {
connectWallet: async () => void provider.connectWallet(),
getAddress: () => provider.getAddress(),
getPublicKeyHex: async () => "",
// Not implemented yet
// getWalletProviderName: () => provider.getWalletProviderName(),
// getWalletProviderIcon: () => provider.getWalletProviderIcon(),
// getOfflineSigner: () => provider.getOfflineSigner(),
// Fallback
getWalletProviderName: async () => "",
getWalletProviderIcon: async () => "",
getOfflineSigner: async () => null as any,
getPublicKeyHex: () => provider.getPublicKeyHex(),
getWalletProviderName: () => provider.getWalletProviderName(),
getWalletProviderIcon: () => provider.getWalletProviderIcon(),
getOfflineSigner: () => provider.getOfflineSigner(),
};
};

Expand Down
11 changes: 3 additions & 8 deletions src/app/context/tomo/BTCConnector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@ const createProvider = (provider: BTCProvider): IBTCProvider => {
signPsbt: (psbtHex: string) => provider.signPsbt(psbtHex),
signPsbts: (psbtsHexes: string[]) => provider.signPsbts(psbtsHexes),
getNetwork: () => provider.getNetwork(),
signMessageBIP322: (message: string) => provider.signMessageBIP322(message),
signMessage: (message: string, type: "ecdsa" | "bip322-simple") =>
signMessage: (message: string, type: "ecdsa") =>
provider.signMessage(message, type),
on: (eventName: string, callBack: () => void) =>
provider.on(eventName, callBack),
off: (eventName: string, callBack: () => void) =>
provider.off(eventName, callBack),
getBalance: () => provider.getBalance(),
getNetworkFees: () => provider.getNetworkFees(),
pushTx: (txHex: string) => provider.pushTx(txHex),
getUtxos: (address: string, amount?: number) =>
provider.getUtxos(address, amount),
getBTCTipHeight: () => provider.getBTCTipHeight(),
getWalletProviderName: () => provider.getWalletProviderName(),
getWalletProviderIcon: () => provider.getWalletProviderIcon(),
getInscriptions: () =>
provider
.getInscriptions()
Expand Down
31 changes: 16 additions & 15 deletions src/app/context/wallet/BTCWalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import {

import { useError } from "@/app/context/Error/ErrorContext";
import { ErrorState } from "@/app/types/errors";
import {
getAddressBalance,
getFundingUTXOs,
getNetworkFees,
getTipHeight,
pushTx,
} from "@/utils/mempool_api";
import {
getPublicKeyNoCoord,
isSupportedAddressType,
Expand All @@ -42,10 +49,7 @@ interface BTCWalletContextProps {
signPsbt: (psbtHex: string) => Promise<string>;
signPsbts: (psbtsHexes: string[]) => Promise<string[]>;
getNetwork: () => Promise<Network>;
signMessage: (
message: string,
type?: "ecdsa" | "bip322-simple",
) => Promise<string>;
signMessage: (message: string, type: "ecdsa") => Promise<string>;
getBalance: () => Promise<number>;
getNetworkFees: () => Promise<Fees>;
pushTx: (txHex: string) => Promise<string>;
Expand Down Expand Up @@ -175,21 +179,18 @@ export const BTCWalletProvider = ({ children }: PropsWithChildren) => {
btcWalletProvider?.signPsbts(psbtsHexes) ?? [],
getNetwork: async () =>
btcWalletProvider?.getNetwork() ?? ({} as Network),
signMessage: async (
message: string,
type: "ecdsa" | "bip322-simple" = "bip322-simple",
) => btcWalletProvider?.signMessage(message, type) ?? "",
getBalance: async () => btcWalletProvider?.getBalance() ?? 0,
getNetworkFees: async () =>
btcWalletProvider?.getNetworkFees() ?? ({} as Fees),
pushTx: async (txHex: string) => btcWalletProvider?.pushTx(txHex) ?? "",
signMessage: async (message: string, type: "ecdsa") =>
btcWalletProvider?.signMessage(message, type) ?? "",
getBalance: async () => getAddressBalance(address),
getNetworkFees: async () => getNetworkFees(),
pushTx: async (txHex: string) => pushTx(txHex),
getUtxos: async (address: string, amount?: number) =>
btcWalletProvider?.getUtxos(address, amount) ?? [],
getBTCTipHeight: async () => btcWalletProvider?.getBTCTipHeight() ?? 0,
getFundingUTXOs(address, amount),
getBTCTipHeight: async () => getTipHeight(),
getInscriptions: async (): Promise<InscriptionIdentifier[]> =>
btcWalletProvider?.getInscriptions().catch(() => []) ?? [],
}),
[btcWalletProvider],
[btcWalletProvider, address],
);

const btcContextValue = useMemo(
Expand Down
6 changes: 3 additions & 3 deletions src/app/context/wallet/CosmosWalletProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import {
BBNProvider,
IBBNProvider,
useChainConnector,
useWalletConnect,
} from "@babylonlabs-io/bbn-wallet-connect";
Expand Down Expand Up @@ -39,7 +39,7 @@ const CosmosWalletContext = createContext<CosmosWalletContextProps>({

export const CosmosWalletProvider = ({ children }: PropsWithChildren) => {
const [BBNWalletProvider, setBBNWalletProvider] = useState<
BBNProvider | undefined
IBBNProvider | undefined
>();
const [cosmosBech32Address, setCosmosBech32Address] = useState("");
const [signingStargateClient, setSigningStargateClient] = useState<
Expand All @@ -57,7 +57,7 @@ export const CosmosWalletProvider = ({ children }: PropsWithChildren) => {
}, []);

const connectCosmos = useCallback(
async (provider: BBNProvider | null) => {
async (provider: IBBNProvider | null) => {
if (!provider) return;

try {
Expand Down
5 changes: 1 addition & 4 deletions src/app/hooks/services/useTransactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ export interface BtcStakingInputs {

interface BtcSigningFuncs {
signPsbt: (psbtHex: string) => Promise<string>;
signMessage: (
message: string,
type?: "ecdsa" | "bip322-simple",
) => Promise<string>;
signMessage: (message: string, type: "ecdsa") => Promise<string>;
signingCallback: (step: SigningStep, status: EOIStepStatus) => Promise<void>;
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/mempool_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export async function getNetworkFees(): Promise<Fees> {
return await response.json();
}
}

// Get the tip height of the BTC chain
export async function getTipHeight(): Promise<number> {
const response = await fetch(btcTipHeightUrl());
Expand Down
5 changes: 1 addition & 4 deletions src/utils/wallet/btc_wallet_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ export abstract class BTCWalletProvider {
* @param type - The type of the message to sign, defaults to 'ecdsa'
* @returns A promise that resolves to the signed message
*/
abstract signMessage(
message: string,
type?: "ecdsa" | "bip322-simple",
): Promise<string>;
abstract signMessage(message: string, type: "ecdsa"): Promise<string>;

/**
* Registers an event listener for the specified event.
Expand Down

0 comments on commit 0a20cc8

Please sign in to comment.