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

[WIP] feature: bbn-wallet-connect native lib #409

Closed
wants to merge 1 commit into from
Closed
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
68 changes: 59 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dependencies": {
"@babylonlabs-io/babylon-proto-ts": "0.0.3-canary.3",
"@babylonlabs-io/bbn-core-ui": "^0.2.0",
"@babylonlabs-io/bbn-wallet-connect": "^0.0.18",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the tomo dependency be removed from this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrwbabylonlab Tomo wallet connect is not currently implemented, it requires additional abstraction

@totraev Should Tomo wallet connect be a dependency and the part of the simple-staking or bbn-wallet-connect?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm getting confused. we are going to use the bbn-wallet-connect. why tomo is still here?

"@babylonlabs-io/btc-staking-ts": "0.4.0-canary.3",
"@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3",
"@bitcoinerlab/secp256k1": "^1.1.1",
Expand Down
4 changes: 3 additions & 1 deletion src/app/components/Connect/ConnectSmall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { LoadingSmall } from "../Loading/Loading";

interface ConnectSmallProps {
loading?: boolean;
connected?: boolean;
onConnect: () => void;
address: string;
btcWalletBalanceSat?: number;
Expand All @@ -26,6 +27,7 @@ interface ConnectSmallProps {

export const ConnectSmall: React.FC<ConnectSmallProps> = ({
loading = false,
connected = false,
onConnect,
address,
btcWalletBalanceSat,
Expand Down Expand Up @@ -64,7 +66,7 @@ export const ConnectSmall: React.FC<ConnectSmallProps> = ({
);
};

return address ? (
return connected ? (
<div className="relative mr-[-10px] text-sm hidden md:flex" ref={ref}>
<button
className="flex cursor-pointer outline-none items-stretch"
Expand Down
4 changes: 3 additions & 1 deletion src/app/components/Connect/ConnectedSmall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import { LoadingSmall } from "../Loading/Loading";

interface ConnectedSmallProps {
loading?: boolean;
connected?: boolean;
address: string;
onDisconnect: () => void;
btcWalletBalanceSat?: number;
}

export const ConnectedSmall: React.FC<ConnectedSmallProps> = ({
loading = false,
connected = false,
address,
btcWalletBalanceSat,
onDisconnect,
Expand All @@ -38,7 +40,7 @@ export const ConnectedSmall: React.FC<ConnectedSmallProps> = ({
const { coinName } = getNetworkConfig();

return (
address && (
connected && (
<div className="relative flex text-sm" ref={ref}>
<button
className="flex cursor-pointer outline-none items-stretch w-full justify-between"
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,7 +1,7 @@
import { useWalletConnect } from "@babylonlabs-io/bbn-wallet-connect";
import { twJoin } from "tailwind-merge";

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 @@ -12,7 +12,7 @@ import { TestingInfo } from "../TestingInfo/TestingInfo";
import { ThemeToggle } from "../ThemeToggle/ThemeToggle";

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

Expand All @@ -35,6 +35,7 @@ export const Header = () => {
address={address}
btcWalletBalanceSat={totalBalance}
onDisconnect={disconnect}
connected={connected}
/>
<ThemeToggle />
</div>
Expand All @@ -49,6 +50,7 @@ export const Header = () => {
address={address}
btcWalletBalanceSat={totalBalance}
onDisconnect={disconnect}
connected={connected}
/>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/app/components/Modals/FilterOrdinalsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useWalletConnect } from "@babylonlabs-io/bbn-wallet-connect";
import { useEffect, useState } from "react";
import { IoMdClose } from "react-icons/io";
import { useLocalStorage } from "usehooks-ts";

import { FILTER_ORDINALS_MODAL_KEY } from "@/app/common/constants";
import { useBTCWallet } from "@/app/context/wallet/BTCWalletProvider";
import { useWalletConnection } from "@/app/context/wallet/WalletConnectionProvider";
import { useAppState } from "@/app/state";

import { GeneralModal } from "./GeneralModal";
Expand All @@ -23,17 +23,17 @@ export const FilterOrdinalsModal: React.FC<FilterOrdinalsModalProps> = ({}) => {
}));
};

const { isConnected } = useWalletConnection();
const { connected } = useWalletConnect();
const { ordinalsExcluded, includeOrdinals, excludeOrdinals } = useAppState();

const [hasSeenFilterOrdinalsModal, setHasSeenFilterOrdinalsModal] =
useLocalStorage<Record<string, boolean>>(FILTER_ORDINALS_MODAL_KEY, {});

useEffect(() => {
if (isConnected && address && !hasSeenFilterOrdinalsModal[address]) {
if (connected && address && !hasSeenFilterOrdinalsModal[address]) {
setModalOpen(true);
}
}, [isConnected, hasSeenFilterOrdinalsModal, address]);
}, [connected, hasSeenFilterOrdinalsModal, address]);

return (
<GeneralModal open={modalOpen} onClose={handleClose}>
Expand Down
19 changes: 19 additions & 0 deletions src/app/context/wallet/BBNWalletProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useContext } from "react";

// import { CosmosWalletContext as NativeCosmosWalletContext } from "./bbn";
import { useWalletConnector, WalletConnectorName } from "./ConnectorProvider";
import { CosmosWalletContext as TomoCosmosWalletContext } from "./tomo";
import { CosmosWalletContext } from "./types";

const CosmosProviders = {
tomo: TomoCosmosWalletContext,
native: TomoCosmosWalletContext,
} as const;

export function useBBNWallet(
connector?: WalletConnectorName,
): CosmosWalletContext {
const { BBN } = useWalletConnector();

return useContext(CosmosProviders[connector ?? BBN]);
}
Loading
Loading