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

feat: Bump wallet connect #515

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3,750 changes: 3,488 additions & 262 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.22",
"@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
8 changes: 6 additions & 2 deletions src/app/components/PersonalBalance/PersonalBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ const QUERY_KEYS = {

export function PersonalBalance() {
const { coinName, coinSymbol } = getNetworkConfig();
const { getBalance: getBTCBalance, connected: btcConnected } = useBTCWallet();
const {
getBalance: getBTCBalance,
connected: btcConnected,
address,
} = useBTCWallet();
const { connected: cosmosConnected } = useCosmosWallet();

const {
Expand All @@ -34,7 +38,7 @@ export function PersonalBalance() {

const { data: btcBalance, isLoading: btcBalanceLoading } = useQuery({
queryKey: [QUERY_KEYS.BTC_BALANCE],
queryFn: getBTCBalance,
queryFn: () => getBTCBalance(address),
enabled: btcConnected,
});

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,11 +49,8 @@ interface BTCWalletContextProps {
signPsbt: (psbtHex: string) => Promise<string>;
signPsbts: (psbtsHexes: string[]) => Promise<string[]>;
getNetwork: () => Promise<Network>;
signMessage: (
message: string,
type?: "ecdsa" | "bip322-simple",
) => Promise<string>;
getBalance: () => Promise<number>;
signMessage: (message: string, type: "ecdsa") => Promise<string>;
getBalance: (address: string) => Promise<number>;
getNetworkFees: () => Promise<Fees>;
pushTx: (txHex: string) => Promise<string>;
getUtxos: (address: string, amount?: number) => Promise<UTXO[]>;
Expand Down Expand Up @@ -175,17 +179,14 @@ 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 (address: string) => getAddressBalance(address),
getNetworkFees: async () => getNetworkFees(),
pushTx: async (txHex: string) => pushTx(txHex),
getUtxos: async (address: string, amount?: number) =>
gbarkhatov marked this conversation as resolved.
Show resolved Hide resolved
btcWalletProvider?.getUtxos(address, amount) ?? [],
getBTCTipHeight: async () => btcWalletProvider?.getBTCTipHeight() ?? 0,
getFundingUTXOs(address, amount),
getBTCTipHeight: async () => getTipHeight(),
getInscriptions: async (): Promise<InscriptionIdentifier[]> =>
btcWalletProvider?.getInscriptions().catch(() => []) ?? [],
}),
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