From a4f19274cdf48d010dd9f4f5c5492b083d2ce5ef Mon Sep 17 00:00:00 2001 From: David Totrashvili <8580261+totraev@users.noreply.github.com> Date: Wed, 25 Dec 2024 09:58:32 +0500 Subject: [PATCH] feat: add network config to every chain (#166) * fix: term of service copy * feat: add network config to every chain * fix: ci/cd issues --- .changeset/angry-cobras-impress.md | 5 +++++ package-lock.json | 4 ++-- src/components/Chains/container.tsx | 2 +- src/components/Chains/index.stories.ts | 3 ++- src/components/Inscriptions/container.tsx | 14 ++++++++++++++ src/components/Inscriptions/index.tsx | 2 ++ src/components/TermsOfService/container.tsx | 15 +++++++++++++++ src/components/TermsOfService/index.tsx | 6 ++++-- .../WalletProvider/components/Screen.tsx | 8 ++++---- src/components/Wallets/container.tsx | 2 +- src/components/Wallets/index.stories.tsx | 2 +- src/context/Chain.context.tsx | 4 ++-- src/core/WalletConnector.ts | 5 +++-- src/core/index.ts | 4 ++-- src/core/types.ts | 6 ++++-- 15 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 .changeset/angry-cobras-impress.md create mode 100644 src/components/Inscriptions/container.tsx create mode 100644 src/components/TermsOfService/container.tsx diff --git a/.changeset/angry-cobras-impress.md b/.changeset/angry-cobras-impress.md new file mode 100644 index 0000000..0a89c72 --- /dev/null +++ b/.changeset/angry-cobras-impress.md @@ -0,0 +1,5 @@ +--- +"@babylonlabs-io/bbn-wallet-connect": patch +--- + +add network config to every chain diff --git a/package-lock.json b/package-lock.json index 2dbd396..0766697 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@babylonlabs-io/bbn-wallet-connect", - "version": "0.1.28", + "version": "0.1.29", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@babylonlabs-io/bbn-wallet-connect", - "version": "0.1.28", + "version": "0.1.29", "dependencies": { "@bitcoin-js/tiny-secp256k1-asmjs": "^2.2.3", "@cosmjs/stargate": "^0.32.4", diff --git a/src/components/Chains/container.tsx b/src/components/Chains/container.tsx index 5b91530..f02c307 100644 --- a/src/components/Chains/container.tsx +++ b/src/components/Chains/container.tsx @@ -13,7 +13,7 @@ interface ContainerProps { onDisconnectWallet?: (chainId: string) => void; } -export default function ChainsContainer(props: ContainerProps) { +export function ChainsContainer(props: ContainerProps) { const { chains, selectedWallets, displayWallets } = useWidgetState(); const { selected } = useWalletConnect(); diff --git a/src/components/Chains/index.stories.ts b/src/components/Chains/index.stories.ts index dfa96cf..0b2aba5 100644 --- a/src/components/Chains/index.stories.ts +++ b/src/components/Chains/index.stories.ts @@ -30,8 +30,9 @@ export const Default: Story = { label: "Installed", }, ], + config: {}, }, - { id: "BBN", name: "Babylon Chain", icon: "/images/chains/babylon.jpeg", wallets: [] }, + { id: "BBN", name: "Babylon Chain", icon: "/images/chains/babylon.jpeg", wallets: [], config: {} }, ], selectedWallets: { BTC: { diff --git a/src/components/Inscriptions/container.tsx b/src/components/Inscriptions/container.tsx new file mode 100644 index 0000000..ac31f49 --- /dev/null +++ b/src/components/Inscriptions/container.tsx @@ -0,0 +1,14 @@ +import { useWidgetState } from "@/hooks/useWidgetState"; + +import { Inscriptions } from "."; + +interface InscriptionsContainerProps { + className?: string; + onSubmit?: (value: boolean, showAgain: boolean) => void; +} + +export function InscriptionsContainer({ className, onSubmit }: InscriptionsContainerProps) { + const { chains } = useWidgetState(); + + return ; +} diff --git a/src/components/Inscriptions/index.tsx b/src/components/Inscriptions/index.tsx index 73c4c5c..52b3543 100644 --- a/src/components/Inscriptions/index.tsx +++ b/src/components/Inscriptions/index.tsx @@ -3,10 +3,12 @@ import { useState } from "react"; import { twMerge } from "tailwind-merge"; import { FieldControl } from "@/components/FieldControl"; +import { BTCConfig } from "@/core/types"; export interface Props { className?: string; onSubmit?: (value: boolean, showAgain: boolean) => void; + config?: BTCConfig; } export function Inscriptions({ className, onSubmit }: Props) { diff --git a/src/components/TermsOfService/container.tsx b/src/components/TermsOfService/container.tsx new file mode 100644 index 0000000..e38e615 --- /dev/null +++ b/src/components/TermsOfService/container.tsx @@ -0,0 +1,15 @@ +import { useWidgetState } from "@/hooks/useWidgetState"; + +import { TermsOfService } from "."; + +export interface TermsOfServiceContainerProps { + className?: string; + onClose?: () => void; + onSubmit?: () => void; +} + +export function TermsOfServiceContainer(props: TermsOfServiceContainerProps) { + const { chains } = useWidgetState(); + + return ; +} diff --git a/src/components/TermsOfService/index.tsx b/src/components/TermsOfService/index.tsx index 0c371b8..089cb96 100644 --- a/src/components/TermsOfService/index.tsx +++ b/src/components/TermsOfService/index.tsx @@ -3,9 +3,11 @@ import { useCallback, useMemo, useState } from "react"; import { twMerge } from "tailwind-merge"; import { FieldControl } from "@/components/FieldControl"; +import { BTCConfig } from "@/core/types"; export interface Props { className?: string; + config?: BTCConfig; onClose?: () => void; onSubmit?: () => void; } @@ -37,7 +39,7 @@ export function TermsOfService({ className, onClose, onSubmit }: Props) { +
I certify that I have read and accept the updated{" "} . - +
} className="b-mb-8" > diff --git a/src/components/WalletProvider/components/Screen.tsx b/src/components/WalletProvider/components/Screen.tsx index 55bf997..0aaf833 100644 --- a/src/components/WalletProvider/components/Screen.tsx +++ b/src/components/WalletProvider/components/Screen.tsx @@ -1,10 +1,10 @@ import { type JSX } from "react"; -import Chains from "@/components/Chains/container"; -import { Inscriptions } from "@/components/Inscriptions"; +import { ChainsContainer as Chains } from "@/components/Chains/container"; +import { InscriptionsContainer as Inscriptions } from "@/components/Inscriptions/container"; import { LoaderScreen } from "@/components/Loader"; -import { TermsOfService } from "@/components/TermsOfService"; -import Wallets from "@/components/Wallets/container"; +import { TermsOfServiceContainer as TermsOfService } from "@/components/TermsOfService/container"; +import { WalletsContainer as Wallets } from "@/components/Wallets/container"; import type { Screen } from "@/context/State.context"; import type { IChain, IWallet } from "@/core/types"; diff --git a/src/components/Wallets/container.tsx b/src/components/Wallets/container.tsx index 40a9d5f..8285d36 100644 --- a/src/components/Wallets/container.tsx +++ b/src/components/Wallets/container.tsx @@ -13,7 +13,7 @@ interface WalletContainerProps { onSelectWallet?: (chain: IChain, wallet: IWallet) => void; } -export default function WalletsContainer({ widgets = {}, ...props }: WalletContainerProps) { +export function WalletsContainer({ widgets = {}, ...props }: WalletContainerProps) { const { chains, screen, displayChains } = useWidgetState(); const chainId = screen.params?.chain ?? ""; const currentChain = chains?.[chainId]; diff --git a/src/components/Wallets/index.stories.tsx b/src/components/Wallets/index.stories.tsx index a4e64d1..d302604 100644 --- a/src/components/Wallets/index.stories.tsx +++ b/src/components/Wallets/index.stories.tsx @@ -71,7 +71,7 @@ const wallets: IWallet[] = [ export const Default: Story = { args: { className: "b-h-[600px]", - chain: { id: "BTC", name: "Bitcoin", icon: "/images/chains/bitcoin.png", wallets }, + chain: { id: "BTC", name: "Bitcoin", icon: "/images/chains/bitcoin.png", config: {}, wallets }, append: (
More wallets with Tomo Connect diff --git a/src/context/Chain.context.tsx b/src/context/Chain.context.tsx index 6e4451b..698fcae 100644 --- a/src/context/Chain.context.tsx +++ b/src/context/Chain.context.tsx @@ -28,8 +28,8 @@ interface ProviderProps { } export interface Connectors { - BTC: WalletConnector<"BTC", IBTCProvider> | null; - BBN: WalletConnector<"BBN", IBBNProvider> | null; + BTC: WalletConnector<"BTC", IBTCProvider, BTCConfig> | null; + BBN: WalletConnector<"BBN", IBBNProvider, BBNConfig> | null; } const defaultState: Connectors = { diff --git a/src/core/WalletConnector.ts b/src/core/WalletConnector.ts index 2fa61ab..4199931 100644 --- a/src/core/WalletConnector.ts +++ b/src/core/WalletConnector.ts @@ -10,7 +10,7 @@ export interface ConnectorEvents

{ error: (error: Error) => void; } -export class WalletConnector implements IConnector { +export class WalletConnector implements IConnector { private _connectedWallet: Wallet

| null = null; private _ee = createNanoEvents>(); @@ -19,6 +19,7 @@ export class WalletConnector implements I public readonly name: string, public readonly icon: string, public readonly wallets: Wallet

[], + public readonly config: C, ) {} get connectedWallet() { @@ -53,7 +54,7 @@ export class WalletConnector implements I } clone() { - return new WalletConnector(this.id, this.name, this.icon, this.wallets); + return new WalletConnector(this.id, this.name, this.icon, this.wallets, this.config); } on>(name: K, handler: ConnectorEvents

[K]) { diff --git a/src/core/index.ts b/src/core/index.ts index 0334abf..498b353 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -67,12 +67,12 @@ export const createWalletConnector = async , context: any, config: C, -): Promise> => { +): Promise> => { const wallets: Wallet

[] = []; for (const walletMetadata of metadata.wallets) { wallets.push(await createWallet(walletMetadata, context, config)); } - return new WalletConnector(metadata.chain, metadata.name, metadata.icon, wallets); + return new WalletConnector(metadata.chain, metadata.name, metadata.icon, wallets, config); }; diff --git a/src/core/types.ts b/src/core/types.ts index 0156857..a501c01 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -76,14 +76,16 @@ export interface IWallet

{ label: string; } -export interface IChain { +export interface IChain { id: K; name: string; icon: string; wallets: IWallet

[]; + config: C; } -export interface IConnector extends IChain { +export interface IConnector + extends IChain { connect(wallet: string | IWallet

): Promise | null>; disconnect(): Promise; on(event: string, cb: (wallet: IWallet

) => void): () => void;